org.jgap
Class MutationOperator

java.lang.Object
  extended by org.jgap.MutationOperator
Direct Known Subclasses:
AddConnectionMutationOperator, AddNeuronMutationOperator, PruneMutationOperator, RemoveConnectionMutationOperator, SingleTopologicalMutationOperator, WeightMutationOperator

public abstract class MutationOperator
extends java.lang.Object

Abstract class for mutation operators. Handles iteration over population and updating chromosome material with changes generated by subclass implementation of mutate( final Configuration config, final ChromosomeMaterial material, Set genesToAdd, Set genesToRemove ).

Author:
Philip Tucker

Constructor Summary
MutationOperator(float aMutationRate)
           
 
Method Summary
protected  boolean doesMutationOccur(java.util.Random rand)
           
protected static boolean doesMutationOccur(java.util.Random rand, float mutationRate)
           
 float getMutationRate()
           
protected abstract  void mutate(Configuration config, ChromosomeMaterial target, java.util.Set allelesToAdd, java.util.Set allelesToRemove)
          Leaves material unmodified, but updates allelesToAdd and allelesToRemove with modifications.
 void mutate(Configuration config, java.util.List offspring)
          The operate method will be invoked on each of the mutation operators referenced by the current Configuration object during the evolution phase.
protected  int numMutations(java.util.Random rand, int numOpportunities)
           
protected  void setMutationRate(float aMutationRate)
           
protected static void updateMaterial(ChromosomeMaterial material, java.util.Set allelesToAdd, java.util.Set allelesToRemove)
          updates material with specified sets of alleles; alleles present in both lists will be added (or replaced if the gene existed on original material)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MutationOperator

public MutationOperator(float aMutationRate)
Parameters:
aMutationRate -
Method Detail

mutate

protected abstract void mutate(Configuration config,
                               ChromosomeMaterial target,
                               java.util.Set allelesToAdd,
                               java.util.Set allelesToRemove)
                        throws InvalidConfigurationException
Leaves material unmodified, but updates allelesToAdd and allelesToRemove with modifications. This interface was chosen at a time when we wanted to have the mutation operators not augment each other; i.e., each one operated on the original material, and the total allelesToAdd and allelesToRemove from all mutations would be applied at once. We have gone back to updating material after each mutation operator, but left the interface this way in case we decide to switch again.

Parameters:
config -
target - chromosome material before mutation
allelesToAdd - alleles added by this mutation, Set contains Allele objects
allelesToRemove - alleles removed by this mutation, Set contains Allele objects
Throws:
InvalidConfigurationException

mutate

public void mutate(Configuration config,
                   java.util.List offspring)
            throws InvalidConfigurationException
The operate method will be invoked on each of the mutation 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.

Parameters:
config - The current active genetic configuration.
offspring - List Contains ChromosomeMaterial objects from the current evolution. Material in this List should be modified directly.
Throws:
InvalidConfigurationException

numMutations

protected int numMutations(java.util.Random rand,
                           int numOpportunities)
Parameters:
rand -
numOpportunities -
Returns:
int number of mutations given rand random number generator, numOpportunities number of oppurtunities for the mutation to occur, and the configured mutation rate

doesMutationOccur

protected boolean doesMutationOccur(java.util.Random rand)
Parameters:
rand -
Returns:
true when mutation rate and random chance dictate a mutation should occur

doesMutationOccur

protected static boolean doesMutationOccur(java.util.Random rand,
                                           float mutationRate)
Parameters:
rand -
mutationRate -
Returns:
true when mutation rate and random chance dictate a mutation should occur

getMutationRate

public float getMutationRate()
Returns:
mutation rate

updateMaterial

protected static void updateMaterial(ChromosomeMaterial material,
                                     java.util.Set allelesToAdd,
                                     java.util.Set allelesToRemove)
updates material with specified sets of alleles; alleles present in both lists will be added (or replaced if the gene existed on original material)

Parameters:
material -
allelesToAdd - Set contains Allele objecs
allelesToRemove - Set contains Allele objects

setMutationRate

protected void setMutationRate(float aMutationRate)
Parameters:
aMutationRate -