Traveling Salesman Solver
Build a closed Euclidean tour through 3–50 coordinates using nearest neighbor plus deterministic 2-opt improvement.
Privacy: your files never leave your device. All processing happens locally in your browser.
How to use
- 1.Enter 3–50 locations as name, x, y, placing the desired start in the first row.
- 2.Build the approximate tour and compare the initial and improved distances.
- 3.Inspect the closed route and assumptions, then copy it only if straight-line Euclidean distance fits the task.
About Traveling Salesman Solver
Traveling Salesman Solver builds an approximate closed tour through named points on a two-dimensional coordinate plane. Enter one location per line as name, x, y. The first row is the fixed starting location. The result lists a route that visits every point once, returns to the start, and reports total straight-line distance. It also shows the nearest-neighbor starting distance and the number of 2-opt passes, making improvement visible rather than hiding the heuristic.
The traveling salesperson problem asks for a shortest closed route that visits all locations. Google OR-Tools explains the same routing objective and cautions that practical solvers can return non-optimal results because routing problems are computationally difficult. This page deliberately uses a bounded, inspectable heuristic instead of claiming an exact solution for arbitrary inputs.
Construction begins at the first input point. At each step, nearest neighbor selects the closest unvisited point using Euclidean distance, sqrt((x2−x1)²+(y2−y1)²). Exact distance ties keep original input order. After a complete tour exists, 2-opt examines two route edges. If reconnecting them by reversing the intervening segment strictly shortens the tour, the exchange is applied and scanning restarts. Passes continue until no improving exchange remains or the defensive limit is reached.
The returned tour is locally improved under those two-edge exchanges, but it is not guaranteed to be globally shortest. A different starting location or construction rule can lead to another local minimum. The solver fixes the first row as start so repeated runs are deterministic. Eight small geometric golden cases—triangles, squares, rectangles, collinear points, and a center point—verify exact perimeter distances, closure, one visit per location, and that 2-opt never makes the initial route longer.
Coordinates are abstract planar values. They can be meters on a local drawing, pixels in a layout, or unitless classroom coordinates if both axes use the same scale. They are not latitude and longitude. Applying Euclidean distance directly to degrees distorts real Earth distance, especially across large regions or the antimeridian. Convert geographic points to an appropriate local projection or use a routing service designed for geodesic distance.
The page also ignores roads, one-way streets, traffic, travel time, obstacles, appointments, vehicle capacity, and multiple drivers. A straight segment between two points is not a claim that a vehicle can travel that way. Real route planning needs an actual distance or time matrix and the relevant constraints. No external map API is called, so there is no paid request and no location data leaves the browser.
Inputs require 3 through 50 distinct coordinate pairs. Duplicate coordinates are rejected because two separately named points at exactly the same location make route display ambiguous. Names may not contain commas, coordinates must be finite and bounded, and the point limit keeps quadratic local search responsive. The copied result contains the full closed name sequence plus the calculated distance.
Use this tool to learn TSP heuristics, explore spatial ordering, plan an approximate inspection sequence on a local coordinate system, or create reproducible test fixtures. Compare several starting-point orders if solution quality matters. For dispatch, navigation, cost commitments, or safety-critical routing, use a validated solver with real network data and independently verify the route rather than treating this local approximation as operational authority.
Methodology & sources
Validate 3–50 unique bounded planar points, fix the first point as start, construct a stable nearest-neighbor closed tour, then repeatedly apply the first strictly improving 2-opt edge exchange. Sum Euclidean hypot distances including return to start; never claim global optimality.
Frequently asked questions
- Does this find the globally shortest route?
- No. Nearest Neighbor plus 2-opt is a deterministic heuristic and can stop at a local minimum.
- Can I enter latitude and longitude?
- Not directly for reliable geographic distance. The solver treats coordinates as a flat Euclidean plane.
- Does it follow roads or traffic?
- No. It uses straight-line coordinate distance and calls no map or routing API.
- Why is the first location special?
- It fixes the starting point and deterministic tie behavior; the tour returns to that location at the end.
Related tools
- GPS Coordinates ConverterConvert coordinates between decimal degrees and DMS.
- Minimum Spanning Tree SolverFind an exact minimum-weight tree connecting every named node with deterministic Kruskal selection and explicit disconnected-graph errors.
- Assignment Problem SolverFind the exact minimum-cost one-to-one pairing between equally sized worker and task sets with the deterministic Hungarian algorithm.
- 24 Game SolverFind exact ways to make 24 from four whole numbers using every number once and only the four basic operations.
- Absolute Value CalculatorInstantly find |x| — the absolute value of any number, free.
- Age CalculatorYour exact age in years, months, and days — updated live
Calculators guides
View all- Traveling Salesman Problem: A Best-Solution Route Builder
- How to Convert Date Format to Month in Excel
- Add Days to a Date: Worked Examples for Common Cases
- How to Transfer Cloud Storage Between Any Units
- How to Calculate Cylinder Volume in Liters
- How to Calculate Cylinder Surface Area: Worked Example
- Cut List Optimizer for PC: Plan Cuts in Your Browser
- How to Calculate Curtain Fabric Yardage
- How to Determine Cube Volume From One Edge
- How to Calculate the Cube Root of a Number by Hand
- How to Find Cone Volume with Slant Height
- Calculate Cone Surface Area With Just Radius and Height
- US, UK and EU Clothing Size Conversion Made Simple
- Chinese Gender Predictor Alternative for Fun Baby Guesses
- How to Calculate a Cat's Age in Months (Vet Chart)
- How to Calculate Calories in Food and Your Daily Needs
- Calculate Business Days in Power BI with NETWORKDAYS
- BHN Calculator: Turn Indent Diameter Into Hardness Number
- Calculate Bra Size With Bust and Underbust: The Method
- How to Calculate BMI with Height and Weight