Module io.jenetics.base
Package io.jenetics
Class UniformCrossover<G extends Gene<?,G>,C extends Comparable<? super C>>
java.lang.Object
io.jenetics.AbstractAlterer<G,C>
io.jenetics.Recombinator<G,C>
io.jenetics.Crossover<G,C>
io.jenetics.UniformCrossover<G,C>
- All Implemented Interfaces:
Alterer<G,
C>
public class UniformCrossover<G extends Gene<?,G>,C extends Comparable<? super C>>
extends Crossover<G,C>
The uniform crossover uses swaps single genes between two chromosomes, instead
of whole ranges as in single- and multipoint crossover.
+---+---+---+---+---+---+---+
| 1 | 2 | 3 | 4 | 6 | 7 | 8 |
+-+-+---+-+-+-+-+---+-+-+---+
| | | | swapping
+-+-+---+-+-+-+-+---+-+-+---+
| a | b | c | d | e | f | g |
+---+---+---+---+---+---+---+
The probability that two genes are swapped is controlled by the
swap-probability (swapProbability()
), whereas the
probability that a given individual is selected for crossover is defined by
the crossover-probability (AbstractAlterer.probability()
).- Since:
- 3.7
- Version:
- 6.0
- See Also:
-
Field Summary
Fields inherited from class io.jenetics.AbstractAlterer
_probability
Fields inherited from interface io.jenetics.Alterer
DEFAULT_ALTER_PROBABILITY
-
Constructor Summary
ConstructorDescriptionCreate a new universal crossover instance.UniformCrossover
(double crossoverProbability) Create a new universal crossover instance.UniformCrossover
(double crossoverProbability, double swapProbability) Create a new universal crossover instance. -
Method Summary
Methods inherited from class io.jenetics.Recombinator
alter, order
Methods inherited from class io.jenetics.AbstractAlterer
probability
-
Constructor Details
-
UniformCrossover
Create a new universal crossover instance.- Parameters:
crossoverProbability
- the recombination probability as defined inCrossover(double)
. This is the probability that a given individual is selected for crossover.swapProbability
- the probability for swapping a given gene of a chromosome- Throws:
IllegalArgumentException
- if the probabilities are not in the valid range of[0, 1]
-
UniformCrossover
Create a new universal crossover instance. TheswapProbability
is set toAlterer.DEFAULT_ALTER_PROBABILITY
.- Parameters:
crossoverProbability
- the recombination probability as defined inCrossover(double)
. This is the probability that a given individual is selected for crossover.- Throws:
IllegalArgumentException
- if the probabilities are not in the valid range of[0, 1]
-
UniformCrossover
public UniformCrossover()Create a new universal crossover instance. The probabilities are set toAlterer.DEFAULT_ALTER_PROBABILITY
.
-
-
Method Details
-
swapProbability
Return the probability for swapping genes of a chromosome.- Returns:
- the probability for swapping genes of a chromosome
-
crossover
Description copied from class:Crossover
Template method which performs the crossover. The arguments given are mutable non-null arrays of the same length.
-