3 #include <boost/optional.hpp> 27 template <Automaton Aut>
28 boost::optional<predecessors_t_of<Aut>>
32 auto dist = std::vector<weight_t_of<Aut>>(
size);
34 auto ws = *aut->weightset();
36 dist[source] = ws.one();
39 for (
auto _: aut->all_states())
44 auto src = aut->src_of(t);
46 if (res[src] != aut->null_transition() || src == source)
48 auto dst = aut->dst_of(t);
49 auto nw = ws.mul(dist[src], aut->weight_of(t));
50 if (res[dst] == aut->null_transition()
51 || ws.less(nw, dist[dst]))
62 auto src = aut->src_of(t);
63 auto dst = aut->dst_of(t);
64 return (res[src] != aut->null_transition()
65 && (res[dst] == aut->null_transition()
66 || ws.less(ws.mul(dist[src], aut->weight_of(t)),
78 template <Automaton Aut>
84 require(
res,
"bellman-ford: automaton with negative cycle");
85 return std::move(*
res);
auto all_transitions(const Aut &aut)
All the transition indexes between all states (including pre and post).
bool any_of(const Range &r, Predicate p)
size_t size(const ExpSet &rs, const typename ExpSet::value_t &r)
typename detail::state_t_of_impl< base_t< ValueSet > >::type state_t_of
size_t states_size(const Aut &aut)
The largest state number, plus one.
std::enable_if_t< weightset_t_of< Aut >::has_lightening_weights(), bool > has_lightening_cycle(const Aut &aut)
std::vector< transition_t_of< Aut > > lightest_path(const Aut &aut, state_t_of< Aut > source, state_t_of< Aut > dest, a_star_tag)
std::vector< transition_t_of< Aut > > predecessors_t_of
A state-indexed vector of predecessor transitions from the path path.
void require(Bool b, Args &&... args)
If b is not verified, raise an error with args as message.
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).
boost::optional< predecessors_t_of< Aut > > bellman_ford_impl(const Aut &aut, state_t_of< Aut > source)
Bellman-Ford implementation of lightest automaton.