18 #ifndef VCSN_ALGORITHMS_STANDARD_OF_HXX
19 # define VCSN_ALGORITHMS_STANDARD_OF_HXX
23 # include <vaucanson/algebra/implementation/series/krat_exp_pattern.hh>
26 # include <vaucanson/misc/usual_macros.hh>
38 class Standard_OfVisitor :
39 public algebra::KRatExpMatcher<
40 Standard_OfVisitor<Exp_, Auto_, Dispatch_>,
47 typedef Auto_* automaton_ptr_t;
48 typedef Auto_ automaton_t;
49 typedef typename automaton_t::set_t automata_set_t;
51 typedef typename automaton_t::series_set_t series_set_t;
52 typedef typename automaton_t::monoid_t monoid_t;
53 typedef typename automaton_t::semiring_t semiring_t;
55 typedef typename automaton_t::series_set_elt_t series_set_elt_t;
56 typedef typename automaton_t::monoid_elt_t monoid_elt_t;
57 typedef typename automaton_t::semiring_elt_t semiring_elt_t;
59 typedef typename automaton_t::hstate_t hstate_t;
60 typedef typename automaton_t::htransition_t htransition_t;
62 typedef typename Exp_::monoid_elt_value_t monoid_elt_value_t;
63 typedef typename Exp_::semiring_elt_value_t semiring_elt_value_t;
65 typedef Standard_OfVisitor<Exp_, Auto_, Dispatch_> this_class;
66 typedef algebra::KRatExpMatcher<this_class, Exp_, Auto_*, Dispatch_>
68 typedef typename parent_class::return_type return_type;
72 Standard_OfVisitor(automaton_t& a) :
73 automata_set_(a.series()),
78 INHERIT_CONSTRUCTORS(this_class, Exp_, Auto_*, Dispatch_);
82 MATCH__(Product, lhs, rhs)
84 AUTOMATON_TYPES(automaton_t);
87 hstate_t lhs_i = initial_;
90 typedef typename std::list<std::pair<hstate_t, series_set_elt_t> >
93 list_fin_st_t lhs_tmp;
95 for_all_final_states(f, *auto_)
96 lhs_tmp.push_back (std::pair<hstate_t, series_set_elt_t>
97 (*f, auto_->get_final(*f)));
103 typedef std::list<hstate_t> list_st_t;
105 list_st_t lhs_finals;
107 for (typename list_fin_st_t::iterator i = lhs_tmp.begin();
111 auto_->set_final(i->first, i->second);
112 lhs_finals.push_back (i->first);
115 concat_of_standard_inside(auto_->structure(),
116 *auto_, lhs_finals, initial_);
123 MATCH__(Sum, lhs, rhs)
125 AUTOMATON_TYPES(automaton_t);
126 typedef typename std::list<std::pair<hstate_t, series_set_elt_t> >
132 hstate_t left_i = initial_;
135 list_fin_st_t lhs_tmp;
137 for_all_const_final_states(f, *auto_)
138 lhs_tmp.push_back (std::pair<hstate_t, series_set_elt_t>
139 (*f, auto_->get_final(*f)));
141 auto_->clear_final();
146 for (typename list_fin_st_t::iterator i = lhs_tmp.begin();
149 auto_->set_final(i->first, i->second);
151 sum_of_standard_inside(auto_->structure(),
152 *auto_, left_i, initial_);
161 AUTOMATON_TYPES(automaton_t);
164 precondition(auto_->get_final(initial_).starable());
166 typedef typename std::list<hstate_t> list_fin_st_t;
171 for_all_final_states(f, *auto_)
175 star_of_standard_inside(auto_->structure(),
176 *auto_, initial_, tmp);
181 MATCH__(LeftWeight, w, node)
183 const semiring_t& semiring = automata_set_.series().semiring();
184 const semiring_elt_t weight (semiring, w);
185 const series_set_elt_t ws(auto_->series(), weight);
188 left_ext_mult_of_standard_inside(auto_->structure(),
189 *auto_, initial_, ws);
194 MATCH__(RightWeight, node, w)
196 const semiring_t& semiring = automata_set_.series().semiring();
197 const semiring_elt_t weight (semiring, w);
200 for (
typename automaton_t::final_iterator
201 f, next = auto_->final().begin();
202 next != auto_->final().end();)
211 auto_->set_final(*f, auto_->get_final(*f) * weight);
220 initial_ = auto_->add_state();
221 hstate_t last = initial_;
222 hstate_t new_f = initial_;
224 for (
typename monoid_elt_value_t::const_iterator i = m.begin();
227 new_f = auto_->add_state();
228 auto_->add_letter_transition(last, new_f, *i);
231 auto_->set_initial(initial_);
232 auto_->set_final(new_f);
240 initial_ = auto_->add_state();
241 auto_->set_initial(initial_);
248 initial_ = auto_->add_state();
249 auto_->set_initial(initial_);
250 auto_->set_final(initial_);
256 automata_set_t automata_set_;
259 automaton_ptr_t auto_;
265 inline hstate_t operator[] (hstate_t a)
276 template <
typename A,
280 do_standard_of(
const AutomataBase<A>&,
284 algebra::Standard_OfVisitor<Exp, Output, algebra::DispatchFunction<Exp> >
297 do_standard_of(out.
structure(), out, kexp);
302 #endif // ! VCSN_ALGORITHMS_STANDARD_OF_HXX