Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimise the tripsQueryOverlay by moving it to a vector #266

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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