From dbc00a67b65b203e7e80cdcfb3b196a9d7e48b15 Mon Sep 17 00:00:00 2001
From: Romain BERNARD <romain.bernard@uca.fr>
Date: Thu, 29 Feb 2024 10:48:08 +0100
Subject: [PATCH] fix endless loop. Line changes still seem borked

---
 .../Transit/TransitAlgorithmState.h             |  4 ++--
 .../Transit/TransitStateContainer.h             | 17 +++++++++++++++--
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/ShortestPath/Transit/TransitAlgorithmState.h b/src/ShortestPath/Transit/TransitAlgorithmState.h
index f0cfded..48707ee 100644
--- a/src/ShortestPath/Transit/TransitAlgorithmState.h
+++ b/src/ShortestPath/Transit/TransitAlgorithmState.h
@@ -116,8 +116,8 @@ public:
      */
     [[nodiscard]] bool strictlyDominates(const TransitAlgorithmState& rhs) const {
         return this->_nodeIndex == rhs.getNodeIndex() //same current node
-               && ((this->getInstant() < rhs.getInstant() && (this->getConnections().size() <= rhs.getConnections().size() || rhs.getConnections().empty()))
-               || (this->getInstant() < rhs.getInstant() && this->getConnections().size() == rhs.getConnections().size()));
+               && ((!this->getConnections().empty() && rhs.getConnections().empty())
+               || (this->getInstant() <= rhs.getInstant() && this->getConnections().size() <= rhs.getConnections().size()));
     }
 
     /**
diff --git a/src/ShortestPath/Transit/TransitStateContainer.h b/src/ShortestPath/Transit/TransitStateContainer.h
index b962c0b..2b8a88d 100644
--- a/src/ShortestPath/Transit/TransitStateContainer.h
+++ b/src/ShortestPath/Transit/TransitStateContainer.h
@@ -8,6 +8,13 @@
 #include <vector>
 #include "TransitShortestPath.h"
 
+#ifdef DEBUG_TRANSIT_PRECOMPUTE
+#include <iostream>
+#define DEBUG_MSG(str) do { std::cout << str << std::endl; } while( false )
+#else
+#define DEBUG_MSG(str) do { } while ( false )
+#endif
+
 class TransitStateContainer {
 private:
     //    int x,delta;
@@ -32,13 +39,19 @@ public:
 
     bool tryAddNewState(int nodeIndex, const TransitAlgorithmState& newState)
     {
-        if(newState.strictlyDominates(solutionVector.at(nodeIndex)[0])) {
+        DEBUG_MSG("Trying to add state " + newState.toString());
+        if(!solutionVector.at(nodeIndex).empty() && newState.strictlyDominates(solutionVector.at(nodeIndex)[0])) {
+            DEBUG_MSG("Added state to position 0, replacing " + solutionVector.at(nodeIndex)[0].toString());
             solutionVector.at(nodeIndex)[0] = newState;
             return true;
-        } else if(newState.strictlyDominates(solutionVector.at(nodeIndex)[1])) {
+        } else if(solutionVector.at(nodeIndex).size() > 1 && newState.strictlyDominates(solutionVector.at(nodeIndex)[1])) {
+            DEBUG_MSG("Added state to position 1, replacing " + solutionVector.at(nodeIndex)[1].toString());
             solutionVector.at(nodeIndex)[1] = newState;
             return true;
         } else {
+            DEBUG_MSG("State wasn't added to the container because it doesn't dominate \n" +
+                        solutionVector.at(nodeIndex)[0].toString() +
+                        (solutionVector.at(nodeIndex).size() > 1 ? "\nor " + solutionVector.at(nodeIndex)[1].toString() : ""));
             return false;
         }
     }
-- 
GitLab