Skip to content
Jelle Victoor edited this page Aug 18, 2016 · 29 revisions

Traffic updates

Biggest feature in OSRM 4.9.0 is experimental support of traffic data. This is achieved by providing osrm-contract with an additional file that specifies edge weight updates. For convenience, updates can be specified in a csv file; each line has to follow the format from_osm_id,to_osm_id,edge_speed_in_km_h.

425656,425655,14
50267,27780,32
25296,25295,24
34491,34494,3

Every line should be a restriction, an empty line will result in an Segment speed file updates.csv malformed error

The from/to ids are OSM node IDs that are directly connected. To update the speed for an entire way, you must list each node pair along the way in the CSV file. Note that order is important, to update both directions for connected nodes A and B, you must list A,B,new_speed_forward and B,A,new_speed_backward.

./osrm-extract data.osm.pbf -p profile.lua --generate-edge-lookup
./osrm-contract data.osrm --segment-speed-file updates.csv
# modify updates.csv
./osrm-contract data.osrm --segment-speed-file updates.csv
# Repeat in loop for desired update time

Since this is too slow for big datasets to get meaningful updates cycles, you can do a partial contraction using the --core parameter.A core factor drastically increases query times. As a result, the alternative-route search is slowed down immensely. Note that the viaroute service calculates alternative routes by default, so you should take care to disable them in each request by appending &alternative=false to the query. If you do not, response times will be very slow. .

./osrm-extract data.osm.pbf -p profile.lua --generate-edge-lookup
# about x8 speedup wrt to --core 1.0
./osrm-contract data.osrm --segment-speed-file updates.csv --core 0.8
# modify updates.csv
./osrm-contract data.osrm --segment-speed-file updates.csv --core 0.8
# Repeat in loop for desired update time

For even more speedups use the --level-cache option:

./osrm-extract data.osm.pbf -p profile.lua --generate-edge-lookup
# For the first run a core of 1.0 is required
./osrm-contract data.osrm --segment-speed-file updates.csv --core 1.0
# modify updates.csv
./osrm-contract data.osrm --segment-speed-file updates.csv --core 0.8 --level-cache true
# Repeat in loop for desired update time

A level cache should always be generated with a full hierarchy (core=1.0). After this initial generation, any core factor can be specified.