10 #include <vcsn/dyn/fwd.hh>
22 template <Automaton Aut>
34 using weight_t =
typename weightset_t::value_t;
57 template <
typename LabelSet = labelset_t>
58 std::enable_if_t<!LabelSet::is_free(),
66 auto q = std::queue<labeled_weight>{};
78 cur.w =
ws_.mul(cur.w,
aut_->weight_of(t));
79 res =
ws_.add(res, cur.w);
81 else if (
auto new_word
84 ws_.mul(cur.w,
aut_->weight_of(t)),
92 template <
typename LabelSet = labelset_t>
93 std::enable_if_t<LabelSet::is_free(),
115 auto ls = *
aut_->labelset();
116 for (
auto l : ls.letters_of(ls.delimit(word)))
118 v2.assign(v2.size(), zero);
119 for (
size_t s = 0; s < v1.size(); ++s)
120 if (!
ws_.is_zero(v1[s]))
126 auto dst =
aut_->dst_of(t);
127 if (v2.size() <= dst)
129 auto capacity = v2.capacity();
130 while (capacity <= dst)
132 v1.reserve(capacity);
133 v2.reserve(capacity);
134 v1.resize(dst + 1, zero);
135 v2.resize(dst + 1, zero);
142 ws_.mul(v1[s],
aut_->weight_of(t)));
146 return v1[
aut_->post()];
153 for (
const auto& m: poly)
170 template <Automaton Aut>
184 template <Automaton Aut>
189 require(
is_proper(a),
"evaluate: cannot evaluate with spontaneous transitions");
190 const auto& ws = *a->weightset();
191 auto res = ws.zero();
194 auto s = a->dst_of(init_tr);
195 auto w = a->weight_of(init_tr);
198 assert(a->dst_of(
out) == a->post());
199 res = ws.add(res, ws.mul(w, a->weight_of(
out)));
210 template <Automaton Aut,
typename LabelSet>
214 const auto& a = aut->
as<Aut>();
215 const auto& l = lbl->
as<LabelSet>().value();
217 return {*a->weightset(),
res};
223 template <Automaton Aut>
239 template <Automaton Aut,
typename PolynomialSet>
243 const auto& a = aut->
as<Aut>();
244 const auto& p = poly->
as<PolynomialSet>().value();
246 return {*a->weightset(),
res};
std::vector< weight_t > weights_t
state -> weight.
value_impl< detail::weight_tag > weight
labeled_weight(weight_t w_, word_t l_, state_t s_)
auto weight_of(const welement< Label, Weight > &m) -> decltype(m.weight())
The weight of a welement.
auto make_word_polynomialset(const Ctx &ctx) -> word_polynomialset_t< Ctx >
The polynomialset of words of a labelset (not necessarily on words itself).
void require(Bool b, Args &&...args)
If b is not verified, raise an error with args as message.
Provide a variadic mul on top of a binary mul(), and one().
labelset_t_of< automaton_t > labelset_t
Evaluate a word on an automaton.
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.
bool is_proper(const Aut &aut)
Test whether an automaton is proper.
auto initial_transitions(const Aut &aut) -> decltype(aut->all_out(aut->pre()))
Indexes of transitions to (visible) initial states.
typename wps_t::value_t polynomial_t
std::enable_if_t<!LabelSet::is_free(), weight_t > operator()(const word_t &word) const
auto out(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions leaving state s.
evaluator(const automaton_t &a)
context_t_of< automaton_t > context_t
weight_t operator()(const polynomial_t &poly) const
Polynomial implementation.
auto all_out(const Aut &aut, state_t_of< Aut > s)
Indexes of transitions leaving state s.
typename law_traits< LabelSet >::type law_t
The smallest wordset that includes LabelSet.
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
typename labelset_t_of< base_t< ValueSet >>::word_t word_t_of
law_t< labelset_t > wordset_t
std::enable_if_t< LabelSet::is_free(), weight_t > operator()(const word_t &word) const
typename weightset_t::value_t weight_t
auto & as()
Extract wrapped typed value.
state_t_of< automaton_t > state_t
auto evaluate(const Aut &a, const typename detail::word_polynomialset_t< context_t_of< Aut >>::value_t &p) -> weight_t_of< Aut >
Evaluation of a polynomial.
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
weight evaluate(const automaton &aut, const label &lbl)
Bridge.
auto evaluate(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.
weightset_t_of< automaton_t > weightset_t
auto & as()
Extract wrapped typed automaton.
weight eval_polynomial(const automaton &aut, const polynomial &poly)
Bridge (evaluate).
word_t_of< automaton_t > word_t
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
auto label_of(const welement< Label, Weight > &m) -> decltype(m.label())
The label of a welement.
law_t< LabelSet > make_wordset(const LabelSet &ls)
The wordset of a labelset.