Vaucanson  1.4.1
transducer_maker.thxx
1 // -*- C++ -*-
2 // transducer_maker.thxx: this file is part of the Vaucanson project.
3 //
4 // Vaucanson, a generic library for finite state machines.
5 //
6 // Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010 The Vaucanson Group.
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License
10 // as published by the Free Software Foundation; either version 2
11 // of the License, or (at your option) any later version.
12 //
13 // The complete GNU General Public Licence Notice can be found as the
14 // `COPYING' file in the root directory.
15 //
16 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
17 //
18 
19 /*
20  * CPP guard should not be inserted here as
21  * VCSN_CONTEXT_NAMESPACE could be changed.
22  */
23 
29 
30 namespace vcsn
31 {
32 
33  namespace VCSN_GRAPH_IMPL
34  {
35 
36  VCSN_CONTEXT_NAMESPACE
37  {
38 
39  /*-----------------.
40  | make_automaton() |
41  `-----------------*/
42 
43  template <class InputIterator>
44  automata_set_t
45  make_automata_set(InputIterator input_alphabet_begin,
46  InputIterator input_alphabet_end,
47  InputIterator output_alphabet_begin,
48  InputIterator output_alphabet_end)
49  {
50  alphabet_t input_alpha;
51  alphabet_t output_alpha;
52 
53  for (InputIterator e = input_alphabet_begin;
54  e != input_alphabet_end; ++e)
55  input_alpha.insert(*e);
56 
57  for (InputIterator e = output_alphabet_begin;
58  e != output_alphabet_end; ++e)
59  output_alpha.insert(*e);
60 
61  monoid_t output_freemonoid (output_alpha);
62  typename output_series_set_t::semiring_t semiring;
63  output_series_set_t output_series (semiring, output_freemonoid);
64  monoid_t freemonoid (input_alpha);
65  series_set_t series (output_series, freemonoid);
66  automata_set_t automata_set (series);
67 
68  return automata_set;
69  }
70 
71 
72  template <class InputIterator>
73  automaton_t
74  make_automaton(InputIterator input_alphabet_begin,
75  InputIterator input_alphabet_end,
76  InputIterator output_alphabet_begin,
77  InputIterator output_alphabet_end)
78  {
79  return automaton_t(make_automata_set(input_alphabet_begin,
80  input_alphabet_end,
81  output_alphabet_begin,
82  output_alphabet_end));
83  }
84 
85 
86  template <class T>
87  automaton_t make_automaton(const T& input_alphabet,
88  const T& output_alphabet)
89  {
90  return make_automaton(input_alphabet.begin(),
91  input_alphabet.end(),
92  output_alphabet.begin(),
93  output_alphabet.end());
94  }
95 
96  template <typename TransStruct,
97  typename TransImpl,
98  typename MonoidStruct,
99  typename MonoidImpl>
100  output_series_set_elt_t
101  do_evaluation(const vcsn::TransducerBase<TransStruct>&,
102  const TransImpl&,
104  const MonoidImpl& input,
105  const Element<TransStruct, TransImpl>& t,
106  const Element<MonoidStruct, MonoidImpl>&)
107  {
108  return eval(t, input);
109  }
110 
111  template <typename TransStruct,
112  typename TransImpl,
113  typename SeriesStruct,
114  typename SeriesImpl,
115  typename S,
116  typename T>
117  output_series_set_elt_t
118  do_evaluation(const vcsn::TransducerBase<TransStruct>&,
119  const TransImpl&,
120  const SeriesStruct&,
121  const vcsn::rat::exp<S, T>& input,
122  const Element<TransStruct, TransImpl>& t,
123  const Element<SeriesStruct, SeriesImpl>&)
124  {
125  AUTOMATON_CONTEXT::automaton_t w =
126  AUTOMATON_CONTEXT::make_automaton(t.structure().series()
127  .monoid().alphabet());
128  typename output_projection_helper<TransStruct, TransImpl>::ret::set_t
129  ret_set(t.structure().series().semiring());
130  AUTOMATON_CONTEXT::gen_automaton_t result (ret_set);
131  standard_of(w, input);
132  evaluation_rw(quotient(w), t, result);
133  return aut_to_exp(quotient(realtime(trim(result))), DMChooser());
134  }
135 
136  template <typename TransStruct,
137  typename TransImpl,
138  typename ArgStruct,
139  typename ArgImpl>
140  output_series_set_elt_t
141  evaluation(const Element<TransStruct, TransImpl>& t,
142  const Element<ArgStruct, ArgImpl>& input)
143  {
144  return do_evaluation(t.structure(), t.value(),
145  input.structure(), input.value(),
146  t, input);
147  }
148 
149  } // End of VCSN_CONTEXT_NAMESPACE.
150  }// End of VCSN_GRAPH_IMPL.
151 } // End of namespace vcsn.
152