In vehicle routing problems (VRPs) stops often have to be serviced within specific time windows. E.g., in a bike sharing problem the stations have to be filled up with bikes while they are empty or bikes have to be picked up while they are full. This is known as the vehicle routing problem with time windows (VRPTW).
The router engine provides the Windows
option to configure time windows for stops.
The Windows
option must be used together with the Shifts option.
The Windows
option is often used together with the Services option.
Example
The router example is used as a base, where routes are created to visit seven landmarks in Kyoto using two vehicles. Here, we define time windows and service times for certain stops and define shifts for both vehicles.
Save the following information in an input.json
file (see input and output for more information on working with input files).
Code
The following program uses the CLI Runner to obtain a solution and requires access to the Nextmv code repository on GitHub. To request access, please contact support@nextmv.io.
To proceed with running the example, create a main.go
file and use the code snippet below.
To execute the example, specify the path to the input.json
file using command-line flags and use jq to extract the solution state (see runners for more information on building and running programs).
Solution
The solution should look similar to this one:
You can see that given the shift availability of the vehicles, stops Fushimi Inari Taisha
and Kiyomizu-dera
are assigned to vehicle v1
as they must be serviced before 12 pm. On the other hand, stops Arashiyama Bamboo Forest
and Kinkaku-ji
are assigned to vehicle v2
, given that they must be visited after mid-day.