|
JGAP | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jgap.Configuration
public class Configuration
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.
| 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.String a_errmsg)
Verifies that a property is not set. |
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. |
IJGAPFactory |
getJGAPFactory()
|
int |
getMinimumPopSizePercent()
|
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). |
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 |
isKeepPopulationSizeConstant()
See setKeepPopulationSizeConstant for description. |
boolean |
isLocked()
Retrieves the lock status of this object. |
boolean |
isPreserveFittestIndividual()
|
void |
lockSettings()
Locks all of the settings in this configuration object. |
protected java.lang.String |
makeKey(java.lang.Object a_obj)
|
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 (may be useful for unit tests). |
static void |
reset(java.lang.String a_id)
|
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 |
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. |
void |
setJGAPFactory(IJGAPFactory a_factory)
|
void |
setKeepPopulationSizeConstant(boolean a_keepPopSizeConstant)
Allows to keep the population size constant after 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 |
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. |
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 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String PROPERTY_JGAPFACTORY_CLASS
public static final java.lang.String PROPERTY_FITFUNC_INST
public static final java.lang.String PROPERTY_BFITFNC_INST
public static final java.lang.String PROPERTY_FITEVAL_INST
public static final java.lang.String PROPERTY_SAMPLE_CHROM_INST
public static final java.lang.String PROPERTY_EVENT_MGR_INST
public static final java.lang.String S_CONFIGURATION
public static final java.lang.String S_CONFIGURATION_NAME
public static final java.lang.String S_POPULATION_SIZE
public static final java.lang.String S_MINPOPSIZE
public static final java.lang.String S_CHROMOSOME_SIZE
public static final java.lang.String S_SAMPLE_CHROM
public static final java.lang.String S_SIZE
public static final java.lang.String S_TOSTRING
public static final java.lang.String S_RANDOM_GENERATOR
public static final java.lang.String S_EVENT_MANAGER
public static final java.lang.String S_NONE
public static final java.lang.String S_CONFIGURATION_HANDLER
public static final java.lang.String S_FITNESS_FUNCTION
public static final java.lang.String S_FITNESS_EVALUATOR
public static final java.lang.String S_GENETIC_OPERATORS
public static final java.lang.String S_NATURAL_SELECTORS
public static final java.lang.String S_PRE
public static final java.lang.String S_POST
| Constructor Detail |
|---|
public Configuration()
public Configuration(java.lang.String a_id,
java.lang.String a_name)
a_id - unique id for the configuration within the current threada_name - informative name of the configuration, may be nullpublic Configuration(java.lang.String a_name)
a_name - informative name of the configuration, may be null
public Configuration(java.lang.String a_configFileName,
boolean a_ignore)
throws ConfigException,
InvalidConfigurationException
a_configFileName - the config file from which to load the
configurationa_ignore - just there to create distinct signatures :-(
ConfigException
InvalidConfigurationException| Method Detail |
|---|
public static void reset()
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).
public static void reset(java.lang.String a_id)
public static void resetProperty(java.lang.String a_propName)
a_propName - the property to reset
public static void resetProperty(java.lang.String a_propName,
java.lang.String a_id)
public void setName(java.lang.String a_name)
a_name - informative name of the configurationpublic java.lang.String getName()
public void setFitnessFunction(FitnessFunction a_functionToSet)
throws InvalidConfigurationException
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.
a_functionToSet - fitness function to be used
InvalidConfigurationException - if the fitness function is null, a
bulk fitness function has already been set, or if this Configuration
object is locked.
protected void checkProperty(java.lang.String a_propname,
java.lang.Object a_obj,
java.lang.String a_errmsg)
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 propertya_errmsg - the error message to throw in case the property is already
set for the current threadprotected java.lang.String makeKey(java.lang.Object a_obj)
a_obj - the object to make a key for, must not be null
public FitnessFunction getFitnessFunction()
public void setBulkFitnessFunction(BulkFitnessFunction a_functionToSet)
throws InvalidConfigurationException
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.
a_functionToSet - bulk fitness function to be used
InvalidConfigurationException - if the bulk fitness function is
null, the normal fitness function has already been set, or if this
Configuration object is lockedpublic BulkFitnessFunction getBulkFitnessFunction()
public void setSampleChromosome(IChromosome a_sampleChromosomeToSet)
throws InvalidConfigurationException
a_sampleChromosomeToSet - Chromosome to be used as the sample
InvalidConfigurationException - if the given Chromosome is null or
this Configuration object is lockedpublic IChromosome getSampleChromosome()
public int getChromosomeSize()
public void setNaturalSelector(NaturalSelector a_selectorToSet)
throws InvalidConfigurationException
a_selectorToSet - the natural selector to be used
InvalidConfigurationException - if the natural selector is null or
this Configuration object is lockedpublic NaturalSelector getNaturalSelector()
public NaturalSelector getNaturalSelector(boolean a_processBeforeGeneticOperators,
int a_index)
a_processBeforeGeneticOperators - booleana_index - int
public ChainOfSelectors getNaturalSelectors(boolean a_processBeforeGeneticOperators)
a_processBeforeGeneticOperators - boolean
public int getNaturalSelectorsSize(boolean a_processBeforeGeneticOperators)
a_processBeforeGeneticOperators - boolean
public void removeNaturalSelectors(boolean a_processBeforeGeneticOperators)
a_processBeforeGeneticOperators - true: remove all selectors
processed before genetic operators, false: remove the ones processed
afterwards
public void setRandomGenerator(RandomGenerator a_generatorToSet)
throws InvalidConfigurationException
a_generatorToSet - random generator to be used
InvalidConfigurationException - if the random generator is null or
this object is lockedpublic RandomGenerator getRandomGenerator()
public void addGeneticOperator(GeneticOperator a_operatorToAdd)
throws InvalidConfigurationException
a_operatorToAdd - The genetic operator to add.
InvalidConfigurationException - if the genetic operator is null or
if this Configuration object is lockedpublic java.util.List getGeneticOperators()
public void setPopulationSize(int a_sizeOfPopulation)
throws InvalidConfigurationException
a_sizeOfPopulation - population size to be used
InvalidConfigurationException - if the population size is not
positive or this object is lockedpublic int getPopulationSize()
public void setEventManager(IEventManager a_eventManagerToSet)
throws InvalidConfigurationException
a_eventManagerToSet - the EventManager instance to use in this
configuration
InvalidConfigurationException - if the event manager is null
or this Configuration object is lockedpublic IEventManager getEventManager()
public void setChromosomePool(IChromosomePool a_chromosomePoolToSet)
throws InvalidConfigurationException
a_chromosomePoolToSet - the ChromosomePool instance to use
InvalidConfigurationException - if this object is lockedpublic IChromosomePool getChromosomePool()
public void lockSettings()
throws InvalidConfigurationException
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.
InvalidConfigurationException - if this Configuration object is
in an invalid state at the time of invocationpublic boolean isLocked()
public void verifyStateIsValid()
throws InvalidConfigurationException
InvalidConfigurationException - if the state of this Configuration
is not valid. The error message in the exception will detail the reason
for invalidity
protected void verifyChangesAllowed()
throws InvalidConfigurationException
InvalidConfigurationException - if this Configuration object is
locked
public void addNaturalSelector(NaturalSelector a_selector,
boolean a_processBeforeGeneticOperators)
throws InvalidConfigurationException
a_selector - the selector to be added to the chaina_processBeforeGeneticOperators - true: execute NaturalSelector
before any genetic operator will be applied, false: .. after..
InvalidConfigurationExceptionpublic void setMinimumPopSizePercent(int a_minimumSizeGuaranteedPercent)
a_minimumSizeGuaranteedPercent - if zero or below then no ensurance
for size given, see Genotype.evolve()public int getMinimumPopSizePercent()
public FitnessEvaluator getFitnessEvaluator()
public void setFitnessEvaluator(FitnessEvaluator a_fitnessEvaluator)
a_fitnessEvaluator - the FitnessEvaluator to be usedpublic boolean isPreserveFittestIndividual()
public void setPreservFittestIndividual(boolean a_preserveFittest)
a_preserveFittest - true: always transfer fittest chromosome to next
generationpublic void incrementGenerationNr()
public int getGenerationNr()
public ConfigurationHandler getConfigurationHandler()
ConfigExceptionpublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean isKeepPopulationSizeConstant()
public void setKeepPopulationSizeConstant(boolean a_keepPopSizeConstant)
Be aware that keeping the population size constant often means that a higher population size is necessary (e.g. for the MinimizingMakeChange example)!
a_keepPopSizeConstant - true: population size will always be
the same size (as given with Configuration.setPopulationSize(int)public IJGAPFactory getJGAPFactory()
protected static java.lang.String getThreadKey(java.lang.Thread current,
java.lang.String a_id)
current - the current Threada_id - a hopefully unique id of the configuration
public void setJGAPFactory(IJGAPFactory a_factory)
a_factory - the IJGAPFactory to use
|
JGAP | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||