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