Feature Request: Avoiding roads
Hi guys!
Are there any plans to introduce roads avoiding feature? For example, i want to exclude some road from routing calculation (so engine should pick a path that goes around this road).
Do you mean certain road tags? Or specific names of roads?
You could solve the former by editing the profile lua that you are using and adding the tag to the blacklist or setting the speed very low so the engine will prefer other ways.
I would like the engine to avoid certain road segments. Would be nice to do this at runtime, without recreating whole hierarchy. I guess it is totally possible to mark specific nodes as "restricted" when iterating through the forward and backward heaps.
This is very unlikely to happen (at least in the mainline OSRM) for the following reason:
- We plan to implement a different (non-CH) routing algorithm soon-ish (read: next year) that will support changing the metric without the longer reprocessing
- Doing so in the current scheme is (theoretical) possible but there are some caveats:
- Routing is done on the edge-expanded representation of the route network, so nodes in the graph correspond to whole street segments, which might not work for your use case
- Adding that requires changes in the internal data model, that would require more memory (so it will probably not get accepted in the mainline version)
- You need to implement an mechanism to modify the data at runtime: Since every matching between the original OSM data and the internal data structures is lost, there is no sensible way to do this
TL,DR: This would be a hack that might even get obsolete soon.
Thank you for the details.
I'm interested in this feature too. Any news about this awesome new algorithm ?
Re-visiting this thread... is this something that is possible to do now?
@rumicuna The profiles now have an exclude property that lets you exclude certain road class combinations. By default the car profile ships with motorway, toll, and ferry, and you an use exclude=motorway in the request URL.
Using this feature requires pre-processing - you have to decide at preprocessing time which classes you want excludable, and which combinations are available.
These are also strict exclude filters, not "avoid".
Thank you Daniel, Here's my use case: I'm working on a disaster relief application where we detect flooded roads and we want to re-route traffic depending on what roads are traversable. We generate a mask which we can use to tag roads. From your response it seems I should to re-ingest the data and mark the non-traversable roads with a "flooded" tag, then user exclude=flooded. So I'm happy there is a solution, however, since the flooded roads could be changing hourly, it seems like this could be a slow process since the area we cover is very large and we have to keep deleting and ingesting the data over and over again. Do you know of a way to do this at run-time, that is, is there a documented way to modify the in-memory structures? If not, do you have any suggestions on where to start if we need to hack away at the code to add this feature? We'd be happy to contribute back to the project if we pursue this.
Using the exclude= approach sounds like it'd be too slow.
However, if roads are flooded, it sounds like traversing them isn't really a preference - they're basically closed.
In that case, you could simulate traffic data for those roads. Use the traffic data feature to set the speeds of the closed roads to 0km/h - this will effectively avoid them. Traffic data imports are fast, so updating hourly should be no problem.
Genius!!! What a nice and clean solution! Thank you!
Daniel, et al. Re: resetting the speed back to original value... I'm using the traffic data feature to simulate flooding by setting the speed to zero, so I really don't know what the original speed was. The flooded areas change continuously, so just before an update I'd like to reset all the roads I changed the speed to zero to their original values. I can keep track of what roads I changed the speed to zero, but I don't know what the original value was. Is there any way to reset a road speed to it's original given value (by osm I assume), or it's calculated value (again I assume some default value is calculated if osm did not have one)?
@rumicuna You should keep a copy of the original output of osrm-extract/osrm-partition. The traffic update modifies files in-place, so your loop would be roughly:
osrm-extract yourmap.osm.pbfosrm-partition yourmap.osrm- copy all files from (2) to new directory
- in new directory, run
osrm-customize --segment-speed-file traffic.csv yourmap.osrm - reload
osrm-routedusing data in new directory - go to 3
I am trying to work this (Rumicuna's selective road closures) out, too.
I am not sure how the traffic.csv needs to look. after the osrm-extract command, what is the process to edit their speeds in a csv? I would assume the process would be something like:
a) access the roads layer of my OSRM server and deploy them in a GIS environment (e.g. qgis, R...) b) perform overlays and identify road segments where the speed would be edited to a given value (e.g. 0 if very flooded, 5 mph if flooded, no changes if not flooded) c) create a csv file with the from and to osm_id of the edited roads, and the new speed (in km/h) d) run osrm-customize e) run the new osrm server and connect my R script to it.
I think my key question as for now is how can I identify the road segments that I would want to edit. Can this be done using the city-name-latest.shp file with the roads to find their ids?
And also - can the .csv file only have the ids of the roads whose speeds I want to overwrite, or does it have to be ALL the roads in my OSRM server (New York State).
Thank you!