17 #ifndef VCSN_ALGORITHMS_EVAL_HXX
18 # define VCSN_ALGORITHMS_EVAL_HXX
21 # include <vaucanson/automata/concept/automata_base.hh>
23 # include <vaucanson/misc/usual_macros.hh>
34 template <
typename auto_t,
typename input_t,
typename Selt>
37 AUTOMATON_TYPES(auto_t);
39 typedef std::vector<semiring_elt_t> weights;
46 typename weights::const_iterator w;
47 typename input_t::const_iterator l;
50 eval_functor(
const AutomataBase<A>&,
const auto_t& aut)
51 : a(aut), max_hstate(a.states().back() + 1),
52 v1(max_hstate, a.series().semiring().wzero_), v2(max_hstate)
55 void execute(
const input_t& word, Selt& result)
57 const monoid_elt_t empty = algebra::identity_as<monoid_elt_value_t>::of(a.series().monoid());
60 for_all_const_initial_states(i, a)
61 v1[*i] = a.get_initial(*i).
get(empty);
63 const semiring_elt_t zero = a.series().semiring().wzero_;
67 for (typename input_t::const_iterator w_end = word.end();
70 std::fill(v2.begin(), v2.end(), zero);
73 for (
typename weights::const_iterator v1_end = v1.end();
78 for (delta_iterator t(a.value(), a.get_state(i)); ! t.done(); t.next())
80 monoid_elt_t l_w(a.series_of(*t).structure().monoid(), *l);
81 if (a.series_of(*t).get(l_w) != a.series().semiring().wzero_)
83 v2[a.dst_of(*t)] += *w *
84 a.series_of(*t).get(monoid_elt_t(a.structure().series().monoid(), *l));
96 for_all_const_ (weights, w, v1)
99 result += *w * a.get_final(i).get(empty);
109 template<
typename A,
typename AI,
typename W>
110 typename Element<A, AI>::semiring_elt_t
113 BENCH_TASK_SCOPED(
"eval");
115 AUTOMATON_TYPES(automaton_t);
116 semiring_elt_t ret(a.
structure().series().semiring());
121 eval_functor<automaton_t, W, semiring_elt_t> evalf(a.
structure(), a);
122 evalf.execute(word, ret);
130 #endif // ! VCSN_ALGORITHMS_EVAL_HXX