[pgrouting-dev] Update on OSRM-pgRouting integration

Hi all,

Here is a demo of using OSRM and pgrouting using php to glue things together.

http://imaptools.com:8081/demo/osrm.html

Sorry for the weird test grid. The roads have some randomly assigned speed_cat and direction of travel which can make for some unexpected routes. When I have a chance I'll build a real work graph.

Read the HELP that comes up when you load the page.

Here is a description of how it works. The [Route Path] function just collects the marker locations and makes a direct call to the OSRM server. No magic there, you can look at the Javascript to see how to make Leaflet do that. I was going to add dragging the route or markers, but it more interesting to get this working in pgrouting.

For the [Optimize *] functions, I call a PHP script to glue everything together for the moment. The basic logic is:

1. get and array of points
2. loop through the points calling OSRM N*(N-1) times to build a distance matrix and cache the result in an NxN array
3. call pgrouting pgr_tsp(dmatrix, start, stop) to get an ordered list of points
4. Get the cached route_geometry for the ordered pairs of nodes
5. return that as jsonp object.

Time vs Distance

Currently there is no easy way to ask OSRM to compute shortest time vs shortest distance. I understand that I might be able to do this using profile.lua files but this would require having two OSRM servers running using different profiles.

For the time being, I compute a routes for the distance matrix calling OSRM and build my distance matrix based on the route_distance vs the route_time values returned in the request. Then TSP orders the nodes to minimize the cost values used. I suspect we would get different results if we could compute the routes based on either time or distance.

My next step is to move the php code into C code in the database. And at some point build out a real road network for a better demo.

-Steve