22namespace shortest_path {
46 typename F = std::function<bool(
const TNode &,
47 const typename TGraph::edge_type::weight_type &)>>
52 F f_user = [](
const TNode &,
53 const typename TGraph::edge_type::weight_type &) ->
bool {
return false; });
76 typename F = std::function<void(
const TNode &,
77 const typename TGraph::edge_type::weight_type &)>>
83 F f_user = [](
const TNode &,
84 const typename TGraph::edge_type::weight_type &) {});
86 template<
typename TGraph,
typename TNode>
114 template<
typename TGraph,
116 typename F = std::function<void(
const TNode &,
117 const typename TGraph::edge_type::weight_type &)>>
123 F f_user = [](
const TNode &,
124 const typename TGraph::edge_type::weight_type &) {});
126 template<
typename TGraph,
typename TNode>
140 template<
typename TNode,
typename TWeight>
149 template<
typename TGraph,
typename TNode,
typename F1,
typename F2>
152 impl(
const TGraph &
graph,
161 template<
typename FEdges,
typename TNode,
typename TWeight,
typename F1,
typename F2,
typename F3>
162 static bool relaxation(FEdges successor_edges,
163 Data<TNode, TWeight> &data,
170 template<
typename TGraph,
typename TNode,
typename F1,
typename F2>
173 implBidirectional(
const TGraph &
graph,
181 template<
typename TNode,
typename TWeight>
182 inline static void init(Dijkstra::Data<TNode, TWeight> &data,
const TNode &
start);
192template<
typename TGraph,
typename TNode,
typename F>
195 impl(
graph,
start,
start, f_user, [](
const TNode &) ->
bool {
return false; });
200template<
typename TGraph,
typename TNode,
typename F>
208 [&](
const TNode &n,
const typename TGraph::edge_type::weight_type &w) ->
bool {
211 }, [&goal](
const TNode &n) ->
bool {
return goal == n; });
216template<
typename TGraph,
typename TNode,
typename F>
224 [&](
const TNode &n,
const typename TGraph::edge_type::weight_type &w) ->
bool {
228 [](
const TNode &) ->
bool {
return false; });
233template<
typename TGraph,
typename TNode,
typename F1,
typename F2>
235Dijkstra::impl(
const TGraph &
graph,
240 using weight_type =
typename TGraph::edge_type::weight_type;
242 Data<TNode, weight_type> data;
247 while (!data.queue.empty()) {
248 bool stop = relaxation([&](
const auto &
node) ->
auto {
return graph.successorEdges(
node); },
252 [](
const TNode &) ->
void {});
264template<
typename FEdges,
typename TNode,
typename TWeight,
typename F1,
typename F2,
typename F3>
265bool Dijkstra::relaxation(FEdges successor_edges,
266 Data<TNode, TWeight> &data,
270 TNode n = data.queue.begin()->second;
271 data.queue.erase(data.queue.begin());
274 if (f_user(n, data.g[n])) {
283 for (
const auto &s_edge: successor_edges(n)) {
287 if (s_edge.weight() < 0) {
288 throw std::out_of_range(
"Dijkstra: Detect negative weight on edge in graph.");
292 TWeight gscore = data.g.at(n) + s_edge.weight();
295 auto search_d = data.g.find(s);
298 if (search_d == data.g.end() || search_d->second > gscore) {
300 if (search_d != data.g.end()) {
301 auto search_q = data.queue.find(
ext::make_pair(search_d->second, s));
302 if (search_q != data.queue.end()) {
304 data.queue.erase(search_q);
309 data.p.insert_or_assign(s, n);
321template<
typename TGraph,
typename TNode,
typename F1,
typename F2>
323Dijkstra::implBidirectional(
const TGraph &
graph,
328 using weight_type =
typename TGraph::edge_type::weight_type;
335 Data<TNode, weight_type> forward_data;
336 Data<TNode, weight_type> backward_data;
339 init(forward_data,
start);
340 auto f_forward_update = [&](
const auto &s) ->
void {
341 if (backward_data.g.find(s) != backward_data.g.end()) {
342 if (forward_data.g.at(s) + backward_data.g.at(s) < p) {
343 p = forward_data.g.at(s) + backward_data.g.at(s);
344 intersection_nodes.push_back(s);
350 init(backward_data, goal);
351 auto f_backward_update = [&](
const auto &s) ->
void {
352 if (forward_data.g.find(s) != forward_data.g.end()) {
353 if (backward_data.g.at(s) + forward_data.g.at(s) < p) {
354 p = backward_data.g.at(s) + forward_data.g.at(s);
355 intersection_nodes.push_back(s);
360 while (!forward_data.queue.empty() && !backward_data.queue.empty()) {
361 if (forward_data.queue.begin()->first + backward_data.queue.begin()->first + eps >= p) {
368 intersection_nodes.back());
372 if (forward_data.queue.begin()->first < backward_data.queue.begin()->first) {
374 relaxation([&](
const auto &
node) ->
auto {
return graph.successorEdges(
node); },
381 relaxation([&](
const auto &
node) ->
auto {
return graph.predecessorEdges(
node); },
394template<
typename TNode,
typename TWeight>
395void Dijkstra::init(Dijkstra::Data<TNode, TWeight> &data,
const TNode &
start) {
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
static ext::pair< ext::vector< TNode >, TWeight > reconstructWeightedPath(const ext::map< TNode, TNode > &p, const ext::map< TNode, TWeight > &g, const TNode &start, const TNode &goal)
Definition: ReconstructPath.hpp:132
static TGraph::edge_type::weight_type getMinEdgeValue(const TGraph &graph)
Definition: SupportFunction.hpp:71
static TNode const & other(const TEdge &e, const TNode &n)
Definition: Dijkstra.hpp:24
static ext::pair< ext::vector< TNode >, typename TGraph::edge_type::weight_type > findPath(const TGraph &graph, const TNode &start, const TNode &goal, F f_user=[](const TNode &, const typename TGraph::edge_type::weight_type &) {})
Definition: Dijkstra.hpp:202
static void run(const TGraph &graph, const TNode &start, F f_user=[](const TNode &, const typename TGraph::edge_type::weight_type &) -> bool { return false;})
Definition: Dijkstra.hpp:193
static ext::pair< ext::vector< TNode >, typename TGraph::edge_type::weight_type > findPathBidirectional(const TGraph &graph, const TNode &start, const TNode &goal, F f_user=[](const TNode &, const typename TGraph::edge_type::weight_type &) {})
Definition: Dijkstra.hpp:218
static ext::pair< ext::vector< TNode >, typename TGraph::edge_type::weight_type > findPathRegistration(const TGraph &graph, const TNode &start, const TNode &goal)
Definition: Dijkstra.hpp:89
static ext::pair< ext::vector< TNode >, typename TGraph::edge_type::weight_type > findPathBidirectionalRegistration(const TGraph &graph, const TNode &start, const TNode &goal)
Definition: Dijkstra.hpp:129
constexpr const T & max(const T &a)
Root case of maximum computation. The maximum from one value is the value itself.
Definition: algorithm.hpp:278
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
Definition: ReconstructPath.hpp:14
void start(measurements::stealth_string name, measurements::Type type)
Definition: measurements.cpp:14