Documentation of 'org.jgap.Configuration' Java class
Configuration
org.jgap

Class Configuration

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Comparable, Configurable, ICloneable
    Direct Known Subclasses:
    DefaultConfiguration, 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
    • 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_CHROMOSOME_SIZE

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

        public static final java.lang.String S_RANDOM_GENERATOR
        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
    • 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
    • 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
      • 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
      • 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
      • 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
      • getId

        public java.lang.String getId()
        Returns:
        the id of the configuration set
        Since:
        3.1
      • 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
      • 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

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.