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
second pass for CostMatrix #4536
Conversation
…also unify its signature; preparation for second pass on matrix
…pler albeit likely less peformant.. added tests to prove that it works, e.g. if A -> B is found but not B -> A, that only B -> A is re-computed, both with no-thru & destonly restrictions
b14fe61
to
8cdd65e
Compare
@@ -90,7 +90,7 @@ void BidirectionalAStar::Clear() { | |||
// Set the ferry flag to false | |||
has_ferry_ = false; | |||
// Set not thru pruning to true | |||
not_thru_pruning_ = true; | |||
set_not_thru_pruning(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's a function for this, I find it nicer for comprehension to use it
if (costing_->pass() > 0 && !(matrix.second_pass(connection_idx))) { | ||
continue; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we're on the second pass and we didn't set the flag on the first pass, then don't bother processing anymore
auto* pbf_time_zone_name = matrix.mutable_time_zone_names()->Add(); | ||
*pbf_time_zone_name = ""; | ||
// let's try a second pass for this connection | ||
matrix.mutable_second_pass()->Set(connection_idx, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
second_pass
is defaulting to false, true
is signaling the second pass that it wasn't found initially
best_connection_.emplace_back(empty, empty, Cost{0.0f, matrix.times(connection_idx)}, | ||
matrix.distances(connection_idx)); | ||
best_connection_.back().found = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we have previously found connections, we transfer the important attributes which make up the response
if (!s.unfound_connections.empty()) { | ||
locs_remaining_[MATRIX_FORW]++; | ||
} else { | ||
// don't look at sources which don't have unfound connections, important for second pass | ||
s.threshold = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setting the threshold to 0 for sources which have all destination found on the first pass, makes sure we don't even expand those sources anymore
@@ -538,7 +550,7 @@ bool CostMatrix::ExpandInner(baldr::GraphReader& graphreader, | |||
pred_dist, newcost.cost); | |||
} | |||
|
|||
return true; | |||
return !(pred.not_thru_pruning() && meta.edge->not_thru()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allow u-turns if we hit a not thru edge
@@ -312,6 +312,7 @@ std::vector<std::vector<thor::PathInfo>> thor_worker_t::get_path(PathAlgorithm* | |||
|
|||
// Check if we should run a second pass pedestrian route with different A* | |||
// (to look for better routes where a ferry is taken) | |||
// TODO(nils): how would a second pass find a better route, if it changes nothing ferry-related? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seemed strange to me
// TODO(nils): TDMatrix doesn't care about either destonly or no_thru | ||
if (algo->name() != "costmatrix") { | ||
algo->SourceToTarget(request, *reader, mode_costing, mode, | ||
max_matrix_distance.find(costing)->second); | ||
return tyr::serializeMatrix(request); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't do second passes for tdmatrices (bss or normal), both don't have a concept of neither destonly nor not_thru
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually unidir a* also allows for destonly, not sure why?
*matrix.mutable_date_times(connection_idx) = dt_info.date_time; | ||
*matrix.mutable_time_zone_offsets(connection_idx) = dt_info.time_zone_offset; | ||
*matrix.mutable_time_zone_names(connection_idx) = dt_info.time_zone_name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also changed this whole logic, it became unbearable now that we're "randomly" processing connections, i.e. not in sequence anymore. I realized that RepeatedPtrFields
don't have a Set()
method but also their operator()
methods aren't const, so we can just assign new values. probably that's quite a bit worse for performance, but I doubt it's very measurable wrt to the whole expansion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
basically now we're initializing all repeated string
fields with ""
in reserve_pbf_arrays()
, just like the other fields which have Set()
this looks broadly good to me other than the tiny nitpicks we just discussed. let me know when those are patched and ill put a ship. would also be nice if @dnesbitt61 had a sec to look |
@kevinkreiser I addressed the comments |
fixes #4474
based on #4535
EDIT: on second thought, I'll leave TDMatrix as TODO for now. Less to review and less relevant overall. Not even sure it makes sense at all. Both TDMatrix algos don't seem to care about nothru pruning or even destonly (yet), hierarchies are not relevant either. Only thing they care about are conditional destonly but those are super rare.
TODO:
[ ] timedistancematrix[ ] timedistancebssmatrixthoughts: