Inferensys

Glossary

Traveling Salesman Problem (TSP)

The Traveling Salesman Problem (TSP) is a foundational NP-hard combinatorial optimization problem that seeks the shortest possible route visiting a set of locations exactly once and returning to the origin.
Finance analyst reviewing cash flow AI optimization on laptop, charts and projections visible, home office work session.
COMBINATORIAL OPTIMIZATION

What is the Traveling Salesman Problem (TSP)?

The Traveling Salesman Problem is a foundational challenge in operations research and computer science, central to spatial-temporal scheduling and route optimization for logistics, manufacturing, and autonomous systems.

The Traveling Salesman Problem (TSP) is a canonical NP-hard combinatorial optimization problem that asks: given a list of locations and the pairwise distances between them, what is the shortest possible route that visits each location exactly once and returns to the starting point? It is the quintessential problem for optimizing a single agent's tour, forming the theoretical core for more complex variants like the Vehicle Routing Problem (VRP). Its computational intractability for large instances makes it a benchmark for heuristic and metaheuristic algorithms like Genetic Algorithms and Simulated Annealing.

In practical heterogeneous fleet orchestration, the TSP provides the foundational logic for sequencing tasks assigned to a single autonomous mobile robot or vehicle. Real-world deployments must extend the classic TSP to handle dynamic constraints like time windows, real-time traffic, and charging stops, often solved via online scheduling and Model Predictive Control (MPC). While exact solutions via Mixed-Integer Programming (MIP) are limited to small scales, high-quality approximations are critical for minimizing makespan and operational costs in automated warehouses and logistics networks.

COMBINATORIAL OPTIMIZATION

Key Variants of the Traveling Salesman Problem

The classic TSP has spawned numerous specialized variants to model real-world constraints in logistics, manufacturing, and spatial-temporal scheduling. These formulations introduce complexities like multiple vehicles, time windows, and capacity limits.

01

Metric TSP

The Metric TSP imposes the triangle inequality on distances: the direct path between two cities is never longer than any indirect route via a third city. This property, which holds in Euclidean space and road networks, enables the use of efficient approximation algorithms like Christofides' algorithm, which guarantees a solution within 1.5 times the optimal length. It is the most studied and computationally tractable variant, forming the basis for more complex problems.

02

Asymmetric TSP (ATSP)

In the Asymmetric TSP (ATSP), the distance from city A to city B is not necessarily equal to the distance from B to A. This models real-world scenarios like one-way streets, airline routes with differing headwinds, or delivery routes with different loading/unloading times. The ATSP is significantly harder to approximate than its symmetric counterpart. Common solution approaches include transforming it into a symmetric problem with twice the nodes or using specialized integer programming formulations.

03

Multiple Traveling Salesmen Problem (mTSP)

The Multiple Traveling Salesmen Problem (mTSP) extends the classic problem by employing multiple salesmen (or vehicles) to service all cities. Key constraints include:

  • Fleet size: A fixed or variable number of vehicles.
  • Depot configuration: One central depot or multiple depots.
  • Objective: Minimize total distance, longest route (min-max), or balanced workload. This is a direct generalization to the Vehicle Routing Problem (VRP), where additional constraints like vehicle capacity are added.
04

Traveling Salesman Problem with Time Windows (TSPTW)

The Traveling Salesman Problem with Time Windows (TSPTW) adds a critical temporal dimension: each city (or customer) must be visited within a specified time interval [e_i, l_i]. Arriving early results in idle waiting time; arriving late is infeasible. This variant is fundamental to just-in-time logistics, home delivery services, and technician dispatch. Solving TSPTW requires algorithms that handle both sequencing and scheduling, often using dynamic programming or sophisticated constraint programming models.

05

Capacitated TSP (CTSP)

The Capacitated TSP (CTSP) introduces a load constraint. The salesman has a vehicle with a finite capacity Q. Each city has a demand d_i (positive for delivery, negative for pickup), and the total load carried along the route must never exceed Q. This variant bridges the gap between the pure TSP and the Capacitated Vehicle Routing Problem (CVRP). Solutions often involve constructing routes that respect capacity, making it a fundamental model for last-mile delivery and inventory routing.

06

Profitable TSP (PTSP) / Prize-Collecting TSP

The Profitable TSP (PTSP) or Prize-Collecting TSP relaxes the requirement to visit all cities. Each city offers a prize (or profit) p_i, but visiting it may incur a cost (distance). The objective is to find a tour that maximizes the total collected prize minus the travel cost, potentially within a time or distance budget. This models scenarios like field service routing where not all tasks can be completed, or tourist itinerary planning where attractions are selected based on interest and proximity.

COMPUTATIONAL COMPLEXITY

Why is TSP So Difficult to Solve?

The Traveling Salesman Problem's notorious difficulty stems from its combinatorial explosion and its classification as an NP-hard problem, making optimal solutions computationally intractable for large-scale instances.

The Traveling Salesman Problem (TSP) is NP-hard, meaning no known algorithm can find the provably shortest route for n cities in polynomial time. The number of possible tours grows factorially ((n-1)!/2), leading to a combinatorial explosion. For just 20 cities, there are over 60 quadrillion possible routes, making exhaustive search impossible for real-world logistics and spatial-temporal scheduling problems.

Exact algorithms like branch and bound can solve small instances, but scale poorly. Therefore, practitioners rely on heuristic and metaheuristic algorithms (e.g., Genetic Algorithms, Simulated Annealing) to find high-quality, feasible solutions quickly. This intrinsic complexity makes TSP a fundamental benchmark in combinatorial optimization and a core challenge in heterogeneous fleet orchestration.

COMPUTATIONAL STRATEGIES

Primary Solution Approaches for TSP

Given the NP-hard nature of the Traveling Salesman Problem, a spectrum of solution methods exists, ranging from exact algorithms for small instances to highly scalable heuristics and metaheuristics for real-world applications.

02

Construction Heuristics

Construction heuristics build a tour from scratch by making a series of locally optimal decisions. They are extremely fast (O(n²) or better) but often produce solutions 10-25% above optimal.

  • Nearest Neighbor: Starts at a random city, repeatedly visits the closest unvisited city, and finally returns to the start. Prone to getting trapped in poor local structures.
  • Greedy (Multi-Fragment): Sorts all edges by length and iteratively adds the shortest edge that does not create a vertex of degree 3 or a premature cycle.
  • Insertion Heuristics (e.g., Nearest, Farthest, Cheapest): Start with a subtour and repeatedly insert the remaining city that minimizes the increase in tour length according to a chosen criterion.
  • Christofides Algorithm: A classic approximation algorithm for metric TSP that guarantees a solution within 1.5 times the optimal length. It builds a Minimum Spanning Tree (MST), adds a minimum-weight perfect matching on its odd-degree vertices, and forms an Eulerian circuit.
03

Improvement Heuristics (Local Search)

These algorithms start with a feasible tour (often from a construction heuristic) and iteratively improve it by exploring neighborhoods—sets of tours reachable by a defined operation.

  • k-opt Moves: The most famous local search for TSP. A 2-opt move removes two edges and reconnects the paths to form a new, shorter tour. The Lin-Kernighan heuristic is a variable-depth, highly effective k-opt variant that is a standard benchmark.
  • 3-opt / 4-opt: Remove three or four edges and reconnect the segments in all possible ways, exploring a larger neighborhood for better improvements at higher computational cost.
  • Or-opt: Relocates a chain of 1-3 consecutive cities to a different position in the tour.
  • The search continues until a local optimum is reached, where no move in the defined neighborhood yields an improvement.
04

Metaheuristics

Metaheuristics are high-level strategies designed to guide underlying heuristics to escape local optima and explore the solution space more thoroughly. They do not guarantee optimality but often find near-optimal solutions for very large-scale problems.

  • Simulated Annealing (SA): Inspired by thermodynamics. It occasionally accepts worse solutions with a probability that decreases over time ("cooling"), allowing the search to escape poor local optima.
  • Genetic Algorithms (GA): A population-based approach. Tours ("chromosomes") are combined ("crossover") and randomly altered ("mutation") over generations, with selection pressure favoring shorter tours.
  • Ant Colony Optimization (ACO): Inspired by ant foraging. Artificial "ants" probabilistically construct tours based on "pheromone" trails, which are reinforced on shorter edges, leading to emergent, self-reinforcing good paths.
  • Tabu Search: Enhances local search by maintaining a short-term memory ("tabu list") of recently visited solutions to avoid cycling and encourage exploration of new regions.
05

Specialized & Modern Approaches

Recent advances leverage new computational paradigms and problem structures for specific TSP variants.

  • Concorde TSP Solver: The de facto exact solver for large-scale symmetric TSP, using advanced branch-and-cut and linear programming techniques. It has solved an 85,900-city instance to optimality.
  • Reinforcement Learning (RL): Models TSP as a sequential decision-making process. Attention-based models (e.g., Transformer architectures) are trained via policy gradient methods to construct tours, learning heuristics that generalize across problem sizes.
  • Dynamic Programming on Subsets (DPS): While Held-Karp is the classic example, modern implementations use bitmask tricks and memory optimization to push the feasible limit for exact solutions.
  • Decomposition & Cluster-First, Route-Second: For massive instances, cities are clustered geographically, the TSP is solved within each cluster, and then the clusters are connected. This is common in Vehicle Routing Problem (VRP) solvers.
85,900
Cities Solved to Optimality (Concorde)
TRAVELING SALESMAN PROBLEM

Frequently Asked Questions

The Traveling Salesman Problem (TSP) is a cornerstone of combinatorial optimization and spatial-temporal scheduling. These questions address its definition, computational complexity, practical applications, and solution strategies.

The Traveling Salesman Problem (TSP) is a foundational combinatorial optimization problem that asks: 'Given a list of cities and the distances between each pair, what is the shortest possible route that visits each city exactly once and returns to the origin city?' It is the canonical problem for studying route optimization and sequence planning.

Formally, it is defined on a complete graph where vertices represent locations and edges have associated costs (distance, time, or money). The goal is to find a Hamiltonian cycle—a cycle that visits every vertex exactly once—with the minimum total cost. Its simplicity in statement belies its extreme computational difficulty, making it a benchmark for optimization algorithms. The TSP is a pure routing problem without constraints like capacities or time windows, which are added in extensions like the Vehicle Routing Problem (VRP).

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.