org.jgap
Class Genotype

java.lang.Object
  |
  +--org.jgap.Genotype

public class Genotype
extends java.lang.Object

Genotypes represent fixed-length collections or "populations" of Chromosomes. As an instance of a genotype is evolved, all of its Chromosomes are also evolved.

Author:
Neil Rotstan (neil at bluesock.org)

Constructor Summary
Genotype(org.jgap.Chromosome[] initialChromosomes, org.jgap.FitnessFunction fitnessFunc, org.jgap.NaturalSelector selector)
          Constructs a new Genotype instance with the given array of Chromosomes and the given fitness function.
 
Method Summary
 void evolve()
          Evolve the collection of Chromosomes within this Genotype.
 org.jgap.Chromosome[] getChromosomes()
          Retrieve the array of Chromosomes that make up this Genotype instance.
 org.jgap.Chromosome getFittestChromosome()
          Retrieve the Chromosome in the population with the highest fitness value.
static org.jgap.Genotype randomInitialGenotype(int populationSize, int chromosomeSize, org.jgap.FitnessFunction fitnessFunc, org.jgap.NaturalSelector selector)
          Convenience method that returns a newly constructed Genotype instance consisting of the given number of Chromosomes of the given size and instantiated with the given fitness function.
static org.jgap.Genotype randomInitialGenotype(int populationSize, int chromosomeSize, int mutationRate, org.jgap.FitnessFunction fitnessFunc, org.jgap.NaturalSelector selector)
          Convenience method that returns a newly constructed Genotype with the given fitness function and consisting of the given number of Chromosomes instantiated with the given size and mutation rate.
 java.lang.String toString()
          Return a string representation of this Genotype instance, useful for debugging purposes.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Genotype

public Genotype(org.jgap.Chromosome[] initialChromosomes,
                org.jgap.FitnessFunction fitnessFunc,
                org.jgap.NaturalSelector selector)
Constructs a new Genotype instance with the given array of Chromosomes and the given fitness function. The fitness function will be used during evolution to implement natural selection.

Method Detail

getChromosomes

public org.jgap.Chromosome[] getChromosomes()
Retrieve the array of Chromosomes that make up this Genotype instance.

Returns:
The chromosomes that make up this Genotype.

getFittestChromosome

public org.jgap.Chromosome getFittestChromosome()
Retrieve the Chromosome in the population with the highest fitness value.

Returns:
The Chromosome with the highest fitness value.

evolve

public void evolve()
Evolve the collection of Chromosomes within this Genotype. This is implemented via the following steps: (1) Reproduce each Chromosome instance. (2) Randomly select two Chromosome instances and have them crossover. Repeat this step a number of times equal to the original number of Chromosomes managed by this Genotype instance. (3) Give each Chromosome instance an opportunity to mutate. (4) Evaluate the fitness of each Chromosome instance and hand the Chromosome and its fitness value to a natural selector. (5) Have the natural selector choose a number of Chromosome instances equal to the size of the original population managed by this Genotype. These instances become the new population managed by this Genotype instance.


toString

public java.lang.String toString()
Return a string representation of this Genotype instance, useful for debugging purposes.

Overrides:
toString in class java.lang.Object
Returns:
A string representation of this Genotype instance.

randomInitialGenotype

public static org.jgap.Genotype randomInitialGenotype(int populationSize,
                                                      int chromosomeSize,
                                                      org.jgap.FitnessFunction fitnessFunc,
                                                      org.jgap.NaturalSelector selector)
Convenience method that returns a newly constructed Genotype instance consisting of the given number of Chromosomes of the given size and instantiated with the given fitness function.

Returns:
A newly constructed Genotype instance.

randomInitialGenotype

public static org.jgap.Genotype randomInitialGenotype(int populationSize,
                                                      int chromosomeSize,
                                                      int mutationRate,
                                                      org.jgap.FitnessFunction fitnessFunc,
                                                      org.jgap.NaturalSelector selector)
Convenience method that returns a newly constructed Genotype with the given fitness function and consisting of the given number of Chromosomes instantiated with the given size and mutation rate.

Returns:
A newly constructed Genotype instance.