OrderedCrossover (Apache Commons Math 3.3 API)

org.apache.commons.math3.genetics

## Class OrderedCrossover<T>

- java.lang.Object
- - org.apache.commons.math3.genetics.OrderedCrossover<T>

- Type Parameters:
    `T` - generic type of the `AbstractListChromosome`s for crossover
  All Implemented Interfaces:
    CrossoverPolicy

      public class OrderedCrossover<T>
      extends Object
      implements CrossoverPolicy

  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
  Version:
    $Id: OrderedCrossover.java 1385297 2012-09-16 16:05:57Z tn $
  See Also:
    Order 1 Crossover Operator

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `OrderedCrossover()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `ChromosomePair` | `crossover(Chromosome first, Chromosome second)` Perform a crossover operation on the given chromosomes.
    `protected ChromosomePair` | `mate(AbstractListChromosome<T> first, AbstractListChromosome<T> second)` Helper for `crossover(Chromosome, Chromosome)`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### OrderedCrossover

          public OrderedCrossover()

  - ### Method Detail

    - #### crossover

          public ChromosomePair crossover(Chromosome first,
                                 Chromosome second)
                                   throws DimensionMismatchException,
                                          MathIllegalArgumentException

      Perform a crossover operation on the given chromosomes.
      Specified by:
        `crossover` in interface `CrossoverPolicy`
      Parameters:
        `first` - the first chromosome.
        `second` - the second chromosome.
      Returns:
        the pair of new chromosomes that resulted from the crossover.
      Throws:
        `MathIllegalArgumentException` - iff one of the chromosomes is not an instance of `AbstractListChromosome`
        `DimensionMismatchException` - if the length of the two chromosomes is different

    - #### mate

          protected ChromosomePair mate(AbstractListChromosome<T> first,
                            AbstractListChromosome<T> second)
                                 throws DimensionMismatchException

      Helper for `crossover(Chromosome, Chromosome)`. Performs the actual crossover.
      Parameters:
        `first` - the first chromosome
        `second` - the second chromosome
      Returns:
        the pair of new chromosomes that resulted from the crossover
      Throws:
        `DimensionMismatchException` - if the length of the two chromosomes is different

Copyright © 2003–2014 The Apache Software Foundation. All rights reserved.