
January 14th, 2004, 01:49 PM
|
 |
Contributing User
|
|
Join Date: May 2003
Location: Tennessee
Posts: 1,355
Time spent in forums: < 1 sec
Reputation Power: 7
|
|
|
Genetic Algorithms
Anybody have any thoughts on or experience with writing genetic algorithms? I tried my first one recently and am eager to hear about other people's experience. To kick things off, I'll describe mine.
It's a genetic algorithm through and through in that it emulates natural selection. I wrote an Ant class and a Couple class. The Ant class contains information about individual Ant objects, including a DNA sequence, the DNA sequence of both parents, and the gene selected for in the current run of the program. The primary method for the Ant class is a little algorithm for determining whether or not the ant is fit to procreate (about which more in a minute).
The Couple class is a wrapper around two ants chosen almost randomly. Its primary method is one I chose in a fit of elementary-school snickering to call "screw" ($couple->screw()) that disassembles the DNA of both parents and spawns a new ant in a new generation using slices of DNA from both parents.
I spawn a random population of ants to begin with, and then I loop through X generations and spawn Y ants for each generation. After the initial random generation, only ants deemed fit based on their genome may breed to produce future generations. So the gene I'm selecting for gradually begins to appear more and more frequently. The more generations, the higher the frequency. And voila, a genotype that found its way into the genome more or less randomly in the first generation becomes a common trait of the species; or, to put it another more concrete (if not ant-specific) way, the opposable thumb is born.
A strand of DNA for my purposes is composed of four two-letter pairs using the 16 possible such combinations of the letters a - d. So aa_bd_ca_bc_ would be one possible strand of DNA. I select for double letters within one pair, so if I decide to select for "a," only ants who have the sequence "aa_" in their DNA can mate.
Genetic algorithms are sometimes used in programming to find the best way of accomplishing a task. They're meta-programming, in a way. You feed a problem to a genetic algorithm, and it attempts to solve the problem in various (random) ways. Each iteration is scored, and as additional attempts are made, past attempts that scored well stand to be recombined with other attempts that do well. I'm not sure how this works in practice (how you write something that attempts random unwritten logic to solve problems), but I hear it's pretty cool. My little program is one of the simplest examples of this sort of algorithm, I imagine.
Anybody else got any experience with genetic algorithms?
|