00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <vaucanson/algorithms/minimization_hopcroft.hh>
00025 #include <vaucanson/algorithms/evaluation_fmp.hh>
00026 #include <vaucanson/algorithms/aut_to_exp.hh>
00027 #include <vaucanson/algorithms/trim.hh>
00028 #include <vaucanson/algorithms/realtime.hh>
00029
00030 namespace vcsn
00031 {
00032 namespace VCSN_GRAPH_IMPL
00033 {
00034 VCSN_CONTEXT_NAMESPACE
00035 {
00036
00037 template <class FirstInputIterator, class SecondInputIterator>
00038 automata_set_t make_automata_set(const FirstInputIterator first_begin,
00039 const FirstInputIterator first_end,
00040 const SecondInputIterator second_begin,
00041 const SecondInputIterator second_end,
00042 const monoid_rep_t& mrep =
00043 *(vcsn::algebra::monoid_rep_default<monoid_t>::get_instance()),
00044 const first_monoid_rep_t& mrep1 =
00045 *(vcsn::algebra::monoid_rep_default<first_monoid_t>::get_instance()),
00046 const second_monoid_rep_t& mrep2 =
00047 *(vcsn::algebra::monoid_rep_default<second_monoid_t>::get_instance()),
00048 const series_rep_t& srep =
00049 *(vcsn::algebra::series_rep_default<semiring_t, monoid_t>::get_instance()),
00050 const first_series_rep_t& srep1 =
00051 *(vcsn::algebra::series_rep_default<semiring_t, first_monoid_t>::get_instance()),
00052 const second_series_rep_t& srep2 =
00053 *(vcsn::algebra::series_rep_default<semiring_t, second_monoid_t>::get_instance()))
00054 {
00055 first_alphabet_t first_alpha;
00056 for (FirstInputIterator e = first_begin; e != first_end; ++e)
00057 first_alpha.insert(*e);
00058
00059 second_alphabet_t second_alpha;
00060 for (SecondInputIterator e = second_begin; e != second_end; ++e)
00061 second_alpha.insert(*e);
00062
00063 semiring_t semiring;
00064 first_monoid_t mA(first_alpha, mrep1);
00065 second_monoid_t mB(second_alpha, mrep2);
00066 monoid_t freemonoidproduct(mA, mB, mrep);
00067
00068 series_set_t series(semiring, freemonoidproduct, srep);
00069
00070 return automata_set_t(series);
00071 }
00072
00073
00074 template <class FirstInputIterator, class SecondInputIterator>
00075 automaton_t make_automaton(const FirstInputIterator first_begin,
00076 const FirstInputIterator first_end,
00077 const SecondInputIterator second_begin,
00078 const SecondInputIterator second_end,
00079 const monoid_rep_t& mrep =
00080 *(vcsn::algebra::monoid_rep_default<monoid_t>::get_instance()),
00081 const first_monoid_rep_t& mrep1 =
00082 *(vcsn::algebra::monoid_rep_default<first_monoid_t>::get_instance()),
00083 const second_monoid_rep_t& mrep2 =
00084 *(vcsn::algebra::monoid_rep_default<second_monoid_t>::get_instance()),
00085 const series_rep_t& srep =
00086 *(vcsn::algebra::series_rep_default<semiring_t, monoid_t>::get_instance()),
00087 const first_series_rep_t& srep1 =
00088 *(vcsn::algebra::series_rep_default<semiring_t, first_monoid_t>::get_instance()),
00089 const second_series_rep_t& srep2 =
00090 *(vcsn::algebra::series_rep_default<semiring_t, second_monoid_t>::get_instance()))
00091 {
00092 return automaton_t (make_automata_set(first_begin, first_end,
00093 second_begin, second_end,
00094 mrep, mrep1, mrep2, srep, srep1, srep2));
00095 }
00096
00097 template <class T1, class T2>
00098 automaton_t make_automaton(const T1& first_alphabet,
00099 const T2& second_alphabet,
00100 const monoid_rep_t& mrep =
00101 *(vcsn::algebra::monoid_rep_default<monoid_t>::get_instance()),
00102 const first_monoid_rep_t& mrep1 =
00103 *(vcsn::algebra::monoid_rep_default<first_monoid_t>::get_instance()),
00104 const second_monoid_rep_t& mrep2 =
00105 *(vcsn::algebra::monoid_rep_default<second_monoid_t>::get_instance()),
00106 const series_rep_t& srep =
00107 *(vcsn::algebra::series_rep_default<semiring_t, monoid_t>::get_instance()),
00108 const first_series_rep_t& srep1 =
00109 *(vcsn::algebra::series_rep_default<semiring_t, first_monoid_t>::get_instance()),
00110 const second_series_rep_t& srep2 =
00111 *(vcsn::algebra::series_rep_default<semiring_t, second_monoid_t>::get_instance()))
00112 {
00113 return make_automaton(first_alphabet.begin(), first_alphabet.end(),
00114 second_alphabet.begin(), second_alphabet.end(),
00115 mrep, mrep1, mrep2, srep, srep1, srep2);
00116 }
00117
00118 template <class FirstIterator, class SecondIterator>
00119 monoid_elt_t make_couple(const FirstIterator first_begin,
00120 const FirstIterator first_end,
00121 const SecondIterator second_begin,
00122 const SecondIterator second_end,
00123 const std::string& first_exp,
00124 const std::string& second_exp)
00125 {
00126 first_alphabet_t first_alpha;
00127 for (FirstIterator e = first_begin; e != first_end; ++e)
00128 first_alpha.insert(*e);
00129
00130 second_alphabet_t second_alpha;
00131 for (SecondIterator e = second_begin; e != second_end; ++e)
00132 second_alpha.insert(*e);
00133
00134 monoid_t fmp (first_alpha, second_alpha);
00135 monoid_elt_value_t fmp_elt_value (first_exp, second_exp);
00136
00137 return Element<monoid_t, monoid_elt_value_t> (fmp, fmp_elt_value);
00138 }
00139
00140 template <class T1, class T2>
00141 monoid_elt_t make_couple(const T1& first_alphabet,
00142 const T2& second_alphabet,
00143 const std::string& first_exp,
00144 const std::string& second_exp)
00145 {
00146 return make_couple(first_alphabet.begin(), first_alphabet.end(),
00147 second_alphabet.begin(), second_alphabet.end(),
00148 first_exp, second_exp);
00149 }
00150
00151
00152 template <typename TransStruct,
00153 typename TransImpl,
00154 typename SeriesStruct,
00155 typename SeriesImpl,
00156 typename S,
00157 typename T>
00158 AUTOMATON_CONTEXT::rat_exp_t
00159 do_evaluation(const vcsn::AutomataBase<TransStruct>&,
00160 const TransImpl&,
00161 const SeriesStruct&,
00162 const vcsn::rat::exp<S, T>& input,
00163 const Element<TransStruct, TransImpl>& t,
00164 const Element<SeriesStruct, SeriesImpl>&)
00165 {
00166 AUTOMATON_CONTEXT::automaton_t w = AUTOMATON_CONTEXT::make_automaton(t.structure().series()
00167 .monoid().first_monoid().alphabet());
00168 AUTOMATON_CONTEXT::automaton_t result = AUTOMATON_CONTEXT::make_automaton(t.structure().series()
00169 .monoid().second_monoid().alphabet());
00170 standard_of(w, input);
00171 evaluation_fmp(t, quotient(w), result);
00172
00173 return aut_to_exp(generalized(quotient(realtime(trim(result)))),
00174 DMChooser());
00175 }
00176
00177
00178 template <typename TransStruct,
00179 typename TransImpl,
00180 typename ArgStruct,
00181 typename ArgImpl>
00182 AUTOMATON_CONTEXT::rat_exp_t
00183 evaluation(const Element<TransStruct, TransImpl>& t,
00184 const Element<ArgStruct, ArgImpl>& input)
00185 {
00186 return do_evaluation(t.structure(), t.value(),
00187 input.structure(), input.value(),
00188 t, input);
00189 }
00190
00191
00192 }
00193 }
00194 }
00195