Reference

Options

A reference for the options to configure vehicle routing.

If both an environment variable and its corresponding CLI flag are defined, the CLI flag will overwrite the environment variable.

These are the default options that are available with vehicle routing.

Nextmv Hybrid Optimization Platform VERSION
Usage:
  -check.duration duration
    	maximum duration of the check (env CHECK_DURATION) (default 30s)
  -check.verbosity string
    	{off, low, medium, high} verbosity of the check (env CHECK_VERBOSITY) (default "off")
  -format.disable.progression
    	disable the progression series (env FORMAT_DISABLE_PROGRESSION)
  -model.constraints.disable.attributes
    	ignore the compatibility attributes constraint (env MODEL_CONSTRAINTS_DISABLE_ATTRIBUTES)
  -model.constraints.disable.capacities value
    	ignore the capacity constraint for the given resource names (env MODEL_CONSTRAINTS_DISABLE_CAPACITIES)
  -model.constraints.disable.capacity
    	ignore the capacity constraint for all resources (env MODEL_CONSTRAINTS_DISABLE_CAPACITY)
  -model.constraints.disable.distancelimit
    	ignore the distance limit constraint (env MODEL_CONSTRAINTS_DISABLE_DISTANCE_LIMIT)
  -model.constraints.disable.groups
    	ignore the groups constraint (env MODEL_CONSTRAINTS_DISABLE_GROUPS)
  -model.constraints.disable.maximumduration
    	ignore the maximum duration constraint (env MODEL_CONSTRAINTS_DISABLE_MAXIMUM_DURATION)
  -model.constraints.disable.maximumstops
    	ignore the maximum stops constraint (env MODEL_CONSTRAINTS_DISABLE_MAXIMUM_STOPS)
  -model.constraints.disable.maximumwaitstop
    	ignore the maximum stop wait constraint (env MODEL_CONSTRAINTS_DISABLE_MAXIMUM_WAIT_STOP)
  -model.constraints.disable.maximumwaitvehicle
    	ignore the maximum vehicle wait constraint (env MODEL_CONSTRAINTS_DISABLE_MAXIMUM_WAIT_VEHICLE)
  -model.constraints.disable.mixingitems
    	ignore the do not mix items constraint (env MODEL_CONSTRAINTS_DISABLE_MIXING_ITEMS)
  -model.constraints.disable.precedence
    	ignore the precedence (pickups & deliveries) constraint (env MODEL_CONSTRAINTS_DISABLE_PRECEDENCE)
  -model.constraints.disable.starttimewindows
    	ignore the start time windows constraint (env MODEL_CONSTRAINTS_DISABLE_START_TIME_WINDOWS)
  -model.constraints.disable.vehicleendtime
    	ignore the vehicle end time constraint (env MODEL_CONSTRAINTS_DISABLE_VEHICLE_END_TIME)
  -model.constraints.disable.vehiclestarttime
    	ignore the vehicle start time constraint (env MODEL_CONSTRAINTS_DISABLE_VEHICLE_START_TIME)
  -model.constraints.enable.cluster
    	enable the cluster constraint (env MODEL_CONSTRAINTS_ENABLE_CLUSTER)
  -model.objectives.capacities string
    	capacity objective, provide triple for each resource 'name:default;factor:1.0;offset;0.0' (env MODEL_OBJECTIVES_CAPACITIES)
  -model.objectives.cluster float
    	factor to weigh the cluster objective (env MODEL_OBJECTIVES_CLUSTER)
  -model.objectives.earlyarrivalpenalty float
    	factor to weigh the early arrival objective (env MODEL_OBJECTIVES_EARLY_ARRIVAL_PENALTY) (default 1)
  -model.objectives.latearrivalpenalty float
    	factor to weigh the late arrival objective (env MODEL_OBJECTIVES_LATE_ARRIVAL_PENALTY) (default 1)
  -model.objectives.minstops float
    	factor to weigh the min stops objective (env MODEL_OBJECTIVES_MIN_STOPS) (default 1)
  -model.objectives.travelduration float
    	factor to weigh the travel duration objective (env MODEL_OBJECTIVES_TRAVEL_DURATION)
  -model.objectives.unplannedpenalty float
    	factor to weigh the unplanned objective (env MODEL_OBJECTIVES_UNPLANNED_PENALTY) (default 1)
  -model.objectives.vehicleactivationpenalty float
    	factor to weigh the vehicle activation objective (env MODEL_OBJECTIVES_VEHICLE_ACTIVATION_PENALTY) (default 1)
  -model.objectives.vehiclesduration float
    	factor to weigh the vehicles duration objective (env MODEL_OBJECTIVES_VEHICLES_DURATION) (default 1)
  -model.properties.disable.durationgroups
    	ignore the durations groups of stops (env MODEL_PROPERTIES_DISABLE_DURATION_GROUPS)
  -model.properties.disable.durations
    	ignore the durations of stops (env MODEL_PROPERTIES_DISABLE_DURATIONS)
  -model.properties.disable.initialsolution
    	ignore the initial solution (env MODEL_PROPERTIES_DISABLE_INITIAL_SOLUTION)
  -model.properties.disable.stopdurationmultipliers
    	ignore the stop duration multipliers defined on vehicles (env MODEL_PROPERTIES_DISABLE_STOP_DURATION_MULTIPLIERS)
  -model.validate.disable.resources
    	disable the resources validation (env MODEL_VALIDATE_DISABLE_RESOURCES)
  -model.validate.disable.starttime
    	disable the start time validation (env MODEL_VALIDATE_DISABLE_START_TIME)
  -model.validate.enable.matrix
    	enable matrix validation (env MODEL_VALIDATE_ENABLE_MATRIX)
  -model.validate.enable.matrixasymmetrytolerance int
    	percentage of acceptable matrix asymmetry, requires matrix validation enabled (env MODEL_VALIDATE_ENABLE_MATRIX_ASYMMETRY_TOLERANCE) (default 20)
  -runner.input.path string
    	The input file path (env RUNNER_INPUT_PATH)
  -runner.output.path string
    	The output file path (env RUNNER_OUTPUT_PATH)
  -runner.output.solutions string
    	{all, last} (env RUNNER_OUTPUT_SOLUTIONS) (default "last")
  -runner.profile.cpu string
    	The CPU profile file path (env RUNNER_PROFILE_CPU)
  -runner.profile.memory string
    	The memory profile file path (env RUNNER_PROFILE_MEMORY)
  -solve.duration duration
    	maximum duration of the solver (env SOLVE_DURATION) (default 30s)
  -solve.iterations int
    	maximum number of iterations, -1 assumes no limit; iterations are counted after start solutions are generated (env SOLVE_ITERATIONS) (default -1)
  -solve.parallelruns int
    	maximum number of parallel runs, -1 results in using all available resources (env SOLVE_PARALLEL_RUNS) (default -1)
  -solve.rundeterministically
    	run the parallel solver deterministically (env SOLVE_RUN_DETERMINISTICALLY)
  -solve.startsolutions int
    	number of solutions to generate on top of those passed in; one solution generated with sweep algorithm, the rest generated randomly (env SOLVE_START_SOLUTIONS) (default -1)
Copy

Valid time units for -solve.duration are as follows, according to time.ParseDuration from Go's standard library:

  • ns (nanoseconds)
  • us/µs (microseconds)
  • ms (milliseconds)
  • s (seconds)
  • m (minutes)
  • h (hours)

The solve duration is displayed in ns in the output.

The options are marshalled to the output when running an app, under the options key. Here is an example of how the options are displayed.

{
  "model": {
    "constraints": {
      "disable": {
        "attributes": false,
        "capacity": false,
        "capacities": null,
        "distance_limit": false,
        "groups": false,
        "maximum_duration": false,
        "maximum_stops": false,
        "maximum_wait_stop": false,
        "maximum_wait_vehicle": false,
        "mixing_items": false,
        "precedence": false,
        "vehicle_start_time": false,
        "vehicle_end_time": false,
        "start_time_windows": false
      },
      "enable": {
        "cluster": false
      }
    },
    "objectives": {
      "capacities": "",
      "min_stops": 1,
      "early_arrival_penalty": 1,
      "late_arrival_penalty": 1,
      "vehicle_activation_penalty": 1,
      "travel_duration": 0,
      "vehicles_duration": 1,
      "unplanned_penalty": 1,
      "cluster": 0
    },
    "properties": {
      "disable": {
        "durations": false,
        "stop_duration_multipliers": false,
        "duration_groups": false,
        "initial_solution": false
      }
    },
    "validate": {
      "disable": {
        "start_time": false,
        "resources": false
      },
      "enable": {
        "matrix": false,
        "matrix_asymmetry_tolerance": 20
      }
    }
  },
  "solve": {
    "iterations": 50,
    "duration": 10000000000,
    "parallel_runs": 1,
    "start_solutions": 1,
    "run_deterministically": true
  },
  "format": {
    "disable": {
      "progression": true
    }
  },
  "check": {
    "duration": 30000000000,
    "verbosity": "off"
  }
}
Copy

When working with platform, you may also modify the options in code, which would override the ones passed from the runner. Here is an example of how this is done and how the resulting output shows the modified options. Notice that options is modified multiple times inside the solver function.

// package main holds the implementation of the nextroute template.
package main

import (
	"context"
	"log"
	"time"

	"github.com/nextmv-io/sdk/nextroute"
	"github.com/nextmv-io/sdk/nextroute/check"
	"github.com/nextmv-io/sdk/nextroute/factory"
	"github.com/nextmv-io/sdk/nextroute/schema"
	"github.com/nextmv-io/sdk/run"
	runSchema "github.com/nextmv-io/sdk/run/schema"
)

func main() {
	runner := run.CLI(solver)
	err := runner.Run(context.Background())
	if err != nil {
		log.Fatal(err)
	}
}

type options struct {
	Model  factory.Options                `json:"model,omitempty"`
	Solve  nextroute.ParallelSolveOptions `json:"solve,omitempty"`
	Format nextroute.FormatOptions        `json:"format,omitempty"`
	Check  check.Options                  `json:"check,omitempty"`
}

func solver(
	ctx context.Context,
	input schema.Input,
	options options,
) (runSchema.Output, error) {
	// Customize options in the code.
	options.Model.Objectives.TravelDuration = 0.5
	options.Model.Objectives.UnplannedPenalty = 0.3
	options.Model.Constraints.Disable.Capacity = true
	options.Model.Constraints.Disable.Attributes = true
	options.Model.Constraints.Disable.Precedence = true
	options.Solve.Duration = time.Duration(11) * time.Second
	options.Solve.Iterations = 51
	options.Format.Disable.Progression = true

	model, err := factory.NewModel(input, options.Model)
	if err != nil {
		return runSchema.Output{}, err
	}

	solver, err := nextroute.NewParallelSolver(model)
	if err != nil {
		return runSchema.Output{}, err
	}

	solutions, err := solver.Solve(ctx, options.Solve)
	if err != nil {
		return runSchema.Output{}, err
	}
	last := solutions.Last()

	output, err := check.Format(ctx, options, options.Check, solver, last)
	if err != nil {
		return runSchema.Output{}, err
	}
	output.Statistics.Result.Custom = factory.DefaultCustomResultStatistics(last)

	return output, nil
}
Copy

Page last updated