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 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         for (FirstInputIterator e = first_begin; e != first_end; ++e)
00045           first_alpha.insert(*e);
00046 
00047         second_alphabet_t       second_alpha;
00048         for (SecondInputIterator e = second_begin; e != second_end; ++e)
00049           second_alpha.insert(*e);
00050 
00051         semiring_t              semiring;
00052         monoid_t                freemonoidproduct (first_alpha, second_alpha);
00053         series_set_t            series (semiring, freemonoidproduct);
00054         return automata_set_t   (series);
00055       }
00056 
00057 
00058       template <class FirstInputIterator, class SecondInputIterator>
00059       automaton_t make_automaton(const FirstInputIterator first_begin,
00060                                  const FirstInputIterator first_end,
00061                                  const SecondInputIterator second_begin,
00062                                  const SecondInputIterator second_end)
00063       {
00064         return automaton_t (make_automata_set(first_begin, first_end,
00065                             second_begin, second_end));
00066       }
00067 
00068       template <class T1, class T2>
00069       automaton_t make_automaton(const T1& first_alphabet,
00070                                  const T2& second_alphabet)
00071       {
00072         return make_automaton(first_alphabet.begin(), first_alphabet.end(),
00073                               second_alphabet.begin(), second_alphabet.end());
00074       }
00075 
00076       template <class FirstIterator, class SecondIterator>
00077       monoid_elt_t make_couple(const FirstIterator first_begin,
00078                                const FirstIterator first_end,
00079                                const SecondIterator second_begin,
00080                                const SecondIterator second_end,
00081                                const std::string& first_exp,
00082                                const std::string& second_exp)
00083       {
00084         first_alphabet_t        first_alpha;
00085         for (FirstIterator e = first_begin; e != first_end; ++e)
00086           first_alpha.insert(*e);
00087 
00088         second_alphabet_t       second_alpha;
00089         for (SecondIterator e = second_begin; e != second_end; ++e)
00090           second_alpha.insert(*e);
00091 
00092         monoid_t                fmp (first_alpha, second_alpha);
00093         monoid_elt_value_t      fmp_elt_value (first_exp, second_exp);
00094 
00095         return Element<monoid_t, monoid_elt_value_t> (fmp, fmp_elt_value);
00096       }
00097 
00098       template <class T1, class T2>
00099       monoid_elt_t make_couple(const T1& first_alphabet,
00100                                const T2& second_alphabet,
00101                                const std::string& first_exp,
00102                                const std::string& second_exp)
00103       {
00104         return make_couple(first_alphabet.begin(), first_alphabet.end(),
00105                            second_alphabet.begin(), second_alphabet.end(),
00106                            first_exp, second_exp);
00107       }
00108 
00109 
00110       template <typename TransStruct,
00111                 typename TransImpl,
00112                 typename SeriesStruct,
00113                 typename SeriesImpl,
00114                 typename S,
00115                 typename T>
00116       AUTOMATON_CONTEXT::rat_exp_t
00117       do_evaluation(const vcsn::AutomataBase<TransStruct>&,
00118                     const TransImpl&,
00119                     const SeriesStruct&,
00120                     const vcsn::rat::exp<S, T>& input,
00121                     const Element<TransStruct, TransImpl>& t,
00122                     const Element<SeriesStruct, SeriesImpl>&)
00123       {
00124         AUTOMATON_CONTEXT::automaton_t w = AUTOMATON_CONTEXT::make_automaton(t.structure().series()
00125             .monoid().first_monoid().alphabet());
00126         AUTOMATON_CONTEXT::automaton_t result = AUTOMATON_CONTEXT::make_automaton(t.structure().series()
00127             .monoid().second_monoid().alphabet());
00128         standard_of(w, input);
00129         evaluation_fmp(t, quotient(w), result);
00130 
00131         return aut_to_exp(generalized(quotient(realtime(trim(result)))),
00132             DMChooser());
00133       }
00134 
00135 
00136       template <typename TransStruct,
00137                 typename TransImpl,
00138                 typename ArgStruct,
00139                 typename ArgImpl>
00140       AUTOMATON_CONTEXT::rat_exp_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 
00150     } // End of VCSN_CONTEXT_NAMESPACE.
00151   } // End of VCSN_GRAPH_IMPL.
00152 } // End of namespace vcsn.
00153 

Generated on Thu Oct 9 20:22:35 2008 for Vaucanson by  doxygen 1.5.1