Project-OSRM / osrm-backend

Open Source Routing Machine - C++ backend
http://map.project-osrm.org
BSD 2-Clause "Simplified" License
6.21k stars 3.29k forks source link

Restrictions not applied in routing? #5068

Open XavierPrudent opened 6 years ago

XavierPrudent commented 6 years ago

Dear OSRMers,

OSRM is a fantastic tool, and as a newbie, despite the learning curve, does worth the effort. The turn restriction with via- and node- has even been implemented for at least 2 versions.

I experienced a curious behaviour of osrm regarding turn restrictions on a local map of a small city in Québec, Canada (Longueuil).

If you look at this map (link below), and look for the point #22 at the intersection of Boulevard Cousineau and Rue Perras, you can see a u-turn done by osrm:

https://civiliagroupeconseil-my.sharepoint.com/:u:/g/personal/xprudent_civilia_ca/EXFdH132gY1Pk38xz54uN08BL87-xayY1WC7jLMTP9axHQ?e=UkCpL6

Here is a zoom on the Rue Perras.

https://civiliagroupeconseil-my.sharepoint.com/:i:/g/personal/xprudent_civilia_ca/ETEmfFrTyIdGrWPwALg-jNMBLhFNB78b068x8ceNRqOw5g?e=YA8dOT

But such turn has been explicitly forbidden in the JOSM editor using the turnrestriction plugin:

https://civiliagroupeconseil-my.sharepoint.com/:u:/g/personal/xprudent_civilia_ca/Ef2rIh5MZ1VNnxrLxcTUkwgB1lJ0d_rTPcfBTH94I3BzCg?e=pd09Va

The osrm server is built on ubuntu 16.04 with the latest version of osrm using:

CAR=../profiles/car.lua OSM=Longueuil-v2.osm.gz SFX=echo $OSM | cut -d "." -f 1 OSRM=${SFX}.gz.osrm osrm-extract -p $CAR $OSM osrm-contract $OSRM

the restriction file being then quasi-empty

more Longueuil-v2.gz.osrm.restrictions OSRN

Here is the OSM map I edit:

https://civiliagroupeconseil-my.sharepoint.com/:u:/g/personal/xprudent_civilia_ca/Ef2rIh5MZ1VNnxrLxcTUkwgB1lJ0d_rTPcfBTH94I3BzCg?e=StlweD

I have tried various possibilities for the last couple of days and I scratch the bottom of my imagination's barrel. Any suggestion will hence be highly welcome.

Regards,

Xavier

XavierPrudent commented 6 years ago

Having dived in the osm file, it looks like: (1) JOSM assigns negative id's to created objects, can OSRM handle negative id's ? (BTW these id's are shown as 0 on JOSM) (2) The turnrestriction plugin seems to mess around the configuration of the restriction in osm, for instance here with two 'via'

<relation id='-183109' action='modify'>
   <member type='way' ref='435638956' role='from' />
   <member type='way' ref='435638957' role='to' />
   <member type='way' ref='-158755' role='via' />
   <member type='way' ref='-158753' role='via' />
   <tag k='restriction' v='no_u_turn' />
   <tag k='type' v='restriction' />

I guess osrm cannot handle such ambiguity. So far it looks more like an issue on JOSM and turnRestriction side. I keep investigating it and will let you know.

danpat commented 6 years ago

@XavierPrudent i edited your comment to better format the XML.

Negative IDs indeed will not work in OSRM - they are not valid according to the OSM XML spec, these are internal identifiers that JOSM uses to track whether new features have been uploaded yet.

You can use osmium-renumber to automatically renumber your edited file to have all positive IDs, or you can just edit it by hand.

Two via ways is valid, it will depend on how your restriction is defined. OSRM can only handle one via way or via node however. There's a ticket over at https://github.com/Project-OSRM/osrm-backend/issues/4439 that is there to track implementation of multi-via-way restrictions, but nobody has started on it yet.

XavierPrudent commented 6 years ago

I focused on the negative ids, changing them by hand to be positive in the osm file, or using the osmium renumber tool. Here are the OSM files where the relation id's have been changed by hand: https://civiliagroupeconseil-my.sharepoint.com/:u:/g/personal/xprudent_civilia_ca/EcbpGqGZSttNrEs2-6l5VwQBbWXXhct-0nA5hzcDAkHKnQ?e=9gKuHa and here with the osmium tool: https://civiliagroupeconseil-my.sharepoint.com/:u:/g/personal/xprudent_civilia_ca/ER1TmHkmxMhHmwXBa1fT5X4BZKRVWTqQjg0iSmfqgaiJpQ?e=CIzafG Both give the same result with OSRM: https://civiliagroupeconseil-my.sharepoint.com/:u:/g/personal/xprudent_civilia_ca/ETYlywIcv79DuV6ruDo0sVIBceizWErNnJJUV5_ZfXNgfA?e=3tL4Ya

You can see at the intersection between the Boulevard Cousinean and the Rue Coderre a u-turn screen shot 2018-05-08 at 4 34 28 pm

even though this u-turn is clearly forbidden by:

  <relation id='300729' action='modify'>
    <member type='way' ref='23552256' role='from' />
    <member type='way' ref='403932024' role='to' />
    <member type='way' ref='37772224' role='via' />
    <tag k='restriction' v='no_u_turn' />
    <tag k='type' v='restriction' />
  </relation>

where the Rue Perras id is 37772224.

I am quite puzzled as now the ids are positive, the syntax of the turn restriction is fine, and still OSRM don't recognize them.

XavierPrudent commented 6 years ago

Running OSRM with steps=TRUE, the forbidden uturn shows up as

,"maneuver":{"bearing_after":25,"type":"continue","modifier":"uturn",\ "bearing_before":116,"location":[-73.420942,45.50054]},"ref":"112 $west","weight":32.6,"distance":465,"name":"Boulevard Cousineau"},{"intersections":[{"in":0,"entry":[true],"bearings":[116],"location":\ [-73.425944,45.5025]}],"geometry":{"coordinates":[[-73.425944,45.5025],[-73.425944,45.5025]],"type":"LineString"},"mode":"driving","duration":0,"maneuver":{"bearing_after":0,"type":"arrive","modifier":\ "right","bearing_before":296,"location":[-73.425944,45.5025]},"ref":"112 $west","weight":0,"distance":0,"name":"Boulevard Cousineau"}]

so it looks like OSRM does not see the in-between street Rue Coderre.

danpat commented 6 years ago

@XavierPrudent I opened up the Longueuil-v2.osm file you attached earlier. I can't see a valid u-turn restriction at the Boulevard Cousinean and Rue Coderre crossing point:

screen shot 2018-05-09 at 8 29 10 pm

You can see that JOSM puts a little no-u-turn arrow on the map when a relation is there.

There's no restriction relation at Rue Coderre that I can see.

The Boulevard Cousinean ways need to be split at Rue Coderre, and Rue Coderre needs to be split at the crossing points of Boulevard Cousinean, then a relation formed to create the no u-turn restriction.

There are other no-u-turn restrictions on the map that look fine.

Am I looking at the right file?

XavierPrudent commented 6 years ago

You got it @danpat There were 2 reasons for my failure: (1) when adding a restriction, the corresponding ways must be split at the crossing point. (2) when editing an OSM map with JOSM, added objects get a negative ID, which are not handled by OSRM (osmium renumber does a good job with that) (3) Changing the negative ids to positive ones by hand does not make OSRM recognize them.

But using osmium forbids the later use of JOSM to re-edit the map.

That was quite a chunk to chew for a newbie :) Thank you all.

github-actions[bot] commented 2 weeks ago

This issue seems to be stale. It will be closed in 30 days if no further activity occurs.