Skip to content
oslew
Get a free key

Learn

TSP vs VRP: which route optimisation problem do you have?

The travelling salesman problem (TSP) asks for the quickest order in which one vehicle can visit a set of stops. The vehicle routing problem (VRP) adds what real fleets have — several vehicles, and usually capacities, delivery time windows and shift lengths — so it must decide which vehicle serves each stop as well as the order. Both are computationally hard: small TSPs can be solved exactly, while practical VRPs are almost always solved by heuristics that find good plans rather than proven best ones.

Last reviewed

“Route optimisation” is used for two problems that differ in kind, not just in size. Buying or building the wrong one is a common and expensive mistake: a single-vehicle optimiser cannot plan a fleet, and a fleet planner is heavy machinery for a technician’s list of calls. This page sets out both, how each is solved, and how to tell which you have.

The travelling salesman problem

One vehicle, a set of stops, and the question of the order. The classic statement asks for the shortest tour that visits every stop once and returns to the start; in practice “shortest” usually means quickest, measured in travel time. Two variants matter for real work:

  • Round trip or open path. A van that returns to the depot needs a tour; a courier who ends the day at home needs a path with a fixed end, and one already on the road may need a path with a free start.
  • Symmetric or asymmetric. Textbook examples assume the trip from A to B takes as long as the trip back. On a real road network it rarely does — one-way streets, divided roads and turning restrictions see to that — so a road TSP is asymmetric, and a solver that assumes symmetry will quietly get it wrong.

The vehicle routing problem

Several vehicles, a set of stops, and two decisions at once: which vehicle serves each stop, and in what order each vehicle visits its share. The plain version has no constraints beyond the fleet, but real problems almost always carry some, and each has a name in the literature:

Variant What it adds
Capacitated (CVRP) Each vehicle carries a limited load; each stop has a demand
With time windows (VRPTW) Each stop must be served between an earliest and a latest time
Multi-depot Vehicles start from, and return to, different bases
Pickup and delivery Stops come in pairs, and the pickup must precede its drop-off on the same vehicle
Heterogeneous fleet Vehicles differ in capacity, cost or what they may carry
With shifts and breaks Drivers have working hours and statutory rests

The objective varies too: total driving time, total distance, the number of vehicles used, lateness against windows, or a weighted mix. Choosing it is a business decision before it is a mathematical one.

Side by side

Travelling salesman problem Vehicle routing problem
Vehicles One Several
Decisions The order Assignment and order
Typical constraints Where to start and end Capacities, time windows, shifts, depots, pairings
Exact solutions practical for Small sets, and much larger ones with specialised solvers Only small instances
Usual approach Construction then local improvement Construction, local search and metaheuristics
Input A travel-time matrix of the stops A matrix, plus every constraint

Why both are hard

Both problems are NP-hard: no known algorithm solves every instance quickly, and the number of candidate orders grows factorially with the number of stops. For the TSP, dynamic programming (the Held–Karp method) proves optimality for small sets, and branch-and-cut solvers have proved it for very large instances, given enough time. For the VRP, even modest instances with time windows are hard to solve to proven optimality, which is why production fleet planners rely on heuristics.

Exact and heuristic methods

Exact methods return a route with a proof that nothing is better. For a small set of stops the simplest exact method — try every order — is instant. Beyond that, exact methods rely on pruning so much of the search that the rest can be enumerated, and their running time becomes hard to predict.

Heuristics trade the proof for speed and predictability. They usually work in two stages:

  1. Construction builds a reasonable first answer: nearest neighbour (always go to the closest unvisited stop), savings methods that merge routes where combining them saves the most, or insertion methods that add stops where they cost least.
  2. Improvement changes the answer a little at a time and keeps any change that helps. 2-opt reverses a stretch of a route to remove a crossing; Or-opt moves a short run of stops elsewhere; VRP solvers add moves that shift or swap stops between vehicles.

Metaheuristics — simulated annealing, tabu search, guided local search, large neighbourhood search — sit on top of improvement moves and occasionally accept a worse answer to escape a local optimum. They are where most of the engineering in commercial and open-source VRP solvers goes.

A heuristic answer can be excellent. What it cannot be is certified: it is a local optimum, the best within reach of its moves.

The matrix underneath

Every method above consumes the same input: the travel time between every pair of places. A travel-time matrix is therefore the foundation of any route optimisation, and its quality caps the quality of the plan. A mathematically perfect order built on times that ignore congestion is still wrong at rush hour. Some VRP formulations use time-dependent travel times for exactly this reason; most practical systems add margins instead. Free-flow versus traffic-aware routing covers what those times do and do not include.

What oslew solves

oslew’s route optimisation API solves the travelling salesman problem on real road networks, asymmetric times included, for between 2 stops and 500 stops. It builds a matrix of the stops, tries every order when the set is small enough to do so exactly, and otherwise constructs a nearest-neighbour order and improves it with 2-opt and Or-opt until neither helps. It supports a round trip or an open path with a fixed or free start and end, and it reports the unimproved nearest-neighbour time beside the optimised one so you can see what the improvement bought.

What oslew deliberately does not

It does not solve the vehicle routing problem: no second vehicle, no capacities, no time windows, no shifts, no pickup-and-delivery pairs. That is a choice rather than a gap waiting to be papered over. A fleet planner is an application full of business rules — which customers accept a late delivery, which drivers hold which licences — and a location API that pretended to be one would do it badly. What oslew supplies instead is the input such a planner needs: a distance matrix of up to 500 points a side, answered in one request, and a single-vehicle optimiser for each route the planner produces. The last-mile delivery workflow shows the pieces fitted together.

Which problem do you have?

  • One driver, one list of stops, no promised times: a TSP. A single-vehicle optimiser is the whole answer.
  • One driver, but customers were promised time slots: a TSP with time windows, which is already beyond a plain TSP solver. Use a VRP solver with a fleet of one.
  • Several drivers, or loads that must fit: a VRP. Build a matrix, choose a solver that models your constraints, and treat its output as the plan.
  • Several drivers with fixed territories: often a TSP per territory, if the territories are stable and stops never move between them.

Bottom line

The TSP orders one vehicle’s stops; the VRP decides who goes where and then orders each route, under the constraints that make fleets hard. Both run on a travel-time matrix, both are hard enough that practical solvers use heuristics, and choosing between them is a question about your operation, not your algorithm. oslew solves the first and supplies the matrix for the second.

Questions

Is the travelling salesman problem a special case of the vehicle routing problem?

Yes. A VRP with one vehicle and no capacity, time-window or shift constraints reduces to a TSP over the depot and the stops. That is also why VRP solvers contain TSP routines: once stops are assigned to vehicles, putting each vehicle’s stops in order is a TSP of its own.

Why can’t a computer simply try every order of stops?

Because the number of orders grows factorially. With a handful of stops, trying them all takes no time; with a few dozen, there are more possible orders than any computer could list. Exact methods beyond small sizes prune the search cleverly, and practical systems improve a good starting order until no simple change helps.

Does a heuristic answer mean a poor route?

No. Local-improvement methods such as 2-opt and Or-opt usually finish close to the best order, and a deterministic one gives the same answer for the same input. What a heuristic gives up is proof: it can say that no single move in its repertoire improves the route, not that no better route exists.

Which of the two problems does oslew solve?

The travelling salesman problem, for one vehicle and up to 500 stops, as a round trip or an open path. It does not solve vehicle routing problems: there are no time windows, capacities or second vehicles. For a fleet, it supplies the travel-time matrix that a VRP solver takes as its input.

What does a vehicle routing solver need as input?

A travel-time matrix covering the depots and every stop, often a distance matrix too, and the constraints: how many vehicles and their capacities, each stop’s demand, time window and service time, and each driver’s shift and breaks. The plan can only be as good as the matrix, so times that ignore congestion need a margin at busy hours.

Browse every page →