"github.com/nextmv-io/code/engines/route"
"github.com/nextmv-io/code/engines/route/vehicle/schema"
"github.com/nextmv-io/code/hop/model"
"github.com/nextmv-io/code/hop/run/cli"
"github.com/nextmv-io/code/hop/solve"
// Struct to read from JSON in.
Stops []route.Stop `json:"stops,omitempty"`
Vehicles []string `json:"vehicles,omitempty"`
// Use the CLI runner to solve a Vehicle Routing Problem.
f := func(i input, opt solve.Options) (solve.Solver, error) {
// Define unassignment penalties to allow for unassigning stops
penalties := []int{100000, 100000, 100000, 100000, 100000, 100000, 100000}
// Define a filter. In this example a vehicle may not have more than 3 stops
filter := func(vehicles, locations model.IntDomain, routes []schema.Route) model.IntDomain {
vehiclesToRemove := model.Domain()
locationCount := locations.Len()
// Determine vehicles which can get the set of locations assigned
iter := vehicles.Iterator()
// Remove vehicle from options, if assigning the locations would
// overflow the maximum number of stops (start&end do not count
// towards maximum number of stops; negative maximum indicates
// unlimited number of stops)
if len(routes[index])-2+locationCount > maxStops {
vehiclesToRemove = vehiclesToRemove.Add(index)
router, err := route.NewRouter(
route.FilterWithRoute(filter),
route.Unassigned(penalties),
return router.Solver(opt)