From 262e28b405ba6d5a14b6b93515f02ed55118b177 Mon Sep 17 00:00:00 2001 From: Romain BERNARD <romain.bernard@uca.fr> Date: Wed, 13 Mar 2024 16:00:21 +0100 Subject: [PATCH] fix state domination rules (might be able to optimize, see TODO) --- src/ShortestPath/Transit/TransitAlgorithmState.h | 7 +++++-- .../Transit/TransitShortestPathPrecompute.cpp | 4 ++-- src/ShortestPath/Transit/TransitStateContainer.h | 8 ++++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/ShortestPath/Transit/TransitAlgorithmState.h b/src/ShortestPath/Transit/TransitAlgorithmState.h index 6a95a31..3af927b 100644 --- a/src/ShortestPath/Transit/TransitAlgorithmState.h +++ b/src/ShortestPath/Transit/TransitAlgorithmState.h @@ -159,8 +159,11 @@ public: * @return */ [[nodiscard]] bool strictlyDominates(const TransitAlgorithmState& rhs) const { - return (this->getInstant() < rhs.getInstant() && this->getConnections().size() <= rhs.getConnections().size()) - || (this->getInstant() == rhs.getInstant() && this->getConnections().size() < rhs.getConnections().size()); + return this->getNodeIndex() == rhs.getNodeIndex() + && this->getLastConnectionLine() == rhs.getLastConnectionLine() +// /*TODO : check */ && (this->getLastConnectionLine() == rhs.getLastConnectionLine() || this->getNbConnections() == 2) /***/ + && ((this->getInstant() < rhs.getInstant() && this->getConnections().size() <= rhs.getConnections().size()) + || (this->getInstant() == rhs.getInstant() && this->getConnections().size() < rhs.getConnections().size())); } /** diff --git a/src/ShortestPath/Transit/TransitShortestPathPrecompute.cpp b/src/ShortestPath/Transit/TransitShortestPathPrecompute.cpp index 8ae226a..7354508 100644 --- a/src/ShortestPath/Transit/TransitShortestPathPrecompute.cpp +++ b/src/ShortestPath/Transit/TransitShortestPathPrecompute.cpp @@ -65,8 +65,8 @@ TransitStateContainer TransitShortestPathPrecompute::executeAlgorithm(const Grap //Add new state to the solution container and the priority queue if it's not strictly dominated by an existing solution if(newState.getNodeIndex() != -1 && !solutionsContainer.strictlyDominates(newState)) { - DEBUG_MSG("Candidate state " + newState.toString() + " is being added to solution container and priority queue\n"); - solutionsContainer.addNewState(nextNode, newState); + DEBUG_MSG("Candidate state " + newState.toString() + " added to priority queue\n"); + solutionsContainer.replaceBestSolutionIfNecessary(nextNode, newState); statePriorityQueue.emplace(newState); } } diff --git a/src/ShortestPath/Transit/TransitStateContainer.h b/src/ShortestPath/Transit/TransitStateContainer.h index 5ce38b2..2f0a61f 100644 --- a/src/ShortestPath/Transit/TransitStateContainer.h +++ b/src/ShortestPath/Transit/TransitStateContainer.h @@ -63,10 +63,14 @@ public: void resizeSolutionsVector(int nbNodes){ solutionVector.resize(nbNodes);} - void addNewState(int nodeIndex, const TransitAlgorithmState& newState) + void replaceBestSolutionIfNecessary(int nodeIndex, const TransitAlgorithmState& newState) { if(newState.getNbConnections() > 0) { - solutionVector.at(nodeIndex).at(newState.getNbConnections() - 1) = newState; + TransitAlgorithmState& currentBest = solutionVector.at(nodeIndex).at(newState.getNbConnections() - 1); + if(currentBest.getInstant() > newState.getInstant()) { + DEBUG_MSG("Candidate state " + newState.toString() + " is the new fastest solution"); + solutionVector.at(nodeIndex).at(newState.getNbConnections() - 1) = newState; + } } } -- GitLab