Project-OSRM / osrm-backend

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

OSRM giving higher travel time on Highways #6526

Closed dkakkar closed 3 months ago

dkakkar commented 1 year ago

We are using OSRM http request to estimate travel time but that is coming significantly different from Google. OSRM is not using Highway speed on Highway and using city speed which is causing difference in time with Google. I am not sure how we can resolve, could either of you please help. Thanks! Here is my code:

def get_drive_time(row):
  mode = "driving"
  url = "http://router.project-osrm.org/route/v1/%s/%f,%f;%f,%f?overview=false"
  resp = requests.get(url%(mode,row["ZIP_X"],row["ZIP_Y"],row["AHA_ID_X"],row["AHA_ID_Y"]))
  res = json.loads(resp.content)
  time.sleep(1)
  if res['code'] == "Ok":
     return res["routes"][0]['duration']
  else:
    print(res)
    return None

od_pairs.loc[:,"OSRM_drive_time_seconds"] = od_pairs.progress_apply(get_drive_time,axis=1)_
datendelphin commented 1 year ago

Can you show an example on https://map.project-osrm.org

dkakkar commented 1 year ago

@datendelphin > Can you show an example on https://map.project-osrm.org: See below

https://map.project-osrm.org/?z=9&center=42.383908%2C-73.072815&loc=42.820213%2C-73.916461&loc=42.376002%2C-72.605453&hl=en&alt=0&srv=0

wybert commented 1 year ago

I would like to share an example,

Notice that for the same route, the difference is about 30 mins.

danpat commented 1 year ago

OSRM makes a best guess on road speeds based on the road tags in OSM. As a general rule, OSRM has a tendency to over estimate speed - ETAs returned from OSRM are usually a bit too optimistic.

To identify where OSRM appears to be under estimating in this case, you'd need to compare progress along the two routes - look at where OSRM is adding additional time, then dig into the data and try to understand how it's coming up with that.

Unfortunately, the OSRM demoserver is just that - a demo server. It uses publicly available OSM data, and no real-world traffic-derived information. Google does, and uses that in preference to map metadata for estimating speeds.

If you can identify a particularly egregiously incorrect section of the sample route, you can then look at the properties of that section in OSM, and the OSRM profiles which convert the OSM tag data into estimated speeds, and figure out what's wrong with the decisions its making.

wybert commented 1 year ago

OSRM makes a best guess on road speeds based on the road tags in OSM.

I am wondering which tag it uses and how it uses the tag.

To identify where OSRM appears to be under estimating in this case, you'd need to compare progress along the two routes - look at where OSRM is adding additional time, then dig into the data and try to understand how it's coming up with that.

I have done some explorations,

I visualized the results from OSRM and results from Google Map API(Click on the links can see the visualization). By hovering over the lines you can see the speed of each line in the routing results. The speed is calculated as distance/duration. We can see from the results in road I-90, the speed OSRM in each line is about 23 m/s but google is about 30 m/s. I check the wiki which gives us a 30 m/s speed limitation of I-90.

I also checked out the OSM data both through openstreetmap.org, see here and through the .osm file I downloaded. The max speed of I-90 in OSM data seems to be 30 m/s (Both from openstreetmap.org and the .osm` file I downloaded).

I extracted the maxspeed tag from our .osm and visualized it with OSRM routing speed (calculated as distance/duration), see the result here. Even I miss some of the osm data when I doing the visualization we can still make the conclusion that the speed from the routing result is not using the max speed.

We also found out (with 10k random samples in the US) that if the routing time is more than 50 mins, the OSRM will estimate the total time as greater than Google Maps. If the routing time is less than 50 mins, there wouldn't have a big different between OSRM routing time and Google Maps.

If you can identify a particularly egregiously incorrect section of the sample route, you can then look at the properties of that section in OSM, and the OSRM profiles which convert the OSM tag data into estimated speeds, and figure out what's wrong with the decisions its making.

That's useful. But it would be great if we can fix it inside OSRM time calculation algorithm.

dkakkar commented 1 year ago

@DennisOSRM - Any tips on this thread?

danpat commented 1 year ago

@wybert The profiles I linked to are the code responsible for assigning a speed to edges in the routing graph. If you want different speeds used for different OSM tags, you need to modify those profiles, then re-generate the routing graph data using the modified profiles.

There is a debugging script included:

https://github.com/Project-OSRM/osrm-backend/blob/master/profiles/debug_way.lua

To use it, obtain an extract of map data from OpenStreetMap for the area you are interested in. Then run:

lua debug_way.lua car <way id>

where <way id> is the OSM way ID for the road you're interested in. The script will print out the travel speed that the processing profiles will assign to that road at data processing time. You can then modify the profiles until you are generating the speed you want. OSRM will then use those speeds at routing time to calculate the time (a simple length * speed = duration calculation, nothing fancy).

A starting point for understanding how the profiles work is to look here:

https://github.com/Project-OSRM/osrm-backend/blob/master/profiles/car.lua#L141-L158

one basic speed assignment uses the highway= tag and that list of values. The final speed assigned to a graph edge is not as simple as highway=motorway->90km/h, other tags on the road are also considered and speedup/penalties are applied to derive the final result.

datendelphin commented 1 year ago

It seems to me that this highway is particularly uncongested. The alledged google result gives an average speed of 104.5km/h which is incredibly close to the max speed of the highway. The OSRM profile has a fudge factor of 0.8 times the max speed to account for usual traffic (see speed_reduction in car.lua). This seems to explain most of the observed difference. So it boils down to what danpat wrote. The demo instance has no observed speed source, and you found an example where that makes a lot of difference.

wybert commented 1 year ago

Thanks for the explaination. About the fudge factor of 0.8, What's the reason to set the factor as 0.8? Can we change it through the API directly? I think the drive speed on a highway should close the the max speed of the highway in most cases.

Below is a plot about the drive time between Google Map and OSRM when the drive time greater than 50 mins,

image

The 4000+ samples show a linear relation between Google Map drive time and OSRM drive time, maybe by change the the fudge factor we can get more accurate drive time estimation.

danpat commented 1 year ago

@wybert To change that fudge factor, you will need to run your own OSRM server, and modify the car.lua profile to your liking.

I will warn you - you might be able to get improvements for certain examples, but it is very hard to make modifications to the profiles that don't deteriorate results elsewhere.

It's unrealistic to expect that OSRM's tag-based rules will be able to give results that would be as good as systems that use measured road speeds from real-world telemetry. It is a data problem, and there are no good free sources of live, real-world traffic data.

One other note: if you're trying to do science and statistics on this data - what is your baseline? It appears that you are assuming that Google is right, and you're trying to adjust OSRM to fit. Having some experience in this, I'll note that Google is generally pretty good, but they too have an error margin compared to what's actually happening in the real world. You have no independent control in your experiments, so you're going to end up chasing ghosts when you try to get consistent results.

wybert commented 1 year ago

Thanks. That makes sense.

SiarheiFedartsou commented 3 months ago

Stale.