Nextmv provides a hosted map data service based on OSRM if you wish to use a pre-calculated distance matrix. The service is available as a paid add on to any paid plan. The service can be configured via the input file and can be used with either the Nextmv Routing marketplace app or custom apps.

This feature is configurable via `.json`

input, without the need for code customization and is available for both the Marketplace app and Platform. You can find a list of all available features here.

This how-to guide assumes you already completed the get started with vehicle routing tutorial.

When `distance_matrix`

(with `speed`

) and `duration_matrix`

are both specified, the `duration_matrix`

takes precedence.

Field name | Required | Data type | SI Unit | Defined on | Example | Configurable via `defaults` |
---|---|---|---|---|---|---|

`distance_matrix` | No | `array` of `array` of `float` | `meters` | input | `{"distance_matrix": [[1.23, 4.56], [7.89, 0.12]]}` | ➖ |

By default, the distance between two locations is calculated using the Haversine formula. To override this behavior, you can specify a distance matrix in the input that provides the distance of going from location A to B, using the `distance_matrix`

feature. The travel duration between locations is obtained by factoring the distance and the `speed`

(specified in `meters/second`

) of each vehicle.

When using the `distance_matrix`

feature, the `speed`

of each vehicle must be specified.

The `distance_matrix`

is useful when you want to use a different distance function, or when you want to use a pre-calculated distance matrix. For example, you may have your own mapping service that provides the distance between locations.

The `distance_matrix`

is an `array`

of `array`

s of `float`

. The units for the values are `meters`

. The matrix must be square, and its size is:

Where:

`n`

: the number of stops.`m`

: the number of vehicles.

If you’re using Nextmv Maps, the max size for the distance matrix is 2,000 x 2,000. If you’re using your own matrix there is no size limit other than the 100 MB file size limit for the input file. The size follows that each `float`

value is the distance in meters of traveling from location at index `i`

to location at index `j`

. Indices must be given in the following order:

The matrix may be asymmetric, meaning that the distance of going from location A to B may be different than the distance of going from location B to A.

Here is an example input defining a complete distance matrix. In this example, the distance to travel from `"Fushimi Inari Taisha"`

to `"Kiyomizu-dera"`

and viceversa is `4300`

meters. Vehicle locations are omitted, given that the distance of going to/from them is zero.

A sample output obtained after solving the problem is also shown.