10 #include <vcsn/dyn/fwd.hh> 22 template <Automaton Aut>
34 using weight_t =
typename weightset_t::value_t;
58 template <
typename LabelSet = labelset_t>
59 std::enable_if_t<!LabelSet::is_free(),
67 auto q = std::queue<labeled_weight>{};
79 cur.w =
ws_.mul(cur.w,
aut_->weight_of(t));
82 else if (
auto new_word
85 ws_.mul(cur.w,
aut_->weight_of(t)),
93 template <
typename LabelSet = labelset_t>
94 std::enable_if_t<LabelSet::is_free(),
113 for (
const auto l :
ls_.letters_of(
ls_.delimit(word)))
115 v2.assign(v2.size(),
ws_.zero());
116 for (
size_t s = 0;
s < v1.size(); ++
s)
117 if (!
ws_.is_zero(v1[
s]))
118 for (
const auto t :
out(
aut_, s,
l))
120 const auto dst =
aut_->dst_of(t);
124 if (v2.size() <= dst)
126 auto capacity = v2.capacity();
127 while (capacity <= dst)
129 v1.reserve(capacity);
130 v2.reserve(capacity);
131 v1.resize(dst + 1,
ws_.zero());
132 v2.resize(dst + 1,
ws_.zero());
139 ws_.mul(v1[s],
aut_->weight_of(t)));
143 return v1[
aut_->post()];
164 for (
const auto& m: poly)
180 template <Automaton Aut>
194 template <Automaton Aut>
200 "evaluate: cannot evaluate with spontaneous transitions");
201 const auto& ws = *a->weightset();
202 auto res = ws.zero();
205 const auto s = a->dst_of(init_tr);
206 const auto w = a->weight_of(init_tr);
209 assert(a->dst_of(
out) == a->post());
210 res = ws.add(res, ws.mul(
w, a->weight_of(
out)));
221 template <Automaton Aut,
typename LabelSet>
231 = (ctx_t::is_lal || ctx_t::is_lan || ctx_t::is_lao
232 || ctx_t::is_lat || ctx_t::is_law);
233 return vcsn::detail::static_if<valid>
234 ([](
const auto& a,
const auto&
l) ->
weight 237 return {*a->weightset(),
res};
239 [](
const auto& a,
const auto&) ->
weight 241 raise(
"evaluate: unsupported labelset: ",
244 (aut->
as<Aut>(), lbl->
as<LabelSet>().value());
250 template <Automaton Aut>
266 template <Automaton Aut,
typename PolynomialSet>
270 const auto& a = aut->
as<Aut>();
271 const auto& p = poly->
as<PolynomialSet>().value();
273 return {*a->weightset(),
res};
std::vector< weight_t > weights_t
state -> weight.
auto initial_transitions(const Aut &aut) -> decltype(aut->all_out(aut->pre()))
Indexes of transitions to (visible) initial states.
weight evaluate_polynomial(const automaton &aut, const polynomial &poly)
Bridge (evaluate).
typename detail::weightset_t_of_impl< base_t< ValueSet > >::type weightset_t_of
std::enable_if_t<!LabelSet::is_free(), weight_t > operator()(const word_t &word) const
Evaluation of a word.
typename detail::state_t_of_impl< base_t< ValueSet > >::type state_t_of
size_t states_size(const Aut &aut)
The largest state number, plus one.
state_t_of< automaton_t > state_t
bool is_proper(const Aut &aut)
Test whether an automaton is proper.
typename wps_t::value_t polynomial_t
labeled_weight(weight_t w_, word_t l_, state_t s_)
auto & as()
Extract wrapped typed value.
word_t_of< automaton_t > word_t
auto all_out(const Aut &aut, state_t_of< Aut > s)
Indexes of transitions leaving state s.
typename detail::context_t_of_impl< base_t< ValueSet > >::type context_t_of
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.
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.
Provide a variadic mul on top of a binary mul(), and one().
evaluator(const automaton_t &a)
context_t_of< automaton_t > context_t
typename detail::labelset_t_of_impl< base_t< ValueSet > >::type labelset_t_of
typename detail::label_t_of_impl< base_t< ValueSet > >::type label_t_of
Evaluate a word on an automaton.
law_t< labelset_t > wordset_t
typename law_traits< LabelSet >::type law_t
The smallest wordset that includes LabelSet.
auto & as()
Extract wrapped typed automaton.
auto make_word_polynomialset(const Ctx &ctx) -> word_polynomialset_t< Ctx >
The polynomialset of words of a labelset (not necessarily on words itself).
void swap(config::value &first, config::value &second)
typename weightset_t::value_t weight_t
auto weight_of(const welement< Label, Weight > &m) -> decltype(m.weight())
The weight of a welement.
auto label_of(const welement< Label, Weight > &m) -> decltype(m.label())
The label of a welement.
typename labelset_t_of< base_t< ValueSet > >::word_t word_t_of
std::enable_if_t< LabelSet::is_free(), weight_t > operator()(const word_t &word) const
law_t< LabelSet > make_wordset(const LabelSet &ls)
The wordset of a labelset.
weight_t operator()(const polynomial_t &poly) const
Polynomial implementation.
weightset_t_of< automaton_t > weightset_t
labelset_t_of< automaton_t > labelset_t
void require(Bool b, Args &&... args)
If b is not verified, raise an error with args as message.
typename detail::weight_t_of_impl< base_t< ValueSet > >::type weight_t_of
value_impl< detail::weight_tag > weight
auto out(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions leaving state s.