diff --git a/CMakeLists.txt b/CMakeLists.txt index 90b954515e91fe8738b0f8fad7e6738e0aaab713..a3bcdc521f14ca796549e590c8423c553178f7d2 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 0000000000000000000000000000000000000000..f895301524f9e23d19ee27869c8eef8e04acd9e0 --- /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 0000000000000000000000000000000000000000..691b9b2d703167d42361023a577bb0e070fb2401 --- /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 2f0a61f635a15d77e4577af608a10d09ef725bcc..12e92ca252a90a2f338b7107565969b0caedb76b 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);