Package io.jenetics

Class MultiPointCrossover<G extends Gene<?,G>,C extends Comparable<? super C>>

All Implemented Interfaces:
Alterer<G,C>
Direct Known Subclasses:
SinglePointCrossover

public class MultiPointCrossover<G extends Gene<?,G>,C extends Comparable<? super C>> extends Crossover<G,C>

Multiple point crossover

If the MultiPointCrossover is created with one crossover point, it behaves exactly like the SinglePointCrossover. The following picture shows how the MultiPointCrossover works with two crossover points, defined at index 1 and 4.

2-point crossover

If the number of crossover points is odd, the crossover looks like in the following figure.

3-point crossover

Since:
1.2
Version:
6.0
See Also:
  • Constructor Details

    • MultiPointCrossover

      public MultiPointCrossover(double probability, int n)
      Create a new crossover instance.
      Parameters:
      probability - the recombination probability.
      n - the number of crossover points.
      Throws:
      IllegalArgumentException - if the probability is not in the valid range of [0, 1] or n &lt; 1.
    • MultiPointCrossover

      public MultiPointCrossover(double probability)
      Create a new crossover instance with two crossover points.
      Parameters:
      probability - the recombination probability.
      Throws:
      IllegalArgumentException - if the probability is not in the valid range of [0, 1].
    • MultiPointCrossover

      public MultiPointCrossover(int n)
      Create a new crossover instance with default crossover probability of 0.05.
      Parameters:
      n - the number of crossover points.
      Throws:
      IllegalArgumentException - if n &lt; 1.
    • MultiPointCrossover

      Create a new crossover instance with two crossover points and crossover probability 0.05.
  • Method Details

    • crossoverPointCount

      public int crossoverPointCount()
      Return the number of crossover points.
      Returns:
      the number of crossover points.
    • 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
    • toString

      public String toString()
      Overrides:
      toString in class Object