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/aut_to_exp.hh>
00025 #include <vaucanson/algorithms/standard_of.hh>
00026 #include <vaucanson/algorithms/thompson.hh>
00027
00028 namespace vcsn
00029 {
00030 namespace VCSN_GRAPH_IMPL
00031 {
00032 VCSN_CONTEXT_NAMESPACE
00033 {
00034
00035
00036
00037
00038 template <class InputIterator>
00039 automata_set_t
00040 make_automata_set(InputIterator begin,
00041 InputIterator end,
00042 const monoid_rep_t& mrep = *(vcsn::algebra::
00043 monoid_rep_default<monoid_t>::
00044 get_instance()),
00045 const series_rep_t& srep = *(vcsn::algebra::
00046 series_rep_default<semiring_t, monoid_t>::
00047 get_instance()))
00048 {
00049 alphabet_t alpha;
00050 for (InputIterator e = begin; e != end; ++e)
00051 alpha.insert(*e);
00052 semiring_t semiring;
00053 monoid_t freemonoid (alpha, mrep);
00054 series_set_t series (semiring, freemonoid, srep);
00055 return automata_set_t (series);
00056 }
00057
00058 template <class InputIterator>
00059 automaton_t
00060 make_automaton(InputIterator begin,
00061 InputIterator end,
00062 const monoid_rep_t& mrep = *(vcsn::algebra::
00063 monoid_rep_default<monoid_t>::
00064 get_instance()),
00065 const series_rep_t& srep = *(vcsn::algebra::
00066 series_rep_default<semiring_t, monoid_t>::
00067 get_instance()))
00068 {
00069 return automaton_t (make_automata_set(begin, end, mrep, srep));
00070 }
00071
00072 template <class T>
00073 automaton_t
00074 make_automaton(const T& alphabet,
00075 const monoid_rep_t& mrep = *(vcsn::algebra::
00076 monoid_rep_default<monoid_t>::
00077 get_instance()),
00078 const series_rep_t& srep = *(vcsn::algebra::
00079 series_rep_default<semiring_t, monoid_t>::
00080 get_instance()))
00081 {
00082 return make_automaton(alphabet.begin(), alphabet.end(), mrep, srep);
00083 }
00084
00085 template <class InputIterator>
00086 automaton_letter_t
00087 make_automaton_letter(InputIterator begin,
00088 InputIterator end)
00089 {
00090 return automaton_letter_t (make_automata_set(begin, end));
00091 }
00092
00093 template <class T>
00094 automaton_letter_t
00095 make_automaton_letter(const T& alphabet)
00096 {
00097 return make_automaton_letter(alphabet.begin(), alphabet.end());
00098 }
00099
00100 template <class InputIterator>
00101 gen_automaton_t
00102 make_gen_automaton(InputIterator begin,
00103 InputIterator end)
00104 {
00105 return gen_automaton_t (make_automata_set(begin, end));
00106 }
00107
00108 template <class T>
00109 gen_automaton_t
00110 make_gen_automaton(const T& alphabet)
00111 {
00112 return make_gen_automaton(alphabet.begin(), alphabet.end());
00113 }
00114
00115
00116
00117
00118
00119 template <class Iterator>
00120 rat_exp_t
00121 make_rat_exp(const Iterator& begin,
00122 const Iterator& end,
00123 const std::string& exp = (vcsn::algebra::
00124 series_rep_default<semiring_t, monoid_t>::
00125 get_instance()->zero),
00126 const monoid_rep_t& mrep = *(vcsn::algebra::
00127 monoid_rep_default<monoid_t>::
00128 get_instance()),
00129 const series_rep_t& srep = *(vcsn::algebra::
00130 series_rep_default<semiring_t, monoid_t>::
00131 get_instance()))
00132 {
00133 alphabet_t alphabet;
00134 for (Iterator i = begin; i != end; ++i)
00135 alphabet.insert(*i);
00136 monoid_t monoid (alphabet, mrep);
00137 semiring_t semiring;
00138 series_set_t series (semiring, monoid, srep);
00139
00140 rat_exp_t r (series);
00141 std::pair<bool, std::string> p = parse(exp, r);
00142
00143 postcondition_ (not p.first, p.second);
00144
00145 return r;
00146 }
00147
00148 template <class T>
00149 rat_exp_t
00150 make_rat_exp(const T& alphabet,
00151 const std::string& exp = (vcsn::algebra::
00152 series_rep_default<semiring_t, monoid_t>::
00153 get_instance()->zero),
00154 const monoid_rep_t& mrep = *(vcsn::algebra::
00155 monoid_rep_default<monoid_t>::
00156 get_instance()),
00157 const series_rep_t& srep = *(vcsn::algebra::
00158 series_rep_default<semiring_t, monoid_t>::
00159 get_instance()))
00160 {
00161 return make_rat_exp(alphabet.begin(), alphabet.end(),
00162 exp, mrep, srep);
00163 }
00164
00165
00166
00167
00168
00169 template <class SeriesImpl>
00170 automaton_t
00171 do_standard_of(const series_set_t& structure, const SeriesImpl& impl)
00172 {
00173 automaton_t r = make_automaton(structure.monoid().alphabet());
00174 standard_of(r, impl);
00175 return r;
00176 }
00177
00178 template <class SeriesSet, class SeriesImpl>
00179 automaton_t
00180 standard_of(const Element<SeriesSet, SeriesImpl>& e)
00181 {
00182 return do_standard_of(e.structure(), e.value());
00183 }
00184
00185
00186
00187
00188
00189 template <class SeriesImpl>
00190 automaton_t
00191 do_thompson_of(const series_set_t& structure, const SeriesImpl& impl)
00192 {
00193 automaton_t r = make_automaton(structure.monoid().alphabet());
00194 thompson_of(r, impl);
00195 return r;
00196 }
00197
00198 template <class SeriesSet, class SeriesImpl>
00199 automaton_t
00200 thompson_of(const Element<SeriesSet, SeriesImpl>& e)
00201 {
00202 return do_thompson_of(e.structure(), e.value());
00203 }
00204
00205
00206
00207
00208
00209 inline
00210 rat_exp_t
00211 aut_to_exp(const automaton_t& a)
00212 {
00213 return aut_to_exp(generalized(a));
00214 }
00215
00216 template <class Chooser>
00217 rat_exp_t
00218 aut_to_exp(const automaton_t& a, const Chooser& c)
00219 {
00220 return aut_to_exp(generalized(a), c);
00221 }
00222
00223 }
00224 }
00225 }