#include <GLPopulationStandard.h>
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 | |
GLBaseOrganismStorage * | m_offsprings |
here the children are stored. | |
GLBaseOrganismStorage * | m_mutants |
here the mutants are stored. | |
bool | m_keep_corpses |
TGLSetOfOrganismsConst | m_morgue |
here all the discarded organisms are to be kept |
Definition at line 13 of file GLPopulationStandard.h.
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.
int GLPopulationStandard::breed | ( | GLBaseBreeder * | breeder, | |
int | max_offsprings = -1 | |||
) | [virtual] |
Create new organisms in population by applying crossover.
breeder | class for producing the offsprings. | |
max_offsprings | maximum number of children generated. if < 0 -- number is limited only by the crossover operator used. |
breeder | class for producing the offsprings. | |
max_offsprings | maximum number of children generated. if <= 0 -- number is limited only by the crossover operator used. |
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.
evaluator | evaluator operator. |
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.
container | container with organisms. | |
evaluator | evaluator operator. | |
not_evaluated_only | when true evaluator will be applied to organisms which were not evaluated before. |
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.
organism | organism to be checked for uniqueness. |
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.
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. |
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. |
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).
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. |
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. |
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.
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.
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.
new_flag | new value of the flag which determines the policy regarding the corpses. |
Definition at line 140 of file GLPopulationStandard.h.
bool GLPopulationStandard::m_keep_corpses [protected] |
when true all the discarded organisms are kept there instead of to be discarded.
Definition at line 162 of file GLPopulationStandard.h.