Traffic in Navit

From Navit's Wiki
Revision as of 22:35, 12 November 2017 by Mvglasow (talk | contribs) (API: reformat table)
Jump to: navigation, search

Navit currently (as of November 2017) does not support routing around traffic problems, although the core functionality exists in the routing engine.

Traffic Distortions

Internally, Navit uses traffic distortions to model traffic issues which may affect the choice of route. A traffic distortion can represent the following:

  • Slow traffic: speed on the affected segment is below the posted limit (or whatever Navit assumes the default speed for the segment to be), e.g. because of dense traffic or because of temporary speed limits. This is represented by setting maxspeed to the expected speed.
  • Delays: there are waiting times or other time penalties on the affected segment. This is represented by setting delay to the expected delay.
  • Closures: the segment is closed to all traffic. This is represented by setting maxspeed to zero.

Both maxspeed and delay can be set at the same time and their effects will add up.

Current Usage

At this moment, traffic distortions are (ab)used to generate penalties for turning around if these are defined in the current vehicle profile. This is done in route.c, in the route_path_new() function, which can be used as an example for inserting traffic distortions.

GUI

The GTK GUI has menu items to enter traffic distortions, but they don’t work in a straightforward manner. If you find Navit happily routing even over the segment you just marked as closed, read on.

All the menu items do is write the segment and its traffic distortion to a file. That file is called distortion.txt and resides in Navit’s data dir. Here’s an example:

type=traffic_distortion maxspeed=0
0x13a07c 0x5e9634
0x139e87 0x5e98ae
type=traffic_distortion maxspeed=10
0x139f22 0x5d6a5a
0x139ec5 0x5d6a13
0x139e88 0x5d69e7
0x139e83 0x5d69e4
type=traffic_distortion delay=3600000
0x13a0f3 0x5d6a41
0x13a101 0x5d6a33
0x13a110 0x5d6a29
0x13a154 0x5d6a03

The file is actually a map in textfile format. The first line for each distortion is the item data: item type (always traffic_distortion here) and its attributes. The following lines are the coordinates for the affected segment.

In the default configuration, that file doesn’t do anything. You can change that by adding the following line to the active mapset in your navit.xml file:

<map type="textfile" enabled="yes" data="$HOME/path/to/distortion.txt"/>

Restart Navit, and it will route around the distortions you have just entered. Apparently this is a feature that never got fully implemented.

TODO: investigate if changes to the file take effect immediately, after a route recalculation or after restarting Navit.

API

The only function to edit traffic distortions is found in route.c:

static void
route_graph_set_traffic_distortion(struct route_graph *this, struct route_graph_segment *seg, int delay);
Sets or clears a traffic distortion for a segment.
This sets a delay (setting speed is not supported) or clears an existing traffic distortion. Note that, although setting a speed is not supported, calling this function with a delay of 0 will also clear an existing speed constraint.
Parameters
this The route graph
seg The segment to which the traffic distortion applies
delay Delay in tenths of a second, or 0 to clear an existing traffic distortion

Limitations:

  • This function prototype is not part of the header file, i.e. not part of the public API. Currently, it is only used internally.
  • There is currently no way to set a maxspeed or closure. However, calling route_graph_set_traffic_distortion() with a zero delay will unset any existing traffic distortion.