org.jgap
Class Genotype

java.lang.Object
  extended byorg.jgap.Genotype
All Implemented Interfaces:
java.io.Serializable

public class Genotype
extends java.lang.Object
implements java.io.Serializable

Genotypes are fixed-length populations of chromosomes. As an instance of a Genotype is evolved, all of its Chromosome objects are also evolved. A Genotype may be constructed normally, whereby an array of Chromosome objects must be provided, or the static randomInitialGenotype() method can be used to generate a Genotype with a randomized Chromosome population. Changes made by Tucker and James for ANJI :

See Also:
Serialized Form

Field Summary
protected  Configuration m_activeConfiguration
          The current active Configuration instance.
protected  java.util.List m_chromosomes
          Chromosomes that makeup thie Genotype's population.
protected  java.util.List m_species
          Species that makeup this Genotype's population.
 
Constructor Summary
Genotype(Configuration a_activeConfiguration, java.util.List a_initialChromosomes)
          This constructor is used for random initial Genotypes.
 
Method Summary
protected  void addChromosome(Chromosome chrom)
          add chromosome to population and to appropriate specie
protected  void addChromosomeFromMaterial(ChromosomeMaterial cMat)
           
protected  void addChromosomes(java.util.Collection chromosomes)
           
protected  void addChromosomesFromMaterial(java.util.Collection chromosomeMaterial)
           
 boolean equals(java.lang.Object other)
          Compares this Genotype against the specified object.
 void evolve()
          Performs one generation cycle, evaluating fitness, selecting survivors, repopulting with offspring, and mutating new population.
 java.util.List getChromosomes()
           
 Chromosome getFittestChromosome()
          Retrieves the Chromosome in the population with the highest fitness value.
 java.util.List getSpecies()
           
static Genotype randomInitialGenotype(Configuration a_activeConfiguration)
          Convenience method that returns a newly constructed Genotype instance configured according to the given Configuration instance.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_activeConfiguration

protected Configuration m_activeConfiguration
The current active Configuration instance.


m_species

protected java.util.List m_species
Species that makeup this Genotype's population.


m_chromosomes

protected java.util.List m_chromosomes
Chromosomes that makeup thie Genotype's population.

Constructor Detail

Genotype

public Genotype(Configuration a_activeConfiguration,
                java.util.List a_initialChromosomes)
         throws InvalidConfigurationException
This constructor is used for random initial Genotypes. Note that the Configuration object must be in a valid state when this method is invoked, or a InvalidconfigurationException will be thrown.

Parameters:
a_activeConfiguration - The current active Configuration object.
a_initialChromosomes - List contains Chromosome objects: The Chromosome population to be managed by this Genotype instance.
Throws:
java.lang.IllegalArgumentException - if either the given Configuration object or the array of Chromosomes is null, or if any of the Genes in the array of Chromosomes is null.
InvalidConfigurationException - if the given Configuration object is in an invalid state.
Method Detail

addChromosomes

protected void addChromosomes(java.util.Collection chromosomes)
Parameters:
chromosomes - Collection contains Chromosome objects
See Also:
addChromosome(Chromosome)

addChromosomesFromMaterial

protected void addChromosomesFromMaterial(java.util.Collection chromosomeMaterial)
Parameters:
chromosomeMaterial - Collection contains ChromosomeMaterial objects
See Also:
addChromosomeFromMaterial(ChromosomeMaterial)

addChromosomeFromMaterial

protected void addChromosomeFromMaterial(ChromosomeMaterial cMat)
Parameters:
cMat - chromosome material from which to construct new chromosome object
See Also:
addChromosome(Chromosome)

addChromosome

protected void addChromosome(Chromosome chrom)
add chromosome to population and to appropriate specie

Parameters:
chrom -

getChromosomes

public java.util.List getChromosomes()
Returns:
List contains Chromosome objects, the population of Chromosomes.

getSpecies

public java.util.List getSpecies()
Returns:
List contains Specie objects

getFittestChromosome

public Chromosome getFittestChromosome()
Retrieves the Chromosome in the population with the highest fitness value.

Returns:
The Chromosome with the highest fitness value, or null if there are no chromosomes in this Genotype.

evolve

public void evolve()
Performs one generation cycle, evaluating fitness, selecting survivors, repopulting with offspring, and mutating new population. This is a modified version of original JGAP method which changes order of operations and splits GeneticOperator into ReproductionOperator and MutationOperator. New order of operations:
  1. assign fitness to all members of population with BulkFitnessFunction or FitnessFunction
  2. select survivors and remove casualties from population
  3. re-fill population with offspring via reproduction operators
  4. mutate offspring (note, survivors are passed on un-mutated)
Genetic event GeneticEvent.GENOTYPE_EVALUATED_EVENT is fired between steps 2 and 3. Genetic event GeneticEvent.GENOTYPE_EVOLVED_EVENT is fired after step 4.


toString

public java.lang.String toString()
Returns:
String representation of this Genotype instance.

randomInitialGenotype

public static Genotype randomInitialGenotype(Configuration a_activeConfiguration)
                                      throws InvalidConfigurationException
Convenience method that returns a newly constructed Genotype instance configured according to the given Configuration instance. The population of Chromosomes will created according to the setup of the sample Chromosome in the Configuration object, but the gene values (alleles) will be set to random legal values.

Note that the given Configuration instance must be in a valid state at the time this method is invoked, or an InvalidConfigurationException will be thrown.

Parameters:
a_activeConfiguration -
Returns:
A newly constructed Genotype instance.
Throws:
InvalidConfigurationException - if the given Configuration instance not in a valid state.

equals

public boolean equals(java.lang.Object other)
Compares this Genotype against the specified object. The result is true if the argument is an instance of the Genotype class, has exactly the same number of chromosomes as the given Genotype, and, for each Chromosome in this Genotype, there is an equal chromosome in the given Genotype. The chromosomes do not need to appear in the same order within the populations.

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