bodhidharma.classifiers.genetic_algorithms
Class Chromosome

java.lang.Object
  extended by bodhidharma.classifiers.genetic_algorithms.Chromosome

public class Chromosome
extends java.lang.Object

Objects of this class represent the individuals that are evolved in a genetic algorithm. The genetic material of each chromosome is represented as an array of shorts, which are set to either 1 or 0.

Objects of this class store their fitness, as calculated by an Evaluator object that they are passed when they are instantiated. Evolution of Chromosome objects is controlled by Breeder objects. Chromosome objects have no understanding of the meaning of these bit strings.

Objects of this class can be instantiated so that their array is randomly set, or they can be instantiated so that the array is composed of two given components. Objects of this class contain methods to return the entire array or sub-arrays split at a given point of division.

The getDNA method of this class can be called to get the DNA of a Chromosome.

The getLeftDNA method of this class can be called to get the first part of the DNA of a Chromosome.

The getRightDNA method of this class can be called to get the second part of the DNA of a Chromosome.

The getFitness method of this class can be called to get the stored fitness of a Chromosome.

The mutate method of this class can be called to cause the Chromosome to undergo mutation.

See Also:
Evaluator, Breeder

Constructor Summary
Chromosome(int size, Evaluator eval)
          Randomly fill the genetic material of a Chromosome with 0's and 1's.
Chromosome(short[] left_DNA, short[] right_DNA, Evaluator eval)
          Generates a Chromosome with genetic material composed of the combination of the two given parent pieces of genetic material.
 
Method Summary
 short[] getDNA()
          Returns the entire genetic material of the Chromosome.
 double getFitness()
          Returns the stored fitness of the Chromosome.
 short[] getLeftDNA(int split_point)
          Returns the genetic material of the Chromosome up to and including the given split point (starting at 1, not 0).
 short[] getRightDNA(int split_point)
          Returns the genetic material of the Chromosome after but not including the given split point (starting at 1, not 0).
 void mutate(double probability)
          Flips bits in bit string with a probability per bit given by the probability parameter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Chromosome

public Chromosome(int size,
                  Evaluator eval)
           throws java.lang.Exception
Randomly fill the genetic material of a Chromosome with 0's and 1's.

An exception is thrown if there is a problem evaluating the fitness of the DNA.

Parameters:
size - The number of bits in the Chromosome's DNA.
eval - The Evaluator object that calculatues the fitness of each Chromosome.
Throws:
java.lang.Exception

Chromosome

public Chromosome(short[] left_DNA,
                  short[] right_DNA,
                  Evaluator eval)
           throws java.lang.Exception
Generates a Chromosome with genetic material composed of the combination of the two given parent pieces of genetic material.

An exception is thrown if there is a problem evaluating the fitness of the DNA.

Parameters:
left_DNA - The first part of the Chromosome's DNA.
right_DNA - The second part of the Chromosome's DNA.
eval - The Evaluator object that calculatues the fitness of each Chromosome.
Throws:
java.lang.Exception
Method Detail

getDNA

public short[] getDNA()
Returns the entire genetic material of the Chromosome.


getLeftDNA

public short[] getLeftDNA(int split_point)
Returns the genetic material of the Chromosome up to and including the given split point (starting at 1, not 0). null is returned if the given split_point is 0


getRightDNA

public short[] getRightDNA(int split_point)
Returns the genetic material of the Chromosome after but not including the given split point (starting at 1, not 0). null is returned if a split_point greater than or equal to the size of bit_string is specified.


getFitness

public double getFitness()
Returns the stored fitness of the Chromosome.


mutate

public void mutate(double probability)
Flips bits in bit string with a probability per bit given by the probability parameter. This probablity must be between 0 and 1. This method is used to implement mutation.