Back to the blog ·

VRP vs TSP: which route optimization API call do you need?

The traveling salesman problem and the vehicle routing problem, what each one solves, and how to pick the right call on an API that bills one vehicle differently from many.

Most route planning requests fall into one of two problems, and the names are often used loosely. The traveling salesman problem (TSP) asks for the shortest order to visit a set of places with one traveler. The vehicle routing problem (VRP) asks which vehicle should visit which places, and in what order, when vehicles have limits. A TSP is a special case of a VRP with one vehicle and no limits. The difference matters for your code and for your bill, so this post shows how to tell them apart and which call to make.

TSP: one vehicle, one order

A TSP has one route. You give it a start point, the stops, and optionally an end point. It returns the order that makes the route shortest or fastest, given the travel times between stops.

Typical cases:

  • A field technician who visits 12 customers from the van depot and goes home.
  • A sales rep who needs the best order for a day of visits.
  • A single courier on a bicycle with no capacity limit.

The route is the answer. There is no fleet to assign.

VRP: several vehicles, limits, and assignments

A VRP adds decisions. Which vehicle serves which stop? What if the vehicle can only carry 20 parcels, or a stop must be served between 09:00 and 11:00, or only vehicles with a refrigerated skill can serve a grocery order? Those limits are what make the problem a VRP. The answer has three parts: the assignment, the order on each vehicle, and the stops that could not be served.

Typical cases:

  • A delivery company with six vans and 300 parcels in a day.
  • A dispatcher who needs to add a new order to a route that is already running.
  • A last-mile operation with depots, time windows and capacities.

Which call to make

Argamin has one optimization endpoint, POST /optimize, and it covers both problems. The number of vehicles in the request decides the price.

  • One vehicle in vehicles is billed as single-vehicle optimization. The free quota is 5,000 stops a month, and the first tier is $3 per 1,000 stops.
  • Two or more vehicles are billed as fleet optimization. The free quota is 1,000 stops, and the first tier is $10 per 1,000 stops.

So a TSP-shaped problem should be sent with one vehicle, and it will be billed at the lower rate. Do not add a dummy second vehicle to get a different answer; that changes the price and the solution.

If you do not need an optimizer at all, use the cheaper, simpler calls:

  • POST /route returns the driving route between 2 and 25 waypoints in the order you give them. Nothing is reordered.
  • POST /matrix returns travel times and distances between origins and destinations. Use it when you build the order yourself.

A TSP request

This is one vehicle that starts at a depot and ends at its last stop. Leaving out end ends the route at the last stop, so the vehicle does not return to the depot.

Terminal window
curl https://api.argamin.ai/v1/optimize \
-H "Authorization: Bearer $ARGAMIN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"vehicles": [
{ "id": "tech-1", "start": { "lat": 51.5072, "lng": -0.1276 } }
],
"jobs": [
{ "id": "visit-01", "location": { "lat": 51.5155, "lng": -0.0922 }, "service": 900 },
{ "id": "visit-02", "location": { "lat": 51.4613, "lng": -0.1156 }, "service": 600 },
{ "id": "visit-03", "location": { "lat": 51.5390, "lng": -0.1426 }, "service": 1200 },
{ "id": "visit-04", "location": { "lat": 51.4934, "lng": -0.0098 }, "service": 900 }
],
"options": { "geometry": true }
}'

service is the time in seconds spent at each stop. The response has one entry in routes, with steps in visiting order:

{
"summary": { "routes": 1, "unassigned": 0, "duration": 4380, "distance": 22510, "service": 3600, "waiting_time": 0, "cost": 4380 },
"routes": [
{
"vehicle_id": "tech-1",
"duration": 4380,
"distance": 22510,
"service": 3600,
"waiting_time": 0,
"geometry": "...",
"steps": [
{ "type": "start", "location": { "lat": 51.5072, "lng": -0.1276 }, "arrival_offset": 0 },
{ "type": "job", "id": "visit-02", "location": { "lat": 51.4613, "lng": -0.1156 }, "arrival_offset": 780, "service": 600 }
]
}
],
"unassigned": [],
"request_id": "req_2b9d6f1e0c8a4e7f9a3b5c7d1e2f4a6b"
}

The example is abbreviated and the numbers are illustrative, not a benchmark. Read the steps array for the real order, and check unassigned before you dispatch anything.

Three checks before you ship

  1. Count vehicles, not intentions. If your business says “one tech, but she needs a second van when the first is full”, that is a VRP with two vehicles. Send both.
  2. Read unassigned. An empty list means every stop was placed. A non-empty list tells you why with a reason code: TIME_WINDOW, CAPACITY, SKILL, UNREACHABLE or OTHER.
  3. Use a stable id for each stop. Responses use the ids you sent, so keep them stable across re-runs. Your own database key works well.

For more on limits that move a problem from TSP to VRP, such as capacity and time windows, see the companion post on time windows and capacities. For cost, see the pricing explainer.

The main decision is simple. If the answer is one route, send one vehicle. If the answer is an assignment across vehicles, send all the vehicles and let the optimizer assign them.

Compare the cost on the pricing page, or join the waitlist.