17 #ifndef VCSN_ALGORITHMS_ONE_EPS_CLOSURE_HXX
18 # define VCSN_ALGORITHMS_ONE_EPS_CLOSURE_HXX
22 # include <vaucanson/automata/concept/automata_base.hh>
23 # include <vaucanson/misc/usual_macros.hh>
29 template<
typename A,
typename AI,
typename S,
typename V>
31 workaround_add_series_transition(
const AutomataBase<A>& a_set,
33 S& src, S& dst, V& val)
35 typedef Element<A, AI> automaton_t;
36 AUTOMATON_TYPES(automaton_t)
42 for (delta_iterator j(a.value(), src); !j.done(); j.next())
44 if (a.dst_of(*j) != dst)
50 val += a.series_of(*j);
55 if (val != a.series().zero_)
56 a.add_series_transition(src, dst, val);
64 template<
class A,
typename AI,
typename EPS>
66 do_backward_one_eps_closure(
const AutomataBase<A>& a_set,
70 typedef Element<A, AI> automaton_t;
71 AUTOMATON_TYPES(automaton_t)
73 hstate_t source = eps.src();
74 hstate_t dest = eps.dst();
76 precondition(source != dest);
82 std::list<htransition_t> transition_list;
83 for (delta_iterator it(a.value(), dest); !it.done(); it.next())
84 transition_list.push_back(*it);
87 for(typename std::list<htransition_t>::iterator it =
88 transition_list.begin(); it != transition_list.end(); ++it)
90 series_set_elt_t series = eps.weight() * a.series_of(*it);
92 if (series == a.series().zero_)
95 hstate_t target = a.dst_of(*it);
97 workaround_add_series_transition(a.structure(), a,
98 source, target, series);
103 series_set_elt_t fin_weight =
104 a.get_final(source) + eps.weight() * a.get_final(dest);
106 a.set_final(source, fin_weight);
109 template<
class A,
typename AI,
typename EPS>
111 do_forward_one_eps_closure(
const AutomataBase<A>& a_set,
115 typedef Element<A, AI> automaton_t;
116 AUTOMATON_TYPES(automaton_t);
118 hstate_t source = eps.src();
119 hstate_t dest = eps.dst();
121 precondition(source != dest);
127 std::list<htransition_t> transition_list;
128 for (rdelta_iterator it(a.value(), source); ! it.done(); it.next())
129 transition_list.push_back(*it);
132 for(
typename std::list<htransition_t>::iterator it =
133 transition_list.begin(); it != transition_list.end(); ++it)
135 series_set_elt_t series = a.series_of(*it) * eps.weight();
137 if (series == a.series().zero_)
140 hstate_t target = a.dst_of(*it);
142 workaround_add_series_transition(a.structure(), a,
143 source, target, series);
147 series_set_elt_t ini_weight =
148 a.get_initial(source) * eps.weight() + a.get_initial(dest);
149 a.set_initial(dest, ini_weight);
152 template<
typename A,
typename AI,
typename EPS>
157 AUTOMATON_TYPES(automaton_t);
158 do_backward_one_eps_closure(a.
structure(), a, eps);
161 template<
typename A,
typename AI,
typename EPS>
166 AUTOMATON_TYPES(automaton_t);
167 do_forward_one_eps_closure(a.
structure(), a, eps);
170 template<
typename A,
typename AI,
typename EPS>
175 AUTOMATON_TYPES(automaton_t);
177 case misc::backward :
178 do_backward_one_eps_closure(a.
structure(), a, eps);
181 do_forward_one_eps_closure(a.
structure(), a, eps);
188 #endif // ! VCSN_ALGORITHMS_ONE_EPS_CLOSURE_HXX