00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef VCSN_ALGORITHMS_IS_AMBIGUOUS_HXX
00019 # define VCSN_ALGORITHMS_IS_AMBIGUOUS_HXX
00020
00021 # include <vaucanson/algorithms/is_ambiguous.hh>
00022 # include <vaucanson/algorithms/trim.hh>
00023 # include <vaucanson/algorithms/product.hh>
00024 # include <vaucanson/misc/usual_macros.hh>
00025
00026 # include <map>
00027 # include <set>
00028
00029 namespace vcsn {
00030
00031
00032
00033
00034 template <typename A, typename AI>
00035 bool
00036 do_is_ambiguous(const AutomataBase<A>&,
00037 const Element<A, AI>& aut)
00038 {
00039 typedef typename Element<A, AI>::hstate_t hstate_t;
00040
00041
00042 std::map<hstate_t, std::pair<hstate_t, hstate_t> > m;
00043 std::map<hstate_t, std::pair<hstate_t, hstate_t> > aut_p_m;
00044 Element<A, AI> aut_p = product (aut, aut, m);
00045 for (typename std::map<hstate_t, std::pair<hstate_t, hstate_t> >::iterator i = m.begin();
00046 i != m.end(); ++i)
00047 aut_p_m.insert(std::make_pair(aut_p.get_state(size_t(i->first)), i->second));
00048
00049 const std::set<hstate_t>& s = useful_states (aut_p);
00050 for_all_const_ (std::set<hstate_t>, i, s)
00051 if (aut_p_m[*i].first != aut_p_m[*i].second)
00052 return true;
00053 return false;
00054 }
00055
00056 template<typename A, typename AI>
00057 bool
00058 is_ambiguous(const Element<A, AI>& aut)
00059 {
00060 BENCH_TASK_SCOPED("is_ambiguous");
00061 return do_is_ambiguous(aut.structure(), aut);
00062 }
00063
00064 }
00065
00066 #endif // ! VCSN_ALGORITHMS_IS_AMBIGUOUS_HXX