Traveling Salesperson Calculator & Route Optimizer
Enter two to ten stops and their directional leg costs. Compare a fixed-start open route with a tour that returns to the same start, trace the exact optimal leg costs and check an optional baseline sequence.
Visit every stop at minimum cost
Compare the least-cost open route and return tour for your directed leg costs.
Edit stops, leg costs and baseline
List one stop per line. Each matrix row starts at that stop and lists costs to each column stop, in the same order. Use a dash for a connection you cannot take.
Open route
65 min
A → B → D → C
1 optimal order
Baseline 75 min · 10 min saved
Return tour
80 min
A → B → D → C → A
2 optimal orders
Baseline 95 min · 15 min saved
Trace the optimum stop order
The diagram shows direction and stop order. Distances come from the matrix.
- A Depot · start
- B Library
- C Workshop
- D Market
Legs and cumulative cost
Review and export the exact route ledger
The ledger includes both optimized routes, exact leg costs, your directed matrix and baseline comparisons.
Costs come from your matrix. Time windows, live routing and visits by multiple vehicles require separate planning.
How to use this calculator
- List the stops in matrix order and enter their directed leg costs row by row.
- Choose the start and cost unit. Put a dash on any leg that cannot be used.
- Optionally enter your current stop order using the displayed letters.
- Compare open and return routes, tied optima and any baseline savings.
- Switch the diagram and select a leg to inspect cumulative cost. Export the exact audit with both routes.
The Formula
The mathematical logic powering this calculation is:
Use a square directed cost matrix. Rows are origins and columns are destinations. Put zero or a dash on the diagonal. A dash elsewhere means the leg is unavailable. A cost can measure time, distance or another consistent objective. One route visits every stop once from the selected start. An open route can end at any remaining stop. A closed tour adds a final leg to the start.
Use the Bellman–Held–Karp subset recurrence. For each visited set S containing the start and endpoint j in S, store the smallest possible cost of ending at j after visiting exactly S. Initialize the start-only state with cost zero. To add j, consider every reachable preceding endpoint i and add its cost for S without j to the entered leg cost from i to j. Keep the smallest total. This works because a cheaper prefix with the same visited set and final stop can replace a costlier prefix before taking the same subsequent legs.
For the open result, take the lowest full-set endpoint cost. For the return tour, first add the available endpoint-to-start leg, then minimize. For tied states and endpoints, add the exact number of tied stop orders and display the first in letter order. With a fixed start, a reversed visit order counts separately when it is also optimal. The optional baseline must contain every stop letter exactly once and begin at the chosen start. A return leg is added automatically for its tour.
Accept two to ten distinct names up to 24 characters each. Costs support 0–1,000,000 with up to six decimal places. Separate matrix cells with commas, tabs or spaces. Matrix arithmetic, comparisons, savings and CSV values are exact. The unit selector labels the supplied costs and keeps their values.
The visual uses a schematic circle for stop position. Its straight or curved arrows show order. The matrix supplies all distances and times. The result compares one fixed-start visit over explicitly available legs. Scheduling constraints, repeated stops, intermediate travel paths, live maps and multiple vehicles need separate modeling.Worked Example
If you input:
- Stops: Depot, Library, Workshop and Market
- Start: Depot
- Baseline: A → B → C → D
Result:
Relative to the baseline, the optimal open route costs 65 minutes and saves 10. The minimum return tour costs 80 minutes and saves 15. Two return-tour orders tie.
Frequently Asked Questions
Can outward and return costs differ?
Yes. Enter each directed leg independently. The solver examines only permitted directions and uses each entered cost.
Can I require the route to return to its starting point?
Choose the return tour to include that final leg. The open result is shown beside it for comparison.
Why can a route visit every stop but fail to return?
A path may reach all stops and end at a stop with no usable connection back to the start. Some one-way networks have a feasible open path and no closed tour.
What happens when several routes cost the same?
The optimizer counts all tied orders for the selected start. It shows the first of those orders by the displayed stop letters.
Can I enter decimal costs?
Yes. Each number can have up to six fractional places. The selected route uses the exact sum and tie comparisons.
Why are no distances taken from the diagram?
The diagram is a schematic stop-order view. Use measured or estimated leg costs from your own source in the matrix.
Similar Calculators
Linear Programming Calculator
Maximize or minimize a linear objective with variable bounds and constraints. Inspect simplex steps, exact certificates and equally good plans.
Critical Path Calculator
Plan finish-to-start dependencies, find critical chains and compare a changed activity duration. Explore Gantt timing, waiting lags and shared float.
Matrix Calculator
Multiply, add, subtract and transpose matrices, or find a determinant and inverse. Get exact fractions, cell explanations and CSV for matrices up to 4 × 4.
Commute Time & On-Time Arrival Calculator
Compare two commute logs by observed on-time share, target travel budget and leave-by time. See how slow trips change the comparison.
