JGAP

org.jgap.impl
Class MutationOperator

java.lang.Object
  extended by org.jgap.BaseGeneticOperator
      extended by org.jgap.impl.MutationOperator
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable, Configurable, GeneticOperator
Direct Known Subclasses:
AlphaMutationOperator, AlphaOffMutationOperator, ColorMutationOperator, PointMutationOperator, PolygonMutationOperator, RangedSwappingMutationOperator, SingleMutationOperator, SwappingMutationOperator

public class MutationOperator
extends BaseGeneticOperator
implements Configurable

The mutation operator runs through the genes in each of the Chromosomes in the population and mutates them in statistical accordance to the given mutation rate. Mutated Chromosomes are then added to the list of candidate Chromosomes destined for the natural selection process. This MutationOperator supports both fixed and dynamic mutation rates. A fixed rate is one specified at construction time by the user. A dynamic rate is determined by this class if no fixed rate is provided, and is calculated based on the size of the Chromosomes in the population. Details are specified in the DefaultMutationRateCalculator class.

Since:
1.0
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.jgap.BaseGeneticOperator
m_monitor, m_monitorActive
 
Constructor Summary
MutationOperator()
          Constructs a new instance of this MutationOperator without a specified mutation rate, which results in dynamic mutation being turned on.
MutationOperator(Configuration a_conf)
           
MutationOperator(Configuration a_config, int a_desiredMutationRate)
          Constructs a new instance of this MutationOperator with the given mutation rate.
MutationOperator(Configuration a_config, IUniversalRateCalculator a_mutationRateCalculator)
          Constructs a new instance of this MutationOperator with a specified mutation rate calculator, which results in dynamic mutation being turned on.
 
Method Summary
 int compareTo(java.lang.Object a_other)
          Compares the given GeneticOperator to this GeneticOperator.
 boolean equals(java.lang.Object a_other)
          Compares this GeneticOperator against the specified object.
 int getMutationRate()
           
 IUniversalRateCalculator getMutationRateCalc()
           
 void operate(Population a_population, java.util.List a_candidateChromosomes)
          The operate method will be invoked on each of the genetic operators referenced by the current Configuration object during the evolution phase.
 void setMutationRate(int a_mutationRate)
           
 void setMutationRateCalc(IUniversalRateCalculator a_mutationRateCalc)
          Sets the MutationRateCalculator to be used for determining the strength of mutation.
 
Methods inherited from class org.jgap.BaseGeneticOperator
getConfiguration
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MutationOperator

public MutationOperator()
                 throws InvalidConfigurationException
Constructs a new instance of this MutationOperator without a specified mutation rate, which results in dynamic mutation being turned on. This means that the mutation rate will be automatically determined by this operator based upon the number of genes present in the chromosomes.

Attention: The configuration used is the one set with the static method Genotype.setConfiguration.

Throws:
InvalidConfigurationException
Since:
1.0

MutationOperator

public MutationOperator(Configuration a_conf)
                 throws InvalidConfigurationException
Parameters:
a_conf - the configuration to use
Throws:
InvalidConfigurationException
Since:
3.0

MutationOperator

public MutationOperator(Configuration a_config,
                        IUniversalRateCalculator a_mutationRateCalculator)
                 throws InvalidConfigurationException
Constructs a new instance of this MutationOperator with a specified mutation rate calculator, which results in dynamic mutation being turned on.

Parameters:
a_config - the configuration to use
a_mutationRateCalculator - calculator for dynamic mutation rate computation
Throws:
InvalidConfigurationException
Since:
1.1

MutationOperator

public MutationOperator(Configuration a_config,
                        int a_desiredMutationRate)
                 throws InvalidConfigurationException
Constructs a new instance of this MutationOperator with the given mutation rate.

Parameters:
a_config - the configuration to use
a_desiredMutationRate - desired rate of mutation, expressed as the denominator of the 1 / X fraction. For example, 1000 would result in 1/1000 genes being mutated on average. A mutation rate of zero disables mutation entirely
Throws:
InvalidConfigurationException
Since:
1.1
Method Detail

operate

public void operate(Population a_population,
                    java.util.List a_candidateChromosomes)
Description copied from interface: GeneticOperator
The operate method will be invoked on each of the genetic operators referenced by the current Configuration object during the evolution phase. Operators are given an opportunity to run in the order that they are added to the Configuration. Implementations of this method may reference the population of Chromosomes as it was at the beginning of the evolutionary phase and/or they may instead reference the candidate Chromosomes, which are the results of prior genetic operators. In either case, only Chromosomes added to the list of candidate chromosomes will be considered for natural selection. The parameters a_population and a_candidateChromosomes may refer to the same list of chromosomes for performance issues. Thus would mean an in-place modification. In ealier JGAP versions it was suggested never modifying the input population. Please refer to implementations delivered with JGAP to get a picture of the way non-susceptible in-place modifications are possible. If wrongly done, ConcurrentModificationException could be risen when accessing the population by an iterator in a GeneticOperator. Or, if population.getChromosomes().size() was used inside a loop where chromosomes were added to the input population this could lead to an infinite loop in worst case.

Specified by:
operate in interface GeneticOperator
Parameters:
a_population - the population of chromosomes from the current evolution prior to exposure to any genetic operators. Chromosomes in this array should not be modified. Please notice, that the call in Genotype.evolve() to the implementations of GeneticOperator overgoes this due to performance issues
a_candidateChromosomes - the pool of chromosomes that have been mutated
Since:
1.0

getMutationRateCalc

public IUniversalRateCalculator getMutationRateCalc()
Returns:
the MutationRateCalculator used
Since:
1.1

setMutationRateCalc

public void setMutationRateCalc(IUniversalRateCalculator a_mutationRateCalc)
Sets the MutationRateCalculator to be used for determining the strength of mutation.

Parameters:
a_mutationRateCalc - MutationRateCalculator
Since:
1.1

setMutationRate

public void setMutationRate(int a_mutationRate)
Parameters:
a_mutationRate - new rate of mutation, expressed as the denominator of the 1 / X fraction. For example, 1000 would result in 1/1000 genes being mutated on average. A mutation rate of zero disables mutation entirely
Since:
3.2.2

equals

public boolean equals(java.lang.Object a_other)
Compares this GeneticOperator against the specified object. The result is true if and the argument is an instance of this class and is equal wrt the data.

Overrides:
equals in class BaseGeneticOperator
Parameters:
a_other - the object to compare against
Returns:
true: if the objects are the same, false otherwise
Since:
2.6

compareTo

public int compareTo(java.lang.Object a_other)
Compares the given GeneticOperator to this GeneticOperator.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
a_other - the instance against which to compare this instance
Returns:
a negative number if this instance is "less than" the given instance, zero if they are equal to each other, and a positive number if this is "greater than" the given instance
Since:
2.6

getMutationRate

public int getMutationRate()

JGAP