Vaucanson  1.4.1
characteristic.hxx
1 // characteristic.hxx: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2011 The Vaucanson Group.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // The complete GNU General Public Licence Notice can be found as the
13 // `COPYING' file in the root directory.
14 //
15 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
16 //
17 
18 # include <vaucanson/design_pattern/design_pattern.hh>
19 # include <vaucanson/automata/concept/automata.hh>
20 # include <map>
21 
22 namespace vcsn
23 {
24  template<typename lhs_t, typename rhs_t>
25  void characteristic(lhs_t& dst, const rhs_t& from)
26  {
27  std::map<typename rhs_t::hstate_t, typename lhs_t::hstate_t> stmap;
28 
29  for (typename rhs_t::state_iterator i = from.states().begin();
30  i != from.states().end(); ++i)
31  {
32  typename lhs_t::hstate_t s = dst.add_state();
33  if (from.is_final(*i))
34  dst.set_final(s);
35  if (from.is_initial(*i))
36  dst.set_initial(s);
37  stmap[*i] = s;
38  }
39 
40  typedef typename lhs_t::semiring_elt_t semiring_elt_t;
41  semiring_elt_t one(dst.series().semiring().wone_);
42  for (typename rhs_t::transition_iterator i = from.transitions().begin();
43  i != from.transitions().end(); ++i)
44  {
45  typename rhs_t::series_set_elt_t label(from.series_of(*i));
46 
47  int size = label.supp().size();
48  if (size > 0)
49  {
50  typename rhs_t::series_set_elt_t::support_t::const_iterator m =
51  label.supp().begin();
52  for (int j = 0; j < size; ++j, ++m)
53  {
54  typename lhs_t::series_set_elt_t
55  series(dst.structure().series());
56  typename lhs_t::monoid_elt_t
57  mv(dst.structure().series().monoid());
58  mv = *m;
59  series.assoc(mv, one);
60  dst.add_series_transition(stmap[from.src_of(*i)],
61  stmap[from.dst_of(*i)], series);
62  }
63  }
64  }
65  }
66 
67 } // ! vcsn