From 5c8720ecc2ec634c5945bc1c332b9b3b315f4755 Mon Sep 17 00:00:00 2001 From: Romain BERNARD <romain.bernard@uca.fr> Date: Mon, 18 Mar 2024 18:30:05 +0100 Subject: [PATCH] refactor shortest paths --- src/ShortestPath/ShortestPath.h | 13 +++---------- .../Transit/TransitShortestPath.h | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/ShortestPath/ShortestPath.h b/src/ShortestPath/ShortestPath.h index c498ece..8ad3290 100644 --- a/src/ShortestPath/ShortestPath.h +++ b/src/ShortestPath/ShortestPath.h @@ -9,26 +9,19 @@ template <typename KeyPoint> class ShortestPath { - int _duration; +protected: std::vector<KeyPoint> _keyPoints; - explicit ShortestPath(int duration) { _duration = duration;} public: - [[nodiscard]] int getDuration() const { - return _duration; - } - - void setDuration(int duration) { - _duration = duration; - } + explicit ShortestPath() = default; [[nodiscard]] const std::vector<KeyPoint> &getKeyPoints() const { return _keyPoints; } void replaceKeyPoint(int keyPointIndex, KeyPoint& value) { - _keyPoints.assign(keyPointIndex, value); + _keyPoints.at(keyPointIndex) = value; } /** diff --git a/src/ShortestPath/Transit/TransitShortestPath.h b/src/ShortestPath/Transit/TransitShortestPath.h index 64be4fd..9aee17c 100644 --- a/src/ShortestPath/Transit/TransitShortestPath.h +++ b/src/ShortestPath/Transit/TransitShortestPath.h @@ -10,8 +10,15 @@ #include "TransitAlgorithmState.h" class TransitShortestPath : public ShortestPath<LineStop> { +private: + int _arrivalTime; public: + explicit TransitShortestPath(const TransitAlgorithmState& state) { + _arrivalTime = state.getInstant(); + std::move(state.getConnections().begin(), state.getConnections().end(),_keyPoints.begin()); + } + /** * Strict dominance between two transit shortest path * @param rhs @@ -19,19 +26,21 @@ public: */ [[nodiscard]] bool strictlyDominates(const TransitShortestPath& rhs) const { return this->getKeyPoints().size() <= rhs.getKeyPoints().size() - && this->getDuration() <= rhs.getDuration(); + && this->getArrivalTime() <= rhs.getArrivalTime(); } bool operator<(const TransitShortestPath& rhs) const { - return this->getDuration() < rhs.getDuration() || - (this->getDuration() == rhs.getDuration() && this->getKeyPoints().size() < rhs.getKeyPoints().size()); + return this->getArrivalTime() < rhs.getArrivalTime() || + (this->getArrivalTime() == rhs.getArrivalTime() && this->getKeyPoints().size() < rhs.getKeyPoints().size()); } bool operator>(const TransitShortestPath& rhs) const { - return this->getDuration() > rhs.getDuration() || - (this->getDuration() == rhs.getDuration() && this->getKeyPoints().size() > rhs.getKeyPoints().size()); + return this->getArrivalTime() > rhs.getArrivalTime() || + (this->getArrivalTime() == rhs.getArrivalTime() && this->getKeyPoints().size() > rhs.getKeyPoints().size()); } + [[nodiscard]] int getArrivalTime() const { return _arrivalTime; } + // FIXME: check if I can properly remove this or if shortest path comparisons may be useful // [[nodiscard]] bool strictlyDominates(const TransitAlgorithmState& rhs) const { -- GitLab