Skip to content

configure turn cost calculation#2957

Merged
karussell merged 50 commits intomasterfrom
turn_costs_calc
Sep 9, 2024
Merged

configure turn cost calculation#2957
karussell merged 50 commits intomasterfrom
turn_costs_calc

Conversation

@karussell
Copy link
Member

@karussell karussell commented Mar 25, 2024

Fixes #1590.

Use cases:

  • avoid left turns for motor vehicles
  • avoid zig zag routes e.g. for bike like described in Prefer cycleway=lane for bike #1500.
  • exclude too sharp turns for e.g. trucks set sharp_left_turn_costs and sharp_right_turn_costs to very high values.
  • if straight_costs gets a value you can avoid dense areas via avoiding too many junctions. As the ETA is unaffected this is similar to a custom model that reduces priority for urban_density==CITY.

Some of the configuration details are stated in core/src/main/resources/com/graphhopper/custom_models/bike_tc.json

Note that there are the following different angles:

  • for 0° until +-min_angle => turn costs is straight_costs (default is 0)
  • for min_turn_angle until min_sharp_angle => turn costs is left_turn_costs (default is 0)
  • for min_sharp_turn_angle until min_u_turn_angle => turn costs is sharp_left_turn_costs (default is 0)
  • for bigger than min_u_turn_angle => turn costs is u_turn_costs

Note:

  • left_turn_costs and right_turn_costs are symmetric
  • default min_turn_angle=25
  • default min_sharp_turn_angle=80
  • default min_u_turn_angle=180

The implementation fills an orientation encoded value where the forward value stores the orientation of the end segment of the edge and the backward value stores the orientation of the start segment of the edge. With that all turn angles can be calculated. Of course sometimes a "left turn" cannot be detected from the angle alone and topology must be considered but for now this orientation approach works good enough (and the topology approach did not work that well alone when I tried it before).

A more sophisticated implementation could also use different turn costs depending on the country or road_class but this and a request-based customization of the turn costs (moving it into the custom_model) should not be part of this PR.

@karussell karussell added this to the 10.0 milestone Apr 24, 2024
…ter change calcOrientation and related to xAxisAngle
…ngle and return u_turn_costs instead of infinity
@karussell karussell merged commit 7f79bbd into master Sep 9, 2024
@karussell karussell deleted the turn_costs_calc branch September 9, 2024 10:31
karussell added a commit that referenced this pull request Sep 25, 2024
OlafFlebbeBosch pushed a commit to OlafFlebbeBosch/graphhopper that referenced this pull request Oct 14, 2024
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.

Using turn costs, not just turn restrictions

1 participant

Comments