Module io.jenetics.ext
Package io.jenetics.ext
Class WeaselMutator<G extends Gene<?,G>,C extends Comparable<? super C>>
java.lang.Object
io.jenetics.AbstractAlterer<G,C>
io.jenetics.Mutator<G,C>
io.jenetics.ext.WeaselMutator<G,C>
- Type Parameters:
G- the gene typeC- the fitness result type
- All Implemented Interfaces:
Alterer<G,C>
public class WeaselMutator<G extends Gene<?,G>,C extends Comparable<? super C>>
extends Mutator<G,C>
Mutator implementation which is part of the
Weasel program
algorithm. The Weasel program is a thought experiment by Richard
Dawkins to illustrate the functioning of the evolution: random mutation
combined with non-random cumulative selection.
The mutator mutates the genes of every chromosome of every genotype in the population with the given mutation probability.
Engine setup for the Weasel program:
final Engine<CharacterGene, Integer> engine = Engine.builder(problem)
// Set the 'WeaselSelector'.
.selector(new WeaselSelector<>())
// Disable survivors selector.
.offspringFraction(1)
// Set the 'WeaselMutator'.
.alterers(new WeaselMutator<>(0.05))
.build();
- Since:
- 3.5
- Version:
- 5.0
- See Also:
-
Field Summary
Fields inherited from class io.jenetics.AbstractAlterer
_probabilityFields inherited from interface io.jenetics.Alterer
DEFAULT_ALTER_PROBABILITY -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new weasel mutator with the default mutation probability of0.05.WeaselMutator(double probability) Create a new weasel mutator with the given mutation probability. -
Method Summary
Modifier and TypeMethodDescriptionConcrete implementation of the alter method.protected MutatorResult<Genotype<G>> mutate(Genotype<G> genotype, double p, RandomGenerator random) Mutates the given genotype.toString()Methods inherited from class io.jenetics.AbstractAlterer
probability
-
Constructor Details
-
WeaselMutator
Create a new weasel mutator with the given mutation probability.- Parameters:
probability- the mutation probability- Throws:
IllegalArgumentException- if theprobabilityis not in the valid range of[0, 1].
-
WeaselMutator
public WeaselMutator()Create a new weasel mutator with the default mutation probability of0.05.
-
-
Method Details
-
alter
Description copied from class:MutatorConcrete implementation of the alter method. It uses the following mutation methods:Mutator.mutate(Phenotype, long, double, RandomGenerator),Mutator.mutate(Genotype, double, RandomGenerator),Mutator.mutate(Chromosome, double, RandomGenerator),Mutator.mutate(Gene, RandomGenerator), in this specific order.- Specified by:
alterin interfaceAlterer<G extends Gene<?,G>, C extends Comparable<? super C>> - Overrides:
alterin classMutator<G extends Gene<?,G>, C extends Comparable<? super C>> - Parameters:
population- The Population to be altered. If thepopulationisnullor empty, nothing is altered.generation- the date of birth (generation) of the altered phenotypes.- Returns:
- the alter-result object, which contains the altered population and the alteration counts
- See Also:
-
mutate
Description copied from class:MutatorMutates the given genotype. -
toString
-