apyhub
Back

Traveling Salesman Problem Solver API

What it does

Traveling Salesman Solver computes a visit order for a set of points and returns the start point, the recommended tour, and the total tour cost.

Send point data as geo-coordinates, grid coordinates, or distance matrices. For geo-coordinates, provide a map of point IDs to lat and lon. For grid mode, provide a map of point IDs to integer x and y. For distance-matrix-asymmetric, provide a full row of integer distances for each point. For distance-matrix-symmetric, provide each point’s distances to the points listed before it, with the first point’s array empty. In every mode, you also pass a start point ID and may include iterations to request additional probabilistic optimization passes.

The response always includes start, tour, and cost. Use it when you need a route order for delivery stops, field visits, warehouse picks, inspection routes, or any workflow where minimizing travel distance matters.

This is a route-optimization endpoint, not a map service. It accepts up to 1000 points per request, and it returns the point IDs in the recommended order rather than turning them into coordinates or directions.

▣ ENDPOINT 01 / 04
POST
travelling-salesman-geo-coordinates
https://api.eu.apyhub.com/modernsoftware-pro/travelling-salesman-problem/geo-coordinates

QUICKSTART

GUIDE

Quickstart

Find a tour order starting from a chosen point, using a small set of coordinates.

curl -X POST "https://api.eu.apyhub.com/modernsoftware-pro/travelling-salesman-problem/geo-coordinates?start=home" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "geo-coordinates": {
      "home": { "lat": 40.7128, "lon": -74.0060 },
      "office": { "lat": 40.7580, "lon": -73.9855 }
    }
  }'

What you'll get back

Returns a JSON object with start as the starting point ID, tour as the recommended visit order, and cost as the total tour cost in kilometers.

{
  "start": "home",
  "tour": ["home", "office"],
  "cost": 5.2
}
TRY ITLIVE · 200 ATOMS
Loading your default key…
The full key is used to call the gateway and stays in this tab — never sent to orbit or saved.
body*
geo-coordinates*
Map of point id to its coordinates. Each key is a point id, 1-40 characters long and containing only letters, digits, underscores, colons, and hyphens (`^[a-zA-Z0-9_:-]{1,40} Traveling Salesman Problem Solver - tour between all points — ApyHub
). At most 1000 points are accepted per request.
Start point ID.
Number of additional probabilistic optimization iterations, range: 0-5000

About this endpoint

What it does

Builds a recommended travel tour from a set of geo-coordinates, starting from the point ID you supply and optionally running additional optimization iterations. The response returns the chosen start point, the ordered tour of point IDs, and the total tour cost.

Query Parameter(s)

AttributeTypeMandatoryDescription
startStringYesStart point ID. Pattern: ^[a-zA-Z0-9_:-]{1,40}$.
iterationsIntegerNoNumber of additional probabilistic optimization iterations. Default: 0. Range: 0-5000.

Request Body

ParameterTypeMandatoryDescription
geo-coordinatesObjectYesMap of point id to its coordinates. Each key is a point id, 1-40 characters long and containing only letters, digits, underscores, colons, and hyphens (^[a-zA-Z0-9_:-]{1,40}$). At most 1000 points are accepted per request.
geo-coordinates[].latNumberYesPoint latitude, from -90.0 (S) to 90.0 (N).
geo-coordinates[].lonNumberYesPoint longitude, from -180.0 (W) to 180.0 (E).

Response

Returns a JSON object with required start string, tour array of strings, and cost number fields. The start field is the start point ID carried over from the query parameters, tour is the recommended visit order, and cost is the total tour cost in kilometers.

ParameterTypeDescription
costNumberTotal tour cost: sum of all distances from previous to the next points (in kilometers).
startStringStart point ID (carried over from the query parameters). Pattern: ^[a-zA-Z0-9_:-]{1,40}$.
tourString ArrayThe list of point IDs in the recommended visit order. Each item matches ^[a-zA-Z0-9_:-]{1,40}$.
▣ ENDPOINT 02 / 04
POST
travelling-salesman-grid
https://api.eu.apyhub.com/modernsoftware-pro/travelling-salesman-problem/grid

QUICKSTART

GUIDE

Quickstart

Send your grid and the starting point to get a recommended tour order.

curl -X POST "https://api.eu.apyhub.com/modernsoftware-pro/travelling-salesman-problem/grid?start=A" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "grid": {
      "A": { "x": 0, "y": 0 },
      "B": { "x": 3, "y": 4 },
      "C": { "x": 6, "y": 1 }
    }
  }'

What you'll get back

Returns a JSON object with three top-level fields: start is the starting point ID, tour is an array of point IDs in the recommended visit order, and cost is the total tour cost as a number.

{
  "start": "A",
  "tour": ["A", "B", "C"],
  "cost": 10.2
}
TRY ITLIVE · 100 ATOMS
Loading your default key…
The full key is used to call the gateway and stays in this tab — never sent to orbit or saved.
body*
grid*
Map of point id to its grid coordinates. Each key is a point id, 1-40 characters long and containing only letters, digits, underscores, colons, and hyphens (`^[a-zA-Z0-9_:-]{1,40} Traveling Salesman Problem Solver - tour between all points — ApyHub
). At most 1000 points are accepted per request.
Start point ID.
Number of additional probabilistic optimization iterations, range: 0-5000

About this endpoint

What it does

Computes a travelling-salesman tour from a set of named grid points and returns the recommended visit order, the starting point used, and the total tour cost. You provide the point coordinates in the request body and choose the start point via query parameters.

Query Parameter(s)

AttributeTypeMandatoryDescription
startStringYesStart point ID. Must match ^[a-zA-Z0-9_:-]{1,40}$.
iterationsIntegerNoNumber of additional probabilistic optimization iterations. Range: 0-5000. Default: 0.

Request Body

ParameterTypeMandatoryDescription
gridObjectYesMap of point ID to its grid coordinates. Point IDs must match ^[a-zA-Z0-9_:-]{1,40}$. At most 1000 points are accepted per request.
grid[].xIntegerYesPosition of the point on X axis.
grid[].yIntegerYesPosition of the point on Y axis.

Response

Returns a JSON object with start as a string, tour as a string array, and cost as a number. start is the start point ID carried over from the query parameters, tour is the recommended visit order, and cost is the total tour cost.

ParameterTypeDescription
costNumberTotal tour cost: sum of all distances from previous to the next points.
startStringStart point ID, matching ^[a-zA-Z0-9_:-]{1,40}$.
tourString ArrayThe list of point IDs in the recommended visit order.
▣ ENDPOINT 03 / 04
POST
travelling-salesman-distance-matrix-asymmetric
https://api.eu.apyhub.com/modernsoftware-pro/travelling-salesman-problem/distance-matrix-asymmetric

QUICKSTART

GUIDE

Quickstart

Find a recommended tour starting from a given point by posting an asymmetric distance matrix and the start query parameter.

curl -X POST "https://api.eu.apyhub.com/modernsoftware-pro/travelling-salesman-problem/distance-matrix-asymmetric?start=A" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"distance-matrix-asymmetric":{"A":[0,10,15],"B":[7,0,9],"C":[6,13,0]}}'

What you'll get back

Returns a JSON object with start as a string, tour as an array of point IDs in visit order, and cost as an integer total tour cost.

{
  "start": "A",
  "tour": ["A", "B", "C"],
  "cost": 25
}
TRY ITLIVE · 100 ATOMS
Loading your default key…
The full key is used to call the gateway and stays in this tab — never sent to orbit or saved.
body*
distance-matrix-asymmetric*
Map of point id to its row of distances to every point, in the same order the points are listed. Each key is a point id, 1-40 characters long and containing only letters, digits, underscores, colons, and hyphens (`^[a-zA-Z0-9_:-]{1,40} Traveling Salesman Problem Solver - tour between all points — ApyHub
). At most 1000 points are accepted per request, and each row's length must match the number of points, with the cell for a point's own id set to 0.
Start point ID.
Number of additional probabilistic optimization iterations, range: 0-5000

About this endpoint

What it does

Calculates a recommended tour order for an asymmetric distance matrix, starting from the specified point. The request sends a map of point IDs to their row of distances, and the response returns the chosen start point, the ordered tour, and the total tour cost.

Query Parameter(s)

AttributeTypeMandatoryDescription
startStringYesStart point ID. Must match ^[a-zA-Z0-9_:-]{1,40}$.
iterationsIntegerNoNumber of additional probabilistic optimization iterations. Default: 0; range: 0-5000.

Request Body

ParameterTypeMandatoryDescription
distance-matrix-asymmetricObjectYesMap of point ID to its row of distances to every point, in the same order the points are listed. At most 1000 points are accepted per request. Each key must match ^[a-zA-Z0-9_:-]{1,40}$. Each row must have the same length as the number of points, and the distance from a point to itself must be 0.
distance-matrix-asymmetric[].*Integer ArrayNoDistances to all other points in the same order. Each distance must be an integer >= 0.

Response

Returns a JSON object with start as a string, tour as a string array, and cost as an integer. start is the start point ID carried over from the query parameters, tour is the recommended visit order, and cost is the total tour cost.

ParameterTypeDescription
startStringStart point ID (carried over from the query parameters). Must match ^[a-zA-Z0-9_:-]{1,40}$.
tourString ArrayThe list of point IDs in the recommended visit order. Each item must match ^[a-zA-Z0-9_:-]{1,40}$.
costIntegerTotal tour cost: sum of all distances from previous to the next points.
▣ ENDPOINT 04 / 04
POST
travelling-salesman-distance-matrix-symmetric
https://api.eu.apyhub.com/modernsoftware-pro/travelling-salesman-problem/distance-matrix-symmetric

QUICKSTART

GUIDE

Quickstart

Find a tour starting from a chosen point for the symmetric distance matrix you provide.

curl -X POST "https://api.eu.apyhub.com/modernsoftware-pro/travelling-salesman-problem/distance-matrix-symmetric?start=home" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "distance-matrix-symmetric": {
      "home": [],
      "a": [10],
      "b": [10, 12]
    }
  }'

What you'll get back

Returns a JSON object with three required fields: start is the start point ID, tour is an array of point IDs in the recommended visit order, and cost is the total tour cost as an integer.

{
  "start": "home",
  "tour": ["home", "a", "b"],
  "cost": 22
}
TRY ITLIVE · 100 ATOMS
Loading your default key…
The full key is used to call the gateway and stays in this tab — never sent to orbit or saved.
body*
distance-matrix-symmetric*
Map of point id to its row of distances to only the points listed before it (the array grows by one entry per subsequent point, and the first point's array is empty). Each key is a point id, 1-40 characters long and containing only letters, digits, underscores, colons, and hyphens (`^[a-zA-Z0-9_:-]{1,40} Traveling Salesman Problem Solver - tour between all points — ApyHub
). At most 1000 points are accepted per request.
Start point ID.
Number of additional probabilistic optimization iterations, range: 0-5000

About this endpoint

What it does

Builds a symmetric distance matrix input from the request body, then returns a recommended tour starting from the specified point along with the total tour cost.

Query Parameter(s)

AttributeTypeMandatoryDescription
startStringYesStart point ID. Must match ^[a-zA-Z0-9_:-]{1,40}$.
iterationsIntegerNoNumber of additional probabilistic optimization iterations. Default: 0. Range: 0-5000.

Request Body

ParameterTypeMandatoryDescription
distance-matrix-symmetricObjectYesMap of point ID to its row of distances to only the points listed before it. Each key is a point ID matching ^[a-zA-Z0-9_:-]{1,40}$. At most 1000 points are accepted per request. Each value is an array of integer distances to previous points, and the first point's array is empty.

Response

Returns a JSON object with start as a string, tour as a string array, and cost as an integer. The start value is the point ID carried over from the query parameters; tour is the recommended visit order; cost is the total tour cost.

ParameterTypeDescription
startStringStart point ID, matching ^[a-zA-Z0-9_:-]{1,40}$.
tourString ArrayThe list of point IDs in the recommended visit order. Each item matches ^[a-zA-Z0-9_:-]{1,40}$.
costIntegerTotal tour cost: sum of all distances from previous to the next points.
▣ COMMON ERRORS

Errors any endpoint can return

400bad_request

Required parameter missing or malformed body.

401unauthorized

API key missing, revoked, or not authorized for this service.

429rate_limited

Your plan's per-second rate exceeded. Retry with exponential backoff.

503upstream_busy

Backend temporarily unavailable. Try again in a few seconds.