Skip to content
Snippets Groups Projects
Commit 5992e047 authored by Romain BERNARD's avatar Romain BERNARD
Browse files

shortest path container implementation (TODO : tests)

parent 5c8720ec
No related branches found
No related tags found
1 merge request!1Transit algorithm implementation
......@@ -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));
}
......@@ -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);
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment