transducer_functions.thxx

00001 //                                                      -*- C++ -*-
00002 // 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) 2004, 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.hh>
00025 #include <vaucanson/algorithms/minimization_hopcroft.hh>
00026 #include <vaucanson/algorithms/trim.hh>
00027 #include <vaucanson/algorithms/aut_to_exp.hh>
00028 #include <vaucanson/algorithms/realtime.hh>
00029 
00030 namespace vcsn
00031 {
00032 
00033   namespace VCSN_CONTEXT_NAMESPACE
00034   {
00035 
00036     /*-----------------.
00037     | make_automaton() |
00038     `-----------------*/
00039 
00040     template <class InputIterator>
00041     automaton_t
00042     make_automaton(InputIterator input_alphabet_begin,
00043                    InputIterator input_alphabet_end,
00044                    InputIterator output_alphabet_begin,
00045                    InputIterator output_alphabet_end)
00046     {
00047       alphabet_t                input_alpha;
00048       alphabet_t                output_alpha;
00049 
00050       for (InputIterator e = input_alphabet_begin;
00051            e != input_alphabet_end; ++e)
00052         input_alpha.insert(*e);
00053 
00054       for (InputIterator e = output_alphabet_begin;
00055            e != output_alphabet_end; ++e)
00056         output_alpha.insert(*e);
00057 
00058       monoid_t                  output_freemonoid (output_alpha);
00059       typename output_series_set_t::semiring_t  semiring;
00060       output_series_set_t       output_series (semiring, output_freemonoid);
00061       monoid_t                  freemonoid (input_alpha);
00062       series_set_t              series (output_series, freemonoid);
00063       automata_set_t            automata_set (series);
00064 
00065       return automaton_t (automata_set);
00066     }
00067 
00068 
00069     template <class T>
00070     automaton_t make_automaton(const T& input_alphabet,
00071                                const T& output_alphabet)
00072     {
00073       return make_automaton(input_alphabet.begin(),
00074                             input_alphabet.end(),
00075                             output_alphabet.begin(),
00076                             output_alphabet.end());
00077     }
00078 
00079 
00080     template <typename TransStruct,
00081               typename TransImpl,
00082               typename MonoidStruct,
00083               typename MonoidImpl>
00084     output_series_set_elt_t
00085     do_evaluation(const vcsn::TransducerBase<TransStruct>&,
00086                   const TransImpl&,
00087                   const vcsn::algebra::FreeMonoidBase<MonoidStruct>&,
00088                   const MonoidImpl& input,
00089                   const Element<TransStruct, TransImpl>& t,
00090                   const Element<MonoidStruct, MonoidImpl>&)
00091     {
00092       return eval(t, input);
00093     }
00094 
00095 
00096     template <typename TransStruct,
00097               typename TransImpl,
00098               typename SeriesStruct,
00099               typename SeriesImpl,
00100               typename S,
00101               typename T>
00102     output_series_set_elt_t
00103     do_evaluation(const vcsn::TransducerBase<TransStruct>&,
00104                   const TransImpl&,
00105                   const SeriesStruct&,
00106                   const vcsn::rat::exp<S, T>& input,
00107                   const Element<TransStruct, TransImpl>& t,
00108                   const Element<SeriesStruct, SeriesImpl>&)
00109     {
00110       AUTOMATON_CONTEXT::automaton_t w = AUTOMATON_CONTEXT::
00111         make_automaton(t.structure().series().monoid().alphabet());
00112       AUTOMATON_CONTEXT::gen_automaton_t result (w.structure());
00113       standard_of(w, input);
00114       evaluation(quotient(w), t, result);
00115       return aut_to_exp(quotient(realtime(trim(result))), DMChooser());
00116     }
00117 
00118 
00119     template <typename TransStruct,
00120               typename TransImpl,
00121               typename ArgStruct,
00122               typename ArgImpl>
00123     output_series_set_elt_t
00124     evaluation(const Element<TransStruct, TransImpl>& t,
00125                const Element<ArgStruct, ArgImpl>& input)
00126     {
00127       return do_evaluation(t.structure(), t.value(),
00128                            input.structure(), input.value(),
00129                            t, input);
00130     }
00131 
00132   } // End of namespace VCSN_CONTEXT_NAMESPACE.
00133 
00134 } // End of namespace vcsn.
00135 

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