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

# transducer_maker.thxx

    00001 //                                                      -*- C++ -*-
    00002 // 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) 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
    00019 /*
    00020  * CPP guard should not be inserted here as
    00021  * VCSN_CONTEXT_NAMESPACE could be changed.
    00022  */
    00023
    00024 #include <vaucanson/algorithms/internal/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   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 =
    00111         AUTOMATON_CONTEXT::make_automaton(t.structure().series()
    00112                                            .monoid().alphabet());
    00113       typename output_projection_helper<TransStruct, TransImpl>::ret::set_t
    00114         ret_set(t.structure().series().semiring());
    00115       AUTOMATON_CONTEXT::gen_automaton_t result (ret_set);
    00116       standard_of(w, input);
    00117       evaluation(quotient(w), t, result);
    00118       return aut_to_exp(quotient(realtime(trim(result))), DMChooser());
    00119     }
    00120
    00121
    00122     template <typename TransStruct,
    00123               typename TransImpl,
    00124               typename ArgStruct,
    00125               typename ArgImpl>
    00126     output_series_set_elt_t
    00127     evaluation(const Element<TransStruct, TransImpl>& t,
    00128                const Element<ArgStruct, ArgImpl>& input)
    00129     {
    00130       return do_evaluation(t.structure(), t.value(),
    00131                            input.structure(), input.value(),
    00132                            t, input);
    00133     }
    00134
    00135   } // End of VCSN_CONTEXT_NAMESPACE.
    00136
    00137 } // End of namespace vcsn.
    00138