Module io.jenetics.base
Package io.jenetics
Class Mutator<G extends Gene<?,G>,C extends Comparable<? super C>>
java.lang.Object
io.jenetics.AbstractAlterer<G,C>
io.jenetics.Mutator<G,C>
- All Implemented Interfaces:
Alterer<G,
C>
- Direct Known Subclasses:
GaussianMutator
,HPRMutator
,RSMutator
,SwapMutator
,TreeMutator
,WeaselMutator
public class Mutator<G extends Gene<?,G>,C extends Comparable<? super C>>
extends AbstractAlterer<G,C>
This class is for mutating the chromosomes of a given population. There are
two distinct roles mutation plays
- Exploring the search space. By making small moves mutation allows a population to explore the search space. This exploration is often slow compared to crossover, but in problems where crossover is disruptive this can be an important way to explore the landscape.
- Maintaining diversity. Mutation prevents a population from correlating. Even if most of the search is being performed by crossover, mutation can be vital to provide the diversity which crossover needs.
The mutation probability is the parameter that must be optimized. The optimal value of the mutation rate depends on the role mutation plays. If mutation is the only source of exploration (if there is no crossover) then the mutation rate should be set so that a reasonable neighborhood of solutions is explored.
The mutation probability P(m) is the probability that a specific gene over the whole population is mutated. The number of available genes of a population iswhere NP is the population size, Ng the number of genes of a genotype. So the (average) number of genes mutated by the mutation is
- Since:
- 1.0
- Version:
- 4.0
-
Field Summary
Fields inherited from class io.jenetics.AbstractAlterer
_probability
Fields inherited from interface io.jenetics.Alterer
DEFAULT_ALTER_PROBABILITY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionConcrete implementation of the alter method.protected G
mutate
(G gene, RandomGenerator random) Mutates the given gene.protected MutatorResult<Chromosome<G>>
mutate
(Chromosome<G> chromosome, double p, RandomGenerator random) Mutates the given chromosome.protected MutatorResult<Genotype<G>>
mutate
(Genotype<G> genotype, double p, RandomGenerator random) Mutates the given genotype.protected MutatorResult<Phenotype<G,
C>> mutate
(Phenotype<G, C> phenotype, long generation, double p, RandomGenerator random) Mutates the given phenotype.toString()
Methods inherited from class io.jenetics.AbstractAlterer
probability
-
Constructor Details
-
Mutator
Construct a Mutation object which a given mutation probability.- Parameters:
probability
- Mutation probability. The given probability is divided by the number of chromosomes of the genotype to form the concrete mutation probability.- Throws:
IllegalArgumentException
- if theprobability
is not in the valid range of[0, 1]
.
-
Mutator
public Mutator()Default constructor, with probability = 0.01.
-
-
Method Details
-
alter
Concrete implementation of the alter method. It uses the following mutation methods:mutate(Phenotype, long, double, RandomGenerator)
,mutate(Genotype, double, RandomGenerator)
,mutate(Chromosome, double, RandomGenerator)
,mutate(Gene, RandomGenerator)
, in this specific order.- Parameters:
population
- The Population to be altered. If thepopulation
isnull
or 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
protected MutatorResult<Phenotype<G,C>> mutate(Phenotype<G, C> phenotype, long generation, double p, RandomGenerator random) Mutates the given phenotype.- Parameters:
phenotype
- the phenotype to mutategeneration
- the actual generationp
- the mutation probability for the underlying genetic objectsrandom
- the random engine used for the phenotype mutation- Returns:
- the mutation result
- See Also:
-
mutate
Mutates the given genotype.- Parameters:
genotype
- the genotype to mutatep
- the mutation probability for the underlying genetic objectsrandom
- the random engine used for the genotype mutation- Returns:
- the mutation result
- See Also:
-
mutate
protected MutatorResult<Chromosome<G>> mutate(Chromosome<G> chromosome, double p, RandomGenerator random) Mutates the given chromosome.- Parameters:
chromosome
- the chromosome to mutatep
- the mutation probability for the underlying genetic objectsrandom
- the random engine used for the genotype mutation- Returns:
- the mutation result
- See Also:
-
mutate
Mutates the given gene.- Parameters:
gene
- the gene to mutaterandom
- the random engine used for the genotype mutation- Returns:
- the mutation result
-
toString
-