Skip to content

Commit

Permalink
Optimise the tripsQueryOverlay by moving it to a vector
Browse files Browse the repository at this point in the history
We gain around 10% to 20% in execution time
  • Loading branch information
greenscientist committed Oct 28, 2023
1 parent 60c4fb6 commit 78975f8
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion connection_scan_algorithm/include/calculator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ namespace TrRouting
std::unordered_map<Node::uid_t, NodeTimeDistance> 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<Trip::uid_t, bool> tripsDisabled;
bool isTripDisabled(Trip::uid_t uid) const { return tripsDisabled.find(uid) != tripsDisabled.end(); }
std::unordered_map<Trip::uid_t, TripQueryData> tripsQueryOverlay; // Store addition trip info during a query processing
std::vector<TripQueryData> 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> connectionSet;

Expand Down
4 changes: 2 additions & 2 deletions connection_scan_algorithm/src/forward_calculation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
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 @@ -34,7 +34,7 @@ namespace TrRouting
egressFootpaths.clear();
egressFootpaths.shrink_to_fit();
}
tripsQueryOverlay.clear();
tripsQueryOverlay.assign(Trip::getMaxUid()+1, TripQueryData());
forwardJourneysSteps.clear();
reverseJourneysSteps.clear();

Expand Down
4 changes: 2 additions & 2 deletions connection_scan_algorithm/src/reverse_calculation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{

Expand Down Expand Up @@ -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))
{
Expand Down
2 changes: 2 additions & 0 deletions include/trip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 78975f8

Please sign in to comment.