Tuesday, December 6, 2011

genetic algorithm I

the first time I wrote a genetic algorithm. starting with a simple geometrical problem (travelling salesman - some random points, find the shortest route trough all of them) the program does the following:

- generate a random line through all of the points, measure the length
- make 10 copies and exchange 2 points with each other randomly, measure the length
- the shortest (the fittest) is the "father" for the new generation
- repeat until there are no fitter copies for 50 generations

these are the statistics for the following example:
starting length: 735.08
optimized length: 344.35
reducing length to: 46.85 %
best solution after 38 generations
16 steps of transformation total

it is fascinating to give a certain intelligence to your scripts. though we have a very simple problem the process of finding a solution to it is very promising. it is a simulation of evolution, only the fittest members can reproduce themselves...



No comments:

Post a Comment