25 template <Automaton Aut>
26 boost::optional<std::vector<transition_t_of<Aut>>>
30 auto size = aut->all_states().back() + 1;
31 auto dist = std::vector<weight_t_of<Aut>>(
size);
32 auto res = std::vector<transition_t>(
size, aut->null_transition());
33 auto ws = *aut->weightset();
35 dist[source] = ws.one();
38 for (
auto _: aut->all_states())
41 auto src = aut->src_of(t);
43 if (res[src] != aut->null_transition() || src == source)
45 auto dst = aut->dst_of(t);
46 auto nw = ws.mul(dist[src], aut->weight_of(t));
47 if (res[dst] == aut->null_transition()
48 || ws.less(nw, dist[dst]))
59 auto src = aut->src_of(t);
60 auto dst = aut->dst_of(t);
61 if (res[src] != aut->null_transition()
62 && (res[dst] == aut->null_transition()
63 || ws.less(ws.mul(dist[src], aut->weight_of(t)), dist[dst])))
67 return std::move(res);
73 template <Automaton Aut>
74 std::vector<transition_t_of<Aut>>
79 require(res,
"bellman-ford: automaton with negative cycle");
80 return std::move(*res);
void require(Bool b, Args &&...args)
If b is not verified, raise an error with args as message.
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
typename detail::transition_t_of_impl< base_t< ValueSet >>::type transition_t_of
auto transitions(const Aut &aut) -> decltype(all_transitions(aut, is_special_t< Aut >
All the transition indexes between visible states.
Bellman-Ford implementation (from vcsn/algos/bellman-ford.hh).
auto all_transitions(const Aut &aut)
All the transition indexes between all states (including pre and post).
size_t size(const ExpSet &rs, const typename ExpSet::value_t &r)
std::vector< transition_t_of< Aut > > lightest_path(const Aut &aut, state_t_of< Aut > source, state_t_of< Aut > dest, a_star_tag)
boost::optional< std::vector< transition_t_of< Aut > > > bellman_ford_impl(const Aut &aut, state_t_of< Aut > source)
Bellman-Ford implementation of lightest automaton.