17 #ifndef VCSN_ALGORITHMS_RW_TO_FMP_HXX
18 # define VCSN_ALGORITHMS_RW_TO_FMP_HXX
20 # include <vaucanson/algebra/concept/freemonoid_product.hh>
21 # include <vaucanson/automata/concept/transducer.hh>
22 # include <vaucanson/automata/concept/automata.hh>
27 template<
typename S,
typename T,
28 typename SS,
typename TT,
37 typedef typename T::hstate_t hstate_t;
39 std::map<hstate_t, hstate_t> m;
47 typename FMP_t::monoid_t fmp(trans.
structure().series().monoid(),
49 typename FMP_t::semiring_t sg;
50 typename FMP_t::series_set_t ss(sg, fmp);
52 typedef vcsn::Element<
typename FMP_t::monoid_t::first_monoid_t,
53 typename FMP_t::monoid_elt_value_t::first_type>
55 typedef vcsn::Element<
typename FMP_t::monoid_t::second_monoid_t,
56 typename FMP_t::monoid_elt_value_t::second_type>
59 typename Trans_t::series_set_elt_value_t>
68 for (
typename Trans_t::state_iterator St = trans.states().begin();
69 St != trans.states().end();
71 m[*St] = res.add_state();
73 typename Trans_t::series_set_elt_t id_series(trans.
structure().series());
74 id_series = vcsn::algebra::
75 identity_as<typename Trans_t::series_set_elt_value_t>::
83 for (
typename Trans_t::initial_iterator St, next = trans.initial().begin();
84 next != trans.initial().end();)
93 typename FMP_t::series_set_elt_t s(ss);
94 typename FMP_t::monoid_elt_t mon(res.
structure().series().monoid());
96 first(res.
structure().series().monoid().first_monoid());
98 second(res.
structure().series().monoid().second_monoid());
99 typename FMP_t::semiring_elt_t
100 weight(res.
structure().series().semiring());
102 mult_elt_t mult = trans.get_initial(*St);
103 if (mult != id_series)
105 hstate_t tmp = res.add_state();
106 typename mult_elt_t::support_t mult_supp = mult.supp();
107 for_all_const_(mult_elt_t::support_t, i, mult_supp)
111 typename Trans_t::semiring_elt_t
112 output(trans.
structure().series().semiring(), mult.get(*i));
113 typename Trans_t::semiring_elt_t::support_t
114 output_supp = output.supp();
115 for_all_const_(Trans_t::semiring_elt_t::support_t,
120 weight = output.get(*j);
121 mon =
typename FMP_t::monoid_elt_value_t(first.value(),
123 s.assoc(mon, weight);
126 res.add_series_transition(tmp, m[*St], s);
127 res.set_initial(tmp);
130 res.set_initial(m[*St]);
138 for (
typename Trans_t::final_iterator St, next = trans.final().begin();
139 next != trans.final().end();)
148 typename FMP_t::series_set_elt_t s(ss);
149 typename FMP_t::monoid_elt_t mon(res.
structure().series().monoid());
151 first(res.
structure().series().monoid().first_monoid());
153 second(res.
structure().series().monoid().second_monoid());
154 typename FMP_t::semiring_elt_t
155 weight(res.
structure().series().semiring());
157 mult_elt_t mult = trans.get_final(*St);
158 if (mult != id_series)
160 hstate_t tmp = res.add_state();
162 typename mult_elt_t::support_t mult_supp = mult.supp();
163 for_all_const_(mult_elt_t::support_t, i, mult_supp)
167 typename Trans_t::semiring_elt_t
168 output(trans.
structure().series().semiring(), mult.get(*i));
169 typename Trans_t::semiring_elt_t::support_t
170 output_supp = output.supp();
171 for_all_const_(Trans_t::semiring_elt_t::support_t,
176 weight = output.get(*j);
177 mon =
typename FMP_t::monoid_elt_value_t(first.value(),
179 s.assoc(mon, weight);
182 res.add_series_transition(m[*St], tmp, s);
186 res.set_final(m[*St]);
194 for (
typename Trans_t::transition_iterator Ed = trans.transitions().begin();
195 Ed != trans.transitions().end();
198 typename FMP_t::series_set_elt_t s(ss);
200 first_monoid_elt_t first(trans.
structure().series().monoid());
202 second(trans.
structure().series().semiring().monoid());
203 typename FMP_t::monoid_elt_t
206 typename Trans_t::series_set_elt_t
208 series_elt = trans.series_of(*Ed);
210 for (
typename Trans_t::series_set_elt_t::support_t::const_iterator
211 i = series_elt.supp().begin();
212 i != series_elt.supp().end();
217 typename Trans_t::semiring_elt_t
218 mult(trans.
structure().series().semiring());
219 mult = series_elt.get(first);
224 typename Trans_t::semiring_elt_t::support_t
225 mult_supp = mult.supp();
226 for (
typename Trans_t::semiring_elt_t::support_t::const_iterator
227 j = mult_supp.begin();
228 j != mult_supp.end();
233 mon =
typename FMP_t::monoid_elt_value_t(first.value(),
235 s.assoc(mon, trans.output_of(*Ed).get(second));
238 res.add_series_transition(m[trans.src_of(*Ed)],
239 m[trans.dst_of(*Ed)],
244 template<
typename S,
typename T,
245 typename SS,
typename TT>
256 #endif // ! VCSN_ALGORITHMS_RW_TO_FMP_HXX