00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
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   
00045   
00046   
00047 
00048   template <typename S, typename T>
00049   inline typename input_projection_helper<Transducer<S>, T>::ret
00050   input_projection_helper<Transducer<S>, T>::
00051   make_input_projection_automaton(const Element<Transducer<S>, T>& t)
00052   {
00053     
00054     typedef typename ret::set_t set_t;
00055     typedef typename set_t::series_set_t series_set_t;
00056 
00057     set_t
00058     auto_set(series_set_t(t.structure().series().
00059                           semiring().semiring(), t.structure().
00060                           series().monoid()));
00061 
00062     return ret(auto_set);
00063   }
00064 
00065   template <typename S, typename T>
00066   inline typename output_projection_helper<Transducer<S>, T>::ret
00067   output_projection_helper<Transducer<S>, T>::
00068   make_output_projection_automaton(const Element<Transducer<S>, T>& t)
00069   {
00070     
00071     typedef typename ret::set_t set_t;
00072     typedef typename set_t::series_set_t series_set_t;
00073 
00074     set_t
00075     auto_set(series_set_t(t.structure().series().semiring()));
00076 
00077     return ret(auto_set);
00078   }
00079 
00080   
00081   
00082   
00083 
00084   template <typename S, typename T>
00085   inline typename input_projection_helper<Automata<S>, T>::ret
00086   input_projection_helper<Automata<S>, T>::
00087   make_input_projection_automaton(const Element<Automata<S>, T>& t)
00088   {
00089     
00090     typedef typename ret::set_t set_t;
00091     typedef typename set_t::series_set_t series_set_t;
00092 
00093     set_t
00094     auto_set(series_set_t(t.structure().series().
00095                           semiring(), t.structure().series().
00096                           monoid().first_monoid()));
00097 
00098     return ret(auto_set);
00099   }
00100 
00101   template <typename S, typename T>
00102   inline typename output_projection_helper<Automata<S>, T>::ret
00103   output_projection_helper<Automata<S>, T>::
00104   make_output_projection_automaton(const Element<Automata<S>, T>& t)
00105   {
00106     
00107     typedef typename ret::set_t set_t;
00108     typedef typename set_t::series_set_t series_set_t;
00109 
00110     set_t
00111     auto_set(series_set_t(t.structure().series().
00112                           semiring(), t.structure().series().
00113                           monoid().second_monoid()));
00114 
00115     return ret(auto_set);
00116   }
00117 
00118   template <class S, class T>
00119   typename identity_transducer_helper<S, T>::ret
00120   partial_identity(const Element<S, T>& a)
00121   {
00122     typedef Element<S, T> automaton_t;
00123     AUTOMATON_TYPES(automaton_t);
00124     typedef typename identity_transducer_helper<S, T>::ret  ret_t;
00125     typedef typename ret_t::series_set_elt_t output_series_set_elt_t;
00126     typedef typename series_set_elt_t::support_t support_t;
00127     typedef typename ret_t::set_t set_t;
00128     typedef typename set_t::series_set_t o_series_set_t;
00129     set_t s (o_series_set_t (a.structure().series(),
00130                              a.structure().series().monoid()));
00131     ret_t ret(s);
00132     std::vector<hstate_t> conv(a.states().size());
00133 
00134     for_all_states(s, a)
00135       conv[ret.add_state()] = *s;
00136     for_all_transitions(e, a)
00137     {
00138       series_set_elt_t t = a.series_of(*e);
00139       series_set_elt_t s(t);
00140       output_series_set_elt_t os(ret.structure().series());
00141       support_t supp = s.supp();
00142       for_all_const_(support_t, m, supp)
00143       {
00144         series_set_elt_t tmp(a.structure().series());
00145         tmp.assoc(*m, s.get(*m));
00146         os.assoc(*m, tmp);
00147       }
00148       htransition_t f = ret.add_series_transition(conv[a.src_of(*e)],
00149                                                   conv[a.dst_of(*e)],
00150                                                   os);
00151     }
00152     
00153     for_all_initial_states(i, a)
00154       ret.set_initial(conv[*i], a.get_initial(*i));
00155     for_all_final_states(f, a)
00156       ret.set_final(conv[*f], a.get_final(*f));
00157     return ret;
00158   }
00159 
00160 } 
00161 
00162 #endif // ! VCSN_AUTOMATA_CONCEPT_TRANSDUCER_HXX