Vehicle routing problems (VRPs) are infeasible if no solution satisfies the set of considerations specific to the problem. For example, stop quantities may exceed a vehicle's capacity, in which case the vehicle can not service all stops. Another example is a vehicle having to fulfill time windows but not being able to arrive at a certain stop in the desired time frame. When a problem is infeasible, the router engine will return an empty solution state because, by default, it must assign all stops to the solution.
The router
engine provides the Unassigned
option to configure penalties for stops. When the stops can not be serviced due to a consideration (constraint) being violated, the engine attempts to make the solution feasible by leaving stops unassigned. The penalties are added to the value of the solution for the stops that are not assigned. Normally, the value of these penalties is larger than the assignment cost.
Example
The capacity example is used as a base, where routes are created to visit seven landmarks in Kyoto using two vehicles that have capacities that must be respected. This time, the stops' demands exceed the vehicles' capacity and penalties are provided to leave stops unassigned.
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 there are three stops that were not assigned, as the total stop quantity exceeds the total vehicle capacity. The stops that are assigned minimize the total distance.