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>
113 template <Automaton Aut>
119 require(
is_proper(a),
"eval: cannot evaluate with spontaneous transitions");
120 const auto& ws = *a->weightset();
121 auto res = ws.zero();
124 auto s = a->dst_of(init_tr);
125 auto w = a->weight_of(init_tr);
128 assert(a->dst_of(
out) == a->post());
129 res = ws.add(res, ws.mul(w, a->weight_of(
out)));
140 template <Automaton Aut,
typename LabelSet>
144 const auto& a = aut->as<Aut>();
145 const auto& l = lbl->as<LabelSet>().
label();
147 const auto&
ctx = a->context();
bool is_proper(const Aut &aut)
Test whether an automaton is proper.
auto all_out(const Aut &aut, state_t_of< Aut > s)
Indexes of transitions leaving state s.
Container::value_type back(const Container &container)
The last member of this Container.
typename weightset_t::value_t weight_t
std::shared_ptr< const detail::weight_base > weight
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
void require(Bool b, Args &&...args)
If b is not verified, raise an error with args as message.
weight make_weight(const WeightSet &ws, const typename WeightSet::value_t &w)
weightset_t_of< automaton_t > weightset_t
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
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
std::shared_ptr< const detail::label_base > label
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.
auto initial_transitions(const Aut &aut) -> decltype(aut->all_out(aut->pre()))
Indexes of transitions to (visible) initial states.
std::vector< weight_t > weights_t
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.
evaluator(const automaton_t &a)
std::shared_ptr< detail::automaton_base > automaton
state_t_of< automaton_t > state_t
static dyn::context ctx(const driver &d)
Get the context of the driver.
word_t_of< automaton_t > word_t
typename labelset_t_of< base_t< ValueSet >>::word_t word_t_of
weight eval(const automaton &aut, const label &lbl)
Bridge.