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

Implement depth-first-search to match way_ids with edge_ids #2848

Merged
merged 10 commits into from
Feb 16, 2021

Conversation

merkispavel
Copy link
Contributor

@merkispavel merkispavel commented Feb 9, 2021

Issue

This implementation handles the case when you might choose wrong direction more than once while matching way_ids with graph_ids. See the gurka test for better understanding

Tasklist

  • Add tests
  • Add #fixes with the issue number that this PR addresses
  • Update the docs with any new request parameters or changes to behavior described
  • Update the changelog

Requirements / Relations

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

{"type", "restriction"},
{"restriction", "no_left_turn"},
}},
};
Copy link
Contributor Author

@merkispavel merkispavel Feb 9, 2021

Choose a reason for hiding this comment

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

So we have FECB restriction and ABCD edges have the same way_id.
Let's say we're starting with the B node and trying to match [3, 2, 1] way_ids.

  • Step 1: we go towards node A as way_id(BA) == 3. But this is wrong direction so we fallback to node B
  • Step 2: we go towards node D as way_id(BCD) == 3. BUt this is wrong direction as well.
  • Step 3: The GetGraphIds function return no match found but it must return BCEF

@merkispavel
Copy link
Contributor Author

merkispavel commented Feb 9, 2021

I built tiles with florida.osm.pbf from master and this branch and got mismatch in restriction counts. Need to check that new restrictions are legal and not produced by a bug

2021/02/08 19:09:46.507802 [INFO] Adding Restrictions at level 2
2021/02/08 19:10:05.361094 [INFO] --Forward restrictions added: 512
2021/02/08 19:10:05.361302 [INFO] --Reverse restrictions added: 345
2021/02/08 19:10:05.361928 [INFO] Adding Restrictions at level 1
2021/02/08 19:10:08.703185 [INFO] --Forward restrictions added: 1078/1088 (+10)
2021/02/08 19:10:08.703238 [INFO] --Reverse restrictions added: 1213/1223 (+10)
2021/02/08 19:10:08.703524 [INFO] Adding Restrictions at level 0
2021/02/08 19:10:10.306843 [INFO] --Forward restrictions added: 1033/1037 (+4)
2021/02/08 19:10:10.307888 [INFO] --Reverse restrictions added: 1065/1069 (+4)

@merkispavel
Copy link
Contributor Author

merkispavel commented Feb 9, 2021

Uffff... I came across another bug: we don't look at the access mode while matching way_ids with graph_ids

@gknisely
Copy link
Member

gknisely commented Feb 9, 2021

@merkispavel is this ready for review or will you address the other issue you found

bool found;

// expand with the next way_id
found = ExpandFromNode(reader, lock, last_node, edge_ids, way_ids, way_id_index + 1, tile,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Calling ExpandFromNode(..., way_id_index + 1, ...) before ExpandFromNode(..., way_id_index, ...) let us not to worry about multiple edges with the last way id. So we need not remove duplicated way_ids in the prefix only

@@ -489,7 +424,7 @@ void build(const std::string& complex_restriction_from_file,
res_way_ids.push_back(restriction_to.to());

// walk in the forward direction (reverse in relation to the restriction)
std::deque<GraphId> tmp_ids = GetGraphIds(currentNode, reader, lock, res_way_ids);
std::vector<GraphId> tmp_ids = GetGraphIds(currentNode, reader, lock, res_way_ids);
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 just don't see sense in using deque here. It just confused me. But I can easily revert it if there's some profit

throw std::invalid_argument("Osm way id has already been used");
}
way_id = id;
way_id = std::stoull(found->second);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I needed a gurka test when multiple edges have the same way id. And this exception used to be thrown. Let me know if there's a better way to get such gurka test(in case you want to revert this piece of code)

Copy link
Member

Choose a reason for hiding this comment

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

@merkispavel we have added exception tests for the path and eta like this here But, it you don't think it will be useful for more tests in the future, I am fine how it is now.

@merkispavel
Copy link
Contributor Author

@merkispavel is this ready for review or will you address the other issue you found

@gknisely This PR doesn't break existing restrictions. What about the new restrictions - some of them are valid and some of them are not. But it's caused by another(unrelated to the current PR) bug (#2849)
So I guess it's ok to review it and merge imho

@merkispavel merkispavel marked this pull request as ready for review February 9, 2021 21:04
@merkispavel merkispavel requested a review from gknisely February 9, 2021 21:04
@mandeepsandhu
Copy link
Contributor

@merkispavel have you RAD tested this? If yes, were there any diffs?

@gknisely
Copy link
Member

gknisely commented Feb 10, 2021

@merkispavel is this ready for review or will you address the other issue you found

@gknisely This PR doesn't break existing restrictions. What about the new restrictions - some of them are valid and some of them are not. But it's caused by another(unrelated to the current PR) bug (#2849)
So I guess it's ok to review it and merge imho

This looks good, but can you send me a sample restriction for the above PR? #2849 I assume you saw it in the FL data set. You should be able to dump out the osmid for the restriction relation. Wondering if we really should be tossing relations if the access/modes on the ways don't match the access/modes on the relations for the restriction.

@merkispavel
Copy link
Contributor Author

merkispavel commented Feb 10, 2021

This looks good, but can you send me a sample restriction for the above PR? #2849 I assume you saw it in the FL data set. You should be able to dump out the osmid for the restriction relation. Wondering if we really should be tossing relations if the access/modes on the ways don't match the access/modes on the relations for the restriction.

@gknisely

https://www.openstreetmap.org/relation/9946366

Screen Shot 2021-02-10 at 14 51 24

@merkispavel
Copy link
Contributor Author

merkispavel commented Feb 10, 2021

@merkispavel have you RAD tested this? If yes, were there any diffs?

not yet @mandeepsandhu. I'll let you know RAD test status when i run it

@merkispavel
Copy link
Contributor Author

Rad tested the changes. Looks good

@merkispavel merkispavel merged commit 1cd806d into master Feb 16, 2021
@merkispavel merkispavel deleted the get-graph-ids branch March 9, 2021 04:28
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