moovexDocs

Optimize Stop Order

Find optimal ordering for a list of stops (TSP)

POST/routing/tsp

Optimize the order of a list of stops using Traveling Salesman Problem (TSP) algorithms. Similar to Single Route but finds the optimal ordering rather than just calculating the route for a given order.

Request Body

FieldTypeRequiredDescription
stopsCoordinates[]YesUnordered list of stops to optimize
startCoordinatesNoFixed starting point
endCoordinatesNoFixed ending point
roundTripbooleanNoReturn to starting point (default: false)
departureISO8601NoDeparture time for traffic calculation

Coordinates

FieldTypeRequiredDescription
latnumberYesLatitude
lngnumberYesLongitude
{ "lat": 40.7128, "lng": -74.0060 }

Example Response

{
  "geometry": "encoded_polyline_string",
  "distance": 12500,
  "duration": 1800,
  "orderedStops": [
    { "lat": 40.7128, "lng": -74.0060 },
    { "lat": 40.7484, "lng": -73.9857 },
    { "lat": 40.7580, "lng": -73.9855 },
    { "lat": 40.7614, "lng": -73.9776 }
  ],
  "legs": [
    { "distance": 3500, "duration": 480 },
    { "distance": 4000, "duration": 540 },
    { "distance": 5000, "duration": 780 }
  ]
}

Response Fields

FieldTypeDescription
geometrystringEncoded polyline of the optimized route
distancenumberTotal distance in meters
durationnumberTotal duration in seconds
orderedStopsCoordinates[]Stops in optimized order
legsRouteLeg[]Per-segment details

Route Leg

Each leg represents the segment between consecutive stops:

FieldTypeDescription
distancenumberSegment distance in meters
durationnumberSegment duration in seconds

Fixed Start/End Points

By default, the algorithm determines the optimal start and end points. You can constrain these:

Fixed Start Only

{
  "stops": [...],
  "start": { "lat": 40.7128, "lng": -74.0060 }
}

Route starts at the specified point, ends at the optimal location.

Fixed Start and End

{
  "stops": [...],
  "start": { "lat": 40.7128, "lng": -74.0060 },
  "end": { "lat": 40.7614, "lng": -73.9776 }
}

Route starts and ends at the specified points.

Round Trip

{
  "stops": [...],
  "start": { "lat": 40.7128, "lng": -74.0060 },
  "roundTrip": true
}

Route returns to the starting point after visiting all stops.

Use Cases

  • Delivery Route Planning: Optimize stop sequence for deliveries
  • Field Service: Plan technician visits in optimal order
  • Sales Routes: Minimize travel time between customer visits
  • Multi-Stop Navigation: Find best order for multiple destinations

On this page