- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

# fmp_transducer_maker.thxx

    00001 //                                                      -*- C++ -*-
    00002 // fmp_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) 2005, 2006, 2008, 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/minimization_hopcroft.hh>
    00025 #include <vaucanson/algorithms/evaluation_fmp.hh>
    00026 #include <vaucanson/algorithms/aut_to_exp.hh>
    00027 #include <vaucanson/algorithms/trim.hh>
    00028 #include <vaucanson/algorithms/realtime.hh>
    00029
    00030 namespace vcsn
    00031 {
    00032   namespace VCSN_GRAPH_IMPL
    00033   {
    00034     VCSN_CONTEXT_NAMESPACE
    00035     {
    00036
    00037       template <class FirstInputIterator, class SecondInputIterator>
    00038       automata_set_t make_automata_set(const FirstInputIterator first_begin,
    00039                                        const FirstInputIterator first_end,
    00040                                        const SecondInputIterator second_begin,
    00041                                        const SecondInputIterator second_end)
    00042       {
    00043         first_alphabet_t first_alpha;
    00044
    00045         for (FirstInputIterator e = first_begin; e != first_end; ++e)
    00046           first_alpha.insert(*e);
    00047
    00048         second_alphabet_t second_alpha;
    00049
    00050         for (SecondInputIterator e = second_begin; e != second_end; ++e)
    00051           second_alpha.insert(*e);
    00052
    00053         semiring_t      semiring;
    00054         first_monoid_t  mA(first_alpha);
    00055         second_monoid_t mB(second_alpha);
    00056         monoid_t        freemonoidproduct(mA, mB);
    00057         series_set_t    series(semiring, freemonoidproduct);
    00058
    00059         return automata_set_t(series);
    00060       }
    00061
    00062       template <class FirstInputIterator, class SecondInputIterator>
    00063       automata_set_t make_automata_set(const FirstInputIterator first_begin,
    00064                                        const FirstInputIterator first_end,
    00065                                        const SecondInputIterator second_begin,
    00066                                        const SecondInputIterator second_end,
    00067                                        const monoid_rep_t& mrep,
    00068                                        const first_monoid_rep_t& mrep1,
    00069                                        const second_monoid_rep_t& mrep2,
    00070                                        const series_rep_t& srep)
    00071       {
    00072         first_alphabet_t first_alpha;
    00073
    00074         for (FirstInputIterator e = first_begin; e != first_end; ++e)
    00075           first_alpha.insert(*e);
    00076
    00077         second_alphabet_t second_alpha;
    00078
    00079         for (SecondInputIterator e = second_begin; e != second_end; ++e)
    00080           second_alpha.insert(*e);
    00081
    00082         semiring_t      semiring;
    00083         first_monoid_t  mA(first_alpha, mrep1);
    00084         second_monoid_t mB(second_alpha, mrep2);
    00085         monoid_t        freemonoidproduct(mA, mB, mrep);
    00086         series_set_t    series(semiring, freemonoidproduct, srep);
    00087
    00088         return automata_set_t(series);
    00089       }
    00090
    00091       template <class FirstInputIterator, class SecondInputIterator>
    00092       automaton_t make_automaton(const FirstInputIterator first_begin,
    00093                                  const FirstInputIterator first_end,
    00094                                  const SecondInputIterator second_begin,
    00095                                  const SecondInputIterator second_end)
    00096       {
    00097         return automaton_t(make_automata_set(first_begin, first_end,
    00098                                              second_begin, second_end));
    00099       }
    00100
    00101       template <class FirstInputIterator, class SecondInputIterator>
    00102       automaton_t make_automaton(const FirstInputIterator first_begin,
    00103                                  const FirstInputIterator first_end,
    00104                                  const SecondInputIterator second_begin,
    00105                                  const SecondInputIterator second_end,
    00106                                  const monoid_rep_t& mrep,
    00107                                  const first_monoid_rep_t& mrep1,
    00108                                  const second_monoid_rep_t& mrep2,
    00109                                  const series_rep_t& srep)
    00110       {
    00111         return automaton_t(make_automata_set(first_begin, first_end,
    00112                                              second_begin, second_end,
    00113                                              mrep, mrep1, mrep2,
    00114                                              srep));
    00115       }
    00116
    00117       template <class T1, class T2>
    00118       automaton_t make_automaton(const T1& first_alphabet,
    00119                                  const T2& second_alphabet)
    00120       {
    00121         return make_automaton(first_alphabet.begin(), first_alphabet.end(),
    00122                               second_alphabet.begin(), second_alphabet.end());
    00123       }
    00124
    00125       template <class T1, class T2>
    00126       automaton_t make_automaton(const T1& first_alphabet,
    00127                                  const T2& second_alphabet,
    00128                                  const monoid_rep_t& mrep,
    00129                                  const first_monoid_rep_t& mrep1,
    00130                                  const second_monoid_rep_t& mrep2,
    00131                                  const series_rep_t& srep)
    00132       {
    00133         return make_automaton(first_alphabet.begin(), first_alphabet.end(),
    00134                               second_alphabet.begin(), second_alphabet.end(),
    00135                               mrep, mrep1, mrep2, srep);
    00136       }
    00137
    00138       template <class FirstIterator, class SecondIterator>
    00139       monoid_elt_t make_couple(const FirstIterator first_begin,
    00140                                const FirstIterator first_end,
    00141                                const SecondIterator second_begin,
    00142                                const SecondIterator second_end,
    00143                                const first_monoid_elt_value_t& first_exp,
    00144                                const second_monoid_elt_value_t& second_exp)
    00145       {
    00146         first_alphabet_t        first_alpha;
    00147         for (FirstIterator e = first_begin; e != first_end; ++e)
    00148           first_alpha.insert(*e);
    00149
    00150         second_alphabet_t       second_alpha;
    00151         for (SecondIterator e = second_begin; e != second_end; ++e)
    00152           second_alpha.insert(*e);
    00153
    00154         monoid_t                fmp (first_alpha, second_alpha);
    00155         monoid_elt_value_t      fmp_elt_value (first_exp, second_exp);
    00156
    00157         return Element<monoid_t, monoid_elt_value_t> (fmp, fmp_elt_value);
    00158       }
    00159
    00160       template <class T1, class T2>
    00161       monoid_elt_t make_couple(const T1& first_alphabet,
    00162                                const T2& second_alphabet,
    00163                                const first_monoid_elt_value_t& first_exp,
    00164                                const second_monoid_elt_value_t& second_exp)
    00165       {
    00166         return make_couple(first_alphabet.begin(), first_alphabet.end(),
    00167                            second_alphabet.begin(), second_alphabet.end(),
    00168                            first_exp, second_exp);
    00169       }
    00170
    00171
    00172       template <typename TransStruct,
    00173                 typename TransImpl,
    00174                 typename SeriesStruct,
    00175                 typename SeriesImpl,
    00176                 typename S,
    00177                 typename T>
    00178       AUTOMATON_CONTEXT::rat_exp_t
    00179       do_evaluation(const vcsn::AutomataBase<TransStruct>&,
    00180                     const TransImpl&,
    00181                     const SeriesStruct&,
    00182                     const vcsn::rat::exp<S, T>& input,
    00183                     const Element<TransStruct, TransImpl>& t,
    00184                     const Element<SeriesStruct, SeriesImpl>&)
    00185       {
    00186         AUTOMATON_CONTEXT::automaton_t w = AUTOMATON_CONTEXT::make_automaton(t.structure().series()
    00187             .monoid().first_monoid().alphabet());
    00188         AUTOMATON_CONTEXT::automaton_t result = AUTOMATON_CONTEXT::make_automaton(t.structure().series()
    00189             .monoid().second_monoid().alphabet());
    00190         standard_of(w, input);
    00191         evaluation_fmp(t, quotient(w), result);
    00192
    00193         return aut_to_exp(generalized(quotient(realtime(trim(result)))),
    00194             DMChooser());
    00195       }
    00196
    00197
    00198       template <typename TransStruct,
    00199                 typename TransImpl,
    00200                 typename ArgStruct,
    00201                 typename ArgImpl>
    00202       AUTOMATON_CONTEXT::rat_exp_t
    00203       evaluation(const Element<TransStruct, TransImpl>& t,
    00204                  const Element<ArgStruct, ArgImpl>& input)
    00205       {
    00206         return do_evaluation(t.structure(), t.value(),
    00207                              input.structure(), input.value(),
    00208                              t, input);
    00209       }
    00210
    00211       inline
    00212       rat_exp_t
    00213       aut_to_exp(const automaton_t& a)
    00214       {
    00215         return aut_to_exp(generalized(a));
    00216       }
    00217
    00218       template <class Chooser>
    00219       rat_exp_t
    00220       aut_to_exp(const automaton_t& a, const Chooser& c)
    00221       {
    00222         return aut_to_exp(generalized(a), c);
    00223       }
    00224
    00225
    00226     } // End of VCSN_CONTEXT_NAMESPACE.
    00227   } // End of VCSN_GRAPH_IMPL.
    00228 } // End of namespace vcsn.