GLOrganismVector< T > Class Template Reference

#include <GLOrganismVector.h>

Inheritance diagram for GLOrganismVector< T >:

GLBaseOrganism GLInterfaceExchangeableGenes GLInterfaceMoveGene GLInterfaceShuffleGenes GLInterfaceSwapSection GLInterfaceSwapTails

List of all members.

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 GLBaseOrganismmakeClone (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.


Detailed Description

template<class T>
class GLOrganismVector< T >

Class based on the 1D vector representation of the organism.

Definition at line 24 of file GLOrganismVector.h.


Constructor & Destructor Documentation

template<class T >
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.

Parameters:
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.

template<class T >
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.

Parameters:
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.

template<class T >
GLOrganismVector< T >::GLOrganismVector ( const GLOrganismVector< T > &  source  )  [inline]

Copying constructor.

Parameters:
source source organism.

Definition at line 57 of file GLOrganismVector.cpp.

template<class T >
GLOrganismVector< T >::~GLOrganismVector (  )  [inline, virtual]

Destructor. Destroys everything.

Definition at line 72 of file GLOrganismVector.cpp.


Member Function Documentation

template<class T >
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.

Parameters:
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.
Checks if the passed pointer is compatible with the current class. If not will throw GLLogicError. Normally this class should be overloaded in parents.
Parameters:
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.

template<class T>
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.

Parameters:
gene gene to be checked.

Definition at line 105 of file GLOrganismVector.h.

template<class T>
virtual bool GLOrganismVector< T >::checkIndex ( int  index  )  const [inline, virtual]

Checks, that index is withing the organism size's limits.

Parameters:
index index of the gene in the organism.
Returns:
true if index >= 0 and index < getSize().

Definition at line 114 of file GLOrganismVector.h.

template<class T >
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.

Parameters:
source source organism.

Reimplemented from GLBaseOrganism.

Definition at line 109 of file GLOrganismVector.cpp.

template<class T >
void GLOrganismVector< T >::exchangeGenes ( int  first,
int  second 
) [inline, virtual]

Exchanges 2 genes withing the organism.

Parameters:
first index of the first gene.
second index of the second gene.

Implements GLInterfaceExchangeableGenes.

Definition at line 130 of file GLOrganismVector.cpp.

template<class T>
const vector<T>& GLOrganismVector< T >::getChromosome (  )  const [inline]

Return the chromosome of the organism -- vector with genetic information.

Returns:
organism's full genetic information.

Definition at line 138 of file GLOrganismVector.h.

template<class T >
const T & GLOrganismVector< T >::getGene ( int  index  )  const [inline]

Returns the single gene of the organism.

Parameters:
index gene's index.
Returns:
single gene.

Definition at line 172 of file GLOrganismVector.cpp.

template<class T >
T & GLOrganismVector< T >::getGene ( int  index  )  [inline]

Returns the single gene of the organism.

Parameters:
index gene's index.
Returns:
single gene.

Definition at line 152 of file GLOrganismVector.cpp.

template<class T>
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&> ??)

Returns:
boundaries imposed on the gene's values.

Definition at line 162 of file GLOrganismVector.h.

template<class T>
GLConstants::TGeneBounds GLOrganismVector< T >::getPropertyBounds (  )  const [inline]

Return property of the bounds on organism's genes.

Returns:
whether organism's genes have bounds or not.

Definition at line 176 of file GLOrganismVector.h.

template<class T>
GLConstants::TSizeLimits GLOrganismVector< T >::getPropertySize (  )  const [inline]

Returns the property of the organism's size.

Returns:
whether organism is fixed size, limited variable size etc.

Definition at line 169 of file GLOrganismVector.h.

template<class T >
int GLOrganismVector< T >::getSize (  )  const [inline, virtual]

Returns the current size of the organism (number of genes).

Returns:
size of the organism.

Implements GLBaseOrganism.

Definition at line 191 of file GLOrganismVector.cpp.

template<class T >
bool GLOrganismVector< T >::isEqual ( const GLBaseOrganism organism,
bool  soft = true 
) const [inline, virtual]

Returns true if 2 organisms are equal.

Parameters:
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.

template<class T >
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.

Parameters:
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.

template<class T >
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;

Parameters:
soft when true only genetic information (chromosome) is copied to the clone.
Returns:
the copy of the current organsim.

Implements GLBaseOrganism.

Definition at line 262 of file GLOrganismVector.cpp.

template<class T >
void GLOrganismVector< T >::moveGene ( int  old_position,
int  new_position 
) [inline, virtual]

Moves the genes from one position to another.

Parameters:
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.

template<class T>
T& GLOrganismVector< T >::operator[] ( int  i  )  [inline]

Operator for accessing genes in vector-like manner.

Parameters:
i index of the gene to be obtained.
Returns:
requested gene.

Definition at line 86 of file GLOrganismVector.h.

template<class T>
const T& GLOrganismVector< T >::operator[] ( int  i  )  const [inline]

Operator for accessing genes in vector-like manner.

Parameters:
i index of the gene to be obtained.
Returns:
requested gene.

Definition at line 78 of file GLOrganismVector.h.

template<class T>
void GLOrganismVector< T >::removeGeneBounds (  )  [inline]

Removes bounds for organism's genes.

Definition at line 229 of file GLOrganismVector.h.

template<class T >
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.

Parameters:
chromosome vector of genes to be filled by the organism.

Definition at line 313 of file GLOrganismVector.cpp.

template<class T >
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)

Parameters:
index index of the gene.
gene new value of the gene.
Sets the value of the i-th gene.
Parameters:
index index of the gene.
gene new value of the gene.

Definition at line 366 of file GLOrganismVector.cpp.

template<class T >
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.

Parameters:
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.
Sets the bounds on the organism's genes. Automatically sets property bounds to GLConstants::BoundedGenes.
Parameters:
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.
Returns:
true if organism was corrected and false otherwise (always false if correct_organism was false).

Definition at line 403 of file GLOrganismVector.cpp.

template<class T>
void GLOrganismVector< T >::setPropertySize ( GLConstants::TSizeLimits  size_limits  )  [inline]

Sets the property of the organism's size.

Parameters:
size_limits new property of the organism's size (fixed, or not).

Definition at line 244 of file GLOrganismVector.h.

template<class T >
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.

Parameters:
gene_numbers vector of positions of the genes to be shuffled.

Implements GLInterfaceShuffleGenes.

Definition at line 485 of file GLOrganismVector.cpp.

template<class T >
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.

Parameters:
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.

template<class T >
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.

Parameters:
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.

template<class T >
ostream & GLOrganismVector< T >::toStream ( ostream &  out  )  const [inline, virtual]

Outputs the containt of the organism to output stream.

Parameters:
out output stream.

Definition at line 590 of file GLOrganismVector.cpp.

template<class T >
ostream & GLOrganismVector< T >::toStreamDebug ( ostream &  out  )  const [inline, virtual]

Outputs the containt of the organism to output stream in debug mode.

Parameters:
out output stream.

Definition at line 605 of file GLOrganismVector.cpp.


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