From b9a2b94e200b9380950698dcb9c274878695dd37 Mon Sep 17 00:00:00 2001 From: Romain BERNARD <romain.bernard@uca.fr> Date: Tue, 12 Mar 2024 18:05:37 +0100 Subject: [PATCH] fix index oob errors --- src/ShortestPath/Transit/TransitStateContainer.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ShortestPath/Transit/TransitStateContainer.h b/src/ShortestPath/Transit/TransitStateContainer.h index 6adf18b..5ce38b2 100644 --- a/src/ShortestPath/Transit/TransitStateContainer.h +++ b/src/ShortestPath/Transit/TransitStateContainer.h @@ -44,12 +44,15 @@ public: * @return The first solution of potentially two saved in this array */ std::vector<TransitAlgorithmState>& getBestSolutions(int nodeIndex){ return solutionVector.at(nodeIndex);} - TransitAlgorithmState& getBestSolution(int nodeIndex, int nbConnections){ return solutionVector.at(nodeIndex)[nbConnections];} + TransitAlgorithmState& getBestSolution(int nodeIndex, int nbConnections){ return solutionVector.at(nodeIndex).at(nbConnections == 0 ? 0 : nbConnections - 1);} 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); + if(state.getNodeIndex() != -1) + return getBestSolution(state.getNodeIndex(), state.getNbConnections()).strictlyDominates(state); + else + return true; } @@ -62,9 +65,8 @@ public: void addNewState(int nodeIndex, const TransitAlgorithmState& newState) { - DEBUG_MSG("Trying to add state " + newState.toString()); if(newState.getNbConnections() > 0) { - solutionVector.at(nodeIndex)[newState.getNbConnections()] = newState; + solutionVector.at(nodeIndex).at(newState.getNbConnections() - 1) = newState; } } -- GitLab