Skip to content

🗺️ Visualize and control algorithms for the traveling salesman problem


Notifications You must be signed in to change notification settings


Repository files navigation

Netlify Status code style: prettier Live Demo Contributors GitHub

Traveling Salesman Problem

The traveling salesman problem (TSP) asks the question, "Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city and returns to the origin city?".

This project

  • Live at
  • The goal of this site is to be an educational resource to help visualize, learn, and develop different algorithms for the traveling salesman problem in a way that's easily accessible
  • As you apply different algorithms, the current best path is saved and used as input to whatever you run next. The order in which you apply different algorithms to the problem is sometimes referred to the meta-heuristic strategy.
  • For example, apply nearest neighbor, then 2-opt inversion, then branch and bound

Heuristic algorithms

Heuristic algorithms attempt to find a good approximation of the optimal path within a more reasonable amount of time.

Construction - Build a path

  • Nearest Neighbor
  • Arbitrary Insertion
  • Furthest Insertion
  • Nearest Insertion
  • Convex Hull Insertion*
  • Simulated Annealing*

Improvement - Attempt to take an existing constructed path and improve on it

  • 2-Opt Reciprocal Exchange
  • 2-Opt Inversion*

Exhaustive algorithms

Exhaustive algorithms will always find the best possible solution by evaluating every possible path. These algorithms are typically significantly more expensive then the heuristic algorithms discussed above. The exhaustive algorithms implemented so far include:

  • Random Paths
  • Depth First Search (Brute Force)
  • Branch and Bound (Cost)
  • Branch and Bound (Cost, Intersections)*


These are the main tools used to build this site:


Pull requests are always welcome! Also, feel free to raise any ideas, suggestions, or bugs as an issue.