diff --git a/connection_scan_algorithm/src/forward_calculation.cpp b/connection_scan_algorithm/src/forward_calculation.cpp index 2251bc8..d257b81 100644 --- a/connection_scan_algorithm/src/forward_calculation.cpp +++ b/connection_scan_algorithm/src/forward_calculation.cpp @@ -21,7 +21,6 @@ namespace TrRouting short connectionMinWaitingTimeSeconds {-1}; //long long footpathsRangeStart {-1}; //long long footpathsRangeEnd {-1}; - int footpathIndex {-1}; int footpathTravelTime {-1}; int footpathDistance {-1}; int tentativeEgressNodeArrivalTime {MAX_INT}; @@ -110,7 +109,6 @@ namespace TrRouting tentativeEgressNodeArrivalTime = connectionArrivalTime; } - footpathIndex = 0; for (const NodeTimeDistance & transferableNode : nodeArrival.transferableNodes) { // Extract tentative time for current transferable node if found @@ -119,18 +117,17 @@ namespace TrRouting if (nodeArrival != transferableNode.node && currentTransferablenNodesTentativeTime < connectionArrivalTime) { - footpathIndex++; continue; } //TODO We should not do a direct == with float values - footpathTravelTime = parameters.getWalkingSpeedFactor() == 1.0 ? nodeArrival.transferableNodes[footpathIndex].time : (int)ceil((float)nodeArrival.transferableNodes[footpathIndex].time / parameters.getWalkingSpeedFactor()); + footpathTravelTime = parameters.getWalkingSpeedFactor() == 1.0 ? transferableNode.time : (int)ceil((float)transferableNode.time / parameters.getWalkingSpeedFactor()); if (footpathTravelTime <= parameters.getMaxTransferWalkingTravelTimeSeconds()) { if (footpathTravelTime + connectionArrivalTime < currentTransferablenNodesTentativeTime) { - footpathDistance = nodeArrival.transferableNodes[footpathIndex].distance; + footpathDistance = transferableNode.distance; nodesTentativeTime[transferableNode.node.uid] = footpathTravelTime + connectionArrivalTime; //TODO DO we need a make_optional here?? @@ -148,11 +145,10 @@ namespace TrRouting ) ) { - footpathDistance = nodeArrival.transferableNodes[footpathIndex].distance; + footpathDistance = transferableNode.distance; forwardEgressJourneysSteps.insert_or_assign(transferableNode.node.uid, JourneyStep(currentTripQueryOverlay.enterConnection, *connection, std::cref(trip), footpathTravelTime, true, footpathDistance)); } } - footpathIndex++; } } reachableConnectionsCount++; @@ -212,7 +208,6 @@ namespace TrRouting short connectionMinWaitingTimeSeconds {-1}; //long long footpathsRangeStart {-1}; //long long footpathsRangeEnd {-1}; - int footpathIndex {-1}; int footpathTravelTime {-1}; int footpathDistance {-1}; bool nodeWasAccessedFromOrigin {false}; @@ -286,7 +281,6 @@ namespace TrRouting const Node &nodeArrival = (*connection).get().getArrivalNode(); connectionArrivalTime = (*connection).get().getArrivalTime(); - footpathIndex = 0; for (const NodeTimeDistance & transferableNode : nodeArrival.transferableNodes) { // Extract tentative time for current transferable node if found @@ -295,18 +289,17 @@ namespace TrRouting if (nodeArrival != transferableNode.node && currentTransferablenNodesTentativeTime < connectionArrivalTime) { - footpathIndex++; continue; } //TODO We should not do a direct == with float values - footpathTravelTime = parameters.getWalkingSpeedFactor() == 1.0 ? nodeArrival.transferableNodes[footpathIndex].time : (int)ceil((float)nodeArrival.transferableNodes[footpathIndex].time / parameters.getWalkingSpeedFactor()); + footpathTravelTime = parameters.getWalkingSpeedFactor() == 1.0 ? transferableNode.time : (int)ceil((float)transferableNode.time / parameters.getWalkingSpeedFactor()); if (footpathTravelTime <= parameters.getMaxTransferWalkingTravelTimeSeconds()) { if (footpathTravelTime + connectionArrivalTime < currentTransferablenNodesTentativeTime) { - footpathDistance = nodeArrival.transferableNodes[footpathIndex].distance; + footpathDistance = transferableNode.distance; nodesTentativeTime[transferableNode.node.uid] = footpathTravelTime + connectionArrivalTime; //TODO DO we need a make_optional here?? @@ -324,11 +317,10 @@ namespace TrRouting ) ) { - footpathDistance = nodeArrival.transferableNodes[footpathIndex].distance; + footpathDistance = transferableNode.distance; forwardEgressJourneysSteps.insert_or_assign(transferableNode.node.uid, JourneyStep(currentTripQueryOverlay.enterConnection, *connection, std::cref(trip), footpathTravelTime, true, footpathDistance)); } } - footpathIndex++; } } reachableConnectionsCount++; diff --git a/connection_scan_algorithm/src/reverse_calculation.cpp b/connection_scan_algorithm/src/reverse_calculation.cpp index 8a1d20c..428c3de 100644 --- a/connection_scan_algorithm/src/reverse_calculation.cpp +++ b/connection_scan_algorithm/src/reverse_calculation.cpp @@ -120,7 +120,7 @@ namespace TrRouting tentativeAccessNodeDepartureTime = connectionDepartureTime; } - footpathIndex = 0; + for (const NodeTimeDistance & transferableNode : nodeDeparture.reverseTransferableNodes) { @@ -131,13 +131,13 @@ namespace TrRouting } //TODO We should not do a direct == with float values - footpathTravelTime = parameters.getWalkingSpeedFactor() == 1.0 ? nodeDeparture.reverseTransferableNodes[footpathIndex].time : (int)ceil((float)nodeDeparture.reverseTransferableNodes[footpathIndex].time / parameters.getWalkingSpeedFactor()); + footpathTravelTime = parameters.getWalkingSpeedFactor() == 1.0 ? transferableNode.time : (int)ceil((float)transferableNode.time / parameters.getWalkingSpeedFactor()); if (footpathTravelTime <= parameters.getMaxTransferWalkingTravelTimeSeconds()) { if (connectionDepartureTime - footpathTravelTime - connectionMinWaitingTimeSeconds >= nodesReverseTentativeTime.at(transferableNode.node.uid)) { - footpathDistance = nodeDeparture.reverseTransferableNodes.at(footpathIndex).distance; + footpathDistance = transferableNode.distance; nodesReverseTentativeTime[transferableNode.node.uid] = connectionDepartureTime - footpathTravelTime - connectionMinWaitingTimeSeconds; //TODO Do we need a make_optional<...>(connection) ?? reverseJourneysSteps.at(transferableNode.node.uid) = JourneyStep(*connection, currentTripQueryOverlay.exitConnection, std::cref(trip), footpathTravelTime, (nodeDeparture == transferableNode.node), footpathDistance); @@ -173,7 +173,6 @@ namespace TrRouting } } } - footpathIndex++; } } reachableConnectionsCount++; @@ -232,7 +231,6 @@ namespace TrRouting short journeyConnectionMinWaitingTimeSeconds {-1}; //long long footpathsRangeStart {-1}; //long long footpathsRangeEnd {-1}; - int footpathIndex {-1}; int footpathTravelTime {-1}; int footpathDistance {-1}; @@ -317,24 +315,22 @@ namespace TrRouting connectionMinWaitingTimeSeconds = (*connection).get().getMinWaitingTimeOrDefault(parameters.getMinWaitingTimeSeconds()); auto nodeDepartureInNodesAccessIte = nodesAccess.find(nodeDeparture.uid); - footpathIndex = 0; for (const NodeTimeDistance & transferableNode : nodeDeparture.reverseTransferableNodes) { if (nodeDeparture != transferableNode.node && nodesReverseTentativeTime.at(transferableNode.node.uid) > connectionDepartureTime - connectionMinWaitingTimeSeconds) { - footpathIndex++; continue; } //TODO We should not do a direct == with float values - footpathTravelTime = parameters.getWalkingSpeedFactor() == 1.0 ? nodeDeparture.reverseTransferableNodes[footpathIndex].time : (int)ceil((float)nodeDeparture.reverseTransferableNodes[footpathIndex].time / parameters.getWalkingSpeedFactor()); + footpathTravelTime = parameters.getWalkingSpeedFactor() == 1.0 ? transferableNode.time : (int)ceil((float)transferableNode.time / parameters.getWalkingSpeedFactor()); if (footpathTravelTime <= parameters.getMaxTransferWalkingTravelTimeSeconds()) { if (connectionDepartureTime - footpathTravelTime - connectionMinWaitingTimeSeconds >= nodesReverseTentativeTime.at(transferableNode.node.uid)) { - footpathDistance = nodeDeparture.reverseTransferableNodes.at(footpathIndex).distance; + footpathDistance = transferableNode.distance; nodesReverseTentativeTime[transferableNode.node.uid] = connectionDepartureTime - footpathTravelTime - connectionMinWaitingTimeSeconds; //TODO Do we need a make_optional<...>(connection) ?? reverseJourneysSteps.at(transferableNode.node.uid) = JourneyStep(*connection, currentTripQueryOverlay.exitConnection, std::cref(trip), footpathTravelTime, (nodeDeparture == transferableNode.node), footpathDistance); @@ -370,7 +366,6 @@ namespace TrRouting } } } - footpathIndex++; } } reachableConnectionsCount++; diff --git a/include/combinations.hpp b/include/combinations.hpp index a464ecd..a95fd3a 100644 --- a/include/combinations.hpp +++ b/include/combinations.hpp @@ -2,6 +2,7 @@ // from https://stackoverflow.com/a/25497877 // With later modifications to adapt for std::reference_wrapper #include +#include template class Combinations { // Combinations(std::vector s, int m) iterate all Combinations without repetition