00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 # include <vaucanson/design_pattern/design_pattern.hh>
00019 # include <vaucanson/automata/concept/automata.hh>
00020 # include <map>
00021
00022 namespace vcsn
00023 {
00024 template<typename lhs_t, typename rhs_t>
00025 void characteristic(lhs_t& dst, const rhs_t& from)
00026 {
00027 std::map<typename rhs_t::hstate_t, typename lhs_t::hstate_t> stmap;
00028
00029 for (typename rhs_t::state_iterator i = from.states().begin();
00030 i != from.states().end(); ++i)
00031 {
00032 typename lhs_t::hstate_t s = dst.add_state();
00033 if (from.is_final(*i))
00034 dst.set_final(s);
00035 if (from.is_initial(*i))
00036 dst.set_initial(s);
00037 stmap[*i] = s;
00038 }
00039
00040 typedef typename lhs_t::semiring_elt_t semiring_elt_t;
00041 semiring_elt_t one(dst.series().semiring().wone_);
00042 for (typename rhs_t::transition_iterator i = from.transitions().begin();
00043 i != from.transitions().end(); ++i)
00044 {
00045 typename rhs_t::series_set_elt_t label(from.series_of(*i));
00046
00047 int size = label.supp().size();
00048 if (size > 0)
00049 {
00050 typename rhs_t::series_set_elt_t::support_t::const_iterator m =
00051 label.supp().begin();
00052 for (int j = 0; j < size; ++j, ++m)
00053 {
00054 typename lhs_t::series_set_elt_t
00055 series(dst.structure().series());
00056 typename lhs_t::monoid_elt_t
00057 mv(dst.structure().series().monoid());
00058 mv = *m;
00059 series.assoc(mv, one);
00060 dst.add_series_transition(stmap[from.src_of(*i)],
00061 stmap[from.dst_of(*i)], series);
00062 }
00063 }
00064 }
00065 }
00066
00067 }