Skip to content

Commit

Permalink
Move nodesReverseTentativeTime to a vector
Browse files Browse the repository at this point in the history
Apply the same optimisation than nodesTentativeTime
  • Loading branch information
greenscientist committed Oct 24, 2023
1 parent 9b91783 commit 9730b22
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 26 deletions.
2 changes: 1 addition & 1 deletion connection_scan_algorithm/include/calculator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ namespace TrRouting
long long calculationTime;

std::vector<int> nodesTentativeTime; // arrival time at node, using the Node::id as index
std::unordered_map<Node::uid_t, int> nodesReverseTentativeTime; // departure time at node
std::vector<int> nodesReverseTentativeTime; // departure time at node
std::unordered_map<Node::uid_t, NodeTimeDistance> nodesAccess; // travel time/distance from origin to accessible nodes
std::unordered_map<Node::uid_t, NodeTimeDistance> nodesEgress; // travel time/distance to reach destination;

Expand Down
2 changes: 1 addition & 1 deletion connection_scan_algorithm/src/resets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ namespace TrRouting
int footpathDistanceMeters;
nodesEgress.clear();
reverseJourneysSteps.clear();
nodesReverseTentativeTime.clear();
nodesReverseTentativeTime.assign(Node::getMaxUid() + 1, -1); //Assign default values to all indexes
for (auto & egressFootpath : egressFootpaths)
{
footpathTravelTimeSeconds = (int)ceil((float)(egressFootpath.time) / params.walkingSpeedFactor);
Expand Down
30 changes: 6 additions & 24 deletions connection_scan_algorithm/src/reverse_calculation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,7 @@ namespace TrRouting
const Node &nodeArrival = (*connection).get().getArrivalNode();

// Extract node arrival time
int nodeArrivalTentativeTime = -1;
auto ite = nodesReverseTentativeTime.find(nodeArrival.uid);
if (ite != nodesReverseTentativeTime.end()) {
nodeArrivalTentativeTime = ite->second;
} else {
nodeArrivalTentativeTime = -1;
}
int nodeArrivalTentativeTime = nodesReverseTentativeTime.at(nodeArrival.uid);

// reachable connections only here:
if (
Expand Down Expand Up @@ -135,9 +129,7 @@ namespace TrRouting
for (const NodeTimeDistance & transferableNode : nodeDeparture.reverseTransferableNodes)
{

auto trite = nodesReverseTentativeTime.find(transferableNode.node.uid);

if (nodeDeparture != transferableNode.node && trite != nodesReverseTentativeTime.end() && trite->second > connectionDepartureTime - connectionMinWaitingTimeSeconds)
if (nodeDeparture != transferableNode.node && nodesReverseTentativeTime.at(transferableNode.node.uid) > connectionDepartureTime - connectionMinWaitingTimeSeconds)
{
footpathIndex++;
continue;
Expand All @@ -147,8 +139,7 @@ namespace TrRouting

if (footpathTravelTime <= parameters.getMaxTransferWalkingTravelTimeSeconds())
{
if ((trite == nodesReverseTentativeTime.end()) || //TODO Unclear if it's equivalent than previous code
connectionDepartureTime - footpathTravelTime - connectionMinWaitingTimeSeconds >= trite->second)
if (connectionDepartureTime - footpathTravelTime - connectionMinWaitingTimeSeconds >= nodesReverseTentativeTime.at(transferableNode.node.uid))
{
footpathDistance = nodeDeparture.reverseTransferableNodes.at(footpathIndex).distance;
nodesReverseTentativeTime[transferableNode.node.uid] = connectionDepartureTime - footpathTravelTime - connectionMinWaitingTimeSeconds;
Expand Down Expand Up @@ -288,13 +279,7 @@ namespace TrRouting
const Node &nodeArrival = (*connection).get().getArrivalNode();

// Extract node arrival time
int nodeArrivalTentativeTime = -1;
auto ite = nodesReverseTentativeTime.find(nodeArrival.uid);
if (ite != nodesReverseTentativeTime.end()) {
nodeArrivalTentativeTime = ite->second;
} else {
nodeArrivalTentativeTime = -1;
}
int nodeArrivalTentativeTime = nodesReverseTentativeTime.at(nodeArrival.uid);

// reachable connections only here:
if (
Expand Down Expand Up @@ -344,9 +329,7 @@ namespace TrRouting
for (const NodeTimeDistance & transferableNode : nodeDeparture.reverseTransferableNodes)
{

auto trite = nodesReverseTentativeTime.find(transferableNode.node.uid);

if (nodeDeparture != transferableNode.node && trite != nodesReverseTentativeTime.end() && trite->second > connectionDepartureTime - connectionMinWaitingTimeSeconds)
if (nodeDeparture != transferableNode.node && nodesReverseTentativeTime.at(transferableNode.node.uid) > connectionDepartureTime - connectionMinWaitingTimeSeconds)
{
footpathIndex++;
continue;
Expand All @@ -356,8 +339,7 @@ namespace TrRouting

if (footpathTravelTime <= parameters.getMaxTransferWalkingTravelTimeSeconds())
{
if ((trite == nodesReverseTentativeTime.end()) || //TODO Unclear if it's equivalent than previous code
connectionDepartureTime - footpathTravelTime - connectionMinWaitingTimeSeconds >= trite->second)
if (connectionDepartureTime - footpathTravelTime - connectionMinWaitingTimeSeconds >= nodesReverseTentativeTime.at(transferableNode.node.uid))
{
footpathDistance = nodeDeparture.reverseTransferableNodes.at(footpathIndex).distance;
nodesReverseTentativeTime[transferableNode.node.uid] = connectionDepartureTime - footpathTravelTime - connectionMinWaitingTimeSeconds;
Expand Down

0 comments on commit 9730b22

Please sign in to comment.