A delivery truck leaving an industrial distribution center, with aligned pallets and a planned route in the background.

What vehicle routing and the traveling salesman problem are

Vehicle routing decides the order in which a vehicle visits a set of stops so that distance or time is as low as possible. When one vehicle must visit every stop and return to the start, it is the traveling salesman problem (TSP).

With several vehicles, load capacity and delivery time windows, the problem becomes the vehicle routing problem (VRP). It is daily work for anyone who ships finished goods, collects parts from suppliers or feeds the line with a milk run.

The TSP is hard because the number of routes explodes. With 5 customers there are 5! = 120 possible sequences; with 10 customers, 10! = 3,628,800. That is why practice relies on heuristics: simple rules that give a good route in seconds, without guaranteeing the best one.

Visual map of routing

The map summarizes this article's example: the route built by nearest neighbor and its 2-opt improvement.

ROUTE: NEAREST NEIGHBOR AND 2-OPT
Visual map 220: Vehicle Routing and Traveling Salesman: Nearest Neighbor, 2-opt. Click the map to see it full size.Download the map as PNG

Example data: a depot and 5 customers

Fictional example, only to illustrate the calculation. Depot D sits at the origin and each grid unit equals 1 km. Coordinates (x, y): D (0, 0), F (1, 3), A (2, 6), B (5, 1), C (6, 5) and E (9, 2).

d = √[(x₂ − x₁)² + (y₂ − y₁)²]

Example: from D to F, d = √(1² + 3²) = √10 = 3.16 km. The table lists every distance between the points, in km.

DFABCE
D–3.166.325.107.819.22
F3.16–3.164.475.398.06
A6.323.16–5.834.128.06
B5.104.475.83–4.124.12
C7.815.394.124.12–4.24
E9.228.068.064.124.24–

In real operations, replace straight-line distance with a road distance or travel-time matrix. The heuristics work the same way.

Advertisement

Nearest neighbor: building the route

This is the simplest heuristic. Start at the depot and, at each step, go to the closest customer not yet visited. When all are visited, return to the depot.

  1. From D, the closest is F (3.16 km), versus A (6.32), B (5.10), C (7.81) and E (9.22).
  2. From F, the closest is A (3.16 km).
  3. From A, the closest is C (4.12 km).
  4. From C, B (4.12 km) is shorter than E (4.24 km), so go to B.
  5. From B, only E remains (4.12 km).
  6. From E, return to D (9.22 km).
StepFromToDistance (km)
1DF3.16
2FA3.16
3AC4.12
4CB4.12
5BE4.12
6ED9.22
Total27.91

The route D–F–A–C–B–E–D adds up to 27.91 km. Note the typical flaw of the method: in the last steps only distant customers are left, and the E–D return of 9.22 km alone makes up a third of the route.

Advertisement

2-opt improvement: swapping two legs

2-opt starts from a finished route and tests replacing two legs (edges) with two others, reversing the segment between them. If the total drops, it keeps the swap and repeats until no swap helps.

gain = (edge 1 + edge 2) removed − (edge 3 + edge 4) added

In route D–F–A–C–B–E–D, remove C–B and E–D. Reconnect C to E and B to D, reversing the B–E segment. The sequence becomes D–F–A–C–E–B–D.

RouteSequenceEdges swappedTotal (km)
Before (nearest neighbor)D–F–A–C–B–E–DC–B (4.12) + E–D (9.22) = 13.3427.91
After (2-opt)D–F–A–C–E–B–DC–E (4.24) + B–D (5.10) = 9.3423.91

The gain is 13.34 − 9.34 = 4.00 km, a 14.3% reduction (from 27.91 to 23.91 km). After testing all remaining swaps, none improves the route further. I checked the result by listing all 120 sequences: 23.91 km is indeed the shortest distance for this example. 2-opt does not always reach the optimum, but it usually gets close.

From the traveling salesman to vehicle routing

The TSP assumes one vehicle with no load limit. Real plants and distribution networks add constraints:

A classic method to split customers into routes is the Clarke and Wright savings algorithm (1964), which merges routes when that reduces total distance. Larger problems or those with many constraints call for integer linear programming models or routing software.

Where routing fits in operations

Common mistakes and limitations

Frequently asked questions

What is the traveling salesman problem?

It is the problem of finding the shortest route that visits each point on a list once and returns to the starting point.

What is vehicle routing?

It is defining the routes of a fleet to serve customers, respecting capacity and time windows at minimum distance or time.

How does nearest neighbor work?

Start at the depot and, at each step, go to the closest unvisited customer until all are visited, then return to the start.

What is 2-opt?

It is an improvement that replaces two edges of the route with two others, reversing the segment between them, when this lowers total distance.

Does nearest neighbor give the best route?

Not guaranteed. In the example it gave 27.91 km and 2-opt reached 23.91 km, the minimum verified among the 120 sequences.

How many routes exist with 10 customers?

10! = 3,628,800 sequences from one depot, which is why heuristics are used instead of testing them all.

Advertisement

Sources

  1. APPLEGATE, D. L. et al. The Traveling Salesman Problem: A Computational Study. Princeton University Press, 2006.
  2. TOTH, P.; VIGO, D. (eds.). The Vehicle Routing Problem. SIAM, 2002.
  3. CROES, G. A. A method for solving traveling-salesman problems. Operations Research, v. 6, 1958.
  4. CLARKE, G.; WRIGHT, J. W. Scheduling of vehicles from a central depot to a number of delivery points. Operations Research, v. 12, 1964.
  5. BALLOU, R. H. Business Logistics/Supply Chain Management. Pearson.

Keep studying: trusted sources and links

Save this address: Manufatura Enxuta is your school for lean manufacturing. Come back whenever you need to study, with a complete article, a visual map and trusted sources. Follow one of the learning paths or check the A–Z glossary.

Want a quick reference guide for the factory floor?

Download the free Pocket Guide e-book with the Lean tools summarized on one page each.

Download the e-book
Photo of Vagner Soares

About the author

Vagner Soares

Lean Manufacturing & Behavioral Management Specialist

Over 20 years in the automotive and metalworking industries (GM and Dana), Lean Manufacturing practitioner since 2006. SENAI instructor and mentor in Brazil’s Brasil Mais Produtivo program, delivering consulting, training and audits for 50+ companies, combining quality, productivity and people development.