org.jgap
Class Configuration

java.lang.Object
  extended byorg.jgap.Configuration
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
DefaultConfiguration, DummyConfiguration, NeatConfiguration

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, genetic operators, 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 addMutationOperator(MutationOperator a_operatorToAdd)
          Add a mutation operator for use in this algorithm.
 void addReproductionOperator(ReproductionOperator a_operatorToAdd)
          Add a reproduction operator for use in this algorithm.
 BulkFitnessFunction getBulkFitnessFunction()
          Retrieves the bulk fitness function previously setup in this Configuration object.
 EventManager getEventManager()
          Retrieves the EventManager associated with this configuration.
 FitnessFunction getFitnessFunction()
          Retrieves the fitness function previously setup in this Configuration object.
 IdFactory getIdFactory()
           
 java.util.List getMutationOperators()
          Retrieve the mutation operators added for this genetic algorithm.
 NaturalSelector getNaturalSelector()
           
 int getPopulationSize()
          Retrieves the population size setup in this Configuration instance.
 java.util.Random getRandomGenerator()
          Retrieves the random generator setup in this Configuration instance.
 java.util.List getReproductionOperators()
          Retrieve the reproduction operators added for this genetic algorithm.
 ChromosomeMaterial getSampleChromosomeMaterial()
          Retrieves sample ChromosomeMaterial that contains the desired Gene setup for each respective gene position (locus).
 SpeciationParms getSpeciationParms()
           
 boolean isLocked()
          Retrieves the lock status of this object.
 void lockSettings()
          Locks all of the settings in this configuration object.
 java.lang.Long nextChromosomeId()
           
 java.lang.Long nextInnovationId()
           
 void setBulkFitnessFunction(BulkFitnessFunction a_functionToSet)
          Sets the bulk fitness function to be used for this genetic algorithm.
 void setEventManager(EventManager a_eventManagerToSet)
          Sets the EventManager that is to be associated with this configuration.
 void setFitnessFunction(FitnessFunction a_functionToSet)
          Sets the fitness function to be used for this genetic algorithm.
 void setIdFactory(IdFactory factory)
           
 void setNaturalSelector(NaturalSelector selector)
          set selector
 void setPopulationSize(int a_sizeOfPopulation)
          Sets the population size to be used for this genetic algorithm.
 void setRandomGenerator(java.util.Random a_generatorToSet)
          Sets the random generator to be used for this genetic algorithm.
 void setSampleChromosomeMaterial(ChromosomeMaterial a_sampleChromosomeMaterial)
          Sets sample ChromosomeMaterial that is to be used as a guide for the construction of other Chromosomes.
protected  void verifyChangesAllowed()
          Makes sure that this Configuration object isn't locked.
 void verifyStateIsValid()
          Tests the state of this Configuration 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

nextChromosomeId

public java.lang.Long nextChromosomeId()
Returns:
next unique chromosome ID

nextInnovationId

public java.lang.Long nextInnovationId()
Returns:
next unique innovation ID

setNaturalSelector

public void setNaturalSelector(NaturalSelector selector)
                        throws InvalidConfigurationException
set selector

Parameters:
selector -
Throws:
InvalidConfigurationException

getNaturalSelector

public NaturalSelector getNaturalSelector()
Returns:
selector

addReproductionOperator

public void addReproductionOperator(ReproductionOperator a_operatorToAdd)
                             throws InvalidConfigurationException
Add a reproduction operator for use in this algorithm. At least one reproduction operator must be provided.

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

getReproductionOperators

public java.util.List getReproductionOperators()
Retrieve the reproduction operators added for this genetic algorithm.

Returns:
The list of reproduction operators added to this Configuration

addMutationOperator

public void addMutationOperator(MutationOperator a_operatorToAdd)
                         throws InvalidConfigurationException
Add a mutation operator for use in this algorithm.

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

getMutationOperators

public java.util.List getMutationOperators()
Retrieve the mutation operators added for this genetic algorithm.

Returns:
The list of mutation operators added to this Configuration

setFitnessFunction

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

Note that it is illegal to set both this fitness function and a bulk fitness function. Although one or the other must be set, the two are mutually exclusive.

Parameters:
a_functionToSet - The fitness function to be used.
Throws:
InvalidConfigurationException - if the fitness function is null, a bulk fitness function has already been set, or if this Configuration object is locked.

getFitnessFunction

public FitnessFunction getFitnessFunction()
Retrieves the fitness function previously setup in this Configuration object.

Returns:
The fitness function.

setBulkFitnessFunction

public void setBulkFitnessFunction(BulkFitnessFunction a_functionToSet)
                            throws InvalidConfigurationException
Sets the bulk fitness function to be used for this genetic algorithm. The bulk fitness function may be used to evaluate and assign fitness values to the entire group of candidate Chromosomes in a single batch. This can be useful in cases where it's difficult to assign fitness values to a Chromosome in isolation from the other candidate Chromosomes.

Note that it is illegal to set both a bulk fitness function and a normal fitness function. Although one or the other is required, the two are mutually exclusive.

Parameters:
a_functionToSet - The bulk fitness function to be used.
Throws:
InvalidConfigurationException - if the bulk fitness function is null, the normal fitness function has already been set, or if this Configuration object is locked.

getBulkFitnessFunction

public BulkFitnessFunction getBulkFitnessFunction()
Retrieves the bulk fitness function previously setup in this Configuration object.

Returns:
The bulk fitness function.

setSampleChromosomeMaterial

public void setSampleChromosomeMaterial(ChromosomeMaterial a_sampleChromosomeMaterial)
                                 throws InvalidConfigurationException
Sets sample ChromosomeMaterial that is to be used as a guide for the construction of other Chromosomes. ChromosomeMaterial should be setup with each gene represented by the desired concrete Gene implementation for that gene position (locus). Anytime a new Chromosome is created, it will be constructed with the same Gene setup as that provided in this sample ChromosomeMaterial.

Parameters:
a_sampleChromosomeMaterial - ChromosomeMaterial to be used as the sample.
Throws:
InvalidConfigurationException - if the given Chromosome is null or this Configuration object is locked.

getSampleChromosomeMaterial

public ChromosomeMaterial getSampleChromosomeMaterial()
Retrieves sample ChromosomeMaterial that contains the desired Gene setup for each respective gene position (locus).

Returns:
the sample Chromosome instance.

setRandomGenerator

public void setRandomGenerator(java.util.Random a_generatorToSet)
                        throws InvalidConfigurationException
Sets 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 null or this object is locked.

getRandomGenerator

public java.util.Random getRandomGenerator()
Retrieves the random generator setup in this Configuration instance.

Returns:
The random generator.

setPopulationSize

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

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

getPopulationSize

public int getPopulationSize()
Retrieves the population size setup in this Configuration instance.

Returns:
The population size.

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 event manager is null or this Configuration 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.

lockSettings

public void lockSettings()
                  throws InvalidConfigurationException
Locks 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 that case, this method does nothing and simply returns.

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

isLocked

public boolean isLocked()
Retrieves 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
Tests the state of this Configuration 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 Configuration 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 Configuration object is locked.

getIdFactory

public IdFactory getIdFactory()
Returns:
factory for generating unique IDs

setIdFactory

public void setIdFactory(IdFactory factory)
Parameters:
factory - factory for generating unique IDs

getSpeciationParms

public SpeciationParms getSpeciationParms()
Returns:
Returns the m_speciationParms.