17 #ifndef AWALI_ALGOS_EVAL_HH
18 # define AWALI_ALGOS_EVAL_HH
26 namespace awali {
namespace sttc {
30 template <
typename Aut>
34 "requires free labelset");
36 using automaton_t = Aut;
39 using weight_t =
typename weightset_t::value_t;
43 using weights_t = std::vector<weight_t>;
49 , ls_(*a_->labelset())
52 void check(
const word_t& word)
const {
54 if(!ls_.genset().has(l))
55 throw std::invalid_argument(
"The word contains some unexpected letters");
61 const weight_t zero = ws_.zero();
67 const auto&
states = a_->states();
68 unsigned last_state = *std::max_element(std::begin(
states),
73 weights_t v1(last_state + 1, zero);
74 v1[a_->pre()] = ws_.one();
85 for (
auto l : lsw.delimit(word))
87 v2.assign(v2.size(), zero);
88 for (
unsigned s = 0; s < v1.size(); ++s)
89 if (!ws_.is_zero(v1[s]))
90 for (
auto t : a_->out(s, l))
95 ws_.add(v2[a_->dst_of(t)],
96 ws_.mul(v1[s], a_->weight_of(t)));
99 return v1[a_->post()];
102 const automaton_t& a_;
103 const weightset_t& ws_;
104 const labelset_t& ls_;
109 template <
typename Aut>
evaluator(const automaton_t &a)
Definition: eval.hh:46
void check(const word_t &word) const
Definition: eval.hh:52
weight_t operator()(const word_t &word) const
Definition: eval.hh:58
weightset_description weightset(const std::string &k)
std::vector< state_t > states(abstract_automaton_t const *aut, bool all)
any_t word_t
Type for words; it is an alias to any_t since the precise type depends on the context (most of the ti...
Definition: typedefs.hh:67
auto eval(const Aut &a, const typename labelset_trait< labelset_t_of< Aut >>::wordset_t::word_t &w, bool check_alphabet=true) -> weight_t_of< Aut >
Definition: eval.hh:112
typename internal::weight_t_of_impl< internal::base_t< ValueSet > >::type weight_t_of
Helper to retrieve the type of the weights of a value set.
Definition: traits.hh:81
typename internal::labelset_t_of_impl< internal::base_t< ValueSet > >::type labelset_t_of
Helper to retrieve the type of the labelset of a value set.
Definition: traits.hh:76
auto get_wordset(const L &labelset) -> typename labelset_trait< L >::wordset_t
Definition: traits.hh:232
typename internal::weightset_t_of_impl< internal::base_t< ValueSet > >::type weightset_t_of
Helper to retrieve the type of the weightset of a value set.
Definition: traits.hh:86
Main namespace of Awali.
Definition: ato.hh:22
trait that computes the related types of a labelset
Definition: traits.hh:34