-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Implement waypoints
parameter in match plugin
#4732
Conversation
d3e3d52
to
506d774
Compare
b7d7f8c
to
346354f
Compare
8e0940c
to
0cd8a06
Compare
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 are some algorithmic things we can simplify. I can run this out, but I'm adding the comments here for visibility to you.
{ | ||
} | ||
|
||
template <typename... Args> | ||
MatchParameters(std::vector<unsigned> timestamps_, GapsType gaps_, bool tidy_, Args... args_) | ||
MatchParameters(std::vector<unsigned> timestamps_, |
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 need to preserve the original constructor here to preserve backwards compatibility.
|
||
bool IsValid() const | ||
{ | ||
auto invalid_idx = std::find_if(waypoints.begin(), waypoints.end(), [this](const auto &w) { |
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 can use std:all_of
instead.
if (result.was_waypoint[i] && (result.parameters.waypoints.back() != last_idx)) | ||
{ | ||
result.parameters.waypoints.push_back(last_idx); | ||
// result.was_waypoint[i] = false; |
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.
Commented out code should be removed.
// todo: this is not always true... e.g. if the first or last coordinate is duplicated and then | ||
// tidied away | ||
// but we do want some kind of check like this | ||
// BOOST_ASSERT(result.parameters.waypoints.size() == params.waypoints.size()); |
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.
Hrm I don't understand this comment or the assertion. Can we specify this more precisely?
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.
Hm, I actually don't think this needs to be assertion anymore, since it's not always true. I think having test coverage over this is good enough for now.
|
||
InternalRouteResult collapsed; | ||
collapsed.shortest_path_weight = leggy_result.shortest_path_weight; | ||
for (std::size_t i = 0; i < leggy_result.unpacked_path_segments.size(); i++) |
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 can use util::irange<size_t>
here.
// case) | ||
if (!last_segment.empty()) | ||
last_segment.pop_back(); | ||
// update target phantom node of leg |
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.
Needs an assertion that segment_end_coordinates
is not empty.
src/engine/plugins/match.cpp
Outdated
if (index != sm.indices.end()) | ||
found = true; | ||
}); | ||
if (!found) |
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.
Needs brackets around body.
src/engine/plugins/match.cpp
Outdated
} | ||
|
||
// Error: Check if user-supplied waypoints can be found in the resulting matches | ||
for (const auto waypoint : tidied.parameters.waypoints) |
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.
The complexity of this check is too high (three nested loops). What about using a std::set<std::size_t>
that contains the waypoint indices. Then we could loop over all sub-matching indices and remove the index of the waypoint we found.
src/engine/plugins/match.cpp
Outdated
{ | ||
std::vector<bool> waypoint_legs; | ||
waypoint_legs.reserve(sub_matchings[index].nodes.size()); | ||
for (unsigned i = 0; i < sub_matchings[index].nodes.size(); ++i) |
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 think we can do this in a single sweep over the indices of the submatch:
- Allocate a vector of size #waypoints
- Iterate over indices and
parameters.waypoints
at the same time (they are both sorted increasing) - Set
waypoints_legs[i]
to true if we find a match.
1c970d7
to
27c8d76
Compare
f54c5a4
to
616e620
Compare
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.
LGTM!
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.
Looks good, just one nit pick.
src/engine/plugins/match.cpp
Outdated
{ | ||
std::set<std::size_t> tidied_waypoints(tidied.parameters.waypoints.begin(), | ||
tidied.parameters.waypoints.end()); | ||
std::for_each(sub_matchings.begin(), sub_matchings.end(), [&](const SubMatching &sm) { |
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.
Instead of for_each
you can use for (const auto& sm : sub_matchings) { for (auto index : sm.indices) {} }
which looks a little cleaner.
with selective input coordinates as waypoints
2bc8a59
to
b5be313
Compare
Issue
Closes #4669
This adds a parameter to the match service plugin,
&waypoints
, that will allow users to specify which input coordinates should be treated aswaypoints
in the response. Current behavior is to treat all input coordinates as waypoints. Implementation details hereTasklist
Debug whyDon't support trace splitting and waypoints togetherwaypoints
crashes when trace splitting happensRequirements / Relations
nerp