3 #include <boost/optional.hpp>
27 template <Automaton Aut>
28 boost::optional<std::vector<transition_t_of<Aut>>>
33 auto dist = std::vector<weight_t_of<Aut>>(
size);
34 auto res = std::vector<transition_t>(
size, aut->null_transition());
35 auto ws = *aut->weightset();
37 dist[source] = ws.one();
40 for (
auto _: aut->all_states())
43 auto src = aut->src_of(t);
45 if (res[src] != aut->null_transition() || src == source)
47 auto dst = aut->dst_of(t);
48 auto nw = ws.mul(dist[src], aut->weight_of(t));
49 if (res[dst] == aut->null_transition()
50 || ws.less(nw, dist[dst]))
61 auto src = aut->src_of(t);
62 auto dst = aut->dst_of(t);
63 if (res[src] != aut->null_transition()
64 && (res[dst] == aut->null_transition()
65 || ws.less(ws.mul(dist[src], aut->weight_of(t)), dist[dst])))
69 return std::move(res);
75 template <Automaton Aut>
76 std::vector<transition_t_of<Aut>>
81 require(
res,
"bellman-ford: automaton with negative cycle");
82 return std::move(*
res);
auto transitions(const Aut &aut) -> decltype(all_transitions(aut, is_special_t< Aut >
All the transition indexes between visible states.
typename detail::transition_t_of_impl< base_t< ValueSet >>::type transition_t_of
size_t states_size(const Aut &aut)
The largest state number, plus one.
size_t size(const ExpSet &rs, const typename ExpSet::value_t &r)
void require(Bool b, Args &&...args)
If b is not verified, raise an error with args as message.
auto all_transitions(const Aut &aut)
All the transition indexes between all states (including pre and post).
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
Bellman-Ford implementation (from vcsn/algos/bellman-ford.hh).
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.
std::vector< transition_t_of< Aut > > lightest_path(const Aut &aut, state_t_of< Aut > source, state_t_of< Aut > dest, a_star_tag)