genetiK::ga::Individual Class Reference
[Genetic Algorithm framework]

Individual: GA-specific Individual. More...

#include <Individual.h>

Inheritance diagram for genetiK::ga::Individual:

Inheritance graph
[legend]
Collaboration diagram for genetiK::ga::Individual:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Individual (unsigned int length)
 creates an Individual by allocating length bits and filling them with random data. It should be called by subclasses' unsigned int constructors.
 Individual (const Individual &individual)
 Copy constructor.
virtual ~Individual (void)
 destructor
virtual double fitness ()=0
 abstract fitness function
virtual genetiK::Individualcopy () const =0
 abstract copy function
virtual int mutate (const double mutationProbability)
 standard one-point mutation
virtual int crossOver (genetiK::Individual *i, genetiK::Individual **child1, genetiK::Individual **child2)
 standard one-point crossover
unsigned int getLength ()
 Returns Individual's length.
bool operator[] (unsigned int index) const
 [] operator
virtual std::string toString () const
 outputs the individual as a sequence of 0s and 1s.

Protected Attributes

unsigned int length
unsigned int * bitArray
unsigned char blockNum

Detailed Description

Individual: GA-specific Individual.

This class extends the generic genetiK::Individual. It represents an individual as a string of bits.


Constructor & Destructor Documentation

genetiK::ga::Individual::Individual unsigned int  length  ) 
 

creates an Individual by allocating length bits and filling them with random data. It should be called by subclasses' unsigned int constructors.

Todo:
add a constructor that allocates memory but does not initialize with random data
Parameters:
length specifies the length of the individual to be created
See also:
Individual(const Individual& individual)

genetiK::ga::Individual::Individual const Individual individual  ) 
 

Copy constructor.

Creates this individual by copying individual. It should be called by subclasses' copy constructors.

Parameters:
individual the individual to be copied
See also:
copy and Individual(unsigned int length)

genetiK::ga::Individual::~Individual void   )  [virtual]
 

destructor

Destroys this instance, freeing the allocated bits

See also:
Individual(unsigned int length) and Individual(const Individual& individual)

Reimplemented from genetiK::Individual.


Member Function Documentation

virtual genetiK::Individual* genetiK::ga::Individual::copy  )  const [pure virtual]
 

abstract copy function

This function must be extended by sublcasses to perform copy.

Returns:
a copy of the individual
See also:
Individual(const Individual& individual)

Implements genetiK::Individual.

int genetiK::ga::Individual::crossOver genetiK::Individual i,
genetiK::Individual **  child1,
genetiK::Individual **  child2
[virtual]
 

standard one-point crossover

Performs one-point crossover between this and individual i, saving the resulting children in child1 and child2.

Parameters:
i the partner to use to perform crossover.
child1 first child.
child2 second child.
Returns:
0 if the operation was successful
See also:
mutate(double mutationProbabilty)

Implements genetiK::Individual.

virtual double genetiK::ga::Individual::fitness  )  [pure virtual]
 

abstract fitness function

This function must be extended by sublcasses to calculate the fitness of the individual.

Returns:
the fitness of the current individual

Implements genetiK::Individual.

unsigned int genetiK::ga::Individual::getLength  )  [inline]
 

Returns Individual's length.

Returns:
this.length

int genetiK::ga::Individual::mutate const double  mutationProbability  )  [virtual]
 

standard one-point mutation

Performs one-point mutation: flips a each bit of the individual with mutationProbability probability.

Parameters:
mutationProbability the probability to mutate a single bit of the Individual
Returns:
0 if the operation was successful
See also:
crossOver

Implements genetiK::Individual.

bool genetiK::ga::Individual::operator[] unsigned int  index  )  const
 

[] operator

Accesses a single bit of the individual bit string.

Parameters:
index 0-based index of the bit to retrieve
Returns:
true if this[index] is 1, false otherwise

string genetiK::ga::Individual::toString  )  const [virtual]
 

outputs the individual as a sequence of 0s and 1s.

Returns:
a sequence of 0s and 1s, representing the bits of the current individual.

Reimplemented from genetiK::Individual.


Member Data Documentation

unsigned int* genetiK::ga::Individual::bitArray [protected]
 

array of the actual bits associated with the Individual (as array of int)

unsigned char genetiK::ga::Individual::blockNum [protected]
 

number of int blocks allocated to store the Individual bits

unsigned int genetiK::ga::Individual::length [protected]
 

Invididual length (number of bits)


The documentation for this class was generated from the following files:
Generated on Thu Feb 23 12:22:18 2006 for GenetiK by  doxygen 1.4.6