JGAP

org.jgap.impl
Class RangedSwappingMutationOperator

java.lang.Object
  extended by org.jgap.BaseGeneticOperator
      extended by org.jgap.impl.MutationOperator
          extended by org.jgap.impl.RangedSwappingMutationOperator
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable, Configurable, GeneticOperator

public class RangedSwappingMutationOperator
extends MutationOperator

Swaps the genes instead of mutating them. This kind of operator is required by Traveling Salesman Problem. Copied and modified from SwappingMutationOperator. This implementation takes a range as parameter and uses it to only swap genes that are -/+ range indexes away from the gene being mutated. This basically allows for local searches before propagating through the entire problem space. Seems to work much better/quicker than a random swapping across the entire chromosome.

Since:
3.3.2
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.jgap.BaseGeneticOperator
m_monitor, m_monitorActive
 
Constructor Summary
RangedSwappingMutationOperator()
          Constructs a new instance of this operator.
RangedSwappingMutationOperator(Configuration a_config, int a_range)
           
RangedSwappingMutationOperator(Configuration a_config, int a_desiredMutationRate, int a_range)
          Constructs a new instance of this MutationOperator with the given mutation rate.
RangedSwappingMutationOperator(Configuration a_config, IUniversalRateCalculator a_mutationRateCalculator, int a_range)
          Constructs a new instance of this operator with a specified mutation rate calculator, which results in dynamic mutation being turned on.
 
Method Summary
 int getRange()
          Gets the mutation range.
 int getStartOffset()
          Gets a number of genes at the start of chromosome, that are excluded from the swapping.
protected  IChromosome operate(IChromosome a_chrom, int a_rate, RandomGenerator a_generator)
          Operate on the given chromosome with the given mutation rate.
 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.
protected  Gene[] operate(RandomGenerator a_generator, int a_target_gene, Gene[] a_genes)
          Operate on the given array of genes.
 void setRange(int a_range)
          Sets the mutation range.
 void setStartOffset(int a_offset)
          Sets a number of genes at the start of chromosome, that are excluded from the swapping.
 
Methods inherited from class org.jgap.impl.MutationOperator
compareTo, equals, getMutationRate, getMutationRateCalc, setMutationRate, setMutationRateCalc
 
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

RangedSwappingMutationOperator

public RangedSwappingMutationOperator()
                               throws InvalidConfigurationException
Constructs a new instance of this operator.

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

Throws:
InvalidConfigurationException
Since:
3.3.2

RangedSwappingMutationOperator

public RangedSwappingMutationOperator(Configuration a_config,
                                      int a_range)
                               throws InvalidConfigurationException
Parameters:
a_config - the configuration to use
a_range - the maximum range to use for considering genes to be swapped. The range is computed as the difference of the indices between two genes
Throws:
InvalidConfigurationException
Since:
3.3.2

RangedSwappingMutationOperator

public RangedSwappingMutationOperator(Configuration a_config,
                                      IUniversalRateCalculator a_mutationRateCalculator,
                                      int a_range)
                               throws InvalidConfigurationException
Constructs a new instance of this operator 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
a_range - the maximum range to use for considering genes to be swapped. The range is computed as the difference of the indices between two genes
Throws:
InvalidConfigurationException
Since:
3.3.2

RangedSwappingMutationOperator

public RangedSwappingMutationOperator(Configuration a_config,
                                      int a_desiredMutationRate,
                                      int a_range)
                               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
a_range - the maximum range to use for considering genes to be swapped. The range is computed as the difference of the indices between two genes
Throws:
InvalidConfigurationException
Since:
3.3.2
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
Overrides:
operate in class MutationOperator
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 selected for the next evolved population
Since:
3.3.2

operate

protected IChromosome operate(IChromosome a_chrom,
                              int a_rate,
                              RandomGenerator a_generator)
Operate on the given chromosome with the given mutation rate.

Parameters:
a_chrom - chromosome to operate
a_rate - mutation rate
a_generator - random generator to use (must not be null)
Returns:
mutated chromosome of null if no mutation has occured.
Since:
3.3.2

operate

protected Gene[] operate(RandomGenerator a_generator,
                         int a_target_gene,
                         Gene[] a_genes)
Operate on the given array of genes. This method is only called when it is already clear that the mutation must occur under the given mutation rate.

Parameters:
a_generator - a random number generator that may be needed to perform a mutation
a_target_gene - an index of gene in the chromosome that will mutate
a_genes - the array of all genes in the chromosome
Returns:
the mutated gene array
Since:
3.3.2

setStartOffset

public void setStartOffset(int a_offset)
Sets a number of genes at the start of chromosome, that are excluded from the swapping. In the Salesman task, the first city in the list should (where the salesman leaves from) probably should not change as it is part of the list. The default value is 1.

Parameters:
a_offset - the offset to set
Since:
3.3.2

getStartOffset

public int getStartOffset()
Gets a number of genes at the start of chromosome, that are excluded from the swapping. In the Salesman task, the first city in the list should (where the salesman leaves from) probably should not change as it is part of the list. The default value is 1.

Returns:
the start offset
Since:
3.3.2

setRange

public void setRange(int a_range)
Sets the mutation range. This specifies the genes before and after which a subject gene is allowed to swap with

Parameters:
a_range - the offset to set
Since:
3.3.2

getRange

public int getRange()
Gets the mutation range.

Returns:
the start offset
Since:
3.3.2

JGAP