From fcd4c4ff300a8496718ed2a0b5ddbda9d03161e6 Mon Sep 17 00:00:00 2001 From: dmatetelki Date: Mon, 24 Aug 2015 14:43:09 +0200 Subject: [PATCH] source is not in q --- lib/graph/graph_algorithms.hpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/graph/graph_algorithms.hpp b/lib/graph/graph_algorithms.hpp index 3042a9d..e928d1c 100644 --- a/lib/graph/graph_algorithms.hpp +++ b/lib/graph/graph_algorithms.hpp @@ -54,15 +54,16 @@ dijkstra_shortest_path_to(const Graph& graph, const V& dest, std::function distanceCompute) { - std::unordered_map dist; /// @todo into std::priority_queue> + std::unordered_map dist; std::unordered_map prev; dist.emplace(source, W()); - std::unordered_set q; - q.insert(source); - const std::vector& s_n = graph.neighboursOf(source); - std::copy(s_n.begin(), s_n.end(), std::inserter(q, q.end())); + for (const auto& v : graph.neighboursOf(source)) { + q.insert(v); + dist[v] = distanceCompute(source, v); + prev[v] = source; + } while (!q.empty()) { const V& u = closestNode(q, dist);