fmp_transducer_functions.thxx

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

Generated on Sat Jul 29 17:12:59 2006 for Vaucanson by  doxygen 1.4.6