Adding initialization costs to vehicles is a common task in vehicle routing problems (VRPs). The activation or initialization of a vehicle can be useful if a vehicle isn't permanently in the fleet, but has to be rented for example. If this vehicle isn't needed in a solution, then the rental cost can be saved. The router engine provides the InitializationCosts
option to configure the costs per vehicle that are added to the value function when a vehicle is used. This is done by specifying the vehicles' initialization costs.
Example
The aim of this example is to add initialization costs to vehicles. The introductory router example is used as a base, where routes are created to visit seven landmarks in Kyoto using two vehicles. In this example, v1
has an expensive initialization cost associated with it, while v2
does not.
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:
Given that v1
is the most expensive vehicle to operate, all stops are assigned to v2
.