Genetic algorithm for genomes in the form of a list. This includes dynamic and statically sized arrays.
T | Type representing the genome. Should be a dynamic or statically sized array |
PopSize | The size of the population |
fitness | User defined fitness function. Must return double |
generator | Function used to create new members of the population |
selector | Selection method used to pick parents of next generation. |
crossover | Used to crossover individuals to create the new generation. |
mutator | Used to alter the population. |
comp | Used to determine whether a larger or smaller fitness is better. |
//Grow individual with greatest sum import devolve, std.algorithm; alias genomeType = int[4]; double fitness(genomeType ind) {return reduce!"a+b"(ind)} void main() { auto ga = new ListGA!(genomeType, 10, fitness, preset!(1, 2, 3, 4)); //converges rapidly on [4, 4, 4, 4] ga.evolve(100); }
Default constructor. No statistics will be printed, and mutation will be set at 1%, crossover rate at 80%
Convienience constructor, equivilant to default constructing and setting mutation rate and statistic frequency