GLPopulationStandard Class Reference

#include <GLPopulationStandard.h>

Inheritance diagram for GLPopulationStandard:

GLBasePopulation

List of all members.

Public Member Functions

 GLPopulationStandard (bool keep_corpses=GLConstants::CORPSES_KEEP)
virtual ~GLPopulationStandard ()
virtual int breed (GLBaseBreeder *breeder, int max_offsprings=-1)
void clearMorgue ()
virtual int evaluateAll (GLBaseEvaluator *evaluator)
bool isKeepCorpses () const
virtual bool isOrganismTrulyNew (const GLBaseOrganism *organism) const
virtual int keepFittest (GLBaseSelectionist *selectionist, vector< const GLBaseOrganism * > &best_organisms, int new_size=-1)
virtual int mutate (GLBaseVariator *variator, int max_mutants=-1, int mutation_policy=GLConstants::MUTATE_CHILDREN|GLConstants::MUTATE_PARENTS)
virtual void populate (int size, GLBaseOrganismInitialiser *initialiser, GLConstants::TTwinsFlags twins=GLConstants::NO_TWINS)
virtual void prepareForNextGeneration ()
virtual void processCorpses (vector< GLBaseOrganism * > &corpses)
void setKeepCorpses (bool new_flag)

Protected Member Functions

virtual int evaluateOrganisms (GLBaseOrganismStorage *container, GLBaseEvaluator *evaluator, bool not_evaluated_only=true)

Protected Attributes

GLBaseOrganismStoragem_offsprings
 here the children are stored.
GLBaseOrganismStoragem_mutants
 here the mutants are stored.
bool m_keep_corpses
TGLSetOfOrganismsConst m_morgue
 here all the discarded organisms are to be kept


Detailed Description

Standard population -- basic real class implementing all the pure virtual functions inherited from the parent.

Definition at line 13 of file GLPopulationStandard.h.


Constructor & Destructor Documentation

GLPopulationStandard::GLPopulationStandard ( bool  keep_corpses = GLConstants::CORPSES_KEEP  ) 

Constructor, creates all the storage containers.

Definition at line 13 of file GLPopulationStandard.cpp.

GLPopulationStandard::~GLPopulationStandard (  )  [virtual]

Destructor, deletes all the storage containers.

Definition at line 21 of file GLPopulationStandard.cpp.


Member Function Documentation

int GLPopulationStandard::breed ( GLBaseBreeder breeder,
int  max_offsprings = -1 
) [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.
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.

Implements GLBasePopulation.

Definition at line 47 of file GLPopulationStandard.cpp.

void GLPopulationStandard::clearMorgue (  ) 

Empties morgue deleting all the rejected organisms which were stored there.

Definition at line 59 of file GLPopulationStandard.cpp.

int GLPopulationStandard::evaluateAll ( GLBaseEvaluator evaluator  )  [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).

Implements GLBasePopulation.

Definition at line 80 of file GLPopulationStandard.cpp.

int GLPopulationStandard::evaluateOrganisms ( GLBaseOrganismStorage container,
GLBaseEvaluator evaluator,
bool  not_evaluated_only = true 
) [protected, virtual]

Evaluates all the organisms in the container.

Parameters:
container container with organisms.
evaluator evaluator operator.
not_evaluated_only when true evaluator will be applied to organisms which were not evaluated before.
Returns:
the number of evaluated organisms.
Evaluates all the organisms in the container.
Parameters:
container container with organisms.
evaluator evaluator operator.
not_evaluated_only when true evaluator will be applied to organisms which were not evaluated before.

Definition at line 95 of file GLPopulationStandard.cpp.

bool GLPopulationStandard::isKeepCorpses (  )  const [inline]

Returns the flag indicating whether unsuccesfull organisms are destroyed or kept in 'morgue'.

Definition at line 57 of file GLPopulationStandard.h.

bool GLPopulationStandard::isOrganismTrulyNew ( const GLBaseOrganism organism  )  const [virtual]

Checks, if organism is really the new one -- check among the current population, newly created mutants, children and in morgue (where rejected organisms are stored) if not empty. Returns true if no identical (with the same chromosome set) organism was found.

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

Implements GLBasePopulation.

Definition at line 127 of file GLPopulationStandard.cpp.

int GLPopulationStandard::keepFittest ( GLBaseSelectionist selectionist,
vector< const GLBaseOrganism * > &  best_organisms,
int  new_size = -1 
) [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.
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 newly created 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.

Implements GLBasePopulation.

Definition at line 158 of file GLPopulationStandard.cpp.

int GLPopulationStandard::mutate ( GLBaseVariator variator,
int  max_mutants = -1,
int  mutation_policy = GLConstants::MUTATE_CHILDREN | GLConstants::MUTATE_PARENTS 
) [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.
mutation_policy determines whether mutator to be applied to children and / or to parents.
max_mutants maximum number of mutants generated. if < 0 -- number is limited only by the mutation algorithm used.
Returns:
number of mutated organisms.
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.
apply_to_newborns when true it can also be applied to the newly born children (after Breed function call).
max_mutants maximum number of mutants generated. if < 0 -- number is limited only by the mutation algorithm used.
Returns:
number of mutated organisms.

Implements GLBasePopulation.

Definition at line 200 of file GLPopulationStandard.cpp.

void GLPopulationStandard::populate ( int  size,
GLBaseOrganismInitialiser initialiser,
GLConstants::TTwinsFlags  twins = GLConstants::NO_TWINS 
) [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.

Implements GLBasePopulation.

Definition at line 240 of file GLPopulationStandard.cpp.

void GLPopulationStandard::prepareForNextGeneration (  )  [virtual]

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

Reimplemented from GLBasePopulation.

Definition at line 257 of file GLPopulationStandard.cpp.

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

Depending on the value of flag isKeepCorpses() either places them into 'morgue' or deletes the organisms and empties the vector.

Parameters:
corpses vector of organisms to be discarded.

Implements GLBasePopulation.

Definition at line 270 of file GLPopulationStandard.cpp.

void GLPopulationStandard::setKeepCorpses ( bool  new_flag  )  [inline]

Sets the policy, whether to keep expand the morgue with new arrivals or not. Note, that when 'false' is passed, new corpses are not added to the morgue, but it is not emptied. Use method clearMorgue for this.

Parameters:
new_flag new value of the flag which determines the policy regarding the corpses.

Definition at line 140 of file GLPopulationStandard.h.


Member Data Documentation

when true all the discarded organisms are kept there instead of to be discarded.

Definition at line 162 of file GLPopulationStandard.h.


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

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