18 #ifndef VCSN_ALGORITHMS_DETERMINIZE_HXX
19 # define VCSN_ALGORITHMS_DETERMINIZE_HXX
24 # include <vaucanson/misc/usual_macros.hh>
25 # include <vaucanson/automata/concept/automata_base.hh>
29 # endif // ! VCSN_NDEBUG
43 template <
typename A,
typename input_t,
typename output_t>
45 do_subset_construction(
const AutomataBase<A>& ,
48 std::map<
typename output_t::hstate_t,
49 std::set<typename input_t::hstate_t> >& m =
50 std::map<
typename output_t::hstate_t,
51 std::set<typename input_t::hstate_t> >())
58 AUTOMATON_TYPES(input_t);
59 AUTOMATON_FREEMONOID_TYPES(input_t);
60 typedef typename std::set<typename input_t::hstate_t> subset_t;
61 typedef typename std::map<subset_t, typename output_t::hstate_t>
63 typedef std::pair<subset_t, typename output_t::hstate_t> subset_set_pair_t;
64 typedef std::vector<typename input_t::hstate_t> delta_ret_t;
71 typename output_t::hstate_t qi_hstate = output.add_state();
73 bool is_final =
false;
74 for_all_const_initial_states(i, input)
77 is_final |= input.is_final(*i);
79 output.set_initial(qi_hstate);
82 output.set_final(qi_hstate);
84 subset_set_t subset_set;
85 subset_set[qi] = qi_hstate;
94 const alphabet_t& alphabet(input.structure().series().monoid().alphabet());
96 dst.reserve(input.states().size());
97 std::queue<subset_t> path;
101 subset_t s = path.front();
102 typename input_t::hstate_t s_hstate = subset_set[s];
105 for_all_const_letters(e, alphabet)
108 bool is_final =
false;
109 for_all_const_ (subset_t, j, s)
111 for (delta_iterator t(input.value(), *j); ! t.done(); t.next())
113 monoid_elt_t w(input.series_of(*t).structure().monoid(), *e);
114 if (input.series_of(*t).get(w) != input.series().semiring().wzero_)
116 hstate_t s = input.dst_of(*t);
118 is_final |= input.is_final(s);
122 typename subset_set_t::const_iterator current = subset_set.find(q);
123 if (current == subset_set.end())
125 typename output_t::hstate_t qs = output.add_state();
126 current = (subset_set.insert(subset_set_pair_t(q, qs))).first;
130 output.set_final(current->second);
133 output.add_letter_transition(s_hstate, (*current).second, *e);
138 template<
typename A,
typename AI>
140 subset_construction(
const Element<A, AI>& a)
142 Element<A, AI> res(a.structure());
143 do_subset_construction(res.structure(), res, a);
150 template <
typename A,
typename AI>
152 do_determinize(
const AutomataBase<A>& a_set,
153 Element<A, AI>& output,
154 const Element<A, AI>& input,
155 std::map<
typename Element<A, AI>::hstate_t,
156 std::set<
typename Element<A, AI>::hstate_t> >& m)
158 BENCH_TASK_SCOPED(
"determinize");
160 do_subset_construction(a_set, output, input, m);
163 template<
typename A,
typename AI>
170 do_determinize(ret.structure(), ret, a, m);
174 template<
typename A,
typename AI>
178 std::map<typename Element<A, AI>::hstate_t,
179 std::set<typename Element<A, AI>::hstate_t> > m;
185 #endif // ! VCSN_ALGORITHMS_DETERMINIZE_HXX