This feature is only available for Platform. You can find a list of all available features here.
This how-to guide assumes you already completed the get started with vehicle routing tutorial.
Using duration matrices (either derived from haversine and speed or a road network) may not always represent the real world drive times good enough, depending on the region where you operate or the time of the day (rush hours).
Following, we will make use of two concepts in our vehicle routing engine that help you mitigate these issues:
- Expression scaling
- Time dependent expressions
Expression scaling can be used to make drive times between stops slower or faster by a given factor. Whilst time dependent duration expressions
introduce a concept of time to an otherwise fixed drive time. This means that you can specify multiple duration matrices along with the information at what time of the day they should be used. In the exmaple below we will combine both concepts.
Example
Let's say you are generally happy with the drive times that are calculated through haversine and a constant speed. But you want to adhere to rush hours in the morning and evening.
First, create a haversine travel duration expression
which will be used as a default for the whole day and scale it to represent slower driving during rush hour:
Of cource, you can use any other travel duration expressions
as your default. You could, for example, use a custom duration matrix or map data.
Next, create a time dependent duration expression
. We will create this expression using the default expression we created before:
Add the time slots when you expect the rush hour to start and end to the time dependent duration expression
using the slower travel duration expression
:
And finally, update the model and add the time dependent duration expression
to every vehicle type
:
Make sure that the times for the time slots must go hand in hand with the start and end times of your vehicles. Here is an example input.json
that we created to work with the code snippets above:
To avoid hard-coding the start and end times of rush hours, you can levarage custom data in your input.json
.