Skip to content

Use MaxSpeed EV in the AbstractFlagEncoder - #2268

Closed
otbutz wants to merge 4 commits into
graphhopper:masterfrom
otbutz:max_speed_enc
Closed

otbutz wants to merge 4 commits into
graphhopper:masterfrom
otbutz:max_speed_enc

Conversation

@otbutz

@otbutz otbutz commented Mar 29, 2021

Copy link
Copy Markdown
Contributor

Fixes #2266

  • avoids parsing the max speed tags multiple times by using the encoded value
  • respects SpatialRules as they are used in the OSMMaxSpeedParser
  • lowered some max speed fallback values for Germany and Austria to match the limits of urban areas
  • adapted unittests

@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 for your pull request!

return 100;
return 50;
case LIVING_STREET:
return 4;

@karussell karussell Apr 16, 2021 •

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.

This does not look right. My understanding of the spatial rules was that they mirror the laws a country has regarding the maximum default speed. But 50km/h is only required inner city. Did you analyse the underlying cause why you had to change this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The SpatialRule acts as a fallback here. We don't know if we're in urban area or not so we have to go with the more defensive assumption that we are.

Otherwise things like #2266 happen: The routing prefers an urban residential road as the maxspeed fallback is 100km/h which is higher than the 70km/h of the B85. The routing acts accordingly and favors a detour.

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.

Hm, this sounds not the way to go. A spatial rule should stay like we defined and be identical to the local laws. If we mix in ETA improvements already here it won't work in the long term. So this PR is surely a step forward but we likely need to start with the ETA improvements before.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

A spatial rule should stay like we defined and be identical to the local laws.

I agree but the law clearly differentiates between urban and non-urban speed limits. Using 100km/h as the fallback for all residential roads is a clear violation of the law for most urban areas.

@karussell karussell Apr 16, 2021 •

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.

I see what you mean but then we need to expand the spatial rules to support inner and outer city limits. But IMO this is a bigger undertaking that we need to plan a bit. E.g. the first step would be to identify from OSM and other sources where "inner city" is, from there we could populate an encoded value inner_city and finally apply the correct rural or urban spatial rule.

For the first step we should be able to use vector data (define our own areas or grab data from OSM) and raster data (using e.g. satellite imagery).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right now, SpatialRules are in a Schrödinger's cat situation: they are both right and wrong depending on which road segment they handle. I agree that we should add the distinction to GH at some point in the future, but for now, defaulting to the lower boundaries is a workable solution.

Comment on lines +218 to +219
if (maxSpeed == MaxSpeed.UNSET_SPEED) {
return Double.NaN;

@karussell karussell Apr 16, 2021 •

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.

Should we refactor the code so that it always use MaxSpeed.UNSET_SPEED instead of two "magic" values?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

A bit unsure about it as MaxSpeed.UNSET_SPEED is rather specific to our encoding and the rest of the logic rolls with NaN which is IMHO a better representation of an unknown value. I'd rather see the default value of the MaxSpeed changed to NaN.

@karussell

Copy link
Copy Markdown
Member

Can we somehow introduce this "single max_speed parsing" without changing the country rules for now?

@otbutz

otbutz commented May 30, 2022

Copy link
Copy Markdown
Contributor Author

Ultimately we need to untangle this thicket of default values and derived ones from maximum values.

To summarize our current approach for routing:

  • use a value from the defaultSpeedMap as basis for the average speed
  • if we have a valid maxspeed tag for the way, we set the average speed to 90% of the limit

This leads to a few quirks:

  • the MaxSpeed EV is only used for details. e.g changing anything via CountryRules.getMaxSpeed() doesn't influence routing
  • we have a single defaultSpeedMap which tries to cover multiple countries

We could gut the CountryRules, remove getMaxSpeed() and roll with parsed MaxSpeed but that doesn't improve the average speed calculation.

My proposal would be to replace CountryRules.getMaxSpeed() with CountryRules.getAverageSpeed(), finally promoting CountryRules from an optional feature to a core component. Our current defaultSpeedMap could be serve as the default implementation. So we would end up with the same average speeds but with the opportunity to tune them on a per-country basis.

@easbar

easbar commented May 30, 2022

Copy link
Copy Markdown
Member

Ultimately we need to untangle this thicket of default values and derived ones from maximum values.

I'd like to see the current VehicleTagParsers split into (vehicle) access and speed parsers. With this in place the speed parsers could use a country rule method that modifies the (global) speed in a country-specific way, just like the other country rule methods modify some encoded value in a country-specific way. Ok, splitting the vehicle parsers into access and speed is probably not absolutely necessary for this, but since this needs to be done anyway...

@otbutz otbutz mentioned this pull request Jan 18, 2023
@karussell

Copy link
Copy Markdown
Member

Shall we close here or can you update to master? (also can you avoid changing the spatial rules -> see #2810)

@otbutz

otbutz commented May 8, 2023

Copy link
Copy Markdown
Contributor Author

Let's close this one and see how things turn out with #2810, which should solve the gist of the problems described in #2268 (comment).

@otbutz otbutz closed this May 8, 2023
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.

Use max_speed EV for the AbstractFlagEncoder

3 participants