Travelling Salesman with multiple salesmen?
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
The Travelling Salesman Problem (TSP) is a classic problem in optimization and logistics. The objective is to find the shortest possible route for a salesman to visit a set of cities exactly once and return to the starting city. A practical variant is the Multiple Travelling Salesmen Problem (mTSP), which involves more than one salesman. This variant adds complexity and real-world applicability, especially in fleet routing, delivery logistics, and operations research.
Problem Definition
Classic TSP
The classic TSP can be represented using a graph where:
- Nodes (cities): The locations that need to be visited.
- Edges (paths): The connections between cities, each with an associated cost or distance.
The goal is to find a Hamiltonian cycle (a loop visiting each node exactly once) with the minimum total cost. Given cities, there are possible tours for an undirected graph, making brute-force infeasible for even moderate .
Multiple Travelling Salesmen Problem (mTSP)
The mTSP introduces salesmen into the scenario:
- Each salesman starts and ends at a common depot.
- The set of cities is partitioned among the salesmen so that each city is visited exactly once by exactly one salesman.
- The objective is to minimize the total cost across all salesmen's routes.
Mathematical Formulation
Classic TSP
Given cities and a cost matrix where is the travel cost from city to city , the objective is:
Subject to:
- for all (leave each city exactly once)
- for all (enter each city exactly once)
- Sub-tour elimination constraints (e.g., Miller-Tucker-Zemlin or Dantzig-Fulkerson-Johnson)
mTSP Formulation
For salesmen servicing cities, introduce a superscript for each salesman:
Subject to:
- Each city visited exactly once: for all
- Each salesman departs from and returns to the depot
- Sub-tour elimination constraints for each salesman
Additional constraints can bound the minimum and maximum number of cities per salesman to ensure balanced workloads.
Solution Approaches
Exact Methods
- Branch and Bound: Systematically explores the solution space by computing lower bounds and pruning branches that cannot improve on the best known solution. Guarantees optimality but has exponential worst-case time.
- Mixed Integer Linear Programming (MILP): Formulates the problem as a linear program with integer constraints. Solvers like Gurobi and CPLEX can handle instances with up to a few hundred cities.
Heuristics
- Nearest Neighbor: A greedy approach where each salesman always visits the closest unvisited city. Fast ( per salesman) but often produces suboptimal tours.
- Cluster-First, Route-Second: Partition cities into clusters (using k-means or geographic partitioning), then solve a single-salesman TSP within each cluster.
- Route-First, Cluster-Second: Solve one large TSP tour, then split it into segments.
Metaheuristics
- Genetic Algorithms (GA): Evolve a population of solutions through crossover and mutation. Good at exploring diverse solutions.
- Ant Colony Optimization (ACO): Simulates ants depositing pheromones on paths, reinforcing shorter routes over time.
- Simulated Annealing: Accepts worse solutions with decreasing probability, helping escape local optima.
- Tabu Search: Uses a memory structure to avoid revisiting recent solutions.
Example Scenario
Consider cities and salesmen with the following assignment:
| Salesman | Route | Cost |
| 1 | Depot - City 1 - City 2 - Depot | 15 |
| 2 | Depot - City 3 - City 4 - City 5 - Depot | 20 |
Total cost: 35. A different partition might yield a lower total, so the optimization lies in both the assignment of cities to salesmen and the ordering within each route.
Applications
- Logistics and Distribution: Optimizing multi-vehicle delivery routes to minimize fuel consumption and time.
- Field Service Scheduling: Deploying technicians to customer sites across a region.
- Manufacturing: Coordinating robotic arms or tool heads visiting multiple positions on an assembly line.
- Drone Delivery: Splitting delivery targets among multiple drones with limited battery life.
Challenges
- Scalability: The mTSP is NP-hard, inheriting the intractability of the classic TSP. The additional partitioning dimension makes it even harder.
- Dynamic Environments: Real-time changes in traffic, new orders, or vehicle breakdowns require adaptive re-optimization.
- Heterogeneous Fleets: Different vehicles may have different speeds, capacities, or operating costs, adding constraints to the formulation.
Summary
The Multiple Travelling Salesmen Problem extends the classic TSP by partitioning cities among multiple agents. The mathematical formulation adds assignment variables for each salesman, and solution methods range from exact MILP solvers (for small instances) to metaheuristics like genetic algorithms and ant colony optimization (for large-scale problems). The choice of method depends on problem size, solution quality requirements, and available computation time.
Related reading
- Travelling Salesman with multiple salesmen with a limit on number of cities per salesman?
- Travelling salesman with repeat nodes dynamic weights
- Tricks for improving iPhone UITableView scrolling performance?
- Tricks to make an AWS spot instance persistent?
- Traversal of an n-dimensional space
- Traverse Matrix in Diagonal strips
- trim all strings in an array
- Try-catch speeding up my code?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.