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/internal/evaluation.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
00083 template <typename TransStruct,
00084 typename TransImpl,
00085 typename MonoidStruct,
00086 typename MonoidImpl>
00087 output_series_set_elt_t
00088 do_evaluation(const vcsn::TransducerBase<TransStruct>&,
00089 const TransImpl&,
00090 const vcsn::algebra::FreeMonoidBase<MonoidStruct>&,
00091 const MonoidImpl& input,
00092 const Element<TransStruct, TransImpl>& t,
00093 const Element<MonoidStruct, MonoidImpl>&)
00094 {
00095 return eval(t, input);
00096 }
00097
00098 template <typename TransStruct,
00099 typename TransImpl,
00100 typename SeriesStruct,
00101 typename SeriesImpl,
00102 typename S,
00103 typename T>
00104 output_series_set_elt_t
00105 do_evaluation(const vcsn::TransducerBase<TransStruct>&,
00106 const TransImpl&,
00107 const SeriesStruct&,
00108 const vcsn::rat::exp<S, T>& input,
00109 const Element<TransStruct, TransImpl>& t,
00110 const Element<SeriesStruct, SeriesImpl>&)
00111 {
00112 AUTOMATON_CONTEXT::automaton_t w =
00113 AUTOMATON_CONTEXT::make_automaton(t.structure().series()
00114 .monoid().alphabet());
00115 typename output_projection_helper<TransStruct, TransImpl>::ret::set_t
00116 ret_set(t.structure().series().semiring());
00117 AUTOMATON_CONTEXT::gen_automaton_t result (ret_set);
00118 standard_of(w, input);
00119 evaluation(quotient(w), t, result);
00120 return aut_to_exp(quotient(realtime(trim(result))), DMChooser());
00121 }
00122
00123 template <typename TransStruct,
00124 typename TransImpl,
00125 typename ArgStruct,
00126 typename ArgImpl>
00127 output_series_set_elt_t
00128 evaluation(const Element<TransStruct, TransImpl>& t,
00129 const Element<ArgStruct, ArgImpl>& input)
00130 {
00131 return do_evaluation(t.structure(), t.value(),
00132 input.structure(), input.value(),
00133 t, input);
00134 }
00135
00136 }
00137 }
00138 }
00139