diff --git a/src/ShortestPath/Transit/TransitAlgorithmState.h b/src/ShortestPath/Transit/TransitAlgorithmState.h index 6a95a312583df54f6fe8592117a569560eaedfb5..3af927b5f87e5e5e86b9efc0cdf60f213e268284 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 8ae226a00d7296b8f2e975325cbce4dc075b1d22..7354508711ac8c2651d8f5fcbc18b0576260124d 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 5ce38b2e6d712d6d1fdc3692845cb5d78c7c1b2d..2f0a61f635a15d77e4577af608a10d09ef725bcc 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; + } } }