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/evaluation_rw.hh>
00025 #include <vaucanson/algorithms/minimization_hopcroft.hh>
00026 #include <vaucanson/algorithms/trim.hh>
00027 #include <vaucanson/algorithms/aut_to_exp.hh>
00028 #include <vaucanson/algorithms/realtime.hh>
00029
00030 namespace vcsn
00031 {
00032
00033 namespace VCSN_GRAPH_IMPL
00034 {
00035
00036 VCSN_CONTEXT_NAMESPACE
00037 {
00038
00039
00040
00041
00042
00043 template <class InputIterator>
00044 automaton_t
00045 make_automaton(InputIterator input_alphabet_begin,
00046 InputIterator input_alphabet_end,
00047 InputIterator output_alphabet_begin,
00048 InputIterator output_alphabet_end)
00049 {
00050 alphabet_t input_alpha;
00051 alphabet_t output_alpha;
00052
00053 for (InputIterator e = input_alphabet_begin;
00054 e != input_alphabet_end; ++e)
00055 input_alpha.insert(*e);
00056
00057 for (InputIterator e = output_alphabet_begin;
00058 e != output_alphabet_end; ++e)
00059 output_alpha.insert(*e);
00060
00061 monoid_t output_freemonoid (output_alpha);
00062 typename output_series_set_t::semiring_t semiring;
00063 output_series_set_t output_series (semiring, output_freemonoid);
00064 monoid_t freemonoid (input_alpha);
00065 series_set_t series (output_series, freemonoid);
00066 automata_set_t automata_set (series);
00067
00068 return automaton_t (automata_set);
00069 }
00070
00071
00072 template <class T>
00073 automaton_t make_automaton(const T& input_alphabet,
00074 const T& output_alphabet)
00075 {
00076 return make_automaton(input_alphabet.begin(),
00077 input_alphabet.end(),
00078 output_alphabet.begin(),
00079 output_alphabet.end());
00080 }
00081
00082 template <typename TransStruct,
00083 typename TransImpl,
00084 typename MonoidStruct,
00085 typename MonoidImpl>
00086 output_series_set_elt_t
00087 do_evaluation(const vcsn::TransducerBase<TransStruct>&,
00088 const TransImpl&,
00089 const vcsn::algebra::FreeMonoidBase<MonoidStruct>&,
00090 const MonoidImpl& input,
00091 const Element<TransStruct, TransImpl>& t,
00092 const Element<MonoidStruct, MonoidImpl>&)
00093 {
00094 return eval(t, input);
00095 }
00096
00097 template <typename TransStruct,
00098 typename TransImpl,
00099 typename SeriesStruct,
00100 typename SeriesImpl,
00101 typename S,
00102 typename T>
00103 output_series_set_elt_t
00104 do_evaluation(const vcsn::TransducerBase<TransStruct>&,
00105 const TransImpl&,
00106 const SeriesStruct&,
00107 const vcsn::rat::exp<S, T>& input,
00108 const Element<TransStruct, TransImpl>& t,
00109 const Element<SeriesStruct, SeriesImpl>&)
00110 {
00111 AUTOMATON_CONTEXT::automaton_t w =
00112 AUTOMATON_CONTEXT::make_automaton(t.structure().series()
00113 .monoid().alphabet());
00114 typename output_projection_helper<TransStruct, TransImpl>::ret::set_t
00115 ret_set(t.structure().series().semiring());
00116 AUTOMATON_CONTEXT::gen_automaton_t result (ret_set);
00117 standard_of(w, input);
00118 evaluation_rw(quotient(w), t, result);
00119 return aut_to_exp(quotient(realtime(trim(result))), DMChooser());
00120 }
00121
00122 template <typename TransStruct,
00123 typename TransImpl,
00124 typename ArgStruct,
00125 typename ArgImpl>
00126 output_series_set_elt_t
00127 evaluation(const Element<TransStruct, TransImpl>& t,
00128 const Element<ArgStruct, ArgImpl>& input)
00129 {
00130 return do_evaluation(t.structure(), t.value(),
00131 input.structure(), input.value(),
00132 t, input);
00133 }
00134
00135 }
00136 }
00137 }
00138