GeneticAlgorithm<T> constructor
GeneticAlgorithm<T> ({})
Implementation
GeneticAlgorithm({
required this.initPopulation,
required this.fitness,
required this.crossover,
required this.mutate,
this.populationSize = 100,
this.mutationRate = 0.01,
this.elitism = 1,
int? seed,
}) : _rand = seed != null ? Random(seed) : Random() {
if (populationSize <= 0) throw ArgumentError('populationSize > 0');
if (mutationRate < 0 || mutationRate > 1) {
throw ArgumentError('mutationRate in [0,1]');
}
if (elitism < 0 || elitism >= populationSize) {
throw ArgumentError('invalid elitism');
}
}