gastring
breed strings with a genetic algorithm
gastring -help
or
gastring
[-target string] [-size integer] [-steps integer]
[-seed integer] [-crate double] [-mrate double]
[-pbase double]
Uses a genetic algorithm to breed strings that match a user-specified target string. This program illustrates how GAs can perform a type of stochastic search in a space of discrete objects. Reproduction of strings entails crossover and mutation with strings being selected based on fitness.
Use a genetic algorithm to breed strings that match a user-specified target string. This program illustrates how GAs can perform a type of stochastic search in a space of discrete objects. Reproduction of strings entails crossover and mutation with strings being selected based on fitness.
Miscellany
The fitness function works in three steps. First, the number of correct characters is tallied and denoted the raw fitness. The scaled fitness is then set to pow(PBASE, raw fitness - string len). The normalized fitness is then set to the scaled fitness divided by the sum of the scaled fitnesses. Thus the sum of the normalized fitnesses must be equal to one while a string with one letter more correct than another string is PBASE times as likely to reproduce, where PBASE is the value supplied with the -pbase option.
Bugs
No sanity checks are performed to make sure that any of the options make sense.
Options
-target | Target string. | furious green ideas sweat profusely |
-size | Population size. | 500 |
-steps | Number of generations. | 50 |
-seed | Random seed. | 0 |
-crate | Crossover rate. | 0.75 |
-mrate | Mutation rate. | 0.01 |
-pbase | Power base for fitness. | 2.0 |