Pickups & deliveries are widely used in vehicle routing problems (VRPs) because often one or more items need to be picked up along the route before they are delivered to a customer. This is known as the vehicle routing problem with pickups & deliveries (VRPPD).
The router engine provides the Precedence
option to configure a precedence relation between stops. This is done by adding a list of precedence jobs. For each job, it is specified that a stop (pick up) must precede another stop (drop off) in the same route. A stop may appear in several jobs, meaning that the option allows you to specify many pickups before a drop off and vice versa.
Example
The router example is used as a base, where routes are created to visit seven landmarks in Kyoto using two vehicles. This time, two precedence instructions are defined.
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 one vehicle serves the stop Arashiyama Bamboo Forest
whereas the other services the rest of the stops. Note that in the extended route the precedence constraints are fulfilled and Fushimi Inari Taisha
and Gionmachi
are visited before Kiyomizu-dera
.