Vcsn  2.2a
Be Rational
weight-series.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vcsn/algos/eval.hh>
6 #include <vcsn/algos/proper.hh>
7 #include <vcsn/dyn/fwd.hh>
8 #include <vcsn/dyn/automaton.hh>
9 #include <vcsn/dyn/weight.hh>
10 #include <vcsn/weightset/fwd.hh> // nmin
11 
12 namespace vcsn
13 {
14  template <Automaton Aut>
15  inline
16  auto
17  weight_series(const Aut& a)
18  -> std::enable_if_t<!is_tropical<weightset_t_of<Aut>>::value,
20  {
21  auto aut = proper(to_spontaneous(a));
22  return eval(aut);
23  }
24 
25  template <Automaton Aut>
26  inline
27  auto
28  weight_series(const Aut& a)
29  -> std::enable_if_t<is_tropical<weightset_t_of<Aut>>::value,
30  weight_t_of<Aut>>
31  {
32  auto res = path_monomial(a, lightest_path(a));
33  return res ? res->second : a->weightset()->zero();
34  }
35 
36  namespace dyn
37  {
38  namespace detail
39  {
41  template <Automaton Aut>
42  weight
44  {
45  const auto& a = aut->as<Aut>();
46  auto res = ::vcsn::weight_series(a);
47  const auto& ctx = a->context();
48  return make_weight(*ctx.weightset(), res);
49  }
50  }
51  }
52 } // namespace vcsn
auto to_spontaneous(const Aut &aut) -> std::enable_if_t<!context_t_of< Aut >::is_lao, decltype(make_mutable_automaton(make_context(oneset(), *aut->weightset())))>
to_spontaneous
A dyn automaton.
Definition: automaton.hh:19
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.
Definition: eval.hh:101
auto proper(const Aut &aut, direction dir=direction::backward, bool prune=true, const std::string &algo="auto") -> fresh_automaton_t_of< Aut, detail::proper_context< context_t_of< Aut >>>
Eliminate spontaneous transitions.
Definition: proper.hh:236
std::vector< transition_t_of< Aut > > lightest_path(const Aut &aut, state_t_of< Aut > source, state_t_of< Aut > dest, a_star_tag)
Definition: a-star.hh:151
std::shared_ptr< const detail::weight_base > weight
Definition: fwd.hh:71
weight weight_series(const automaton &aut)
Bridge.
weight make_weight(const WeightSet &ws, const typename WeightSet::value_t &w)
Definition: weight.hh:79
auto weight_series(const Aut &a) -> std::enable_if_t<!is_tropical< weightset_t_of< Aut >>::value, weight_t_of< Aut >>
static dyn::context ctx(const driver &d)
Get the context of the driver.
Definition: parse.cc:82
auto path_monomial(const Aut &aut, const std::vector< transition_t_of< Aut >> &path, state_t_of< Aut > src=Aut::element_type::pre(), state_t_of< Aut > dst=Aut::element_type::post()) -> boost::optional< typename detail::word_polynomialset_t< context_t_of< Aut >>::monomial_t >
Given a path (typically computed by lightest_path), the corresponding monomial (label, weight).
auto & as()
Extract wrapped typed automaton.
Definition: automaton.hh:39
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of
Definition: traits.hh:58
Definition: a-star.hh:8