artoflife pre0.1.0-dev

org.artoflife.gp.genome
Class GpTreeChromosome

java.lang.Object
  |
  +--org.artoflife.gp.Chromosome
        |
        +--org.artoflife.gp.genome.GpTreeChromosome
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class GpTreeChromosome
extends Chromosome

A Chromosome that describes a procedure expressed as a tree of GpTreeNodes to return a value of a fixed type.

The root gene has a return type specific to this Chromosome which must not be allowed to vary. The Chromosome has an ID used to test compatibility with other Chromosomes.

Author:
Steve Meyfroidt
See Also:
Serialized Form

Field Summary
protected  RootGene rootGene
          Root of the tree of genes.
 
Constructor Summary
GpTreeChromosome(java.lang.String id, java.lang.Class type)
          Create with an identifying ID and set the root Gene to a random Gene of the correct type.
 
Method Summary
 java.lang.Object clone()
          Must be able to clone an Individual's genome during clone of an Individual.
 void crossover(Chromosome chromosome)
          Subclasses should ensure compatibility before doing the crossover, throwing an IncompatibleGenotypeException if not.
protected  java.util.SortedMap getCrossovers()
          Provides a SortedMap of GpCrossovers with their probabilities (Doubles between 0.0 and 1.0) so that #crossover(Chromosome, float) can choose one to do a crossover.
 GpTreeNode getRootGene()
           
 int getSize()
          Return number of genes.
 void mutate(float probability)
          Just ask the root Gene to mutate.
 java.lang.String toString()
           
 
Methods inherited from class org.artoflife.gp.Chromosome
compatibleWith, getId
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

rootGene

protected RootGene rootGene
Root of the tree of genes. Has an immutable type.

Constructor Detail

GpTreeChromosome

public GpTreeChromosome(java.lang.String id,
                        java.lang.Class type)
Create with an identifying ID and set the root Gene to a random Gene of the correct type.

Parameters:
id - the Chromosome's id, not null
type - Class that the root Gene returns on evaluation
Method Detail

getRootGene

public GpTreeNode getRootGene()

crossover

public void crossover(Chromosome chromosome)
               throws IncompatibleChromosomeException
Description copied from class: Chromosome
Subclasses should ensure compatibility before doing the crossover, throwing an IncompatibleGenotypeException if not.

Specified by:
crossover in class Chromosome
Parameters:
chromosome - the Chromosome to crossover this one with
IncompatibleChromosomeException

getCrossovers

protected java.util.SortedMap getCrossovers()
Provides a SortedMap of GpCrossovers with their probabilities (Doubles between 0.0 and 1.0) so that #crossover(Chromosome, float) can choose one to do a crossover. The map needs to look like:
0.1
a GpCrossover instance with 10% chance of being used
0.2
a different GpCrossover instance with 10% chance of being used
1.0
a GpCrossover instance with 80% chance of being used

Load from configuration properties. [getClass().getName()].crossover.class.0 and optionally [getClass().getName()].crossover.probability.0


mutate

public void mutate(float probability)
Just ask the root Gene to mutate.

Specified by:
mutate in class Chromosome
Parameters:
probability - that a Gene will mutate.

getSize

public int getSize()
Return number of genes. This implementation is expensive to call.

Specified by:
getSize in class Chromosome
Returns:
measure of size of this Chromosome

clone

public java.lang.Object clone()
Description copied from class: Chromosome
Must be able to clone an Individual's genome during clone of an Individual.

Overrides:
clone in class Chromosome

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

artoflife pre0.1.0-dev

Copyright © 2002 the Art Of Life team. All Rights Reserved.