transducer.hxx

00001 // transducer.hxx: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 2001, 2002, 2003, 2004 The Vaucanson Group.
00006 //
00007 // This program is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2
00010 // of the License, or (at your option) any later version.
00011 //
00012 // The complete GNU General Public Licence Notice can be found as the
00013 // `COPYING' file in the root directory.
00014 //
00015 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
00016 //
00017 #ifndef VCSN_AUTOMATA_CONCEPT_TRANSDUCER_HXX
00018 # define VCSN_AUTOMATA_CONCEPT_TRANSDUCER_HXX
00019 
00020 #include <vaucanson/automata/concept/transducer_base.hh>
00021 
00022 namespace vcsn {
00023 
00024   template <class Series>
00025   Transducer<Series>::Transducer(const series_set_t& s):
00026     SetSlot<Series>(s)
00027   {}
00028 
00029   template <class Series>
00030   const typename Transducer<Series>::series_set_t&
00031   Transducer<Series>::series() const
00032   {
00033     return this->_structure_get();
00034   }
00035 
00036   template <class Series>
00037   bool
00038   operator==(const Transducer<Series>& lhs,
00039              const Transducer<Series>& rhs)
00040   {
00041     return & lhs.series() == & rhs.series();
00042   }
00043 
00044   template <class S, class T>
00045   typename identity_transducer_helper<S, T>::ret
00046   partial_identity(const Element<S, T>& a)
00047   {
00048     typedef Element<S, T> automaton_t;
00049     AUTOMATON_TYPES(automaton_t);
00050     typedef typename identity_transducer_helper<S, T>::ret  ret_t;
00051     typedef typename ret_t::series_set_elt_t output_series_set_elt_t;
00052     typedef typename series_set_elt_t::support_t support_t;
00053     typedef typename ret_t::set_t set_t;
00054     typedef typename set_t::series_set_t o_series_set_t;
00055     set_t s (o_series_set_t (a.structure().series(),
00056                              a.structure().series().monoid()));
00057     ret_t ret(s);
00058     std::vector<hstate_t> conv(a.states().size());
00059 
00060     for_each_state(s, a)
00061       conv[ret.add_state()] = *s;
00062     for_each_transition(e, a)
00063     {
00064       series_set_elt_t t = a.series_of(*e);
00065       series_set_elt_t s(t);
00066       output_series_set_elt_t os(ret.structure().series());
00067       support_t supp = s.supp();
00068       for_each_const_(support_t, m, supp)
00069       {
00070         series_set_elt_t tmp(a.structure().series());
00071         tmp.assoc(*m, s.get(*m));
00072         os.assoc(*m, tmp);
00073       }
00074       htransition_t f = ret.add_series_transition(conv[a.src_of(*e)],
00075                                                   conv[a.dst_of(*e)],
00076                                                   os);
00077     }
00078     // FIXME: set initial/final weights.
00079     for_each_initial_state(i, a)
00080       ret.set_initial(conv[*i], a.get_initial(*i));
00081     for_each_final_state(f, a)
00082       ret.set_final(conv[*f], a.get_final(*f));
00083     return ret;
00084   }
00085 
00086 } // vcsn
00087 
00088 #endif // ! VCSN_AUTOMATA_CONCEPT_TRANSDUCER_HXX

Generated on Fri Jul 28 12:18:55 2006 for Vaucanson by  doxygen 1.4.6