Solving the Travelling Salesman Problem with Genetic Algorithms

We saw last time that it might be useful to find a route for the Travelling Salesman Problem that is a short route, but perhaps not the exact best. This is what we do in situations where, due to time constraints, we choose to trade the ideal solution in exchange for a good solution that can be found quickly. It is also useful as a first step in finding the exact solution.

There are many methods that have been developed to find good solutions to this problem. Most of these techniques are applicable to a wide range of problems. One of these techniques is genetic algorithms.

The basic idea of a genetic algorithm is to start with a set of random routes. Think of these routes as a population of organisms, with the data defining the routes as the genetic material of the organisms. We'll take these organisms and evolve them, by breeding them with each other, and also by allowing mutations to occur in their genes. In each generation, the organisms compete with each other - the most successful organisms survive and breed, and we dispose of many of the unsuccessful organisms (routes). In this setting, an organism is successful if its genes represent a short route.

In order to implement this, we need to figure out a way to think of the data defining the routes as genes, we need to figure out a way to breed two organisms by combining their genes in some way, and we need to figure out a way to mutate the genes. There are many ways to do this. First, let's think of the routes through n cities as a permutation of n numbers. For example, in a problem with 6 cities, the permutation (1 6 3 2 4 5) represents the route 1 -> 6 -> 3 -> 2 -> 4 -> 5. The elements of the permutation represent the genes of the organism. Now we need a way to cross two permutations (the parents) to create a new permutation (a child). One way is to take the first n/2 elements of first permutation, then fill in the remaining n/2 from the 2nd permutation in the order that the unvisited cities occur. For example, a cross of the permutations (2 6 3 5 4 1) and (1 4 2 3 5 6) is (2 6 3 1 4 5). Another way to breed two routes is to choose two cross-points instead of one, or to randomly choose the location of the cross. There are many other methods to breed permutations. Now to mutate an organism, you might randomly choose two of the genes and swap them. Another way to mutate a permutation is to choose a random-length subpath from a random location in the route and reverse it. There are many other methods you could devise to mutate a permutation.

In addition to deciding how to model the breeding and mutation or organisms, we have to decide the size of the original population, how many pairs of the organisms we will breed, how many children we will produce, at what rate we will produce mutations, what criteria we will use to determine survival, etc.

A modification of a genetic algorithm is to include the idea of "elitism". In elitism, we always retain the most successful organism found thus far.

Here is a web site that implements a genetic algorithm solution to the travelling salesman problem. Genetic algorithms