CSC 486 Artificial Intelligence
Lisp Code for a Genetic AlgorithmObjectives
First pioneered by John Holland in the 60s, Genetic Algorithms have been widely studied and applied in many fields. GAs provide an alternative method to solving problems, and often outperforms other traditional methods for problems that have time complexities that are polynomial or worse. In practice, genetic algorithms have been widely applied in optimization problems such as scheduling and circuit layout. In this assignment, we will explore another application.
Many TSP's are symmetric - that is, for any two cities A and B, the distance from A to B is the same as that from B to A. In this case you will get exactly the same tour length if you reverse the order in which they are visited - so there is no need to distinguish between a tour and its reverse.
If there are only 2 cities then the TSP problem is trivial, since only one tour is possible. For the symmetric case a 3 city TSP is also trivial. If all roads are present then there are (n-1)! different tours for an n city asymmetric TSP. To see why this is so, pick any city as the first - then there are n-1 choices for the second city visited, n-2 choices for the third, and so on. Thus, for the symmetric case there are half as many distinct solutions - (n-1)!/2 for an n city TSP. In either case the number of solutions becomes extremely large for large n, so that an exhaustive search is impractible for large n. For example, testing every possibility for an n city tour would require n! math additions just to compute each path. Thus, a 30 city tour would require 2.65 X 1032 additions. Assuming 1 billion additions per second, this would take over 8,000,000,000,000,000 years. Adding one more city would cause the number of additions to increase by a factor of 31. Obviously, exhaustive search is an impossible solution.
For these reasons, the TSP problem has some importance to computer scientists and appliued mathematicians, since many practical applications can be put in this form. It also has a theoretical importance in the field of complexity theory, since the TSP is one of the class of "NP Complete" combinatorial problems. NP Complete problems have intractable in the sense that no one has found any really efficient way of solving them for large n. They are also known to be essentially equivalent to each other; if you figure out how to solve one kind of NP Complete problem with an efficient algorithm you could solve all of them that way.
A genetic algorithm can be used to find a solution is much less time than the exhastive search. Although the GA may not find the best solution, it can find a good solution in less than a minute. In GAs a "fitness function" or "strength function" is used to measure how good a solution has been obtained. There are two basic steps to solving the travelling salesman problem using a GA. First, you create a group of many random tours in what is called a population of tours. Second, you pick two of the better tours as parents in the population and combine them, using a teachnique called crossover, to create a new solution child in the hope that it is an even better solution to the TSP problem than the parents were.
Drop the text document named yourlastname(s)A14 in "A14 Genetic" when you are finished.