class BRKGA::Population
Overview
Encapsulates a population of chromosomes. More…
#include <brkga_mp_ipr.hpp> class Population { public: // fields std::vector<Chromosome> chromosomes; std::vector<std::pair<fitness_t, unsigned>> fitness; // construction Population( const unsigned chr_size, const unsigned pop_size ); Population(const Population& other); // methods Population& operator = (const Population&); unsigned getChromosomeSize() const; unsigned getPopulationSize() const; double operator () ( const unsigned chromosome, const unsigned allele ) const; double& operator () ( const unsigned chromosome, const unsigned allele ); Chromosome& operator () (unsigned chromosome); fitness_t getBestFitness() const; fitness_t getFitness(const unsigned i) const; Chromosome& getChromosome(unsigned i); const Chromosome& getChromosome(const unsigned i) const; void sortFitness(const Sense sense); void setFitness( const unsigned chromosome, const fitness_t value ); };
Detailed Documentation
Encapsulates a population of chromosomes.
Encapsulates a population of chromosomes providing supporting methods for making the implementation easier.
J All methods and attributes are public and can be manipulated directly from BRKGA algorithms. Note that this class is not meant to be used externally of this unit.
Fields
std::vector<Chromosome> chromosomes
Chromosomes as vectors of probabilities.
std::vector<std::pair<fitness_t, unsigned>> fitness
Fitness of each chromosome.
Construction
Population( const unsigned chr_size, const unsigned pop_size )
Default constructor.
Parameters:
chr_size |
size of chromosome. |
pop_size |
size of population. |
std::range_error |
if population size or chromosome size is zero. |
Population(const Population& other)
Copy constructor.
Methods
Population& operator = (const Population&)
Assignment operator.
unsigned getChromosomeSize() const
Returns the size of each chromosome.
unsigned getPopulationSize() const
Returns the size of the population.
double operator () ( const unsigned chromosome, const unsigned allele ) const
Returns a copy of an allele for a given chromosome.
Parameters:
chromosome |
index of desired chromosome. |
allele |
index of desired allele. |
Returns:
a copy of the allele value.
double& operator () ( const unsigned chromosome, const unsigned allele )
Returns a reference for an allele for a given chromosome.
Usually used to set the allele value.
Parameters:
chromosome |
index of desired chromosome. |
allele |
index of desired allele. |
Returns:
a reference of the allele value.
Chromosome& operator () (unsigned chromosome)
Returns a reference to a chromosome.
Parameters:
chromosome |
index of desired chromosome. |
Returns:
a reference to chromosome.
fitness_t getBestFitness() const
Returns the best fitness in this population.
fitness_t getFitness(const unsigned i) const
Returns the fitness of chromosome i.
Chromosome& getChromosome(unsigned i)
Returns a reference to the i-th best chromosome.
const Chromosome& getChromosome(const unsigned i) const
Returns a const reference to the i-th best chromosome.
void sortFitness(const Sense sense)
Sorts fitness
by its first parameter according to the sense.
Parameters:
sense |
Optimization sense. |
void setFitness( const unsigned chromosome, const fitness_t value )
Sets the fitness of chromosome.
Parameters:
chromosome |
index of chromosome. |
value |
allele value. |