GLBasePopulation Class Reference

#include <GLBasePopulation.h>

Inheritance diagram for GLBasePopulation:

GLPopulationStandard

List of all members.

Public Member Functions

 GLBasePopulation (GLBaseOrganismStorage *storage)
virtual ~GLBasePopulation ()
bool addOrganism (GLBaseOrganism *organism, GLConstants::TTwinsFlags twins=GLConstants::NO_TWINS)
virtual int breed (GLBaseBreeder *breeder, int max_offsprings=-1)=0
virtual int createNewGeneration (GLBaseBreeder *breeder, GLBaseVariator *variator, GLBaseEvaluator *evaluator, GLBaseSelectionist *selectionist, vector< const GLBaseOrganism * > &best_organisms, int max_offsprings=-1, int max_mutants=-1, int mutation_policy=GLConstants::MUTATE_CHILDREN|GLConstants::MUTATE_PARENTS, int new_size=-1)
virtual int evaluateAll (GLBaseEvaluator *evaluator)=0
int getSize ()
virtual int getOrganismsVector (vector< const GLBaseOrganism * > &container, GLConstants::TStorageFilling fill=GLConstants::APPEND, int size=-1, bool copy_clones=false) const
virtual int getOrganismsVector (vector< GLBaseOrganism * > &container, GLConstants::TStorageFilling fill=GLConstants::APPEND, int size=-1, bool copy_clones=false)
virtual bool isOrganismTrulyNew (const GLBaseOrganism *organism) const =0
virtual int keepFittest (GLBaseSelectionist *selectionist, vector< const GLBaseOrganism * > &best_organisms, int new_size=-1)=0
virtual int mutate (GLBaseVariator *variator, int max_mutants=-1, int mutation_policy=GLConstants::MUTATE_CHILDREN|GLConstants::MUTATE_PARENTS)=0
virtual void populate (int size, GLBaseOrganismInitialiser *initialiser, GLConstants::TTwinsFlags twins=GLConstants::NO_TWINS)=0
virtual void prepareForNextGeneration ()
virtual void processCorpses (vector< GLBaseOrganism * > &corpses)=0
virtual void printRankedPopulation (ostream &out, GLBaseEvaluator *evaluator, GLBaseRanker *ranker)

Protected Attributes

GLBaseOrganismStoragem_main_storage


Detailed Description

Base class for keeping and maintaining the population of organisms. In general, population is supposed to delete all the organisms in destructor, so please, take care to save organisms you need somewhere else.

Definition at line 18 of file GLBasePopulation.h.


Constructor & Destructor Documentation

GLBasePopulation::GLBasePopulation ( GLBaseOrganismStorage storage  ) 

Constructor, creates the population of given size and initialising it, if necessary.

Parameters:
storage main storage container for keeping the organisms.

Definition at line 15 of file GLBasePopulation.cpp.

GLBasePopulation::~GLBasePopulation (  )  [virtual]

Destroys everything worth destroying.

Definition at line 30 of file GLBasePopulation.cpp.


Member Function Documentation

bool GLBasePopulation::addOrganism ( GLBaseOrganism organism,
GLConstants::TTwinsFlags  twins = GLConstants::NO_TWINS 
) [inline]

Adds new organism to population. If the 'allow_duplicates' it false and organism is already in the population -- do not add it.

Parameters:
organism new organism to be added to storage.
twins when NO_TWINS, check that this organism is not in the storage already.
Returns:
true if organism was succesfully added and false otherwise.

Definition at line 41 of file GLBasePopulation.h.

virtual int GLBasePopulation::breed ( GLBaseBreeder breeder,
int  max_offsprings = -1 
) [pure virtual]

Create new organisms in population by applying crossover.

Parameters:
breeder class for producing the offsprings.
max_offsprings maximum number of children generated. if < 0 -- number is limited only by the crossover operator used.
Returns:
number of newly created organisms.

Implemented in GLPopulationStandard.

int GLBasePopulation::createNewGeneration ( GLBaseBreeder breeder,
GLBaseVariator variator,
GLBaseEvaluator evaluator,
GLBaseSelectionist selectionist,
vector< const GLBaseOrganism * > &  best_organisms,
int  max_offsprings = -1,
int  max_mutants = -1,
int  mutation_policy = GLConstants::MUTATE_CHILDREN | GLConstants::MUTATE_PARENTS,
int  new_size = -1 
) [virtual]

Creates new generation from the existing pool of organism. The general algorithm is following: 1) Create offsprings by using the crossover operator. 2) Create mutants by applying mutator. 3) Evaluate all or new only organisms. 4) Keep the fittest.

Parameters:
breeder class for producing the offsprings.
variator class to mutate the organisms in container.
evaluator class for evaluating the organisms.
selectionist class to select those to be included in the next generation.
best_organisms best organism(s) in newly created population. The previous content of this vector will be lost.
max_offsprings maximum number of offsprings generated. if < 0 -- number is limited only by the breeding algorithm used.
max_mutants maximum number of mutants generated. if < 0 -- number is limited only by the mutation algorithm used.
mutation_policy determines whether mutator to be applied to children and / or to parents.
new_size the size of the new population. If < 0 its size will be equal to the size of the current population.
Returns:
number of new organisms in the new generation.

Definition at line 68 of file GLBasePopulation.cpp.

virtual int GLBasePopulation::evaluateAll ( GLBaseEvaluator evaluator  )  [pure virtual]

Evaluates all the organisms in the population. It is up to implementation to decide, whether to evaluate only new organisms or all of them.

Parameters:
evaluator evaluator operator.
Returns:
number of organism which were evaluated (for which evaluation operator was called).

Implemented in GLPopulationStandard.

virtual int GLBasePopulation::getOrganismsVector ( vector< GLBaseOrganism * > &  container,
GLConstants::TStorageFilling  fill = GLConstants::APPEND,
int  size = -1,
bool  copy_clones = false 
) [inline, virtual]

Provides the vector of pointers to the organisms in storage starting from the first one. The base version uses iterator to fill the vector, however, for real implementation of storage which uses stl containers more efficient approach should be possible.

Parameters:
container vector of pointers to the organisms from storage (output value).
fill when APPEND the new organisms are added to the container, when REPLACE -- the container is cleaned before adding the organisms.
size number of organisms from storage to be returned in vector. if < 0 or > getSize() then returns all the organisms.
copy_clones when true the pointers to the clones of the organisms will be copied, otherwise -- pointers to the original organisms.
Returns:
number of elements transferred to container.

Definition at line 155 of file GLBasePopulation.h.

virtual int GLBasePopulation::getOrganismsVector ( vector< const GLBaseOrganism * > &  container,
GLConstants::TStorageFilling  fill = GLConstants::APPEND,
int  size = -1,
bool  copy_clones = false 
) const [inline, virtual]

Returns the vector of pointers to the organisms from main storage.

Parameters:
container vector of pointers to the organisms from storage (output value).
fill when APPEND the new organisms are added to the container, when REPLACE -- the container is cleaned before adding the organisms.
size number of organisms from storage to be returned in vector. if < 0 or > getSize() then returns all the organisms.
copy_clones when true the pointers to the clones of the organisms will be returned, otherwise -- pointers to the original organisms.
Returns:
number of elements transferred to container.

Definition at line 128 of file GLBasePopulation.h.

int GLBasePopulation::getSize (  )  [inline]

Returns the current size of the population.

Returns:
the current size of the population.

Definition at line 110 of file GLBasePopulation.h.

virtual bool GLBasePopulation::isOrganismTrulyNew ( const GLBaseOrganism organism  )  const [pure virtual]

Checks, if organism is really the new one for this population.

Parameters:
organism organism to be checked for uniqueness.
Returns:
true if no identical organisms was found everywhere within population.

Implemented in GLPopulationStandard.

virtual int GLBasePopulation::keepFittest ( GLBaseSelectionist selectionist,
vector< const GLBaseOrganism * > &  best_organisms,
int  new_size = -1 
) [pure virtual]

Forms the new generation out of existing organisms by using the selectionist. The size of the new generation will be new_size or the total number of organisms available, whatever is less. This function normally to be called after methods 'breed', 'mutate' and 'evaluateAll' were called.

Parameters:
selectionist class to select those to be included in the next generation.
best_organisms best organism(s) in new generation. The previous content of this vector will be lost.
new_size size of the new generation. If < 0 then the size of the new generation will be == the size of the current one.
Returns:
number of NEW organisms (not present in current generation) in next generation.

Implemented in GLPopulationStandard.

virtual int GLBasePopulation::mutate ( GLBaseVariator variator,
int  max_mutants = -1,
int  mutation_policy = GLConstants::MUTATE_CHILDREN|GLConstants::MUTATE_PARENTS 
) [pure virtual]

Mutate the original population and the newborn (it is assumed, that this method is called after Breed).

Parameters:
variator mutator operator to be applied to the organisms.
max_mutants maximum number of mutants generated. if < 0 -- number is limited only by the mutation algorithm used.
mutation_policy determines whether mutator to be applied to children and / or to parents.
Returns:
number of mutated organisms.

Implemented in GLPopulationStandard.

virtual void GLBasePopulation::populate ( int  size,
GLBaseOrganismInitialiser initialiser,
GLConstants::TTwinsFlags  twins = GLConstants::NO_TWINS 
) [pure virtual]

Cleans the population and adds new organisms.

Parameters:
size number of new organisms to be set.
initialiser factory for organisms production.
twins when NO_TWINS no duplicates are possible in the population.

Implemented in GLPopulationStandard.

virtual void GLBasePopulation::prepareForNextGeneration (  )  [inline, virtual]

Last function to be called in create new generation. Deletes temporary arrays etc.

Reimplemented in GLPopulationStandard.

Definition at line 225 of file GLBasePopulation.h.

void GLBasePopulation::printRankedPopulation ( ostream &  out,
GLBaseEvaluator evaluator,
GLBaseRanker ranker 
) [virtual]

DEBUG METHOD. Evaluates the organisms in population and prints them in ranked order. Note, that this debug method may change the organisms' states by evaluating them.

Parameters:
out output stream.
evaluator evaluator for evaluating elements.
ranker operator to arrange the organisms according to their rank.

Definition at line 113 of file GLBasePopulation.cpp.

virtual void GLBasePopulation::processCorpses ( vector< GLBaseOrganism * > &  corpses  )  [pure virtual]

Method to deal with discarded elements -- free memory, keep it in 'morgue' to avoid considered organisms twice etc. After this operation the vector of corpses should be empty.

Parameters:
corpses vector of organisms to be discarded.

Implemented in GLPopulationStandard.


Member Data Documentation

Here core (active) population is stored. Only members from this container are considered to be members of the current population.

Definition at line 250 of file GLBasePopulation.h.


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

Generated on Sat Jun 13 13:58:07 2009 for GenLib by  doxygen 1.5.9