Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

gal::Chromosome< T > Class Template Reference

Represents a chromosome that models a value of any type T. More...

#include <Chromosome.h>

Inheritance diagram for gal::Chromosome< T >:

[legend]
List of all members.

Public Member Functions

 Chromosome ()
 Constructs an empty Chromosome.
 Chromosome (int length)
 Constructs a Chromosome, initialised with a random bitstring.
int length ()
 Returns the length of the bitstring.
bool isElite ()
 Returns whether this Chromosome has the elite-status, which is needed in the Population evolution.
void setElite (bool isElite=true)
 Sets the elite status of this chromosome.
void setLength (int length)
 Sets the number of bits in this Chromosome's bitstring.
virtual void setBits (char *c)
 Sets the bitstring of this chromosome, from begin to end.
virtual std::list< char
> const 
getInterpretedBitstring ()
 Returns the actual interpretation of a bit string.
virtual T const getValue ()
 Returns the represented value of this Chromosome.
virtual std::string const getValueText ()
 Returns the represented value of this Chromosome as a string.
virtual std::string const getBitstringText ()
 Returns a string representation of the raw bitstring.
virtual std::string const getInterpretedBitstringText ()
 Returns a string representation of the interpreted bitstring.
virtual void mutate (double prob)
 Perform mutation, i.e.
virtual void crossover (int pos, Chromosome< T > *g)
 Perform crossover with another Chromosome, i.e.
virtual void crossover (Chromosome< T > *g)
 Perform crossover with an other Chromosome at a random position.

Protected Attributes

std::list< char > _bits
 The bitstring as a list of chars.

Detailed Description

template<class T>
class gal::Chromosome< T >

Represents a chromosome that models a value of any type T.

Examples of type T are: int for one variable, vector<double> for a point in n-dimensional space.

One always needs to use a subclass of this class, where all virtual functions are defined.

See also:
IntChromosome


Constructor & Destructor Documentation

template<class T>
gal::Chromosome< T >::Chromosome  )  [inline]
 

Constructs an empty Chromosome.

template<class T>
gal::Chromosome< T >::Chromosome int  length  )  [inline]
 

Constructs a Chromosome, initialised with a random bitstring.

Parameters:
length The number of bits in this Chromosome.


Member Function Documentation

template<class T>
virtual void gal::Chromosome< T >::crossover Chromosome< T > *  g  )  [inline, virtual]
 

Perform crossover with an other Chromosome at a random position.

See also:
Chromosome<T>::crossover(int pos, Chromosome<T>* g)

template<class T>
virtual void gal::Chromosome< T >::crossover int  pos,
Chromosome< T > *  g
[inline, virtual]
 

Perform crossover with another Chromosome, i.e.

split both this and the other chromosome at the same position in their bitstring, and exchange one of their halves.

  chromosome 1: AAAABBB  --> AAAADDD
  chromosome 2: CCCCDDD  --> CCCCBBB
                    ^pos = 4 (i.e. start at 0)
 
Parameters:
pos bit position where crossover takes place.
g The other 'parent' in this crossover.

template<class T>
virtual std::string const gal::Chromosome< T >::getBitstringText  )  [inline, virtual]
 

Returns a string representation of the raw bitstring.

template<class T>
virtual std::list<char> const gal::Chromosome< T >::getInterpretedBitstring  )  [inline, virtual]
 

Returns the actual interpretation of a bit string.

By default, this is just the same bit string, but an alternative would be the Gray-decoded value of the raw bit string.

See also:
GrayCodeChromosome

Reimplemented in gal::GrayCodeChromosome< T >, and gal::GrayCodeChromosome< int >.

template<class T>
virtual std::string const gal::Chromosome< T >::getInterpretedBitstringText  )  [inline, virtual]
 

Returns a string representation of the interpreted bitstring.

See also:
getInterpretedBitstring()

template<class T>
virtual T const gal::Chromosome< T >::getValue  )  [inline, virtual]
 

Returns the represented value of this Chromosome.

This method should always be defined in a derived class.

Reimplemented in gal::IntChromosome, and gal::IntGCChromosome.

template<class T>
virtual std::string const gal::Chromosome< T >::getValueText  )  [inline, virtual]
 

Returns the represented value of this Chromosome as a string.

This method should always be defined in a derived class.

Reimplemented in gal::IntChromosome, and gal::IntGCChromosome.

template<class T>
bool gal::Chromosome< T >::isElite  )  [inline]
 

Returns whether this Chromosome has the elite-status, which is needed in the Population evolution.

template<class T>
int gal::Chromosome< T >::length  )  [inline]
 

Returns the length of the bitstring.

template<class T>
virtual void gal::Chromosome< T >::mutate double  prob  )  [inline, virtual]
 

Perform mutation, i.e.

flip each bit with specified probability.

Parameters:
prob Probability of a single bitflip.

template<class T>
virtual void gal::Chromosome< T >::setBits char *  c  )  [inline, virtual]
 

Sets the bitstring of this chromosome, from begin to end.

Parameters:
c Array of bits (generally 0 and 1's).

template<class T>
void gal::Chromosome< T >::setElite bool  isElite = true  )  [inline]
 

Sets the elite status of this chromosome.

Parameters:
isElite When no value is specified, the status defaults to true.

template<class T>
void gal::Chromosome< T >::setLength int  length  )  [inline]
 

Sets the number of bits in this Chromosome's bitstring.


The documentation for this class was generated from the following file:
Generated on Tue Oct 20 12:59:24 2009 for LabSci GALib optimisation by genetic algorithms, student version by  doxygen 1.3.9.1