EZRoutePlanner

Free tool · no sign-up

Traveling salesman problem solver

Drop points, press Solve, and watch a short round trip through all of them take shape: first the nearest-neighbour guess, then 2-opt untangling it one swap at a time.

Runs in your browser. Nothing you paste is uploaded or stored.

Updated

S12345678910111213

In the order the points were added. Press Solve.

14 pointsUnsolved

In short

The traveling salesman problem asks for the shortest route that visits every point once and returns to the start. Checking every order is impossible beyond a handful of stops: 15 stops have over 43 billion distinct round trips. Practical solvers build a good route fast and improve it. This one uses nearest neighbour, then 2-opt swaps that uncross legs until no single swap helps.

Possible round trips
(n − 1)! ÷ 2: 43.6 billion for 15 stops
Step 1
Nearest neighbour: go to the closest unvisited point
Step 2
2-opt: reverse a stretch when it makes the loop shorter
Result
A short route, not a proven optimum

How to use the solver

  1. 01

    Add points

    Click the canvas to drop points, or press Random points. The first point (S) is the start.

  2. 02

    Solve

    Nearest neighbour builds a first route, then 2-opt swaps shorten it step by step.

  3. 03

    Compare

    The badge shows how much shorter the result is than the order the points were added.

  4. 04

    Try a one-way trip

    Turn off Round trip to find a short path that doesn't return to the start.

Why is the traveling salesman problem hard?

Because the number of possible orders explodes. With a fixed start, n stops can be visited in (n − 1)! orders, and a round trip and its reverse are the same length, so there are (n − 1)! ÷ 2 distinct loops.

StopsDistinct round trips
512
82,520
10181,440
1543,589,145,600
20about 60 quadrillion
30about 4 × 10³⁰
Even at a billion routes a second, checking every round trip through 20 stops would take about two years.

Mathematically it's NP-hard: no one knows a method that's guaranteed to find the best route quickly for every case. Real route planners therefore use heuristics: fast methods that find very good routes, usually within a few percent of the best possible.

Nearest neighbour and 2-opt, in plain words

  1. 1

    Nearest neighbour

    Start at the base and always drive to the closest stop you haven't visited. It's fast and usually decent, but it paints itself into corners: the last few stops are often far apart, and the route crosses itself.

  2. 2

    2-opt

    Take any two legs of the route. If reversing the stretch between them makes the trip shorter, which is exactly what happens when two legs cross, do it. Repeat until no swap helps. The result has no crossings.

EZRoutePlanner's Optimize Route works the same way, nearest neighbour followed by 2-opt improvement, with your start kept in place and the end either back at the start or pinned to a last stop. Then it draws the route on real roads and measures every leg. Read how route optimization works.

From points on a canvas to stops on a map

Real routes add roads. Two stops that look close can be on opposite sides of a river or a highway. A route planner looks each address up, orders the stops, then follows the road network for the actual driving distance and time. The bigger the list, the bigger the gap between the order a list happens to be in and a good one.

© Mapbox © OpenStreetMap
In the order listed33 mi · 1 hr 38 min
© Mapbox © OpenStreetMap
Optimized15 mi · 49 min−55%
One of EZRoutePlanner's example routes on real roads: the same stops in the order they were listed, and optimized.

Frequently asked questions

What is the traveling salesman problem?

It's the problem of finding the shortest route that visits each of a set of locations exactly once and returns to the start. It's the core of route optimization for deliveries, service calls and sales visits.

Can the traveling salesman problem be solved exactly?

Small cases, yes: specialised solvers prove the optimum for thousands of points with heavy computation. Everyday route planners use heuristics like nearest neighbour and 2-opt because they're fast and land very close to the optimum.

What's the difference between TSP and VRP?

The traveling salesman problem has one vehicle. The vehicle routing problem (VRP) has several vehicles, and often adds capacities and time windows, so it also decides which stops go to which vehicle. See the glossary.

How do I solve it for my real addresses?

Paste the addresses into EZRoutePlanner and press Optimize Route. It runs the same kind of method on your real stops and draws the result on real roads.

Want the best order, not just a link?

EZRoutePlanner puts your stops in the shortest order with one click, keeps every address on a map, and sends the route to your phone. Free to start.

Free plan. No credit card. Works in any browser.

Traveling Salesman Problem Solver (Interactive, Free)