/Travelling_salesman_problem

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.

Primary LanguagePython

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: