From 5992e04715b3e2ffe727ce15561d0729d3e8e56b Mon Sep 17 00:00:00 2001 From: Romain BERNARD <romain.bernard@uca.fr> Date: Mon, 18 Mar 2024 18:30:24 +0100 Subject: [PATCH] shortest path container implementation (TODO : tests) --- .../Transit/TransitShortestPathContainer.cpp | 33 +++++++++++++++++++ .../Transit/TransitShortestPathContainer.h | 9 ++--- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/ShortestPath/Transit/TransitShortestPathContainer.cpp b/src/ShortestPath/Transit/TransitShortestPathContainer.cpp index f895301..0c35c86 100644 --- a/src/ShortestPath/Transit/TransitShortestPathContainer.cpp +++ b/src/ShortestPath/Transit/TransitShortestPathContainer.cpp @@ -3,3 +3,36 @@ // #include "TransitShortestPathContainer.h" + +void TransitShortestPathContainer::addShortestPathCollection(int startNodeIndex, + const std::pair<int, std::vector<TransitShortestPath>>& shortestPathList) { + container.at(startNodeIndex).emplace_back(shortestPathList); +} + +void TransitShortestPathContainer::addShortestPathCollection(int startNodeIndex, int startingInstant, int graphSize, + const std::vector<TransitAlgorithmState>& algorithmResultStates) { + std::vector<TransitShortestPath> shortestPathList; + shortestPathList.reserve(graphSize); + + //Convert states to shortest paths and add to collection + for(const auto& state: algorithmResultStates) { + shortestPathList.emplace_back(state); + } + + //Add the (startingInstant, pathVector) pair at the appropriate node index + container.at(startNodeIndex).emplace_back(startingInstant, shortestPathList); +} + +std::vector<std::pair<int, std::vector<TransitShortestPath>>>::iterator +TransitShortestPathContainer::getShortestPathsFromTime(int startNodeIndex, int earliestStartInstant) { + const auto& iterator = std::lower_bound(container.at(startNodeIndex).begin(), container.at(startNodeIndex).end(), + std::pair<int, std::vector<TransitShortestPath>>(earliestStartInstant, {})); + + return iterator; +} + +std::pair<int, TransitShortestPath> +TransitShortestPathContainer::getShortestPathToYFromTime(int startNodeIndex, int earliestStartInstant, int goalNode) { + const auto& shortestPathsIterator = getShortestPathsFromTime(startNodeIndex, earliestStartInstant); + return std::pair(shortestPathsIterator->first, shortestPathsIterator->second.at(goalNode)); +} diff --git a/src/ShortestPath/Transit/TransitShortestPathContainer.h b/src/ShortestPath/Transit/TransitShortestPathContainer.h index b2e69cf..923e816 100644 --- a/src/ShortestPath/Transit/TransitShortestPathContainer.h +++ b/src/ShortestPath/Transit/TransitShortestPathContainer.h @@ -11,12 +11,13 @@ class TransitShortestPathContainer { private: - std::vector<std::pair<int, std::vector<TransitShortestPath>>> container; //Node vector -> Pair<Instant, ShortestPath[Node]> + std::vector<std::vector<std::pair<int, std::vector<TransitShortestPath>>>> container; //NodeVector< PairVector<Pair<Instant, NodeVector<ShortestPath> >> > public: - void addShortestPathCollection(int startNodeIndex, std::pair<int, std::vector<TransitShortestPath>> shortestPathList); - void addShortestPathCollection(int startNodeIndex, int startingInstant, std::vector<TransitAlgorithmState> algorithmResultStates); - std::pair<int, std::vector<TransitShortestPath>> getShortestPathsFromTime(int startNodeIndex, int ); + void addShortestPathCollection(int startNodeIndex, const std::pair<int, std::vector<TransitShortestPath>>& shortestPathList); + void addShortestPathCollection(int startNodeIndex, int startingInstant, int graphSize, const std::vector<TransitAlgorithmState>& algorithmResultStates); + std::vector<std::pair<int, std::vector<TransitShortestPath>>>::iterator getShortestPathsFromTime(int startNodeIndex, int earliestStartInstant); + std::pair<int, TransitShortestPath> getShortestPathToYFromTime(int startNodeIndex, int earliestStartInstant, int goalNode); }; -- GitLab