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

Respect interpolated matches when building matched route #3646

Closed
wants to merge 3 commits into from

Conversation

nilsnolde
Copy link
Member

fixes #3371

for more context see #3645 where I tried to change too much and it was very hard to keep the same results. now I just introduced one more nested loop more or less which fixes the problem and passes the tests

int prev_idx = first_idx;
for (int curr_idx = first_idx + 1; curr_idx <= last_idx; ++curr_idx) {
const MatchResult& curr_match = match_results[curr_idx];
const MatchResult& prev_match = match_results[prev_idx];

// skip if we do not need to cut
if (!curr_match.is_break_point && curr_idx != last_idx) {
Copy link
Member Author

@nilsnolde nilsnolde May 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so before this was just looping through non-interpolated points and only copied the segments when we were at the last segment of the passed range. this would skip updating segments whose first or last matched point was interpolated. now there'll be a whole lot more allocations to the route vector below, only to keep the indices of the matched points correctly on the segments. in #3645 I tried to get around this by only adding segments to the route once we have a segment transition which was much less work for the algo. maybe I'll revisit that. what do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I "benchmarked" master vs this branch on a 200 point trace_attributes request, 10000 loops per run. in sweden, somewhere remote-ish, and dense gps sampling (i.e. routing takes relatively less time, so I'd imagine a bigger impact of this PRs changes):

0.1296 secs (master) vs 0.1304 secs (this branch)

I really tried hard to make the other approach work which would've reduced the vector allocations tremendously, probably also less than master, but I just couldn't tweak the algo properly. so many cases, so much headache.

Comment on lines +224 to +225
for (int cut_begin_idx = prev_idx, cut_end_idx = prev_idx + 1; cut_end_idx <= curr_idx;
++cut_end_idx) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loop through all points in between the two stateful points (and skip unmatched ones)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's basically it here, didn't change anything else

)";

const gurka::ways ways = {{"AB", {{"highway", "primary"}}},
{"BC", {{"highway", "primary"}}},
{"CD", {{"highway", "primary"}}}};

const double gridsize = 10;
const double gridsize = 9;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9 meters ensures that node 5 will be set "interpolated" (the default interpolation_distance is 10)

DirectionsLeg::Maneuver::kRight,
DirectionsLeg::Maneuver::kDestination});

gurka::assert::raw::expect_path_length(result_route, 0.099, 0.001);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the path is identical but the grid size is now 9 meters instead of 10, however the length is only 1 meter different? that is confusing, i would think it would be 12 meters different (1 meter for every space in the ascii)

Copy link
Member

@kevinkreiser kevinkreiser Jun 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there seem to be 11 chars in total in the path so it should be 11*9==99 so that seems right but, why wasnt it 11*10 ==110 before??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at the map again, I added one more node, so one more grid cell, easy to miss really

@kevinkreiser
Copy link
Member

@nilsnolde i made a branch of your branch and tried a different approach in which i refactored cut segments to remember the last position it searched from within the two match points. this way there is no more iteration than needed. i moved the check for continuing down after that search and then inside the if with the continue im going to try to patch the segment that touches that match point. i think this should fix the issue without extra looping or allocations. just need another free night to do the actual patching inside that if. i'll push it up when i get a chance so you can take a look.

@kevinkreiser
Copy link
Member

for others following along i pushed up my slight refactor to this branch: https://github.com/valhalla/valhalla/tree/kk_interpolated_match_index

im hopeful that if we fill out the TODO we'll be able to mark the segments such that the indices will come out properly

@nilsnolde
Copy link
Member Author

@kevinkreiser did it more properly over in #3670 , closing this one

@nilsnolde nilsnolde closed this Jun 30, 2022
@nilsnolde nilsnolde deleted the nn-fix-interpolated-matches branch October 3, 2022 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

edge_index of some interpolated points is 18446744073709551615
2 participants