JGAP

org.jgap
Class Configuration

java.lang.Object
  extended by org.jgap.Configuration
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable, Configurable, ICloneable
Direct Known Subclasses:
DefaultConfiguration, GAConfiguration, GPConfiguration, PermutingConfiguration

public class Configuration
extends java.lang.Object
implements Configurable, java.io.Serializable, ICloneable, java.lang.Comparable

The Configuration class represents the current configuration of plugins and parameters 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.

Since:
1.0
See Also:
Serialized Form

Nested Class Summary
 class Configuration.ConfigurationConfigurable
           
 
Field Summary
static java.lang.String PROPERTY_BFITFNC_INST
           
static java.lang.String PROPERTY_EVENT_MGR_INST
           
static java.lang.String PROPERTY_FITEVAL_INST
           
static java.lang.String PROPERTY_FITFUNC_INST
           
static java.lang.String PROPERTY_JGAPFACTORY_CLASS
          Constant for class name of JGAP Factory to use.
static java.lang.String PROPERTY_SAMPLE_CHROM_INST
           
static java.lang.String S_CHROMOSOME_SIZE
           
static java.lang.String S_CONFIGURATION
          Constants for toString()
static java.lang.String S_CONFIGURATION_HANDLER
           
static java.lang.String S_CONFIGURATION_NAME
           
static java.lang.String S_EVENT_MANAGER
           
static java.lang.String S_FITNESS_EVALUATOR
           
static java.lang.String S_FITNESS_FUNCTION
           
static java.lang.String S_GENETIC_OPERATORS
           
static java.lang.String S_MINPOPSIZE
           
static java.lang.String S_NATURAL_SELECTORS
           
static java.lang.String S_NONE
           
static java.lang.String S_POPULATION_SIZE
           
static java.lang.String S_POST
           
static java.lang.String S_PRE
           
static java.lang.String S_RANDOM_GENERATOR
           
static java.lang.String S_SAMPLE_CHROM
           
static java.lang.String S_SIZE
           
static java.lang.String S_TOSTRING
           
 
Constructor Summary
Configuration()
           
Configuration(java.lang.String a_name)
          Constructs a configuration with an informative name but without a unique ID.
Configuration(java.lang.String a_configFileName, boolean a_ignore)
          Reads in the configuration from the given file.
Configuration(java.lang.String a_id, java.lang.String a_name)
          Initialize with default values.
 
Method Summary
 void addGeneticOperator(GeneticOperator a_operatorToAdd)
          Adds a genetic operator for use in this algorithm.
 void addNaturalSelector(NaturalSelector a_selector, boolean a_processBeforeGeneticOperators)
          Adds a NaturalSelector to the ordered chain of registered NaturalSelector's.
protected  void checkProperty(java.lang.String a_propname, java.lang.Object a_obj, java.lang.Object a_oldObj, java.lang.String a_errmsg)
          Verifies that a property is not set.
 java.lang.Object clone()
           
 int compareTo(java.lang.Object a_other)
          The compareTo-method.
protected  java.lang.Object doClone(java.lang.Object a_objToClone)
          Helper called from clone.
 boolean equals(java.lang.Object a_other)
          The equals-method.
 IBreeder getBreeder()
           
 BulkFitnessFunction getBulkFitnessFunction()
          Retrieves the bulk fitness function previously setup in this Configuration object.
 IChromosomePool getChromosomePool()
          Retrieves the ChromosomePool instance, if any, that is associated with this configuration.
 int getChromosomeSize()
          Retrieves the chromosome size being used by this genetic algorithm.
 ConfigurationHandler getConfigurationHandler()
          Implementation of the Configurable interface.
 IEventManager getEventManager()
          Retrieves the event manager associated with this configuration.
 FitnessEvaluator getFitnessEvaluator()
           
 FitnessFunction getFitnessFunction()
          Retrieves the fitness function previously setup in this Configuration object.
 int getGenerationNr()
           
 java.util.List getGeneticOperators()
          Retrieves the genetic operators setup in this Configuration instance.
 java.lang.String getId()
           
 IJGAPFactory getJGAPFactory()
           
 int getMinimumPopSizePercent()
           
 IEvolutionMonitor getMonitor()
           
 java.lang.String getName()
           
 NaturalSelector getNaturalSelector()
          Deprecated. use getNaturalSelectors(true) or getNaturalSelectors(false) to obtain the relevant chain of NaturalSelector's and then call the chain's get(index) method
 NaturalSelector getNaturalSelector(boolean a_processBeforeGeneticOperators, int a_index)
           
 ChainOfSelectors getNaturalSelectors(boolean a_processBeforeGeneticOperators)
          Only use for read-only access!
 int getNaturalSelectorsSize(boolean a_processBeforeGeneticOperators)
           
 int getPopulationSize()
          Retrieves the population size setup in this Configuration instance.
 RandomGenerator getRandomGenerator()
          Retrieves the random generator setup in this Configuration instance.
 IChromosome getSampleChromosome()
          Retrieves the sample Chromosome that contains the desired Gene setup for each respective gene position (locus).
 double getSelectFromPrevGen()
           
protected static java.lang.String getThreadKey(java.lang.Thread current, java.lang.String a_id)
          Builds a string considering the current thread and the given id.
 void incrementGenerationNr()
           
 boolean isAlwaysCalculateFitness()
           
 boolean isKeepPopulationSizeConstant()
          See setKeepPopulationSizeConstant and GABreeder#evolve(Population, Configuration) for detailled explanation.
 boolean isLocked()
          Retrieves the lock status of this object.
 boolean isPreserveFittestIndividual()
           
 boolean isUniqueKeysActive()
           
 void lockSettings()
          Locks all of the settings in this configuration object.
protected  java.lang.String makeKey(java.lang.Object a_obj)
           
protected  java.lang.String makeThreadKey()
           
 Configuration newInstance(java.lang.String a_id, java.lang.String a_name)
          Creates a new Configuration instance by cloning.
 void removeNaturalSelectors(boolean a_processBeforeGeneticOperators)
          Removes all natural selectors (either pre or post ones).
static void reset()
          SHOULD NOT BE NECESSARY TO CALL UNDER NORMAL CIRCUMSTANCES.
static void reset(java.lang.String a_id)
          Reset the configuration so that re-setting parameters such as fitness function is possible (without calling this method, an overwriting of a previously set fitness function results in a RuntimeException).
static void resetProperty(java.lang.String a_propName)
          See Configuration.reset().
static void resetProperty(java.lang.String a_propName, java.lang.String a_id)
           
 void setAlwaysCaculateFitness(boolean a_alwaysCalculate)
           
 void setBreeder(IBreeder a_breeder)
           
 void setBulkFitnessFunction(BulkFitnessFunction a_functionToSet)
          Sets the bulk fitness function to be used for this genetic algorithm.
 void setChromosomePool(IChromosomePool a_chromosomePoolToSet)
          Sets the ChromosomePool that is to be associated with this configuration.
 void setEventManager(IEventManager a_eventManagerToSet)
          Sets the event manager that is to be associated with this configuration.
 void setFitnessEvaluator(FitnessEvaluator a_fitnessEvaluator)
          Set the fitness evaluator (deciding if a given fitness value is better when it's higher or better when it's lower).
 void setFitnessFunction(FitnessFunction a_functionToSet)
          Sets the fitness function to be used for this genetic algorithm.
protected  void setId(java.lang.String a_id)
          Only to be called by sub classes, such as GPConfiguration.
 void setJGAPFactory(IJGAPFactory a_factory)
           
 void setKeepPopulationSizeConstant(boolean a_keepPopSizeConstant)
          Allows to keep the population size constant during one evolution, even if there is no appropriate instance of NaturalSelector (such as WeightedRouletteSelector) registered with the Configuration.
 void setMinimumPopSizePercent(int a_minimumSizeGuaranteedPercent)
          Minimum size guaranteed for population.
 void setMonitor(IEvolutionMonitor a_monitor)
          Sets a monitor for auditing evolution progress.
 void setName(java.lang.String a_name)
           
 void setNaturalSelector(NaturalSelector a_selectorToSet)
          Deprecated. use addNaturalSelector(false) instead
 void setPopulationSize(int a_sizeOfPopulation)
          Sets the population size to be used for this genetic algorithm.
 void setPreservFittestIndividual(boolean a_preserveFittest)
          Determines whether to save (keep) the fittest individual.
 void setRandomGenerator(RandomGenerator a_generatorToSet)
          Sets the random generator to be used for this genetic algorithm.
 void setSampleChromosome(IChromosome a_sampleChromosomeToSet)
          Sets the sample Chromosome that is to be used as a guide for the construction of other Chromosomes.
 void setSelectFromPrevGen(double a_percentage)
           
 void setUniqueKeysActive(boolean a_active)
           
 java.lang.String toString()
           
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
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PROPERTY_JGAPFACTORY_CLASS

public static final java.lang.String PROPERTY_JGAPFACTORY_CLASS
Constant for class name of JGAP Factory to use. Use as: System.setProperty(PROPERTY_JGAPFACTORY_CLASS, "myJGAPFactory"); If none such property set, class JGAPFactory will be used.

See Also:
Constant Field Values

PROPERTY_FITFUNC_INST

public static final java.lang.String PROPERTY_FITFUNC_INST
See Also:
Constant Field Values

PROPERTY_BFITFNC_INST

public static final java.lang.String PROPERTY_BFITFNC_INST
See Also:
Constant Field Values

PROPERTY_FITEVAL_INST

public static final java.lang.String PROPERTY_FITEVAL_INST
See Also:
Constant Field Values

PROPERTY_SAMPLE_CHROM_INST

public static final java.lang.String PROPERTY_SAMPLE_CHROM_INST
See Also:
Constant Field Values

PROPERTY_EVENT_MGR_INST

public static final java.lang.String PROPERTY_EVENT_MGR_INST
See Also:
Constant Field Values

S_CONFIGURATION

public static final java.lang.String S_CONFIGURATION
Constants for toString()

See Also:
Constant Field Values

S_CONFIGURATION_NAME

public static final java.lang.String S_CONFIGURATION_NAME
See Also:
Constant Field Values

S_POPULATION_SIZE

public static final java.lang.String S_POPULATION_SIZE
See Also:
Constant Field Values

S_MINPOPSIZE

public static final java.lang.String S_MINPOPSIZE
See Also:
Constant Field Values

S_CHROMOSOME_SIZE

public static final java.lang.String S_CHROMOSOME_SIZE
See Also:
Constant Field Values

S_SAMPLE_CHROM

public static final java.lang.String S_SAMPLE_CHROM
See Also:
Constant Field Values

S_SIZE

public static final java.lang.String S_SIZE
See Also:
Constant Field Values

S_TOSTRING

public static final java.lang.String S_TOSTRING
See Also:
Constant Field Values

S_RANDOM_GENERATOR

public static final java.lang.String S_RANDOM_GENERATOR
See Also:
Constant Field Values

S_EVENT_MANAGER

public static final java.lang.String S_EVENT_MANAGER
See Also:
Constant Field Values

S_NONE

public static final java.lang.String S_NONE
See Also:
Constant Field Values

S_CONFIGURATION_HANDLER

public static final java.lang.String S_CONFIGURATION_HANDLER
See Also:
Constant Field Values

S_FITNESS_FUNCTION

public static final java.lang.String S_FITNESS_FUNCTION
See Also:
Constant Field Values

S_FITNESS_EVALUATOR

public static final java.lang.String S_FITNESS_EVALUATOR
See Also:
Constant Field Values

S_GENETIC_OPERATORS

public static final java.lang.String S_GENETIC_OPERATORS
See Also:
Constant Field Values

S_NATURAL_SELECTORS

public static final java.lang.String S_NATURAL_SELECTORS
See Also:
Constant Field Values

S_PRE

public static final java.lang.String S_PRE
See Also:
Constant Field Values

S_POST

public static final java.lang.String S_POST
See Also:
Constant Field Values
Constructor Detail

Configuration

public Configuration()

Configuration

public Configuration(java.lang.String a_id,
                     java.lang.String a_name)
Initialize with default values.

Parameters:
a_id - unique id for the configuration within the current thread
a_name - informative name of the configuration, may be null
Since:
1.0

Configuration

public Configuration(java.lang.String a_name)
Constructs a configuration with an informative name but without a unique ID. This practically prevents more than one configurations to be instantiated within the same thread.

Parameters:
a_name - informative name of the configuration, may be null

Configuration

public Configuration(java.lang.String a_configFileName,
                     boolean a_ignore)
              throws ConfigException,
                     InvalidConfigurationException
Reads in the configuration from the given file.

Parameters:
a_configFileName - the config file from which to load the configuration
a_ignore - just there to create distinct signatures :-(
Throws:
ConfigException
InvalidConfigurationException
Since:
2.3
Method Detail

reset

public static void reset()
SHOULD NOT BE NECESSARY TO CALL UNDER NORMAL CIRCUMSTANCES. May be useful for unit tests.

Reset the configuration so that re-setting parameters such as fitness function is possible (without calling this method, an overwriting of a previously set fitness function results in a RuntimeException).

Since:
3.0

reset

public static void reset(java.lang.String a_id)
Reset the configuration so that re-setting parameters such as fitness function is possible (without calling this method, an overwriting of a previously set fitness function results in a RuntimeException).

Parameters:
a_id - a hopefully unique id of the configuration
Since:
3.0

resetProperty

public static void resetProperty(java.lang.String a_propName)
See Configuration.reset().

Parameters:
a_propName - the property to reset
Since:
3.0

resetProperty

public static void resetProperty(java.lang.String a_propName,
                                 java.lang.String a_id)

setName

public void setName(java.lang.String a_name)
Parameters:
a_name - informative name of the configuration
Since:
2.3

getName

public java.lang.String getName()
Returns:
informative name of the configuration
Since:
2.3

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

checkProperty

protected void checkProperty(java.lang.String a_propname,
                             java.lang.Object a_obj,
                             java.lang.Object a_oldObj,
                             java.lang.String a_errmsg)
Verifies that a property is not set. If not set, set it, otherwise throw a RuntimeException with a_errmsg as text.

Parameters:
a_propname - the property to check (the current thread will be considered as a part of the property's name, too)
a_obj - the object that should be set in charge of the property
a_oldObj - the old object that is set until now. Not used yet
a_errmsg - the error message to throw in case the property is already set for the current thread
Since:
3.0

makeKey

protected java.lang.String makeKey(java.lang.Object a_obj)
Parameters:
a_obj - the object to make a key for, must not be null
Returns:
key produced for the object (hashCode() is used, so it should be implemented properly!)
Since:
3.0

getFitnessFunction

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

Returns:
the fitness function
Since:
1.0

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

getBulkFitnessFunction

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

Returns:
the bulk fitness function
Since:
1.0

setSampleChromosome

public void setSampleChromosome(IChromosome 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 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 Chromosome.

Parameters:
a_sampleChromosomeToSet - Chromosome to be used as the sample
Throws:
InvalidConfigurationException - if the given Chromosome is null or this Configuration object is locked
Since:
1.0

getSampleChromosome

public IChromosome getSampleChromosome()
Retrieves the sample Chromosome that contains the desired Gene setup for each respective gene position (locus).

Returns:
sample Chromosome instance
Since:
1.0

getChromosomeSize

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

Returns:
chromosome size used in this configuration
Since:
1.0

setNaturalSelector

public void setNaturalSelector(NaturalSelector a_selectorToSet)
                        throws InvalidConfigurationException
Deprecated. use addNaturalSelector(false) instead

Sets 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 guided by 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 null or this Configuration object is locked
Since:
1.0

getNaturalSelector

public NaturalSelector getNaturalSelector()
Deprecated. use getNaturalSelectors(true) or getNaturalSelectors(false) to obtain the relevant chain of NaturalSelector's and then call the chain's get(index) method

Retrieves the natural selector setup in this Configuration instance.

Returns:
the natural selector
Since:
1.0

getNaturalSelector

public NaturalSelector getNaturalSelector(boolean a_processBeforeGeneticOperators,
                                          int a_index)
Parameters:
a_processBeforeGeneticOperators - true: retrieve selector that is registered to be executed before genetic operators, false: get the one that is registered to be executed after genetic operators
a_index - index of the selector to get
Returns:
NaturalSelector
Since:
1.1

getNaturalSelectors

public ChainOfSelectors getNaturalSelectors(boolean a_processBeforeGeneticOperators)
Only use for read-only access! Especially don't call clear() for the returned ChainOfSelectors object!

Parameters:
a_processBeforeGeneticOperators - true: retrieve selector that is registered to be executed before genetic operators, false: get the one that is registered to be executed after genetic operators
Returns:
ChainOfSelectors
Since:
1.1

getNaturalSelectorsSize

public int getNaturalSelectorsSize(boolean a_processBeforeGeneticOperators)
Parameters:
a_processBeforeGeneticOperators - true: retrieve selector that is registered to be executed before genetic operators, false: get the one that is registered to be executed after genetic operators
Returns:
size of selector list (distinct by a_processBeforeGeneticOperators)
Since:
1.1

removeNaturalSelectors

public void removeNaturalSelectors(boolean a_processBeforeGeneticOperators)
Removes all natural selectors (either pre or post ones).

Parameters:
a_processBeforeGeneticOperators - true: remove all selectors processed before genetic operators, false: remove the ones processed afterwards
Since:
2.3

setRandomGenerator

public void setRandomGenerator(RandomGenerator 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 - random generator to be used
Throws:
InvalidConfigurationException - if the random generator is null or this object is locked
Since:
1.0

getRandomGenerator

public RandomGenerator getRandomGenerator()
Retrieves the random generator setup in this Configuration instance.

Returns:
the random generator
Since:
1.0

addGeneticOperator

public void addGeneticOperator(GeneticOperator a_operatorToAdd)
                        throws InvalidConfigurationException
Adds 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 add.
Throws:
InvalidConfigurationException - if the genetic operator is null or if this Configuration object is locked
Since:
1.0

getGeneticOperators

public java.util.List getGeneticOperators()
Retrieves the genetic operators setup in this Configuration instance. 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
Since:
1.0

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 - population size to be used
Throws:
InvalidConfigurationException - if the population size is not positive or this object is locked
Since:
1.0

getPopulationSize

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

Returns:
population size

setEventManager

public void setEventManager(IEventManager a_eventManagerToSet)
                     throws InvalidConfigurationException
Sets the event manager that is to be associated with this configuration. The event manager 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
Since:
1.0

getEventManager

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

Returns:
the actively configured event manager instance
Since:
1.0

setChromosomePool

public void setChromosomePool(IChromosomePool a_chromosomePoolToSet)
                       throws InvalidConfigurationException
Sets the ChromosomePool that is to be associated with this configuration. The ChromosomePool is used to pool discarded Chromosome instances so that they may be recycled later, thereby saving memory and the time to construct them from scratch. 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
Since:
1.0

getChromosomePool

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

Returns:
the ChromosomePool instance associated this configuration, or null if none has been provided
Since:
1.0

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

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

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

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

addNaturalSelector

public void addNaturalSelector(NaturalSelector a_selector,
                               boolean a_processBeforeGeneticOperators)
                        throws InvalidConfigurationException
Adds a NaturalSelector to the ordered chain of registered NaturalSelector's. It's possible to execute the NaturalSelector before or after (registered) genetic operations have been applied. Normally, you would add a selector that is applied after the genetic operators are processed (a_processBeforeGeneticOperators = false).

Parameters:
a_selector - the selector to be added to the chain
a_processBeforeGeneticOperators - true: execute NaturalSelector before any genetic operator will be applied, false: .. after..
Throws:
InvalidConfigurationException
Since:
1.1

setMinimumPopSizePercent

public void setMinimumPopSizePercent(int a_minimumSizeGuaranteedPercent)
Minimum size guaranteed for population. This is significant during evolution as natural selectors could select fewer chromosomes for the next generation than the initial population size was.

Parameters:
a_minimumSizeGuaranteedPercent - if zero or below then no ensurance for size given, see Genotype.evolve()

getMinimumPopSizePercent

public int getMinimumPopSizePercent()

getFitnessEvaluator

public FitnessEvaluator getFitnessEvaluator()
Returns:
the assigned FitnessEvaluator
Since:
2.0

setFitnessEvaluator

public void setFitnessEvaluator(FitnessEvaluator a_fitnessEvaluator)
Set the fitness evaluator (deciding if a given fitness value is better when it's higher or better when it's lower).

Parameters:
a_fitnessEvaluator - the FitnessEvaluator to be used
Since:
2.0

isPreserveFittestIndividual

public boolean isPreserveFittestIndividual()
Returns:
true: fittest chromosome should always be transferred to next generation
Since:
2.1

setPreservFittestIndividual

public void setPreservFittestIndividual(boolean a_preserveFittest)
Determines whether to save (keep) the fittest individual.

Parameters:
a_preserveFittest - true: always transfer fittest chromosome to next generation
Since:
2.1

incrementGenerationNr

public void incrementGenerationNr()

getGenerationNr

public int getGenerationNr()

getConfigurationHandler

public ConfigurationHandler getConfigurationHandler()
Implementation of the Configurable interface.

Returns:
ConfigurationHandler
Throws:
ConfigException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
string representation of the configuration containing all configurable elements
Since:
2.3

isKeepPopulationSizeConstant

public boolean isKeepPopulationSizeConstant()
See setKeepPopulationSizeConstant and GABreeder#evolve(Population, Configuration) for detailled explanation.

Returns:
true: population size will always be the same size (as given with Configuration.setPopulationSize(int)
Since:
2.4

setKeepPopulationSizeConstant

public void setKeepPopulationSizeConstant(boolean a_keepPopSizeConstant)
Allows to keep the population size constant during one evolution, even if there is no appropriate instance of NaturalSelector (such as WeightedRouletteSelector) registered with the Configuration.

See setKeepPopulationSizeConstant and GABreeder#evolve(Population, Configuration) for detailled explanation.

Parameters:
a_keepPopSizeConstant - true: population size will always be the same size (as given with Configuration.setPopulationSize(int)
Since:
2.4

setSelectFromPrevGen

public void setSelectFromPrevGen(double a_percentage)

getSelectFromPrevGen

public double getSelectFromPrevGen()

getJGAPFactory

public IJGAPFactory getJGAPFactory()
Returns:
the JGAP factory registered

getThreadKey

protected static java.lang.String getThreadKey(java.lang.Thread current,
                                               java.lang.String a_id)
Builds a string considering the current thread and the given id.

Parameters:
current - the current Thread
a_id - a hopefully unique id of the configuration
Returns:
string built up
Since:
3.01

setJGAPFactory

public void setJGAPFactory(IJGAPFactory a_factory)
Parameters:
a_factory - the IJGAPFactory to use
Since:
3.01

setBreeder

public void setBreeder(IBreeder a_breeder)
Parameters:
a_breeder - the breeder to use
Since:
3.2

getBreeder

public IBreeder getBreeder()
Returns:
the breeder set or new standard breeder instance in case no breeder was set before.
Since:
3.2

setAlwaysCaculateFitness

public void setAlwaysCaculateFitness(boolean a_alwaysCalculate)
Parameters:
a_alwaysCalculate - true: Chromosome.getFitnessValue() will always (re-)calculate the fitness value. This may be necessary in case of environments where the state changes without the chromosome to notice.
Since:
3.2.2

isAlwaysCalculateFitness

public boolean isAlwaysCalculateFitness()
Returns:
true: Chromosome.getFitnessValue() will always (re-)calculate the fitness value. This may be necessary in case of environments where the state changes without the chromosome to notice.
Since:
3.2.2

makeThreadKey

protected java.lang.String makeThreadKey()

getId

public java.lang.String getId()
Returns:
the id of the configuration set
Since:
3.1

setId

protected void setId(java.lang.String a_id)
Only to be called by sub classes, such as GPConfiguration.

Parameters:
a_id - the id to set
Since:
3.2

clone

public java.lang.Object clone()
Specified by:
clone in interface ICloneable
Overrides:
clone in class java.lang.Object
Returns:
deep clone of this instance
Since:
3.2

newInstance

public Configuration newInstance(java.lang.String a_id,
                                 java.lang.String a_name)
Creates a new Configuration instance by cloning. Allows to preset the ID and the name.

Parameters:
a_id - new ID for clone
a_name - new name for clone
Returns:
deep clone of this instance
Since:
3.2

doClone

protected java.lang.Object doClone(java.lang.Object a_objToClone)
                            throws java.lang.Exception
Helper called from clone.

Parameters:
a_objToClone - the object to clone
Returns:
cloned object or null, if cloning not possible
Throws:
java.lang.Exception
Since:
3.2

equals

public boolean equals(java.lang.Object a_other)
The equals-method.

Overrides:
equals in class java.lang.Object
Parameters:
a_other - the other object to compare
Returns:
true if seen as equal
Since:
3.2

compareTo

public int compareTo(java.lang.Object a_other)
The compareTo-method.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
a_other - the other object to compare
Returns:
-1, 0, 1
Since:
3.2

setMonitor

public void setMonitor(IEvolutionMonitor a_monitor)
Sets a monitor for auditing evolution progress.

Parameters:
a_monitor - the monitor to use
Since:
3.5

getMonitor

public IEvolutionMonitor getMonitor()
Returns:
the monitor uses for auditing the evolution progress.
Since:
3.5

setUniqueKeysActive

public void setUniqueKeysActive(boolean a_active)
Parameters:
a_active - true: use unique keys to allow tracking and monitoring
Since:
3.5

isUniqueKeysActive

public boolean isUniqueKeysActive()
Returns:
true: use unique keys to allow tracking and monitoring
Since:
3.5

JGAP