I’m not sure I’m in the right category with my question.
I learned a while ago from UPS and FedEx and perhaps other logistic companies which are avoiding left turns in routing their vehicles. I’m intrigued by that idea and looking for a place to try this. Neither Google Maps nor opensource routing software offers that option.
I noticed that Graphhopper is highly configurable and wondered whether I could customize a routing query in that way.
Would that be possible?
There is an experimental branch where you can configure the turn costs based on the turn angle: Using turn costs, not just turn restrictions · Issue #1590 · graphhopper/graphhopper · GitHub
That sounds cool. I guess I have to deploy the system myself to use this branch?
I installed the branch “turn_costs_calc” from github.
I also fetched ontario-latest.osm.pbf for my local area.
I configured the config.yml as described here: Change priority based on turn preference - #4 by karussell.
I put in the custom model configuration as described.
The result is rather unexpected as there are a lot of left turns in the routes.
Any advice?
-st
Uhm, it seems I changed the JSON at some point in the branch (see CustomModel + TurnCostsConfig) and so it is now:
{
"turn_costs": {
"straight": 1,
"left": 1000,
"right": 1
}
}
(Have updated the linked post)
I changed the custom model according to your suggestion. Unfortunately, there was no change in the outcome.
I wonder if I do everything correctly:
graph.encoded.values: orientation
profiles:
- name: car
vehicle: car
turn_costs: true
weighting: custom
custom_model:
distance_influence: 70
- I can access my local linux server after I changed the bindings in the config to 0.0.0.0
- I can do “normal” routing from point to point (can’t use addresses though)
- I activate the custom model text field in the UI and enter the following code
{
"priority": [],
"turn_costs": {
"straight": 1,
"left": 10000,
"right": 1,
"min_left_angle": 17,
"max_left_angle": 180,
"min_right_angle": -17,
"max_right_angle": -180
}
}
- I press Ctrl-Enter and observe a refresh of the webpage, but the result is the same.
Is there anything I can do with logging or debugging the process?
-st
Maybe debug into CustomModel.setTurnCostsConfig to see if the actual values end up there?
I tried this and with the change I proposed it worked (note the plural turn_costs
).
this comes from the log file:
2023-08-15 11:59:59.710 [dw-19 - POST /route?key=] INFO c.g.resources.RouteResource - xxx.xxx.x.x en_US Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/[115.0.0.0](http://115.0.0.0/) Safari/537.36 2, took: 141.2 ms, algo: alternative_route, profile: car, custom_model: distanceInfluence=null|headingPenalty=300.0|speedStatements=[]|priorityStatements=[]|areas=[]|turnCostConfig=leftCost=10000.0, rightCost=1.0, straightCost=1.0, minLeftAngle=17.0, maxLeftAngle=180.0, minRightAngle=-17.0, maxRightAngle=-180.0, alternatives: 3, distance0: 14193.2164241163, weight0: 2084.336217474581, time0: 18min, points0: 116, debugInfo: idLookup:8.22361E-4s; ; ;
Is that enough proof?
-st
Hm, strange. Can you try removing the graph-cache?
done it. The result is the same.
Should I try and use a different map?
-st
Tried it step by step and found a typo in your config
… it should be:
graph.encoded_values: orientation
Once this is changed you need to remove the graph-cache again …
Yessss! It worked. Klasse!
Now the next question: Is there a way to create a permanent custom profile on the server?
Yessss! It worked. Klasse!

create a permanent custom profile on the server?
Yes, it should work via copying the custom_model to the profile section:
profiles:
- name: car
vehicle: car
turn_costs: true
weighting: custom
custom_model: {
"turn_costs": {
"straight": 1,
"left": 10000,
"right": 1
}
}
Note, that yaml format is a bit picky when using the JSON directly and the closing bracket of the custom_model
section must have the same indentation like the the start of custom_model
(or convert the JSON to yaml format)