Input
The format for timestamps should be RFC3339
, e.g.: "2023-01-01T00:00:00Z"
.
The input schema is a JSON payload defining the vehicles, stops, and features for a given routing problem. Nextmv's tools are designed to operate directly on business data (in JSON
) to produce decisions that are actionable by software systems. This makes decisions more interpretable and easier to test. It also makes integration with data warehouses and business intelligence platforms significantly easier. An input contains the following components:
Field name | Required | Data type | SI Unit | Description | Example |
---|---|---|---|---|---|
vehicles | Yes | array of vehicle | NA | Vehicles to route. | See vehicle |
stops | Yes | array of stop | NA | Stops that will be routed and assigned to the vehicles. | See stop |
alternate_stops | No | array of alternate_stop | NA | Alternate stops which can be serviced. | {"alternate_stops": [{"id": "Inafuku","location": { "lon": 123, "lat": 456 }}]} |
defaults | No | object | NA | Default properties for vehicles and stops. | {"defaults": {"stops": {"duration": 1.23}}} |
stop_groups | No | array of array of string | NA | Group of stops that must be part of the same route. | {"stop_groups": [["foo", "bar"], ["baz", "roh"]]} |
duration_matrix | No | array of array of float | seconds | Matrix of durations between locations. | {"duration_matrix": [[1.23, 4.56], [7.89, 0.12]]} |
distance_matrix | No | array of array of float | meters | Matrix of distances between locations. | {"distance_matrix": [[1.23, 4.56], [7.89, 0.12]]} |
duration_groups | No | array of duration_group | NA | Duration added when approaching the group. | {"duration_groups": [{"group":["foo", "bar"], "duration": 200}] |
custom_data | No | any | NA | Custom data to be used arbitrarily within the model. | {"custom_data": {"foo": "bar"}} |
options | No | object | NA | Arbitrary options. | {"options": {"foo": "bar"}} |
Here you can find a sample .json
with the input schema:
Alternate stop
An alternate stop has all the same fields as a stop
excluding the following:
precedes
succeeds
compatibility_attributes
The id
of the alternate stop is used as part of the alternate_stops
field in the vehicle
schema.
Defaults
The defaults
schema defines the default values for all the vehicles
and stops
. Please go to each section to determine which fields are configurable as defaults.
Field name | Required | Data type | Description | Example |
---|---|---|---|---|
vehicles | No | vehicle | Default values for the vehicle. | {"vehicle": {"capacity": 5}} |
stops | No | stop | Default values for the stop. | {"stop": {"duration": 123}} |
Duration Group
A duration groups is used in the input
schema.
Field name | Required | Data type | SI Unit | Description | Example |
---|---|---|---|---|---|
group | Yes | array of string | NA | Stop IDs contained in the group. | {"group": ["foo", "bar"]} |
duration | Yes | int | seconds | Duration to add when visiting the group. | {"duration": 4} |
Location
A location is used in the vehicle
and stop
schemas.
Field name | Required | Data type | Description | Example |
---|---|---|---|---|
lon | Yes | float | Longitude of the location. | {"lon": 1.23} |
lat | Yes | float | Latitude of the location. | {"lat": 4.56} |
Stop
The target_arrival_time
is used in the early_arrival_time_penalty
and late_arrival_time_penalty
features.
Field name | Required | Data type | SI Unit | Description | Example | Configurable via defaults |
---|---|---|---|---|---|---|
id | Yes | string | NA | Unique identifier for the stop. | {"id": "foo"} | ➖ |
location | Yes | location | NA | Location of the stop. | {"location": {"lon": 1.23, "lat": 4.56}} | ➖ |
precedes | No | array of string or string | NA | Stops that must be visited after this one on the same route. | {"precedes": ["foo", "bar"]} | ➖ |
succeeds | No | array of string or string | NA | Stops that must be visited before this one on the same route. | {"succeeds": ["foo", "bar"]} | ➖ |
quantity | No | object (string to int ) or int | NA | Quantity of the stop. | {"quantity": -1} | ✅ |
target_arrival_time | No | timestamp | NA | Target arrival time at the stop. | {"target_arrival_time": "2023-01-01T00:00:00Z"} | ✅ |
start_time_window | No | array of timestamp or array of array of timestamp | NA | Time window in which the stop can start service. | {"start_time_window": [["2023-01-01T12:00:00Z", "2023-01-01T12:05:00Z"], ["2023-01-01T12:30:00Z", "2023-01-01T13:35:00Z"]]} | ✅ |
max_wait | No | int | seconds | Maximum waiting time at the stop. | {"max_wait": 123} | ✅ |
duration | No | int | seconds | Duration of the service time at the stop. | {"duration": 123} | ✅ |
unplanned_penalty | No | int | NA | Penalty for not planning the stop. | {"unplanned_penalty": 123} | ✅ |
early_arrival_time_penalty | No | float | NA | Penalty for arriving at the stop before the target arrival time. | {"early_arrival_time_penalty": 1.23} | ✅ |
late_arrival_time_penalty | No | float | NA | Penalty for arriving at the stop after the target arrival time. | {"late_arrival_time_penalty": 1.23} | ✅ |
compatibility_attributes | No | array of string | NA | Attributes that the stop is compatible with. | {"compatibility_attributes": ["foo", "bar"]} | ✅ |
mixing_items | No | map of string to mix_item | NA | Propoerties which can not be on a vehicle at the same time. | {"mixing_items": {"hazchem": {"name": "F-A-W-E","quantity": 1}} | ➖ |
custom_data | No | any | NA | Custom data to be used arbitrarily within the model. | {"custom_data": {"foo": "bar"}} | ➖ |
Here you can find additional definitions used in the stop
schema:
mix_item
Field name Required Data type Description Example name
Yes string
Name of the "ingredient" to avoid mixing. {"id": "vegan"}
quantity
Yes int
Quantity the stop adds / removes of the "ingredient" {"quantity": 1}
Vehicle
If the duration_matrix
is not specified in the input, the speed
must be present.
Field name | Required | Data type | SI Unit | Description | Example | Configurable via defaults |
---|---|---|---|---|---|---|
id | Yes | string | NA | Unique identifier for the vehicle. | {"id": "foo"} | ➖ |
capacity | No | object (string to int ) or int | NA | Capacity of the vehicle. | {"capacity": {"bar": 2}} | ✅ |
start_level | No | object (string to int ) or int | NA | Initial capacity of the vehicle. | {"start_level": {"bar": 2}} | ✅ |
start_location | No | location | NA | Location where the vehicle starts. | {"start_location": {"lon": 1.23, "lat": 4.56}} | ✅ |
end_location | No | location | NA | Location where the vehicle ends. | {"end_location": {"lon": 1.23, "lat": 4.56}} | ✅ |
min_stops | No | int | NA | Minimum stops that a vehicle should visit. | {"min_stops": 8} | ✅ |
min_stops_penalty | No | float | NA | Penalty for not complying with minimum stops. | {"min_stops_penalty": 1000} | ✅ |
speed | No | float | meters/second | Speed of the vehicle. | {"speed": 1.23} | ✅ |
start_time | No | timestamp | NA | Time when the vehicle starts its route. | {"start_time": "2023-01-01T00:00:00Z"} | ✅ |
end_time | No | timestamp | NA | Latest time at which the vehicle ends its route. | {"end_time": "2023-01-01T00:00:00Z"} | ✅ |
compatibility_attributes | No | array of string | NA | Attributes that the vehicle is compatible with. | {"compatibility_attributes": ["foo", "bar"]} | ✅ |
max_stops | No | int | NA | Maximum number of stops that the vehicle can visit. | {"max_stops": 2} | ✅ |
max_distance | No | int | meters | Maximum distance that the vehicle can travel. | {"max_distance": 123} | ✅ |
max_duration | No | int | seconds | Maximum duration that the vehicle can travel. | {"max_duration": 123} | ✅ |
max_wait | No | int | seconds | Maximum aggregated waiting time that the vehicle can wait across route stops. | {"max_wait": 123} | ✅ |
stop_duration_multiplier | No | float | NA | Multiplier on a stop's duration. | {"stop_duration_multiplier": 1.23} | ✅ |
activation_penalty | No | int | NA | Cost of using the vehicle. | {"activation_penalty": 1.23} | ✅ |
alternate_stops | No | array of string | NA | Alternate stops IDs to service for the vehicle. | {"alternate_stops": ["foo", "bar"]} | ✅ |
initial_stops | No | array of initial_stop | NA | Initial stops planned on the vehicle. | {"initial_stops": [{"id": "bar"}]} | ➖ |
custom_data | No | any | NA | Custom data to be used arbitrarily within the model. | {"custom_data": {"foo": "bar"}} | ➖ |
Here you can find additional definitions used in the vehicle
schema:
initial_stop
Field name Required Data type Description Example id
Yes string
Unique identifier for the stop. {"id": "foo"}
fixed
No bool
Whether the stop is fixed or not. {"fixed": true}
Input schema Validation
The Nextmv SDK runner implements automatic schema validation for:
- correctly named fields,
- unknown fields,
- invalid data types.
This validation applies to any input passed to the runner including custom input.
If you prefer to turn off schema validation, you can add the run.InputValidate
argument.
Output
The output schema defines the solution to the routing problem, in addition to the options that were used and summary statistics, all in JSON
format. The output schema contains the following components.
Field name | Always present | Data type | SI Unit | Description | Example |
---|---|---|---|---|---|
options | Yes | options | NA | Options used to generate the solution. | {"options": {"solve": {"iterations": 50}}} |
solutions | Yes | array of solution | NA | Solutions to the routing problem. | {"solutions": []} |
statistics | Yes | statistics | NA | Summary statistics of the solution. | {"statistics": {"total_cost": 123}} |
version | Yes | object | NA | Version of the Nextmv SDK used to generate the solution. | {"version": {"sdk": "v1.2.3"}} |
Here you can find a sample .json
with the output schema:
Solution
Field name | Always present | Data type | SI Unit | Description | Example |
---|---|---|---|---|---|
check | No | check | NA | Information about feasibility of the input or solution. | See check |
objective | Yes | objective | NA | Objective value of the solution. | See objective |
unplanned | Yes | array of output_stop | NA | Unplanned stops. | See output_stop |
vehicles | Yes | array of output_vehicle | NA | Vehicles with planned stops. | See output_vehicle |
Check
Check holds information about the feasibility of the input or solution depending on the type of check that was performed. It is only used when the nextcheck feaure is used.
Field name | Always present | Data type | SI Unit | Description | Example |
---|---|---|---|---|---|
duration_maximum | Yes | float | seconds | The time allowed to generate a feasibility report. | {"duration_maximum": 12.3} |
duration_used | Yes | float | seconds | The time it took to generate the feasibility report. | {"duration_used": 12.3} |
plan_units | Yes | array of plan_unit | NA | Reports on the the individual plan units. It defines which stops are part of the plan unit and whether or not is has a best move; if there is no best move reasons are given for why. The level of detail for each plan unit in the plan units report depends on the verbosity defined for the report. | See plan_unit |
remark | Yes | string | NA | This reports the status of the check report. Its value can be completed or timedout . | {"remark": "completed"} |
solution | Yes | solution | NA | Contains a summary of the plan being examined. It includes information on the number of plan units that were parsed from the list of stops, the objective function that was defined, and the vehicle information. | See solution |
summary | Yes | summary | NA | Summarizes how many plan units need to be checked and how many were checked. It also summarizes the results of the plan units that were checked. | See summary |
vehicles | Yes | array of vehicles | NA | Aggregates the individual plan units per vehicle. | See vehicles |
verbosity | Yes | string | NA | The level of verbosity used to generate the report. | {"verbosity": "high"} |
Plan unit
A plan unit is a set of stops that need to be visited by one vehicle. Depending on features used in the model, plan units consist of one or more stops. Features that lead to plan units with more than one stop are e.g. Precedence or stop groups.
Field name | Always present | Data type | SI Unit | Description | Example |
---|---|---|---|---|---|
stops | Yes | array of string | NA | ID is the ID of the plan unit. The ID of the plan unit is the slice of ID's of the stops in the plan unit. | {"stops": ["1", "2"]} |
has_best_move | Yes | bool | NA | True if a move is found for the plan unit. A plan unit has no move found if the plan unit is over-constrained or the move found is too expensive. | {"has_best_move": true} |
best_move_increases_objective | Yes | bool | NA | True if the best move for the plan unit increases the objective. | {"best_move_increases_objective": true} |
best_move_failed | Yes | bool | NA | True if the plan unit best move failed to execute. | {"best_move_increases_objective": true} |
vehicles_have_moves | No | int | NA | The number of vehicles that have moves for the plan unit. Only calculated if the verbosity is medium or higher. | {"vehicles_have_moves": 1} |
vehicles_with_moves | No | array of string | NA | The IDs of the vehicles that have moves for the plan unit. Only calculated if the verbosity is very high . | {"vehicles_with_moves": ["1", "2"]} |
constraints | No | map of string to int | NA | Shows how often each violated constraint was violated. | {"maximum_stops": 2} |
best_move_objective | No | objective | NA | The estimate of the objective of the best move if the plan unit has a best move. | See objective |
Best move objective
Field name | Always present | Data type | SI Unit | Description | Example |
---|---|---|---|---|---|
vehicle | No | string | NA | The ID of the vehicle for which it reports the objective. | {"vehicle": "1"} |
value | Yes | float | NA | The value of the objective. | {"value": "1.0"} |
terms | Yes | array of objective term | NA | The value of the objective terms. | See objective term |
Objective term
Field name | Always present | Data type | SI Unit | Description | Example |
---|---|---|---|---|---|
name | Yes | string | NA | The name of the objective term. | {"name": "term1"} |
factor | Yes | float | NA | The factor of the objective term. | {"factor": 2.0} |
base | Yes | float | NA | The base value of the objective term. | {"base": 1.0} |
value | Yes | float | NA | The value of the objective term which is the factor times base . | {"value": 2.0} |
Solution (Nextcheck)
Field name | Always present | Data type | SI Unit | Description | Example |
---|---|---|---|---|---|
stops_planned | Yes | int | NA | The number of stops planned in the start solution. | {"stops_planned": 11} |
plan_units_planned | Yes | int | NA | The number of units planned in the start solution. | {"plan_units_planned": 10} |
plan_units_unplanned | Yes | int | NA | The number of units unplanned in the start solution. | {"plan_units_unplanned": 9} |
vehicles_used | Yes | int | NA | The number of vehicles used in the start solution. | {"vehicles_used": 2} |
vehicles_not_used | Yes | int | NA | The number of vehicles not used in the start solution, the empty vehicles. | {"vehicles_not_used": 3} |
objective | Yes | objective | NA | The objective of the start solution. | See objective |
Objective (Nextcheck)
Field name | Always present | Data type | SI Unit | Description | Example |
---|---|---|---|---|---|
vehicle | No | string | NA | The ID of the vehicle for which it reports the objective. | {"vehicle": "1"} |
value | Yes | float | NA | The value of the objective. | {"value": 2.0} |
terms | Yes | array of objective term | NA | The check of the individual terms of the objective. | See objective term |
Summary
Field name | Always present | Data type | SI Unit | Description | Example |
---|---|---|---|---|---|
plan_units_to_be_checked | Yes | int | NA | The number of plan units to be checked. | {"duration_maximum": 12} |
plan_units_checked | Yes | int | NA | The number of plan units checked. If this is less than plan_units_to_be_checked the check timed out. | {"plan_units_checked": 42} |
plan_units_best_move_found | Yes | int | NA | The number of plan units for which at least one move has been found and the move is executable. | {"plan_units_best_move_found": 2} |
plan_units_have_no_move | Yes | int | NA | The number of plan units for which no feasible move has been found. This implies there is no move that can be executed without violating a constraint. | {"plan_units_have_no_move": 12} |
plan_units_best_move_increases_objective | Yes | int | NA | The number of plan units for which the best move is executable but would increase the objective value instead of decreasing it. | {"plan_units_best_move_increases_objective": 12} |
plan_units_best_move_failed | Yes | int | NA | The number of plan units for which the best move can not be planned. This should not happen if all the constraints are implemented correct. | {"plan_units_best_move_failed": 12} |
moves_failed | Yes | int | NA | The number of moves that failed. | {"moves_failed": 12} |
Vehicle (Nextcheck)
Field name | Always present | Data type | SI Unit | Description | Example |
---|---|---|---|---|---|
id | Yes | string | NA | The ID of the vehicle. | {"id": "vehicle-1"} |
plan_units_have_moves | No | int | NA | The number of plan units that have moves for the vehicle. Only calculated if the depth is medium . | {"plan_units_have_moves": 1} |
Objective
Field name | Always present | Data type | SI Unit | Description | Example |
---|---|---|---|---|---|
name | Yes | string | NA | Name of the objective. | {"name": "foo"} |
objectives | No | array of objective | NA | Terms of the main objective. | {"objectives": [{"name": "foo"}, {"name": "bar"}]} |
factor | Yes | float | NA | Factor of the objective. | {"factor": 1.23} |
base | Yes | float | NA | Base value of the objective. | {"base": 1.23} |
value | Yes | float | NA | Value of the objective, equivalent to factor * base . | {"value": 1.23} |
Output stop
Field name | Always present | Data type | SI Unit | Description | Example |
---|---|---|---|---|---|
id | Yes | string | NA | Unique identifier for the stop. | {"id": "foo"} |
location | Yes | location | NA | Location of the stop. | {"location": {"lon": 1.23, "lat": 4.56}} |
custom_data | No, only if defined on the input stop | any | NA | Custom data to be used arbitrarily within the model. | {"custom_data": {"foo": "bar"}} |
Output vehicle
Field name | Always present | Data type | SI Unit | Description | Example |
---|---|---|---|---|---|
id | Yes | string | NA | Unique identifier for the vehicle. | {"id": "foo"} |
route | Yes | array of planned_stop | NA | Planned stops for the vehicle. | See planned_stop |
route_travel_duration | Yes | int | seconds | Total travel duration of the route. | {"route_travel_duration": 123} |
route_duration | Yes | int | seconds | Total duration of the route, including waiting times. | {"route_duration": 123} |
route_stops_duration | No, only if greater than zero. | int | seconds | Total duration of the service times across all stops. | {"route_stops_duration": 123} |
route_waiting_duration | No, only if greater than zero. | int | seconds | Total waiting time across all stops. | {"route_waiting_duration": 123} |
custom_data | No, only if defined on the input vehicle | any | NA | Custom data to be used arbitrarily within the model. | {"custom_data": {"foo": "bar"}} |
route_travel_distance | No, only if greater than zero. | int | meters | Total travel distance of the route. | {"route_travel_distance": 123} |
Planned stop
Field name | Always present | Data type | SI Unit | Description | Example |
---|---|---|---|---|---|
stop | Yes | output_stop | NA | Stop that was planned. | See output_stop |
cumulative_travel_duration | Yes | int | seconds | Cumulative travel duration of the route up to the stop. | {"cumulative_travel_duration": 123} |
travel_duration | Yes | int | seconds | Travel duration from the previous stop to the current stop. | {"travel_duration": 123} |
target_arrival_time | No, only if defined on the input stop | timestamp | NA | Target arrival time at the stop. | {"target_arrival_time": "2023-01-01T00:00:00Z"} |
arrival_time | No, only if the input vehicle has start_time | timestamp | NA | Arrival time at the stop. | {"arrival_time": "2023-01-01T00:00:00Z"} |
start_time | No, only if the input vehicle has start_time | timestamp | NA | Time at which the stop starts service. | {"start_time": "2023-01-01T00:00:00Z"} |
end_time | No, only if the input vehicle has start_time | timestamp | NA | Time at which the stop ends service. | {"end_time": "2023-01-01T00:00:00Z"} |
waiting_duration | No, only if greater than zero. | int | seconds | Waiting time at the stop. | {"waiting_duration": 123} |
duration | No, only if greater than zero. | int | seconds | Duration of the service time at the stop. | {"duration": 123} |
early_arrival_duration | No, only if greater than zero. | int | seconds | Duration by which the vehicle arrived early at the stop. | {"early_arrival_duration": 123} |
late_arrival_duration | No, only if greater than zero. | int | seconds | Duration by which the vehicle arrived late at the stop. | {"late_arrival_duration": 123} |
cumulative_travel_distance | No, only if greater than zero. | int | meters | Cumulative travel distance of the route up to the stop. | {"cumulative_travel_distance": 123} |
travel_distance | No, only if greater than zero. | int | meters | Travel distance from the previous stop to the current stop. | {"travel_distance": 123} |
Statistics
By default, all fields in statistics
are always present. The -format.disable.progression
option can be used to disable the result
and series_data
fields.
Field name | Always present | Data type | SI Unit | Description / Example |
---|---|---|---|---|
| No |
| NA | Final result of the solutions. See |
| Yes |
| NA | Information of the run. See |
| Yes |
| NA | Schema of the statistics.
|
| No |
| NA | Data series of solution values. See |
See the Add custom statistics section for an example of how to add your own custom statistics.
Here you can find additional definitions used in the statistics
schema:
result
Field name | Always present | Data type | SI Unit | Description / Example |
---|---|---|---|---|
| Yes |
|
| Time duration to get to the final result.
|
| Yes |
| NA | Value of the final result.
|
| No |
| NA | Custom metrics specified in the custom app (see below).
|
run
Field name | Always present | Data type | SI Unit | Description / Example |
---|---|---|---|---|
| Yes |
|
| Time duration of the run.
|
| No |
| NA | A measure of work done within the algorithm, typically to improve a solution.
|
series_data
Field name | Always present | Data type | SI Unit | Description / Example |
---|---|---|---|---|
| Yes |
| NA | Value of the data series. See |
| No |
| NA | Custom data in the series, will only appear if specified explicitly. See |
series
Field name | Always present | Data type | SI Unit | Description / Example |
---|---|---|---|---|
| Yes |
| NA | Name of the series.
|
| Yes |
| NA | Data points of the series. See |
data_point
Field name | Always present | Data type | SI Unit | Description / Example |
---|---|---|---|---|
| Yes |
| NA | X value of the data point.
|
| Yes |
| NA | Y value of the data point.
|