18 template <Automaton Aut>
37 std::vector<path<automaton_t>>
42 auto res = std::vector<path<automaton_t>>{};
44 queue.emplace(
aut_,
aut_->null_transition(),
52 tree.get_weight_of(src));
54 for (
int k = 0; k < K && !queue.empty(); k++)
56 auto k_path_implicit = std::move(queue.top());
59 auto k_path = k_path_implicit.explicit_path(
res, tree, src);
60 if (k_path.get_path().empty())
63 res.emplace_back(std::move(k_path));
84 const auto& ws = *
aut_->weightset();
85 const auto& k_path_cost = k_path_implicit.
get_weight();
86 auto transition_stack = std::vector<transition_t>{};
89 transition_stack.push_back(tr);
91 while (!transition_stack.empty())
94 transition_stack.pop_back();
96 bool has_curr =
has(sidetracks, curr);
100 if (parent ==
aut_->null_state() || parent !=
aut_->dst_of(curr))
105 = ws.rdivide(ws.mul(
aut_->weight_of(curr),
113 queue.emplace(
aut_, curr, k,
114 ws.mul(k_path_cost, sidetracks[curr]));
117 transition_stack.push_back(tr);
127 template <Automaton Aut>
128 std::vector<detail::path<Aut>>
ATTRIBUTE_PURE bool has(const boost::container::flat_set< Key, Compare, Allocator > &s, const Key &e)
Whether e is member of s.
weight_t_of< automaton_t > weight_t
typename detail::transition_t_of_impl< base_t< ValueSet > >::type transition_t_of
typename detail::state_t_of_impl< base_t< ValueSet > >::type state_t_of
transition_t_of< automaton_t > transition_t
Implicit Path representation.
Eppstein implementation of the K shortest path problem adapted to Vcsn.
std::vector< detail::path< Aut > > compute_eppstein(const Aut &aut, state_t_of< Aut > src, state_t_of< Aut > dst, unsigned num)
Compute the num lightest paths in the automaton aut from src to dst.
transition_t get_sidetrack() const
void add_children_to_queue_(sidetrack_costs_t &sidetracks, state_t src, const implicit_path_t &k_path_implicit, int k, queue_t &queue, shortest_path_tree< automaton_t > &tree)
Update queue with children of the first state in the sidetrack path.
eppstein(const automaton_t &aut)
weight_t get_weight_of(state_t s) const
const weight_t & get_weight() const
auto all_out(const Aut &aut, state_t_of< Aut > s)
Indexes of transitions leaving state s.
shortest_path_tree< Aut > make_shortest_path_tree(const Aut &aut, state_t_of< Aut > root)
state_t_of< automaton_t > state_t
static constexpr int null_parent_path
vcsn::min_fibonacci_heap< implicit_path_t > queue_t
std::unordered_map< transition_t, weight_t > sidetrack_costs_t
state_t get_parent_of(state_t s) const
std::vector< path< automaton_t > > k_shortest_path(state_t src, state_t dst, int K)
Compute the K shortest paths in the automaton from src to dst.
boost::heap::fibonacci_heap< Elt, detail::comparator_t< Elt > > min_fibonacci_heap
typename detail::weight_t_of_impl< base_t< ValueSet > >::type weight_t_of