diff --git a/connection_scan_algorithm/include/calculator.hpp b/connection_scan_algorithm/include/calculator.hpp index 1c66a29..640862e 100644 --- a/connection_scan_algorithm/include/calculator.hpp +++ b/connection_scan_algorithm/include/calculator.hpp @@ -119,9 +119,10 @@ namespace TrRouting std::unordered_map nodesEgress; // travel time/distance to reach destination; // Field used at the time of the query, mostly for alternatives, which deactivate some of the scenario trips. Typically, there are less disabled trips and enabled ones, so we keep only those + // Since the number of disabled trip is more commonly low, the map query is fast std::unordered_map tripsDisabled; bool isTripDisabled(Trip::uid_t uid) const { return tripsDisabled.find(uid) != tripsDisabled.end(); } - std::unordered_map tripsQueryOverlay; // Store addition trip info during a query processing + std::vector tripsQueryOverlay; // Store additionnal trip info during a query processing, indexed by Trip::uid // A subset of the connections that are used for the current query. std::shared_ptr connectionSet; diff --git a/connection_scan_algorithm/src/forward_calculation.cpp b/connection_scan_algorithm/src/forward_calculation.cpp index 8e6d91e..2359352 100644 --- a/connection_scan_algorithm/src/forward_calculation.cpp +++ b/connection_scan_algorithm/src/forward_calculation.cpp @@ -47,7 +47,7 @@ namespace TrRouting const Trip & trip = (*connection).get().getTrip(); // Cache the current query data overlay si we don't check the hashmap every time - auto & currentTripQueryOverlay = tripsQueryOverlay[trip.uid]; + auto & currentTripQueryOverlay = tripsQueryOverlay.at(trip.uid); // enabled trips only here: if (!isTripDisabled(trip.uid)) @@ -237,7 +237,7 @@ namespace TrRouting const Trip & trip = (*connection).get().getTrip(); // Cache the current query data overlay si we don't check the hashmap every time - auto & currentTripQueryOverlay = tripsQueryOverlay[trip.uid]; + auto & currentTripQueryOverlay = tripsQueryOverlay.at(trip.uid); // enabled trips only here: if (!isTripDisabled(trip.uid)) diff --git a/connection_scan_algorithm/src/resets.cpp b/connection_scan_algorithm/src/resets.cpp index c847137..02c3b52 100644 --- a/connection_scan_algorithm/src/resets.cpp +++ b/connection_scan_algorithm/src/resets.cpp @@ -34,7 +34,7 @@ namespace TrRouting egressFootpaths.clear(); egressFootpaths.shrink_to_fit(); } - tripsQueryOverlay.clear(); + tripsQueryOverlay.assign(Trip::getMaxUid()+1, TripQueryData()); forwardJourneysSteps.clear(); reverseJourneysSteps.clear(); diff --git a/connection_scan_algorithm/src/reverse_calculation.cpp b/connection_scan_algorithm/src/reverse_calculation.cpp index 960c1a6..be53d6f 100644 --- a/connection_scan_algorithm/src/reverse_calculation.cpp +++ b/connection_scan_algorithm/src/reverse_calculation.cpp @@ -53,7 +53,7 @@ namespace TrRouting const Trip & trip = (*connection).get().getTrip(); // enabled trips only here: - auto & currentTripQueryOverlay = tripsQueryOverlay[trip.uid]; + auto & currentTripQueryOverlay = tripsQueryOverlay.at(trip.uid); if (currentTripQueryOverlay.usable && !isTripDisabled(trip.uid)) { @@ -262,7 +262,7 @@ namespace TrRouting const Trip & trip = (*connection).get().getTrip(); // enabled trips only here: - auto & currentTripQueryOverlay = tripsQueryOverlay[trip.uid]; + auto & currentTripQueryOverlay = tripsQueryOverlay.at(trip.uid); // FIXME Determine with the new connection cache if a trip could be disabled in the all nodes path if ((currentTripQueryOverlay.usable) && !isTripDisabled(trip.uid)) { diff --git a/include/trip.hpp b/include/trip.hpp index e6f551c..01ae34c 100644 --- a/include/trip.hpp +++ b/include/trip.hpp @@ -53,6 +53,8 @@ namespace TrRouting uid_t uid; //Local, temporary unique id, used to speed up lookups inline bool operator==(const Trip& other ) const { return uuid == other.uuid; } + + static uid_t getMaxUid() { return global_uid; } private: //TODO, this could probably be an unsigned long, but current MAX_INT is good enough for our needs inline static uid_t global_uid = 0;