"github.com/nextmv-io/code/engines/route"
vehicleEngine "github.com/nextmv-io/code/engines/route/vehicle"
"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"`
// A custom type that implements Violated to fulfill the Constraint interface
type CustomConstraint struct {
// Violated is one of the two methods that must be implemented to be used as a
func (c CustomConstraint) Violated(state vehicleEngine.State) (vehicleEngine.Constraint, bool) {
// Count only assigned stops, do not include start/end stops in count.
violated := len(state.Route())-2 > c.count
// Use the CLI runner to solve a Vehicle Routing Problem.
f := func(i input, opt solve.Options) (solve.Solver, error) {
// Create a custom constraint.
constraint := CustomConstraint{count: 4}
router, err := route.NewRouter(
route.Constraint(constraint, []string{"v1", "v2"}),
return router.Solver(opt)