1 #ifndef VCSN_ALGOS_PUSH_WEIGHTS_HH
2 # define VCSN_ALGOS_PUSH_WEIGHTS_HH
5 # include <unordered_map>
25 template <
typename Aut>
30 return d[aut->post()];
35 template <
typename Aut>
36 std::unordered_map<state_t_of<Aut>, weight_t_of<Aut>>
40 for (
auto s : aut->states())
51 template <
typename Aut>
58 auto ws = *res->weightset();
59 distances[res->post()] = ws.one();
60 for (
auto t : res->all_transitions())
62 auto ds = distances[res->src_of(t)];
63 auto de = distances[res->dst_of(t)];
64 auto w = ws.mul(res->weight_of(t), de);
65 if (res->src_of(t) == res->pre())
66 res->set_weight(t, de);
67 else if (!ws.is_zero(ds))
68 res->set_weight(t, ws.rdiv(w, ds));
78 template <
typename Aut>
82 const auto& a = aut->as<Aut>();
93 #endif // !VCSN_ALGOS_PUSH_WEIGHTS_HH
REGISTER_DECLARE(accessible,(const automaton &) -> automaton)
std::shared_ptr< detail::automaton_base > automaton
weight_t_of< Aut > shortest_distance_to_finals(Aut aut, state_t_of< Aut > s0)
Find shorhest of s0 to the final states of aut by using single source shortest distance.
automaton make_automaton(const Aut &aut)
Build a dyn::automaton.
AutOut copy(const AutIn &input, Pred keep_state)
A copy of input keeping only its states that are accepted by keep_state.
std::unordered_map< state_t_of< Aut >, weight_t_of< Aut > > ss_shortest_distance(Aut aut, state_t_of< Aut > s0)
Single source shortest distance.
auto push_weights(const Aut &aut) -> decltype(::vcsn::copy(aut))
The algorithm weight pushing.
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
automaton push_weights(const automaton &aut)
Bridge.