Vaucanson  1.4.1
fmp_transducer_maker.thxx
1 // -*- C++ -*-
2 // fmp_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) 2005, 2006, 2008, 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  namespace VCSN_GRAPH_IMPL
33  {
34  VCSN_CONTEXT_NAMESPACE
35  {
36 
37  template <class FirstInputIterator, class SecondInputIterator>
38  automata_set_t make_automata_set(const FirstInputIterator first_begin,
39  const FirstInputIterator first_end,
40  const SecondInputIterator second_begin,
41  const SecondInputIterator second_end)
42  {
43  first_alphabet_t first_alpha;
44 
45  for (FirstInputIterator e = first_begin; e != first_end; ++e)
46  first_alpha.insert(*e);
47 
48  second_alphabet_t second_alpha;
49 
50  for (SecondInputIterator e = second_begin; e != second_end; ++e)
51  second_alpha.insert(*e);
52 
53  semiring_t semiring;
54  first_monoid_t mA(first_alpha);
55  second_monoid_t mB(second_alpha);
56  monoid_t freemonoidproduct(mA, mB);
57  series_set_t series(semiring, freemonoidproduct);
58 
59  return automata_set_t(series);
60  }
61 
62  template <class FirstInputIterator, class SecondInputIterator>
63  automata_set_t make_automata_set(const FirstInputIterator first_begin,
64  const FirstInputIterator first_end,
65  const SecondInputIterator second_begin,
66  const SecondInputIterator second_end,
67  const monoid_rep_t& mrep,
68  const first_monoid_rep_t& mrep1,
69  const second_monoid_rep_t& mrep2,
70  const series_rep_t& srep)
71  {
72  first_alphabet_t first_alpha;
73 
74  for (FirstInputIterator e = first_begin; e != first_end; ++e)
75  first_alpha.insert(*e);
76 
77  second_alphabet_t second_alpha;
78 
79  for (SecondInputIterator e = second_begin; e != second_end; ++e)
80  second_alpha.insert(*e);
81 
82  semiring_t semiring;
83  first_monoid_t mA(first_alpha, mrep1);
84  second_monoid_t mB(second_alpha, mrep2);
85  monoid_t freemonoidproduct(mA, mB, mrep);
86  series_set_t series(semiring, freemonoidproduct, srep);
87 
88  return automata_set_t(series);
89  }
90 
91  template <class FirstInputIterator, class SecondInputIterator>
92  automaton_t make_automaton(const FirstInputIterator first_begin,
93  const FirstInputIterator first_end,
94  const SecondInputIterator second_begin,
95  const SecondInputIterator second_end)
96  {
97  return automaton_t(make_automata_set(first_begin, first_end,
98  second_begin, second_end));
99  }
100 
101  template <class FirstInputIterator, class SecondInputIterator>
102  automaton_t make_automaton(const FirstInputIterator first_begin,
103  const FirstInputIterator first_end,
104  const SecondInputIterator second_begin,
105  const SecondInputIterator second_end,
106  const monoid_rep_t& mrep,
107  const first_monoid_rep_t& mrep1,
108  const second_monoid_rep_t& mrep2,
109  const series_rep_t& srep)
110  {
111  return automaton_t(make_automata_set(first_begin, first_end,
112  second_begin, second_end,
113  mrep, mrep1, mrep2,
114  srep));
115  }
116 
117  template <class T1, class T2>
118  automaton_t make_automaton(const T1& first_alphabet,
119  const T2& second_alphabet)
120  {
121  return make_automaton(first_alphabet.begin(), first_alphabet.end(),
122  second_alphabet.begin(), second_alphabet.end());
123  }
124 
125  template <class T1, class T2>
126  automaton_t make_automaton(const T1& first_alphabet,
127  const T2& second_alphabet,
128  const monoid_rep_t& mrep,
129  const first_monoid_rep_t& mrep1,
130  const second_monoid_rep_t& mrep2,
131  const series_rep_t& srep)
132  {
133  return make_automaton(first_alphabet.begin(), first_alphabet.end(),
134  second_alphabet.begin(), second_alphabet.end(),
135  mrep, mrep1, mrep2, srep);
136  }
137 
138  template <class FirstIterator, class SecondIterator>
139  monoid_elt_t make_couple(const FirstIterator first_begin,
140  const FirstIterator first_end,
141  const SecondIterator second_begin,
142  const SecondIterator second_end,
143  const first_monoid_elt_value_t& first_exp,
144  const second_monoid_elt_value_t& second_exp)
145  {
146  first_alphabet_t first_alpha;
147  for (FirstIterator e = first_begin; e != first_end; ++e)
148  first_alpha.insert(*e);
149 
150  second_alphabet_t second_alpha;
151  for (SecondIterator e = second_begin; e != second_end; ++e)
152  second_alpha.insert(*e);
153 
154  monoid_t fmp (first_alpha, second_alpha);
155  monoid_elt_value_t fmp_elt_value (first_exp, second_exp);
156 
157  return Element<monoid_t, monoid_elt_value_t> (fmp, fmp_elt_value);
158  }
159 
160  template <class T1, class T2>
161  monoid_elt_t make_couple(const T1& first_alphabet,
162  const T2& second_alphabet,
163  const first_monoid_elt_value_t& first_exp,
164  const second_monoid_elt_value_t& second_exp)
165  {
166  return make_couple(first_alphabet.begin(), first_alphabet.end(),
167  second_alphabet.begin(), second_alphabet.end(),
168  first_exp, second_exp);
169  }
170 
171 
172  template <typename TransStruct,
173  typename TransImpl,
174  typename SeriesStruct,
175  typename SeriesImpl,
176  typename S,
177  typename T>
178  AUTOMATON_CONTEXT::rat_exp_t
179  do_evaluation(const vcsn::AutomataBase<TransStruct>&,
180  const TransImpl&,
181  const SeriesStruct&,
182  const vcsn::rat::exp<S, T>& input,
183  const Element<TransStruct, TransImpl>& t,
184  const Element<SeriesStruct, SeriesImpl>&)
185  {
186  AUTOMATON_CONTEXT::automaton_t w = AUTOMATON_CONTEXT::make_automaton(t.structure().series()
187  .monoid().first_monoid().alphabet());
188  AUTOMATON_CONTEXT::automaton_t result = AUTOMATON_CONTEXT::make_automaton(t.structure().series()
189  .monoid().second_monoid().alphabet());
190  standard_of(w, input);
191  evaluation_fmp(t, quotient(w), result);
192 
193  return aut_to_exp(generalized(quotient(realtime(trim(result)))),
194  DMChooser());
195  }
196 
197 
198  template <typename TransStruct,
199  typename TransImpl,
200  typename ArgStruct,
201  typename ArgImpl>
202  AUTOMATON_CONTEXT::rat_exp_t
203  evaluation(const Element<TransStruct, TransImpl>& t,
204  const Element<ArgStruct, ArgImpl>& input)
205  {
206  return do_evaluation(t.structure(), t.value(),
207  input.structure(), input.value(),
208  t, input);
209  }
210 
211  inline
212  rat_exp_t
213  aut_to_exp(const automaton_t& a)
214  {
215  return aut_to_exp(generalized(a));
216  }
217 
218  template <class Chooser>
219  rat_exp_t
220  aut_to_exp(const automaton_t& a, const Chooser& c)
221  {
222  return aut_to_exp(generalized(a), c);
223  }
224 
225 
226  } // End of VCSN_CONTEXT_NAMESPACE.
227  } // End of VCSN_GRAPH_IMPL.
228 } // End of namespace vcsn.