17 #ifndef VCSN_ALGORITHMS_BERRY_SETHI_HXX
18 # define VCSN_ALGORITHMS_BERRY_SETHI_HXX
24 # include <vaucanson/algorithms/internal/build_pattern.hh>
25 # include <vaucanson/automata/concept/automata_base.hh>
30 # include <vaucanson/misc/usual_macros.hh>
34 using namespace algorithm_patterns;
47 template <
typename S,
typename T>
48 typename linearize_element<S, T>::alphabet_t
52 typedef typename linearize_element<S, T>::letter_t letter_t;
54 alphabet_t result =
linearize(exp).structure().monoid().alphabet();
55 result.insert(letter_t(0, 0));
69 template <
typename Exp,
typename Letter>
73 typedef typename Exp::set_t::monoid_t::alphabet_t alphabet_t;
74 typedef typename alphabet_t::iterator iterator;
75 typedef typename Exp::value_t value_t;
80 alphabet_t alpha = exp.structure().monoid().alphabet();
81 Exp zero = exp.structure().zero(
SELECT(value_t));
82 std::list<Exp> exp_list;
84 exp_list.push_back(exp);
86 while (!exp_list.empty())
88 Exp exp = exp_list.front();
95 for (iterator i = alpha.begin(); i != alpha.end(); ++i)
99 if (deriv != zero && deriv != exp)
100 exp_list.push_back(deriv);
125 template <
typename T_auto,
typename S,
typename T>
127 BerrySethiAlgo<T_auto, S, T>,
129 typename linearize_element<S, T>::letter_t >
139 typedef typename linearize_element<S, T>::letter_t
etiq_t;
142 AUTOMATON_TYPES(T_auto);
143 AUTOMATON_FREEMONOID_TYPES(T_auto);
161 linear_alpha(linear_exp.structure().monoid().alphabet())
163 linear_alpha.insert(
etiq_t(0, 0));
170 return (e ==
etiq_t(0, 0));
176 != linear_exp.structure().semiring().zero(
SELECT(semiring_elt_value_t));
181 std::set<etiq_t> delta(
const etiq_t& e,
const letter_t& l)
183 typedef typename linear_alphabet_t::iterator iterator;
184 std::set<etiq_t> result;
187 for (iterator i = linear_alpha.begin(); i != linear_alpha.end(); ++i)
189 && (derivation(continuation_e, *i)
197 linear_exp_t derivation(
const linear_exp_t& exp,
const etiq_t& e)
199 if (e == etiq_t(0, 0))
206 linear_exp_t linear_exp;
208 linear_alphabet_t linear_alpha;
211 template<
typename T_auto,
typename S,
typename T>
213 do_berry_sethi(
const T_auto& out,
const Element<S, T>& kexp)
215 BerrySethiAlgo<T_auto, S, T> berrysethi_algo(out.series(), kexp);
216 berrysethi_algo.run();
217 return berrysethi_algo.get();
220 template<
typename A,
typename T,
typename Exp>
224 BENCH_TASK_SCOPED(
"berry_sethi");
232 #endif // ! VCSN_ALGORITHMS_BERRY_SETHI_HXX