Skip to content

This code implements a genetic algorithm for solving the Traveling Salesman Problem (TSP) on a set of cities from a distance matrix, utilizing techniques such as tournament selection, PMX crossover, inversion and exchange mutations, and elitism to optimize the route and minimize total distance.

Notifications You must be signed in to change notification settings

SonnyFixit/Travelling_salesman_problem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Genetic Algorithm for TSP Solver

Content

General info

This project implements a Genetic Algorithm to solve the Traveling Salesman Problem (TSP), a classic optimization problem.
The TSP Solver is designed for academic purposes demonstrating the application of genetic algorithms in solving complex optimization problems.
The code includes functions for loading distance matrices, creating symmetric matrices, and various genetic operations like selection, crossover, and mutation.

Key Programming Practices

Modularity: The code is organized into functions for easy readability and maintainability. Efficiency: Algorithms are optimized for efficient computation of routes and distances. Readability: Consistent naming conventions and code structuring are used for clarity. Error Handling: Rrror handling to ensure reliable operation under various input scenarios. Documentation: Comprehensive comments to explain the functionality of each part of the code.

Technologies

  • Python 3.11.3
  • Visual Studio Code
  • LineProfiler

Features

  • Loading and processing triangular matrix files for distance calculations.
  • Symmetric matrix generation for TSP.
  • Implementation of genetic algorithm operations: Population initialization, Tournament selection, Partially Mapped Crossover (PMX), Inversion and Exchange mutations
  • Elitism strategy to retain top-performing solutions.
  • Calculation and display of the optimal route and distance.
  • Performance measurement for algorithm execution.

How to run

  • Ensure right version of Python is installed.
  • Place the triangular matrix file in the same directory as the script.
  • Run the script in a Python environment.
  • The best route and distance will be displayed, along with the execution time.

Team:

About

This code implements a genetic algorithm for solving the Traveling Salesman Problem (TSP) on a set of cities from a distance matrix, utilizing techniques such as tournament selection, PMX crossover, inversion and exchange mutations, and elitism to optimize the route and minimize total distance.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages