Package io.jenetics

Class UniformCrossover<G extends Gene<?,G>,C extends Comparable<? super 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:
  • Constructor Details

    • UniformCrossover

      public UniformCrossover(double crossoverProbability, double swapProbability)
      Create a new universal crossover instance.
      Parameters:
      crossoverProbability - the recombination probability as defined in Crossover(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

      public UniformCrossover(double crossoverProbability)
      Create a new universal crossover instance. The swapProbability is set to Alterer.DEFAULT_ALTER_PROBABILITY.
      Parameters:
      crossoverProbability - the recombination probability as defined in Crossover(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

      Create a new universal crossover instance. The probabilities are set to Alterer.DEFAULT_ALTER_PROBABILITY.
  • Method Details

    • swapProbability

      public double swapProbability()
      Return the probability for swapping genes of a chromosome.
      Returns:
      the probability for swapping genes of a chromosome
    • crossover

      protected int crossover(MSeq<G> that, MSeq<G> other)
      Description copied from class: Crossover
      Template method which performs the crossover. The arguments given are mutable non-null arrays of the same length.
      Specified by:
      crossover in class Crossover<G extends Gene<?,G>,C extends Comparable<? super C>>
      Parameters:
      that - the genes of the first chromosome
      other - the genes of the other chromosome
      Returns:
      the number of altered genes