optimize

To solve the travelling salesman problem, that is, to build the best route for passing all the specified checkpoints and get the time of arrival at each of them, use the route/optimize command:

Copied!
svc=route/optimize&params={
  "pathMatrix": [
    [<uint>, ...],
    ...
  ],
  "pointSchedules": [
    {
      "from": <uint>,
      "to": <uint>,
      "waitInterval": <uint>
    },
    ...
  ],
  "flags": <uint>
}

Parameters

Parameter Description
pathMatrix Matrix specifying the movement time (in minutes) between the points (see below).
pointSchedules Schedule specifying the visit and wait time for each point. The number of elements must equal the number of elements in the pathMatrix parameter.
from
to
Parameters defining the time interval (in minutes) within which the courier should visit the point.
waitInterval Time (in minutes) the courier should wait at a point after arrival.
flags Problem condition flags (see below).

pathMatrix

The pathMatrix parameter must always be a square matrix, where the size corresponds to the number of the specified points.

Example:

Copied!
"pathMatrix": [[0, 1, 2], [3, 0, 4], [5, 6, 0]]

This input defines the movement time (in minutes) between three points. In other words, it shows how long it takes to travel from one point to another.

Let’s analyze each row of the matrix.

The first row [0, 1, 2] means:

  • From point 1 to point 1: 0 minutes
  • From point 1 to point 2: 1 minute
  • From point 1 to point 3: 2 minutes

The second row [3, 0, 4] means:

  • From point 2 to point 1: 3 minutes
  • From point 2 to point 2: 0 minutes
  • From point 2 to point 3: 4 minutes

The third row [5, 6, 0] means:

  • From point 3 to point 1: 5 minutes
  • From point 3 to point 2: 6 minutes
  • From point 3 to point 3: 0 minutes

There is always a zero in each row because it represents the travel time from a point to itself.

Flags

Problem condition flags are represented as hexadecimal values.

Flag Description
0x01 The pointSchedules data becomes a mandatory condition.
0x08 It is mandatory to start the route from the first point.
0x10 It is mandatory to end the route in the last point.

Response

If the request is completed successfully, the response is returned in the following format:

Copied!
{
  "success": <bool>,  /* A value of 1 means the problem is solved and all conditions (defined by the flags) are met. A value of 0 means the problem is not solved, or solved with not all of the conditions being met. */
  "order": [
    {
      "tm": 0,          /* Arrival time in seconds. */
      "tmf": "<text>",  /* Formatted arrival time. Example: "hours:minutes". */
      "id": 0           /* Matrix point index, starting from 0. */
    },
    ...                /* Results for other points. */
  ]
}

If the request fails, an error code is returned.

Error codes

Error code Description
4 Internal error.
7 Validation error (invalid matrix structure, incorrect schedule counts, and so on).

If you find a mistake in the text, please select it and press Ctrl+Enter.

Report a mistake

Your message was sent. Thank you!

An error occurred while submitting the form

Download PDF file
Download Word document

See also