Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

gal::Population< T > Class Template Reference

Population is the center of an optimisation run: it contains all Chromosome members, the Problem at hand, and evolves the population through many generations. More...

#include <Population.h>

List of all members.

Public Member Functions

 Population (Problem< T > *problem)
 Constructs a new Population without initialising.
 Population (Problem< T > *problem, int size, int chromoLength)
 Constructs a new Population and fills and initialises it.
 ~Population ()
 Destroys this Population, freeing all used resources.
void addMember (Chromosome< T > *g)
 Adds a Chromosome as a member to this Population.
int const size ()
 The number of Chromosomes in this Population.
void initialise (int size, int chromoLength)
 Initialises this population with a number of random members.
void setEliteSize (int nrElite)
 Sets the size of the elite subgroup.
void setProbabilities (double probMutate, double probCrossover)
 Sets probabilities for genetic evolution.
void evaluateFitness ()
 Evaluates the fitness of the current population.
void markElite ()
 Selects the new elite members for the current population.
void mutate ()
 Performs mutation on the population members.
int selectByRoulette ()
 Selects a new Chromosome from the current population by roulette wheel selection.
void selectAndReproduce ()
 Evolves the current population (generation) into the next generation with the following techniques: 1.
void nextGeneration ()
 Evolutes the population into a new generation.
void const print (int generationNr, int printbits, int printmode, std::ostream &outstr)
 Prints population details on screen.
int testConvergence (int nrequal)
 Tests whether the Population has 'converged'.
void writePopulation (std::ostream &outstr)
 Writes all members in current population to a file (or other output stream).
void readPopulation (std::istream &instr)
 Reads population data from a file (or other input stream) as produced by writePopulation and updates the population with the chromosome data.


Detailed Description

template<class T>
class gal::Population< T >

Population is the center of an optimisation run: it contains all Chromosome members, the Problem at hand, and evolves the population through many generations.

The Population type is a template type and needs to be instantiated with the base type of the search domain. For a function f: R -> R this type is simply 'double'.

See also:
initialise()

nextGeneration()


Constructor & Destructor Documentation

template<class T>
gal::Population< T >::Population Problem< T > *  problem  )  [inline]
 

Constructs a new Population without initialising.

Parameters:
problem The Problem specifying what needs to be optimised.
See also:
initialise()

template<class T>
gal::Population< T >::Population Problem< T > *  problem,
int  size,
int  chromoLength
[inline]
 

Constructs a new Population and fills and initialises it.

Parameters:
problem The Problem specifying what needs to be optimised.
size The number of chromosomes in this population.
chromoLength The chromosome length of members.
See also:
initialise()

template<class T>
gal::Population< T >::~Population  )  [inline]
 

Destroys this Population, freeing all used resources.


Member Function Documentation

template<class T>
void gal::Population< T >::addMember Chromosome< T > *  g  )  [inline]
 

Adds a Chromosome as a member to this Population.

Parameters:
g The Chromosome to be added.

template<class T>
void gal::Population< T >::evaluateFitness  )  [inline]
 

Evaluates the fitness of the current population.

It uses the evaluateObjective function from the Problem object and then normalizes all values, so that they sum up to 1.

Note that a Population aims at MAXIMISING the objective.

template<class T>
void gal::Population< T >::initialise int  size,
int  chromoLength
[inline]
 

Initialises this population with a number of random members.

Parameters:
size The number of chromosomes in this population.
chromoLength The chromosome length of members.

template<class T>
void gal::Population< T >::markElite  )  [inline]
 

Selects the new elite members for the current population.

The selected member Chromosomes are marked as elite, and stored in a Population variable as well.

template<class T>
void gal::Population< T >::mutate  )  [inline]
 

Performs mutation on the population members.

See also:
setProbabilities()

template<class T>
void gal::Population< T >::nextGeneration  )  [inline]
 

Evolutes the population into a new generation.

This is done by mutation, selection and crossover.

See also:
mutate()

selectAndReproduce()

template<class T>
void const gal::Population< T >::print int  generationNr,
int  printbits,
int  printmode,
std::ostream &  outstr
[inline]
 

Prints population details on screen.

printmodes for bitstrings: PRINTINTERP, PRINTBITSTRING, PRINTVALUE, PRINTOBJECTIVE, PRINTFITNESS These modes may be added in any combination, e.g. PRINTBITSTRING | PRINTVALUE

printmodes/selectionmodes for Population members: PRINTALL, PRINTBEST, PRINTWORST, PRINTAVG, ONLYIFBETTER These modes can not be combined, except for ONLYIFBETTER with the others.

Parameters:
generationNr The number ('year') of this generation.
printbits The form in which the bitstring should be printed.
printmode The form in which Population members should be printed.
outstr The stream to which the output should be written.

template<class T>
void gal::Population< T >::readPopulation std::istream &  instr  )  [inline]
 

Reads population data from a file (or other input stream) as produced by writePopulation and updates the population with the chromosome data.

NOTE! Current population should be initialised with same settings for problem, size, elite count, etc.!

Parameters:
instr The input stream to read from.
See also:
writePopulation

template<class T>
void gal::Population< T >::selectAndReproduce  )  [inline]
 

Evolves the current population (generation) into the next generation with the following techniques: 1.

roulette wheel selection to select good chromosomes with high probability. 2. crossover on selected chromosomes to produce offspring.

template<class T>
int gal::Population< T >::selectByRoulette  )  [inline]
 

Selects a new Chromosome from the current population by roulette wheel selection.

Don't forget to disable selected chromosome (at the call site) to prevent double selection.

Returns:
The *index* in _members vector.

template<class T>
void gal::Population< T >::setEliteSize int  nrElite  )  [inline]
 

Sets the size of the elite subgroup.

The next generation will be the first to include elite members.

template<class T>
void gal::Population< T >::setProbabilities double  probMutate,
double  probCrossover
[inline]
 

Sets probabilities for genetic evolution.

Parameters:
probMutate Probability for a single Chromosome bit to mutate.
probCrossover Probability for two Chromosomes to perform crossover.
See also:
Chromosome::mutate()

Chromosome::crossover()

template<class T>
int const gal::Population< T >::size  )  [inline]
 

The number of Chromosomes in this Population.

template<class T>
int gal::Population< T >::testConvergence int  nrequal  )  [inline]
 

Tests whether the Population has 'converged'.

Conversion is defined as an unchanged objective value over several generations.

Parameters:
nrequal Number of generations that should have same objective value.

template<class T>
void gal::Population< T >::writePopulation std::ostream &  outstr  )  [inline]
 

Writes all members in current population to a file (or other output stream).

This can serve as input later for a 'resume'.

Parameters:
outstr The output stream to write to (probably an ofstream).
See also:
readPopulation


The documentation for this class was generated from the following file:
Generated on Tue Oct 20 12:59:25 2009 for LabSci GALib optimisation by genetic algorithms, student version by  doxygen 1.3.9.1