| ||||||||||||||
| ||||||||||||||
|
||||||||||||||
Genetic Algorithm and Traveling Salesman ProblemBy Konstantin Boukreev
Title: Genetic Algorithm and Traveling Salesman Problem Author: Konstantin Boukreev Email: konstantin@mail.primorye.ru Environment: VC++ 6.0. SP5, Win2k SP2, MS Platform SDK April 2001 Description: The example of using Genetic Algorithm for solving Traveling Salesman Problem
contents
DisclaimerI am not a GA guru and I do not have any degree in GA so this article can't be used as GA book or GA tutorial. There aren't any mathematics nor logic nor algebra about GA. It's only a programmer's view on Genetic Algorithms and only example of GA coding. Use it carefully! Any comments and criticism are highly appreciated. Genetic Algorithm, TheoryThere are so many books and so many resources on the WEB about Genetic Algorithms. The best that I can do is quote some nice descriptions from my preferred sites. Definition from Marek Obitko's Site: "Genetic algorithms are a part of evolutionary computing, which is a rapidly growing area of artificial intelligence. As you can guess, genetic algorithms are inspired by Darwin's theory about evolution. Simply said, solution to a problem solved by genetic algorithms is evolved." Explanation from Generation5.org: "Genetic algorithms are not too hard to program or understand, since they are biological based. Thinking in terms of real-life evolution may help you understand. Here is the general algorithm for a GA: In my opinion, the GA is easy to understand and easy to implement using C++. The main advantage and disadvantage of GA at the same time is robustness. Even if you implement some features incorrectly, the GA will continue run and sooner or later will solve the problem (or find any local optimum). Definitely such a feature can produce some trouble during debugging and tuning. Another interesting problem is to choose the best algorithms from existing plethora of algorithms of crossover, mutation, gene presentation, etc. See references topic for some useful links about GA theory. Genetic Algorithm and Traveling Salesman ProblemAbout Traveling Salesman ProblemAgain a quotation from http://www.math.princeton.edu/tsp/ "The traveling salesman problem, or TSP for short, is this: given a finite number of 'cities' along with the cost of travel between each pair of them, find the cheapest way of visiting all the cities and returning to your starting point." Genome and AlgorithmWe can't use a traditional presentation and algorithm for the TSP problem, because every city must be unique in a gene, and can't be duplicated. For a gene presentation, I used a sequential representation where the cities are listed in the order in which they are visited. It's common way for TSP Genome. Example: [9 3 4 0 1 2 5 7 6 8] For a crossover operation after several tests and researching I selected the Greedy Crossover by J. Grefenstette. The citation from Sushil J. Louis "Greedy crossover selects the first city of one parent, compares the cities leaving that city in both parents, and chooses the closer one to extend the tour. If one city has already appeared in the tour, we choose the other city. If both cities have already appeared, we randomly select a non-selected city." From my experience it's a very effective method. MutationWe can't change the gene's bits as the usual traditional mutation does. Instead we must swap the order of cities in a path. Example: Before mutation [0 1 2 3 4 5 6] After mutation [0 1 3 2 4 5 6] There are a lot of ways of doing such a swapping operation. Easiest way in using random swap. Unfortunately, such a strategy is unable to achieve an optimum quickly but can prevent convergence into a local optimum. Additionally I used a greedy-swap mutation. Once more citation from Sushil J. Louis "The basic idea of greedy-swap is to randomly select two cities from one chromosome and swap them if the new (swapped) tour length is shorter than the old one" While browsing the web I discovered research into GA "A fast TSP solver using a genetic algorithm" by Hiroaki Sengoku and Ikuo Yoshihara. It's the fastest algorithm I ever saw. Unfortunately, It's a Java implementation and without any source. I could find only one PDF document with a description about this algorithm: arob98.pdf After reading and studying I used the "Mutation by 2opt" idea in my code. This method has the same idea as greedy-swap mutation but more expansive and more effective. After adding into code I can improve speed of my program greatly on small and middle sets (till 200 cities). However for big sets (1000 and more) this heuristics is very slow method. SelectionI implemented three selection methods : routlette rank, roulette cost and tournamnet. Of course I used elitism too. Roulette Wheel SelectionDefinition from Marek Obitko's Site"Cost Selection : Parents are selected according to their fitness. The better the chromosomes are, the more chances to be selected they have. Imagine a roulette wheel where are placed all chromosomes in the population, every has its place big accordingly to its fitness function Tournamnet Selection and ElitismDefinition from W. B. Langdon, University College, London
"A mechanism for choosing individuals from a population. A group (typically between 2 and 7 individuals) are selected at random from the population and the best (normally only one, but possibly more) is chosen An elitist genetic algorithm is one that always retains in the population the best individual found so far, Tournamnet Selection is naturally elitist." In my opinion and after testing the roulette rank and tournament selections are slightly faster for TSP case. For another problems, others selection algorithms can be best. Co-evolutions. MigrationsI didn't find many documents about these methods in WEB. The base idea: allow evolving of several populations at the same time. The description found in Generation5.org Site "Genetic algorithms are neat, but they do come with their own set of problems. One big problem is that genetic algorithms have a tendency to get stuck at local optima. In other words, they will find a reasonable solution, but not the best solution. There are several methods that have been devised to counter this problem, and the one we will look at is coevolution"Simultaneously, co-evolution idea allows utilizing the SMP ability of WinNT\2k machines with multi CPUs. We can easily run several GA in separate threads without any penalty. For exchange data between different GA we can migrate the best genes in population.
Base implementation
|
|
|||||||||||||
All content copyright © 1998-2007, Generation5 unless otherwise noted.
- Privacy Policy - Legal - Terms of Use -