In vehicle routing problems (VRPs) it is sometimes required to limit routes. To limit the route length or duration the router engine offers the LimitDistances
and LimitDurations options. For all other use cases it provides the Limits option to configure custom limits for vehicles.
Note that LimitDistances
is working with haversine distances internally. If you want to calculate limit distances based on another measure, please use the Limits option.
To limit the route's length, a slice of values representing the maximum length must be provided. The values must be given in meters as the underlying measure uses this unit. In addition, a flag must be specified to ignore or adhere to the triangle inequality.
Example
The aim of this example is to define distance limits for vehicles and an unassigned penalty to be able to receive a solution. 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.
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 stop is unassigned in the solution. Because of the route's limitation, it was not possible to add it to either of the two routes anymore.