17 #ifndef VCSN_ALGORITHMS_FMP_TO_RW_HXX
18 # define VCSN_ALGORITHMS_FMP_TO_RW_HXX
20 # include <vaucanson/automata/concept/automata.hh>
21 # include <vaucanson/automata/concept/transducer.hh>
22 # include <vaucanson/algebra/concept/freemonoid_product.hh>
29 template<
typename S,
typename T,
30 typename SS,
typename TT,
39 typedef typename T::hstate_t hstate_t;
41 std::map<hstate_t, hstate_t> m;
54 for (
typename FMP_t::state_iterator St = fmp.states().begin();
55 St != fmp.states().end();
57 m[*St] = res.add_state();
64 for (
typename FMP_t::initial_iterator St, next = fmp.initial().begin();
65 next != fmp.initial().end();)
74 typename Trans_t::series_set_elt_t s(res.
structure().series());
76 typename FMP_t::series_set_elt_t s_elt = fmp.get_initial(*St);
77 for_all_const_(FMP_t::series_set_elt_t::support_t, i, s_elt.supp())
79 typename Trans_t::semiring_elt_value_t::monoid_elt_value_t
81 typename Trans_t::semiring_elt_t::semiring_elt_t weight;
83 typename Trans_t::monoid_elt_value_t
84 input_monoid_value = (*i).first;
85 typename Trans_t::monoid_elt_t
86 input_monoid(res.
structure().series().monoid(),
89 typename Trans_t::semiring_elt_t::monoid_elt_t
90 output_monoid(res.
structure().series().semiring().monoid(),
92 weight = s_elt.get(*i);
95 typename Trans_t::semiring_elt_t
96 out_mult(res.
structure().series().semiring());
97 out_mult.assoc(output_monoid, weight);
100 s.assoc(input_monoid, out_mult);
102 res.set_initial(m[*St], s);
110 for (
typename FMP_t::final_iterator St, next = fmp.final().begin();
111 next != fmp.final().end();)
120 typename Trans_t::series_set_elt_t s(res.
structure().series());
122 typename FMP_t::series_set_elt_t s_elt = fmp.get_final(*St);
123 for_all_const_(FMP_t::series_set_elt_t::support_t, i, s_elt.supp())
125 typename Trans_t::semiring_elt_value_t::monoid_elt_value_t
127 typename Trans_t::semiring_elt_t::semiring_elt_t weight;
129 typename Trans_t::monoid_elt_value_t input_monoid_value =
131 typename Trans_t::monoid_elt_t
132 input_monoid(res.
structure().series().monoid(),
134 typename Trans_t::semiring_elt_t::monoid_elt_t
135 output_monoid(res.
structure().series().semiring().monoid(),
137 weight = s_elt.get(*i);
140 typename Trans_t::semiring_elt_t
141 out_mult(res.
structure().series().semiring());
142 out_mult.assoc(output_monoid, weight);
145 s.assoc(input_monoid, out_mult);
147 res.set_final(m[*St], s);
155 for (
typename FMP_t::transition_iterator Ed = fmp.transitions().begin();
156 Ed != fmp.transitions().end();
161 typename Trans_t::series_set_elt_t
162 transition_value(res.
structure().series());
164 typename Trans_t::monoid_elt_value_t input_monoid_value;
165 typename Trans_t::semiring_elt_value_t::monoid_elt_value_t
168 typename FMP_t::series_set_elt_t series_fmp(fmp.
structure().series());
169 typename Trans_t::semiring_elt_t
170 out_mult(res.
structure().series().semiring());
171 series_fmp = fmp.series_of(*Ed);
173 for_all_const_(FMP_t::series_set_elt_t::support_t,
177 input_monoid_value = (*i).first;
178 output_monoid_value = (*i).second;
181 typename Trans_t::semiring_elt_t::semiring_elt_t
182 transition_weight(res.
structure().series().semiring().semiring(),
184 typename Trans_t::semiring_elt_t
185 out_mult(res.
structure().series().semiring());
186 out_mult.assoc(
typename Trans_t::semiring_elt_t::monoid_elt_t
187 (res.
structure().series().semiring().monoid(),
188 output_monoid_value),
192 typename Trans_t::monoid_elt_t
195 transition_value.assoc(input, out_mult);
196 res.add_series_transition(m[fmp.src_of(*Ed)],
203 template<
typename S,
typename T,
204 typename SS,
typename TT>
209 BENCH_TASK_SCOPED(
"fmp_to_rw");
216 #endif // ! VCSN_ALGORITHMS_FMP_TO_RW_HXX