org.jgap
Class Configuration

java.lang.Object
  |
  +--org.jgap.Configuration
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
DefaultConfiguration

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

The Configuration class represents the current configuration of plugins and flags necessary to execute the genetic algorithm (such as fitness function, natural selector, mutation rate, and so on).

Note that, while during setup, the settings, flags, and other values may be set multiple times. But once the lockSettings() method is invoked, they cannot be changed. The default behavior of the Genotype constructor is to invoke this method, meaning that once a Configuration object is passed to a Genotype, it cannot be subsequently modified. There is no mechanism for unlocking the settings once they are locked.

Not all configuration options are required. See the documentation for each of the respective mutator methods to determine whether it is required to provide a value for that setting, and what the setting will default to if not.

See Also:
Serialized Form

Constructor Summary
Configuration()
           
 
Method Summary
 void addGeneticOperator(GeneticOperator a_operatorToAdd)
          Add a genetic operator for use in this algorithm.
 ChromosomePool getChromosomePool()
          Retrieves the ChromosomePool instance, if any, that is associated with this configuration.
 int getChromosomeSize()
          Retrieve the chromosome size being used by this genetic algorithm.
 EventManager getEventManager()
          Retrieves the EventManager associated with this configuration.
 FitnessFunction getFitnessFunction()
          Retrieve the fitness function being used by this genetic algorithm.
 java.util.List getGeneticOperators()
          Retrieve the genetic operators added for this genetic algorithm.
 NaturalSelector getNaturalSelector()
          Retrieve the natural selector being used by this genetic algorithm.
 int getPopulationSize()
          Retrieve the population size being used by this genetic algorithm.
 RandomGenerator getRandomGenerator()
          Retrieve the random generator being used by this genetic algorithm.
 Chromosome getSampleChromosome()
          Retrieves the sample Chromosome that contains the desired Allele types at each respective gene location (locus).
 boolean isLocked()
          Retrieve the lock status of this object.
 void lockSettings()
          Lock all of the settings in this configuration object.
 void setChromosomePool(ChromosomePool a_chromosomePoolToSet)
          Sets the ChromosomePool that is to be associated with this configuration.
 void setEventManager(EventManager a_eventManagerToSet)
          Sets the EventManager that is to be associated with this configuration.
 void setFitnessFunction(FitnessFunction a_functionToSet)
          Set the fitness function to be used for this genetic algorithm.
 void setNaturalSelector(NaturalSelector a_selectorToSet)
          Set the natural selector to be used for this genetic algorithm.
 void setPopulationSize(int a_sizeOfPopulation)
          Set the population size to be used for this genetic algorithm.
 void setRandomGenerator(RandomGenerator a_generatorToSet)
          Set the random generator to be used for this genetic algorithm.
 void setSampleChromosome(Chromosome a_sampleChromosomeToSet)
          Sets the sample Chromosome that is to be used as a guide for the construction of other Chromosomes.
protected  void verifyChangesAllowed()
          Makes sure that this object isn't locked.
 void verifyStateIsValid()
          Test the state of this object to make sure it's valid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Configuration

public Configuration()
Method Detail

setFitnessFunction

public void setFitnessFunction(FitnessFunction a_functionToSet)
                        throws InvalidConfigurationException
Set the fitness function to be used for this genetic algorithm. The fitness function is responsible for evaluating a given Chromosome and returning an integer that represents its worth as a candidate solution. These values are typically used by the natural selector to determine which Chromosome instances will be allowed to move on to the next round of evolution, and which will instead be eliminated. This setting is required.

Throws:
InvalidConfigurationException - if the fitness function is not satisfactory or if this object is locked.

getFitnessFunction

public FitnessFunction getFitnessFunction()
Retrieve the fitness function being used by this genetic algorithm.

Returns:
The fitness function used by this genetic algorithm.

setSampleChromosome

public void setSampleChromosome(Chromosome a_sampleChromosomeToSet)
                         throws InvalidConfigurationException
Sets the sample Chromosome that is to be used as a guide for the construction of other Chromosomes. The Chromosome should be constructed with each gene represented by the Allele desired Allele type for that locus. Those types will be maintained for genes at those respective locations in all Chromosomes generated with this Configuration.

Parameters:
a_sampleChromosomeToSet - The Chromosome to be used as the sample.
Throws:
InvalidConfigurationException - if the given Chromosome is not satisfactory, this Configuration is locked, or the sample Allele has already been set.

getSampleChromosome

public Chromosome getSampleChromosome()
Retrieves the sample Chromosome that contains the desired Allele types at each respective gene location (locus).

Returns:
the sample Chromosome instance.

setNaturalSelector

public void setNaturalSelector(NaturalSelector a_selectorToSet)
                        throws InvalidConfigurationException
Set the natural selector to be used for this genetic algorithm. The natural selector is responsible for actually selecting which Chromosome instances are allowed to move on to the next round of evolution (usually based on the fitness values provided by the fitness function). This setting is required.

Parameters:
a_selectorToSet - The natural selector to be used.
Throws:
InvalidConfigurationException - if the natural selector is not satisfactory or this object is locked.

getNaturalSelector

public NaturalSelector getNaturalSelector()
Retrieve the natural selector being used by this genetic algorithm.

Returns:
The natural selector used by this genetic algorithm.

setRandomGenerator

public void setRandomGenerator(RandomGenerator a_generatorToSet)
                        throws InvalidConfigurationException
Set the random generator to be used for this genetic algorithm. The random generator is responsible for generating random numbers, which are used throughout the process of genetic evolution and selection. This setting is required.

Parameters:
a_generatorToSet - The random generator to be used.
Throws:
InvalidConfigurationException - if the random generator is not satisfactory or this object is locked.

getRandomGenerator

public RandomGenerator getRandomGenerator()
Retrieve the random generator being used by this genetic algorithm.

Returns:
The random generator used by this genetic algorithm.

addGeneticOperator

public void addGeneticOperator(GeneticOperator a_operatorToAdd)
                        throws InvalidConfigurationException
Add a genetic operator for use in this algorithm. Genetic operators represent evolutionary steps that, when combined, make up the evolutionary process. Examples of genetic operators are reproduction, crossover, and mutation. During the evolution process, all of the genetic operators added via this method are invoked in the order they were added. At least one genetic operator must be provided.

Parameters:
a_operatorToAdd - The genetic operator to be added.
Throws:
InvalidConfigurationException - if the genetic operator is null a_operatorToAdd this robject is locked.

getGeneticOperators

public java.util.List getGeneticOperators()
Retrieve the genetic operators added for this genetic algorithm. Note that once this Configuration instance is locked, a new, immutable list of operators is used and any lists previously retrieved with this method will no longer reflect the actual list in use.

Returns:
The list of genetic operators added to this Configuration

getChromosomeSize

public int getChromosomeSize()
Retrieve the chromosome size being used by this genetic algorithm. This value is set automatically when the sample Chromosome is provided.

Returns:
The chromosome size used in this Configuration.

setPopulationSize

public void setPopulationSize(int a_sizeOfPopulation)
                       throws InvalidConfigurationException
Set the population size to be used for this genetic algorithm. The population size is a fixed value that represntes the number of Chromosomes represented in a Genotype. This setting is required.

Parameters:
a_sizeOfPopulation - The population size to be used.
Throws:
InvalidConfigurationException - if the population size is not satisfactory or this object is locked.

getPopulationSize

public int getPopulationSize()
Retrieve the population size being used by this genetic algorithm.

Returns:
The population size used by this genetic algorithm.

setEventManager

public void setEventManager(EventManager a_eventManagerToSet)
                     throws InvalidConfigurationException
Sets the EventManager that is to be associated with this configuration. The EventManager is responsible for the management of event subscribers and event notifications.

Parameters:
a_eventManagerToSet - the EventManager instance to use in this configuration.
Throws:
InvalidConfigurationException - if the population size is not satisfactory or this object is locked.

getEventManager

public EventManager getEventManager()
Retrieves the EventManager associated with this configuration. The EventManager is responsible for the management of event subscribers and event notifications.

Returns:
the actively configured EventManager instance.

setChromosomePool

public void setChromosomePool(ChromosomePool a_chromosomePoolToSet)
                       throws InvalidConfigurationException
Sets the ChromosomePool that is to be associated with this configuration. The ChromosomePool is used to pool unused Chromosome instances so that they may be recycled later, thereby saving time and memory. The presence of a ChromosomePool is optional. If none exists, then a new Chromosome will be constructed each time one is needed.

Parameters:
a_chromosomePoolToSet - The ChromosomePool instance to use.
Throws:
InvalidConfigurationException - if this object is locked.

getChromosomePool

public ChromosomePool getChromosomePool()
Retrieves the ChromosomePool instance, if any, that is associated with this configuration. The ChromosomePool is used to pool unused Chromosome instances so that they may be recycled later, thereby saving time and memory. The presence of a ChromosomePool instance is optional. If none exists, then new Chromosomes will be constructed each time one is needed.

Returns:
The ChromosomePool instance associated this configuration, or null if none has been set.

lockSettings

public void lockSettings()
                  throws InvalidConfigurationException
Lock all of the settings in this configuration object. Once this method is successfully invoked, none of the settings may be changed. There is no way to unlock this object once it is locked.

Prior to returning successfully, this method will first invoke the verifyStateIsValid() method to make sure that any required configuration options have been properly set. If it detects a problem, it will throw an InvalidConfigurationException and leave the object unlocked.

It's possible to test whether is object is locked through the isLocked() method.

It is ok to lock an object more than once. In this case, this method does nothing and simply returns.

Throws:
InvalidConfigurationException - if the object is in an invalid state at the time of invocation.

isLocked

public boolean isLocked()
Retrieve the lock status of this object.

Returns:
true if this object has been locked by a previous successful call to the lockSettings() method, false otherwise.

verifyStateIsValid

public void verifyStateIsValid()
                        throws InvalidConfigurationException
Test the state of this object to make sure it's valid. This generally consists of verifying that required settings have, in fact, been set. If this object is not in a valid state, then an exception will be thrown detailing the reason the state is not valid.

Throws:
InvalidConfigurationException - if the state of this Configuration is not valid. The error message in the exception will detail the reason for invalidity.

verifyChangesAllowed

protected void verifyChangesAllowed()
                             throws InvalidConfigurationException
Makes sure that this object isn't locked. If it is, then an exception is thrown with an appropriate message indicating that settings in this object may not be altered. This method should be invoked by any mutator method in this object prior to making any state alterations.

Throws:
InvalidConfigurationException - if this object is locked.

SourceForge.net Logo