GeneticAlgoithm
Implementation of the genetic algorithm
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
IPopulation Class Referenceabstract

Abstract class describing a population of models. More...

#include <IPopulation.h>

Inheritance diagram for IPopulation:
Inheritance graph
[legend]
Collaboration diagram for IPopulation:
Collaboration graph
[legend]

Public Member Functions

 IPopulation ()
 
virtual ~IPopulation ()
 
void initialize (int n)
 
void crossOver ()
 
void mutate ()
 
void score ()
 
void setRandomSeed (int seed)
 
void setMutateRate (double rate)
 
void setFigureOfMerit (IFigureOfMerit *fom)
 
IFigureOfMeritgetFigureOfMerit ()
 
IModelgetBestFitted (int rank=0)
 
int size ()
 
double getScoreMean ()
 
double getScoreRMS ()
 
void clear ()
 

Protected Member Functions

virtual void doInitialize (int n)=0
 
virtual void doCrossOver (const std::vector< std::vector< IModel *> > &parents)=0
 
virtual void doMutate (IModel *model)=0
 
virtual void selectParents (int &p1, int &p2)
 
void sort ()
 
void checkFigureOfMerit ()
 

Protected Attributes

double m_mutateRate
 Stores the mutate rate.
 
bool m_sorted
 Stores whether the ranking is valid or needs to be redone.
 
std::vector< IModel * > m_individuals
 Stores the individuals of this population.
 
IFigureOfMeritm_fom
 Stores the figure of merit to be used to calculate scores and perform the ranking.
 
TRandom3 * m_random
 Stores a random number generator.
 
double m_scoreMean
 Stores the mean score for the population.
 
double m_scoreRMS
 Stores the score RMS for the population.
 
std::vector< std::vector< IModel * > > m_parents
 Stores the list of parents about to be crossed-over.
 

Detailed Description

Abstract class describing a population of models.

This class should implement the following functionalities:

Derive from this class by implementing at least these three methods:

Definition at line 27 of file IPopulation.h.

Constructor & Destructor Documentation

◆ IPopulation()

IPopulation::IPopulation ( )

Default Constructor

Definition at line 10 of file IPopulation.cxx.

◆ ~IPopulation()

IPopulation::~IPopulation ( )
virtual

Destructor

Definition at line 20 of file IPopulation.cxx.

Member Function Documentation

◆ initialize()

void IPopulation::initialize ( int  n)

Initialize a population of a given size.

Parameters
nDesired size of the population.

Definition at line 28 of file IPopulation.cxx.

◆ crossOver()

void IPopulation::crossOver ( )

Performs population cross-over.

Definition at line 34 of file IPopulation.cxx.

◆ mutate()

void IPopulation::mutate ( )

Performs individual mutations.

Definition at line 56 of file IPopulation.cxx.

◆ score()

void IPopulation::score ( )

Compute the scores for the members of the population.

This function also calculates the mean and RMS for the scores of this population.

Definition at line 93 of file IPopulation.cxx.

◆ setRandomSeed()

void IPopulation::setRandomSeed ( int  seed)

Sets the random seed for the random number generator.

Parameters
seedRandom number generator seed.

Definition at line 70 of file IPopulation.cxx.

◆ setMutateRate()

void IPopulation::setMutateRate ( double  rate)

Sets the mutation rate.

Parameters
rateDesired mutation rate.

Definition at line 79 of file IPopulation.cxx.

◆ setFigureOfMerit()

void IPopulation::setFigureOfMerit ( IFigureOfMerit fom)

Sets the figure of merit to be used to calculate scores and perform the ranking.

Parameters
fomPointer to a figure of merit object to be used to calculate scores and perform the ranking.

Definition at line 120 of file IPopulation.cxx.

◆ getFigureOfMerit()

IFigureOfMerit * IPopulation::getFigureOfMerit ( )

Returns the figure of merit that is used to calculate scores and perform the ranking.

Returns
Pointer to the figure of merit object used to calculate scores and perform the ranking.

Definition at line 128 of file IPopulation.cxx.

◆ getBestFitted()

IModel * IPopulation::getBestFitted ( int  rank = 0)

Returns the method at a given rank.

Parameters
rankRank.
Returns
Model at the given rank.

Definition at line 137 of file IPopulation.cxx.

◆ size()

int IPopulation::size ( )

Returns the size of the population.

Returns
Size of this population.

Definition at line 154 of file IPopulation.cxx.

◆ getScoreMean()

double IPopulation::getScoreMean ( )

Returns the mean score for the population.

Returns
Mean score for this population.

Definition at line 162 of file IPopulation.cxx.

◆ getScoreRMS()

double IPopulation::getScoreRMS ( )

Returns the RMS of the scores for the population.

Returns
RMS of the scores for this population.

Definition at line 170 of file IPopulation.cxx.

◆ clear()

void IPopulation::clear ( )

Resets the population.

Definition at line 175 of file IPopulation.cxx.

◆ doInitialize()

virtual void IPopulation::doInitialize ( int  n)
protectedpure virtual

Should implement the actual initialization.

Implemented in ParametricModelPopulation.

◆ doCrossOver()

virtual void IPopulation::doCrossOver ( const std::vector< std::vector< IModel *> > &  parents)
protectedpure virtual

Should implement the cross-over.

Implemented in ParametricModelPopulation.

◆ doMutate()

virtual void IPopulation::doMutate ( IModel model)
protectedpure virtual

Should implement the mutation of a model.

Implemented in ParametricModelPopulation.

◆ selectParents()

void IPopulation::selectParents ( int &  p1,
int &  p2 
)
protectedvirtual

Selects parents to be crossed-over

Parameters
p1Returns the index of the first parent.
p2Returns the index of the second parent.

Definition at line 221 of file IPopulation.cxx.

◆ sort()

void IPopulation::sort ( )
protected

Performs the ranking from the best to the least fitted.

Definition at line 183 of file IPopulation.cxx.

◆ checkFigureOfMerit()

void IPopulation::checkFigureOfMerit ( )
protected

Makes sure an IFigureOfMerit object is assigned to this population.

Definition at line 209 of file IPopulation.cxx.


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