#include <Population.hpp>
Public Member Functions | |
Population (Context *pcontext, Evaluator *peval, int iPopulationSize=100, int iTournamentSize=3, int iMinDepth=0, int iMaxDepth=30, int iTries=5) | |
void | generateInitialPopulation () |
Individual * | getBestIndividual () const |
Individual * | selectIndividual () const |
void | addIndividual (Individual *ind) |
double | getBestFitness () const |
int | getBestHits () const |
double | getAverageFitness () const |
double | getAverageHits () const |
void | mutate (double dMutationRate) |
void | crossover (double dCrossoverRate) |
void | evaluate () |
Population::Population | ( | Context * | pcontext, | |
Evaluator * | peval, | |||
int | iPopulationSize = 100 , |
|||
int | iTournamentSize = 3 , |
|||
int | iMinDepth = 0 , |
|||
int | iMaxDepth = 30 , |
|||
int | iTries = 5 | |||
) |
Create a new population object. This merely sets the population up, and does not populate it with individuals.
[in,out] | pcontext | A pointer to the context for the GP. |
[in] | peval | A pointer to the evaluator object. |
[in] | iPopulationSize | The number of individuals to allocate space for in the population. |
[in] | iTournamentSize | The size of the pool of random individuals from which the best is chosen in the selection method. |
[in] | iMinDepth | The minimum depth an individual in this population's symbol tree * must be to be considered valid. |
[in] | iMaxDepth | The maximum depth an individual in this population's symbol tree must be to be considered valid. |
[in] | iTries | The number of attempts a particular mutation or crossover will try before it will fail. |
void Population::addIndividual | ( | Individual * | ind | ) |
Adds the given individual to the population.
[in] | ind | The individual to be added to the population |
void Population::crossover | ( | double | dCrossoverRate | ) |
Performs crossover on a given proportion of the population. The individuals crossed over are chosen at random, individuals are crossed with neighboring individuals in the population list. Since the order of the list is made random with the selection process in each generation this does not mean that the same two individuals are always crossed.
[in] | dCrossoverRate | The proportion of individuals to be crossed |
void Population::evaluate | ( | ) |
Evaluates the entire population, updating the best individual pointer and averages to reflect the new values. This should be called between any modification to the population and any access to these statistics.
void Population::generateInitialPopulation | ( | ) |
Constructs enough random individuals to fill the population.
double Population::getAverageFitness | ( | ) | const |
Returns the mean fitness value of the individuals in the population.
double Population::getAverageHits | ( | ) | const |
Returns the mean hit value of the individuals in the population.
double Population::getBestFitness | ( | ) | const |
Returns the highest fitness value of any individual in the population.
int Population::getBestHits | ( | ) | const |
Returns the number of hits in the individual with the best fitness
Individual * Population::getBestIndividual | ( | ) | const |
Returns a copy of the individual in the population with the highest fitness value. A pointer to this individual is kept when the population is evaluated so this can be done in constant time.
void Population::mutate | ( | double | dMutationRate | ) |
Performs mutations on a given proportion of the population. The actual individuals mutated are chosen at random.
[in] | dMutationRate | The proportion to be mutated |
Individual * Population::selectIndividual | ( | ) | const |
Performs tournament selection to choose an individual from the population. Specifically this picks a number of individuals from the population at random and returns the one with the highest fitness.