Vaucanson  1.4.1
is_ambiguous.hxx
1 // is_ambiguous.hxx: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2006, 2008 The Vaucanson Group.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // The complete GNU General Public Licence Notice can be found as the
13 // `COPYING' file in the root directory.
14 //
15 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
16 //
17 
18 #ifndef VCSN_ALGORITHMS_IS_AMBIGUOUS_HXX
19 # define VCSN_ALGORITHMS_IS_AMBIGUOUS_HXX
20 
24 # include <vaucanson/misc/usual_macros.hh>
25 
26 # include <map>
27 # include <set>
28 
29 namespace vcsn {
30 
31  /*-------------.
32  | is_ambiguous |
33  `-------------*/
34  template <typename A, typename AI>
35  bool
36  do_is_ambiguous(const AutomataBase<A>&,
37  const Element<A, AI>& aut)
38  {
39  typedef typename Element<A, AI>::hstate_t hstate_t;
40 
41  // This map is used to know which state is created by which two ones.
42  std::map<hstate_t, std::pair<hstate_t, hstate_t> > m;
43  std::map<hstate_t, std::pair<hstate_t, hstate_t> > aut_p_m;
44  Element<A, AI> aut_p = product (aut, aut, m);
45  for (typename std::map<hstate_t, std::pair<hstate_t, hstate_t> >::iterator i = m.begin();
46  i != m.end(); ++i)
47  aut_p_m.insert(std::make_pair(aut_p.get_state(size_t(i->first)), i->second));
48 
49  const std::set<hstate_t>& s = useful_states (aut_p);
50  for_all_const_ (std::set<hstate_t>, i, s)
51  if (aut_p_m[*i].first != aut_p_m[*i].second)
52  return true;
53  return false;
54  }
55 
56  template<typename A, typename AI>
57  bool
58  is_ambiguous(const Element<A, AI>& aut)
59  {
60  BENCH_TASK_SCOPED("is_ambiguous");
61  return do_is_ambiguous(aut.structure(), aut);
62  }
63 
64 } // End of namespace vcsn.
65 
66 #endif // ! VCSN_ALGORITHMS_IS_AMBIGUOUS_HXX