From 3544acf4aa7d32cb28699fa2bb9b46eea212bb8a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Tr=C3=A1vn=C3=AD=C4=8Dek?= <travnja3@fit.cvut.cz>
Date: Wed, 23 Jun 2021 16:35:35 +0200
Subject: [PATCH] graph algo: fix Dijkstra's algo

---
 alib2graph_algo/src/shortest_path/Dijkstra.hpp | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/alib2graph_algo/src/shortest_path/Dijkstra.hpp b/alib2graph_algo/src/shortest_path/Dijkstra.hpp
index 4a25f1f472..fff9385e15 100644
--- a/alib2graph_algo/src/shortest_path/Dijkstra.hpp
+++ b/alib2graph_algo/src/shortest_path/Dijkstra.hpp
@@ -292,10 +292,12 @@ bool Dijkstra::relaxation(FEdges successor_edges,
     // If not or the distance can be improve do relaxation
     if (search_d == data.g.end() || search_d->second > gscore) {
       // Search if the node s is in OPEN
-      auto search_q = data.queue.find(ext::make_pair(search_d->second, s));
-      if (search_q != data.queue.end()) {
-        // Erase node from priority queue
-        data.queue.erase(search_q);
+      if (search_d != data.g.end()) {
+        auto search_q = data.queue.find(ext::make_pair(search_d->second, s));
+        if (search_q != data.queue.end()) {
+          // Erase node from priority queue
+          data.queue.erase(search_q);
+        }
       }
 
       data.g[s] = gscore;
-- 
GitLab