Calculating the Best Route for Rush Hour Traffic

This article discusses the use case of calculating a routeA route corresponds to a path of a vehicle through the underlying transport network. The main attributes of a route are the distance and the time that the vehicle travels along the path. by taking into account a typical rush hour traffic situation.


By considering the time of the day for a route calculation in conjunction with the Feature Layer themes PTV_SpeedPatterns and PTV_TrafficIncidents it is possible to get realistic and accurate information about ETAETA (Estimated Time of Arrival) is the time when a ship, vehicle, aircraft, cargo or emergency service is expected to arrive at a certain place. and ETDETD (Estimated Time of Departure) is the time when a ship, vehicle, aircraft, cargo or emergency service is expected to leave a certain place. for a trip. It is also possible to compare the travel times for a trip starting (or ending) at different points in time. This allows for example to determine the typical time loss when driving a route during rush hour in comparison to hours with less traffic.


Check if the following prerequisites are fulfilled before you start with the use case.


The Feature Layer PTV_SpeedPatterns defines average speeds on roads at different times of a day.
The Feature layer PTV_TrafficIncidents defines the speed on roads where some incidents are ongoing.
With the requestOption timeConsideration it is then possible to define the way how the time should be considered and thus which average speeds should be taken into account. For details see the technical concept about time consideration.

Regarding this speed over time data there are several possibilities to deal with time consideration:


This kind of time consideration provides the most accurate results because it evaluates all time dependent data at the exact time at which the data is reached by the vehicleThe term vehicle describes what is being routed or planned for. Vehicles are used in route calculation, distance matrix calculation and effectively also in tour planning. In route calculation, vehicle properties like overall size, weight and speed are in focus. In tour planning, it is vehicle properties like capacity and availability. Commonly a vehicle is motorized, like a truck - including its trailer or a car. However also a bike or even a pedestrian are included in this definition.. But there are drawbacks of this solution, too:


This kind of time consideration provides less accurate results than the exact time consideration because it evaluates all time dependent data at the given reference time and not at the exact time at which the data is reached by the vehicle. The resulting effect is that the longer the route the bigger gets the error of the ETA / ETD. Regarding the use case of a typical (and not dedicated) traffic situation these differences may be acceptable at least for short (e.g. urban) routes.

On the other hand the performance of this kind of calculation is much better than the exact time consideration because all typical calculation optimization techniques are applied.

Additional improvements

The use of additional Feature Layers like PTV_TruckAttributes may improve the results regarding the route course and the travel time by considering (time dependent) blockings and/or construction sites.

Programming Guide

The example below shows the calculation of a route in conjunction with the Feature Layers PTV_SpeedPatterns and PTV_TrafficIncidents. Therefor the JavaScript bindings to the xRoute service API is used:

var A = { "$type": "OffRoadWaypoint", "location": { "offRoadCoordinate": { "x": 6.1240625381469735, "y": 49.58069567721273 } } }; var B = { "$type": "OffRoadWaypoint", "location": { "offRoadCoordinate": { "x": 6.053037643432618, "y": 49.603590524348704 } } }; var outputString = ''; function calculateSpecificRoute(tct) { xroute.calculateRoute({ "requestProfile": { "featureLayerProfile": { "themes": [{ "id": "PTV_SpeedPatterns", "enabled": true },{ "id": "PTV_TrafficIncidents", "enabled": true }] } }, "waypoints": [A, B], "routeOptions": { "timeConsideration": { "$type": tct, "referenceTime": "2016-07-12T16:29:10+01:00" } }, "resultFields": { "polyline": true } }, function(route, exception) { if (tct == "ExactTimeConsiderationAtStart") { outputString += 'exact time consideration: ' + route.travelTime + ' s '; } else { outputString += 'snapshot time consideration: ' + route.travelTime + ' s '; } print(outputString); }); } calculateSpecificRoute("ExactTimeConsiderationAtStart"); calculateSpecificRoute("SnapshotTimeConsideration");

In the example above one route is calculated twice with the same reference time but different time consideration scenarios. Some of the speed values along the route are changing during the time of the route. This leads to different resulting travel times, because the exact time consideration scenario reflects these changes but the snapshot time consideration scenario does not. The travel time of both calculations is displayed in the result line. The requestOption timeConsideration it is adjusted in the calculateSpecificRoute JavaScript callback function. For further information about the way this sample is implemented see the use-case Calculating a route.

Related Topics