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"]} | ✅ |
custom_data | No | any | NA | Custom data to be used arbitrarily within the model. | {"custom_data": {"foo": "bar"}} | ➖ |
Vehicle
- If the
duration_matrix
is not specified in the input, thespeed
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:
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"}} |
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} |
Solution
Field name | Always present | Data type | SI Unit | Description | Example |
---|---|---|---|---|---|
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 |
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 |
---|---|---|---|---|---|
result | No | result | NA | Final result of the solutions. | See result |
run | Yes | run | NA | Information of the run. | See run |
schema | Yes | string | NA | Schema of the statistics. | {"schema": "v1"} |
series_data | No | series_data | NA | Data series of solution values. | See series_data |
Here you can find additional definitions used in the statistics
schema:
result
Field name Always present Data type SI Unit Description Example duration
Yes float
seconds
Time duration to get to the final result. {"duration": 0.123}
value
Yes float
NA Value of the final result. {"value": 0.123}
`custom No any
NA Custom metrics specified in the custom app (see below). {"custom": {"activated_vehicles": 2,"unplanned_stops": 4}}
run
Field name Always present Data type SI Unit Description Example duration
Yes float
seconds
Time duration of the run. {"duration": 0.123}
series_data
Field name Always present Data type SI Unit Description Example value
Yes series
NA Value of the data series. See series
custom
No, only if specified array
ofseries
NA Custom data in the series. See series
series
Field name Always present Data type SI Unit Description Example name
Yes string
NA Name of the series. {"name": "foo"}
data_points
Yes array
ofdata_point
NA Data points of the series. See data_point
data_point
Field name Always present Data type SI Unit Description Example x
Yes float
NA X value of the data point. {"x": 0.123}
y
Yes float
NA Y value of the data point. {"y": 0.123}
Add custom statistics
If you have a custom app, you may wish to add custom statistics to your result. You can do this by passing a computed statistic in to output.Statistics.Result.Custom
. For example, if you want to add unplanned stop count as a custom statistic, you can:
- format the output using the nextroute factory formatter.
- Add custom unplanned stop count to the formatted solution output.
An example is shown below: