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.

Go

These are the default options that are available with the go-nextroute community app and the Nextmv routing app.

Nextmv Hybrid Optimization Platform
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 5s)
  -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.

Python

These are the default options that are available with the python-nextroute community app.

usage: main.py [options]

Options for main.py. Use command-line arguments (highest precedence) or
environment variables.

options:
  -h, --help            show this help message and exit
  -input INPUT, --input INPUT
                        [env var: INPUT] (default: ) (type: str): Path to
                        input file. Default is stdin.
  -output OUTPUT, --output OUTPUT
                        [env var: OUTPUT] (default: ) (type: str): Path to
                        output file. Default is stdout.
  -check_duration CHECK_DURATION, --check_duration CHECK_DURATION
                        [env var: CHECK_DURATION] (default: 30.0) (type:
                        float): CHECK_DURATION
  -check_verbosity CHECK_VERBOSITY, --check_verbosity CHECK_VERBOSITY
                        [env var: CHECK_VERBOSITY] (default: off) (type: str):
                        CHECK_VERBOSITY
  -format_disable_progression FORMAT_DISABLE_PROGRESSION, --format_disable_progression FORMAT_DISABLE_PROGRESSION
                        [env var: FORMAT_DISABLE_PROGRESSION] (default: False)
                        (type: bool): FORMAT_DISABLE_PROGRESSION
  -model_constraints_disable_attributes MODEL_CONSTRAINTS_DISABLE_ATTRIBUTES, --model_constraints_disable_attributes MODEL_CONSTRAINTS_DISABLE_ATTRIBUTES
                        [env var: MODEL_CONSTRAINTS_DISABLE_ATTRIBUTES]
                        (default: False) (type: bool):
                        MODEL_CONSTRAINTS_DISABLE_ATTRIBUTES
  -model_constraints_disable_capacities MODEL_CONSTRAINTS_DISABLE_CAPACITIES, --model_constraints_disable_capacities MODEL_CONSTRAINTS_DISABLE_CAPACITIES
                        [env var: MODEL_CONSTRAINTS_DISABLE_CAPACITIES]
                        (default: []) (type: list):
                        MODEL_CONSTRAINTS_DISABLE_CAPACITIES
  -model_constraints_disable_capacity MODEL_CONSTRAINTS_DISABLE_CAPACITY, --model_constraints_disable_capacity MODEL_CONSTRAINTS_DISABLE_CAPACITY
                        [env var: MODEL_CONSTRAINTS_DISABLE_CAPACITY]
                        (default: False) (type: bool):
                        MODEL_CONSTRAINTS_DISABLE_CAPACITY
  -model_constraints_disable_distancelimit MODEL_CONSTRAINTS_DISABLE_DISTANCELIMIT, --model_constraints_disable_distancelimit MODEL_CONSTRAINTS_DISABLE_DISTANCELIMIT
                        [env var: MODEL_CONSTRAINTS_DISABLE_DISTANCELIMIT]
                        (default: False) (type: bool):
                        MODEL_CONSTRAINTS_DISABLE_DISTANCELIMIT
  -model_constraints_disable_groups MODEL_CONSTRAINTS_DISABLE_GROUPS, --model_constraints_disable_groups MODEL_CONSTRAINTS_DISABLE_GROUPS
                        [env var: MODEL_CONSTRAINTS_DISABLE_GROUPS] (default:
                        False) (type: bool): MODEL_CONSTRAINTS_DISABLE_GROUPS
  -model_constraints_disable_maximumduration MODEL_CONSTRAINTS_DISABLE_MAXIMUMDURATION, --model_constraints_disable_maximumduration MODEL_CONSTRAINTS_DISABLE_MAXIMUMDURATION
                        [env var: MODEL_CONSTRAINTS_DISABLE_MAXIMUMDURATION]
                        (default: False) (type: bool):
                        MODEL_CONSTRAINTS_DISABLE_MAXIMUMDURATION
  -model_constraints_disable_maximumstops MODEL_CONSTRAINTS_DISABLE_MAXIMUMSTOPS, --model_constraints_disable_maximumstops MODEL_CONSTRAINTS_DISABLE_MAXIMUMSTOPS
                        [env var: MODEL_CONSTRAINTS_DISABLE_MAXIMUMSTOPS]
                        (default: False) (type: bool):
                        MODEL_CONSTRAINTS_DISABLE_MAXIMUMSTOPS
  -model_constraints_disable_maximumwaitstop MODEL_CONSTRAINTS_DISABLE_MAXIMUMWAITSTOP, --model_constraints_disable_maximumwaitstop MODEL_CONSTRAINTS_DISABLE_MAXIMUMWAITSTOP
                        [env var: MODEL_CONSTRAINTS_DISABLE_MAXIMUMWAITSTOP]
                        (default: False) (type: bool):
                        MODEL_CONSTRAINTS_DISABLE_MAXIMUMWAITSTOP
  -model_constraints_disable_maximumwaitvehicle MODEL_CONSTRAINTS_DISABLE_MAXIMUMWAITVEHICLE, --model_constraints_disable_maximumwaitvehicle MODEL_CONSTRAINTS_DISABLE_MAXIMUMWAITVEHICLE
                        [env var:
                        MODEL_CONSTRAINTS_DISABLE_MAXIMUMWAITVEHICLE]
                        (default: False) (type: bool):
                        MODEL_CONSTRAINTS_DISABLE_MAXIMUMWAITVEHICLE
  -model_constraints_disable_mixingitems MODEL_CONSTRAINTS_DISABLE_MIXINGITEMS, --model_constraints_disable_mixingitems MODEL_CONSTRAINTS_DISABLE_MIXINGITEMS
                        [env var: MODEL_CONSTRAINTS_DISABLE_MIXINGITEMS]
                        (default: False) (type: bool):
                        MODEL_CONSTRAINTS_DISABLE_MIXINGITEMS
  -model_constraints_disable_precedence MODEL_CONSTRAINTS_DISABLE_PRECEDENCE, --model_constraints_disable_precedence MODEL_CONSTRAINTS_DISABLE_PRECEDENCE
                        [env var: MODEL_CONSTRAINTS_DISABLE_PRECEDENCE]
                        (default: False) (type: bool):
                        MODEL_CONSTRAINTS_DISABLE_PRECEDENCE
  -model_constraints_disable_starttimewindows MODEL_CONSTRAINTS_DISABLE_STARTTIMEWINDOWS, --model_constraints_disable_starttimewindows MODEL_CONSTRAINTS_DISABLE_STARTTIMEWINDOWS
                        [env var: MODEL_CONSTRAINTS_DISABLE_STARTTIMEWINDOWS]
                        (default: False) (type: bool):
                        MODEL_CONSTRAINTS_DISABLE_STARTTIMEWINDOWS
  -model_constraints_disable_vehicleendtime MODEL_CONSTRAINTS_DISABLE_VEHICLEENDTIME, --model_constraints_disable_vehicleendtime MODEL_CONSTRAINTS_DISABLE_VEHICLEENDTIME
                        [env var: MODEL_CONSTRAINTS_DISABLE_VEHICLEENDTIME]
                        (default: False) (type: bool):
                        MODEL_CONSTRAINTS_DISABLE_VEHICLEENDTIME
  -model_constraints_disable_vehiclestarttime MODEL_CONSTRAINTS_DISABLE_VEHICLESTARTTIME, --model_constraints_disable_vehiclestarttime MODEL_CONSTRAINTS_DISABLE_VEHICLESTARTTIME
                        [env var: MODEL_CONSTRAINTS_DISABLE_VEHICLESTARTTIME]
                        (default: False) (type: bool):
                        MODEL_CONSTRAINTS_DISABLE_VEHICLESTARTTIME
  -model_constraints_enable_cluster MODEL_CONSTRAINTS_ENABLE_CLUSTER, --model_constraints_enable_cluster MODEL_CONSTRAINTS_ENABLE_CLUSTER
                        [env var: MODEL_CONSTRAINTS_ENABLE_CLUSTER] (default:
                        False) (type: bool): MODEL_CONSTRAINTS_ENABLE_CLUSTER
  -model_objectives_capacities MODEL_OBJECTIVES_CAPACITIES, --model_objectives_capacities MODEL_OBJECTIVES_CAPACITIES
                        [env var: MODEL_OBJECTIVES_CAPACITIES] (default: )
                        (type: str): MODEL_OBJECTIVES_CAPACITIES
  -model_objectives_cluster MODEL_OBJECTIVES_CLUSTER, --model_objectives_cluster MODEL_OBJECTIVES_CLUSTER
                        [env var: MODEL_OBJECTIVES_CLUSTER] (default: 0.0)
                        (type: float): MODEL_OBJECTIVES_CLUSTER
  -model_objectives_earlyarrivalpenalty MODEL_OBJECTIVES_EARLYARRIVALPENALTY, --model_objectives_earlyarrivalpenalty MODEL_OBJECTIVES_EARLYARRIVALPENALTY
                        [env var: MODEL_OBJECTIVES_EARLYARRIVALPENALTY]
                        (default: 1.0) (type: float):
                        MODEL_OBJECTIVES_EARLYARRIVALPENALTY
  -model_objectives_latearrivalpenalty MODEL_OBJECTIVES_LATEARRIVALPENALTY, --model_objectives_latearrivalpenalty MODEL_OBJECTIVES_LATEARRIVALPENALTY
                        [env var: MODEL_OBJECTIVES_LATEARRIVALPENALTY]
                        (default: 1.0) (type: float):
                        MODEL_OBJECTIVES_LATEARRIVALPENALTY
  -model_objectives_minstops MODEL_OBJECTIVES_MINSTOPS, --model_objectives_minstops MODEL_OBJECTIVES_MINSTOPS
                        [env var: MODEL_OBJECTIVES_MINSTOPS] (default: 1.0)
                        (type: float): MODEL_OBJECTIVES_MINSTOPS
  -model_objectives_travelduration MODEL_OBJECTIVES_TRAVELDURATION, --model_objectives_travelduration MODEL_OBJECTIVES_TRAVELDURATION
                        [env var: MODEL_OBJECTIVES_TRAVELDURATION] (default:
                        0.0) (type: float): MODEL_OBJECTIVES_TRAVELDURATION
  -model_objectives_unplannedpenalty MODEL_OBJECTIVES_UNPLANNEDPENALTY, --model_objectives_unplannedpenalty MODEL_OBJECTIVES_UNPLANNEDPENALTY
                        [env var: MODEL_OBJECTIVES_UNPLANNEDPENALTY] (default:
                        1.0) (type: float): MODEL_OBJECTIVES_UNPLANNEDPENALTY
  -model_objectives_vehicleactivationpenalty MODEL_OBJECTIVES_VEHICLEACTIVATIONPENALTY, --model_objectives_vehicleactivationpenalty MODEL_OBJECTIVES_VEHICLEACTIVATIONPENALTY
                        [env var: MODEL_OBJECTIVES_VEHICLEACTIVATIONPENALTY]
                        (default: 1.0) (type: float):
                        MODEL_OBJECTIVES_VEHICLEACTIVATIONPENALTY
  -model_objectives_vehiclesduration MODEL_OBJECTIVES_VEHICLESDURATION, --model_objectives_vehiclesduration MODEL_OBJECTIVES_VEHICLESDURATION
                        [env var: MODEL_OBJECTIVES_VEHICLESDURATION] (default:
                        1.0) (type: float): MODEL_OBJECTIVES_VEHICLESDURATION
  -model_properties_disable_durationgroups MODEL_PROPERTIES_DISABLE_DURATIONGROUPS, --model_properties_disable_durationgroups MODEL_PROPERTIES_DISABLE_DURATIONGROUPS
                        [env var: MODEL_PROPERTIES_DISABLE_DURATIONGROUPS]
                        (default: False) (type: bool):
                        MODEL_PROPERTIES_DISABLE_DURATIONGROUPS
  -model_properties_disable_durations MODEL_PROPERTIES_DISABLE_DURATIONS, --model_properties_disable_durations MODEL_PROPERTIES_DISABLE_DURATIONS
                        [env var: MODEL_PROPERTIES_DISABLE_DURATIONS]
                        (default: False) (type: bool):
                        MODEL_PROPERTIES_DISABLE_DURATIONS
  -model_properties_disable_initialsolution MODEL_PROPERTIES_DISABLE_INITIALSOLUTION, --model_properties_disable_initialsolution MODEL_PROPERTIES_DISABLE_INITIALSOLUTION
                        [env var: MODEL_PROPERTIES_DISABLE_INITIALSOLUTION]
                        (default: False) (type: bool):
                        MODEL_PROPERTIES_DISABLE_INITIALSOLUTION
  -model_properties_disable_stopdurationmultipliers MODEL_PROPERTIES_DISABLE_STOPDURATIONMULTIPLIERS, --model_properties_disable_stopdurationmultipliers MODEL_PROPERTIES_DISABLE_STOPDURATIONMULTIPLIERS
                        [env var:
                        MODEL_PROPERTIES_DISABLE_STOPDURATIONMULTIPLIERS]
                        (default: False) (type: bool):
                        MODEL_PROPERTIES_DISABLE_STOPDURATIONMULTIPLIERS
  -model_validate_disable_resources MODEL_VALIDATE_DISABLE_RESOURCES, --model_validate_disable_resources MODEL_VALIDATE_DISABLE_RESOURCES
                        [env var: MODEL_VALIDATE_DISABLE_RESOURCES] (default:
                        False) (type: bool): MODEL_VALIDATE_DISABLE_RESOURCES
  -model_validate_disable_starttime MODEL_VALIDATE_DISABLE_STARTTIME, --model_validate_disable_starttime MODEL_VALIDATE_DISABLE_STARTTIME
                        [env var: MODEL_VALIDATE_DISABLE_STARTTIME] (default:
                        False) (type: bool): MODEL_VALIDATE_DISABLE_STARTTIME
  -model_validate_enable_matrix MODEL_VALIDATE_ENABLE_MATRIX, --model_validate_enable_matrix MODEL_VALIDATE_ENABLE_MATRIX
                        [env var: MODEL_VALIDATE_ENABLE_MATRIX] (default:
                        False) (type: bool): MODEL_VALIDATE_ENABLE_MATRIX
  -model_validate_enable_matrixasymmetrytolerance MODEL_VALIDATE_ENABLE_MATRIXASYMMETRYTOLERANCE, --model_validate_enable_matrixasymmetrytolerance MODEL_VALIDATE_ENABLE_MATRIXASYMMETRYTOLERANCE
                        [env var:
                        MODEL_VALIDATE_ENABLE_MATRIXASYMMETRYTOLERANCE]
                        (default: 20) (type: int):
                        MODEL_VALIDATE_ENABLE_MATRIXASYMMETRYTOLERANCE
  -solve_duration SOLVE_DURATION, --solve_duration SOLVE_DURATION
                        [env var: SOLVE_DURATION] (default: 5.0) (type:
                        float): SOLVE_DURATION
  -solve_iterations SOLVE_ITERATIONS, --solve_iterations SOLVE_ITERATIONS
                        [env var: SOLVE_ITERATIONS] (default: -1) (type: int):
                        SOLVE_ITERATIONS
  -solve_parallelruns SOLVE_PARALLELRUNS, --solve_parallelruns SOLVE_PARALLELRUNS
                        [env var: SOLVE_PARALLELRUNS] (default: -1) (type:
                        int): SOLVE_PARALLELRUNS
  -solve_rundeterministically SOLVE_RUNDETERMINISTICALLY, --solve_rundeterministically SOLVE_RUNDETERMINISTICALLY
                        [env var: SOLVE_RUNDETERMINISTICALLY] (default: False)
                        (type: bool): SOLVE_RUNDETERMINISTICALLY
  -solve_startsolutions SOLVE_STARTSOLUTIONS, --solve_startsolutions SOLVE_STARTSOLUTIONS
                        [env var: SOLVE_STARTSOLUTIONS] (default: -1) (type:
                        int): SOLVE_STARTSOLUTIONS
Copy

The units for options that deal with time duration (such as -solve_duration) are seconds. This applies for the input and output as well.

Output

Most options are parsed to the output, under the options key. Here is an example of a Go app.

{
  "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 a custom app, 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.

// © 2019-present nextmv.io inc

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

import (
	"context"
	"log"
	"time"

	"github.com/nextmv-io/nextroute"
	"github.com/nextmv-io/nextroute/check"
	"github.com/nextmv-io/nextroute/factory"
	"github.com/nextmv-io/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, err := solutions.Last()
	if err != nil {
		return runSchema.Output{}, err
	}

	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

Go to on-page nav menu