From 636a16aed1a791dbc3e9abbc35abbe0b49d2076b Mon Sep 17 00:00:00 2001
From: Romain BERNARD <romain.bernard@uca.fr>
Date: Mon, 11 Mar 2024 17:34:55 +0100
Subject: [PATCH] simplify notations and state container behaviour

---
 .../Transit/TransitShortestPathPrecompute.cpp          | 10 +++++-----
 src/ShortestPath/Transit/TransitStateContainer.h       |  8 +++++++-
 src/instance/graph/Graph.h                             |  4 ++++
 src/instance/graph/LineStop.h                          |  4 +---
 4 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/src/ShortestPath/Transit/TransitShortestPathPrecompute.cpp b/src/ShortestPath/Transit/TransitShortestPathPrecompute.cpp
index 01a72f4..27db781 100644
--- a/src/ShortestPath/Transit/TransitShortestPathPrecompute.cpp
+++ b/src/ShortestPath/Transit/TransitShortestPathPrecompute.cpp
@@ -29,14 +29,14 @@ TransitStateContainer TransitShortestPathPrecompute::executeAlgorithm(const Grap
         //Extract head from our state priority queue
         currentState = statePriorityQueue.top();
         statePriorityQueue.pop();
-        if(!solutionsContainer.getBestSolution(currentState.getNodeIndex()).strictlyDominates(currentState)) {
-            DEBUG_MSG("\n\nComparing state " + currentState.toString() + " and \n" + solutionsContainer.getBestSolution(currentState.getNodeIndex()).toString());
+        if(!solutionsContainer.strictlyDominates(currentState)) {
+            DEBUG_MSG("\n\nComparing state " + currentState.toString() + " and \n" + solutionsContainer.getBestSolution(currentState.getNodeIndex(), currentState.getNbConnections()).toString());
             DEBUG_MSG("State isn't dominated, trying to extend it");
-            for (auto& lineStop : graph.getNode(currentState.getNodeIndex()).getPTLinesSet())
+            for (auto& lineStop : graph.getPTLinesSet(currentState.getNodeIndex()))
             {
                 int nextNode = lineStop.getNextNodeIndex();
                 //If there is a proper next node and if it's not the same as our last used line stop predecessor
-                if(nextNode != -1 && (currentState.getConnections().empty() || nextNode != currentState.getConnections().back().getPrecedingNodeIndex())) {
+                if(nextNode != -1 && (currentState.isEmpty() || nextNode != currentState.getPrecedingNodeIndex())) {
                     TransitAlgorithmState newState; //define variable before conditionals
                     if(currentState.isEmpty() || currentState.getLastConnectionLine() != lineStop.getLineRef()) // if new line is different than current line
                     {
@@ -64,7 +64,7 @@ TransitStateContainer TransitShortestPathPrecompute::executeAlgorithm(const Grap
                     DEBUG_MSG("Created new state " + newState.toString());
 
                     //Add new state to the solution container and the priority queue if it's not strictly dominated by an existing solution
-                    if(!solutionsContainer.getBestSolution(currentState.getNodeIndex()).strictlyDominates(currentState)) {
+                    if(!solutionsContainer.strictlyDominates(currentState)) {
                         DEBUG_MSG("Candidate state " + newState.toString() + " is being added to solution container and priority queue");
                         solutionsContainer.addNewState(nextNode, newState);
                         statePriorityQueue.emplace(newState);
diff --git a/src/ShortestPath/Transit/TransitStateContainer.h b/src/ShortestPath/Transit/TransitStateContainer.h
index a1ed77f..6adf18b 100644
--- a/src/ShortestPath/Transit/TransitStateContainer.h
+++ b/src/ShortestPath/Transit/TransitStateContainer.h
@@ -43,10 +43,16 @@ public:
      * @param nodeIndex
      * @return The first solution of potentially two saved in this array
      */
-    TransitAlgorithmState& getBestSolution(int nodeIndex){ return solutionVector.at(nodeIndex)[0];}
+    std::vector<TransitAlgorithmState>& getBestSolutions(int nodeIndex){ return solutionVector.at(nodeIndex);}
+    TransitAlgorithmState& getBestSolution(int nodeIndex, int nbConnections){ return solutionVector.at(nodeIndex)[nbConnections];}
     std::vector<TransitAlgorithmState>& getSolutions(int nodeIndex){ return solutionVector.at(nodeIndex);}
     std::vector<std::vector<TransitAlgorithmState>>& getSolutionsVector(){ return solutionVector;}
 
+    bool strictlyDominates(const TransitAlgorithmState& state){
+        return getBestSolution(state.getNodeIndex(), state.getNbConnections()).strictlyDominates(state);
+    }
+
+
     /**
      * Resizes solution vector and initializes state vectors to be able to add our solutions during algorithm execution
      * @param nbNodes How many nodes there are in the full graph
diff --git a/src/instance/graph/Graph.h b/src/instance/graph/Graph.h
index 0f95d0b..c1b329d 100644
--- a/src/instance/graph/Graph.h
+++ b/src/instance/graph/Graph.h
@@ -42,6 +42,10 @@ public:
         return nodesVector.at(nodeIndex);
     }
 
+    [[nodiscard]] std::vector<LineStop> getPTLinesSet(int nodeIndex) const {
+        return nodesVector.at(nodeIndex).getPTLinesSet();
+    }
+
     /**
      * @return The graph's edge vector
      */
diff --git a/src/instance/graph/LineStop.h b/src/instance/graph/LineStop.h
index 5a1e195..e4883c2 100644
--- a/src/instance/graph/LineStop.h
+++ b/src/instance/graph/LineStop.h
@@ -22,9 +22,7 @@ public:
         return _lineRef;
     }
 
-    void setLineRef(Line &lineRef) {
-        _lineRef = lineRef;
-    }
+    [[nodiscard]] int getInstant(int stationIdx, int scheduleIdx) const { return _lineRef.getInstant(stationIdx, scheduleIdx); }
 
     /**
      * @return -1 if there are no valid successors to this LineStop's node. Returns the node index in the graph if there is a valid successor
-- 
GitLab