Not every vehicle routing problem (VRP) is about minimizing time or distance. Sometimes, you want to maximize profit or another measure of your business. The router engine provides the Minimize
and Maximize
options to configure the desired solver type to minimize or maximize the target value, respectively. As a default, the router
uses minimization as its configuration.
Example
The router example is used as a base, where routes are created to visit seven landmarks in Kyoto. This time, only one vehicle is used.
Save the following information in an input.json
file (see input and output for more information on working with input files).
Code
To minimize the total route distance, the same code from the base router example can be used, given that minimization is the default configuration. To maximize, you can run a different program.
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 maximization 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 for minimization (default or via the Minimize
option) should look similar to this one:
The solution for maximization, using the program in the code snippet, should look similar to this:
You can notice that by using the Maximize
option, the route distance for a single vehicle is maximized to be the longest possible.