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

Bug: bidirerctionalastar ignores complex restriction #2781

Merged
merged 15 commits into from
Jan 27, 2021

Conversation

merkispavel
Copy link
Contributor

@merkispavel merkispavel commented Jan 19, 2021

Issue

Bug details: #2781 (comment)
the PR has both a gurka test which fails on master and the suggested fix

Tasklist

  • Add tests
  • Add #fixes with the issue number that this PR addresses
  • Generally use squash merge to rebase and clean comments before merging
  • Update the changelog

Requirements / Relations

Link any requirements here. Other pull requests this PR is based on?


try {
auto result = gurka::route(map, "D", "E", "auto");
gurka::assert::raw::expect_path(result, {"Unexpected path found"});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It returns DC-CB-BE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From my view the bug is around this line

if (rev_pred.on_complex_rest()) {

rev_pred == DC and rev_pred.on_complex_restr() returns false

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess the problem is in restrictionbuilder.cc.

Let's say we have a restriction A -> B -> C. So we take the edge AB and it's marked as start_restriction. We go forward and reach the node C. We go backwards and finally have the edges {CB, BA}. After that we add reverse restriction using the BA edge as from. BUT we add it to the tile of the AB edge.
tldr: if nodes A and B belong to different tiles (Houston) we got a problem

Copy link
Member

Choose a reason for hiding this comment

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

the good news is this should be incredibly rare! but also wow, good find, what a needle in a haystack. i suppose we have to detect when restrictions cross tile boundaries in the restrictions builder and patch it to handle that case.

Copy link
Contributor Author

@merkispavel merkispavel Jan 20, 2021

Choose a reason for hiding this comment

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

the good news is this should be incredibly rare

agreed!

@purew purew self-requested a review January 19, 2021 15:48
@merkispavel merkispavel force-pushed the bdir-ignores-restriction branch from fb1b19c to 5636538 Compare January 20, 2021 18:10
@@ -331,8 +329,7 @@ void build(const std::string& complex_restriction_from_file,
if (restriction.type() < RestrictionType::kOnlyRightTurn ||
restriction.type() > RestrictionType::kOnlyStraightOn) {

GraphId currentNode = GraphId(tile->id().tileid(), tile->id().level(), i);
GraphId tileid = tile->id();
GraphId currentNode = directededge.endnode();
Copy link
Contributor Author

@merkispavel merkispavel Jan 20, 2021

Choose a reason for hiding this comment

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

Turned out that both forward and it's opposite edge are marked with start_restriction flag.
So let's say we have a restriction A - B - C. Both AB & BA are start_restriction-s.
Before this change:

  • algorithm starts with the node A and succeeds when directededge == AB

After this change

  • algorithm starts with the node A and succeeds when directededge == BA

so the PR doesn't breaks anything

@merkispavel
Copy link
Contributor Author

Going to build large enough area to compare the number of restrictions against master to make sure the data is static

@merkispavel
Copy link
Contributor Author

merkispavel commented Jan 26, 2021

Going to build large enough area to compare the number of restrictions against master to make sure the data is static

Did a test with florida-latest.osm.pbf. Suprisingly I got 1 more restriction with my changes. Investigating 👀 ..

UPD: the mismatched restriction https://www.openstreetmap.org/relation/7680229#map=18/25.74885/-80.21806

master

2021/01/25 14:07:30.819573 [INFO] Adding Restrictions at level 2
2021/01/25 14:07:42.640216 [INFO] --Forward restrictions added: 534
2021/01/25 14:07:42.640241 [INFO] --Reverse restrictions added: 345
2021/01/25 14:07:42.640766 [INFO] Adding Restrictions at level 1
2021/01/25 14:07:44.755671 [INFO] --Forward restrictions added: 1079
2021/01/25 14:07:44.755694 [INFO] --Reverse restrictions added: 1214
2021/01/25 14:07:44.755969 [INFO] Adding Restrictions at level 0
2021/01/25 14:07:46.014482 [INFO] --Forward restrictions added: 1033
2021/01/25 14:07:46.014505 [INFO] --Reverse restrictions added: 1065

this branch

2021/01/25 14:05:33.527092 [INFO] Adding Restrictions at level 2
2021/01/25 14:05:46.330749 [INFO] --Forward restrictions added: 535 // vs 534 in master
2021/01/25 14:05:46.330792 [INFO] --Reverse restrictions added: 345
2021/01/25 14:05:46.331898 [INFO] Adding Restrictions at level 1
2021/01/25 14:05:48.692780 [INFO] --Forward restrictions added: 1079
2021/01/25 14:05:48.692811 [INFO] --Reverse restrictions added: 1214
2021/01/25 14:05:48.693068 [INFO] Adding Restrictions at level 0
2021/01/25 14:05:50.047939 [INFO] --Forward restrictions added: 1033
2021/01/25 14:05:50.047961 [INFO] --Reverse restrictions added: 1065

@merkispavel merkispavel self-assigned this Jan 26, 2021

if (tmp_ids.size()) {
if (tmp_ids.size() && tmp_ids.back().Tile_Base() == tile_id) {
Copy link
Contributor Author

@merkispavel merkispavel Jan 26, 2021

Choose a reason for hiding this comment

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

it happens if we split an osmway into a few edges and not all edges go to the same tile
E.g. if you have a restriction "from ABC to CD"

A -- B -- C
          | 
          D

there are cases that A-B-C has the same osmway property. And if the edges AB and BC are from the different tiles then master code produces redundant restrictions: they are harmless but useless: both AB & BC edges are marked as start restrictions but finally you'll get the only restriction "from (BC) to (CD)"

@merkispavel
Copy link
Contributor Author

merkispavel commented Jan 26, 2021

Going to build large enough area to compare the number of restrictions against master to make sure the data is static

Did a test with florida-latest.osm.pbf. Suprisingly I got 1 more restriction with my changes. Investigating 👀 ..

UPD: the mismatched restriction https://www.openstreetmap.org/relation/7680229#map=18/25.74885/-80.21806

master

2021/01/25 14:07:30.819573 [INFO] Adding Restrictions at level 2
2021/01/25 14:07:42.640216 [INFO] --Forward restrictions added: 534
2021/01/25 14:07:42.640241 [INFO] --Reverse restrictions added: 345
2021/01/25 14:07:42.640766 [INFO] Adding Restrictions at level 1
2021/01/25 14:07:44.755671 [INFO] --Forward restrictions added: 1079
2021/01/25 14:07:44.755694 [INFO] --Reverse restrictions added: 1214
2021/01/25 14:07:44.755969 [INFO] Adding Restrictions at level 0
2021/01/25 14:07:46.014482 [INFO] --Forward restrictions added: 1033
2021/01/25 14:07:46.014505 [INFO] --Reverse restrictions added: 1065

this branch

2021/01/25 14:05:33.527092 [INFO] Adding Restrictions at level 2
2021/01/25 14:05:46.330749 [INFO] --Forward restrictions added: 535 // vs 534 in master
2021/01/25 14:05:46.330792 [INFO] --Reverse restrictions added: 345
2021/01/25 14:05:46.331898 [INFO] Adding Restrictions at level 1
2021/01/25 14:05:48.692780 [INFO] --Forward restrictions added: 1079
2021/01/25 14:05:48.692811 [INFO] --Reverse restrictions added: 1214
2021/01/25 14:05:48.693068 [INFO] Adding Restrictions at level 0
2021/01/25 14:05:50.047939 [INFO] --Forward restrictions added: 1033
2021/01/25 14:05:50.047961 [INFO] --Reverse restrictions added: 1065

Everything's fine. The master code used to loose a restriction. This PR fixes it. Ready for review

purew
purew previously approved these changes Jan 27, 2021
Copy link
Contributor

@purew purew left a comment

Choose a reason for hiding this comment

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

LGTM

CHANGELOG.md Outdated
@@ -130,6 +130,7 @@
* FIXED: Remove redundant return statements [#2776](https://github.com/valhalla/valhalla/pull/2776)
* FIXED: Add support for geos-3.9 c++ api [#2739](https://github.com/valhalla/valhalla/issues/2739)
* FIXED: Fix check for live speed validness [#2797](https://github.com/valhalla/valhalla/pull/2797)
* FIXED: Store restrictions in the right tile [#2781](https://github.com/valhalla/valhalla/pull/2781)
Copy link
Member

Choose a reason for hiding this comment

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

we made a release please move this to the correct section above

@merkispavel merkispavel merged commit 1577f88 into master Jan 27, 2021
@merkispavel merkispavel deleted the bdir-ignores-restriction branch January 27, 2021 16:35
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.

3 participants