00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef VCSN_ALGORITHMS_FMP_TO_REALTIME_HXX
00018 # define VCSN_ALGORITHMS_FMP_TO_REALTIME_HXX
00019
00020 # include <vaucanson/automata/concept/automata.hh>
00021 # include <vaucanson/automata/concept/transducer.hh>
00022 # include <vaucanson/algebra/concept/freemonoid_product.hh>
00023
00024 # include <map>
00025
00026 namespace vcsn
00027 {
00028
00029 template<typename S, typename T,
00030 typename SS, typename TT,
00031 typename Self>
00032 void
00033 do_fmp_to_realtime(const vcsn::AutomataBase<S>&,
00034 const vcsn::TransducerBase<SS>&,
00035 const vcsn::algebra::FreeMonoidProductBase<Self>&,
00036 const vcsn::Element<S, T>& fmp,
00037 vcsn::Element<SS, TT>& res)
00038 {
00039
00040 std::map<vcsn::hstate_t, vcsn::hstate_t> m;
00041
00042
00043 typedef vcsn::Element<S, T> FMP_t;
00044
00045
00046 typedef vcsn::Element<SS, TT> Trans_t;
00047
00048
00049
00050
00051
00052
00053 for (typename FMP_t::state_iterator St = fmp.states().begin();
00054 St != fmp.states().end();
00055 ++St)
00056 m[*St] = res.add_state();
00057
00058
00059
00060
00061
00062
00063 for (typename FMP_t::initial_iterator St, next = fmp.initial().begin();
00064 next != fmp.initial().end();)
00065 {
00066
00067
00068
00069
00070 St = next;
00071 next++;
00072
00073 typename Trans_t::series_set_elt_t s(res.structure().series());
00074
00075 typename FMP_t::series_set_elt_t s_elt = fmp.get_initial(*St);
00076 for_all_const_(FMP_t::series_set_elt_t::support_t, i, s_elt.supp())
00077 {
00078 typename Trans_t::semiring_elt_value_t::monoid_elt_value_t
00079 output_monoid_value;
00080 typename Trans_t::semiring_elt_t::semiring_elt_t weight;
00081
00082 typename Trans_t::monoid_elt_value_t
00083 input_monoid_value = (*i).first;
00084 typename Trans_t::monoid_elt_t
00085 input_monoid(res.structure().series().monoid(),
00086 input_monoid_value);
00087
00088 typename Trans_t::semiring_elt_t::monoid_elt_t
00089 output_monoid(res.structure().series().semiring().monoid(),
00090 (*i).second);
00091 weight = s_elt.get(*i);
00092
00093
00094 typename Trans_t::semiring_elt_t
00095 out_mult(res.structure().series().semiring());
00096 out_mult.assoc(output_monoid, weight);
00097
00098
00099 s.assoc(input_monoid, out_mult);
00100 }
00101 res.set_initial(m[*St], s);
00102 }
00103
00104
00105
00106
00107
00108
00109 for (typename FMP_t::final_iterator St, next = fmp.final().begin();
00110 next != fmp.final().end();)
00111 {
00112
00113
00114
00115
00116 St = next;
00117 next++;
00118
00119 typename Trans_t::series_set_elt_t s(res.structure().series());
00120
00121 typename FMP_t::series_set_elt_t s_elt = fmp.get_final(*St);
00122 for_all_const_(FMP_t::series_set_elt_t::support_t, i, s_elt.supp())
00123 {
00124 typename Trans_t::semiring_elt_value_t::monoid_elt_value_t
00125 output_monoid_value;
00126 typename Trans_t::semiring_elt_t::semiring_elt_t weight;
00127
00128 typename Trans_t::monoid_elt_value_t input_monoid_value =
00129 (*i).first;
00130 typename Trans_t::monoid_elt_t
00131 input_monoid(res.structure().series().monoid(),
00132 input_monoid_value);
00133 typename Trans_t::semiring_elt_t::monoid_elt_t
00134 output_monoid(res.structure().series().semiring().monoid(),
00135 (*i).second);
00136 weight = s_elt.get(*i);
00137
00138
00139 typename Trans_t::semiring_elt_t
00140 out_mult(res.structure().series().semiring());
00141 out_mult.assoc(output_monoid, weight);
00142
00143
00144 s.assoc(input_monoid, out_mult);
00145 }
00146 res.set_final(m[*St], s);
00147 }
00148
00149
00150
00151
00152
00153
00154 for (typename FMP_t::transition_iterator Ed = fmp.transitions().begin();
00155 Ed != fmp.transitions().end();
00156 ++Ed)
00157 {
00158
00159
00160 typename Trans_t::series_set_elt_t
00161 transition_value(res.structure().series());
00162
00163 typename Trans_t::monoid_elt_value_t input_monoid_value;
00164 typename Trans_t::semiring_elt_value_t::monoid_elt_value_t
00165 output_monoid_value;
00166
00167 typename FMP_t::series_set_elt_t series_fmp(fmp.structure().series());
00168 typename Trans_t::semiring_elt_t
00169 out_mult(res.structure().series().semiring());
00170 series_fmp = fmp.series_of(*Ed);
00171
00172 for_all_const_(FMP_t::series_set_elt_t::support_t,
00173 i,
00174 series_fmp.supp())
00175 {
00176 input_monoid_value = (*i).first;
00177 output_monoid_value = (*i).second;
00178
00179
00180 typename Trans_t::semiring_elt_t::semiring_elt_t
00181 transition_weight(res.structure().series().semiring().semiring(),
00182 series_fmp.get(*i));
00183 typename Trans_t::semiring_elt_t
00184 out_mult(res.structure().series().semiring());
00185 out_mult.assoc(typename Trans_t::semiring_elt_t::monoid_elt_t
00186 (res.structure().series().semiring().monoid(),
00187 output_monoid_value),
00188 transition_weight);
00189
00190
00191 typename Trans_t::monoid_elt_t
00192 input(res.structure().series().monoid(),
00193 input_monoid_value);
00194 transition_value.assoc(input, out_mult);
00195 res.add_series_transition(m[fmp.src_of(*Ed)],
00196 m[fmp.dst_of(*Ed)],
00197 transition_value);
00198 }
00199 }
00200 }
00201
00202 template<typename S, typename T,
00203 typename SS, typename TT>
00204 vcsn::Element<SS, TT>&
00205 fmp_to_realtime(const vcsn::Element<S, T>& fmp,
00206 vcsn::Element<SS, TT>& res)
00207 {
00208 TIMER_SCOPED("fmp_to_realtime");
00209 do_fmp_to_realtime(fmp.structure(), res.structure(),
00210 fmp.structure().series().monoid(),
00211 fmp, res);
00212 return res;
00213 }
00214 }
00215 #endif // ! VCSN_ALGORITHMS_FMP_TO_REALTIME_HXX