diff --git a/connection_scan_algorithm/include/calculator.hpp b/connection_scan_algorithm/include/calculator.hpp index f4b0091..1c66a29 100644 --- a/connection_scan_algorithm/include/calculator.hpp +++ b/connection_scan_algorithm/include/calculator.hpp @@ -114,7 +114,7 @@ namespace TrRouting long long calculationTime; std::vector nodesTentativeTime; // arrival time at node, using the Node::id as index - std::unordered_map nodesReverseTentativeTime; // departure time at node + std::vector nodesReverseTentativeTime; // departure time at node std::unordered_map nodesAccess; // travel time/distance from origin to accessible nodes std::unordered_map nodesEgress; // travel time/distance to reach destination; diff --git a/connection_scan_algorithm/src/resets.cpp b/connection_scan_algorithm/src/resets.cpp index 0617757..c847137 100644 --- a/connection_scan_algorithm/src/resets.cpp +++ b/connection_scan_algorithm/src/resets.cpp @@ -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); diff --git a/connection_scan_algorithm/src/reverse_calculation.cpp b/connection_scan_algorithm/src/reverse_calculation.cpp index aad39b5..960c1a6 100644 --- a/connection_scan_algorithm/src/reverse_calculation.cpp +++ b/connection_scan_algorithm/src/reverse_calculation.cpp @@ -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 ( @@ -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; @@ -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; @@ -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 ( @@ -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; @@ -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;