CalcWorldHub
Free online calculator · no signup

Exact small traveling salesman tour calculator

Find a minimum-cost closed tour that starts at city one and visits every other city exactly once.

4,000 tools
Exact small traveling salesman tour calculator — Row-major travel cost matrix, Number of cities and calculation method
Exact small traveling salesman tour calculator: inputs and calculation method.

How to use this calculator

Find a minimum-cost closed tour that starts at city one and visits every other city exactly once.

  1. Enter Row-major travel cost matrix, Number of cities. Match the units shown beside each field and review the result together with the assumptions below.
  2. Read the worked example below to check the expected input format and result.
  3. Compare another scenario by changing one input at a time. Use Reset to return to the starting values.
Calculation guide

Exact small traveling salesman tour explained

This exact search anchors a closed tour at city 1, visits every other city once, and returns to the start. It minimizes the costs in the supplied matrix; the matrix may represent directed or symmetric travel, and larger city counts increase the search workload rapidly.

Minimum closed tour cost80cost units
Minimum closed tour cost: 80 cost units in the worked scenario.

Inputs, symbols, and units

a — Row-major travel cost matrix
Row-major travel cost matrix. Use comma-separated values in the stated order.
n — Number of cities
Number of cities. Enter a whole number.

Formula and method

Held–Karp subset dynamic programming

A state records the cheapest path from city one through a visited subset to a final city. Extend it by each unvisited city and finally add the return edge. Backtracking the subset predecessors yields one optimal closed tour.

A worked scenario

Row-major travel cost matrix = 0, 10, 15, 20, 10, 0, 35, 25, 15, 35, 0, 30, 20, 25, 30, 0; Number of cities = 4.

  • Minimum closed tour cost: 80 cost units
  • City tour: 1 → 3 → 4 → 2 → 1

One optimal tour is 1→2→4→3→1. Its costs add to 10+25+30+15=80; reversing that tour ties because this example matrix is symmetric.

Assumptions and edge cases

Complete finite nonnegative cost matrix; asymmetric travel is allowed. Limited to 12 cities for browser computation.

Frequently asked questions

Does the route return to its start?

Yes.

Can forward and reverse costs differ?

Yes.

Is this a large-route optimizer?

No, the exact subset algorithm grows exponentially.

How do I use the Exact small traveling salesman tour calculator?

Enter Row-major travel cost matrix, Number of cities. Match the units shown beside each field and review the result together with the assumptions below.

What is a worked example of Exact small traveling salesman tour?

Row-major travel cost matrix = 0, 10, 15, 20, 10, 0, 35, 25, 15, 35, 0, 30, 20, 25, 30, 0; Number of cities = 4. Minimum closed tour cost: 80 cost units City tour: 1 → 3 → 4 → 2 → 1 One optimal tour is 1→2→4→3→1. Its costs add to 10+25+30+15=80; reversing that tour ties because this example matrix is symmetric.