9 #include <vcsn/dyn/fwd.hh>
17 template <Automaton Aut>
21 "evaluate: requires free labelset");
27 using weight_t =
typename weightset_t::value_t;
57 auto ls = *
aut_->labelset();
58 for (
auto l : ls.letters_of(ls.delimit(word)))
60 v2.assign(v2.size(), zero);
61 for (
size_t s = 0; s < v1.size(); ++s)
62 if (!
ws_.is_zero(v1[s]))
68 auto dst =
aut_->dst_of(t);
71 auto capacity = v2.capacity();
72 while (capacity <= dst)
76 v1.resize(dst + 1, zero);
77 v2.resize(dst + 1, zero);
84 ws_.mul(v1[s],
aut_->weight_of(t)));
88 return v1[
aut_->post()];
98 template <Automaton Aut>
112 template <Automaton Aut>
117 require(
is_proper(a),
"eval: cannot evaluate with spontaneous transitions");
118 const auto& ws = *a->weightset();
119 auto res = ws.zero();
122 auto s = a->dst_of(init_tr);
123 auto w = a->weight_of(init_tr);
126 assert(a->dst_of(
out) == a->post());
127 res = ws.add(res, ws.mul(w, a->weight_of(
out)));
138 template <Automaton Aut,
typename LabelSet>
142 const auto& a = aut->
as<Aut>();
143 const auto& l = lbl->
as<LabelSet>().value();
145 return {*a->weightset(),
res};
value_impl< detail::weight_tag > weight
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of
typename labelset_t_of< base_t< ValueSet >>::word_t word_t_of
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
size_t states_size(const Aut &aut)
The largest state number, plus one.
typename weightset_t::value_t weight_t
auto out(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions leaving state s.
state_t_of< automaton_t > state_t
void require(Bool b, Args &&...args)
If b is not verified, raise an error with args as message.
weightset_t_of< automaton_t > weightset_t
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
weight eval(const automaton &aut, const label &lbl)
Bridge.
auto eval(const Aut &a, const word_t_of< Aut > &w) -> std::enable_if_t<!context_t_of< Aut >::is_lao, weight_t_of< Aut >>
General case of evaluation.
word_t_of< automaton_t > word_t
evaluator(const automaton_t &a)
bool is_proper(const Aut &aut)
Test whether an automaton is proper.
weight_t operator()(const word_t &word) const
auto initial_transitions(const Aut &aut) -> decltype(aut->all_out(aut->pre()))
Indexes of transitions to (visible) initial states.
auto & as()
Extract wrapped typed value.
std::vector< weight_t > weights_t
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
auto & as()
Extract wrapped typed automaton.
auto all_out(const Aut &aut, state_t_of< Aut > s)
Indexes of transitions leaving state s.