org.jgap.impl
Class SwappingMutationOperator
- java.lang.Object
-
- org.jgap.BaseGeneticOperator
-
- org.jgap.impl.MutationOperator
-
- org.jgap.impl.SwappingMutationOperator
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Comparable, Configurable, GeneticOperator
public class SwappingMutationOperator extends MutationOperator
Swaps the genes instead of mutating them. This kind of operator is required by Traveling Salesman Problem. See J. Grefenstette, R. Gopal, R. Rosmaita, and D. Gucht. Genetic algorithms for the traveling salesman problem. In Proceedings of the Second International Conference on Genetic Algorithms. Lawrence Eribaum Associates, Mahwah, NJ, 1985. and also Sushil J. Louis & Gong Li }- Since:
- 2.0
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description SwappingMutationOperator()Constructs a new instance of this operator.SwappingMutationOperator(Configuration a_config)SwappingMutationOperator(Configuration a_config, int a_desiredMutationRate)Constructs a new instance of this MutationOperator with the given mutation rate.SwappingMutationOperator(Configuration a_config, IUniversalRateCalculator a_mutationRateCalculator)Constructs a new instance of this operator with a specified mutation rate calculator, which results in dynamic mutation being turned on.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description intgetStartOffset()Gets a number of genes at the start of chromosome, that are excluded from the swapping.voidoperate(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.voidsetStartOffset(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
-
-
-
-
Constructor Detail
-
SwappingMutationOperator
public SwappingMutationOperator() throws InvalidConfigurationExceptionConstructs a new instance of this operator.Attention: The configuration used is the one set with the static method Genotype.setConfiguration.
- Throws:
InvalidConfigurationException
-
SwappingMutationOperator
public SwappingMutationOperator(Configuration a_config) throws InvalidConfigurationException
- Parameters:
a_config- the configuration to use- Throws:
InvalidConfigurationException- Since:
- 3.0
-
SwappingMutationOperator
public SwappingMutationOperator(Configuration a_config, IUniversalRateCalculator a_mutationRateCalculator) 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 usea_mutationRateCalculator- calculator for dynamic mutation rate computation- Throws:
InvalidConfigurationException- Since:
- 3.0 (previously: without a_config)
-
SwappingMutationOperator
public SwappingMutationOperator(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 usea_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:
- 3.0 (previously: without a_config)
-
-
Method Detail
-
operate
public void operate(Population a_population, java.util.List a_candidateChromosomes)
Description copied from interface:GeneticOperatorThe 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:
operatein interfaceGeneticOperator- Overrides:
operatein classMutationOperator- 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 issuesa_candidateChromosomes- the pool of chromosomes that have been selected for the next evolved population- Since:
- 2.0
-
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:
- 2.0
-
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:
- 2.0
-
-
DMelt 3.0 © DataMelt by jWork.ORG