17 #ifndef VCSN_ALGORITHMS_PAIR_TO_FMP_HXX
18 # define VCSN_ALGORITHMS_PAIR_TO_FMP_HXX
25 # define MUTE_TRAITS mute_pair_to_fmp<S, T>
27 template <
typename S,
typename T>
28 inline typename MUTE_TRAITS::ret
30 make_automaton(
const typename MUTE_TRAITS::ret_first_alphabet_t& A,
31 const typename MUTE_TRAITS::ret_second_alphabet_t& B)
35 second_monoid_t sM(B);
36 ret_monoid_t freemonoidproduct(fM, sM);
37 typename ret::series_set_t series(semiring, freemonoidproduct);
39 return ret(Automata<typename ret::series_set_t, typename ret::kind_t>(series));
42 template <
typename S,
typename T>
43 inline typename MUTE_TRAITS::ret
45 make_automaton(
const Element<S, T>& aut)
47 ret_first_alphabet_t fA = alphabet_traits_t::first_projection(aut.
48 series().monoid().alphabet());
49 ret_second_alphabet_t sA = alphabet_traits_t::second_projection(aut.
50 series().monoid().alphabet());
52 return make_automaton(fA, sA);
55 template <
typename S,
typename T>
56 inline typename MUTE_TRAITS::ret::series_set_elt_t
58 series_convert(
const typename MUTE_TRAITS::ret_series_set_t& series,
59 const typename MUTE_TRAITS::automaton_t::
62 typedef typename MUTE_TRAITS::automaton_t::series_set_elt_t
65 typename ret::series_set_elt_t R(series);
67 for_all_const_(series_set_elt_t::support_t, it, ss.supp())
69 R.assoc(std::make_pair(word_traits_t::first_projection(*it),
70 word_traits_t::second_projection(*it)),
77 template <
typename S,
typename T>
79 do_pair_to_fmp(
const Element<S, T>& src,
80 typename MUTE_TRAITS::ret& res)
82 BENCH_TASK_SCOPED(
"pair_to_fmp");
85 typedef typename MUTE_TRAITS::automaton_t automaton_t;
86 typedef MUTE_TRAITS fmp_traits_t;
87 typedef typename fmp_traits_t::ret res_t;
88 AUTOMATON_TYPES(automaton_t);
89 AUTOMATON_TYPES_(res_t, res_);
92 std::map<hstate_t, res_hstate_t> m;
94 for_all_const_states(p, src)
95 m[*p] = res.add_state();
98 for_all_const_initial_states(i, src)
100 res.set_initial(m[*i],
102 series_convert(res.structure().series(),
103 src.get_initial(*i)));
107 for_all_const_transitions(e, src)
109 res.add_series_transition(m[src.src_of(*e)],
112 series_convert(res.structure().series(),
117 for_all_const_final_states(f, src)
121 series_convert(res.structure().series(),
130 template <
typename S,
typename T>
132 pair_to_fmp(
const Element<S, T>& aut,
133 typename MUTE_TRAITS::ret& res)
135 do_pair_to_fmp(aut, res);
138 template <
typename S,
typename T>
139 typename MUTE_TRAITS::ret
140 pair_to_fmp(
const Element<S, T>& aut)
142 typename MUTE_TRAITS::ret res = MUTE_TRAITS::make_automaton(aut);
144 do_pair_to_fmp(aut, res);
153 #endif // ! VCSN_ALGORITHMS_PAIR_TO_FMP_HXX