17 #ifndef VCSN_ALGORITHMS_PROJECTION_HXX
18 # define VCSN_ALGORITHMS_PROJECTION_HXX
26 template <
typename auto_t,
typename trans_t>
29 std::map<typename trans_t::hstate_t, typename auto_t::hstate_t>&
32 AUTOMATON_TYPES_(trans_t, trans_);
33 AUTOMATON_TYPES(auto_t);
35 typedef typename trans_series_set_elt_t::support_t trans_support_t;
37 const series_set_t& series = res.structure().series();
38 const monoid_t& monoid = res.structure().series().monoid();
40 for_all_const_states(fmp_s, fmp_trans)
42 hstate_t s = res.add_state();
45 if (fmp_trans.is_initial(*fmp_s))
47 trans_series_set_elt_t in = fmp_trans.get_initial(*fmp_s);
48 trans_support_t supp = in.supp();
50 semiring_elt_t in_semi_elt = in.get(*(supp.begin()));
51 series_set_elt_t series_elt(series);
53 series_elt.assoc(monoid_elt_t(monoid,
58 res.set_initial(s, series_elt);
61 if (fmp_trans.is_final(*fmp_s))
63 trans_series_set_elt_t out = fmp_trans.get_final(*fmp_s);
64 trans_support_t supp = out.supp();
66 semiring_elt_t out_semi_elt = out.get(*(supp.begin()));
67 series_set_elt_t series_elt(series);
69 series_elt.assoc(monoid_elt_t(monoid,
74 res.set_final(s, series_elt);
83 template <
typename S1,
typename S2,
typename M1,
typename M2,
84 typename auto_t,
typename trans_t>
86 do_identity(
const AutomataBase<S1>&,
87 const algebra::FreeMonoidBase<M1>&,
88 const AutomataBase<S2>&,
89 const algebra::FreeMonoidProduct<M1,M2>&,
90 const auto_t& aut, trans_t& res)
92 BENCH_TASK_SCOPED(
"identity");
93 AUTOMATON_TYPES_(auto_t, aut_);
94 AUTOMATON_TYPES(trans_t);
96 std::map<hstate_t, aut_hstate_t> stmap;
97 typedef typename aut_series_set_elt_t::support_t aut_support_t;
99 const series_set_t& series = res.structure().series();
100 const monoid_t& monoid = res.structure().series().monoid();
101 const aut_monoid_t& aut_monoid = aut.structure().series().monoid();
105 for_all_const_transitions_(aut_, aut_e, aut)
107 const aut_series_set_elt_t aut_series_elt = aut.series_of(*aut_e);
111 aut_support_t aut_supp = aut_series_elt.supp();
112 for_all_const_(aut_support_t, label, aut_supp)
114 const aut_monoid_elt_t aut_monoid_elt(aut_monoid, *label);
115 const monoid_elt_value_t word(aut_monoid_elt.value(),
116 aut_monoid_elt.value());
118 series_set_elt_t series_elt(series);
119 series_elt.assoc(monoid_elt_t(monoid, word),
120 aut_series_elt.get(aut_monoid_elt));
122 res.add_series_transition(stmap[aut.src_of(*aut_e)],
123 stmap[aut.dst_of(*aut_e)], series_elt);
128 template <
typename S,
typename S2,
typename T,
typename T2>
140 template <
typename S1,
typename S2,
typename M1,
typename M2,
141 typename auto_t,
typename trans_t>
143 do_partial_erase(
const AutomataBase<S1>&,
144 const algebra::FreeMonoidBase<M1>&,
145 const AutomataBase<S2>&,
146 const algebra::FreeMonoidProduct<M1,M2>&,
147 const auto_t& aut, trans_t& res)
149 BENCH_TASK_SCOPED(
"partial erase");
150 AUTOMATON_TYPES_(auto_t, aut_);
151 AUTOMATON_TYPES(trans_t);
153 std::map<hstate_t, aut_hstate_t> stmap;
154 typedef typename aut_series_set_elt_t::support_t aut_support_t;
156 const series_set_t& series = res.structure().series();
157 const monoid_t& monoid = res.structure().series().monoid();
158 const aut_monoid_t& aut_monoid = aut.structure().series().monoid();
159 aut_monoid_elt_value_t empty_word =
160 algebra::identity_as<aut_monoid_elt_value_t>::of(aut_monoid).value();
164 for_all_const_transitions_(aut_, aut_e, aut)
166 const aut_series_set_elt_t aut_series_elt = aut.series_of(*aut_e);
170 aut_support_t aut_supp = aut_series_elt.supp();
171 for_all_const_(aut_support_t, label, aut_supp)
173 const aut_monoid_elt_t aut_monoid_elt(aut_monoid, *label);
174 const monoid_elt_value_t word(aut_monoid_elt.value(),
177 series_set_elt_t series_elt(series);
178 series_elt.assoc(monoid_elt_t(monoid, word),
179 aut_series_elt.get(aut_monoid_elt));
181 res.add_series_transition(stmap[aut.src_of(*aut_e)],
182 stmap[aut.dst_of(*aut_e)], series_elt);
187 template <
typename S,
typename S2,
typename T,
typename T2>
197 #endif // ! VCSN_ALGORITHMS_PROJECTION_HXX