Simulated Annealing TSP
Simulated annealing attacks the travelling salesman problem by proposing random 2-opt moves — reversing a segment of the tour — and accepting each one with the Metropolis rule: improvements always, worsenings with probability exp(−Δ/T) that shrinks as the temperature T cools geometrically. Click cities onto the canvas or generate random, circle, clustered or grid layouts, set the initial temperature and cooling rate, and run thousands of proposals per second while the blue current tour writhes and the orange best-so-far tour settles. Charts track tour length and temperature, the status line reports how often worse moves are still being accepted, and a nearest-neighbour baseline and a Reheat button let you compare and escape local minima.
Runs 100% in your browser — models are trained and computed locally on your device.
Read the full guide to this tool
Notes
- The Metropolis criterion accepts a worsening move of size Δ with probability exp(−Δ/T); at high T the search is nearly random, at T → 0 it becomes pure hill climbing.
- A 2-opt move removes two edges and reconnects the tour reversed in between; its cost change is computed from just four edge lengths in O(1), which is what makes thousands of proposals per frame cheap.
- Convergence to the global optimum is only guaranteed for impractically slow logarithmic cooling; the geometric schedule used here is a heuristic, so reheating can rescue a run that froze too early.
- The circle preset has a known optimum — the cities in hull order — handy for checking how close the annealer gets.
- Runs 100% in your browser — models are trained and computed locally on your device.