Close

2020-04-02

Implementation of the Travelling Salesman problem using the Genetic Algorithm

Implementation of the Travelling Salesman problem using the Genetic Algorithm

The Traveling Salesman Problem (TSP) is a well-known problem in computer science and operations research. It involves finding the shortest route that visits a given set of cities and returns to the starting point. Genetic algorithms (GAs) are famous for solving TSPs because they can find approximate solutions to complex optimization problems.

A genetic algorithm for solving the TSP begins by generating a population of candidate solutions represented as arrays of city indices. Each candidate solution represents a possible route that visits the cities in a different order. The initial population is typically generated randomly.

Next, the GA evaluates each candidate solution’s fitness by calculating the route’s total distance. The fitness function is used to determine the quality of each candidate solution. The GA uses this fitness information to select the fittest individuals from the current population to become the next generation’s parents.

The GA then applies genetic operators such as crossover and mutation to the parents to generate new candidate solutions for the next generation. Crossover combines the genetic information of two parents to create a new offspring, while mutation randomly changes a small portion of the genetic information of a candidate solution.

This process is repeated for multiple generations until a satisfactory solution or a stopping criterion is met. The final solution is the shortest route that visits all the cities and returns to the starting point.

It’s worth noting that the TSP is an NP-hard problem, and the solution provided by GA is approximate, not optimal. Some alternative methods, such as branch and bound dynamic programming and ant colony optimization, can also be used to find the optimal solution.