Skip to content

Allow CountryRules to provide fallback values for toll - #2164

Merged
karussell merged 9 commits into
graphhopper:masterfrom
otbutz:spatial_toll_rule
Oct 29, 2021
Merged

karussell merged 9 commits into
graphhopper:masterfrom
otbutz:spatial_toll_rule

Conversation

@otbutz

@otbutz otbutz commented Oct 26, 2020

Copy link
Copy Markdown
Contributor

This should improve our toll information coverage for Germany and Austria. I'd really like to get this merged before i start to work on #1808 so that all intended features are already upstream.

@karussell karussell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, see my comments. (note that it also needs to be updated to master)

@otbutz

otbutz commented Sep 24, 2021

Copy link
Copy Markdown
Contributor Author

Any idea why the edge weight in the CustomWeightingTest increases?

@karussell

karussell commented Sep 24, 2021 •

Copy link
Copy Markdown
Member

You introduced MISSING("missing") and the rule their expects that all values != NO have toll.

@otbutz

otbutz commented Sep 24, 2021

Copy link
Copy Markdown
Contributor Author

Gotcha. Should i change the unittest here? The OSMTollParser doesn't store this value and only uses it internally.

@karussell

karussell commented Sep 27, 2021 •

Copy link
Copy Markdown
Member

As this is a different issue, can you remove MISSING from Toll for this PR?

And why do you think we should differentiate between NO and MISSING? Is there a use case you had in mind or for consistency reasons?

@otbutz

otbutz commented Sep 27, 2021 •

Copy link
Copy Markdown
Contributor Author

There's a difference between a way which is explicitly tagged as toll=no and a way without any toll information.
Most rules will only provide fallback values and should not override toll=no.

We could pass null for currentToll instead but having to handle null in all country rules is uglier IMHO.

This is also consistent with other encoded values which also treat MISSING as a distinct value like e.g Smoothness, Surface or TrackType

@karussell

Copy link
Copy Markdown
Member

This is also consistent with other encoded values

Yes. But are there really many streets that are tagged toll=no and if there are what would be the use case to differentiate between those two cases? (no and missing)

But again, I think this is a different issue and unnecessarily delays merging this PR.

@otbutz

otbutz commented Sep 27, 2021

Copy link
Copy Markdown
Contributor Author

This is also consistent with other encoded values

Yes. But are there really many streets that are tagged toll=no and if there are what would be the use case to differentiate between those two cases? (no and missing)

Basically toll=no accounts for 23% of all toll tags: https://taginfo.openstreetmap.org/keys/toll#values

As this PR intends to add a fallback logic, we should not override existing mapping information. e.g motorways in country X usually require toll to be paid. Mappers might tag ways with toll=no if they are explicitly exempt from this.

@karussell

Copy link
Copy Markdown
Member

Thanks, now I understand the problem :)

The problem I have is that this would break existing custom models that use toll (they can be in the request too!) and so this needs more care. (I wonder how we should handle such changes in general?)

@boldtrn

boldtrn commented Sep 27, 2021

Copy link
Copy Markdown
Member

+1 to differentiate between no and undefined. Some motorways are explicitly tagged with toll=no to show a difference from the default value of that country.

For example in Austria there are some parts of the motorways that have explicitly no toll and it would be good if that would not be overwritten by the default being yes.

@otbutz

otbutz commented Sep 27, 2021 •

Copy link
Copy Markdown
Contributor Author

The problem I have is that this would break existing custom models that use toll (they can be in the request too!) and so this needs more care. (I wonder how we should handle such changes in general?)

Is this really a problem as we do not encode MISSING ?

https://github.com/graphhopper/graphhopper/blob/6f052a2ad9d6bb5a9f57135f9d020a93c0e50ca7/core/src/main/java/com/graphhopper/routing/util/parsers/OSMTollParser.java#L68-L72

@karussell

Copy link
Copy Markdown
Member

Yes, this is a problem and the reason why the unit tests failed.

@otbutz

otbutz commented Sep 27, 2021

Copy link
Copy Markdown
Contributor Author

Yes, this is a problem and the reason why the unit tests failed.

As far as i understood this, the test doesn't set a value which causes the EV to pick up the default value which is now MISSING.
But this situation wouldn't arise for regular users as the parser will only encode NO,HGV or YES

@otbutz

otbutz commented Sep 27, 2021

Copy link
Copy Markdown
Contributor Author

Just checked my assumption by declaring MISSING as the last value in the Toll enum and keeping NO as the first one. With this change, the test completes without setting any toll values on the EdgeIteratorState.

So the only problem is the failing unittest itself, which blindly assumes that the default value is NO if no value has been explicitly set.

@otbutz

otbutz commented Sep 29, 2021

Copy link
Copy Markdown
Contributor Author

Existing custom models should also be fine as we encode only NO, HGV and MISSING:

  • "if": "toll == ALL" works
  • "if": "toll == HGV" works
  • "if": "toll == NO" works
  • "if": "toll != NO" works

@karussell

karussell commented Sep 29, 2021 •

Copy link
Copy Markdown
Member

The problem is that the meaning of toll != NO changes when we introduce MISSING. E.g. for the custom model

"priority": {
   "if": "toll != NO",
   "multiply_by": 0
}

the intent is to exclude tolls, but when we introduce MISSING this no longer works and you would need
toll == YES || toll == HGV.

@otbutz

otbutz commented Sep 29, 2021

Copy link
Copy Markdown
Contributor Author

@karussell

karussell commented Sep 29, 2021 •

Copy link
Copy Markdown
Member

Ok, I see. So you introduced MISSING only for the purpose of country rules and in the final graph we never have MISSING. This is a bit confusing I think and not consistent with the other encoded values.

@otbutz

otbutz commented Sep 29, 2021

Copy link
Copy Markdown
Contributor Author

I'm open for other solutions but this allows us to avoid null handling in the CountryRules.

@otbutz otbutz changed the title Allow spatial rules to provide fallback values for toll Allow CountryRules to provide fallback values for toll Sep 29, 2021
@otbutz
otbutz force-pushed the spatial_toll_rule branch 2 times, most recently from 28c915f to 81e861b Compare October 1, 2021 14:12
@otbutz

otbutz commented Oct 1, 2021

Copy link
Copy Markdown
Contributor Author

@karussell i'm now using Optional to avoid null handling or introducing new Toll values

@karussell

Copy link
Copy Markdown
Member

Hm, thanks for the effort here. Unfortunately it is not consistent with the other methods now :)

Ok. Let's introduce the MISSING value and do not overwrite it in the parser, so that everything is consistent and we really have MISSING values for missing tags.

We must write this change as a breaking one into the changelog. Furthermore we need to fix all examples, tests and docs where we use toll != NO. Do you think this is a better solution?

@otbutz

otbutz commented Oct 5, 2021

Copy link
Copy Markdown
Contributor Author

IMHO it is better to break things here and issue a warning. On the positive side, the user gains more flexibility as the CustomModels can handle MISSING at runtime.

@otbutz
otbutz force-pushed the spatial_toll_rule branch from 81e861b to 609c5e9 Compare October 5, 2021 10:57
@otbutz
otbutz requested a review from karussell October 5, 2021 10:58
@karussell karussell added this to the 5.0 milestone Oct 5, 2021
@otbutz

otbutz commented Oct 18, 2021

Copy link
Copy Markdown
Contributor Author

@karussell i resolved the changelog conflict

@otbutz

otbutz commented Oct 27, 2021

Copy link
Copy Markdown
Contributor Author

@karussell anything missing?

@karussell karussell left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, sure - nothing missing - thanks!

@karussell
karussell merged commit 65fdf55 into graphhopper:master Oct 29, 2021
aoles added a commit to GIScience/graphhopper that referenced this pull request Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants