Metrobi logo

Learning center series

Travelling salesman problem explained

  • Published on April 26, 2024
  • by Oguzhan Uyar
  • Last updated: 2 months ago

Travelling Salesman Problem

Revolutionize your understanding of the Travelling Salesman Problem (TSP); a mind-boggling conundrum that has compelled academia and industry alike. In the upcoming lines, we decode the key concepts, algorithms, and anticipated solutions for 2024 to this age-old dilemma.

Now, picture the TSP as a globetrotting traveling salesman who’s whirlwind journey. He must stop at every city once, only the origin city once, and find the quickest shortest possible route back home. If daunting to visualize, consider this: the possible number of routes in the problem concerning just 20 cities exceeds the number of atoms in the observable universe.

Fathom the sheer magnitude?

So, what is the Travelling Salesman Problem, and why has it remained unsolved for years? Let’s snap together the puzzle of this notorious problem that spans mathematics, computer science, and beyond. Welcome to an insightful voyage into the astonishing world of the TSP. Delve deeper into how optimizing travel routes can transform the efficiency of solving the Travelling Salesman Problem, marking a milestone in the journey toward more effective logistics and navigational strategies.

Understanding the Travelling Salesman Problem (TSP): Key Concepts and Algorithms

Defining the travelling salesman problem: a comprehensive overview.

The Travelling Salesman Problem, often abbreviated as TSP, has a strong footing in the realm of computer science. To the untrained eye, it presents itself as a puzzle: a salesperson or traveling salesman must traverse through a number of specific cities before an ending point and return to their ending point as of origin, managing to do so in the shortest possible distance. But this problem is not simply a conundrum for those fond of riddles; it holds immense significance in the broad field of computer science and optimization. Optimizing travel routes is the key to solving the Travelling Salesman Problem efficiently, ensuring the shortest and most cost-effective journey for salespeople or travelers.

The sheer computational complexity of TSP is what sets it apart, and incidentally, why it is considered a challenging problem to solve. Its complexity derives from the factorial nature of the problem: whenever a new city is added, the total number of possibilities increases exponentially. Thus, as the problem scope enlarges, it swiftly becomes computationally prohibitive to simply calculate all possible solutions to identify an optimal shortest route through. Consequently, developing effective and efficient algorithms to solve the TSP has become a priority in the world of computational complexity.

Polynomial Time Solution: The TSP can be solved by a deterministic Turing machine in polynomial time, which means that the number of steps to solve the problem can be at most 1.5 times the optimal global solution.

One such algorithm is the dynamic programming approach that can solve TSP problems in polynomial time. The approach uses a recursive formula to compute the shortest possible route that visits all other nodes in the cities exactly once and ends at all nodes in the starting point or city. Moreover, linear programming and approximation algorithms have also been used to find near-optimal solutions. Discover how dynamic programming and other strategies serve as algorithms for optimizing routes , enhancing efficiency in plotting course paths.

Unraveling TSP Algorithms: From Brute Force to Heuristics

A multitude of algorithms have been developed to contend with the TSP. The brute force method, for example, entails considering the shortest distance for all possible permutations of cities, calculating the total distance for six cities along each route, and selecting the shortest distance for one. While brute force promises an optimal solution, it suffers from exponential computational complexity, rendering it unfeasible for large datasets.

TSP Complexity: A TSP with just 10 cities has 362,880 possible routes , making brute force infeasible for larger instances.

On the other hand, we have heuristic algorithms that generate good, albeit non-optimal, solutions in reasonable timeframes. The greedy algorithm, for instance, initiates from a starting city and looks for the shortest distance from other nodes to the next node minimizes the distance, and guarantees speed but is not necessarily an optimal solution.

Algorithmic Potential: Local Solutions 4/3 Times Optimal Global: The theoretical conjecture suggests an algorithm that can provide a local solution within 4/3 times the optimal global solution.
Record Local TSP Solution: The record for a local solution to the Traveling Salesman Problem (TSP) is 1.4 times the optimal global solution, achieved in September 2012 by Andr´as Seb˝o and Jens Vygen.

Exploring further, we encounter more refined heuristic solutions such as the genetic algorithm and simulated annealing algorithm. These algorithms deploy probabilistic rules, with the former incorporating principles of natural evolution and the latter being inspired by the cooling process in metallurgy. They differ significantly from each other in terms of how they search for solutions, but when compared to brute force, they often offer a promising trade-off between quality and computational effort.

Certainly, the TSP is far more than a problem to puzzle over during a Sunday afternoon tea. It’s a complex computational task with real-world implications, and unraveling it requires more than brute force; it demands the application of sophisticated algorithms designed to balance efficiency and quality of results. Nevertheless, with a better understanding of the problem statement and its dynamics, you can unlock the potential to not just solve problems faster, but to do so more intelligently.

Did You Know?

The average Metrobi driver rating is 4.97 / 5.00

Metrobi drivers are highly rated by local businesses for their professionalism and reliability, giving you peace of mind with every delivery.

Practical Solutions to the Travelling Salesman Problem

Implementing tsp solutions: a step-by-step guide, a comprehensive process for implementing tsp solutions.

Developing complete, practical solutions for the Travelling Salesman Problem (TSP) requires a good grasp of specific algorithms. Visual aids, for example, such as finding all the edges leading out of a given city, can help to simplify the process. Enhance your ability to solve the Travelling Salesman Problem by mastering route optimization with Google Maps , streamlining your path and saving significant time on the go.

TSP's Computer Science Quest for Shortest Routes: The TSP involves finding the shortest route to visit a set of cities exactly once before returning to the starting city, aiming to minimize travel distance.

Travelling Salesman Problem Explained - Travelling Salesman Problem -

One popular approach to TSP problem solving is the dynamic programming approach, which involves breaking down the problem into smaller sub-problems and recursively solving them. Other approaches include approximation algorithms, which generate near-optimal solutions to small problems in polynomial time, and bound algorithms, which aim to find an upper bound on the optimal solution given graph top. Discover how software for planning routes can revolutionize your approach to the TSP problem, offering near-optimal solutions that enhance efficiency and effectiveness in logistical planning.

TSP Variants: ASTP and STSP The TSP can be divided into two types: the asymmetric traveling salesman problem (ASTP) and the symmetric traveling salesman problem (STSP)

Practical code implementation

Before diving into code manipulations, it’s worth noting that practical implementation varies based on the specifics of the problem and the chosen algorithm. Let’s further deconstruct these notions by examining the steps for code implementation for a pre-determined shortest path first. It’s crucial to efficiently concede each point of the shortest path, call other nodes, connect each node, and conclude each route. Hereby, I shall delve into the practicalities of coding from an output standpoint, concentrating on readability, scalability, and execution efficiency. Uncover how optimizing routes can elevate your coding practices for more efficient, scalable, and readable solutions in logistics and transportation.

TSP Instance Size: The size of the TSP instances used in the studies is 100 nodes.
Cluster Quantity in TSP Instances: The number of clusters in the TSP instances used in the studies is 10 .
The Quantity of Instances per Cluster in Studies: The number of instances in each cluster used in the studies is 100.

Optimizing TSP Solutions: Tips and Tricks

Tsp solutions optimization techniques.

An optimized solution for the TSP is often accomplished using advanced algorithms and techniques. Optimization techniques allow professionals to solve more intricate problems, rendering them invaluable tools when handling large datasets and attempting to achieve the best possible solution. Several approaches can be taken, such as heuristic and metaheuristic approaches, that can provide near-optimal solutions with less use of resources. Discover the key to enhancing your logistics operations by mastering the art of optimizing delivery routes , thereby achieving efficiency and reducing costs significantly.

Expert Advice for Maximum Efficiency Minimum Cost

Even the most proficient problem solvers can gain from learning expert tips and tricks. These nuggets of wisdom often provide the breakthrough needed to turn a good solution into a great one. The TSP is no exception. Peering into the realm of experts can provide novel and creative ways to save time, increase computation speed, manage datasets, and achieve the most efficient shortest route around.

By comprehending and implementing these solutions to the Travelling Salesman Problem, one can unravel the complex web of nodes and paths. This equips any problem-solver with invaluable insights that make navigating through real-world TSP applications much more manageable. By adopting sophisticated routing planner software , businesses can significantly streamline their delivery operations, ensuring a more predictable and cost-effective way of dealing with the challenges presented by the Travelling Salesman Problem.

Real-World Applications of the Travelling Salesman Problem

Tsp in logistics and supply chain management.

The Travelling Salesman Problem (TSP) is not confined to theoretical mathematics or theoretical computer science either, it shines in real-world applications too. One of its most potent applications resides in the field of logistics and supply chain management. Explore how the latest gratis route planning applications can revolutionize logistics and supply chain efficiency by uncovering the top 10 free software tools for 2024.

With globalization, the importance of more efficient routes for logistics and supply chain operations has risen dramatically. Optimizing routes and decreasing costs hold the key to success in this arena. Here’s where TSP comes into play. Discover how Planning for Multiple Stops can revolutionize your logistics, ensuring the most efficient paths are taken. Dive into our post to see how it streamlines operations and reduces expenses.

In the vast complexity of supply chain networks, routing can be a colossal task. TSP algorithms bring clarity to the chaos, eliminating redundant paths and pointing to the optimal route covering the most distance, shortest path, and least distance between all the necessary points—leading to a drastic dip in transportation costs and delivery times. Uncover how optimizing delivery routes can revolutionize your logistics, ensuring efficiency and cost-effectiveness in your delivery operations.

Real-World Examples

Consider the case of UPS – the multinational package delivery company. They’ve reportedly saved hundreds of millions of dollars yearly by implementing route optimization algorithms originating from the Travelling Salesman Problem. The solution, named ORION, helped UPS reduce the distance driven by their drivers roughly by 100 million miles annually. Understand the intricacies of the problem of routing vehicles to appreciate how businesses like UPS can significantly benefit from efficient logistical strategies and route optimization systems.

TSP in GIS and Urban Planning: Optimal Route

TSP’s contributions to cities aren’t confined to logistics; it is invaluable in Geographic Information Systems (GIS) and urban planning as well. A city’s efficiency revolves around transportation. The better the transport networks and systems, the higher the city’s productivity. And as city authorities continuously strive to upgrade transportation systems, they find an ally in TSP. Discover how TSP enhances road architecture by integrating specialized truck routing solutions , elevating urban transport strategies.

Advanced GIS systems apply TSP to design more efficient routes and routing systems for public transportation. The aim of the route is to reach maximum locations with the least travel time and least distance, ensuring essential amenities are accessible to everyone in the city. Discover how dynamic routing optimization can enhance city-wide transportation efficiency and accessibility for all residents.

The city of Singapore, known for its efficient public transportation system, owes part of its success to similar routing algorithms. The Land Transport Authority uses TSP-related solutions to plan bus routes, reducing travel durations and enhancing accessibility across the city.

Delving Deeper: The Complexity and History of the Travelling Salesman Problem

Understanding the complexity of tsp.

TSP is fascinating not just for its inherent practicality but also for the complexity it brings along. TSP belongs to a class of problems known as NP-hard, a category that houses some of the most complex problems in computer science. But what makes TSP so gnarled?

Unravel the Intricacies: Why is TSP complex?

TSP is a combinatorial optimization problem, which simply means that it’s all about figuring out the most often optimal solution among a vast number of possible solutions or combinations of approximate solutions. The real challenge comes from an innocent-sounding feature of TSP: As the number of cities (we call them nodes) increases, the complexity heightens exponentially, not linearly. The number of possible routes takes a dramatic upward turn as you add more nodes, clearly exemplifying why TSP is no walk-in-the-park problem. Discover how leveraging multi-stop itinerary planning can transform this complex task, offering a streamlined solution to navigate through the myriad of possibilities efficiently.

NP-hard and TSP: A Connection Explored

In computer science, we use the terms P and NP for classifying problems. P stands for problems where a solution can be found in ‘polynomial time’. NP stands for ‘nondeterministic polynomial time’, which includes problems where a solution can be verified in polynomial time. The concept of ‘NP-hardness’ applies to TSP. Any problem that can be ‘reduced’ to an NP problem in polynomial time is described as NP-hard. In simpler terms, it’s harder than the hardest problems of NP. TSP holds a famed position in this class, making it a noteworthy example of an NP-hard problem. Discovering efficient solutions for the Traveling Salesman Problem (TSP) exemplifies how optimizing routes can streamline complex logistical challenges, showcasing the practical impact of advancements in algorithmic route optimization.

A Look Back: The History of the Travelling Salesman Problem

TSP is not a new kid on the block. Its roots can be traced back to the 1800s, and the journey since then has been nothing short of a compelling tale of mathematical and computational advancements.

The Origins and Evolution of TSP

Believe it or not, the Travelling Salesman Problem was first formulated as a mathematical problem in the 1800s. This was way before the advent of modern computers. Mathematicians and logisticians were intrigued by the problem and its implications. However, it wasn’t until the mid-20th century that the problem started to gain more widespread attention. Over the years, the TSP has transformed from a theoretical model to a practical problem that helps solve real-world issues.

A Classic Shortest Route Problem Since 1930s: The TSP is a classic optimization problem within the field of operations research, first studied during the 1930s.

Milestones in TSP Research

Looking at all the cities and milestones in TSP research, the story is truly impressive. From some of the initial heuristic algorithms to solve smaller instances of TSP, to geometric methods and then approximation algorithms, TSP research has seen a lot. More recently, we have also seen practical solutions to TSP using quantum computing — a testament to how far we’ve come. Each of these milestones signifies an innovative shift in how we understand and solve TSP. Discovering the top delivery route planning software in 2024, we navigated through the advancements in TSP solutions to identify which applications excel in streamlining delivery logistics.

Wrapping Up The Journey With Algorithms and Solutions

The Travelling Salesman Problem (TSP) remains a complex enigma of business logistics, yet, the advent of sophisticated algorithms and innovative solutions are paving avenues to optimize routing, reduce travel costs further, and enhance customer interactions.

Navigating the TSP intricacies is no longer a daunting challenge but a worthwhile investment in refining operational efficiency and delivering unparalleled customer experiences. With advanced toolsets and intelligent systems, businesses are closer to making more informed, strategic decisions. Elevate your logistical operations and customer satisfaction with the strategic integration of route scheduling solutions .

Now, it’s your turn. Reflect on your current logistics complexities. How can your business benefit from implementing these key concepts and algorithms? Consider where you could incorporate these practices to streamline and revolutionize your daily operations.

Remember, in the world of dynamic business operations, mastering the TSP is not just an option, but a strategic imperative. As you move forward into 2024, embrace the art of solving the TSP. Unravel the potential, decipher the complexities, and unlock new horizons for your business.

Ready for the challenge?

What is route optimization?

Top route optimization algorithms

What is multi-stop route planning and why is it important?

What is multi stop route planning and why is it important?

How to optimize routes with Google Maps

7 benefits of using route scheduling software

Benefits of using route scheduling software

Why delivery route optimization is crucial

What does a route planning software do?

Truck route planning vs common route planning

methods travelling salesman problem

‟Metrobi does exactly what I wanted my drivers to do”

LuNo Culinary

‟The quality of customer service is great!”

‟On-Time Pick-Up & Courteous Drivers”

‟My products are handled professionally and I have access to a reliable delivery solution”

Quinlan-Wasserman

methods travelling salesman problem

  • Route Optimization
  • travelling salesman problem

Travelling Salesman Problem

  • dynamic route optimization

Static vs dynamic route optimization

  • vehicle routing problem

What is vehicle routing problem (VRP)

  • free route planning software

free route planning software

  • truck route

Truck Route

  • route planning software

What does a route planning software do

  • Agricultural Productivity
  • agricultural productivity

increase agricultural productivity

  • Retail Emergency Actions
  • crisis management in retail

crisis management in retail

  • Restaurant Loss Prevention Tips
  • restaurant loss prevention

Restaurant loss prevention

  • Growing Your Team
  • employee perks for small businesses

The best employee perks for small businesses to offer

  • Agricultural Cooperatives
  • agricultural cooperatives

Agricultural cooperatives

  • Farm Marketing
  • online farm sales

How to boost your online farm sales

  • Types of Shipping Methods
  • International shipping

international shipping

  • Click and collect shipping

click and collect shipping

  • omnichannel logistics

omnichannel logistics

  • Last Mile Delivery Glossary
  • green transportation

Benefits of green transportation to your business

  • payload capacity

How to calculate your payload capacity

Success Stories

Benz’s Food Products Inc.

methods travelling salesman problem

Fleurs to You

methods travelling salesman problem

Field Trip Flowers

methods travelling salesman problem

Dorchester Brewing Company

methods travelling salesman problem

Smart Lunches

methods travelling salesman problem

DELIVER WITH METROBI

Grow with confidence

  • Atlanta courier service
  • Austin courier service
  • Boston courier service
  • Chicago courier service
  • Denver courier service
  • Miami courier service
  • New York City courier service
  • Los Angeles courier service
  • Philadelphia courier service
  • San Francisco courier service
  • Washington DC courier service
  • See all locations
  • Driver Network
  • Software Only

methods travelling salesman problem

  • 55 Court St, Boston, MA 02108
  • [email protected]
  • Team Metrobi
  • Privacy policy
  • Terms of service
  • Write for us NEW

Refer us to a company, you earn $250 and they earn $250. Learn more

methods travelling salesman problem

  • Delivery Management Software
  • Shopify Delivery Planner App
  • Metrobi Delivery API NEW
  • Zapiet: Pickup Delivery NEW
  • See all integrations
  • Metrobi vs. Onfleet
  • Metrobi vs. Roadie
  • Metrobi vs. Roadie Support
  • See all comparisons
  • Bulk Order Delivery Service
  • Express Urgent Delivery Service
  • Fixed Route Delivery Service
  • On Demand Delivery Service
  • Overnight Delivery Service
  • Same Day Delivery Service
  • Scheduled Delivery Service
  • Wholesale Delivery Service
  • See all delivery services
  • Artisan Food
  • Food Producers
  • See all industries

methods travelling salesman problem

Want to access our large pool of drivers?

We started Metrobi to take operations off your plate. We provide drivers (rated 4.97/5), dedicated operation managers (70% cheaper), and routing software with a receiver notification system.

NextBillion.ai

Key Products

  • Route Optimization API

Optimize routing, task allocation and dispatch

  • Directions and Distance Matrix API

Calculate accurate ETAs, distances and directions

  • Navigation API & SDKs

Provide turn-by-turn navigation instructions

  • Live Tracking API & SDKs

Track and manage assets in real time

  • All Products

Product Demos

See NextBillion.ai APIs & SDKs In action

  • Integrations

Easily integrate our products with your tools

Platform Overview

Learn about how Nextbillion.ai's platform is designed

Routing Customizations

Learn about NextBillion.ai's routing & map customizations capabilities

Supply Chain & Logistics

Get regulation-compliant truck routes

  • Fleet Management

Solve fleet tracking, routing and navigation

  • Last-Mile Delivery

Maximize fleet utilization with optimal routes

  • On-Demand Delivery

Real-time ETA calculation

  • Middle Mile Delivery

Real-time ETA Calculation

  • Ride Hailing

Optimized routes for cab services

  • Non-Emergency Medical Transport

Optimize routing and dispatch

Field Workforce

  • Field Services

Automate field service scheduling

  • Waste Collection

Efficient route planning with road restrictions

BY BUSINESS TYPE

Logistics technology providers

Fleet owners

BY LOGISTICS TYPE

Long haul trucking

Middle-mile logistics

Last-mile delivery

Urban mobility

Field services

Non-emergency transportation

See NextBillion.ai APIs & SDKs in Action

  • Case Studies

Discover what customers are building in real time with NextBillion.ai

Get in-depth and detailed insights

  • Product Updates

Latest product releases and enhancements

Navigate the spatial world with engaging and informative content

methods travelling salesman problem

NextBillion.ai vs. Google Route Optimization API

Experience a more powerful optimization and scheduling platform, better optimized routes, advanced integration capabilities and flexible pricing with NextBillion.ai.

  • API Documentation

Comprehensive API guides and references

Interactive API examples

Integrate tools you use to run your business

  • Technical Blogs

Deep-dive into the technical details

Get quick answers to common queries

FEATURED TECHNICAL BLOG

methods travelling salesman problem

How to Implement Route Optimization API using Python

Learn how to implement route optimization for vehicle fleet management using python in this comprehensive tutorial.

ROUTE OPTIMIZATION API

API Reference

DISTANCE MATRIX API

Navigation api & sdk.

Android SDK

Flutter SDK

Documentation

Integration

NEXTBILLION.AI

Partner with us

Our story, vision and mission

Meet our tribe

Latest scoop on product updates, partnerships and more

Come join us - see open positions

Reach out to us for any product- or media-related queries

For support queries, write to us at

To partner with us, contact us at

For all media-related queries, reach out to us at

For all career-related queries, reach out to us at

  • Request a Demo

Table of Contents

9 Best Algorithms for Traveling Salesman Problem Solutions

Rishabh singh.

  • March 15, 2024

In the field of combinatorial optimization, the Traveling Salesman Problem (TSP) is a well-known puzzle with applications ranging from manufacturing and circuit design to logistics and transportation. The goal of cost-effectiveness and efficiency has made it necessary for businesses and industries to identify the best TSP solutions. It’s not just an academic issue, either. Using route optimization algorithms to find more profitable routes for delivery companies also lowers greenhouse gas emissions since fewer miles are traveled.

What is the Traveling Salesman Problem?

The TSP has captivated mathematicians, computer scientists, and operations researchers for decades. At its core, the problem is deceptively simple: given a list of cities and the distances between each pair, find the shortest possible route that visits each city once and then returns to the origin city. Despite its simplicity, the TSP is notoriously difficult to solve, especially as the number of cities increases. 

In this technical blog, we’ll examine some top algorithms for Traveling Salesman Problem solutions and describe their advantages, disadvantages and practical uses.

Explore NextBillion.ai’s Route Optimization API , which uses advanced algorithms to solve TSP in real-world scenarios.

Popular Traveling Salesman Problem Solution Algorithms

The Traveling Salesman Problem (TSP) is one of the most studied problems in optimization and computer science. Unsurprisingly, this has led to the development of a variety of algorithms to solve the problem, each with its own applications. Some of the most popular ones include:

  • The Brute Force Algorithm

The Branch-and-Bound Method

The nearest neighbor method, ant colony optimization.

  • Genetic Algorithms

The Lin-Kernighan Heuristic

Chained lin-kernighan heuristic, the christofides algorithm, concorde tsp solver.

These algorithms represent a diverse toolkit of Traveling Salesman Problem solutions, each with its advantages and trade-offs. Understanding their mechanisms and applications can help select the right approach for specific instances and requirements, whether you seek exact solutions or efficient approximations. So, let’s take a closer look at these algorithms and how they work.

Brute Force Algorithm

The simplest method for solving the TSP is the brute force algorithm. It includes looking at every way the cities could be scheduled and figuring out how far away each approach is overall. Since it ensures that the best solution will be found, it is not useful for large-scale situations due to its time complexity, which increases equally with the number of cities.

This is a detailed explanation of how the TSP is solved by the brute force algorithm:

Create Every Permutation: Make every combination of the cities that is possible. There are a total of n! permutations to think about for n cities. Every combination shows a possible sequence where the salesman could visit the cities.

Determine the Total Distance for Every Combination: Add up the distances between each city in the permutation to find the overall distance traveled for each one. To finish the trip, consider the time from the final city to the starting point.

Determine the Best Option: Observe which permutation produces the smallest total distance and record it. This permutation represents the ideal tour. Return the most effective permutation to the TSP as the solution after examining every option.

Give back the best answer possible: Return the most effective permutation to the TSP as the solution after all possible combinations have been examined.

Even though this implementation gives an exact solution for the TSP, it becomes costly to compute for larger instances due to its time complexity, which increases factorially with the number of cities. 

The Branch-and-Bound method can be used to solve the Traveling Salesman Problem (TSP) and other combinatorial optimization problems. To effectively find a suitable space and the best answer, divide-and-conquer strategies are combined with eliminating less-than-ideal solutions.

This is how the Branch and Bound method for the Traveling Salesman Problem works:

Start : First, give a simple answer. You could find this by starting with an empty tour or using a heuristic method.

Limit Calculation : Find the lowest total cost of the current partial solution. This limit shows the least amount of money needed to finish the tour.

Divide : Select a variable that is associated with the subsequent stage of the tour. This could mean picking out the next city to visit.

When making branches, think about the possible values for the variable you’ve chosen. Each branch stands for a different choice or option.

Cutting down : If a branch’s lower bound is higher than the best-known solution right now, cut it because you know that it can’t lead to the best solution.

Exploration : Keep using the branch-and-bound method to look into the other branches. Keep cutting and branching until all of your options have been thought through.

New Ideal Solution : Save the best solution you found while doing research. You should change the known one if a new, cheaper solution comes along.

Termination : Continue investigating until all possible paths have been considered and no more choices exist that could lead to a better solution. End the algorithm when all possible outcomes have been studied.

Selecting the order in which to visit the cities is one of the decision variables for the Traveling Salesman Problem. Usually, methods like the Held-Karp lower bound are used to calculate the lower bound. The technique identifies and cuts branches that are likely to result in less-than-ideal solutions as it carefully investigates various combinations of cities.

A heuristic algorithm called the Nearest Neighbor method estimates solutions to the Traveling Salesman Problem (TSP). In contrast to exact methods like brute force or dynamic programming, which always get the best results, the Nearest Neighbor method finds a quick and reasonable solution by making local, greedy choices.

Here is a detailed explanation of how the nearest-neighbor method solves the TSP problem:

Starting Point : Pick a city randomly to be the tour’s starting point.

Picking Something Greedy: Select the next city on the tour to visit at each stage based on how close the current city is to the not-explored city. Usually, a selected measurement is used to calculate the distance between cities (e.g., Euclidean distance).

Go and Mark: Visit the closest city you picked, add it to your tour, and mark it as observed.

Additionally: Continue this manner until every city has been visited at least once.

Go Back to the Beginning City: After visiting all the other cities, return to the starting city to finish the tour. 

The nearest-neighbor method’s foundation is making locally optimal choices at each stage and hoping that the sum of these choices will produce a reasonable overall solution. Compared to exact algorithms, this greedy approach drastically lowers the level of computation required, which makes it appropriate for relatively large cases of the TSP.

ACO, or Ant Colony Optimization, is a metaheuristic algorithm that draws inspiration from ants’ seeking habits. It works very well for resolving a combination of optimization issues, such as the TSP (Traveling Salesman Problem). The idea behind ACO is to imitate ant colonies’ chemical trail communication to determine the best routes.

Ant Colony Optimization provides the following solution for the Traveling Salesman Problem:

Starting Point: A population of synthetic ants should be planted in a random starting city. Every ant is a possible solution for the TSP.

Initialization of The scents: Give each edge in the problem space (connections between cities) an initial amount of synthetic pheromone. The artificial ants communicate with one another via the fragrance. 

Ant Motion: Each ant creates a tour by constantly selecting the next city to visit using a combination of fragrance levels and a heuristic function.

The quantity of fragrance on the edge that links the candidate city to the current city, as well as a heuristic measure that could be based on factors like distance between cities, impact the chances of selecting a specific city.

Ants mimic how real ants use chemical trails for communication by following paths with higher fragrance levels.

Update on Pheromones: The pheromone concentration on every edge is updated once every ant has finished traveling.

The update involves placing fragrances on the borders of the best tours and evaporating existing fragrances to copy the natural breakdown of chemical paths, which is intended to encourage the search for successful paths.

Repetition: For the fixed number of cycles or until a shift standard is satisfied, repeat the steps of ant movement, fragrance update, and tour construction.

Building Solution : After a few iterations, the artificial ants develop an answer, which is considered the algorithm’s outcome. This solution approximates the most efficient TSP tour.

Enhancement: To improve progress and solution quality, the process can be optimized by adjusting parameters like the influence of the heuristic function and the rate at which fragrances evaporate.

Ant Colony Optimization is excellent at solving TSP cases by using the ant population’s group ability. By striking a balance between exploration and exploitation, the algorithm can find potential paths and take advantage of success. It is a well-liked option in the heuristics field since it has been effectively used to solve various optimization issues.

Genetic Algorithm

Genetic Algorithms (GAs) are optimization algorithms derived from the concepts of genetics and natural selection. These algorithms imitate evolution to find predictions for complex problems, such as the Traveling Salesman Problem (TSP). 

Here is how genetic algorithms resolve the TSP:

Starting Point: select a starting group of possible TSP solutions. Every possible tour that visits every city exactly once is represented by each solution.

Assessment: Examine each solution’s fitness within the population. Fitness is commonly defined in the TSP environment as the opposite of the total distance traveled. Tour length is a determining factor in fitness scores.

Choice: Choose people from the population to be the parents of the following generation. Each person’s fitness level determines the likelihood of selection. More fit solutions have a higher chance of being selected.

Transformation (Recombination): To produce offspring, perform crossover, or recombination, on pairs of chosen parents. To create new solutions, crossover entails sharing information between parent solutions.

Crossover can be applied in various ways for TSP, such as order crossover (OX) or partially mapped crossover (PMX), to guarantee that the resulting tours preserve the authenticity of city visits.

Change: Change some of the offspring solutions to introduce arbitrary changes. A mutation can involve flipping two cities or changing the order of a subset of cities.

Mutations add diversity to the population when discovering new regions of the solution space. 

Substitute: Parents and children together make up the new generation of solutions that will replace the old ones. A portion of the top-performing solutions from the previous generation may be retained in the new generation as part of a privileged replacement process.

Finalization: For a predetermined number of generations or until a convergence criterion is satisfied, repeat the selection, crossover, mutation, and replacement processes. 

Enhancement: Modify variables like population size, crossover rate, and mutation rate to maximize the algorithm’s capacity to identify excellent TSP solutions.

When it comes to optimizing combinations, genetic algorithms are exceptional at sifting through big solution spaces and identifying superior answers. Because of their capacity to duplicate natural evolution, they can adjust to the TSP’s structure and find almost ideal tours. GAs are an effective tool in the field of evolutionary computation because they have been successfully applied to a wide range of optimization problems.

The Lin-Kernighan Heuristic is a local search algorithm that iteratively improves a tour by performing a series of edge exchanges.

How the Lin-Kernighan Heuristic works as a Traveling Salesman Problem solution:

Initial Tour: It begins with an initial tour, which can be generated by any heuristic method, allowing it to start from a reasonable solution.

Edge Exchanges: The algorithm identifies pairs of edges in the tour that can be exchanged to reduce the total tour length. This local optimization step is crucial in refining the tour.

Move Selection: It performs the best exchange and updates the tour, ensuring continuous improvement.

Repetition: The process is repeated until no further improvements can be found, ensuring a thorough search of the local neighborhood.

The heuristic uses variable-depth searches, making it adaptive and efficient for large datasets, as it can adjust the search depth based on the problem’s complexity. This adaptability and focus on local optimizations enable the Lin-Kernighan Heuristic to effectively handle large instances of TSP, often producing near-optimal solutions with relatively low computational effort.

The Chained Lin-Kernighan (CLK) Heuristic is an advanced extension of the Lin-Kernighan heuristic, designed to further enhance solution quality and efficiency for large instances of the TSP.

Here’s how Chained Lin-Kernighan can be used as a Traveling Salesman Problem solution:

Initial Tour: Start with an initial tour generated by any heuristic method.

Lin-Kernighan Improvements: Apply the Lin-Kernighan heuristic to iteratively improve the tour by performing a series of edge exchanges until no further improvements can be found.

K-Opt Moves: Introduce more complex k-opt moves, where multiple edges are swapped simultaneously to escape local minima and explore a larger solution space.

Tour Perturbation: Perturb the current tour by making substantial changes, such as removing a segment and reinserting it elsewhere, to jump to a new region of the solution space.

Reapplication: Reapply the Lin-Kernighan heuristic to the perturbed tour to refine it further.

Chaining Process: Repeat the perturbation and reapplication steps, creating a chain of tours that explore different regions of the solution space.

Selection: Select the best tour found during the chaining process.

By combining Lin-Kernighan improvements with more complex k-opt moves and tour perturbations, CLK often finds near-optimal solutions. The chaining process helps escape local minima by exploring new regions of the solution space, leading to better solutions. This algorithm is highly effective for large TSP instances, maintaining efficiency while improving solution quality.

The Christofides Algorithm is a well-known approximation algorithm for Traveling Salesman Problem solutions that guarantee an output within 1.5 times the optimal tour length. It combines several techniques to produce high-quality solutions efficiently.

Here’s how Christofides Algorithm resolves the TSP:

Minimum Spanning Tree (MST): Construct a minimum spanning tree of the graph, connecting all vertices with the least total edge weight without forming any cycles.

Odd Degree Vertices: Identify all vertices in the MST that have an odd degree. The number of these vertices is always even.

Minimum Weight Matching: Find a minimum weight matching for the odd degree vertices. This step pairs the odd degree vertices with the least possible total edge weight, resulting in a perfect matching.

Eulerian Circuit: Combine the edges of the MST and the minimum weight matching to form a multigraph with an Eulerian circuit (a circuit that visits every edge exactly once). 

Hamiltonian Circuit: Convert the Eulerian circuit to a Hamiltonian circuit by skipping repeated vertices, which results in a valid TSP tour.

The Christofides Algorithm guarantees a solution within 1.5 times the optimal tour length, which is a significant advantage in approximation algorithms. This algorithm is particularly valuable in scenarios where an exact solution is not necessary, but a near-optimal solution is acceptable within a guaranteed bound. Its balance between computational efficiency and solution quality makes it a robust choice for approximating Traveling Salesman Problem solutions.

The Christofides Algorithm is a well-known

The Concorde TSP Solver is widely regarded as the state-of-the-art exact algorithm for Traveling Salesman Problem solutions. It is notable for its ability to handle large and complex instances efficiently, combining multiple advanced techniques to find optimal solutions.

How Concorde TSP Solver resolves the TSP:

Cutting Planes: Concorde uses cutting-plane methods to solve the linear programming relaxation of the TSP. This involves finding hyperplanes (cuts) that progressively tighten the feasible region of the solution space, excluding infeasible solutions and honing in on the optimal tour.

Branch and Bound: The algorithm employs branch-and-bound techniques to systematically explore subsets of solutions. By branching on decision variables and bounding using the current best solution, it effectively prunes large portions of the solution space, reducing the number of tours that need to be examined.

Heuristics: Concorde incorporates various heuristic methods to generate initial feasible solutions and improve intermediate solutions. These heuristics, such as the Lin-Kernighan heuristic and others, provide high-quality starting points and guide the search process.

Cutting Plane Management: The solver manages a pool of cutting planes, dynamically adding and removing them as needed. This ensures that the algorithm remains efficient and can handle large-scale problems without being overwhelmed by the number of cuts.

Concorde’s blend of cutting-edge mathematical techniques and practical heuristics is designed to find exact solutions, meaning it guarantees the optimality of the tour. Despite the complexity of TSP, Concorde’s advanced techniques allow it to solve instances with thousands of cities within a reasonable timeframe, making it the go-to solver for benchmark testing and large-scale applications. Its ability to deliver exact solutions for large-scale problems cements its reputation as the leading TSP solver.

approximation algorithm for Traveling Salesman Problem solutions that guarantee an output within 1.5 times the optimal tour length. It combines several techniques to produce high-quality solutions efficiently.

The Traveling Salesman Problem (TSP) remains a fundamental challenge in optimization, with a wide array of algorithms offering diverse approaches to finding solutions. Understanding these algorithms provides valuable insights for tackling complex routing problems, advancing both theoretical research and practical applications in various fields.

If you’re looking for a solution to help optimize routing for your business, NextBillion.ai offers an advanced Route Optimization API that solves real-life TSP and VRP problems and can be easily integrated with your applications. 

Book a demo today to see firsthand how it works!

In this Article

About author.

Rishabh is a freelance technical writer based in India. He is a technology enthusiast who loves working in the B2B tech space.

It is not possible to solve the Traveling Salesman Problem with Dijkstra’s algorithm. Dijkstra’s algorithm, a single-source shortest path algorithm, finds the shortest possible route from a given source node to every other node in a weighted graph. In comparison, the Traveling Salesman Problem looks for the quickest route that stops in every city exactly once before returning to the starting point.

The term “traveling salesman” refers to a scenario where a salesperson visits different cities to sell goods or services. The goal of this problem is to find the shortest route that goes to each city once and returns to the starting point. It is a fundamental problem in algorithmic optimization to determine the best order of city trips and minimize travel time or distance.

“Route salesman” or just “sales representative” are other terms for a traveling salesman. These people go to various places to sell goods and services to customers. The traveling salesman, who determines the shortest route to visit multiple cities, is often referred to as a “touring agent” or simply as the “salesman” in the context of mathematical optimization.

The minimum distance a salesman needs to visit each city exactly once and then return to the starting city is known as the shortest distance in the Traveling Salesman Problem (TSP). It stands for the ideal tour duration that reduces the total travel distance. The goal of solving the TSP, an essential issue in combinatorial optimization, is finding the shortest distance.

Algorithms for the Travelling Salesman Problem

Portrait of Marc Kuo

Printables.com

  • The Travelling Salesman Problem (TSP) is a classic algorithmic problem in the field of computer science and operations research, focusing on optimization. It seeks the shortest possible route that visits every point in a set of locations just once.
  • The TSP problem is highly applicable in the logistics sector , particularly in route planning and optimization for delivery services. TSP solving algorithms help to reduce travel costs and time.
  • Real-world applications often require adaptations because they involve additional constraints like time windows, vehicle capacity, and customer preferences.
  • Advances in technology and algorithms have led to more practical solutions for real-world routing problems. These include heuristic and metaheuristic approaches that provide good solutions quickly.
  • Tools like Routific use sophisticated algorithms and artificial intelligence to solve TSP and other complex routing problems, transforming theoretical solutions into practical business applications.

The Traveling Salesman Problem (TSP) is the challenge of finding the shortest path or shortest possible route for a salesperson to take, given a starting point, a number of cities (nodes), and optionally an ending point. It is a well-known algorithmic problem in the fields of computer science and operations research, with important real-world applications for logistics and delivery businesses.

There are obviously a lot of different routes to choose from, but finding the best one — the one that will require the least distance or cost — is what mathematicians and computer scientists have spent decades trying to solve.

It’s much more than just an academic problem in graph theory. Finding more efficient routes using route optimization algorithms increases profitability for delivery businesses, and reduces greenhouse gas emissions because it means less distance traveled.

In theoretical computer science, the TSP has commanded so much attention because it’s so easy to describe yet so difficult to solve. The TSP is known to be a combinatorial optimization problem that’s an NP-hard problem, which means that the number of possible solution sequences grows exponential with the number of cities. Computer scientists have not found any algorithm for solving travelling salesman problems in polynomial time, and therefore rely on approximation algorithms to try numerous permutations and select the shortest route with the minimum cost.

A random scattering of 22 black dots on a white background.

The main problem can be solved by calculating every permutation using a brute force approach, and selecting the optimal solution. However, as the number of destinations increases, the corresponding number of roundtrips grows exponentially, soon surpassing the capabilities of even the fastest computers. With 10 destinations, there can be more than 300,000 roundtrip permutations. With 15 destinations, the number of possible routes could exceed 87 billion.

For larger real-world travelling salesman problems, when manual methods such as Google Maps Route Planner or Excel route planner no longer suffice, businesses rely on approximate solutions that are sufficiently optimized by using fast tsp algorithms that rely on heuristics. Finding the exact optimal solution using dynamic programming is usually not practical for large problems.

The same 22 black dots, joined by a single black line in a continuous loop. The resulting shape is an irregular polygon.

Three popular Travelling Salesman Problem Algorithms

Here are some of the most popular solutions to the Travelling Salesman Problem:

1. The brute-force approach

TThe brute-force approach, also known as the naive approach, calculates and compares all possible permutations of routes or paths to determine the shortest unique solution. To solve the TSP using the brute-force approach, you must calculate the total number of routes and then draw and list all the possible routes. Calculate the distance of each route and then choose the shortest one — this is the optimal solution. 

This is only feasible for small problems, rarely useful beyond theoretical computer science tutorials.

2. The branch and bound method

The branch and bound algorithm starts by creating an initial route, typically from the starting point to the first node in a set of cities. Then, it systematically explores different permutations to extend the route beyond the first pair of cities, one node at a time. Each time a new node is added, the algorithm calculates the current path's length and compares it to the optimal route found so far. If the current path is already longer than the optimal route, it "bounds" or prunes that branch of the exploration, as it would not lead to a more optimal solution.

This pruning is the key to making the algorithm efficient. By discarding unpromising paths, the search space is narrowed down, and the algorithm can focus on exploring only the most promising paths. The process continues until all possible routes are explored, and the shortest one is identified as the optimal solution to the traveling salesman problem. Branch and bound is an effective greedy approach for tackling NP-hard optimization problems like the traveling salesman problem.

3. The nearest neighbor method

To implement the nearest neighbor algorithm, we begin at a randomly selected starting point. From there, we find the closest unvisited node and add it to the sequencing. Then, we move to the next node and repeat the process of finding the nearest unvisited node until all nodes are included in the tour. Finally, we return to the starting city to complete the cycle.

While the nearest neighbor approach is relatively easy to understand and quick to execute, it rarely finds the optimal solution for the traveling salesperson problem. It can be significantly longer than the optimal route, especially for large and complex instances. Nonetheless, the nearest neighbor algorithm serves as a good starting point for tackling the traveling salesman problem and can be useful when a quick and reasonably good solution is needed.

This greedy algorithm can be used effectively as a way to generate an initial feasible solution quickly, to then feed into a more sophisticated local search algorithm, which then tweaks the solution until a given stopping condition. ‍

How route optimization algorithms work to solve the Travelling Salesman Problem.

Academic tsp solutions.

Academics have spent years trying to find the best solution to the Travelling Salesman Problem The following solutions were published in recent years:

  • Machine learning speeds up vehicle routing : MIT researchers apply Machine Learning methods to solve large np-complete problems by solving sub-problems.
  • Zero Suffix Method : Developed by Indian researchers, this method solves the classical symmetric TSP. 
  • Biogeography‐based Optimization Algorithm : This method is designed based on the animals’ migration strategy to solve the problem of optimization. 
  • Meta-Heuristic Multi Restart Iterated Local Search (MRSILS): The proponents of this research asserted that the meta-heuristic MRSILS is more efficient than the Genetic Algorithms when clusters are used. 
  • Multi-Objective Evolutionary Algorithm : This method is designed for solving multiple TSP based on NSGA-II. 
  • Multi-Agent System : This system is designed to solve the TSP of N cities with fixed resource. 

Real-world TSP applications

Despite the complexity of solving the Travelling Salesman Problem, approximate solutions — often produced using artificial intelligence and machine learning — are useful in all verticals.

For example, TSP solutions can help the logistics sector improve efficiency in the last mile. Last mile delivery is the final link in a supply chain, when goods move from a transportation hub, like a depot or a warehouse, to the end customer. Last mile delivery is also the leading cost driver in the supply chain. It costs an average of $10.1, but the customer only pays an average of $8.08 because companies absorb some of the cost to stay competitive. So bringing that cost down has a direct effect on business profitability.

The same field of dots from the last images, now in three groups each joined by a single continuous loop. The three loops meet in the middle so that the image looks almost like a flower with three oddly-shaped petals.

Minimizing costs in last mile delivery is essentially a Vehicle Routing Problem (VRP). VRP, a generalized version of the travelling salesman problem, is one of the most widely studied problems in mathematical optimization. Instead of one best path, it deals with finding the most efficient set of routes or paths. The problem may involve multiple depots, hundreds of delivery locations, and several vehicles. As with the travelling salesman problem, determining the best solution to VRP is NP-complete.

Real-life TSP and VRP solvers

While academic solutions to TSP and VRP aim to provide the optimal solution to these NP-hard problems, many of them aren’t practical when solving real world problems, especially when it comes to solving last mile logistical challenges.

That’s because academic solvers strive for perfection and thus take a long time to compute the optimal solutions – hours, days, and sometimes years. If a delivery business needs to plan daily routes, they need a route solution within a matter of minutes. Their business depends on delivery route planning software so they can get their drivers and their goods out the door as soon as possible. Another popular alternative is to use Google maps route planner .

Real-life TSP and VRP solvers use route optimization algorithms that find near-optimal solutions in a fraction of the time, giving delivery businesses the ability to plan routes quickly and efficiently.

If you want to know more about real-life TSP and VRP solvers, check out the resources below 👇

Route Optimization API - TSP Solver

Route Optimization API - VRP Solver

Portrait of Marc Kuo

Frequently Asked Questions

What is a hamiltonian cycle, and why is it important in solving the travelling salesman problem.

A Hamiltonian cycle is a complete loop that visits every vertex in a graph exactly once before returning to the starting vertex. It's crucial for the TSP because the problem essentially seeks to find the shortest Hamiltonian cycle that minimizes travel distance or time.

What role does linear programming play in solving the Travelling Salesman Problem?

Linear programming (LP) is a mathematical method used to optimize a linear objective function, subject to linear equality and inequality constraints. In the context of TSP, LP can help in formulating and solving relaxation of the problem to find bounds or approximate solutions, often by ignoring the integer constraints (integer programming being a subset of LP) to simplify the problem.

What is recursion, and how does it apply to the Travelling Salesman Problem?

Recursion involves a function calling itself to solve smaller sub-problems of the same type as the larger problem. In TSP, recursion is used in methods like the "Divide and Conquer" strategy, breaking down the problem into smaller, manageable subsets, which can be particularly useful in dynamic programming solutions. It reduces redundancy and computation time, making the problem more manageable.

Why is understanding time complexity important when studying the Travelling Salesman Problem?

Time complexity refers to the computational complexity that describes the amount of computer time it takes to solve a problem. For TSP, understanding time complexity is crucial because it helps predict the performance of different algorithms, especially given that TSP is NP-hard and solutions can become impractically slow as the number of cities increases.

Related articles

Liked this article? See below for more recommended reading!

A man wearing a red T-shirt with the word "Delivery" across the front stands at the open door of a van. He is holding a small package and looking at his watch.

Solving the Vehicle Routing Problem (2024)

Decorative graphic repeating the post title with a Google Maps screenshot.

How To Optimize Multi-Stop Routes With Google Maps (2024)

Photograph of a rural scene that suggests the Alps. In the foreground is a green meadow with a scattering of purple wildflowers and some trees, sloping down to a collection of small huts or cabins on a piece of level ground. In the background are snow-capped mountains.

How Route Optimization Impacts Our Earth

elogii-route-optimization-software-side-banner

Home  >   Blog  >   Travelling Salesman Problem: Definition, Algorithms & Solutions

Travelling Salesman Problem: Definition, Algorithms & Solutions

Explore the Traveling Salesman Problem, its algorithms, real-world applications, and practical solutions for optimizing delivery routes in logistics.

Table Of Contents

The Traveling Salesman Problem (TSP) is all about figuring out the shortest route for a salesperson to visit several cities, starting from one place and possibly ending at another. It's a well-known problem in computer science and operations research, with real-world uses in logistics and delivery.

There are many possible routes, but the goal is to find the one that covers the least distance or costs the least. This is what mathematicians and computer scientists have been working on for decades.

This isn’t just a theory problem. Using route optimization algorithms to find better routes can help delivery businesses make more money. It also helps to lower their greenhouse gas emissions by traveling less.

In theoretical computer science, the Traveling Salesman Problem (TSP) gets a lot of attention because it’s simple to explain but tough to solve. It’s a type of problem called combinatorial optimization and is known as NP-hard. This means the number of possible routes grows very quickly as more cities are added. Since there isn’t an efficient algorithm to solve TSP quickly, computer scientists use approximation algorithms. These methods test many different routes and pick the shortest one that costs the least.

You can solve the main problem by trying every possible route and picking the best one, but this brute-force method gets tricky as you add more destinations. The number of possible routes grows quickly, quickly overwhelming even the fastest computers. For just 10 destinations, there are over 300,000 possible routes. When there are 15 destinations, the number of routes can skyrocket to over 87 billion.

For bigger real-world Traveling Salesman Problems, tools like Google Maps Route Planner or Excel just don’t cut it anymore. Businesses turn to approximate solutions using quick TSP algorithms that use smart shortcuts. Trying to find the exact best route with dynamic programming isn’t usually practical for large problems.

In this post:

Three Common Algorithms for the Traveling Salesman Problem

Academic solutions for the traveling salesman problem, real-world uses of the traveling salesman problem, practical solutions for tsp and vrp, faqs about the travelling salesman problem.

boost-efficiency-wih-route-optimization-software-desktop

1. Brute-Force Method

The brute-force method, sometimes called the naive approach, tries every possible route to find the shortest one. To use this method, you list all possible routes, calculate the distance for each one, and then pick the shortest route as the best solution.

This method works only for small problems and is mostly used for teaching in theoretical computer science. For larger problems, it's not practical.

2. Branch and Bound Method

The branch and bound method starts with an initial route, usually from the start point to the first city. It then explores different ways to extend the route by adding one city at a time. For each new route, it checks the length and compares it to the best route found so far. If the current route is longer than the best one, the algorithm "prunes" or cuts off that route, since it won’t be the best solution.

This pruning helps make the algorithm more efficient by focusing only on the most promising routes. The process continues until all possible routes have been checked, and the shortest one is chosen as the best solution. Branch and bound is a smart way to handle tough problems like the traveling salesman problem.

3. Nearest Neighbor Method

The nearest neighbor algorithm starts from a random point. From there, it finds the closest city that hasn't been visited yet and adds it to the route. This process is repeated by moving to the next closest unvisited city until all cities are included in the route. Finally, the route loops back to the starting city to complete the tour.

Although the nearest neighbor method is simple and fast, it often doesn't find the best possible route. For large or complex problems, it might end up with a route much longer than the optimal one. Still, it’s a useful starting point for solving the traveling salesman problem and can quickly provide a good enough solution.

This approach can also be used as the first step to create a decent route, which can then be improved with more advanced algorithms to get an even better solution.

Researchers have been working for years to find the best solutions for the Traveling Salesman Problem. Here are some of the recent advancements:

  • Machine Learning for Vehicle Routing . MIT researchers use machine learning to tackle large, complex problems by breaking them into smaller, more manageable ones.
  • Zero Suffix Method . Developed by researchers in India, this technique addresses the classical symmetric Traveling Salesman Problem.
  • Biogeography-Based Optimization Algorithm . Inspired by animal migration patterns, this method uses nature's strategies to find optimization solutions.
  • Meta-Heuristic Multi-Restart Iterated Local Search (MRSILS) . This approach claims to be more effective than genetic algorithms when working with clusters.
  • Multi-Objective Evolutionary Algorithm . Based on the NSGA-II framework, this method solves multiple Traveling Salesman Problems simultaneously.
  • Multi-Agent System . This system handles the Traveling Salesman Problem for N cities with fixed resources.

Even though solving the Traveling Salesman Problem is complex, approximate solutions—often using artificial intelligence and machine learning—are valuable across many industries.

For instance, TSP solutions can enhance efficiency in last-mile delivery. Last-mile delivery is the final stage in the supply chain, where goods move from a warehouse or depot to the customer. This step is also the biggest cost factor in the supply chain. It typically costs about $10.10, while customers only pay around $8.08, with companies covering the difference to stay competitive. Reducing these costs can significantly boost business profitability.

traveling-salesman-problem-algorithm

Reducing costs in last-mile delivery is a lot like solving a Vehicle Routing Problem (VRP) . VRP is a broader version of the Travelling Salesman Problem and is a key topic in mathematical optimization. Instead of finding just one best route, VRP focuses on finding the most efficient set of routes. It might involve multiple depots, many delivery locations, and several vehicles. Like the Travelling Salesman Problem, finding the best solution for VRP is also a tough challenge.

Academic solutions for the Traveling Salesman Problem (TSP) and Vehicle Routing Problem (VRP) aim to find the perfect answer to these tough problems. However, these solutions often aren't practical for real-world issues, especially when dealing with last-mile logistics.

Academic solvers focus on perfection, which means they can take a long time—sometimes hours, days, or even years—to compute the best solutions. For a delivery business that needs to plan routes every day , waiting that long isn't feasible. They need quick results to get their drivers and goods moving as soon as possible. Many businesses turn to tools like Google Maps Route Planner for a faster option.

In contrast, real-life TSP and VRP solvers use route optimization algorithms that provide near-perfect solutions in much less time. This allows delivery businesses to plan routes efficiently and swiftly, keeping their operations running smoothly.

What is a Hamiltonian cycle, and why is it key to the Travelling Salesman Problem?

A Hamiltonian cycle is a route in a graph that visits every point (vertex) exactly once before returning to where it started. It's essential for solving the Travelling Salesman Problem (TSP) because TSP is about finding the shortest Hamiltonian cycle that minimizes the total travel distance or time.

How does linear programming help with the Travelling Salesman Problem?

Linear programming (LP) is a mathematical technique used to optimize a linear function while meeting certain constraints. For the TSP, LP is useful for creating and solving a simpler version of the problem to find bounds or approximate solutions. It often involves relaxing some constraints, like integer constraints, to make the problem easier to handle.

What is recursion, and how does it apply to the Travelling Salesman Problem?

Recursion is a method where a function solves a problem by breaking it down into smaller, similar problems and calling itself to handle these smaller problems. In the context of the TSP, recursion is used in approaches like "Divide and Conquer," which breaks the main problem into smaller parts, making it easier to solve. This helps reduce repetitive calculations and speeds up finding a solution.

Why is time complexity important for understanding the Travelling Salesman Problem?

Time complexity measures how the time required to solve a problem grows as the size of the problem increases. For the Travelling Salesman Problem, knowing the time complexity is important because it helps estimate how long different algorithms will take, especially since TSP is NP-hard. As the number of cities grows, finding a solution can become very slow and challenging.

Similar posts

How to start a tow truck business in 2024.

Start a tow truck business in 2024 with our guide. Learn costs, regulations, and strategies to maximize profitability in this booming industry.

ELD Short-Haul Exemptions: Is Your Team Eligible?

Optimize routes, boost productivity, and ensure compliance with eLogii's fleet management solution. Simplify operations and maximize efficiency today!

What Is the Multi-Depot Vehicle Routing Problem? [+How to Solve It]

Want to know how to solve the Multi-Depot Vehicle Routing Problem? Read this guide to get a complete breakdown of MDVRP and how to do it.

The leading Route Optimization resource

Be the first to know when new articles are released. eLogii has a market-leading blog and resources centre designed specifically to help business across countless distribution and field-services sub sectors worldwide to succeed with actionable content and tips.

Form CTA

Data Structures & Algorithms Tutorial

  • Data Structures & Algorithms
  • DSA - Overview
  • DSA - Environment Setup
  • DSA - Algorithms Basics
  • DSA - Asymptotic Analysis
  • Data Structures
  • DSA - Data Structure Basics
  • DSA - Data Structures and Types
  • DSA - Array Data Structure
  • Linked Lists
  • DSA - Linked List Data Structure
  • DSA - Doubly Linked List Data Structure
  • DSA - Circular Linked List Data Structure
  • Stack & Queue
  • DSA - Stack Data Structure
  • DSA - Expression Parsing
  • DSA - Queue Data Structure
  • Searching Algorithms
  • DSA - Searching Algorithms
  • DSA - Linear Search Algorithm
  • DSA - Binary Search Algorithm
  • DSA - Interpolation Search
  • DSA - Jump Search Algorithm
  • DSA - Exponential Search
  • DSA - Fibonacci Search
  • DSA - Sublist Search
  • DSA - Hash Table
  • Sorting Algorithms
  • DSA - Sorting Algorithms
  • DSA - Bubble Sort Algorithm
  • DSA - Insertion Sort Algorithm
  • DSA - Selection Sort Algorithm
  • DSA - Merge Sort Algorithm
  • DSA - Shell Sort Algorithm
  • DSA - Heap Sort
  • DSA - Bucket Sort Algorithm
  • DSA - Counting Sort Algorithm
  • DSA - Radix Sort Algorithm
  • DSA - Quick Sort Algorithm
  • Graph Data Structure
  • DSA - Graph Data Structure
  • DSA - Depth First Traversal
  • DSA - Breadth First Traversal
  • DSA - Spanning Tree
  • Tree Data Structure
  • DSA - Tree Data Structure
  • DSA - Tree Traversal
  • DSA - Binary Search Tree
  • DSA - AVL Tree
  • DSA - Red Black Trees
  • DSA - B Trees
  • DSA - B+ Trees
  • DSA - Splay Trees
  • DSA - Tries
  • DSA - Heap Data Structure
  • DSA - Recursion Algorithms
  • DSA - Tower of Hanoi Using Recursion
  • DSA - Fibonacci Series Using Recursion
  • Divide and Conquer
  • DSA - Divide and Conquer
  • DSA - Max-Min Problem
  • DSA - Strassen's Matrix Multiplication
  • DSA - Karatsuba Algorithm
  • Greedy Algorithms
  • DSA - Greedy Algorithms
  • DSA - Travelling Salesman Problem (Greedy Approach)
  • DSA - Prim's Minimal Spanning Tree
  • DSA - Kruskal's Minimal Spanning Tree
  • DSA - Dijkstra's Shortest Path Algorithm
  • DSA - Map Colouring Algorithm
  • DSA - Fractional Knapsack Problem
  • DSA - Job Sequencing with Deadline
  • DSA - Optimal Merge Pattern Algorithm
  • Dynamic Programming
  • DSA - Dynamic Programming
  • DSA - Matrix Chain Multiplication
  • DSA - Floyd Warshall Algorithm
  • DSA - 0-1 Knapsack Problem
  • DSA - Longest Common Subsequence Algorithm
  • DSA - Travelling Salesman Problem (Dynamic Approach)
  • Approximation Algorithms
  • DSA - Approximation Algorithms
  • DSA - Vertex Cover Algorithm
  • DSA - Set Cover Problem
  • DSA - Travelling Salesman Problem (Approximation Approach)
  • Randomized Algorithms
  • DSA - Randomized Algorithms
  • DSA - Randomized Quick Sort Algorithm
  • DSA - Karger’s Minimum Cut Algorithm
  • DSA - Fisher-Yates Shuffle Algorithm
  • DSA Useful Resources
  • DSA - Questions and Answers
  • DSA - Quick Guide
  • DSA - Useful Resources
  • DSA - Discussion
  • Selected Reading
  • UPSC IAS Exams Notes
  • Developer's Best Practices
  • Questions and Answers
  • Effective Resume Writing
  • HR Interview Questions
  • Computer Glossary

Travelling Salesman Problem (Greedy Approach)

Travelling salesperson algorithm.

The travelling salesman problem is a graph computational problem where the salesman needs to visit all cities (represented using nodes in a graph) in a list just once and the distances (represented using edges in the graph) between all these cities are known. The solution that is needed to be found for this problem is the shortest possible route in which the salesman visits all the cities and returns to the origin city.

If you look at the graph below, considering that the salesman starts from the vertex ‘a’, they need to travel through all the remaining vertices b, c, d, e, f and get back to ‘a’ while making sure that the cost taken is minimum.

salesman_graph

There are various approaches to find the solution to the travelling salesman problem: naive approach, greedy approach, dynamic programming approach, etc. In this tutorial we will be learning about solving travelling salesman problem using greedy approach.

As the definition for greedy approach states, we need to find the best optimal solution locally to figure out the global optimal solution. The inputs taken by the algorithm are the graph G {V, E}, where V is the set of vertices and E is the set of edges. The shortest path of graph G starting from one vertex returning to the same vertex is obtained as the output.

Travelling salesman problem takes a graph G {V, E} as an input and declare another graph as the output (say G’) which will record the path the salesman is going to take from one node to another.

The algorithm begins by sorting all the edges in the input graph G from the least distance to the largest distance.

The first edge selected is the edge with least distance, and one of the two vertices (say A and B) being the origin node (say A).

Then among the adjacent edges of the node other than the origin node (B), find the least cost edge and add it onto the output graph.

Continue the process with further nodes making sure there are no cycles in the output graph and the path reaches back to the origin node A.

However, if the origin is mentioned in the given problem, then the solution must always start from that node only. Let us look at some example problems to understand this better.

Consider the following graph with six cities and the distances between them −

graph_six_cities

From the given graph, since the origin is already mentioned, the solution must always start from that node. Among the edges leading from A, A → B has the shortest distance.

graph a to b

Then, B → C has the shortest and only edge between, therefore it is included in the output graph.

graph_b_to_c

There’s only one edge between C → D, therefore it is added to the output graph.

graph_c_to_d

There’s two outward edges from D. Even though, D → B has lower distance than D → E, B is already visited once and it would form a cycle if added to the output graph. Therefore, D → E is added into the output graph.

graph d to e

There’s only one edge from e, that is E → F. Therefore, it is added into the output graph.

graph e to f

Again, even though F → C has lower distance than F → A, F → A is added into the output graph in order to avoid the cycle that would form and C is already visited once.

graph f to a

The shortest path that originates and ends at A is A → B → C → D → E → F → A

The cost of the path is: 16 + 21 + 12 + 15 + 16 + 34 = 114.

Even though, the cost of path could be decreased if it originates from other nodes but the question is not raised with respect to that.

The complete implementation of Travelling Salesman Problem using Greedy Approach is given below −

12.9 Traveling Salesperson Problem

Learning objectives.

After completing this section, you should be able to:

  • Distinguish between brute force algorithms and greedy algorithms.
  • List all distinct Hamilton cycles of a complete graph.
  • Apply brute force method to solve traveling salesperson applications.
  • Apply nearest neighbor method to solve traveling salesperson applications.

We looked at Hamilton cycles and paths in the previous sections Hamilton Cycles and Hamilton Paths . In this section, we will analyze Hamilton cycles in complete weighted graphs to find the shortest route to visit a number of locations and return to the starting point. Besides the many routing applications in which we need the shortest distance, there are also applications in which we search for the route that is least expensive or takes the least time. Here are a few less common applications that you can read about on a website set up by the mathematics department at the University of Waterloo in Ontario, Canada:

  • Design of fiber optic networks
  • Minimizing fuel expenses for repositioning satellites
  • Development of semi-conductors for microchips
  • A technique for mapping mammalian chromosomes in genome sequencing

Before we look at approaches to solving applications like these, let's discuss the two types of algorithms we will use.

Brute Force and Greedy Algorithms

An algorithm is a sequence of steps that can be used to solve a particular problem. We have solved many problems in this chapter, and the procedures that we used were different types of algorithms. In this section, we will use two common types of algorithms, a brute force algorithm and a greedy algorithm . A brute force algorithm begins by listing every possible solution and applying each one until the best solution is found. A greedy algorithm approaches a problem in stages, making the apparent best choice at each stage, then linking the choices together into an overall solution which may or may not be the best solution.

To understand the difference between these two algorithms, consider the tree diagram in Figure 12.187 . Suppose we want to find the path from left to right with the largest total sum. For example, branch A in the tree diagram has a sum of 10 + 2 + 11 + 13 = 36 10 + 2 + 11 + 13 = 36 .

To be certain that you pick the branch with greatest sum, you could list each sum from each of the different branches:

A : 10 + 2 + 11 + 13 = 36 10 + 2 + 11 + 13 = 36

B : 10 + 2 + 11 + 8 = 31 10 + 2 + 11 + 8 = 31

C : 10 + 2 + 15 + 1 = 28 10 + 2 + 15 + 1 = 28

D : 10 + 2 + 15 + 6 = 33 10 + 2 + 15 + 6 = 33

E : 10 + 7 + 3 + 20 = 40 10 + 7 + 3 + 20 = 40

F : 10 + 7 + 3 + 14 = 34 10 + 7 + 3 + 14 = 34

G : 10 + 7 + 4 + 11 = 32 10 + 7 + 4 + 11 = 32

H : 10 + 7 + 4 + 5 = 26 10 + 7 + 4 + 5 = 26

Then we know with certainty that branch E has the greatest sum.

Now suppose that you wanted to find the branch with the highest value, but you only were shown the tree diagram in phases, one step at a time.

After phase 1, you would have chosen the branch with 10 and 7. So far, you are following the same branch. Let’s look at the next phase.

After phase 2, based on the information you have, you will choose the branch with 10, 7 and 4. Now, you are following a different branch than before, but it is the best choice based on the information you have. Let’s look at the last phase.

After phase 3, you will choose branch G which has a sum of 32.

The process of adding the values on each branch and selecting the highest sum is an example of a brute force algorithm because all options were explored in detail. The process of choosing the branch in phases, based on the best choice at each phase is a greedy algorithm. Although a brute force algorithm gives us the ideal solution, it can take a very long time to implement. Imagine a tree diagram with thousands or even millions of branches. It might not be possible to check all the sums. A greedy algorithm, on the other hand, can be completed in a relatively short time, and generally leads to good solutions, but not necessarily the ideal solution.

Example 12.42

Distinguishing between brute force and greedy algorithms.

A cashier rings up a sale for $4.63 cents in U.S. currency. The customer pays with a $5 bill. The cashier would like to give the customer $0.37 in change using the fewest coins possible. The coins that can be used are quarters ($0.25), dimes ($0.10), nickels ($0.05), and pennies ($0.01). The cashier starts by selecting the coin of highest value less than or equal to $0.37, which is a quarter. This leaves $ 0.37 − $ 0.25 = $ 0.12 $ 0.37 − $ 0.25 = $ 0.12 . The cashier selects the coin of highest value less than or equal to $0.12, which is a dime. This leaves $ 0.12 − $ 0.10 = $ 0.02 $ 0.12 − $ 0.10 = $ 0.02 . The cashier selects the coin of highest value less than or equal to $0.02, which is a penny. This leaves $ 0.02 − $ 0.01 = $ 0.01 $ 0.02 − $ 0.01 = $ 0.01 . The cashier selects the coin of highest value less than or equal to $0.01, which is a penny. This leaves no remainder. The cashier used one quarter, one dime, and two pennies, which is four coins. Use this information to answer the following questions.

  • Is the cashier’s approach an example of a greedy algorithm or a brute force algorithm? Explain how you know.
  • The cashier’s solution is the best solution. In other words, four is the fewest number of coins possible. Is this consistent with the results of an algorithm of this kind? Explain your reasoning.
  • The approach the cashier used is an example of a greedy algorithm, because the problem was approached in phases and the best choice was made at each phase. Also, it is not a brute force algorithm, because the cashier did not attempt to list out all possible combinations of coins to reach this conclusion.
  • Yes, it is consistent. A greedy algorithm does not always yield the best result, but sometimes it does.

Your Turn 12.42

The traveling salesperson problem.

Now let’s focus our attention on the graph theory application known as the traveling salesperson problem (TSP) in which we must find the shortest route to visit a number of locations and return to the starting point.

Recall from Hamilton Cycles , the officer in the U.S. Air Force who is stationed at Vandenberg Air Force base and must drive to visit three other California Air Force bases before returning to Vandenberg. The officer needed to visit each base once. We looked at the weighted graph in Figure 12.192 representing the four U.S. Air Force bases: Vandenberg, Edwards, Los Angeles, and Beal and the distances between them.

Any route that visits each base and returns to the start would be a Hamilton cycle on the graph. If the officer wants to travel the shortest distance, this will correspond to a Hamilton cycle of lowest weight. We saw in Table 12.11 that there are six distinct Hamilton cycles (directed cycles) in a complete graph with four vertices, but some lie on the same cycle (undirected cycle) in the graph.

Since the distance between bases is the same in either direction, it does not matter if the officer travels clockwise or counterclockwise. So, there are really only three possible distances as shown in Figure 12.193 .

The possible distances are:

So, a Hamilton cycle of least weight is V → B → E → L → V (or the reverse direction). The officer should travel from Vandenberg to Beal to Edwards, to Los Angeles, and back to Vandenberg.

Finding Weights of All Hamilton Cycles in Complete Graphs

Notice that we listed all of the Hamilton cycles and found their weights when we solved the TSP about the officer from Vandenberg. This is a skill you will need to practice. To make sure you don't miss any, you can calculate the number of possible Hamilton cycles in a complete graph. It is also helpful to know that half of the directed cycles in a complete graph are the same cycle in reverse direction, so, you only have to calculate half the number of possible weights, and the rest are duplicates.

In a complete graph with n n vertices,

  • The number of distinct Hamilton cycles is ( n − 1 ) ! ( n − 1 ) ! .
  • There are at most ( n − 1 ) ! 2 ( n − 1 ) ! 2 different weights of Hamilton cycles.

TIP! When listing all the distinct Hamilton cycles in a complete graph, you can start them all at any vertex you choose. Remember, the cycle a → b → c → a is the same cycle as b → c → a → b so there is no need to list both.

Example 12.43

Calculating possible weights of hamilton cycles.

Suppose you have a complete weighted graph with vertices N, M, O , and P .

  • Use the formula ( n − 1 ) ! ( n − 1 ) ! to calculate the number of distinct Hamilton cycles in the graph.
  • Use the formula ( n − 1 ) ! 2 ( n − 1 ) ! 2 to calculate the greatest number of different weights possible for the Hamilton cycles.
  • Are all of the distinct Hamilton cycles listed here? How do you know? Cycle 1: N → M → O → P → N Cycle 2: N → M → P → O → N Cycle 3: N → O → M → P → N Cycle 4: N → O → P → M → N Cycle 5: N → P → M → O → N Cycle 6: N → P → O → M → N
  • Which pairs of cycles must have the same weights? How do you know?
  • There are 4 vertices; so, n = 4 n = 4 . This means there are ( n − 1 ) ! = ( 4 − 1 ) ! = 3 ⋅ 2 ⋅ 1 = 6 ( n − 1 ) ! = ( 4 − 1 ) ! = 3 ⋅ 2 ⋅ 1 = 6 distinct Hamilton cycles beginning at any given vertex.
  • Since n = 4 n = 4 , there are ( n − 1 ) ! 2 = ( 4 − 1 ) ! 2 = 6 2 = 3 ( n − 1 ) ! 2 = ( 4 − 1 ) ! 2 = 6 2 = 3 possible weights.
  • Yes, they are all distinct cycles and there are 6 of them.
  • Cycles 1 and 6 have the same weight, Cycles 2 and 4 have the same weight, and Cycles 3 and 5 have the same weight, because these pairs follow the same route through the graph but in reverse.

TIP! When listing the possible cycles, ignore the vertex where the cycle begins and ends and focus on the ways to arrange the letters that represent the vertices in the middle. Using a systematic approach is best; for example, if you must arrange the letters M, O, and P, first list all those arrangements beginning with M, then beginning with O, and then beginning with P, as we did in Example 12.42.

Your Turn 12.43

The brute force method.

The method we have been using to find a Hamilton cycle of least weight in a complete graph is a brute force algorithm, so it is called the brute force method . The steps in the brute force method are:

Step 1: Calculate the number of distinct Hamilton cycles and the number of possible weights.

Step 2: List all possible Hamilton cycles.

Step 3: Find the weight of each cycle.

Step 4: Identify the Hamilton cycle of lowest weight.

Example 12.44

Applying the brute force method.

On the next assignment, the air force officer must leave from Travis Air Force base, visit Beal, Edwards, and Vandenberg Air Force bases each exactly once and return to Travis Air Force base. There is no need to visit Los Angeles Air Force base. Use Figure 12.194 to find the shortest route.

Step 1: Since there are 4 vertices, there will be ( 4 − 1 ) ! = 3 ! = 6 ( 4 − 1 ) ! = 3 ! = 6 cycles, but half of them will be the reverse of the others; so, there will be ( 4 − 1 ) ! 2 = 6 2 = 3 ( 4 − 1 ) ! 2 = 6 2 = 3 possible distances.

Step 2: List all the Hamilton cycles in the subgraph of the graph in Figure 12.195 .

To find the 6 cycles, focus on the three vertices in the middle, B, E, and V . The arrangements of these vertices are BEV, BVE, EBV, EVB, VBE , and VEB . These would correspond to the 6 cycles:

1: T → B → E → V → T

2: T → B → V → E → T

3: T → E → B → V → T

4: T → E → V → B → T

5: T → V → B → E → T

6: T → V → E → B → T

Step 3: Find the weight of each path. You can reduce your work by observing the cycles that are reverses of each other.

1: 84 + 410 + 207 + 396 = 1097 84 + 410 + 207 + 396 = 1097

2: 84 + 396 + 207 + 370 = 1071 84 + 396 + 207 + 370 = 1071

3: 370 + 410 + 396 + 396 = 1572 370 + 410 + 396 + 396 = 1572

4: Reverse of cycle 2, 1071

5: Reverse of cycle 3, 1572

6: Reverse of cycle 1, 1097

Step 4: Identify a Hamilton cycle of least weight.

The second path, T → B → V → E → T , and its reverse, T → E → V → B → T , have the least weight. The solution is that the officer should travel from Travis Air Force base to Beal Air Force Base, to Vandenberg Air Force base, to Edwards Air Force base, and return to Travis Air Force base, or the same route in reverse.

Your Turn 12.44

Now suppose that the officer needed a cycle that visited all 5 of the Air Force bases in Figure 12.194 . There would be ( 5 − 1 ) ! = 4 ! = 4 × 3 × 2 × 1 = 24 ( 5 − 1 ) ! = 4 ! = 4 × 3 × 2 × 1 = 24 different arrangements of vertices and ( 5 − 1 ) ! 2 = 4 ! 2 = 24 2 = 12 ( 5 − 1 ) ! 2 = 4 ! 2 = 24 2 = 12 distances to compare using the brute force method. If you consider 10 Air Force bases, there would be ( 10 − 1 ) ! = 9 ! = 9 ⋅ 8 ⋅ 7 ⋅ 6 ⋅ 5 ⋅ 4 ⋅ 3 ⋅ 2 ⋅ 1 = 362 , 880 ( 10 − 1 ) ! = 9 ! = 9 ⋅ 8 ⋅ 7 ⋅ 6 ⋅ 5 ⋅ 4 ⋅ 3 ⋅ 2 ⋅ 1 = 362 , 880 different arrangements and ( 10 − 1 ) ! 2 = 9 ! 2 = 9 ⋅ 8 ⋅ 7 ⋅ 6 ⋅ 5 ⋅ 4 ⋅ 3 ⋅ 2 ⋅ 1 2 = 181 , 440 ( 10 − 1 ) ! 2 = 9 ! 2 = 9 ⋅ 8 ⋅ 7 ⋅ 6 ⋅ 5 ⋅ 4 ⋅ 3 ⋅ 2 ⋅ 1 2 = 181 , 440 distances to consider. There must be another way!

The Nearest Neighbor Method

When the brute force method is impractical for solving a traveling salesperson problem, an alternative is a greedy algorithm known as the nearest neighbor method , which always visit the closest or least costly place first. This method finds a Hamilton cycle of relatively low weight in a complete graph in which, at each phase, the next vertex is chosen by comparing the edges between the current vertex and the remaining vertices to find the lowest weight. Since the nearest neighbor method is a greedy algorithm, it usually doesn’t give the best solution, but it usually gives a solution that is "good enough." Most importantly, the number of steps will be the number of vertices. That’s right! A problem with 10 vertices requires 10 steps, not 362,880. Let’s look at an example to see how it works.

Suppose that a candidate for governor wants to hold rallies around the state. They plan to leave their home in city A , visit cities B, C, D, E , and F each once, and return home. The airfare between cities is indicated in the graph in Figure 12.196 .

Let’s help the candidate keep costs of travel down by applying the nearest neighbor method to find a Hamilton cycle that has a reasonably low weight. Begin by marking starting vertex as V 1 V 1 for "visited 1st." Then to compare the weights of the edges between A and vertices adjacent to A : $250, $210, $300, $200, and $100 as shown in Figure 12.197 . The lowest of these is $100, which is the edge between A and F .

Mark F as V 2 V 2 for "visited 2nd" then compare the weights of the edges between F and the remaining vertices adjacent to F : $170, $330, $150 and $350 as shown in Figure 12.198 . The lowest of these is $150, which is the edge between F and D .

Mark D as V 3 V 3 for "visited 3rd." Next, compare the weights of the edges between D and the remaining vertices adjacent to D : $120, $310, and $270 as shown in Figure 12.199 . The lowest of these is $120, which is the edge between D and B .

So, mark B as V 4 V 4 for "visited 4th." Finally, compare the weights of the edges between B and the remaining vertices adjacent to B : $160 and $220 as shown in Figure 12.200 . The lower amount is $160, which is the edge between B and E .

Now you can mark E as V 5 V 5 and mark the only remaining vertex, which is C , as V 6 V 6 . This is shown in Figure 12.201 . Make a note of the weight of the edge from E to C , which is $180, and from C back to A , which is $210.

The Hamilton cycle we found is A → F → D → B → E → C → A . The weight of the circuit is $ 100 + $ 150 + $ 120 + $ 160 + $ 180 + $ 210 = $ 920 $ 100 + $ 150 + $ 120 + $ 160 + $ 180 + $ 210 = $ 920 . This may or may not be the route with the lowest cost, but there is a good chance it is very close since the weights are most of the lowest weights on the graph and we found it in six steps instead of finding 120 different Hamilton cycles and calculating 60 weights. Let’s summarize the procedure that we used.

Step 1: Select the starting vertex and label V 1 V 1 for "visited 1st." Identify the edge of lowest weight between V 1 V 1 and the remaining vertices.

Step 2: Label the vertex at the end of the edge of lowest weight that you found in previous step as V n V n where the subscript n indicates the order the vertex is visited. Identify the edge of lowest weight between V n V n and the vertices that remain to be visited.

Step 3: If vertices remain that have not been visited, repeat Step 2. Otherwise, a Hamilton cycle of low weight is V 1 → V 2 → ⋯ → V n → V 1 V 1 → V 2 → ⋯ → V n → V 1 .

Example 12.45

Using the nearest neighbor method.

Suppose that the candidate for governor wants to hold rallies around the state but time before the election is very limited. They would like to leave their home in city A , visit cities B , C , D , E , and F each once, and return home. The airfare between cities is not as important as the time of travel, which is indicated in Figure 12.202 . Use the nearest neighbor method to find a route with relatively low travel time. What is the total travel time of the route that you found?

Step 1: Label vertex A as V 1 V 1 . The edge of lowest weight between A and the remaining vertices is 85 min between A and D .

Step 2: Label vertex D as V 2 V 2 . The edge of lowest weight between D and the vertices that remain to be visited, B, C, E , and F , is 70 min between D and F .

Repeat Step 2: Label vertex F as V 3 V 3 . The edge of lowest weight between F and the vertices that remain to be visited, B, C, and E , is 75 min between F and C .

Repeat Step 2: Label vertex C as V 4 V 4 . The edge of lowest weight between C and the vertices that remain to be visited, B and E , is 100 min between C and B .

Repeat Step 2: Label vertex B as V 5 V 5 . The only vertex that remains to be visited is E . The weight of the edge between B and E is 95 min.

Step 3: A Hamilton cycle of low weight is A → D → F → C → B → E → A . So, a route of relatively low travel time is A to D to F to C to B to E and back to A . The total travel time of this route is: 85 min + 70 min + 75 min + 100 min + 95 min + 90 min = 515 min or 8 hrs 35 min 85 min + 70 min + 75 min + 100 min + 95 min + 90 min = 515 min or 8 hrs 35 min

Your Turn 12.45

Check your understanding, section 12.9 exercises.

This book may not be used in the training of large language models or otherwise be ingested into large language models or generative AI offerings without OpenStax's permission.

Want to cite, share, or modify this book? This book uses the Creative Commons Attribution License and you must attribute OpenStax.

Access for free at https://openstax.org/books/contemporary-mathematics/pages/1-introduction
  • Authors: Donna Kirk
  • Publisher/website: OpenStax
  • Book title: Contemporary Mathematics
  • Publication date: Mar 22, 2023
  • Location: Houston, Texas
  • Book URL: https://openstax.org/books/contemporary-mathematics/pages/1-introduction
  • Section URL: https://openstax.org/books/contemporary-mathematics/pages/12-9-traveling-salesperson-problem

© Jul 25, 2024 OpenStax. Textbook content produced by OpenStax is licensed under a Creative Commons Attribution License . The OpenStax name, OpenStax logo, OpenStax book covers, OpenStax CNX name, and OpenStax CNX logo are not subject to the Creative Commons license and may not be reproduced without the prior and express written consent of Rice University.

Javatpoint Logo

  • Interview Q

DAA Tutorial

Asymptotic analysis, analysis of sorting, divide and conquer, lower bound theory, sorting in linear time, binary search trees, red black tree, dynamic programming, greedy algorithm, backtracking, shortest path, all-pairs shortest paths, maximum flow, sorting networks, complexity theory, approximation algo, string matching.

Interview Questions

JavaTpoint

  • Send your Feedback to [email protected]

Help Others, Please Share

facebook

Learn Latest Tutorials

Splunk tutorial

Transact-SQL

Tumblr tutorial

Reinforcement Learning

R Programming tutorial

R Programming

RxJS tutorial

React Native

Python Design Patterns

Python Design Patterns

Python Pillow tutorial

Python Pillow

Python Turtle tutorial

Python Turtle

Keras tutorial

Preparation

Aptitude

Verbal Ability

Interview Questions

Company Questions

Trending Technologies

Artificial Intelligence

Artificial Intelligence

AWS Tutorial

Cloud Computing

Hadoop tutorial

Data Science

Angular 7 Tutorial

Machine Learning

DevOps Tutorial

B.Tech / MCA

DBMS tutorial

Data Structures

DAA tutorial

Operating System

Computer Network tutorial

Computer Network

Compiler Design tutorial

Compiler Design

Computer Organization and Architecture

Computer Organization

Discrete Mathematics Tutorial

Discrete Mathematics

Ethical Hacking

Ethical Hacking

Computer Graphics Tutorial

Computer Graphics

Software Engineering

Software Engineering

html tutorial

Web Technology

Cyber Security tutorial

Cyber Security

Automata Tutorial

C Programming

C++ tutorial

Control System

Data Mining Tutorial

Data Mining

Data Warehouse Tutorial

Data Warehouse

RSS Feed

InterviewBit

  • Coding Problems

Travelling Salesman Problem (TSP)

Problem statement, example 1: travelling salesman problem, example 2: travelling salesman problem, 1. simple approach, c++ code implementation, java code implementation, python code implementation, 2. travelling salesman problem using dynamic programming, c code implementation, 3. greedy approach, practice questions, frequently asked questions, 1. which algorithm is used for the travelling salesman problem, 2. what is the complexity of the travelling salesman problem, 3. how is this problem modelled as a graph problem, 4: what is the difficulty level of the travelling salesman problem.

Travelling Salesman Problem (TSP) – Given a set of cities and the distance between every pair of cities as an adjacency matrix, the problem is to find the shortest possible route that visits every city exactly once and returns to the starting point. The ultimate goal is to minimize the total distance travelled, forming a closed tour or circuit.

The TSP is referred to as an NP-hard problem, meaning there is no known algorithm to solve it in polynomial time for large instances. As the number of cities increases, the number of potential solutions grows exponentially, making an exhaustive search unfeasible. This complexity is one of the reasons why the TSP remains a popular topic of research. Learn More .

Input –

Confused about your next job?

Output –

Here, the TSP Tour is 0-2-1-3-0 and the cost of the tour is 48.

Minimum weight Hamiltonian Cycle : EACBDE= 32

Wondering how the Hamiltonian Cycle Problem and the Traveling Salesman Problem differ? The Hamiltonian Cycle problem is to find out if there exists a tour that visits each city exactly once. Here, we know that the Hamiltonian Tour exists (due to the graph being complete), and there are indeed many such tours. The problem is to find a minimum weight Hamiltonian Cycle.

There are various approaches to finding the solution to the travelling salesman problem- simple (naïve) approach, dynamic programming approach, and greedy approach. Let’s explore each approach in detail:

  • Consider city 1 as the starting and ending point. Since the route is cyclic, we can consider any point as a starting point.
  • Now, we will generate all possible permutations of cities which are (n-1)!.
  • Find the cost of each permutation and keep track of the minimum cost permutation.
  • Return the permutation with minimum cost.
  • Time complexity: O(N!), Where N is the number of cities.
  • Space complexity: O(1).

In the travelling salesman problem algorithm, we take a subset N of the required cities that need to be visited, the distance among the cities dist, and starting cities s as inputs. Each city is identified by a unique city id which we say like 1,2,3,4,5………n

Here we use a dynamic approach to calculate the cost function Cost(). Using recursive calls, we calculate the cost function for each subset of the original problem.

To calculate the cost(i) using Dynamic Programming , we need to have some recursive relation in terms of sub-problems.

We start with all subsets of size 2 and calculate C(S, i) for all subsets where S is the subset, then we calculate C(S, i) for all subsets S of size 3 and so on.

There are at most O(n2^n) subproblems, and each one takes linear time to solve. The total running time is, therefore, O(n^22^n). The time complexity is much less than O(n!) but still exponential. The space required is also exponential.

  • Time Complexity: O(N^2*2^N).
  • First of them is a list that can hold the indices of the cities in terms of the input matrix of distances between cities
  • And the Second one is the array which is our result
  • Perform traversal on the given adjacency matrix tsp[][] for all the cities and if the cost of reaching any city from the current city is less than the current cost update the cost.
  • Generate the minimum path cycle using the above step and return their minimum cost.
  • Time complexity: O(N^2*logN), Where N is the number of cities.
  • Space complexity: O(N).
  • City Tour Problem
  • Shortest Common Substring

Ans . Travelling Salesman Problem uses Dynamic programming with a masking algorithm.

Ans.: The complexity of TSP using Greedy will be O(N^2 LogN) and using DP will be O(N^2 2^N).

Ans .: The TSP can be modelled as a graph problem by considering a complete graph G = (V, E). A tour is then a circuit in G that meets every node. In this context, tours are sometimes called Hamiltonian circuits.

Ans.: It is an NP-hard problem.

  • Travelling Salesman Problem

Previous Post

Top principles of scrum, difference between product and service based company.

TRACKOBIT

Manage commercial vehicles with the new-age Fleet Management Software

methods travelling salesman problem

Streamline your scattered workforce with Field Force Management Software

methods travelling salesman problem

Optimize your delivery process with last mile delivery software

methods travelling salesman problem

How to Enhance the Field Sales Team’s Performance? The Secret is Out!

methods travelling salesman problem

What is PUDO? How Does PickUp and DropOff Location Work?

GPS Hardware Types of hardware devices we support for utmost security.

GPS Hardware Manufacturers Top GPS hardware manufacturers, our solutions are supportive of.

Blog Carefully Curated articles to update you on industrial trends.

White Paper Insightful papers and analysis on essential subject matters.

Glossary Offer clients a modern, all-in-one payroll and HR system you’ll both love

About Us Get to know TrackoBit: our team, ethos, values, and vision.

Careers Join the most dynamic cult of coders, creatives and changemakers.

Tech Support Learn about our technical support team and services in detail.

Events Check out the exhibitions where we left our marks and conquered.

Contact Us Connect with us and let us know how we can be of service.

What is a Travelling Salesman Problem (TSP)? Explained!

  • Author: Diksha Bhandari
  • Read Time: 9 min
  • Published: September 14, 2023
  • Last Update: July 4, 2024

Table of Contents

  • Fleet Management
  • Leave And Attendance
  • Video telematics
  • TrackoField Industries
  • Route Planning
  • Driver Behaviour
  • Last Mile Delivery
  • Asset Tracking
  • Dispatch Management
  • Fuel Management
  • Route Optimisation
  • Electric Vehicle
  • Roster Management
  • Vehicle Tracking
  • TrackoMile Industries
  • TrackoBit Industries
  • Sensor Integration
  • GPS Trackers and Hardware
  • Tech and Beyond
  • TrackoField
  • What's New
  • Employee Management
  • Field Sales And Service
  • Task and Workflow
  • Miscellaneous
  • GPS Software
  • Lead Management

What is a Traveling Salesman Problem (TSP)

Want to know what a travelling salesman problem (TSP) is? Need solutions to real-life TSP challenges. Learn here. 

Do you also look for the shortest route on Google Maps before embarking on a trip?

I am sure, you know multiple routes to reach the office, the mall, or your desired location, but checking on the internet before leaving home has become a ritual. It becomes all the more important to refer to maps when you have to pick up friends or colleagues along the way.

‘ADD STOPS’

Yes, you are right! 💯

That’s what solving the TSP challenge using software means!

What is a Travelling Salesman Problem (TSP)?

The traveling salesman problem is the popular combinatorial optimisation challenge in mathematics and computer science. The prime objective of the problem is to determine the shortest possible route a salesperson must take to cover a set of locations in one go and then return to the starting point.

Addressing travelling salesman challenges and their optimisation are more relevant in this time and age, especially in the supply chain, logistics and delivery space.

TSP may result in delayed deliveries and slimming profits as it’s not easy for delivery agents to choose the most viable and cost-effective route in real-time.

What are Traveling Salesman Problem Challenges to Solve?

When a salesperson is in the field hopping from one client site to another, finding out the best and the shortest route is an added pressure on the agent. In today’s day and age, distance isn’t the only factor that defines efficiency. There are several factors, such as time, fuel consumption, capacity, etc. that together define efficiency.

However, addressing the travelling salesman challenges involves mitigating a few unavoidable challenges along the way that field agents face themselves.

1. Time Constraints

Sales agents often have a tight schedule with multiple deliveries to make with a short TAT. Similarly, in TSP, optimising routes to minimise travel time is a fundamental challenge.

2. Last-minute Changes

Eleventh-hour changes are not a new concept for salespeople. They encounter urgent visits and last-minute cancellations a lot. Similarly, TSP solutions must be adaptable to handle dynamic scenarios and route modifications.

3. Resource Efficiency

Just as salespersons aim at reducing fuel costs and ensuring on-time deliveries, TSP solutions such as TrackoMile must strive for resource optimisation by reducing travel distances and delivery TAT.

4. Objective Diversification

While solving the travelling salesman problem (TSP) , optimising multiple objectives such as cost, time, and environmental factors adds complexity as solutions need to balance conflicting goals.

5. Combinatorial Complexity

TSP is a combinatorial optimisation problem, which means it involves complicated mathematical calculations with numerous variables. Sometimes, complex scenarios get further intricate as multiple variables are involved.

6. Adaptability and Scalability

Similarly, how sales agents adjust to the routes on the fly, the route algorithm must be flexible and responsive to real-time changes such as spiking volumes, vehicle breakdown or traffic slow down. A TSP solution must have a good appetite to handle large datasets and complex networks.

Also Read 4 Key Solutions for Fuel Management System 2023

Top 5 Solutions to The Travelling Salesman Problem

The traveling salesman problem solutions offer various trade-offs between computational intricacies and the quality of the resolution, allowing practitioners to choose the best-suited approach based on their needs and problems.

Here are the Top 5 solutions to the Traveling Salesman Problem (TSP) :

1. Brute Force Algorithm

The Brute Force algorithm is a straight approach to solving the Traveling Salesman Problem (TSP). It systematically explores all possible routes to identify the shortest one among them all. While it guarantees an optimal solution, its downside lies in its major time complexity, making it practical only for small TSP challenges.

Brute Force Algorithm

2. Nearest Neighbour Algorithm

The Nearest Neighbour method is the simplest heuristic for the TSP. It starts from the first location and repeatedly selects the closest unvisited location to form a tour. Although it is quick to implement this method, it may always yield the optimal solution for it prioritises proximity over other factors.

Nearest neighbour Algorithm - Traveling Salesman Problem

3. Genetic Algorithm

This technique or method draws inspiration from nature itself. They evolve TSP solutions through selection, crossovers and mutation. They pick the best routes and mix them up. This creates new routes that might be even better. Then, they keep the best ones and repeat the mixing and picking process. Survival of the fittest in the true sense.

Genetic Algorithm - Traveling Salesman Problem

4. Ant Colony Optimisation (ACO)

Ants have a tendency to leave pheromones on the shorter routes they find, calling fellow ants on the same route. They keep leaving more pheromones on the shorter routes they find. Over time, the collective behaviour of the ants causes them to converge on the shortest route. Inspired by the nature of ants, ACO finds the shortest route by analysing the trails of data left by artificial ants based on the strength of these data trails.

Ant Colony Optimisation (ACO) - Traveling Salesman Problem

5. Dynamic Programming

Dynamic Programming is like solving a puzzle, step-by-step, by breaking it into smaller pieces. In TSP challenges, it finds the best route to visit all locations. It begins with figuring out the shortest route between two locations; then it builds on that to find ways to more locations. It’s a smart TSP solution for small scenarios but may require significant memory resources for larger and more complex problems.

What Are Real-world Travelling Salesman Problem Applications?

The Traveling Salesman Problem (TSP) has a wide array of applications across various domains due to its relevance in optimising routes and sequences. Here are several crucial real-word TSP applications and implementations in the real world.

1. TSP implementation in Logistics and Delivery Services

The logistics and supply chain sectors have the widest TSP applications.

  • Courier, Express & Parcel : Companies like FedEx, UPS, and DHL rely on TSP algorithms to optimise delivery routes for their fleet of delivery trucks. By finding the most efficient sequence of stops, they minimise fuel consumption , reduce delivery TAT, and save on operational overheads too.
  • On-demand Delivery : Food delivery companies, instant grocery delivery apps and at-home appointment platforms like Swiggy, BlinkIt and UrbanCompany, respectively, leverage TSP solutions to ensure timely delivery. Enhancing the customer experience and increasing the number of deliveries each rider can make.

2. TSP Applications in Transportation and Urban Planning Waste collection routes, Traffic light synchronisation, optic cable installation, etc. are some areas where TSP Solutions works like a knight in shining armour. Other real-world TSP applications include

  • Public Transport : City planners and public transport agencies use TSP principles to design bus, tram and train routes that reduce travel for passengers.
  • Emergency Service Dispatch : Ambulance services, Police PCR vans employ TSP algorithms to dispatch vehicles quickly and efficiently in response to emergency calls. Finding the shortest route to reach the incident location can save lives.
  • Urban Mobility Solution : In the era of ride-sharing and on-demand mobility apps like Uber, Ola, Lyft, etc., real-world TSP applications become prominent. TSP solutions optimise the route to destinations, ensuring quick and cost-effective transportation.

Other significant real-life applications of the Travelling Salesman Problem are

  • TSP in Healthcare and Medical Research – for DNA sequencing and understanding genetic patterns and diseases.
  • TSP in Manufacturing and Production – In circuit board manufacturing and job scheduling of technicians.
  • TSP in Robotics and Autonomous Vehicles -Self-driving cars and drones use TSP-like algorithms for efficient navigation.

Solving the Travelling Salesman Problem – Last Mile Delivery Route Optimisation

Route optimisation is the key to efficient last-mile delivery . In order to attain flawless route optimisation, the software must solve the traveling salesman problem every step of the way.

Why it’s essential to solve TSP for Last Mile Delivery?

In simple and minimal words, solving TSP problems helps in many ways:

  • Saves Time : It makes deliveries faster, so your customers get orders sooner.
  • Customer Satisfaction : Fast deliveries give you an edge over the competition and enhance customer experience too.
  • Saves Money : It reduces fuel wastage and vehicle wear, making deliveries cheaper.
  • Environment Friendly : It lowers pollution by using fewer vehicles and shorter routes.
  • Happy Staff: Drivers and dispatchers have less stress and can finish their work faster.

How do we solve the travelling salesman problem for last-mile delivery?

Solving TSP challenges for Last-mile delivery is like solving a big jigsaw puzzle. There are a hundred thousand addresses to visit daily. The software must find the shortest and most optimised route to them and come back to the starting point at the end.

  • Our route optimisation software , TrackoMile, leverages capacity management , routing algorithms and robust rule engines to present the most optimal combination of delivery addresses. Thereby giving the most optimally planned routes or trips.
  • All delivery managers have to do is upload the CSV file of the addresses or integrate TrackoMile to their CRM to fetch the delivery addresses. Now trip allocation, route optimisation, dispatch and everything else happen in a few clicks.
  • ETA when the delivery is en route, POD when the order is delivered successfully, and trip analysis, are added features to simplify overall operations.

The Vehicle Routing Problem is very similar to TSP, with wide applications in logistics, delivery services and transportation. While TSP focuses on finding the shortest route for a single traveller visiting various locations, VRP deals with multiple vehicles serving multiple customers, considering added constraints like vehicle capacity, TATs and more.

vehicle route problem

How Can AI Help in Solving Traveling Salesman Problem (TSP)?

AI or Artificial Intelligence are becoming the driving force for business growth across various industrial sectors. AI particularly aids in solving the Traveling Salesman Problem(TSP) in the logistics and delivery sector by employing advanced algorithms and techniques. What are a few tricks up AI’s sleeves that help in automating TSP resolution? Let’s find out!

1. Advanced Algorithms

AI algorithms such as Genetic Algorithms, ACO, simulated annealing and a few others mentioned above, tackle complex Travelling Salesman Problem scenarios.

2. Machine Learning

Gathering information from historical data and optimising routes based on real-time insights is what AI is best for. Machine learning models are trained to adapt to changing conditions, like traffic, weather and delivery constraints, to provide a more accurate plan of action.

3. Parallel Computing

AIi enables the use of a parallel computing process, which means solving multiple segments of TSP simultaneously. This accelerates the problem-solving process for large-scale challenges.

4. Heuristic Improvement

TSP Heuristics powered by AI can groom initial solutions, gradually improving their results over time. These heuristics can be applied iteratively by AI to reach better results.

5. Hybrid Approaches

Applying hybrid algorithms is not a new technique to refine techniques and produce more accurate results. AI on top of it singles out data-oriented combinations that work the best in varied use cases.

Wrapping Up!

The travelling salesman problem’s importance lies in its real-world applications. Whether optimising delivery routes, planning manufacturing processes or organising circuit board drilling, finding the most efficient way to cover multiple locations is crucial to minimise costs and save time.

The TSP problems have evolved over the years, and so have TSP algorithms, heuristics and solutions. With the advent of advanced technologies such as GPS and machine learning, TSP continues to adapt and find new applications in emerging fields, cementing its status as a fundamental problem in optimization theory and a valuable tool for various industries. Mobility automation software like Trackobit, TrackoMile and TrackoField resort to TSP heuristics to solve challenges along the way.

Read Blog – Best Delivery Route Planner Apps for 2023

Traveling Salesman Problem FAQs

What is tsp.

TSP is an abbreviation for Traveling Salesman Problem. It’s the routing problem that deals with finding the shortest route to travel to a combination of locations in the most optimal manner.

Is Travelling Salesman Problem Solvable?

Yes, the Traveling Salesman Problem (TSP) is solvable, but the time to find the solution can grow proportionately with an increase in the number of locations. With the evolution of travelling salesman problem applications, various TSP algorithms and heuristics, their hybrids have also emerged.

Wh at is the objective of TSP?

The objective of the Traveling Salesman Problem (TSP) is to find the shortest possible route that covers all given locations or waypoints and comes back to the starting point with the least resource utilisation.

What is a Travelling Salesman Problem (TSP)? Explained!

Diksha Bhandari

Currently creating SaaSy content strategies for TrackoBit and TrackoField, this content professional has dedicated a decade of her life to enriching her portfolio and continues to do so. In addition to playing with words and spilling SaaS, she has a passion for traveling to the mountains and sipping on adrak wali chai.

  • Author Showcase
  • All Blog Post

methods travelling salesman problem

Never Miss a Beat

methods travelling salesman problem

Related Blog Test

What is an End-User License Agreement (EULA)

What is an End-User License Agreement (EULA)?

EULA, or End-user license agreement, we all know, is a legal agreement granting users a software license and how it protects ownership rights. Let’s learn the ins and outs of the EULA agreement & how it’s different from SLAs.

GPS vs NavIC - Which One is Better

GPS vs NavIC: Global Reach vs. Regional Precision

Want to know what’s better, GPS or NavIC? This piece of writing will surely give you clarity on all the ins and outs of both navigation systems.

what is NavIC - India’s Eye in the Sky

What is NavIC- India’s Homegrown GNSS System

Have you heard of NavIC – YES India’s very own GPS tracking system! This piece of writing is all about the Indigenous Global Navigation Satellite System (GNSS).

methods travelling salesman problem

Top 12 Google Map Alternatives – Offering Precise Navigation

Explore our best picks for 12 free Google map alternatives that offer accurate and secure location and navigational solutions. 

Thank you

Thank you for reaching out! We'll speak to you soon.

In the meantime, why not find out more about us, explore our products, or visit our blog?

Stay Updated on tech, telematics and mobility. Don't miss out on the latest in the industry.

Cookie Consent

We use cookies to enhance and personalize your browsing experience. By continuing to use our website, you agree to our Privacy Policy.

Caev Expo

  • DSA Tutorial
  • Data Structures
  • Linked List
  • Dynamic Programming
  • Binary Tree
  • Binary Search Tree
  • Divide & Conquer
  • Mathematical
  • Backtracking
  • Branch and Bound
  • Pattern Searching

Travelling Salesman Problem | Greedy Approach

Given a 2D matrix tsp[][] , where each row has the array of distances from that indexed city to all the other cities and -1 denotes that there doesn’t exist a path between those two indexed cities. The task is to print minimum cost in TSP cycle. Examples:  

Input:   tsp[][] = {{-1, 10, 15, 20},  {10, -1, 35, 25},  {15, 35, -1, 30},  {20, 25, 30, -1}};  Below is the given graph:    Output: 80  Explanation:   We are trying to find out the path/route with the minimum cost such that our aim of visiting all cities once and return back to the source city is achieved. The path through which we can achieve that, can be represented as 1 -> 2 -> 4 -> 3 -> 1. Here, we started from city 1 and ended on the same visiting all other cities once on our way. The cost of our path/route is calculated as follows:  1 -> 2 = 10  2 -> 4 = 25  4 -> 3 = 30  3 -> 1 = 15  (All the costs are taken from the given 2D Array)  Hence, total cost = 10 + 25 + 30 + 15 = 80 Input:   tsp[][] = {{-1, 30, 25, 10},  {15, -1, 20, 40},  {10, 20, -1, 25},  {30, 10, 20, -1}};  Output: 50 

We introduced Travelling Salesman Problem and discussed Naive and Dynamic Programming Solutions for the problem in the previous post . Both of the solutions are infeasible. In fact, there is no polynomial-time solution available for this problem as the problem is a known NP-Hard problem. There are approximate algorithms to solve the problem though.  This problem can be related to the Hamiltonian Cycle problem , in a way that here we know a Hamiltonian cycle exists in the graph, but our job is to find the cycle with minimum cost. Also, in a particular TSP graph, there can be many hamiltonian cycles but we need to output only one that satisfies our required aim of the problem. Approach: This problem can be solved using Greedy Technique . Below are the steps: 

  • A list that holds the indices of the cities in terms of the input matrix of distances between cities.
  • Result array which will have all cities that can be displayed out to the console in any manner.
  • Perform traversal on the given adjacency matrix tsp[][] for all the city and if the cost of the reaching any city from current city is less than current cost the update the cost.
  • Generate the minimum path cycle using the above step and return there minimum cost.

Below is the implementation of the above approach:

Time Complexity: O(N 2 *log 2 N)  Auxiliary Space: O(N)  

Please Login to comment...

Similar reads.

  • Competitive Programming
  • Computer Subject
  • Java Programs
  • Algorithms-Greedy Algorithms
  • California Lawmakers Pass Bill to Limit AI Replicas
  • Best 10 IPTV Service Providers in Germany
  • Python 3.13 Releases | Enhanced REPL for Developers
  • IPTV Anbieter in Deutschland - Top IPTV Anbieter Abonnements
  • Content Improvement League 2024: From Good To A Great Article

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

iMTSP: Solving Min-Max Multiple Traveling Salesman Problem with Imperative Learning

This paper considers a Min-Max Multiple Traveling Salesman Problem (MTSP), where the goal is to find a set of tours, one for each agent, to collectively visit all the cities while minimizing the length of the longest tour. Though MTSP has been widely studied, obtaining near-optimal solutions for large-scale problems is still challenging due to its NP-hardness. Recent efforts in data-driven methods face challenges of the need for hard-to-obtain supervision and issues with high variance in gradient estimations, leading to slow convergence and highly sub-optimal solutions. We address these issues by reformulating MTSP as a bilevel optimization problem, using the concept of imperative learning (IL). This involves introducing an allocation network that decomposes the MTSP into multiple single-agent traveling salesman problems (TSPs). The longest tour from these TSP solutions is then used to self-supervise the allocation network, resulting in a new self-supervised, bilevel, end-to-end learning framework, which we refer to as imperative MTSP (iMTSP). Additionally, to tackle the high-variance gradient issues during the optimization, we introduce a control variate-based gradient estimation algorithm. Our experiments showed that these innovative designs enable our gradient estimator to converge 20 × 20\times 20 × faster than the advanced reinforcement learning baseline, and find up to 80 % percent 80 80\% 80 % shorter tour length compared with Google OR-Tools MTSP solver, especially in large-scale problems (e.g. 1000 1000 1000 1000 cities and 15 15 15 15 agents).

I Introduction

The multiple traveling salesman problem (MTSP) seeks tours for multiple agents such that all cities are visited exactly once while minimizing an objective function defined over the tours. MTSP arises in numerous robotics topics that require a team of robots to collectively visit many target locations such as unmanned aerial vehicles path planning  [ 1 , 2 ] , automated agriculture  [ 3 ] , warehouse logistics  [ 4 ] . As their names suggest, Min-Sum MTSP minimizes the sum of tour lengths, while Min-Max MTSP minimizes the longest tour length, both of which are NP-hard  [ 5 ] to solve to optimality. 1 1 1 MTSP is challenging and renowned for its NP-hardness  [ 5 ] . Intuitively, MTSP involves many decision variables: both assigning the cities to the agents and determining the visiting order of the assigned cities. As an example, an MTSP with 100 100 100 100 cities and 10 10 10 10 agents involves 100 ! × 99 ! 10 ! × 89 ! ≈ 10 20000 100 99 10 89 superscript 10 20000 \frac{100!\times 99!}{10!\times 89!}\approx 10^{20000} divide start_ARG 100 ! × 99 ! end_ARG start_ARG 10 ! × 89 ! end_ARG ≈ 10 start_POSTSUPERSCRIPT 20000 end_POSTSUPERSCRIPT possible solutions, while the number of atoms in the observable universe is estimated to be “merely” in the range from 10 78 superscript 10 78 10^{78} 10 start_POSTSUPERSCRIPT 78 end_POSTSUPERSCRIPT to 10 82 superscript 10 82 10^{82} 10 start_POSTSUPERSCRIPT 82 end_POSTSUPERSCRIPT   [ 6 ] . In this paper, we focus on Min-Max MTSP while our method will also be applicable to Min-Sum MTSP. Min-Max MTSP is more often used when the application seeks to minimize the overall completion time  [ 7 ] . Due to the NP-hardness of MTSP, one must consider the trade-off between the solution optimality and the computational efficiency, since finding an optimal solution is often intractable for large problems.

A variety of classic (non-learning) approaches, including exact  [ 8 , 9 ] , approximation  [ 10 ] , and heuristic  [ 11 , 12 , 2 ] algorithms, have been developed to handle MTSP, but most of them consider minimizing the sum of tour lengths (Min-Sum), rather than the maximum tour length (Min-Max). In recent years, there has been a notable shift towards employing deep learning techniques to tackle TSP and MTSP  [ 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 ] . However, these methods still have fundamental limitations, particularly in their ability to generalize to unseen problem sizes, and in consistently finding high-quality solutions for large-scale problems. For deep learning-based methods that supervise the model with heuristic or exact solutions  [ 15 , 16 , 17 ] , they struggle with limited supervision on small-scale problems and lack feasible supervision for large-scale instances, leading to poor generalization. Reinforcement learning (RL)-based approaches  [ 14 , 18 , 19 , 20 ] usually exploit implementations of the policy gradient algorithm, such as the REINFORCE  [ 23 ] algorithm and its variants. These RL approaches face the issue of high-variance gradient estimations, which can result in slow convergence and highly sub-optimal solutions. Researchers have also developed strategies like training greedy policy networks  [ 19 , 18 , 21 ] or iteratively improving solutions  [ 22 ] , which often get stuck at local optima.

To enhance generalization and accelerate the training process, we reformulate the Min-Max MTSP as a bilevel optimization problem. This comprises an upper-level optimization that focuses on training a city allocation network, and a lower-level optimization that solves multiple signal-agent TSPs, inspired by imperative learning (IL)  [ 24 , 25 , 26 ] . Specifically, the allocation network is to assign each city to an agent, which decomposes the MTSP into multiple single-agent TSPs. Then, a classic TSP solver, which can quickly produce a near-optimal tour for a single-agent TSP with up to a few hundred cities, is employed to find a tour for each agent based on the allocation. A key aspect is that the upper-level optimization, namely the training of the allocation network, is supervised by the lower-level TSP solver. This metric-based supervision from the lower-level optimization results in an end-to-end, self-supervised framework for solving MTSP, which we refer to as imperative MTSP (iMTSP).

One technical obstacle when developing iMTSP is that the space of possible city allocations is discrete. As a result, the objective function, i.e., the maximum tour length given by the lower-level TSP solver, is non-differentiable to the city allocation, which prevents the back-propagation to the allocation network’s parameters. One of the solutions is to explore the policy gradient algorithm or the reparameterization trick  [ 27 ] , which often use Monte-Carlo methods to estimate the gradient. However, these methods can lead to gradient estimations with high variance since the space of city allocation is extremely large. To handle this difficulty, we introduce a control variate  [ 28 ] to reduce the variance of the gradient estimations. Parameterized by a trainable surrogate network running in parallel with the TSP solver, the control variate can be efficiently computed, and the overall algorithm can provide low variance gradient information through the non-differentiable solver and the discrete decision space. The main contributions of this paper are summarized as follows:

Framework : We formulate the MTSP as a bilevel optimization problem, introduce a new end-to-end, self-supervised framework for Min-Max MTSP. This decomposes a large-scale Min-Max MTSP into several smaller TSPs, each of which can be solved efficiently.

Methodology : To tackle the problem of bilevel optimization in discrete space, we introduce a control variate-based technique for back-propagation. This produces low-variance gradient estimations despite the non-differentiability of the lower-level optimization problem.

Experiments : We corroborate iMTSP in terms of efficiency and solution quality against both an RL-based and a classic (non-learning) methods. On large-scale problems, iMTSP achieves at most 80 % percent 80 80\% 80 % shorter tours and with only 1.6 % percent 1.6 1.6\% 1.6 % inference time compared with Google OR-Tools routing library  [ 29 ] . Also, iMTSP’s gradient estimator converges about 20 × 20\times 20 × faster and produces 3.2 ± 0.01 % plus-or-minus 3.2 percent 0.01 3.2\pm 0.01\% 3.2 ± 0.01 % shorter tours, compared with the RL-based approach  [ 14 ] .

II Related works

MTSP has been extensively studied. Analytical methods  [ 8 ] use graph theory, game theory, and combinatorial optimization, etc.  [ 30 ] , and can provide guarantees on solution optimality. However, these methods usually struggle at solving large-scale MTSP due to its NP-hardness.

Heuristic approaches for MTSP handle the challenge by decomposing the original problem into several phases which in turn reduces the computational burden of each phase. Examples are particle swarm optimization  [ 31 ] , ant colony optimization  [ 12 ] , etc  [ 32 , 33 ] . Although heuristic algorithms usually run faster than analytical approaches, they lack theoretic guarantees on solution quality and could produce highly sub-optimal solutions especially for large-scale problems with hundreds and thousands of cities.

Recently, researchers tried to solve MTSP with machine learning (ML) methods using recurrent neural networks (RNN)  [ 34 ] , transformer  [ 35 ] , etc. These learning-based methods usually scale well as the size of the problem increases. However, they may not generalize well to problem sizes outside the training set. As an early attempt  [ 17 ] , an RNN based method is developed and can handle TSP with up to 50 50 50 50 cities. Hu et al.  [ 14 ] propose a hybrid approach within the RL framework, which shows impressive generalization ability. However, their gradient estimator has high variance, which leads to slow convergence and sub-optimal solutions especially when dealing with large-scale problems. Other ML-based methods include  [ 19 , 18 , 21 , 22 ] . Note that most of them consider TSP instead of MTSP.

Imperative Learning As an emerging learning framework, imperative learning (IL) has inspired some pioneering works in simultaneous localization and mapping (SLAM)  [ 24 ] , path planning  [ 25 ] , and visual feature matching  [ 26 ] . The most significant difference between our work and theirs is that the lower-level optimization problems in their scenarios are all in continuous space, while iMTSP needs to deal with an extremely large discrete decision space.

Control Variate Control variate has been investigated by the ML community. In general, any policy gradient algorithm with a baseline or an actor-critic can be interpreted as an additive control variate method  [ 36 ] . Additionally, Grathwohl et.al.  [ 37 ] propose gradient estimators for a non-differentiable function with continuous and discrete inputs, respectively. Their insight is evaluating the control variate directly with a single sample estimation of the gradient variance. Our work leverages this insight. Gu et.al.  [ 38 ] produce a family of policy gradient methods using control variate to merge gradient information from both on-policy and off-policy updates. Control variate technique has also been used for meta-RL  [ 39 ] , federated learning  [ 40 ] , etc  [ 41 , 42 , 43 ] .

III Problem Formulation

where D ⁢ ( T j ) 𝐷 subscript 𝑇 𝑗 D(T_{j}) italic_D ( italic_T start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT ) is the cost of route T j subscript 𝑇 𝑗 T_{j} italic_T start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT . For easier understanding, we use Euclidean distance as the cost in this paper, i.e.,:

This section first elaborates on the reformulation of MTSP as a bilevel optimization problem, and then introduces the forward computation of the our framework and the control variate-based optimization algorithm.

IV-A Reformulation of MTSP

The MTSP formulation in Section  III is reformulated as the following bilevel optimization problem: For each instance ( X , 𝐱 𝐝 , M ) 𝑋 subscript 𝐱 𝐝 𝑀 (X,\mathbf{x_{d}},M) ( italic_X , bold_x start_POSTSUBSCRIPT bold_d end_POSTSUBSCRIPT , italic_M ) , the upper-level problem is to assign each city to an agent, and the lower-level problem is to compute the visiting order of assigned cities for each agent. We define f 𝑓 f italic_f as the allocation network with parameters θ 𝜃 \mathbf{\theta} italic_θ , and g 𝑔 g italic_g as the single-agent TSP solver with parameters μ 𝜇 \mathbf{\mu} italic_μ . The imperative MTSP (iMTSP) is defined as:

where a j subscript 𝑎 𝑗 a_{j} italic_a start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT is the allocation for agent j 𝑗 j italic_j sampling from the probability matrix by row, and L 𝐿 L italic_L returns the maximum route length among all agents. s 𝑠 s italic_s is a surrogate network with parameter γ 𝛾 \gamma italic_γ , which will be explained in detail in Section  IV-C along with the specific definitions of upper-level objectives. Specifically, the upper-level optimization consists of two separate steps: the upper-level cost U θ subscript 𝑈 𝜃 U_{\theta} italic_U start_POSTSUBSCRIPT italic_θ end_POSTSUBSCRIPT is to optimize the allocation network f ⁢ ( θ ) 𝑓 𝜃 f(\theta) italic_f ( italic_θ ) , while U γ subscript 𝑈 𝛾 U_{\gamma} italic_U start_POSTSUBSCRIPT italic_γ end_POSTSUBSCRIPT is to optimize the surrogate network s ⁢ ( γ ) 𝑠 𝛾 s(\gamma) italic_s ( italic_γ ) . The framework of iMTSP is shown in Fig.  1 .

Refer to caption

IV-B Forward Propagation Details

Iv-b 1 embedding, iv-b 2 allocation network.

As we have extracted the topological information into vector representations, we can now calculate the allocation matrix using the attention mechanism again. The keys 𝐤 ′ superscript 𝐤 ′ \mathbf{k}^{\prime} bold_k start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT and queries 𝐪 ′ superscript 𝐪 ′ \mathbf{q}^{\prime} bold_q start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT are computed from the city and agent embeddings, respectively, and the relative importance of each city to each agent is computed as:

The allocation matrix has a shape of N × M 𝑁 𝑀 N\times M italic_N × italic_M with N 𝑁 N italic_N and M 𝑀 M italic_M are the number of cities and agents, respectively. The model produces the final allocation by sampling each row of the allocation matrix. With the allocation, the MTSP is decomposed into M 𝑀 M italic_M TSPs. A classic TSP solver (such as Google OR-Tools) is invoked on each of the TSP to find the tour length of each TSP. The final return L 𝐿 L italic_L of the MTSP is the maximum tour length among all the TSPs. Because the TSP solver is non-differentiable and the allocation variables are discrete, network optimization is very challenging.

IV-C Optimization

Now we demonstrate how the non-differentiabiliy prevents us from using the analytical gradient, and how our control-variate approach can pass low-variance gradient estimations through the classic solver and the discrete allocation space.

IV-C 1 Gradient

𝜃 {\frac{\partial\mu^{*}}{\partial\theta}} divide start_ARG ∂ italic_μ start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT end_ARG start_ARG ∂ italic_θ end_ARG , the optimization process in g ⁢ ( ⋅ ) 𝑔 ⋅ g(\cdot) italic_g ( ⋅ ) is not differentiable; and (iii) μ ∗ superscript 𝜇 \mu^{*} italic_μ start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT and θ 𝜃 \theta italic_θ related implicitly. To deal with the non-differentiability, we can use the Log-derivative trick, which has been widely used in RL, and estimates the above gradient as

However, our experiments showed that this estimator provides a gradient with a high variance, which slows down the convergence rate and compromises the solution quality.

IV-C 2 Control Variate

To address the above issue, we introduce a control variate  [ 28 ] to reduce the variance of a stochastic estimator. Suppose d 𝑑 d italic_d (as in derivative) is a random variable (RV), h ⁢ ( d ) ℎ 𝑑 h(d) italic_h ( italic_d ) is an estimator of 𝔼 ⁢ ( d ) 𝔼 𝑑 \mathbb{E}(d) blackboard_E ( italic_d ) , the control variate c ⁢ ( d ) 𝑐 𝑑 c(d) italic_c ( italic_d ) is a function of d 𝑑 d italic_d whose mean value is known. Define a new estimator with a control variate as:

When constant ζ 𝜁 \zeta italic_ζ is properly chosen, h ⁢ ( d ) n ⁢ e ⁢ w ℎ subscript 𝑑 𝑛 𝑒 𝑤 h(d)_{new} italic_h ( italic_d ) start_POSTSUBSCRIPT italic_n italic_e italic_w end_POSTSUBSCRIPT has the same expected value but lower variance than h ⁢ ( d ) ℎ 𝑑 h(d) italic_h ( italic_d ) , as long as the control variate c ⁢ ( d ) 𝑐 𝑑 c(d) italic_c ( italic_d ) is correlated to h ⁢ ( d ) ℎ 𝑑 h(d) italic_h ( italic_d ) . We briefly summarize the underlying principle of control variate technique  [ 45 ] as follows and omit the dependency on d 𝑑 d italic_d for simplicity.

ℎ 𝜁 𝑐 𝔼 𝑐 h_{new}=h+\zeta(c-\mathbb{E}(c)) italic_h start_POSTSUBSCRIPT italic_n italic_e italic_w end_POSTSUBSCRIPT = italic_h + italic_ζ ( italic_c - blackboard_E ( italic_c ) ) has same expected value but smaller variance, when the constant ζ 𝜁 \zeta italic_ζ is properly chosen and c 𝑐 c italic_c is correlated with h ℎ h italic_h .

The variance of the new estimator is

Differentiate the above equation w.r.t. γ 𝛾 \gamma italic_γ and set the derivative to zero, the optimal choice of ζ 𝜁 \zeta italic_ζ is

superscript 𝜁 2 Var 𝑐 2 𝜁 Cov ℎ 𝑐 0 \zeta^{2}\mathrm{Var}(c)+2\zeta\mathrm{Cov}(h,c)<0 italic_ζ start_POSTSUPERSCRIPT 2 end_POSTSUPERSCRIPT roman_Var ( italic_c ) + 2 italic_ζ roman_Cov ( italic_h , italic_c ) < 0 , we get ζ ∈ ( − 2 ⁢ C ⁢ o ⁢ v ⁢ ( h , c ) Var ⁢ ( c ) , 0 ) 𝜁 2 C o v ℎ 𝑐 Var 𝑐 0 \zeta\in(\frac{-2\mathrm{Cov}(h,c)}{\mathrm{Var}(c)},0) italic_ζ ∈ ( divide start_ARG - 2 roman_C roman_o roman_v ( italic_h , italic_c ) end_ARG start_ARG roman_Var ( italic_c ) end_ARG , 0 ) , which indicates that as long as k 𝑘 k italic_k is set in this range, Var ⁢ ( h new ) Var subscript ℎ new \mathrm{Var}(h_{\text{new}}) roman_Var ( italic_h start_POSTSUBSCRIPT new end_POSTSUBSCRIPT ) is less than Var ⁢ ( h ) Var ℎ \mathrm{Var}(h) roman_Var ( italic_h ) . When h ℎ h italic_h and c 𝑐 c italic_c are highly correlated and are of similar ranges, Cov ⁢ ( h , c ) ≈ Var ⁢ ( c ) Cov ℎ 𝑐 Var 𝑐 \mathrm{Cov}(h,c)\approx\mathrm{Var}(c) roman_Cov ( italic_h , italic_c ) ≈ roman_Var ( italic_c ) , thus ζ ∗ ≈ − 1 superscript 𝜁 1 \zeta^{*}\approx-1 italic_ζ start_POSTSUPERSCRIPT ∗ end_POSTSUPERSCRIPT ≈ - 1 , which is our empirical choice of ζ 𝜁 \zeta italic_ζ .

Inspired by the control variant gradient estimator ( 10 ) we design a lower variance, unbiased gradient estimator using trainable surrogate network s 𝑠 s italic_s . Choose the allocation log-derivative estimator as h ⁢ ( d ) ℎ 𝑑 h(d) italic_h ( italic_d ) in ( 10 ), and replace c ⁢ ( d ) 𝑐 𝑑 c(d) italic_c ( italic_d ) and 𝔼 ⁢ [ c ⁢ ( d ) ] 𝔼 delimited-[] 𝑐 𝑑 \mathbb{E}[c(d)] blackboard_E [ italic_c ( italic_d ) ] with the surrogate log-derivative estimator and the actual surrogate network gradient, respectively, the upper-level costs U θ subscript 𝑈 𝜃 U_{\theta} italic_U start_POSTSUBSCRIPT italic_θ end_POSTSUBSCRIPT of our bilevel framework is:

where the constant ζ 𝜁 \zeta italic_ζ in ( 10 ) is substituted with − 1 1 -1 - 1 . L ′ superscript 𝐿 ′ L^{\prime} italic_L start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT is output of the surrogate network (control variate) but is taken as a constant by cutting its gradients. In turn, our gradient for the allocation network parameters θ 𝜃 \theta italic_θ is:

IV-C 3 Surrogate Network

We implement the idea of control variate with a surrogate network s ⁢ ( γ ) 𝑠 𝛾 s(\gamma) italic_s ( italic_γ ) in parallel with the TSP solver. Note that the surrogate network takes the allocation matrix P 𝑃 P italic_P as its input and predicts the maximum tour length, while the inputs of the actual TSP solver are allocations A 𝐴 A italic_A and coordinate data X 𝑋 X italic_X . Naively optimizing the surrogate network to imitate the input-output map of the TSP solver is ineffective because learning such a map does not guarantee learning correct gradient information. Since we require the surrogate network (control variate) to reduce the gradient variance of allocation parameters, we directly optimize the surrogate parameters to minimize a single sample estimation of the allocation gradient variance. Thus, the upper-level objective U γ subscript 𝑈 𝛾 U_{\gamma} italic_U start_POSTSUBSCRIPT italic_γ end_POSTSUBSCRIPT for the surrogate network is

𝜃 2 \rm{Var}(\frac{\partial U_{\theta}}{\partial\theta})=\mathbb{E}[(\frac{% \partial U_{\theta}}{\partial\theta})^{2}]-\mathbb{E}[(\frac{\partial U_{% \theta}}{\partial\theta})]^{2} roman_Var ( divide start_ARG ∂ roman_U start_POSTSUBSCRIPT italic_θ end_POSTSUBSCRIPT end_ARG start_ARG ∂ italic_θ end_ARG ) = blackboard_E [ ( divide start_ARG ∂ roman_U start_POSTSUBSCRIPT italic_θ end_POSTSUBSCRIPT end_ARG start_ARG ∂ italic_θ end_ARG ) start_POSTSUPERSCRIPT 2 end_POSTSUPERSCRIPT ] - blackboard_E [ ( divide start_ARG ∂ roman_U start_POSTSUBSCRIPT italic_θ end_POSTSUBSCRIPT end_ARG start_ARG ∂ italic_θ end_ARG ) ] start_POSTSUPERSCRIPT 2 end_POSTSUPERSCRIPT , the gradient of the surrogate network is

𝜃 2 \frac{\partial}{\partial\gamma}\mathbb{E}[(\frac{\partial U_{\theta}}{\partial% \theta})^{2}] divide start_ARG ∂ end_ARG start_ARG ∂ italic_γ end_ARG blackboard_E [ ( divide start_ARG ∂ italic_U start_POSTSUBSCRIPT italic_θ end_POSTSUBSCRIPT end_ARG start_ARG ∂ italic_θ end_ARG ) start_POSTSUPERSCRIPT 2 end_POSTSUPERSCRIPT ] is always zero because the surrogate network has no explicit influence on the return L 𝐿 L italic_L . For ease of understanding, we summarize our control variate-based bilevel optimization method in Algorithm 1 .

V Experiments

We next conduct comprehensive experiments to demonstrate the generalization ability, computational efficiency, and convergence speed of our iMTSP framework. We focus our experiments on large-scale settings ( ≥ 400 absent 400 \geq 400 ≥ 400 cities) because current classic solvers can already efficiently find near-optimal solutions for small-scale problems.

V-A Baselines

To demonstrate the advantages of our method, we compare it with both classic methods and learning-based methods. Specifically, we select a state-of-the-art reinforcement learning (RL)-based model from  [ 14 ] as a baseline. Their framework can efficiently solve MTSPs with up to a few thousand cities. Using S-batched REINFORCE, it has shown outstanding generalization ability and has a reduced variance for the gradient estimator than the vanilla REINFORCE  [ 23 ] . The other potential baseline methods  [ 13 , 46 , 20 ] either don’t provide source codes or cannot be directly applied to our settings. We also compare iMTSP with a well-known meta-heuristic method implemented by the Google OR-Tools routing library  [ 18 , 22 , 14 ] . It provides near-optimal solutions to MTSPs with a few hundred cities and is a popular MTSP baseline  [ 29 ] . For abbreviation, we will refer to the two methods as an RL baseline and Google OR-Tools. All approaches are tested locally with the same hardware.

Refer to caption

V-B Experiment Setting

We learn from  [ 17 , 22 , 18 ] that, existing classic and learning-based approaches can handle MTSPs with about 150 150 150 150 cities, but their performance will significantly compromise with 400 400 400 400 or more cities. To demonstrate iMTSP’s ability to generalization and handle large-scale problems, we conduct experiments on training sets with 50 50 50 50 to 100 100 100 100 cities but test the models on problems with 400 400 400 400 to 1000 1000 1000 1000 cities. We believe this challenging setting can reflect the generalization ability of the proposed models.

In our tests, all the instances are generated by uniformly sampling N 𝑁 N italic_N coordinates in a unit rectangular so that both x 𝑥 x italic_x and y 𝑦 y italic_y coordinates are in the range of 0 0 to 1 1 1 1 . We employ a batch size of 512 512 512 512 and a training-to-validation data size ratio of 10 : 1 : 10 1 10:1 10 : 1 . The test set consists of i.i.d. batches but with a larger number of cities ( 400 400 400 400 to 1000 1000 1000 1000 ) as aforementioned.

Specifically, agents and cities are embedded into 64 64 64 64 dimensional vectors. The allocation network contains one attention layer, where keys, queries, and values are of 128 128 128 128 , 16 16 16 16 , and 16 16 16 16 dimensions, respectively. The clip constant α 𝛼 \alpha italic_α in ( 6c ) is set to be 10 10 10 10 . The surrogate network consists of three fully connected layers, whose hidden dimension is 256 256 256 256 and activation function is tanh . Google OR-Tools provides the TSP solver in iMTSP and the MTSP solver as a baseline. It uses the “Global Cheapest Arc” strategy to generate its initial solutions and uses “Guided local search” for local improvements. All the strategies are defined in  [ 29 ] and we selected the best options in the experiments.

V-C Quantitative Performance

We next conduct a quantitative performance comparison with the two baseline methods and show it in Table  I . We focus on large-scale MTSPs since many approaches can well solve small-size MTSPs but very few algorithms (both classic or learning-based) can deal with large-scale problems.

V-C 1 Comparison with Google OR-Tools

By decomposing a large MTSP into several small TSPs, iMTSP is stronger to handle large-scale problems. We demonstrate such a merit by comparing our model with the classic routing module in OR-Tools, which is given 300 300 300 300 seconds time budget. The results are shown in Table I . Specially, these route lengths of OR-Tools are averaged over 10 10 10 10 test instances. OR-Tools appears to be very inferior because it cannot converge to a local minimum given 300 300 300 300 seconds time budget. In our experiments, OR-Tools can handle 500 500 500 500 or less cities with 1800 1800 1800 1800 seconds budget. However, it does not converge even computing for 7200 7200 7200 7200 seconds with 600 600 600 600 or more cities, indicating that its computational complexity grows steeply w.r.t. the problem size. Also, the difference of the route length increases as the problem size becomes larger and larger. Remember that the final routes of iMTSP are also solved by Google routing module, while it can easily handle MTSP with up to a few thousand cities with the help of the allocation network.

Refer to caption

V-C 2 Comparison with the RL Baseline

To show the effectiveness of our control variate-based optimization algorithm, we also compare iMTSP with the RL baseline  [ 14 ] which shares a similar forward process as iMTSP. In most cases, training on bigger problems leads to a better generalization ability on large-scale problems, but it also indicates larger parameter space, more complicated gradient information, and longer training time. This makes the quality of the gradient very crucial. As presented in the Table  I , iMTSP outperforms the RL baseline in most cases, providing solutions with 3.2 ± 0.01 % plus-or-minus 3.2 percent 0.01 3.2\pm 0.01\% 3.2 ± 0.01 % shorter maximum route length over the RL baseline on average. When the models are trained with 100 100 100 100 cities, the difference between the route lengths monotonically increases from 0.4 % percent 0.4 0.4\% 0.4 % to 8.0 % percent 8.0 8.0\% 8.0 % and from 3.4 % percent 3.4 3.4\% 3.4 % to 8.9 % percent 8.9 8.9\% 8.9 % , respectively with 10 10 10 10 and 15 15 15 15 agents. The results demonstrate that with the lower-variance gradient provided by our control variate-based optimization algorithm, iMTSP usually converges to better solutions when being trained on large-scale instances.

V-D Qualitative Performance

To find out the specific advantages in iMTSP’s solutions, we plot and compare the results of iMTSP and two baselines on two example instances. Fig.  2 provides a visualization of the solutions from both baselines and iMTSP on two instances with 5 5 5 5 agents and 500 500 500 500 cities. The depot of the first instance is close to the center of cities while it’s off the center in the second instance. In Fig.  2(d) , there are long straight partial routes (e.g., blue and purple), indicating some agents have travelled for a long distance before they visit their first destination. Also, some circular parts exist in the OR-Tools’ solutions (e.g., the green route in Fig.  2(b) ) meaning that this agent travels for extra distance to visit the cities on the circle. Both of these are typical symptoms of sub-optimality. Such symptoms are not observed in the two solutions from iMTSP. In both instances, iMTSP produces the best performance. Note that both the RL baseline and iMTSP finish their computation within a few seconds while OR-Tools takes 1800 1800 1800 1800 seconds to produce comparable solutions.

V-E Efficiency Analysis

Since iMTSP contains both a learning-based allocation network and a classic TSP solver, it is important to identify the bottleneck of the architecture for future improvements. As in Table II , with 5 5 5 5 , 10 10 10 10 , and 15 15 15 15 agents, the computing time of our model are 4.85 4.85 4.85 4.85 seconds, 1.98 1.98 1.98 1.98 seconds, and 1.35 1.35 1.35 1.35 seconds, respectively, to solve one instance with 1000 1000 1000 1000 cities. Note that the computing time decrease as the number of agents increases. This fact indicates that the major computational bottleneck is the TSP solvers rather than the allocation network, because more agents are required to run more times of TSP solvers. One of the promising solutions to further reduce our computing time is to create multiple threads to run the TSP solvers in parallel since the TSPs in the lower-level optimization of iMSTP are independent. Since this is not the focus of this paper, we put it as a future work.

V-F Gradient Variance

As demonstrated in Section  IV-C , with an optimized surrogate network, the variance of iMTSP’s gradient are expected to be smaller than the gradient from the vanilla REINFORCE algorithm  [ 23 ] . We verify such a hypothesis by explicitly recording the mini-batch gradient variance during the training process. The experiment is conducted twice with 10 10 10 10 agents visiting 50 50 50 50 cities and 100 100 100 100 cities. Training data are divided into several mini-batches, each of which contains 32 32 32 32 instances. The gradient is computed and stored for every mini-batch, and the variance is later computed with these stored gradient. The network parameters are updated with the average gradient of the whole batch. The results are shown in Fig.  3 , where the x 𝑥 x italic_x -axis denotes the number of iterations and the y 𝑦 y italic_y -axis represents the natural logarithm of the summed variance of all trainable parameters in the allocation network. It is observed that the gradient variance of our iMTSP is much smaller and converges 20 × 20\times 20 × faster than the RL baseline. This verifies the effectiveness of our control variate-based bilevel optimization process.

V-G Ablation Study

To confirm that the improvements of solution quality are majorly contributed by the control variate-based optimization algorithm, we also track the performance of the fine-tuned network with the baseline optimization method. As shown in Table III , the route lengths from our control variate-based optimization algorithm are averagely 7.8 % ± 2.1 % plus-or-minus percent 7.8 percent 2.1 7.8\%\pm 2.1\% 7.8 % ± 2.1 % shorter than that from the baseline algorithm. We can also observe that better results always come from iMTSP, which indicates that the better solution quality is mainly contributed by our control variate-based optimization algorithm.

VI Conclusion and Future Work

In the paper, we reformulate the Min-Max MTSP as a bilevel optimization problem. We introduce a self-supervised framework iMTSP, which can efficiently handle large-scale MTSP with thousands of cities. With the control variate-based optimization algorithm, iMTSP produces a low-variance gradient through a non-differentiable TSP solver and a discrete allocation space to update the allocation network. Experimental results demonstrated the advantages of iMTSP in solution quality, computational efficiency, and optimization stability. In future work, we will also consider the constraints of environmental obstacles and inter-agent collision, which will enable iMTSP to conduct multi-agent path planning in real-world scenarios.

VII Acknowledgements

This work was, in part, funded by the DARPA grant DARPA-PS-23-13. The views and conclusions contained in this document are those of the authors and should not be interpreted as representing the official policies, either expressed or implied, of DARPA.

  • [1] K. Sundar and S. Rathinam, “Algorithms for routing an unmanned aerial vehicle in the presence of refueling depots,” IEEE Transactions on Automation Science and Engineering , vol. 11, no. 1, pp. 287–294, 2013.
  • [2] Y. Ma, H. Zhang, Y. Zhang, R. Gao, Z. Xu, and J. Yang, “Coordinated optimization algorithm combining GA with cluster for multi-UAVs to multi-tasks task assignment and path planning,” in International Conference on Control and Automation .   IEEE, 2019, pp. 1026–1031.
  • [3] R. F. Carpio, J. Maiolini, C. Potena, E. Garone, G. Ulivi, and A. Gasparn, “Mp-stsp: A multi-platform steiner traveling salesman problem formulation for precision agriculture in orchards,” in International Conference on Robotics and Automation .   IEEE, 2021, pp. 2345–2351.
  • [4] Z. Ren, S. Rathinam, and H. Choset, “CBSS: A new approach for multiagent combinatorial path finding,” IEEE Transactions on Robotics , vol. 39, no. 4, pp. 2669–2683, 2023.
  • [5] T. Bektas, “The multiple traveling salesman problem: an overview of formulations and solution procedures,” omega , vol. 34, no. 3, pp. 209–219, 2006.
  • [6] E. Gaztañaga, “The mass of our observable universe,” Monthly Notices of the Royal Astronomical Society: Letters , vol. 521, no. 1, pp. L59–L63, 2023.
  • [7] J. Park, C. Kwon, and J. Park, “Learn to solve the min-max multiple traveling salesmen problem with reinforcement learning,” in Proceedings of the 2023 International Conference on Autonomous Agents and Multiagent Systems , 2023, pp. 878–886.
  • [8] A. M. Ham, “Integrated scheduling of m-truck, m-drone, and m-depot constrained by time-window, drop-pickup, and m-visit using constraint programming,” Transportation Research Part C: Emerging Technologies , vol. 91, pp. 1–14, 2018.
  • [9] Z. Ren, S. Rathinam, and H. Choset, “MS: A new exact algorithm for multi-agent simultaneous multi-goal sequencing and path finding,” in International Conference on Robotics and Automation .   IEEE, 2021, pp. 11 560–11 565.
  • [10] K. Bérczi, M. Mnich, and R. Vincze, “Approximations for many-visits multiple traveling salesman problems,” Omega , vol. 116, p. 102816, 2023.
  • [11] M. A. Al-Omeer and Z. H. Ahmed, “Comparative study of crossover operators for the MTSP,” in 2019 International Conference on Computer and Information Sciences .   IEEE, 2019, pp. 1–6.
  • [12] R. Necula, M. Breaban, and M. Raschip, “Tackling the bi-criteria facet of multiple traveling salesman problem with ant colony systems,” in 27th International Conference on Tools with Artificial Intelligence .   IEEE, 2015, pp. 873–880.
  • [13] H. Liang, Y. Ma, Z. Cao, T. Liu, F. Ni, Z. Li, and J. Hao, “SplitNet: a reinforcement learning based sequence splitting method for the MinMax multiple travelling salesman problem,” in Proceedings of the AAAI Conference on Artificial Intelligence , vol. 37, no. 7, 2023, pp. 8720–8727.
  • [14] Y. Hu, Y. Yao, and W. S. Lee, “A reinforcement learning approach for optimizing multiple traveling salesman problems over graphs,” Knowledge-Based Systems , vol. 204, p. 106244, 2020.
  • [15] L. Xin, W. Song, Z. Cao, and J. Zhang, “NeuroLKH: Combining deep learning model with Lin-Kernighan-Helsgaun heuristic for solving the traveling salesman problem,” Advances in Neural Information Processing Systems , vol. 34, pp. 7472–7483, 2021.
  • [16] S. Miki, D. Yamamoto, and H. Ebara, “Applying deep learning and reinforcement learning to traveling salesman problem,” in International Conference on Computing, Electronics and Communications Engineering .   IEEE, 2018, pp. 65–70.
  • [17] O. Vinyals, M. Fortunato, and N. Jaitly, “Pointer networks,” Advances in Neural Information Processing Systems , vol. 28, 2015.
  • [18] W. Kool, H. Van Hoof, and M. Welling, “Attention, learn to solve routing problems!” arXiv preprint arXiv:1803.08475 , 2018.
  • [19] M. Nazari, A. Oroojlooy, L. Snyder, and M. Takác, “Reinforcement learning for solving the vehicle routing problem,” Advances in Neural Information Processing Systems , vol. 31, 2018.
  • [20] J. Park, S. Bakhtiyar, and J. Park, “Schedulenet: Learn to solve multi-agent scheduling problems with reinforcement learning,” arXiv preprint arXiv:2106.03051 , 2021.
  • [21] E. Khalil, H. Dai, Y. Zhang, B. Dilkina, and L. Song, “Learning combinatorial optimization algorithms over graphs,” Advances in Neural Information Processing Systems , vol. 30, 2017.
  • [22] Y. Wu, W. Song, Z. Cao, J. Zhang, and A. Lim, “Learning improvement heuristics for solving routing problems,” IEEE Transactions on Neural Networks and Learning Systems , vol. 33, no. 9, pp. 5057–5069, 2021.
  • [23] R. J. Williams, “Simple statistical gradient-following algorithms for connectionist reinforcement learning,” Machine Learning , vol. 8, pp. 229–256, 1992.
  • [24] T. Fu, S. Su, Y. Lu, and C. Wang, “iSLAM: Imperative SLAM,” IEEE Robotics and Automation Letters (RA-L) , 2024.
  • [25] F. Yang, C. Wang, C. Cadena, and M. Hutter, “iPlanner: Imperative path planning,” in Robotics: Science and Systems (RSS) , 2023.
  • [26] Z. Zhan, D. Gao, Y.-J. Lin, Y. Xia, and C. Wang, “iMatching: Imperative correspondence learning,” arXiv preprint arXiv:2312.02141 , 2023.
  • [27] M. Figurnov, S. Mohamed, and A. Mnih, “Implicit reparameterization gradients,” Advances in Neural Information Processing Systems , vol. 31, 2018.
  • [28] B. L. Nelson, “Control variate remedies,” Operations Research , vol. 38, no. 6, pp. 974–992, 1990.
  • [29] L. Perron and F. Didier, “ORTools routing options,” Google, 2023. [Online]. Available: https://developers.google.com/optimization/routing/routing_options
  • [30] O. Cheikhrouhou and I. Khoufi, “A comprehensive survey on the multiple traveling salesman problem: Applications, approaches and taxonomy,” Computer Science Review , vol. 40, p. 100369, 2021.
  • [31] C. Wei, Z. Ji, and B. Cai, “Particle swarm optimization for cooperative multi-robot task allocation: a multi-objective approach,” IEEE Robotics and Automation Letters , vol. 5, no. 2, pp. 2530–2537, 2020.
  • [32] P. Kitjacharoenchai, M. Ventresca, M. Moshref-Javadi, S. Lee, J. M. Tanchoco, and P. A. Brunese, “Multiple traveling salesman problem with drones: Mathematical model and heuristic approach,” Computers and Industrial Engineering , vol. 129, pp. 14–30, 2019.
  • [33] C. C. Murray and R. Raj, “The multiple flying sidekicks traveling salesman problem: Parcel delivery with multiple drones,” Transportation Research Part C: Emerging Technologies , vol. 110, pp. 368–398, 2020.
  • [34] D. E. Rumelhart, G. E. Hinton, R. J. Williams et al. , “Learning internal representations by error propagation,” 1985.
  • [35] A. Vaswani, N. Shazeer, N. Parmar, J. Uszkoreit, L. Jones, A. N. Gomez, Ł. Kaiser, and I. Polosukhin, “Attention is all you need,” Advances in Neural Information Processing Systems , vol. 30, 2017.
  • [36] E. Greensmith, P. L. Bartlett, and J. Baxter, “Variance reduction techniques for gradient estimates in reinforcement learning.” Journal of Machine Learning Research , vol. 5, no. 9, 2004.
  • [37] W. Grathwohl, D. Choi, Y. Wu, G. Roeder, and D. Duvenaud, “Backpropagation through the void: Optimizing control variates for black-box gradient estimation,” arXiv preprint arXiv:1711.00123 , 2017.
  • [38] S. S. Gu, T. Lillicrap, R. E. Turner, Z. Ghahramani, B. Schölkopf, and S. Levine, “Interpolated policy gradient: Merging on-policy and off-policy gradient estimation for deep reinforcement learning,” Advances in Neural Information Processing Systems , vol. 30, 2017.
  • [39] H. Liu, R. Socher, and C. Xiong, “Taming MAML: Efficient unbiased meta-reinforcement learning,” in International Conference on Machine Learning .   PMLR, 2019, pp. 4061–4071.
  • [40] S. P. Karimireddy, S. Kale, M. Mohri, S. Reddi, S. Stich, and A. T. Suresh, “Scaffold: Stochastic controlled averaging for federated learning,” in International Conference on Machine Learning .   PMLR, 2020, pp. 5132–5143.
  • [41] J. Baker, P. Fearnhead, E. B. Fox, and C. Nemeth, “Control variates for stochastic gradient MCMC,” Statistics and Computing , vol. 29, pp. 599–615, 2019.
  • [42] T. Geffner and J. Domke, “Using large ensembles of control variates for variational inference,” Advances in Neural Information Processing Systems , vol. 31, 2018.
  • [43] W. Guo, S. Wang, P. Ding, Y. Wang, and M. I. Jordan, “Multi-source causal inference using control variates,” arXiv preprint arXiv:2103.16689 , 2021.
  • [44] J. Gilmer, S. S. Schoenholz, P. F. Riley, O. Vinyals, and G. E. Dahl, “Neural message passing for quantum chemistry,” in International Conference on Machine Learning .   PMLR, 2017, pp. 1263–1272.
  • [45] S. Meyn, Control techniques for complex networks .   Cambridge University Press, 2008.
  • [46] H. Gao, X. Zhou, X. Xu, Y. Lan, and Y. Xiao, “AMARL: An attention-based multiagent reinforcement learning approach to the min-max multiple traveling salesmen problem,” IEEE Transactions on Neural Networks and Learning Systems , 2023.

IMAGES

  1. Solved The Traveling Salesman ProblemStarting from city 1,

    methods travelling salesman problem

  2. Traveling Salesman Problem (TSP) with Miller-Tucker-Zemlin (MTZ) in

    methods travelling salesman problem

  3. PPT

    methods travelling salesman problem

  4. PPT

    methods travelling salesman problem

  5. Traveling Salesman Problem

    methods travelling salesman problem

  6. PPT

    methods travelling salesman problem

VIDEO

  1. Travelling Salesman Problem

  2. Travelling salesman problem

  3. 3.14. 1 Travelling Salesman Problem Branch and Bound

  4. Traveling Salesman Problem| NP- Class Problem

  5. 3.12 Travelling Salesman Problem Dynamic Programming

  6. 2.7 Travelling salesman problem

COMMENTS

  1. Travelling salesman problem

    It is used as a benchmark for many optimization methods. Even though the problem is computationally difficult, ... In March 2005, the travelling salesman problem of visiting all 33,810 points in a circuit board was solved using Concorde TSP Solver: a tour of length 66,048,945 units was found, and it was proven that no shorter tour exists. The ...

  2. Traveling Salesman Problem (TSP) Implementation

    A TSP tour in the graph is 1-2-4-3-1. The cost of the tour is 10+25+30+15 which is 80. The problem is a famous NP-hard problem. There is no polynomial-time known solution for this problem. Examples: Output of Given Graph: minimum weight Hamiltonian Cycle : 10 + 25 + 30 + 15 := 80. In this post, the implementation of a simple solution is discussed.

  3. Travelling salesman problem explained

    Defining the Travelling Salesman Problem: A Comprehensive Overview. The Travelling Salesman Problem, often abbreviated as TSP, has a strong footing in the realm of computer science. To the untrained eye, it presents itself as a puzzle: a salesperson or traveling salesman must traverse through a number of specific cities before an ending point ...

  4. 9 Best Algorithms for Traveling Salesman Problem Solutions

    The Christofides Algorithm is a well-known. The Concorde TSP Solver is widely regarded as the state-of-the-art exact algorithm for Traveling Salesman Problem solutions. It is notable for its ability to handle large and complex instances efficiently, combining multiple advanced techniques to find optimal solutions.

  5. Traveling Salesman Problem: Exact Solutions vs. Heuristic vs

    The Traveling Salesman Problem (TSP) is a well-known challenge in computer science, mathematical optimization, and operations research that aims to locate the most efficient route for visiting a group of cities and returning to the initial city.TSP is an extensively researched topic in the realm of combinatorial optimization.It has practical uses in various other optimization problems ...

  6. Algorithms for the Travelling Salesman Problem

    The Traveling Salesman Problem (TSP) is the challenge of finding the shortest path or shortest possible route for a salesperson to take, given a starting point, a number of cities (nodes), and optionally an ending point. ... For larger real-world travelling salesman problems, when manual methods such as Google Maps Route Planner or Excel route ...

  7. Travelling Salesman Problem: Definition, Algorithms & Solutions

    The Traveling Salesman Problem (TSP) is all about figuring out the shortest route for a salesperson to visit several cities, starting from one place and possibly ending at another. It's a well-known problem in computer science and operations research, with real-world uses in logistics and delivery. There are many possible routes, but the goal ...

  8. 6.6: Hamiltonian Circuits and the Traveling Salesman Problem

    Select the cheapest unused edge in the graph. 2. Repeat step 1, adding the cheapest unused edge to the circuit, unless: a. adding the edge would create a circuit that doesn't contain all vertices, or. b. adding the edge would give a vertex degree 3. 3. Repeat until a circuit containing all vertices is formed.

  9. How to Solve Traveling Salesman Problem

    The traveling salesman problem is a classic problem in combinatorial optimization. This problem is finding the shortest path a salesman should take to traverse a list of cities and return to the origin city. The list of cities and the distance between each pair are provided. TSP is beneficial in various real-life applications such as planning ...

  10. Heuristic Algorithms for the Traveling Salesman Problem

    The traveling salesman problem (TSP) involves finding the shortest path that visits n specified locations, starting and ending at the same place and visiting the other n-1 destinations exactly ...

  11. Travelling Salesman Problem (Greedy Approach)

    The travelling salesman problem is a graph computational problem where the salesman needs to visit all cities (represented using nodes in a graph) in a list just once and the distances (represented using edges in the graph) between all these cities are known. The solution that is needed to be found for this problem is the shortest possible ...

  12. Travelling Salesman Problem: Python, C++ Algorithm

    The branch-and-bound method: The problem is broken down into sub-problems in this approach. The solution of those individual sub-problems would provide an optimal solution. This tutorial will demonstrate a dynamic programming approach, the recursive version of this branch-and-bound method, to solve the traveling salesman problem.

  13. 12.9 Traveling Salesperson Problem

    For the following exercises, use your solutions to the indicated exercises to compare the results of the brute force method to the results of the nearest neighbor method for each traveling salesman problem of finding a reasonably short route to leave from city U, visit each of the other cities listed and return to city U. Indicate whether the ...

  14. Travelling Salesman Problem using Dynamic Programming

    The problem is a famous NP-hard problem. There is no polynomial-time know solution for this problem. The following are different solutions for the traveling salesman problem. Naive Solution: 1) Consider city 1 as the starting and ending point. 2) Generate all (n-1)!

  15. Traveling salesman problem heuristics: Leading methods, implementations

    1. Introduction. The traveling salesman problem (TSP) is undoubtedly the most extensively studied problem in combinatorial optimization. In popular language, the TSP can be described as the problem of finding a minimum distance tour of n cities, starting and ending at the same city and visiting each other city exactly once. In spite of the simplicity of its problem statement, the TSP is ...

  16. PDF Networks 3: Traveling salesman problem

    The Traveling Salesman Problem and Heuristics . Quotes of the day 2 "Problem solving is hunting. It is savage pleasure and we are born to it." -- Thomas Harris "An algorithm must be seen to be believed." -- Donald Knuth . Heuristics A heuristic is a technique designed for solving a problem more quickly when classic methods are too

  17. Travelling Salesman Problem

    The Travelling Salesman Problem (also known as the Travelling Salesperson Problem or TSP) is an NP-hard graph computational problem where the salesman must visit all cities (denoted using vertices in a graph) given in a set just once. The distances (denoted using edges in the graph) between all these cities are known.

  18. Travelling Salesman Problem (TSP) using Different Approaches

    There are various approaches to finding the solution to the travelling salesman problem- simple (naïve) approach, dynamic programming approach, and greedy approach. Let's explore each approach in detail: 1. Simple Approach. Consider city 1 as the starting and ending point. Since the route is cyclic, we can consider any point as a starting point.

  19. Traveling Salesman Problem (TSP) in Python

    The Traveling Salesman Problem (TSP) is a classic algorithmic problem in the fields of computer science and operations research. It involves finding the shortest possible route that visits a set of cities and returns to the origin city. The challenge of TSP lies in its NP-hard nature, meaning that as the number of cities increases, the problem becomes exponentially more complex to solve optimally.

  20. 12.10: Traveling Salesperson Problem

    For the following exercises, use your solutions to the indicated exercises to compare the results of the brute force method to the results of the nearest neighbor method for each traveling salesman problem of finding a reasonably short route to leave from city U, visit each of the other cities listed and return to city U. Indicate whether the ...

  21. What is a Traveling Salesman Problem? Explained and Solved.

    Here are the Top 5 solutions to the Traveling Salesman Problem (TSP): 1. Brute Force Algorithm. The Brute Force algorithm is a straight approach to solving the Traveling Salesman Problem (TSP). It systematically explores all possible routes to identify the shortest one among them all.

  22. The neural network methods for solving Traveling Salesman Problem

    Traveling Salesman Problem (TSP) is a main attention issue at present. Neural network can be used to solve combinatorial optimization problems. In recent years, there have existed many neural network methods for solving TSP, which has made a big step forward for solving combinatorial optimization problems. This paper reviews the neural network ...

  23. Travelling Salesman Problem

    Approach: This problem can be solved using Greedy Technique. Below are the steps: Create two primary data holders: A list that holds the indices of the cities in terms of the input matrix of distances between cities. Result array which will have all cities that can be displayed out to the console in any manner.

  24. iMTSP: Solving Min-Max Multiple Traveling Salesman Problem with

    The multiple traveling salesman problem (MTSP) seeks tours for multiple agents such that all cities are visited exactly once while minimizing an objective function defined over the tours. ... Z. Li, and J. Hao, "SplitNet: a reinforcement learning based sequence splitting method for the MinMax multiple travelling salesman problem," in ...

  25. Combinatorial lower bounds for the Generalized Traveling Salesman

    Low computational requirements of the proposed method are demonstrated in a solution of the Close-Enough Traveling Salesman Problem (CETSP), which is a special case of the TSPN with the disk ...