|
panga
|
#include <Population.h>
Public Member Functions | |
| Population (const Genome &genome) | |
| Population (const Population &rhs)=delete | |
| Population (Population &&rhs)=default | |
| Population & | operator= (const Population &rhs)=delete |
| size_t | Size () const |
| void | Resize (size_t size, RandomWrapper *random) |
| void | Initialize (const std::vector< BitVector > &initial_population) |
| void | InitializePartialSums () |
| void | Sort () |
| void | Replace (size_t index, const Individual &individual) |
| const Individual & | GetBestIndividual () const |
| const Individual & | GetIndividual (size_t index) const |
| Individual & | GetIndividualWritable (size_t index) |
| double | GetMinimumScore () const |
| double | GetAverageScore () const |
| double | GetScoreStandardDeviation () const |
| double | GetPopulationDiversity () const |
| const Individual & | UniformSelect (RandomWrapper *random) const |
| const Individual & | RouletteWheelSelect (RandomWrapper *random) const |
| const Individual & | TournamentSelect (size_t tournament_size, RandomWrapper *random) const |
| const Individual & | RankSelect () const |
| void | Evaluate (FitnessFunction fitness_function, void *user_data) |
Just a collection of Individual objects.
We can select Individuals from this population according to their fitness values.
Note: In order for the select functions to work correctly, the population must be sorted in decreasing fitness order with the Individual at index 0 being the most fit.
| void panga::Population::Evaluate | ( | FitnessFunction | fitness_function, |
| void * | user_data | ||
| ) |
Use |fitness_function| to score each Individual in the population and then sort the population in terms of decreasing fitness.
| double panga::Population::GetAverageScore | ( | ) | const |
Get the average score between individuals in the population.
| const Individual & panga::Population::GetBestIndividual | ( | ) | const |
Return the Individual with highest fitness value in the population.
Note: Requires the population to have been sorted.
| const Individual & panga::Population::GetIndividual | ( | size_t | index | ) | const |
Return the Individual at |index| position in the population based on fitness where the individual at index 0 is the most fit, the second most fit is at index 1, etc.
Note: Requires the population to have been sorted.
| Individual & panga::Population::GetIndividualWritable | ( | size_t | index | ) |
Get a writable reference to the individual at |index| position in the population.
Does not require the population to be sorted and does not return individuals in relative order of fitness.
Note: Modifying individuals in the population while the genetic algorithm is running may lead to undexpected results.
| double panga::Population::GetMinimumScore | ( | ) | const |
Get the minimum score among individuals in the population.
| double panga::Population::GetPopulationDiversity | ( | ) | const |
Get the population diversity among individuals in the population.
The population diversity is a metric used to indicate how much the genetic material backing the individuals varies. A high diversity value means the individuals have very different genetic components. A value of zero means the individuals are identical.
| double panga::Population::GetScoreStandardDeviation | ( | ) | const |
Get the standard deviation of scores between individuals in the population.
| void panga::Population::Initialize | ( | const std::vector< BitVector > & | initial_population | ) |
Initialize the population based on |initial_population|.
Clears any individuals currently in the population.
| initial_population | We will construct new population members and interpret these values as binary chromosome data. |
| void panga::Population::InitializePartialSums | ( | ) |
Initialize the set of partial sums we use for the roulette wheel selector.
Note: Requires the population to have been sorted.
| const Individual & panga::Population::RankSelect | ( | ) | const |
Select the individual in the population with highest fitness score.
| void panga::Population::Replace | ( | size_t | index, |
| const Individual & | individual | ||
| ) |
Replace the individual currently at |index| in the population with |individual|.
| void panga::Population::Resize | ( | size_t | size, |
| RandomWrapper * | random | ||
| ) |
Resize the population to hold |size| individuals.
If |size| is greater than the current size of the population, new random individuals will be added until we reach |size| individuals.
| const Individual & panga::Population::RouletteWheelSelect | ( | RandomWrapper * | random | ) | const |
Spin a roulette wheel to select an individual where each slice on the wheel corresponds to the partial sum of a ranked individual. The size of each partial sum on the wheel is relative to the fitness of that individual with more fit individuals having a larger-sized slice.
Patial sums must have already been created via InitializePartialSums.
| size_t panga::Population::Size | ( | ) | const |
Return the number of individuals in the population.
| void panga::Population::Sort | ( | ) |
Sort the individuals in the population by decreasing fitness - ie: the best individual will be stored at index 0, the second best at index 1, etc.
This must be called before using the selection functions as they rely on the population being sorted.
| const Individual & panga::Population::TournamentSelect | ( | size_t | tournament_size, |
| RandomWrapper * | random | ||
| ) | const |
Randomly select |tournament_size| individuals from the population and return the one with highest fitness.
| const Individual & panga::Population::UniformSelect | ( | RandomWrapper * | random | ) | const |
Select an individual from the population at random.
1.8.17