How to prevent unlawfull u-turns

Hi everyone, I am a little stuck figuring out a specific u-turn. I am hosting the latest Graphhopper version with a very recent planet osm file and got a user who noticed a unlawfull u-turn.

Which I agree with. First i asumed the relation was wrong in OSM data, and even edited a small section in JOSM to see it that is the case. However, using GraphHopper Maps | Route Planner on the same stretch, it does correctly finds an alternative.

Which is good! However, I am clearly missing some important configuration preventing non existing u-turn places.

Custom model

{
  "distance_influence": 90,
  "priority": [
    { "if": "!car_access", "multiply_by": "0" },
    { "if": "road_access == DESTINATION || road_access == PRIVATE", "multiply_by": "0.1" }
  ],
  "speed": [
    { "if": "true", "limit_to": "car_average_speed" }
  ]
}

Profile defined in config

    - name: car
      turn_costs:
        vehicle_types: [ "motor_vehicle", "motorcar" ]
        u_turn_costs: 1
        left_turn_costs: 1
        right_turn_costs: 1
        sharp_left_turn_costs: 2
        sharp_right_turn_costs: 2
      custom_model_files: [car.json]

...

profiles_lm: [bike, foot, car]

How i then post the route request

{"profile":"car","calc_points":true,"instructions":true,"points_encoded":false,"points":[[6.1407673358917,51.998575521226],[6.1372321844101,51.998066891662],[6.1375594139099,51.998846347597]],"snap_preventions":[],"ch.disable":true,"custom_model":{"priority":[],"u_turn_costs":50000000}}

I think i posted all the relevant information. I am using a few extra custom parsers and use more priority statements to prefer certain roads when calculating routes. However, that should and must not influence finding valid routes.

I would love to know what im doing wrong!

Hi

Maybe try setting the u-turn costs to a higher number (test with something huge like 1000), it may be that the alternative route is just much further and so the cost of 1 does not convince the engine to skp that turn.

I believe setting the cost to -1 is the equivalent of blocking u-turns as it means infinite cost.

Correct me if im wrong, but this will also have a global effect right? It is okay if an u-turn is needed for the shortest route, but I dont want u-turns where this is not allowed.

Sidenote, the reason i introduced slight penalties for right and left turns is because I noticed that sometimes a route goes off and on the motorway, presumably to avoid a small part when I discourage use of motorways in priority rules. However this is off topic for my main question.

In your first screenshot it looks like you selected the foot profile? Turn restrictions won’t apply to pedestrians. Then again pedestrians should not be allowed on this highway N338?!

Ah true, I usualy use leaflet to visualize graphhopper results and did not see the profile selection. I included the car profile in a picture.

However, you raise a good point. I do use the default foot profile shipped with the code.
Foot profile json

{
  "priority": [
    { "if": "!foot_access || hike_rating >= 2 || mtb_rating > 2", "multiply_by": "0" },
    { "else": "", "multiply_by": "foot_priority"},
    { "if": "country == DEU && road_class == BRIDLEWAY && foot_road_access != YES", "multiply_by": "0" },
    { "if": "foot_road_access == PRIVATE", "multiply_by": "0" }
  ],
  "speed": [
    { "if": "true", "limit_to": "foot_average_speed" }
  ]
}

Config file

    - name: foot
      custom_model_files: [foot.json, foot_elevation.json]

For the car profile configuration you showed the route should be illegal because of this turn restriction: Relation: 16764719 | OpenStreetMap
My next best guess why it is ignored in your case is that your OSM data might be outdated?