org.jgap
Class Genotype

java.lang.Object
  extended byorg.jgap.Genotype
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
DistributedGenotype

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 Chromosomes are also evolved. A Genotype may be constructed normally, whereby an array of Chromosomes must be provided, or the static randomInitialGenotype() method can be used to generate a Genotype with a randomized Chromosome population.

Since:
1.0
Author:
Neil Rotstan, Klaus Meffert
See Also:
Serialized Form

Constructor Summary
Genotype(Configuration a_activeConfiguration, Chromosome[] a_initialChromosomes)
          Deprecated. use Genotype(Configuration, Population) instead
Genotype(Configuration a_activeConfiguration, Population a_population)
          Constructs a new Genotype instance with the given array of Chromosomes and the given active Configuration instance.
 
Method Summary
 boolean equals(java.lang.Object other)
          Compares this Genotype against the specified object.
 void evolve()
          Evolve the population of Chromosomes within this Genotype.
 void evolve(int a_numberOfEvolutions)
          Evolves this Genotype the specified number of times.
 Chromosome[] getChromosomes()
          Deprecated. uses getPopulation() instead
static Configuration getConfiguration()
           
 Chromosome getFittestChromosome()
          Retrieves the Chromosome in the population with the highest fitness value.
 Population getPopulation()
           
static Genotype randomInitialGenotype(Configuration a_activeConfiguration)
          Convenience method that returns a newly constructed Genotype instance configured according to the given Configuration instance.
 void setActiveConfiguration(Configuration a_activeConfiguration)
          Sets the active Configuration object on this Genotype and its member Chromosomes.
static void setConfiguration(Configuration a_configuration)
           
 java.lang.String toString()
          Return a string representation of this Genotype instance, useful for display purposes.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Genotype

public Genotype(Configuration a_activeConfiguration,
                Chromosome[] a_initialChromosomes)
         throws InvalidConfigurationException
Deprecated. use Genotype(Configuration, Population) instead

Constructs a new Genotype instance with the given array of Chromosomes and the given active Configuration instance. 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 - 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.
Since:
1.0

Genotype

public Genotype(Configuration a_activeConfiguration,
                Population a_population)
         throws InvalidConfigurationException
Constructs a new Genotype instance with the given array of Chromosomes and the given active Configuration instance. 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_population - The Chromosome population to be managed by this Genotype instance.
Throws:
InvalidConfigurationException
Since:
2.0
Method Detail

setActiveConfiguration

public void setActiveConfiguration(Configuration a_activeConfiguration)
                            throws InvalidConfigurationException
Sets the active Configuration object on this Genotype and its member Chromosomes. This method should be invoked immediately following deserialization of this Genotype. If an active Configuration has already been set on this Genotype, then this method will do nothing.

Parameters:
a_activeConfiguration - The current active Configuration object that is to be referenced internally by this Genotype and its member Chromosome instances.
Throws:
InvalidConfigurationException - if the Configuration object is null or cannot be locked because it is in an invalid or incomplete state.
Since:
1.0

getChromosomes

public Chromosome[] getChromosomes()
Deprecated. uses getPopulation() instead

Retrieves the array of Chromosomes that make up the population of this Genotype instance.

Returns:
The population of Chromosomes.
Since:
1.0

getPopulation

public Population getPopulation()

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.
Since:
1.0

evolve

public void evolve()
Evolve the population of Chromosomes within this Genotype. This will execute all of the genetic operators added to the present active configuration and then invoke the natural selector to choose which chromosomes will be included in the next generation population. Note that the population size not always remains constant (dependent on the NaturalSelectors used!).

Since:
1.0

evolve

public void evolve(int a_numberOfEvolutions)
Evolves this Genotype the specified number of times. This is equivalent to invoking the standard evolve() method the given number of times in a row.

Parameters:
a_numberOfEvolutions - The number of times to evolve this Genotype before returning.
Since:
1.1

toString

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

Returns:
A string representation of this Genotype instance.
Since:
1.0

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 - The current active Configuration object.
Returns:
A newly constructed Genotype instance.
Throws:
java.lang.IllegalArgumentException - if the given Configuration object is null.
InvalidConfigurationException - if the given Configuration instance not in a valid state.
Since:
1.0

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.
Since:
1.0

getConfiguration

public static Configuration getConfiguration()

setConfiguration

public static void setConfiguration(Configuration a_configuration)