org.jgap
Class ChromosomeMaterial

java.lang.Object
  extended byorg.jgap.ChromosomeMaterial
All Implemented Interfaces:
java.lang.Comparable, java.io.Serializable

public class ChromosomeMaterial
extends java.lang.Object
implements java.lang.Comparable, java.io.Serializable

This is the guts of the original Chromosome object, pulled out so the genes can be modified by genetic operators before creating the Chromosome object. Also enables us to handle special cases, like sample chromosome, where you don't need a Configuration or fitness value. Also, made methods not synchronized, since only Genotype.evolve() should be modifying this object.

See Also:
Serialized Form

Constructor Summary
ChromosomeMaterial(java.util.Collection a_initialAlleles)
          Create chromosome with no parents.
ChromosomeMaterial(java.util.Collection a_initialGenes, java.lang.Long aPrimaryParentId)
          Create chromosome with one parents.
ChromosomeMaterial(java.util.Collection a_initialAlleles, java.lang.Long aPrimaryParentId, java.lang.Long aSecondaryParentId)
          Create chromosome with two parents.
 
Method Summary
 ChromosomeMaterial clone(java.lang.Long parentId)
          Returns a copy of this ChromosomeMaterial.
 int compareTo(java.lang.Object other)
          Compares the given Chromosome to this Chromosome.
 double distance(ChromosomeMaterial target, SpeciationParms speciationParms)
          Calculates compatibility distance between this and target according to NEAT speciation methodology.
 boolean equals(java.lang.Object other)
          Compares this Chromosome against the specified object.
 java.util.SortedSet getAlleles()
          Retrieves the set of genes.
 java.lang.Long getPrimaryParentId()
           
 java.lang.Long getSecondaryParentId()
           
static ChromosomeMaterial randomInitialChromosomeMaterial(Configuration a_activeConfiguration)
          Convenience method that returns a new Chromosome instance with its genes values (alleles) randomized.
 void setSecondaryParentId(java.lang.Long id)
           
 java.lang.String toString()
          Returns a string representation of this Chromosome, useful for some display purposes.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ChromosomeMaterial

public ChromosomeMaterial(java.util.Collection a_initialAlleles,
                          java.lang.Long aPrimaryParentId,
                          java.lang.Long aSecondaryParentId)
Create chromosome with two parents. Used for crossover.

Parameters:
a_initialAlleles -
aPrimaryParentId -
aSecondaryParentId -

ChromosomeMaterial

public ChromosomeMaterial(java.util.Collection a_initialGenes,
                          java.lang.Long aPrimaryParentId)
Create chromosome with one parents. Used for cloning.

Parameters:
a_initialGenes -
aPrimaryParentId -
See Also:
ChromosomeMaterial(Collection, Long, Long)

ChromosomeMaterial

public ChromosomeMaterial(java.util.Collection a_initialAlleles)
Create chromosome with no parents. Used for startup sample chromosome material.

Parameters:
a_initialAlleles -
See Also:
ChromosomeMaterial(Collection, Long, Long)
Method Detail

clone

public ChromosomeMaterial clone(java.lang.Long parentId)
Returns a copy of this ChromosomeMaterial. The returned instance can evolve independently of this instance.

Parameters:
parentId - represents ID of chromosome that was cloned. If this is initial chromosome material without a parent, or is the clone of material only (e.g., before the it has become a Chromosome), parentId == null.
Returns:
copy of this object

getAlleles

public java.util.SortedSet getAlleles()
Retrieves the set of genes. This method exists primarily for the benefit of GeneticOperators that require the ability to manipulate Chromosomes at a low level.

Returns:
an array of the Genes contained within this Chromosome.

toString

public java.lang.String toString()
Returns a string representation of this Chromosome, useful for some display purposes.

Returns:
A string representation of this Chromosome.

randomInitialChromosomeMaterial

public static ChromosomeMaterial randomInitialChromosomeMaterial(Configuration a_activeConfiguration)
                                                          throws InvalidConfigurationException
Convenience method that returns a new Chromosome instance with its genes values (alleles) randomized. Note that, if possible, this method will acquire a Chromosome instance from the active ChromosomePool (if any) and then randomize its gene values before returning it. If a Chromosome cannot be acquired from the pool, then a new instance will be constructed and its gene values randomized before returning it.

Parameters:
a_activeConfiguration - The current active configuration.
Returns:
new ChromosomeMaterial
Throws:
InvalidConfigurationException - if the given Configuration instance is invalid.
java.lang.IllegalArgumentException - if the given Configuration instance is null.

equals

public boolean equals(java.lang.Object other)
Compares this Chromosome against the specified object. The result is true if and the argument is an instance of the Chromosome class and has a set of genes equal to this one.

Parameters:
other - The object to compare against.
Returns:
true if the objects are the same, false otherwise.

compareTo

public int compareTo(java.lang.Object other)
Compares the given Chromosome to this Chromosome. This chromosome is considered to be "less than" the given chromosome if it has a fewer number of genes or if any of its gene values (alleles) are less than their corresponding gene values in the other chromosome.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
other - The Chromosome against which to compare this chromosome.
Returns:
a negative number if this chromosome is "less than" the given chromosome, zero if they are equal to each other, and a positive number if this chromosome is "greater than" the given chromosome.
See Also:
Comparable.compareTo(java.lang.Object)

getPrimaryParentId

public java.lang.Long getPrimaryParentId()
Returns:
primary parent ID; dominant parent if chromosome spawned by crossover

getSecondaryParentId

public java.lang.Long getSecondaryParentId()
Returns:
primary parent ID; recessive parent if chromosome spawned by crossover

setSecondaryParentId

public void setSecondaryParentId(java.lang.Long id)
Parameters:
id - ID of recessive parent

distance

public double distance(ChromosomeMaterial target,
                       SpeciationParms speciationParms)
Calculates compatibility distance between this and target according to NEAT speciation methodology. Made it generic enough that the genes do not have to be nodes and connections.

Parameters:
target -
speciationParms -
Returns:
distance between this object and target
See Also:
Allele.distance(Allele)