Repository navigation
scriptable turn statements: "turn_penalty" - #3174
Conversation
|
I'm on vacation next week but I'm looking forward to providing feedback once I'm back. 🙂 |
|
I like this. |
|
My opinions on the wording question:
|
|
Though I still maintain that, at least for road transportation, a 90° turn is a turn of regular sharpness, not a sharp turn. 🤪 But now that they aren't prescribed categories anymore, I shouldn't care that much. |
|
And I still think it's important to be clear that turn costs in the narrower sense of e.g. "discourage left turns" are not about angles. When some road goes left, even sharply, that's not a turn, that's just a bend. A left turn is (in many countries) when there's conflict with oncoming traffic, and you don't see that from the angle. Just like or even more than with estimating link travel time, I'm almost sure this ultimately isn't scriptable by looking just at local attributes. You will quickly want to look at the entire node with all its edges, and, for complicated intersections, at the entire complicated intersection. |
|
As a solution to the destination-restriction problem, it just sounds really, really good. |
| "priority": [ | ||
| { "if": "hgv == NO", "multiply_by": "0" }, | ||
| { "if": "!car_access && road_access != PRIVATE && hgv != DELIVERY && hgv != DESTINATION", "multiply_by": "0" }, | ||
| // also have a look into avoid_private_etc.json |
There was a problem hiding this comment.
Should we follow the car custom model and provide a avoid_delivery.json ?
|
I haven't tested the angle calculation changes, but this should be doable without conditions and only using modulo operations. |
… to slightly reduce CH prep time without much query speed slow down
…r fixes to custom models
* initial working state. fix for graphhopper#733 * move most of the turn cost config into new turn_time statements * support to specify "add":"Infinity" * rename 'turn time' to 'turn weight' * minor fix * turn_weight is only possible when turn_costs is configured * by default allow the turn_weight feature only on server-side * minor simplify * 'add' for speed is ok * minor comment * removed TODO NOW * delete file * for now no negative adds * minor * improvements and review comments * slightly reduce EdgeBasedNodeContractor.Params.maxPollFactorHeuristic to slightly reduce CH prep time without much query speed slow down * rename turn_weight to turn_penalty * readd bike_tc as might be usefull illustration too * move allow_turn_penalty_in_request into TurnCostsConfig and some minor fixes to custom models * add docs * minor



This PR implements scriptable statements for turns (currently the turn penalty, not turn time). I.e. one can now model advanced turn costs and there is no need for the several turn costs parameters in the config.yml (see
avoid_turns.json) and instead you can model much more complex situations like a turn cost for bigger roads or different costs for left hand traffic etc. Furthmore you can try all changes out at query time directly in the custom model. However, it needs to be enabled in the config.yml viaallow_turn_weight_in_request: truein theturn_costssection.Compared to the turn cost parameters that we currently have there are no downsides, except maybe the initial setup is a bit more complicated, but even query and import speed is comparable or slightly faster for the new scriptable
turn_penaltystatements. Here is the exampleavoid_turns.json:🎉 Work is sponsored by OPTITOOL (cc @otbutz)
TODOs:
decide on naminguseturn_weightandaddturn_penaltyinstead ofturn_weightturn_penaltytoo (for tests)turn_costsis named differently because the costs consists of the penalty and the time. So this should be fine. Different names with different meaning.allow_turn_penalty_in_requestinto TurnCostsConfigThe main driving force behind this feature was to fix the longstanding issue #733 via the idea mentioned here:
"add": "2500"it seems to be the right balance for this case (not sure yet, if we should use it for everything else too).Although there are some downsides with this change the destination-only (or other avoidance) cases behave finally exactly how they should: they are avoided except if a waypoint is on an edge (or in an area) with destination-only access. The acceptable detour can be controlled with the value for
add. Furthermore this change enables this "advanced avoidance" for other use cases, likehazmat_waterandhighway=track. Also it can be used to avoid country border crossings via the custom model without specially crafted polygons.And in the future we can use the same approach to fix a few problems for short ferries, but we would need to modify the ETA too not only the weight. I.e. instead of
turn_penaltywe would needturn_time. With this more realistic ferry times are possible.Downsides of this approach compared to just a low priority for destination-only cases:
turn_costssupport is already enabled.private(ordestination) tagging inside such an private (or destination-only) area will become very obvious. E.g. forpoint=51.11853%2C13.61062&point=51.12035%2C13.60681but it is easy to fix this IMO tagging mistake.This is likely detectable and fixable via some pre-processing.
Instead of the
turn_penaltywe could add barrier edges whenever there is a change e.g. from road access "yes" to "destination". But we would have to pre-process the data and create a boolean encoded value that is true whenever there is such a change and useaddinpriority. This would avoid that we need to enable turn costs, but then these cases need to be known before the import (and a different solution would be required for "per-request") and also the implementation of it sounds trickier, also regarding multiple edges which needs to be joined or junctions with different values.Note: I slightly adjusted the maxPollFactorHeuristic in EdgeBasedNodeContractor for ~10% faster preparation (compared to maxPollFactorHeuristic=5). With this the CH preparation compared to just turn restrictions is still 17% slower (95k sec vs 111k sec with private/destination avoidance; planet; car)