In vehicle routing problems (VRPs) stops often have to be serviced in the same route together. In many cases this is a simple pickup/dropoff problem which you can easily address with our precedence option in the router engine. However, in some cases you may need to address more specific requirements that involve setting up groups that are served by the same vehicle.
The router
engine provides the Grouper
option to set up groups of stops. This is done by adding a stop matrix that defines the groups.
Example
The aim of this example is to create two groups of stops by ID that must be served together. The introductory router example is used as a base, where routes are created to visit seven landmarks in Kyoto using two 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. We create 2 groups which we then pass into the Grouper
option.
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 stops which are grouped together are assigned to the same route. In this case both groups are assigned to the same vehicle for optimality reasons.