This device is not compatible.


Use Simulated Annealing for the Traveling Salesman Problem

In this project, we will use simulated annealing to approximate an optimal solution to the Traveling Salesman Problem. We will implement the simulated annealing algorithm from scratch and apply it to a given instance of the Traveling Salesman Problem.

Use Simulated Annealing for the Traveling Salesman Problem

You will learn to:

Implement the simulated annealing algorithm.

Apply a global optimization algorithm to a combinatorial optimization problem.

Observe the performance of a global search algorithm over a solution space.

Plot data using Python libraries.


Data Plotting

Probabilistic Metaheuristics

Combinatorial Optimization


Basic understanding of optimization theory

Basic understanding of graph theory

Experience with Python





Project Description

The Traveling Salesman Problem (TSP) is one of the most famous problems in combinatorial optimization, in which the target is to find the shortest route for the salesman through various cities. In every known algorithm that solves this problem exactly, increasing the number of cities increases the running time of the problem exponentially.

Simulated annealing is a probabilistic technique to approximate the global optimum. Inspired by metallic annealing, where metal is first heated and then cooled to increase its ductility, the step size of simulated annealing is initially kept high to traverse the entire solution space and is gradually decreased to improve the accuracy of the solution.

In this project, we will implement the simulated annealing algorithm and apply it to find an approximate solution to TSP.

A fully-connected TSP graph with 10 cities (distances not to scale)

Project Tasks


Implement TSP

Task 0: Introduction

Task 1: Import Libraries

Task 2: Visualize the TSP Data

Task 3: Construct the Adjacency Matrix

Task 4: Create a Function to Evaluate Distance


Implement the Simulated Annealing Algorithm

Task 5: Set the Initial State of the System

Task 6: Find a Candidate State

Task 7: Update the State of the System

Task 8: Implement the Metropolis Acceptance Criterion

Task 9: Save Temperature and Cost Data in Arrays

Task 10: Print the Optimization Results at Different Iterations


Use Simulated Annealing to Solve TSP

Task 11: Run the simulated_annealing() Function

Task 12: Plot the Shortest Route on a Graph

Task 13: Plot the Cost Value

Task 14: Plot the Evolution of Temperature