Class that performs a genetic algorithm. More...
#include <evolver.h>
Public Member Functions | |
Evolver (int nGenes, int nIndividuals, int nPopulations) | |
void | setPopulationData (int nGenes, int nIndividuals, int nPopulations) |
void | evolve (int nSteps, int populationMatchingPeriod) |
void | setRescaleLimits (double low, double high) |
void | setRescaleCycles (int rescaleCycles) |
void | rescale () |
Public Attributes | |
vec | allBestGenes |
Protected Member Functions | |
virtual double | fitness (vec &coefficients, int population, int individual)=0 |
void | updateBest () |
Protected Attributes | |
int | nIndividuals |
int | nGenes |
int | nPopulations |
int | cycle |
long * | idum |
double | scale |
double | lowScaleLimit |
double | highScaleLimit |
double | initialLowScaleLimit |
double | initialHighScaleLimit |
double | rescalePrecisionLimit |
vec ** | populations |
uvec * | bestIndices |
vec * | values |
double | allBestValue |
int | allBestIndex |
int | allBestPopulationIndex |
int | rescaleCycles |
int | cyclesSinceLastImprovement |
int | cyclesSinceLastRescale |
double | lastWorkingScale |
bool | veryFirst |
Class that performs a genetic algorithm.
This class must be inherited and have its fitness function defined to be used.
void Evolver::evolve | ( | int | nSteps, |
int | populationMatchingPeriod | ||
) |
The evolutionary algorithm. Runs for the given number of cycles, uses the fitness function on all individuals' genes and ranks them each cycle. Then the best individuals are mated to produce offspring while the offspring and worst individuals are mutated. Some new individuals are introduced. See the report for more information.
void Evolver::rescale | ( | ) |
Updates the scaling of new suggestions for mutations within the given scale. This works logarithmically so that it is a uniform probability for the logarithmic powers between the scale limits.
void Evolver::setPopulationData | ( | int | nGenes, |
int | nIndividuals, | ||
int | nPopulations | ||
) |
Defines the number of genes, populations and individuals and allocates memory to these.
void Evolver::updateBest | ( | ) | [protected] |
Updates the scoreboard over which individuals are best within each population.