17 template <Automaton Aut>
21 "evaluate: requires free labelset");
23 using automaton_t = Aut;
27 using weight_t =
typename weightset_t::value_t;
30 using weights_t = std::vector<weight_t>;
37 weight_t operator()(
const word_t& word)
const
40 const weight_t zero = ws_.zero();
50 weights_t v1(2, zero);
52 v1[aut_->pre()] = ws_.one();
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]))
63 for (
auto t :
out(aut_, s, l))
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()];
92 const weightset_t& ws_ = *aut_->weightset();
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();
std::shared_ptr< const detail::weight_base > weight
bool is_proper(const Aut &aut)
Test whether an automaton is proper.
weight make_weight(const WeightSet &ws, const typename WeightSet::value_t &w)
void require(Bool b, Args &&...args)
If b is not verified, raise an error with args as message.
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.
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
static dyn::context ctx(const driver &d)
Get the context of the driver.
typename labelset_t_of< base_t< ValueSet >>::word_t word_t_of
auto initial_transitions(const Aut &aut) -> decltype(aut->all_out(aut->pre()))
Indexes of transitions to (visible) initial states.
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
std::shared_ptr< const detail::label_base > label
auto out(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions leaving state s.
weight eval(const automaton &aut, const label &lbl)
Bridge.
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of
Container::value_type back(const Container &container)
The last member of this Container.
auto all_out(const Aut &aut, state_t_of< Aut > s)
Indexes of transitions leaving state s.
std::shared_ptr< detail::automaton_base > automaton