You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Prevent u-turns at tower nodes that are connecting different OSM ways #2139
Btw: I ran into another problem: When I click on the above link (in @camelCaseSucks comment) and then change the vehicle to foot and back to car again I get another route once again, because for some reason turn_costs=false is appended to the url...
Yes, it really looks like it is :) But this is just a region border, so it should not even be considered by our OSM parser? If it was a ferry I would totally understand what happens because this would create a 'ghost junction' : #1858
Isn't it because the way in OSM is cut at the region border, so we get a tower node by definition? If one wants to avoid that, you would have to merge the features in OSM.
When GH parses OSM it first checks which of the nodes are really junctions (it counts how many ways there are for every node). And only for real junctions (>2 ways) a tower node is introduced. Otherwise the ways are simply merged into one GH edge (at least this is what I thought so far). But sure you are right this merging would only work if the tags were the same. However, here it looks like they are:
and there is no merging code. And even if such merging code would exist the question is really how we could avoid tower node creation when the tags would be different.
Ah ok so we never merge multiple ways, but we make sure that we do not split single ways when there is no real junction (and use pillar nodes instead). I think this is where my confusion came from.
Ok so in summary the problem is that there can be u-turns at nodes that are not junctions, simply because they connect two OSM ways.
changed the title [-]Suggested route includes illegal u-turn[/-][+]Prevent u-turns at tower nodes that are connecting different OSM ways[/+]on Oct 1, 2020
We might have to rethink about when we can allow U-turns because this depends on many things like the vehicle, the circumstances at the junction, the road class (or width), the traffic (or average/max speed) and other things.
We partially already do that when we say that a U-turn is only possible at junctions (due to the space) but we do not make it vehicle-dependent which should be easy as well (e.g. motorcycle vs. car vs. bike). And the road-property-dependency is likely even more important (but probably a bit trickier to implement). E.g. in this issue here it is a primary road and we could say we do not allow U-turns even for junctions (at primary roads)?
Yes we definitely should make this more specific. This probably will decrease performance, but certainly leads to higher quality routing. For the present case we could use road_environment (no u-turns on bridges, ever)? But really we should probably start with a list of cases where u-turns should / should not be allowed (and at which cost).
and there is no merging code. And even if such merging code would exist the question is really how we could avoid tower node creation when the tags would be different.
So any street which is split up in multiple connected OSM ways is going to produce tower nodes at its joints?
At the moment we create a tower node as soon as an OSM node is used from two or more OSM ways (or if it is terminal). This already depends on the vehicle, i.e. if just car is configured then only car-accessible OSM ways are considered.
Another example: https://www.openstreetmap.org/changeset/109903470
Just by looking at the relations that have been created in this changeset you will easily understand that something has gone off rails here. Sure, that particular OSM contributor was a novice when the changeset was created and also apparently did not understand how turn restriction relations work but we have to look deeper why the user did it in the first place. You can find the initial reason in the changeset’s comment. Although it speaks of “some map issues”, it actually means that the user has had some ill advised U-turn encounters in his/her routing app and assumed that because the routing algorithm is more or less perfect (or immutable for his/her purposes), there has to be something wrong with the map. Perhaps that user was even encouraged by the routing app’s developers to “fix the user’s problem” by “fixing the map”?
You can find many similar examples in the Seattle, WA area too.
I do not know for sure whether Amazon uses Graphhopper for its routing apps but I have a gut feeling they might do. Amazon is not an outlier here, many other delivery and ride sharing employees suffer from similar problems and try to mitigate this issue by “fixing the map”.
If we did not cover this algorithmically we wouldn't be able to calculate such routes at all. There can always be situations where u-turns are the only possible option, like a curbside constraint pointing towards the end of a dead-end street: One has to turn around to get out of such a street again, otherwise we would not find a path at all. This is the reason the u_turn_cost parameter cannot be infinite.
Please, excuse me for not being a routing expert but isn’t this a special case? I would assume that from a routing perspective there is no U-turn involved in this case. You start a fresh route search in the only feasible direction?
For a safe and/or comfortable driving experience I think applications need to find a good way to tell drivers they need to turn around at the next suitable spot, and not just show them the next turn of the calculated route. Say, for example the route contains a u-turn (or some loop that avoids it), then an informed driver can find the next spot where this is possible and turn around instead of blindly following the route.
🤔 The thing is that experience and reality have proven that there is no safe or comfortable way of saying to drivers to make a U-turn.
Long time ago, when in-car-navigation was new, companies like TomTom and many car makers encountered basically the same problem. Initially, drivers were told to “make a U-turn when possible or safe”. And, guess what? Drivers did whatever they wanted, mostly dangerous stuff and accidents, because they felt the pressure to comply with navigation as soon as possible. For many drivers this kind of pressure increased the longer it took them to do the U-turn. You can imagine that operating any heavy machinery under pressure is not a good idea. It is just how human psyche works. So, the solution was to basically avoid these rather dangerous “make a U-turn when possible or safe” messages at any cost. U-turns are not dangerous per se but it is a very unnatural maneuver for most drivers, especially in areas they are not familiar with. Most of the time, drivers go from A to B and this is also what they expect from their navigation. They do not care if there is a loop involved in the route. They want to get safely and stress free to their destination.
Typically, OSM mapping shouldn't be done for routers specifically, but turn restrictions might be an exception, because routing is the only reason turn restrictions are mapped at all?
True.
Or we could assume that doing a u-turn is basically never possible, which corresponds to a large (global) u-turn cost. In this case no-u-turn relations will hardly ever be needed or useful.
I think that although this may not be the most efficient basic assumption, especially in those jurisdictions that legally allow a U-turn at arbitrary junctions by default, this is the smarter and safer assumption.
Do you suggest that:
routers should try to avoid u-turns as much as possible by default everywhere, including at junctions where there is no traffic sign or turn relation (a large u_turn_cost parameter in our case)
👍 Yes.
restriction relations should mostly be used for left/right/normal turns, but not really for u-turns?
no_u_turn restrictions can and should be mapped. But, only where it makes sense from a flow of traffic or routing point of view. When you assume (or come to the conclusion) that only a safe router is a router with a very high U-turn cost by default then one class of no_u_turn restriction relations becomes obsolete, namely those that have identical ways in the from and to roles. Why? Because a safe and sane router always optimizes for a loop or a turning_circle (or the like) first and will basically almost never suggest a U-turn at an arbitrary junction node.
no-u-turn traffic signs can still be mapped using the traffic_sign tag in OSM for completeness, but they won't really be used by routing software
Right, because of the above assumption about a safe and sane router.
Just by looking at the relations that have been created in this changeset you will easily understand that something has gone off rails here.
Yes, I see, this is unfortunate.
Please, excuse me for not being a routing expert but isn’t this a special case? I would assume that from a routing perspective there is no U-turn involved in this case.
Yes, it is a special case, but one that needs to be covered. But if the u-turn costs are sufficiently high u-turns will only be suggested for this special case (when there really is no other option). Actually there always needs to be some kind of constraint (like a one-way road, turn restriction, etc.) for a u-turn to occur, otherwise there would always be a path that does not go to the place where the u-turn occurs at all.
You start a fresh route search in the only feasible direction?
You cannot tell what is the feasible direction without calculating the route. For example if you want to prevent u-turns at the stops of a multi-stop route you need to constrain the starting direction at each stop. And once you do that you might find you are in the situation where going into this direction it is not possible to turn around without a u-turn. Imagine this road network where you arrive at s from the West. Your only options are doing a u-turn at s, or continuing in Eastern direction and doing a u-turn somewhere. You can't tell if turning around without a u-turn is possible without exploring the road network (running the routing algorithm). But once you found the route and see it includes a u-turn you could tell the driver to turn around wherever possible, right when she gets back to the car and even before she starts driving to the next stop.
-------
|
----s-------------------
| | |
The thing is that experience and reality...
Thanks for your input, this sounds reasonable.
Ok, I think there are basically two issues here:
GraphHopper (using default settings and the hosted API) suggests u-turns too often
Some mappers add too many non-sensical no_u_turn restriction relations to OSM
For 1) we need to think about our settings and there is an issue with the relationship of the priority and u_turn_costs in CustomWeighting (the meaning of the u_turn_costs parameter changes once the priority is below 1), something we are currently investigating.
For 2) I think it is most important to use the OSM wiki to communicate what should and should not be mapped. Not only for mappers adding these relations but also for those removing them again, so there is something they can argue with. Contacting these mappers / companies directly could also help.
The issues could or could not be related. Like I said, GraphHopper currently still ignores the no_u_turn tag: #2570, so 'fixing' the map does not even change anything, at least when using vanilla GraphHopper.
Yes, with #2761 I got the same route as OSRM (using the turning circle at the end of Winding Wood Court). And when I increased the u_turn_costs (without this PR) I got the Valhalla route plus another alternative:
At first sight it seems logical to add no-u-turn tagging to OSM, because there are traffic signs that indicate this (just like for normal turn restrictions), but tagging this everywhere to satisfy the routers, even in places where there is no 'no u-turn' sign, would be the wrong thing to do.
It is already done in some cities. Not 100% coverage of course, but close to >90%.
Simply because of safety considerations, it is almost always a bad idea to suggest a U-turn to any driver at any arbitrary junction node.
Maybe it is in your country, but in many others it's not. There is at least two cases where u-turns aren't something special:
dedicated u-turn lanes
regular city junctions with traffic lights.
The thing is, in many cases it's necessary to use curbside constraint, otherwise the router will suggest illegal turns in the middle of the road (yes, this means every other OSM router I know is broken by design). And with this constraint it's also necessary to correctly suggest u-turns, respecting mapped restrictions and in some cases implicit restrictions.
example
This is the case I'm talking about. Without curbside constraint every router will suggest the red path from A to B, not respecting which side of the road you are on. Here it means taking forbidden u-turn across the street, and then either another forbidden u-turn or stopping on the other side of the street and walking across.
With Graphhopper one can account for that, but then u-turns become a problem. Currently I can either forbid them altogether (the default), or allow them anywhere regardless of the restrictions (the blue line on the picture). Both are unusable.
It is already done in some cities. Not 100% coverage of course, but close to >90%.
Can you please provide some links to the cases or mention some of the cities you have in mind?
Maybe it is in your country, but in many others it's not.
I'm not sure this depends on the country much. I think it is pretty clear that there are always junctions where u-turns are possible and/or reasonable and others where they are inappropriate, dangerous or even impossible. So whichever default is used it will be wrong in many cases. Suggesting a u-turn to a driver that might be dangerous or impossible seems a lot more problematic to me than avoiding it and suggesting an alternative (possibly longer) route instead. Don't you agree?
There is at least two cases where u-turns aren't something special:
dedicated u-turn lanes
regular city junctions with traffic lights.
I'm not sure what you are trying to say. Yes, there are junctions with dedicated u-turn lanes and some with traffic lights, and doing a u-turn there might be possible. So generally there are junctions where doing a u-turn is possible and safe. But like I said, there are also many junctions (and even more nodes in GraphHopper that one probably wouldn't even call a junction, but that technically are junctions for GraphHopper because they are connecting different edges) where doing a u-turn is dangerous or impossible, so I think the better default is avoiding u-turns in general.
And with this constraint it's also necessary to correctly suggest u-turns, respecting mapped restrictions and in some cases implicit restrictions.
When curbside constraints are used some routes can become impossible without doing a u-turn. In many other cases driving some kind of loop can also work, even though that might not be ideal, because there might be a route that uses a legal/reasonable u-turn.
Without curbside constraint every router will suggest the red path from A to B, not respecting which side of the road you are on. Here it means taking forbidden u-turn across the street, and then either another forbidden u-turn or stopping on the other side of the street and walking across.
Yes, if the road is mapped as a single way in OSM there is no way one can tell there are separate lanes and without curbside information it is not clear going from A to B directly is not the desired route.
Currently I can either forbid them altogether (the default), or allow them anywhere regardless of the restrictions (the blue line on the picture). Both are unusable.
You can choose the u_turn_costs parameter anywhere between 0 (the blue line) and infinity (the default). If you use a finite value the u-turns may occur if they are necessary but will be generally avoided (in this case the route would probably do some kind of loop). Using a high, but finite value is a compromise: You might get routes that take a detour, even though a shorter route would be possible doing a u-turn, but on the other hand you are also avoiding u-turns that might be dangerous. It appears to me that you are mostly concerned about the detour?
At first sight it seems logical to add no-u-turn tagging to OSM, because there are traffic signs that indicate this (just like for normal turn restrictions), but tagging this everywhere to satisfy the routers, even in places where there is no 'no u-turn' sign, would be the wrong thing to do.
It is already done in some cities. Not 100% coverage of course, but close to >90%.
This should not have happened and should not happen. It just bloats the database and wastes compute cycles when routing. I am not sure why exactly this happened but routing algorithms with broken basic assumptions may have contributed to it. People, especially those companies who payed people to add this bloat data, should take responsibility and remove it from OSM.
Maybe it is in your country, but in many others it's not.
This has nothing to do with the country or more specifically, the traffic code you consider. As a general rule; just because something is legal or is not forbidden by regulations does not imply that it is also safe or smart to do, or even physically possible. For example, most jurisdictions do not forbid jumping out the window, yet it is neither safe nor smart to do. The same goes for traffic code rules. Just because some traffic codes allow or do not forbid u-turns on specific junctions (often with traffic signals only) by default, it does not mean that it is always safe or smart to do a u-turn on every (such) junction.
We are talking here about sane and safe global routing algorithm assumptions, not legal rules or restrictions. OSM turn restriction relations have been designed for mapping the flow of traffic (for routers). Hence, OSM turn restriction relation instances can be identical to legal restrictions on the road but they do not always have to. They should only be used when needed to restrict the modeled default flow of traffic, not to override any traffic code’s legal default.
dedicated u-turn lanes
These have never been disputed nor they have had an effect on routing. Dedicated u-turn lanes are a traffic flow and safety tool for road engineers. Roads with dedicated u-turn lanes are by definition designed for safe u-turns and often employ dedicated road geometry, which is also consequently reflected in OSM data. Hence, as long as the road geometry has been properly mapped in OSM, routing algorithms always have, can, should, and will route u-turns there if needed.
regular city junctions with traffic lights
Again, you are referring to the traffic code only without considering safety when routing (and finally driving). The issue is that OSM has no data type to indicate how safe or unsafe it is to make a u-turn at any junction (except for topology data derived from road geometry data, or potentially maybe no_u_turn restrictions in rare cases but this is rather the exception than the rule).
The thing is, in many cases it's necessary to use curbside constraint, otherwise the router will suggest illegal turns in the middle of the road (yes, this means every other OSM router I know is broken by design).
No. No routing algorithm will suggest a u-turn on sections (edges) between junctions (junction nodes). It is just that routing algorithms search for the shortest path from A to B and it has no clue (input parameter) which side of the road you are on.
Without curbside constraint every router will suggest the red path from A to B, not respecting which side of the road you are on.
This is not a bug or some deficiency but the effect of pure theory. Anyhow, what you can do already is to add an intermediate destination on the same edge you start your route in the direction you want to go. Note that this does not and will not invalidate the general assumptions on safe and sane u-turns, and the routing algorithm is going to compute a loop if necessary.
Suggesting a u-turn to a driver that might be dangerous or impossible seems a lot more problematic to me than avoiding it and suggesting an alternative (possibly longer) route instead. Don't you agree?
Maybe; maybe not. It depends on the user/driver and their specific use case. That's why it's configurable, right?
I'm not sure what you are trying to say.
Sorry, maybe that's because I have two different things in mind.
First, the general observation, not about any specific case. People do u-turns all the time, at least in the cities I lived in. So when the router ignores potential route with the u-turn the driver knows is legal and safe, and suggests 2x longer route instead, there's a strong chance this router will go out of the window. Same with suggesting u-turn where it's not legal or impossible.
I think this is not the case where one can strongly de-prioritize u-turns, trading potential longer routes for assumed safety. Both will be considered broken.
Second, the specific use case where this issue is more clear and even critical: calculating routes for taxi drivers.
There is a taxi company in my city that is using routing on the OSM data (possibly OSRM, but I don't know for sure). They need to calculate the exact route the driver will take (including specific side of the street) to measure the distance and display the price. Because of that long detours are not acceptable, as well as impossible/illegal u-turns.
Currently they have an issue with routing that I showed in the picture in the previous post. They don't know how to fix this in the router, so they are trying to 'fix' the map by splitting the streets in two ways (even where that is against common practice) and messing up everything around in the process. Our local OSM community had enough of this and we wanted to suggest them a better router.
Anyhow, what you can do already is to add an intermediate target on the same edge you start your route in the direction you want to go
Suggesting a u-turn to a driver that might be dangerous or impossible seems a lot more problematic to me than avoiding it and suggesting an alternative (possibly longer) route instead. Don't you agree?
Maybe; maybe not. It depends on the user/driver and their specific use case. That's why it's configurable, right?
There is no maybe. The router has no way of telling without adequate data how safe or unsafe a u‑turn maneuver may be (or whether it is even physically possible) at an arbitrary junction node, except for turning_circle and turning_loop. Period. Furthermore, the statistics and experience of routing vendors regarding u‑turns have been conclusive for a very long time.
The u‑turn cost is configurable to be able to compute multi‑stop routes (which is far more complex than most people think at first glance because it requires multi‑stage route searching) and because there are corner cases in certain situations where you have to run multiple searches with different parameters in order to get to a solution.
Second, the specific use case where this issue is more clear and even critical: calculating routes for taxi drivers.
There is a taxi company in my city that is using routing on the OSM data (possibly OSRM, but I don't know for sure). They need to calculate the exact route the driver will take (including specific side of the street) to measure the distance and display the price. Because of that long detours are not acceptable, as well as impossible/illegal u-turns.
Currently they have an issue with routing that I showed in the picture in the previous post. They don't know how to fix this in the router, so they are trying to 'fix' the map by splitting the streets in two ways (even where that is against common practice) and messing up everything around in the process. Our local OSM community had enough of this and we wanted to suggest them a better router.
Then they have to:
use the right tool for their needs, like a sane router,
configure the router for their purpose correctly, and
stop mapping for any router but map to OSM guidelines only.
Furthermore, taxi companies or ride sharing services that have to project the cost and route for a customer can only do what it says: project. In this business it is impossible to always project the exact cost ahead of time, that’s the nature of things. Just think about accidents or any other unforeseeable event on the road that is going to lead to a detour. Hence, sometimes customers will pay more, sometimes less than the projected price after the ride. Usually, there is something like a ±5% tolerance deemed acceptable in the final price. Or, there is a minimum price added on top of the projected price to account for these unforeseen detours.
No router is perfect. And, like with everything, you have to know your trade. Sometimes you have to reconfigure the router and sometimes you have to edit the map because the map is not perfect either. But, never edit the map for anything specific but to mapping guidelines only.
AFAKT, this junction has been mapped largely correctly, except for the dead data no_u_turn relation, which is complete non‑sense. Additionally, imho this only_right_turn relation would have been better mapped with no_left_turn. Note that no_left_turn ≭ only_right_turn. Neither are legally and in effect and traffic signs equivalent.
Maybe; maybe not. It depends on the user/driver and their specific use case. That's why it's configurable, right?
Yes, you're right what is the better default certainly depends on the specific use case and it is a good thing it is configurable. For actual driving/navigation I would still prefer a detour over a possibly dangerous or illegal u-turn. The aware driver will still be able to find a spot to turn around safely (that the router's data might not contain), and a less aware driver might not even notice there was a detour at all when driving a bit of a loop.
when the router ignores potential route with the u-turn the driver knows is legal and safe, and suggests 2x longer route instead, there's a strong chance this router will go out of the window. Same with suggesting u-turn where it's not legal or impossible.
That is exactly the problem. Whichever default one uses there will be lots of cases where the opposite setting would have been better. So the real question here is how the false cases can be reduced, i.e. how can we find locations in OSM data where u-turns are reasonable and where they need to be avoided as much as possible? And what is the default (in OSM)? For example should the default assumption be that u-turns are nowhere possible and possible u-turns need to be tagged explicitly? Or should it be that u-turns are possible basically everywhere (at all 'junctions'?) unless there is a no_u_turn restriction? Or maybe this should depend on some tags like highway, lanes etc.? I could not find an answer to this question in the OSM wiki. And as long as there is no agreement there, mappers won't know how to map and router developers won't know how to interpret the data.
They don't know how to fix this in the router, so they are trying to 'fix' the map by splitting the streets in two ways (even where that is against common practice) and messing up everything around in the process. Our local OSM community had enough of this and we wanted to suggest them a better router.
This is very bad of course. Maybe the best the OSM community can do would be establishing clear guidelines how turn restrictions should be mapped? Which brings me back to my previous question. Unless the guidelines are clear it is hard to hold anyone accountable for tagging or not tagging something? What do you think GraphHopper can do about this?
Activity
easbar commentedon Oct 1, 2020
Thanks for reporting!
This seems to be a u-turn, because if I set u_turn_costs to infinity I get the same route as on OSRM:
https://graphhopper.com/maps/?point=45.501467%2C-122.661254&point=45.501237%2C-122.66142&ch.disable=true&u_turn_costs=-1
Apparently there is a tower node in the middle of the bridge, even though there is no junction. There is a region border though:
@karussell any idea why we get a tower node here?
Btw: I ran into another problem: When I click on the above link (in @camelCaseSucks comment) and then change the vehicle to foot and back to car again I get another route once again, because for some reason
turn_costs=falseis appended to the url...karussell commentedon Oct 1, 2020
No, this looks strange. As this is the main issue for me here - should I rename the issue title?
outch, this is likely yet another bug in the UI :/
otbutz commentedon Oct 1, 2020
https://www.openstreetmap.org/way/587574521
easbar commentedon Oct 1, 2020
What do you think is suspicious here?
otbutz commentedon Oct 1, 2020
It might be the line crossing the bridge
easbar commentedon Oct 1, 2020
Yes, it really looks like it is :) But this is just a region border, so it should not even be considered by our OSM parser? If it was a ferry I would totally understand what happens because this would create a 'ghost junction' : #1858
boldtrn commentedon Oct 1, 2020
Isn't it because the way in OSM is cut at the region border, so we get a tower node by definition? If one wants to avoid that, you would have to merge the features in OSM.
easbar commentedon Oct 1, 2020
When GH parses OSM it first checks which of the nodes are really junctions (it counts how many ways there are for every node). And only for real junctions (>2 ways) a tower node is introduced. Otherwise the ways are simply merged into one GH edge (at least this is what I thought so far). But sure you are right this merging would only work if the tags were the same. However, here it looks like they are:
https://www.openstreetmap.org/way/123374695
vs
https://www.openstreetmap.org/way/587574521
But I am pretty sure there are similar cases where the tags are different and then we would have the same problem despite the merging.
karussell commentedon Oct 1, 2020
Ah, yeah. This is the reason ...
... as soon as 2 ways use the same node a tower node is introduced: https://github.com/graphhopper/graphhopper/blob/master/reader-osm/src/main/java/com/graphhopper/reader/osm/OSMReader.java#L550
and there is no merging code. And even if such merging code would exist the question is really how we could avoid tower node creation when the tags would be different.
Related #758
easbar commentedon Oct 1, 2020
Ah ok so we never merge multiple ways, but we make sure that we do not split single ways when there is no real junction (and use pillar nodes instead). I think this is where my confusion came from.
Ok so in summary the problem is that there can be u-turns at nodes that are not junctions, simply because they connect two OSM ways.
[-]Suggested route includes illegal u-turn[/-][+]Prevent u-turns at tower nodes that are connecting different OSM ways[/+]karussell commentedon Oct 1, 2020
We might have to rethink about when we can allow U-turns because this depends on many things like the vehicle, the circumstances at the junction, the road class (or width), the traffic (or average/max speed) and other things.
We partially already do that when we say that a U-turn is only possible at junctions (due to the space) but we do not make it vehicle-dependent which should be easy as well (e.g. motorcycle vs. car vs. bike). And the road-property-dependency is likely even more important (but probably a bit trickier to implement). E.g. in this issue here it is a primary road and we could say we do not allow U-turns even for junctions (at primary roads)?
easbar commentedon Oct 1, 2020
Yes we definitely should make this more specific. This probably will decrease performance, but certainly leads to higher quality routing. For the present case we could use road_environment (no u-turns on bridges, ever)? But really we should probably start with a list of cases where u-turns should / should not be allowed (and at which cost).
otbutz commentedon Oct 1, 2020
So any street which is split up in multiple connected OSM ways is going to produce tower nodes at its joints?
karussell commentedon Oct 1, 2020
At the moment we create a tower node as soon as an OSM node is used from two or more OSM ways (or if it is terminal). This already depends on the vehicle, i.e. if just car is configured then only car-accessible OSM ways are considered.
16 remaining items
JakeSmarter commentedon Feb 23, 2023
I have just recently removed some here: https://www.openstreetmap.org/changeset/132897711
Perhaps you can download just the changeset and recreate how it looked before. It was one giant mess of U-turns. Please, note all the superfluous U-turn relations I had to delete.
Another example:

https://www.openstreetmap.org/changeset/109903470
Just by looking at the relations that have been created in this changeset you will easily understand that something has gone off rails here. Sure, that particular OSM contributor was a novice when the changeset was created and also apparently did not understand how turn restriction relations work but we have to look deeper why the user did it in the first place. You can find the initial reason in the changeset’s
comment. Although it speaks of “some map issues”, it actually means that the user has had some ill advised U-turn encounters in his/her routing app and assumed that because the routing algorithm is more or less perfect (or immutable for his/her purposes), there has to be something wrong with the map. Perhaps that user was even encouraged by the routing app’s developers to “fix the user’s problem” by “fixing the map”?You can find many similar examples in the Seattle, WA area too.
I do not know for sure whether Amazon uses Graphhopper for its routing apps but I have a gut feeling they might do. Amazon is not an outlier here, many other delivery and ride sharing employees suffer from similar problems and try to mitigate this issue by “fixing the map”.
Please, excuse me for not being a routing expert but isn’t this a special case? I would assume that from a routing perspective there is no U-turn involved in this case. You start a fresh route search in the only feasible direction?
🤔 The thing is that experience and reality have proven that there is no safe or comfortable way of saying to drivers to make a U-turn.
Long time ago, when in-car-navigation was new, companies like TomTom and many car makers encountered basically the same problem. Initially, drivers were told to “make a U-turn when possible or safe”. And, guess what? Drivers did whatever they wanted, mostly dangerous stuff and accidents, because they felt the pressure to comply with navigation as soon as possible. For many drivers this kind of pressure increased the longer it took them to do the U-turn. You can imagine that operating any heavy machinery under pressure is not a good idea. It is just how human psyche works. So, the solution was to basically avoid these rather dangerous “make a U-turn when possible or safe” messages at any cost. U-turns are not dangerous per se but it is a very unnatural maneuver for most drivers, especially in areas they are not familiar with. Most of the time, drivers go from A to B and this is also what they expect from their navigation. They do not care if there is a loop involved in the route. They want to get safely and stress free to their destination.
True.
I think that although this may not be the most efficient basic assumption, especially in those jurisdictions that legally allow a U-turn at arbitrary junctions by default, this is the smarter and safer assumption.
👍 Yes.
no_u_turnrestrictions can and should be mapped. But, only where it makes sense from a flow of traffic or routing point of view. When you assume (or come to the conclusion) that only a safe router is a router with a very high U-turn cost by default then one class ofno_u_turnrestriction relations becomes obsolete, namely those that have identical ways in thefromandtoroles. Why? Because a safe and sane router always optimizes for a loop or aturning_circle(or the like) first and will basically almost never suggest a U-turn at an arbitrary junction node.Right, because of the above assumption about a safe and sane router.
easbar commentedon Feb 24, 2023
Yes, I see, this is unfortunate.
Yes, it is a special case, but one that needs to be covered. But if the u-turn costs are sufficiently high u-turns will only be suggested for this special case (when there really is no other option). Actually there always needs to be some kind of constraint (like a one-way road, turn restriction, etc.) for a u-turn to occur, otherwise there would always be a path that does not go to the place where the u-turn occurs at all.
You cannot tell what is the feasible direction without calculating the route. For example if you want to prevent u-turns at the stops of a multi-stop route you need to constrain the starting direction at each stop. And once you do that you might find you are in the situation where going into this direction it is not possible to turn around without a u-turn. Imagine this road network where you arrive at s from the West. Your only options are doing a u-turn at s, or continuing in Eastern direction and doing a u-turn somewhere. You can't tell if turning around without a u-turn is possible without exploring the road network (running the routing algorithm). But once you found the route and see it includes a u-turn you could tell the driver to turn around wherever possible, right when she gets back to the car and even before she starts driving to the next stop.
Thanks for your input, this sounds reasonable.
Ok, I think there are basically two issues here:
For 1) we need to think about our settings and there is an issue with the relationship of the priority and u_turn_costs in CustomWeighting (the meaning of the u_turn_costs parameter changes once the priority is below 1), something we are currently investigating.
For 2) I think it is most important to use the OSM wiki to communicate what should and should not be mapped. Not only for mappers adding these relations but also for those removing them again, so there is something they can argue with. Contacting these mappers / companies directly could also help.
The issues could or could not be related. Like I said, GraphHopper currently still ignores the no_u_turn tag: #2570, so 'fixing' the map does not even change anything, at least when using vanilla GraphHopper.
JakeSmarter commentedon Feb 24, 2023
Thank you for acknowledging the issue with understanding.
Just FYI, it is interesting to see how different routers come to different solutions in this case.


I like OSRM's solution. 😉
otbutz commentedon Feb 24, 2023
GH should yield a similar result with the PR from @easbar: #2761
easbar commentedon Feb 24, 2023
Yes, with #2761 I got the same route as OSRM (using the turning circle at the end of Winding Wood Court). And when I increased the u_turn_costs (without this PR) I got the Valhalla route plus another alternative:
Arcturuss commentedon Jun 12, 2024
It is already done in some cities. Not 100% coverage of course, but close to >90%.
Maybe it is in your country, but in many others it's not. There is at least two cases where u-turns aren't something special:
The thing is, in many cases it's necessary to use curbside constraint, otherwise the router will suggest illegal turns in the middle of the road (yes, this means every other OSM router I know is broken by design). And with this constraint it's also necessary to correctly suggest u-turns, respecting mapped restrictions and in some cases implicit restrictions.
example
This is the case I'm talking about. Without curbside constraint every router will suggest the red path from A to B, not respecting which side of the road you are on. Here it means taking forbidden u-turn across the street, and then either another forbidden u-turn or stopping on the other side of the street and walking across.
With Graphhopper one can account for that, but then u-turns become a problem. Currently I can either forbid them altogether (the default), or allow them anywhere regardless of the restrictions (the blue line on the picture). Both are unusable.
easbar commentedon Jun 12, 2024
Can you please provide some links to the cases or mention some of the cities you have in mind?
I'm not sure this depends on the country much. I think it is pretty clear that there are always junctions where u-turns are possible and/or reasonable and others where they are inappropriate, dangerous or even impossible. So whichever default is used it will be wrong in many cases. Suggesting a u-turn to a driver that might be dangerous or impossible seems a lot more problematic to me than avoiding it and suggesting an alternative (possibly longer) route instead. Don't you agree?
I'm not sure what you are trying to say. Yes, there are junctions with dedicated u-turn lanes and some with traffic lights, and doing a u-turn there might be possible. So generally there are junctions where doing a u-turn is possible and safe. But like I said, there are also many junctions (and even more nodes in GraphHopper that one probably wouldn't even call a junction, but that technically are junctions for GraphHopper because they are connecting different edges) where doing a u-turn is dangerous or impossible, so I think the better default is avoiding u-turns in general.
When curbside constraints are used some routes can become impossible without doing a u-turn. In many other cases driving some kind of loop can also work, even though that might not be ideal, because there might be a route that uses a legal/reasonable u-turn.
Yes, if the road is mapped as a single way in OSM there is no way one can tell there are separate lanes and without curbside information it is not clear going from A to B directly is not the desired route.
You can choose the u_turn_costs parameter anywhere between 0 (the blue line) and infinity (the default). If you use a finite value the u-turns may occur if they are necessary but will be generally avoided (in this case the route would probably do some kind of loop). Using a high, but finite value is a compromise: You might get routes that take a detour, even though a shorter route would be possible doing a u-turn, but on the other hand you are also avoiding u-turns that might be dangerous. It appears to me that you are mostly concerned about the detour?
JakeSmarter commentedon Jun 12, 2024
This should not have happened and should not happen. It just bloats the database and wastes compute cycles when routing. I am not sure why exactly this happened but routing algorithms with broken basic assumptions may have contributed to it. People, especially those companies who payed people to add this bloat data, should take responsibility and remove it from OSM.
This has nothing to do with the country or more specifically, the traffic code you consider. As a general rule; just because something is legal or is not forbidden by regulations does not imply that it is also safe or smart to do, or even physically possible. For example, most jurisdictions do not forbid jumping out the window, yet it is neither safe nor smart to do. The same goes for traffic code rules. Just because some traffic codes allow or do not forbid u-turns on specific junctions (often with traffic signals only) by default, it does not mean that it is always safe or smart to do a u-turn on every (such) junction.
We are talking here about sane and safe global routing algorithm assumptions, not legal rules or restrictions. OSM turn restriction relations have been designed for mapping the flow of traffic (for routers). Hence, OSM turn restriction relation instances can be identical to legal restrictions on the road but they do not always have to. They should only be used when needed to restrict the modeled default flow of traffic, not to override any traffic code’s legal default.
These have never been disputed nor they have had an effect on routing. Dedicated u-turn lanes are a traffic flow and safety tool for road engineers. Roads with dedicated u-turn lanes are by definition designed for safe u-turns and often employ dedicated road geometry, which is also consequently reflected in OSM data. Hence, as long as the road geometry has been properly mapped in OSM, routing algorithms always have, can, should, and will route u-turns there if needed.
Again, you are referring to the traffic code only without considering safety when routing (and finally driving). The issue is that OSM has no data type to indicate how safe or unsafe it is to make a u-turn at any junction (except for topology data derived from road geometry data, or potentially maybe
no_u_turnrestrictions in rare cases but this is rather the exception than the rule).No. No routing algorithm will suggest a u-turn on sections (edges) between junctions (junction nodes). It is just that routing algorithms search for the shortest path from A to B and it has no clue (input parameter) which side of the road you are on.
This is not a bug or some deficiency but the effect of pure theory. Anyhow, what you can do already is to add an intermediate destination on the same edge you start your route in the direction you want to go. Note that this does not and will not invalidate the general assumptions on safe and sane u-turns, and the routing algorithm is going to compute a loop if necessary.
Arcturuss commentedon Jun 13, 2024
Ukraine, Belarus, major cities in Russia, other ex-USSR countries.
Example
https://www.openstreetmap.org/node/4810494980 Street with a double solid line mapped as a single line in OSM, and junctions (service ways) with restrictions for left turn and u-turn.
https://yandex.ru/maps/-/CDrkf28x street view
Maybe; maybe not. It depends on the user/driver and their specific use case. That's why it's configurable, right?
Sorry, maybe that's because I have two different things in mind.
First, the general observation, not about any specific case. People do u-turns all the time, at least in the cities I lived in. So when the router ignores potential route with the u-turn the driver knows is legal and safe, and suggests 2x longer route instead, there's a strong chance this router will go out of the window. Same with suggesting u-turn where it's not legal or impossible.
I think this is not the case where one can strongly de-prioritize u-turns, trading potential longer routes for assumed safety. Both will be considered broken.
Second, the specific use case where this issue is more clear and even critical: calculating routes for taxi drivers.
There is a taxi company in my city that is using routing on the OSM data (possibly OSRM, but I don't know for sure). They need to calculate the exact route the driver will take (including specific side of the street) to measure the distance and display the price. Because of that long detours are not acceptable, as well as impossible/illegal u-turns.
Currently they have an issue with routing that I showed in the picture in the previous post. They don't know how to fix this in the router, so they are trying to 'fix' the map by splitting the streets in two ways (even where that is against common practice) and messing up everything around in the process. Our local OSM community had enough of this and we wanted to suggest them a better router.
That's a good workaround, thanks!
JakeSmarter commentedon Jun 13, 2024
There is no maybe. The router has no way of telling without adequate data how safe or unsafe a u‑turn maneuver may be (or whether it is even physically possible) at an arbitrary junction node, except for
turning_circleandturning_loop. Period. Furthermore, the statistics and experience of routing vendors regarding u‑turns have been conclusive for a very long time.The u‑turn cost is configurable to be able to compute multi‑stop routes (which is far more complex than most people think at first glance because it requires multi‑stage route searching) and because there are corner cases in certain situations where you have to run multiple searches with different parameters in order to get to a solution.
Then they have to:
Furthermore, taxi companies or ride sharing services that have to project the cost and route for a customer can only do what it says: project. In this business it is impossible to always project the exact cost ahead of time, that’s the nature of things. Just think about accidents or any other unforeseeable event on the road that is going to lead to a detour. Hence, sometimes customers will pay more, sometimes less than the projected price after the ride. Usually, there is something like a ±5% tolerance deemed acceptable in the final price. Or, there is a minimum price added on top of the projected price to account for these unforeseen detours.
No router is perfect. And, like with everything, you have to know your trade. Sometimes you have to reconfigure the router and sometimes you have to edit the map because the map is not perfect either. But, never edit the map for anything specific but to mapping guidelines only.
AFAKT, this junction has been mapped largely correctly, except for the dead data
and
traffic signs equivalent.
no_u_turnrelation, which is complete non‑sense. Additionally, imho thisonly_right_turnrelation would have been better mapped withno_left_turn. Note thatno_left_turn≭only_right_turn. Neither are legally and in effecteasbar commentedon Jun 16, 2024
Yes, you're right what is the better default certainly depends on the specific use case and it is a good thing it is configurable. For actual driving/navigation I would still prefer a detour over a possibly dangerous or illegal u-turn. The aware driver will still be able to find a spot to turn around safely (that the router's data might not contain), and a less aware driver might not even notice there was a detour at all when driving a bit of a loop.
That is exactly the problem. Whichever default one uses there will be lots of cases where the opposite setting would have been better. So the real question here is how the false cases can be reduced, i.e. how can we find locations in OSM data where u-turns are reasonable and where they need to be avoided as much as possible? And what is the default (in OSM)? For example should the default assumption be that u-turns are nowhere possible and possible u-turns need to be tagged explicitly? Or should it be that u-turns are possible basically everywhere (at all 'junctions'?) unless there is a
no_u_turnrestriction? Or maybe this should depend on some tags likehighway,lanesetc.? I could not find an answer to this question in the OSM wiki. And as long as there is no agreement there, mappers won't know how to map and router developers won't know how to interpret the data.This is very bad of course. Maybe the best the OSM community can do would be establishing clear guidelines how turn restrictions should be mapped? Which brings me back to my previous question. Unless the guidelines are clear it is hard to hold anyone accountable for tagging or not tagging something? What do you think GraphHopper can do about this?
karussell commentedon Aug 27, 2024
The problematic routes are now fixed:
See da748e6