17 #ifndef VCSN_ALGORITHMS_OUTSPLITTING_HXX
18 # define VCSN_ALGORITHMS_OUTSPLITTING_HXX
33 # include <vaucanson/algebra/implementation/series/series.hh>
34 # include <vaucanson/algebra/concept/freemonoid_product.hh>
43 template <
typename S,
typename M1,
typename M2,
typename Auto_t>
45 do_outsplitting(
const AutomataBase<S>&,
46 const algebra::FreeMonoidProduct<M1, M2>&,
48 std::set<typename Auto_t::hstate_t>& m)
50 AUTOMATON_TYPES(Auto_t);
52 typedef typename series_set_elt_t::support_t support_t;
54 typedef typename monoid_t::second_monoid_t second_monoid_t;
56 typedef typename monoid_elt_value_t::second_type
57 second_monoid_elt_value_t;
58 typedef Element<second_monoid_t, second_monoid_elt_value_t>
61 typedef std::list<htransition_t> set_of_transitions_t;
65 second_monoid_elt_t second_identity =
66 algebra::identity_as<second_monoid_elt_value_t>::
67 of(aut.structure().series().monoid().second_monoid());
71 const series_set_t& series = res.structure().series();
72 const monoid_t& monoid = series.monoid();
76 for_all_states(s, res)
79 bool other_out =
false;
85 for (delta_iterator e(res.value(), *s); ! e.done(); e.next())
86 transitions.push_back(*e);
87 for_all_const_(set_of_transitions_t, e, transitions)
89 const series_set_elt_t series = res.series_of(*e);
90 support_t supp = series.supp();
91 const monoid_elt_t supp_elt (monoid, *(supp.begin()));
93 if (supp_elt.value().second == second_identity.value())
97 if (eps_out and other_out)
104 if (eps_out and not diff)
110 hstate_t s2 = res.add_state();
111 if (res.is_initial(*s))
112 res.set_initial(s2, res.get_initial(*s));
114 set_of_transitions_t in_transitions;
115 for (rdelta_iterator e(res.value(), *s); ! e.done(); e.next())
116 in_transitions.push_back(*e);
118 for_all_(set_of_transitions_t, e, in_transitions)
119 res.add_series_transition(res.src_of(*e), s2, res.series_of(*e));
121 for_all_const_(set_of_transitions_t, e, transitions)
123 const series_set_elt_t series = res.series_of(*e);
124 support_t supp = series.supp();
125 const monoid_elt_t supp_elt (monoid, *(supp.begin()));
127 if (supp_elt.value().second == second_identity.value())
129 res.add_series_transition(s2, res.dst_of(*e), res.series_of(*e));
130 res.del_transition(*e);
144 template <
typename S,
typename M1,
typename M2,
typename Auto_t>
146 do_insplitting(
const AutomataBase<S>&,
147 const algebra::FreeMonoidProduct<M1, M2>&,
149 std::set<typename Auto_t::hstate_t>& m)
151 AUTOMATON_TYPES(Auto_t);
153 typedef typename series_set_elt_t::support_t support_t;
155 typedef typename monoid_t::first_monoid_t first_monoid_t;
157 typedef typename monoid_elt_value_t::first_type
158 first_monoid_elt_value_t;
159 typedef Element<first_monoid_t, first_monoid_elt_value_t>
162 typedef std::list<htransition_t> set_of_transitions_t;
166 first_monoid_elt_t first_identity =
167 algebra::identity_as<first_monoid_elt_value_t>::
168 of(aut.structure().series().monoid().first_monoid());
172 const series_set_t& series = res.structure().series();
173 const monoid_t& monoid = series.monoid();
177 for_all_states(s, res)
180 bool other_in =
false;
185 set_of_transitions_t transitions;
186 for (rdelta_iterator e(res.value(), *s); ! e.done(); e.next())
187 transitions.push_back(*e);
188 for_all_const_(set_of_transitions_t, e, transitions)
190 const series_set_elt_t series = res.series_of(*e);
191 support_t supp = series.supp();
192 const monoid_elt_t supp_elt (monoid, *(supp.begin()));
194 if (supp_elt.value().first == first_identity.value())
198 if (eps_in and other_in)
205 if (eps_in and not diff)
211 hstate_t s2 = res.add_state();
212 if (res.is_final(*s))
213 res.set_final(s2, res.get_final(*s));
215 set_of_transitions_t out_transitions;
216 for (delta_iterator e(res.value(), *s); ! e.done(); e.next())
217 out_transitions.push_back(*e);
219 for_all_(set_of_transitions_t, e, out_transitions)
220 res.add_series_transition(s2, res.dst_of(*e), res.series_of(*e));
222 for_all_const_(set_of_transitions_t, e, transitions)
224 const series_set_elt_t series = res.series_of(*e);
225 support_t supp = series.supp();
226 const monoid_elt_t supp_elt (monoid, *(supp.begin()));
228 if (supp_elt.value().first == first_identity.value())
230 res.add_series_transition(res.src_of(*e), s2,
232 res.del_transition(*e);
242 template <
typename S,
typename T>
244 outsplitting(
const Element<S, T>& aut,
245 std::set<typename T::hstate_t>& states)
247 return do_outsplitting(aut.structure(),
248 aut.structure().series().monoid(),
254 template <
typename S,
typename T>
256 insplitting(
const Element<S, T>& aut,
257 std::set<typename T::hstate_t>& states)
259 return do_insplitting(aut.structure(),
260 aut.structure().series().monoid(),
267 template <
typename S,
typename T>
269 outsplitting(
const Element<S, T>& aut)
271 std::set<typename T::hstate_t> states;
272 return do_outsplitting(aut.structure(),
273 aut.structure().series().monoid(),
279 template <
typename S,
typename T>
281 insplitting(
const Element<S, T>& aut)
283 std::set<typename T::hstate_t> states;
284 return do_insplitting(aut.structure(),
285 aut.structure().series().monoid(),
292 #endif // ! VCSN_ALGORITHMS_OUTSPLITTING_HXX