diff --git a/connection_scan_algorithm/include/calculator.hpp b/connection_scan_algorithm/include/calculator.hpp index 1c66a29..fcd6487 100644 --- a/connection_scan_algorithm/include/calculator.hpp +++ b/connection_scan_algorithm/include/calculator.hpp @@ -127,8 +127,8 @@ namespace TrRouting std::vector accessFootpaths; // pair: accessNodeIndex, walkingTravelTimeSeconds, walkingDistanceMeters std::vector egressFootpaths; // pair: egressNodeIndex, walkingTravelTimeSeconds, walkingDistanceMeters - std::unordered_map forwardJourneysSteps; - std::unordered_map reverseJourneysSteps; + std::vector forwardJourneysSteps; // indexed by Node::uid + std::vector reverseJourneysSteps; // indexed by Node::uid }; diff --git a/connection_scan_algorithm/include/journey_step.hpp b/connection_scan_algorithm/include/journey_step.hpp index 1b75bc9..e423029 100644 --- a/connection_scan_algorithm/include/journey_step.hpp +++ b/connection_scan_algorithm/include/journey_step.hpp @@ -21,6 +21,7 @@ namespace TrRouting { transferTravelTime(_transferTravelTime), sameNodeTransfer(_sameNodeTransfer), transferDistance(_transferDistance) { } + JourneyStep() : JourneyStep(std::nullopt, std::nullopt, std::nullopt, -1, false, -1) {} //TODO Why is there Final in the function name. Is that appropriate? std::optional> getFinalEnterConnection() const {return finalEnterConnection;} diff --git a/connection_scan_algorithm/src/forward_calculation.cpp b/connection_scan_algorithm/src/forward_calculation.cpp index 8e6d91e..bbe8259 100644 --- a/connection_scan_algorithm/src/forward_calculation.cpp +++ b/connection_scan_algorithm/src/forward_calculation.cpp @@ -137,7 +137,7 @@ namespace TrRouting nodesTentativeTime[transferableNode.node.uid] = footpathTravelTime + connectionArrivalTime; //TODO DO we need a make_optional here?? - forwardJourneysSteps.insert_or_assign(transferableNode.node.uid, JourneyStep(currentTripQueryOverlay.enterConnection, *connection, std::cref(trip), footpathTravelTime, (nodeArrival == transferableNode.node), footpathDistance)); + forwardJourneysSteps.at(transferableNode.node.uid) = JourneyStep(currentTripQueryOverlay.enterConnection, *connection, std::cref(trip), footpathTravelTime, (nodeArrival == transferableNode.node), footpathDistance); } if ( @@ -316,7 +316,7 @@ namespace TrRouting nodesTentativeTime[transferableNode.node.uid] = footpathTravelTime + connectionArrivalTime; //TODO DO we need a make_optional here?? - forwardJourneysSteps.insert_or_assign(transferableNode.node.uid, JourneyStep(currentTripQueryOverlay.enterConnection, *connection, std::cref(trip), footpathTravelTime, (nodeArrival == transferableNode.node), footpathDistance)); + forwardJourneysSteps.at(transferableNode.node.uid) = JourneyStep(currentTripQueryOverlay.enterConnection, *connection, std::cref(trip), footpathTravelTime, (nodeArrival == transferableNode.node), footpathDistance); } if ( diff --git a/connection_scan_algorithm/src/resets.cpp b/connection_scan_algorithm/src/resets.cpp index c847137..544aa9e 100644 --- a/connection_scan_algorithm/src/resets.cpp +++ b/connection_scan_algorithm/src/resets.cpp @@ -79,7 +79,7 @@ namespace TrRouting int footpathTravelTimeSeconds; int footpathDistanceMeters; nodesAccess.clear(); - forwardJourneysSteps.clear(); + forwardJourneysSteps.assign(Node::getMaxUid() + 1, JourneyStep()); nodesTentativeTime.assign(Node::getMaxUid() + 1, MAX_INT); //Assign default values to all indexes for (auto & accessFootpath : accessFootpaths) @@ -90,7 +90,7 @@ namespace TrRouting nodesAccess.emplace(accessFootpath.node.uid, NodeTimeDistance(accessFootpath.node, footpathTravelTimeSeconds, footpathDistanceMeters)); - forwardJourneysSteps.insert_or_assign(accessFootpath.node.uid, JourneyStep(std::nullopt, std::nullopt, std::nullopt, footpathTravelTimeSeconds, false, footpathDistanceMeters)); + forwardJourneysSteps.at(accessFootpath.node.uid) = JourneyStep(std::nullopt, std::nullopt, std::nullopt, footpathTravelTimeSeconds, false, footpathDistanceMeters); nodesTentativeTime[accessFootpath.node.uid] = departureTimeSeconds + footpathTravelTimeSeconds; if (footpathTravelTimeSeconds < minAccessTravelTime) { @@ -115,7 +115,7 @@ namespace TrRouting int footpathTravelTimeSeconds; int footpathDistanceMeters; nodesEgress.clear(); - reverseJourneysSteps.clear(); + reverseJourneysSteps.assign(Node::getMaxUid() + 1, JourneyStep()); nodesReverseTentativeTime.assign(Node::getMaxUid() + 1, -1); //Assign default values to all indexes for (auto & egressFootpath : egressFootpaths) { @@ -126,7 +126,7 @@ namespace TrRouting footpathTravelTimeSeconds, footpathDistanceMeters)); - reverseJourneysSteps.insert_or_assign(egressFootpath.node.uid, JourneyStep(std::nullopt, std::nullopt, std::nullopt, footpathTravelTimeSeconds, false, footpathDistanceMeters)); + reverseJourneysSteps.at(egressFootpath.node.uid) = JourneyStep(std::nullopt, std::nullopt, std::nullopt, footpathTravelTimeSeconds, false, footpathDistanceMeters); nodesReverseTentativeTime[egressFootpath.node.uid] = arrivalTimeSeconds - footpathTravelTimeSeconds; if (footpathTravelTimeSeconds > maxEgressTravelTime) { diff --git a/connection_scan_algorithm/src/reverse_calculation.cpp b/connection_scan_algorithm/src/reverse_calculation.cpp index 960c1a6..eb58e29 100644 --- a/connection_scan_algorithm/src/reverse_calculation.cpp +++ b/connection_scan_algorithm/src/reverse_calculation.cpp @@ -81,11 +81,10 @@ namespace TrRouting { // Make sure the arrival of the connection can unboard and is a candidate for the journey. Nodes are candidate if they can either reach the destination by foot, or a connection that can reach the destination within the specified parameters. - auto rjsIte = reverseJourneysSteps.find(nodeArrival.uid); - if ((*connection).get().canUnboard() && rjsIte != reverseJourneysSteps.end()) + if ((*connection).get().canUnboard()) { // Extract journeyStep once from map - const JourneyStep & reverseStepAtArrival = rjsIte->second; + const JourneyStep & reverseStepAtArrival = reverseJourneysSteps.at(nodeArrival.uid); if (!tripExitConnection.has_value()) // <= to make sure we get the same result as forward calculation, which uses > { currentTripQueryOverlay.exitConnection = *connection; @@ -144,7 +143,7 @@ namespace TrRouting footpathDistance = nodeDeparture.reverseTransferableNodes.at(footpathIndex).distance; nodesReverseTentativeTime[transferableNode.node.uid] = connectionDepartureTime - footpathTravelTime - connectionMinWaitingTimeSeconds; //TODO Do we need a make_optional<...>(connection) ?? - reverseJourneysSteps.insert_or_assign(transferableNode.node.uid, JourneyStep(*connection, currentTripQueryOverlay.exitConnection, std::cref(trip), footpathTravelTime, (nodeDeparture == transferableNode.node), footpathDistance)); + reverseJourneysSteps.at(transferableNode.node.uid) = JourneyStep(*connection, currentTripQueryOverlay.exitConnection, std::cref(trip), footpathTravelTime, (nodeDeparture == transferableNode.node), footpathDistance); } if ( nodeDeparture == transferableNode.node @@ -344,7 +343,7 @@ namespace TrRouting footpathDistance = nodeDeparture.reverseTransferableNodes.at(footpathIndex).distance; nodesReverseTentativeTime[transferableNode.node.uid] = connectionDepartureTime - footpathTravelTime - connectionMinWaitingTimeSeconds; //TODO Do we need a make_optional<...>(connection) ?? - reverseJourneysSteps.insert_or_assign(transferableNode.node.uid, JourneyStep(*connection, currentTripQueryOverlay.exitConnection, std::cref(trip), footpathTravelTime, (nodeDeparture == transferableNode.node), footpathDistance)); + reverseJourneysSteps.at(transferableNode.node.uid) = JourneyStep(*connection, currentTripQueryOverlay.exitConnection, std::cref(trip), footpathTravelTime, (nodeDeparture == transferableNode.node), footpathDistance); } if ( nodeDeparture == transferableNode.node