Vaucanson 1.4
|
00001 // -*- C++ -*- 00002 // transducer_maker.thxx: this file is part of the Vaucanson project. 00003 // 00004 // Vaucanson, a generic library for finite state machines. 00005 // 00006 // Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010 The Vaucanson Group. 00007 // 00008 // This program is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU General Public License 00010 // as published by the Free Software Foundation; either version 2 00011 // of the License, or (at your option) any later version. 00012 // 00013 // The complete GNU General Public Licence Notice can be found as the 00014 // `COPYING' file in the root directory. 00015 // 00016 // The Vaucanson Group consists of people listed in the `AUTHORS' file. 00017 // 00018 00019 /* 00020 * CPP guard should not be inserted here as 00021 * VCSN_CONTEXT_NAMESPACE could be changed. 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 | make_automaton() | 00041 `-----------------*/ 00042 00043 template <class InputIterator> 00044 automata_set_t 00045 make_automata_set(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 automata_set; 00069 } 00070 00071 00072 template <class InputIterator> 00073 automaton_t 00074 make_automaton(InputIterator input_alphabet_begin, 00075 InputIterator input_alphabet_end, 00076 InputIterator output_alphabet_begin, 00077 InputIterator output_alphabet_end) 00078 { 00079 return automaton_t(make_automata_set(input_alphabet_begin, 00080 input_alphabet_end, 00081 output_alphabet_begin, 00082 output_alphabet_end)); 00083 } 00084 00085 00086 template <class T> 00087 automaton_t make_automaton(const T& input_alphabet, 00088 const T& output_alphabet) 00089 { 00090 return make_automaton(input_alphabet.begin(), 00091 input_alphabet.end(), 00092 output_alphabet.begin(), 00093 output_alphabet.end()); 00094 } 00095 00096 template <typename TransStruct, 00097 typename TransImpl, 00098 typename MonoidStruct, 00099 typename MonoidImpl> 00100 output_series_set_elt_t 00101 do_evaluation(const vcsn::TransducerBase<TransStruct>&, 00102 const TransImpl&, 00103 const vcsn::algebra::FreeMonoidBase<MonoidStruct>&, 00104 const MonoidImpl& input, 00105 const Element<TransStruct, TransImpl>& t, 00106 const Element<MonoidStruct, MonoidImpl>&) 00107 { 00108 return eval(t, input); 00109 } 00110 00111 template <typename TransStruct, 00112 typename TransImpl, 00113 typename SeriesStruct, 00114 typename SeriesImpl, 00115 typename S, 00116 typename T> 00117 output_series_set_elt_t 00118 do_evaluation(const vcsn::TransducerBase<TransStruct>&, 00119 const TransImpl&, 00120 const SeriesStruct&, 00121 const vcsn::rat::exp<S, T>& input, 00122 const Element<TransStruct, TransImpl>& t, 00123 const Element<SeriesStruct, SeriesImpl>&) 00124 { 00125 AUTOMATON_CONTEXT::automaton_t w = 00126 AUTOMATON_CONTEXT::make_automaton(t.structure().series() 00127 .monoid().alphabet()); 00128 typename output_projection_helper<TransStruct, TransImpl>::ret::set_t 00129 ret_set(t.structure().series().semiring()); 00130 AUTOMATON_CONTEXT::gen_automaton_t result (ret_set); 00131 standard_of(w, input); 00132 evaluation_rw(quotient(w), t, result); 00133 return aut_to_exp(quotient(realtime(trim(result))), DMChooser()); 00134 } 00135 00136 template <typename TransStruct, 00137 typename TransImpl, 00138 typename ArgStruct, 00139 typename ArgImpl> 00140 output_series_set_elt_t 00141 evaluation(const Element<TransStruct, TransImpl>& t, 00142 const Element<ArgStruct, ArgImpl>& input) 00143 { 00144 return do_evaluation(t.structure(), t.value(), 00145 input.structure(), input.value(), 00146 t, input); 00147 } 00148 00149 } // End of VCSN_CONTEXT_NAMESPACE. 00150 }// End of VCSN_GRAPH_IMPL. 00151 } // End of namespace vcsn. 00152