fmp_transducer_functions.thxx 4.86 KB
Newer Older
Michaël Cadilhac's avatar
Michaël Cadilhac committed
1
//							-*- C++ -*-
2
// fmp_transducer_functions.thxx: this file is part of the Vaucanson project.
Michaël Cadilhac's avatar
Michaël Cadilhac committed
3
//
4
// Vaucanson, a generic library for finite state machines.
Michaël Cadilhac's avatar
Michaël Cadilhac committed
5
6
7
//
// Copyright (C) 2005, 2006 The Vaucanson Group.
//
8
9
10
11
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
Michaël Cadilhac's avatar
Michaël Cadilhac committed
12
//
13
// The complete GNU General Public Licence Notice can be found as the
14
// `COPYING' file in the root directory.
Michaël Cadilhac's avatar
Michaël Cadilhac committed
15
//
16
// The Vaucanson Group consists of people listed in the `AUTHORS' file.
17
//
Michaël Cadilhac's avatar
Michaël Cadilhac committed
18
19

/**
Akim Demaille's avatar
Akim Demaille committed
20
 * CPP guard should not be inserted here as
Michaël Cadilhac's avatar
Michaël Cadilhac committed
21
22
23
24
25
26
27
28
 * VCSN_CONTEXT_NAMESPACE could be changed.
 */

#include <vaucanson/algorithms/evaluation_fmp.hh>
#include <vaucanson/algorithms/minimization_hopcroft.hh>
#include <vaucanson/algorithms/aut_to_exp.hh>
#include <vaucanson/algorithms/trim.hh>
#include <vaucanson/algorithms/realtime.hh>
29

30
31
32
33
34
35
namespace vcsn
{
  namespace VCSN_CONTEXT_NAMESPACE
  {

    template <class FirstInputIterator, class SecondInputIterator>
Michaël Cadilhac's avatar
Michaël Cadilhac committed
36
37
38
39
    automata_set_t make_automata_set(const FirstInputIterator first_begin,
				     const FirstInputIterator first_end,
				     const SecondInputIterator second_begin,
				     const SecondInputIterator second_end)
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
    {
      first_alphabet_t		first_alpha;
      for (FirstInputIterator e = first_begin; e != first_end; ++e)
	first_alpha.insert(*e);

      second_alphabet_t		second_alpha;
      for (SecondInputIterator e = second_begin; e != second_end; ++e)
	second_alpha.insert(*e);

      semiring_t		semiring;
      monoid_t			freemonoidproduct (first_alpha, second_alpha);
      series_set_t		series (semiring, freemonoidproduct);
      return automata_set_t	(series);
    }


    template <class FirstInputIterator, class SecondInputIterator>
57
    automaton_t make_automaton(const FirstInputIterator first_begin,
Michaël Cadilhac's avatar
Michaël Cadilhac committed
58
59
60
			       const FirstInputIterator first_end,
			       const SecondInputIterator second_begin,
			       const SecondInputIterator second_end)
61
    {
Michaël Cadilhac's avatar
Michaël Cadilhac committed
62
63
      return automaton_t (make_automata_set(first_begin, first_end,
					    second_begin, second_end));
64
65
66
    }

    template <class T1, class T2>
67
    automaton_t make_automaton(const T1& first_alphabet,
Michaël Cadilhac's avatar
Michaël Cadilhac committed
68
			       const T2& second_alphabet)
69
    {
70
      return make_automaton(first_alphabet.begin(), first_alphabet.end(),
Michaël Cadilhac's avatar
Michaël Cadilhac committed
71
			    second_alphabet.begin(), second_alphabet.end());
72
73
74
    }

    template <class FirstIterator, class SecondIterator>
75
76
77
78
79
80
    monoid_elt_t make_couple(const FirstIterator first_begin,
			     const FirstIterator first_end,
			     const SecondIterator second_begin,
			     const SecondIterator second_end,
			     const std::string& first_exp,
			     const std::string& second_exp)
81
82
83
84
85
86
87
88
89
    {
      first_alphabet_t		first_alpha;
      for (FirstIterator e = first_begin; e != first_end; ++e)
	first_alpha.insert(*e);

      second_alphabet_t		second_alpha;
      for (SecondIterator e = second_begin; e != second_end; ++e)
	second_alpha.insert(*e);

90
      monoid_t			fmp (first_alpha, second_alpha);
91

92
93
      monoid_elt_value_t	fmp_elt_value (first_exp, second_exp);
      return Element<monoid_t, monoid_elt_value_t> (fmp, fmp_elt_value);
94
95
96
    }

    template <class T1, class T2>
97
98
99
100
    monoid_elt_t make_couple(const T1& first_alphabet,
			     const T2& second_alphabet,
			     const std::string& first_exp,
			     const std::string& second_exp)
101
102
103
104
105
106
    {
      return make_couple(first_alphabet.begin(), first_alphabet.end(),
			 second_alphabet.begin(), second_alphabet.end(),
			 first_exp, second_exp);
    }

107
108
109
110
111
112
113

    template <typename TransStruct,
	      typename TransImpl,
	      typename SeriesStruct,
	      typename SeriesImpl,
	      typename S,
	      typename T>
114
    AUTOMATON_CONTEXT::rat_exp_t
115
116
117
118
119
120
121
    do_evaluation(const vcsn::AutomataBase<TransStruct>&,
		  const TransImpl&,
		  const SeriesStruct&,
		  const vcsn::rat::exp<S, T>& input,
		  const Element<TransStruct, TransImpl>& t,
		  const Element<SeriesStruct, SeriesImpl>&)
    {
122
      AUTOMATON_CONTEXT::automaton_t w = AUTOMATON_CONTEXT::
123
	make_automaton(t.structure().series()
Michaël Cadilhac's avatar
Michaël Cadilhac committed
124
		       .monoid().first_monoid().alphabet());
125
      AUTOMATON_CONTEXT::automaton_t result = AUTOMATON_CONTEXT::
126
	make_automaton(t.structure().series()
Michaël Cadilhac's avatar
Michaël Cadilhac committed
127
		       .monoid().second_monoid().alphabet());
128
      standard_of(w, input);
129
130
131
      evaluation_fmp(t, quotient(w), result);
      return aut_to_exp(generalized(quotient(realtime(trim(result)))),
			DMChooser());
132
133
134
135
136
137
138
    }


    template <typename TransStruct,
	      typename TransImpl,
	      typename ArgStruct,
	      typename ArgImpl>
139
    AUTOMATON_CONTEXT::rat_exp_t
140
141
142
143
144
145
146
147
148
    evaluation(const Element<TransStruct, TransImpl>& t,
	       const Element<ArgStruct, ArgImpl>& input)
    {
      return do_evaluation(t.structure(), t.value(),
			   input.structure(), input.value(),
			   t, input);
    }


149
150
  } // End of namespace VCSN_CONTEXT_NAMESPACE.
} // End of namespace vcsn.
151