panga
Public Member Functions | List of all members
panga::Population Class Reference

#include <Population.h>

Public Member Functions

 Population (const Genome &genome)
 
 Population (const Population &rhs)=delete
 
 Population (Population &&rhs)=default
 
Populationoperator= (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 IndividualGetBestIndividual () const
 
const IndividualGetIndividual (size_t index) const
 
IndividualGetIndividualWritable (size_t index)
 
double GetMinimumScore () const
 
double GetAverageScore () const
 
double GetScoreStandardDeviation () const
 
double GetPopulationDiversity () const
 
const IndividualUniformSelect (RandomWrapper *random) const
 
const IndividualRouletteWheelSelect (RandomWrapper *random) const
 
const IndividualTournamentSelect (size_t tournament_size, RandomWrapper *random) const
 
const IndividualRankSelect () const
 
void Evaluate (FitnessFunction fitness_function, void *user_data)
 

Detailed Description

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.

Member Function Documentation

◆ Evaluate()

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.

◆ GetAverageScore()

double panga::Population::GetAverageScore ( ) const

Get the average score between individuals in the population.

◆ GetBestIndividual()

const Individual & panga::Population::GetBestIndividual ( ) const

Return the Individual with highest fitness value in the population.
Note: Requires the population to have been sorted.

◆ GetIndividual()

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.

◆ GetIndividualWritable()

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.

◆ GetMinimumScore()

double panga::Population::GetMinimumScore ( ) const

Get the minimum score among individuals in the population.

◆ GetPopulationDiversity()

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.

◆ GetScoreStandardDeviation()

double panga::Population::GetScoreStandardDeviation ( ) const

Get the standard deviation of scores between individuals in the population.

◆ Initialize()

void panga::Population::Initialize ( const std::vector< BitVector > &  initial_population)

Initialize the population based on |initial_population|.
Clears any individuals currently in the population.

Parameters
initial_populationWe will construct new population members and interpret these values as binary chromosome data.

◆ InitializePartialSums()

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.

◆ RankSelect()

const Individual & panga::Population::RankSelect ( ) const

Select the individual in the population with highest fitness score.

◆ Replace()

void panga::Population::Replace ( size_t  index,
const Individual individual 
)

Replace the individual currently at |index| in the population with |individual|.

◆ Resize()

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.

◆ RouletteWheelSelect()

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.

See also
InitializePartialSums

◆ Size()

size_t panga::Population::Size ( ) const

Return the number of individuals in the population.

◆ Sort()

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.

◆ TournamentSelect()

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.

◆ UniformSelect()

const Individual & panga::Population::UniformSelect ( RandomWrapper random) const

Select an individual from the population at random.


The documentation for this class was generated from the following files: