From ab18eab4231fe867b42745bb74a335dd46b97486 Mon Sep 17 00:00:00 2001 From: Romain BERNARD <romain.bernard@uca.fr> Date: Thu, 14 Mar 2024 12:55:12 +0100 Subject: [PATCH] WIP transit solutions container --- CMakeLists.txt | 2 ++ .../Transit/TransitShortestPathContainer.cpp | 5 ++++ .../Transit/TransitShortestPathContainer.h | 24 +++++++++++++++++++ .../Transit/TransitStateContainer.h | 17 +++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 src/ShortestPath/Transit/TransitShortestPathContainer.cpp create mode 100644 src/ShortestPath/Transit/TransitShortestPathContainer.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 90b9545..a3bcdc5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,4 +34,6 @@ add_executable(GreedyAlgorithm src/ShortestPath/Transit/TransitShortestPathPrecompute.h src/ShortestPath/Transit/TransitAlgorithmState.cpp src/ShortestPath/Transit/TransitAlgorithmState.h + src/ShortestPath/Transit/TransitShortestPathContainer.cpp + src/ShortestPath/Transit/TransitShortestPathContainer.h ) diff --git a/src/ShortestPath/Transit/TransitShortestPathContainer.cpp b/src/ShortestPath/Transit/TransitShortestPathContainer.cpp new file mode 100644 index 0000000..f895301 --- /dev/null +++ b/src/ShortestPath/Transit/TransitShortestPathContainer.cpp @@ -0,0 +1,5 @@ +// +// Created by romain on 13/03/24. +// + +#include "TransitShortestPathContainer.h" diff --git a/src/ShortestPath/Transit/TransitShortestPathContainer.h b/src/ShortestPath/Transit/TransitShortestPathContainer.h new file mode 100644 index 0000000..691b9b2 --- /dev/null +++ b/src/ShortestPath/Transit/TransitShortestPathContainer.h @@ -0,0 +1,24 @@ +// +// Created by romain on 13/03/24. +// + +#ifndef GREEDYALGORITHM_TRANSITSHORTESTPATHCONTAINER_H +#define GREEDYALGORITHM_TRANSITSHORTESTPATHCONTAINER_H + + +#include <vector> +#include "TransitShortestPath.h" + +class TransitShortestPathContainer { +private: + std::vector<std::pair<int, std::vector<TransitShortestPath>>> container; //Node vector -> Pair<Instant, ShortestPath[Node]> + +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 ); + +}; + + +#endif //GREEDYALGORITHM_TRANSITSHORTESTPATHCONTAINER_H diff --git a/src/ShortestPath/Transit/TransitStateContainer.h b/src/ShortestPath/Transit/TransitStateContainer.h index 2f0a61f..12e92ca 100644 --- a/src/ShortestPath/Transit/TransitStateContainer.h +++ b/src/ShortestPath/Transit/TransitStateContainer.h @@ -74,6 +74,23 @@ public: } } + /** + * Compares the states available to get to a given node index and returns the best by comparing their time of arrival. + * If equivalent solutions wrt time exist, the one with the lowest amount of connections required will be returned + * @param nodeIndex The node we try to get to + * @return + */ + TransitAlgorithmState getBestSolution(int nodeIndex) { + TransitAlgorithmState currentBestSol = solutionVector.at(nodeIndex).at(0); + for(size_t i = 1; i < solutionVector.at(nodeIndex).size(); ++i) { + if(solutionVector.at(nodeIndex).at(i).getInstant() < currentBestSol.getInstant()) { + currentBestSol = solutionVector.at(nodeIndex).at(i); + } + } + + return currentBestSol; + } + void pushEmptyState(int nodeIndex) { TransitAlgorithmState newState = TransitAlgorithmState(nodeIndex); -- GitLab