00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef VCSN_ALGORITHMS_DOMAIN_HXX
00018 # define VCSN_ALGORITHMS_DOMAIN_HXX
00019
00020 # include <vaucanson/algorithms/domain.hh>
00021
00022 namespace vcsn
00023 {
00024
00025
00026
00027
00028
00029 template <typename src_t, typename dst_t>
00030 void
00031 do_fmp_domain(const src_t& src, dst_t& dst)
00032 {
00033 BENCH_TASK_SCOPED("fmp_domain");
00034 AUTOMATON_TYPES_(src_t, trans_);
00035 AUTOMATON_TYPES(dst_t);
00036
00037 typedef typename trans_series_set_elt_t::support_t trans_support_t;
00038 std::map<trans_hstate_t, hstate_t> stmap;
00039
00040 const series_set_t& series = dst.structure().series();
00041 const monoid_t& monoid = dst.structure().series().monoid();
00042 const trans_monoid_t& trans_monoid =
00043 src.structure().series().monoid();
00044
00045 set_states(src, dst, stmap);
00046
00047 for_all_const_transitions_(trans_, fmp_e, src)
00048 {
00049 const trans_series_set_elt_t trans_series_elt =
00050 src.series_of(*fmp_e);
00051 trans_support_t trans_supp = trans_series_elt.supp();
00052 const trans_monoid_elt_t trans_monoid_elt
00053 (trans_monoid, *(trans_supp.begin()));
00054 const monoid_elt_value_t word(trans_monoid_elt.value().first);
00055
00056 series_set_elt_t series_elt(series);
00057
00058 series_elt.assoc(monoid_elt_t(monoid, word),
00059 trans_series_elt.get(trans_monoid_elt));
00060
00061 dst.add_series_transition(stmap[src.src_of(*fmp_e)],
00062 stmap[src.dst_of(*fmp_e)], series_elt);
00063 }
00064 }
00065
00066
00067
00068
00069
00070
00071
00072
00073 template <typename src_t, typename dst_t>
00074 void
00075 do_rw_domain(const src_t& src, dst_t& dst)
00076 {
00077 BENCH_TASK_SCOPED("rw_domain");
00078 std::map<typename src_t::hstate_t, typename dst_t::hstate_t> m;
00079 AUTOMATON_TYPES(src_t);
00080
00081 for_all_const_states(p, src)
00082 {
00083 m[*p] = dst.add_state();
00084 }
00085
00086 for_all_const_initial_states(p, src)
00087 dst.set_initial(m[*p]);
00088
00089 for_all_const_final_states(p, src)
00090 dst.set_final(m[*p]);
00091
00092 for_all_const_transitions(e, src)
00093 {
00094 dst.add_series_transition(m[src.src_of(*e)],
00095 m[src.dst_of(*e)],
00096 src.input_of(*e));
00097 }
00098 }
00099
00100
00101
00102
00103
00104
00105
00106
00107 template <typename S, typename S2, typename T, typename T2>
00108 void
00109 domain_dispatch(const AutomataBase<S>&, const Element<S,T>& src, Element<S2, T2>& dst)
00110 {
00111 do_fmp_domain(src, dst);
00112 }
00113
00114 template <typename S, typename S2, typename T, typename T2>
00115 void
00116 domain_dispatch(const TransducerBase<S>&, const Element<S,T>& src, Element<S2, T2>& dst)
00117 {
00118 do_rw_domain(src, dst);
00119 }
00120
00121 template <typename S, typename S2, typename T, typename T2>
00122 void
00123 domain(const Element<S,T>& src, Element<S2, T2>& dst)
00124 {
00125 domain_dispatch(src.structure(), src, dst);
00126 }
00127
00128 }
00129
00130 #endif // ! VCSN_ALGORITHMS_DOMAIN_HXX