#include <GLOrganismVector.h>
Public Member Functions | |
GLOrganismVector (unsigned init_size, GLConstants::TSizeLimits size_property=GLConstants::FIXED, unsigned max_size=UINT_MAX) | |
GLOrganismVector (const vector< T > &chromosome, GLConstants::TSizeLimits size_property=GLConstants::FIXED, unsigned max_size=UINT_MAX) | |
GLOrganismVector (const GLOrganismVector< T > &source) | |
virtual | ~GLOrganismVector () |
const T & | operator[] (int i) const |
T & | operator[] (int i) |
virtual void | assertCompatibility (const GLBaseOrganism *source, const string &message) const |
bool | checkBounds (const T &gene) |
virtual bool | checkIndex (int index) const |
virtual void | copyGeneticData (const GLBaseOrganism *source) |
virtual void | exchangeGenes (int first, int second) |
const vector< T > & | getChromosome () const |
T & | getGene (int index) |
const T & | getGene (int index) const |
pair< const T, const T > | getGeneBounds () const |
GLConstants::TSizeLimits | getPropertySize () const |
GLConstants::TGeneBounds | getPropertyBounds () const |
virtual int | getSize () const |
virtual bool | isEqual (const GLBaseOrganism *organism, bool soft=true) const |
virtual bool | isLess (const GLBaseOrganism *organism, bool soft=true) const |
virtual GLBaseOrganism * | makeClone (bool soft=true) const |
virtual void | moveGene (int old_position, int new_position) |
void | removeGeneBounds () |
void | setChromosome (const vector< T > &chromosome) |
void | setPropertySize (GLConstants::TSizeLimits size_limits) |
void | setGene (int index, const T &gene) |
bool | setGeneBounds (const T &gene_min, const T &gene_max, bool correct_organism=true) |
virtual void | shuffleGenes (const vector< int > &gene_numbers) |
virtual void | swapSections (GLBaseOrganism *anotherOrganism, int leftPos, int rightPos) |
virtual void | swapTails (GLBaseOrganism *anotherOrganism, int i) |
virtual ostream & | toStream (ostream &out) const |
virtual ostream & | toStreamDebug (ostream &out) const |
Protected Attributes | |
vector< T > | m_storage |
Storage for organism data are stored. |
Definition at line 24 of file GLOrganismVector.h.
GLOrganismVector< T >::GLOrganismVector | ( | unsigned | init_size, | |
GLConstants::TSizeLimits | size_property = GLConstants::FIXED , |
|||
unsigned | max_size = UINT_MAX | |||
) | [inline] |
Creates organism based on 1D vector representation.
init_size | initial size of the organism. Should be non-negative. | |
size_property | determines the size variability of the organism. | |
max_size | maximum size of the organism (used only when size_property is != FIXED, otherwise set to init_size). By default for organism of not_fixed size it will be set to init_size. |
Definition at line 19 of file GLOrganismVector.cpp.
GLOrganismVector< T >::GLOrganismVector | ( | const vector< T > & | chromosome, | |
GLConstants::TSizeLimits | size_property = GLConstants::FIXED , |
|||
unsigned | max_size = UINT_MAX | |||
) | [inline] |
Creates organism based on 1D vector representation.
chromosome | chromosome -- content of the organism. | |
size_property | determines the size variability of the organism. | |
max_size | maximum size of the organism (used only when size_property is != FIXED, otherwise set to chromosome.size()). By default for organism of not_fixed size it will be set to chromosome.size(). |
Definition at line 41 of file GLOrganismVector.cpp.
GLOrganismVector< T >::GLOrganismVector | ( | const GLOrganismVector< T > & | source | ) | [inline] |
Copying constructor.
source | source organism. |
Definition at line 57 of file GLOrganismVector.cpp.
GLOrganismVector< T >::~GLOrganismVector | ( | ) | [inline, virtual] |
Destructor. Destroys everything.
Definition at line 72 of file GLOrganismVector.cpp.
void GLOrganismVector< T >::assertCompatibility | ( | const GLBaseOrganism * | source, | |
const string & | message | |||
) | const [inline, virtual] |
Checks if the passed pointer is compatible with the current class. If not will throw GLLogicError. Normally this class should be overloaded in parents.
source | class to check the compatibility with the current. | |
message | some text to be used in exception. E.g. where this function was called from. |
source | class to check the compatibility with the current. some text to be used in exception. E.g. where this function was called from. |
Reimplemented from GLBaseOrganism.
Definition at line 86 of file GLOrganismVector.cpp.
bool GLOrganismVector< T >::checkBounds | ( | const T & | gene | ) | [inline] |
Checks, that gene is within the organism's bounds. If bounds are not set will always return true.
gene | gene to be checked. |
Definition at line 105 of file GLOrganismVector.h.
virtual bool GLOrganismVector< T >::checkIndex | ( | int | index | ) | const [inline, virtual] |
Checks, that index is withing the organism size's limits.
index | index of the gene in the organism. |
Definition at line 114 of file GLOrganismVector.h.
void GLOrganismVector< T >::copyGeneticData | ( | const GLBaseOrganism * | source | ) | [inline, virtual] |
Copies the genetic information from the source organism to the current one (e.g. chromosome, type or the organism, bounds etc.) leaving out fitness information and similar not-internal data. Normally will reset fitness value.
source | source organism. |
Reimplemented from GLBaseOrganism.
Definition at line 109 of file GLOrganismVector.cpp.
void GLOrganismVector< T >::exchangeGenes | ( | int | first, | |
int | second | |||
) | [inline, virtual] |
Exchanges 2 genes withing the organism.
first | index of the first gene. | |
second | index of the second gene. |
Implements GLInterfaceExchangeableGenes.
Definition at line 130 of file GLOrganismVector.cpp.
const vector<T>& GLOrganismVector< T >::getChromosome | ( | ) | const [inline] |
Return the chromosome of the organism -- vector with genetic information.
Definition at line 138 of file GLOrganismVector.h.
const T & GLOrganismVector< T >::getGene | ( | int | index | ) | const [inline] |
Returns the single gene of the organism.
index | gene's index. |
Definition at line 172 of file GLOrganismVector.cpp.
T & GLOrganismVector< T >::getGene | ( | int | index | ) | [inline] |
Returns the single gene of the organism.
index | gene's index. |
Definition at line 152 of file GLOrganismVector.cpp.
pair<const T, const T> GLOrganismVector< T >::getGeneBounds | ( | ) | const [inline] |
Return the boundaries of the genes. First element in pair is minimum, second is maximum. Note, that if getPropertyBounds == UNBOUNDED_GENE the values in returned structure are undefined. (Why I am not able to return pair<const T&, const T&> ??)
Definition at line 162 of file GLOrganismVector.h.
GLConstants::TGeneBounds GLOrganismVector< T >::getPropertyBounds | ( | ) | const [inline] |
Return property of the bounds on organism's genes.
Definition at line 176 of file GLOrganismVector.h.
GLConstants::TSizeLimits GLOrganismVector< T >::getPropertySize | ( | ) | const [inline] |
Returns the property of the organism's size.
Definition at line 169 of file GLOrganismVector.h.
int GLOrganismVector< T >::getSize | ( | ) | const [inline, virtual] |
Returns the current size of the organism (number of genes).
Implements GLBaseOrganism.
Definition at line 191 of file GLOrganismVector.cpp.
bool GLOrganismVector< T >::isEqual | ( | const GLBaseOrganism * | organism, | |
bool | soft = true | |||
) | const [inline, virtual] |
Returns true if 2 organisms are equal.
organism | another organism to be compared with. | |
soft | when true soft comparison is done -- only gene's value. When false compares all others values -- fitness fucntion etc. Tag's value are never compared. |
First, find out if the second organism is comparable in principle.
Implements GLBaseOrganism.
Definition at line 203 of file GLOrganismVector.cpp.
bool GLOrganismVector< T >::isLess | ( | const GLBaseOrganism * | organism, | |
bool | soft = true | |||
) | const [inline, virtual] |
Returns true if this organism is less the one passed as a parameter.
organism | another organism to be compared with. | |
soft | when true soft comparison is done -- based only on gene's value. When false compares all others values -- fitness fucntion etc. Tag's value are never compared. |
Implements GLBaseOrganism.
Definition at line 230 of file GLOrganismVector.cpp.
GLBaseOrganism * GLOrganismVector< T >::makeClone | ( | bool | soft = true |
) | const [inline, virtual] |
Creates the copy of the current organism. Do not forget to delete it, once not needed anymore. this->isEqual(makeClone(true), true) == true; this->isEqual(makeClone(true), false) == ?; this->isEqual(makeClone(false), false) == true;
soft | when true only genetic information (chromosome) is copied to the clone. |
Implements GLBaseOrganism.
Definition at line 262 of file GLOrganismVector.cpp.
void GLOrganismVector< T >::moveGene | ( | int | old_position, | |
int | new_position | |||
) | [inline, virtual] |
Moves the genes from one position to another.
old_position | where the gene is moving from. | |
new_position | where the gene is moving to. |
Implements GLInterfaceMoveGene.
Definition at line 276 of file GLOrganismVector.cpp.
T& GLOrganismVector< T >::operator[] | ( | int | i | ) | [inline] |
Operator for accessing genes in vector-like manner.
i | index of the gene to be obtained. |
Definition at line 86 of file GLOrganismVector.h.
const T& GLOrganismVector< T >::operator[] | ( | int | i | ) | const [inline] |
Operator for accessing genes in vector-like manner.
i | index of the gene to be obtained. |
Definition at line 78 of file GLOrganismVector.h.
void GLOrganismVector< T >::removeGeneBounds | ( | ) | [inline] |
Removes bounds for organism's genes.
Definition at line 229 of file GLOrganismVector.h.
void GLOrganismVector< T >::setChromosome | ( | const vector< T > & | chromosome | ) | [inline] |
Sets the whole chromosome. If the organism of the fixed size the chromosome must be == size of the organism. If bounds for the organism are sets checks are made that those bounds are satisfied.
chromosome | vector of genes to be filled by the organism. |
Definition at line 313 of file GLOrganismVector.cpp.
void GLOrganismVector< T >::setGene | ( | int | index, | |
const T & | gene | |||
) | [inline] |
Sets the value of the i-th gene. If fitness function was evaluated -- reset it when gene != getGene(index)
index | index of the gene. | |
gene | new value of the gene. |
index | index of the gene. | |
gene | new value of the gene. |
Definition at line 366 of file GLOrganismVector.cpp.
bool GLOrganismVector< T >::setGeneBounds | ( | const T & | gene_min, | |
const T & | gene_max, | |||
bool | correct_organism = true | |||
) | [inline] |
Sets the bounds on the organism's genes. Automatically sets property bounds to GLConstants::BoundedGenes.
gene_min | minimum value of the gene. | |
gene_max | maximum value of the gene. | |
correct_organism | when true, ensures that after limits were imposed organism's genes are within the boundaries. |
gene_min | minimum value of the gene. | |
gene_max | maximum value of the gene. | |
correct_organism | when true, ensures that after limits were imposed organism's genes are within the boundaries. |
Definition at line 403 of file GLOrganismVector.cpp.
void GLOrganismVector< T >::setPropertySize | ( | GLConstants::TSizeLimits | size_limits | ) | [inline] |
Sets the property of the organism's size.
size_limits | new property of the organism's size (fixed, or not). |
Definition at line 244 of file GLOrganismVector.h.
void GLOrganismVector< T >::shuffleGenes | ( | const vector< int > & | gene_numbers | ) | [inline, virtual] |
Shuffles the set of genes in the organism. Genes which are in the positions from the gene_numbers vector will be randomly shuffled. Genes from other positions will stay where they are.
gene_numbers | vector of positions of the genes to be shuffled. |
Implements GLInterfaceShuffleGenes.
Definition at line 485 of file GLOrganismVector.cpp.
void GLOrganismVector< T >::swapSections | ( | GLBaseOrganism * | anotherOrganism, | |
int | leftPos, | |||
int | rightPos | |||
) | [inline, virtual] |
Swaps sections with another organism. After this method is called the current organism should have section of the anotherOrganism, while the latter will have the section of the caller. Therefore, all genes from the caller with numbers leftPos, rightPos - 1 inclusive will go to the anotherOrganism, while be replaced with the corresponding genes from anotherOrganism in caller. If rightPos == organism.getSize() the effect is equivalent to swapping tails. leftPos must be < rightPos.
anotherOrganism | organism with which the section will be swapped. | |
leftPos | the beginning of the section to be swapped (this gene will be swapped too). | |
rightPos | the end of the section to be swapped (this gene will NOT be swapped). |
Implements GLInterfaceSwapSection.
Definition at line 518 of file GLOrganismVector.cpp.
void GLOrganismVector< T >::swapTails | ( | GLBaseOrganism * | anotherOrganism, | |
int | pos | |||
) | [inline, virtual] |
Swaps tails with another organism. After this method is called the current organism should have tail of the anotherOrganism, while the latter will have the tail of the caller.
Swaps tails with another organism. After this method is called the current organism should have tail of the anotherOrganism, while the latter will have the tail of the caller.
anotherOrganisms | organism with which the tails will be swapped. | |
pos | point starting with which the tails will be swapped (including this position). |
Implements GLInterfaceSwapTails.
Definition at line 563 of file GLOrganismVector.cpp.
ostream & GLOrganismVector< T >::toStream | ( | ostream & | out | ) | const [inline, virtual] |
Outputs the containt of the organism to output stream.
out | output stream. |
Definition at line 590 of file GLOrganismVector.cpp.
ostream & GLOrganismVector< T >::toStreamDebug | ( | ostream & | out | ) | const [inline, virtual] |
Outputs the containt of the organism to output stream in debug mode.
out | output stream. |
Definition at line 605 of file GLOrganismVector.cpp.