Top Description Constructors Methods
org.apache.commons.math3.genetics

public Class OrderedCrossover<T>

extends Object
implements CrossoverPolicy
Class Inheritance
All Implemented Interfaces
org.apache.commons.math3.genetics.CrossoverPolicy
Type Parameters
<T>
generic type of the AbstractListChromosomes for crossover
Imports
java.util.ArrayList, .Collections, .HashSet, .List, .Set, org.apache.commons.math3.exception.DimensionMismatchException, .MathIllegalArgumentException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.random.RandomGenerator, org.apache.commons.math3.util.FastMath

Order 1 Crossover [OX1] builds offspring from ordered chromosomes by copying a consecutive slice from one parent, and filling up the remaining genes from the other parent as they appear.

This policy works by applying the following rules:

  1. select a random slice of consecutive genes from parent 1
  2. copy the slice to child 1 and mark out the genes in parent 2
  3. starting from the right side of the slice, copy genes from parent 2 as they appear to child 1 if they are not yet marked out.

Example (random sublist from index 3 to 7, underlined):

p1 = (8 4 7 3 6 2 5 1 9 0)   X   c1 = (0 4 7 3 6 2 5 1 8 9)
            ---------                        ---------
p2 = (0 1 2 3 4 5 6 7 8 9)   X   c2 = (8 1 2 3 4 5 6 7 9 0)

This policy works only on AbstractListChromosome, and therefore it is parameterized by T. Moreover, the chromosomes must have same lengths.

Since
3.1
See Also
Order 1 Crossover Operator

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public ChromosomePair
crossover(final Chromosome
the first chromosome.
first
,
final Chromosome
the second chromosome.
second
)

Implements org.apache.commons.math3.genetics.CrossoverPolicy.crossover.

Perform a crossover operation on the given chromosomes.

protected ChromosomePair

Returns:

the pair of new chromosomes that resulted from the crossover
mate
(final AbstractListChromosome<T>
the first chromosome
first
,
final AbstractListChromosome<T>
the second chromosome
second
)

Helper for crossover(Chromosome, Chromosome).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

OrderedCrossoverback to summary
public OrderedCrossover()

Method Detail

crossoverback to summary
public ChromosomePair crossover(final Chromosome first, final Chromosome second) throws DimensionMismatchException, MathIllegalArgumentException

Implements org.apache.commons.math3.genetics.CrossoverPolicy.crossover.

Doc from org.apache.commons.math3.genetics.CrossoverPolicy.crossover.

Perform a crossover operation on the given chromosomes.

Parameters
first:Chromosome

the first chromosome.

second:Chromosome

the second chromosome.

Returns:ChromosomePair

the pair of new chromosomes that resulted from the crossover.

Annotations
@SuppressWarnings:unchecked
Exceptions
DimensionMismatchException:
if the length of the two chromosomes is different
MathIllegalArgumentException:
iff one of the chromosomes is not an instance of AbstractListChromosome
mateback to summary
protected ChromosomePair mate(final AbstractListChromosome<T> first, final AbstractListChromosome<T> second) throws DimensionMismatchException

Helper for crossover(Chromosome, Chromosome). Performs the actual crossover.

Parameters
first:AbstractListChromosome<T>

the first chromosome

second:AbstractListChromosome<T>

the second chromosome

Returns:ChromosomePair

the pair of new chromosomes that resulted from the crossover

Exceptions
DimensionMismatchException:
if the length of the two chromosomes is different