java.lang.Object
org.cicirello.search.operators.permutations.CycleCrossover
All Implemented Interfaces:
PermutationFullBinaryOperator, Splittable<CrossoverOperator<Permutation>>, CrossoverOperator<Permutation>

public final class CycleCrossover extends Object implements CrossoverOperator<Permutation>, PermutationFullBinaryOperator
Implementation of cycle crossover (CX). CX selects a random index into the permutations, computes the permutation cycle of the pair of parent permutations that includes that randomly chosen element, and then exchanges the elements of the cycle between the parents in forming the children.

For example, consider the permutation p1 = [0, 1, 2, 3, 4, 5, 6, 7] and the permutation p2 = [1, 2, 0, 5, 6, 7, 4, 3]. Consider that the random index is 3. At index 3 in p1 is element 3, and at that same index in p2 is element 5. At the same position as 5 in p1 is 7 in p2. And at the same position as element 7 in p1 is element 3 in p2, thus completing the cycle. The elements of the cycle are exchanged between the parents to form the children. Thus, the children are c1 = [0, 1, 2, 5, 4, 7, 6, 3] and c2 = [1, 2, 0, 3, 6, 5, 4, 7].

The worst case runtime of a call to cross is O(n), where n is the length of the permutations.

The CX operator was introduced in the following paper:
Oliver, I.M., Smith, D.J., and Holland, J.R.C. A study of permutation crossover operators on the traveling salesman problem. Proceedings of the 2nd International Conference on Genetic Algorithms, 1987, pp. 224-230.

  • Constructor Details

    • CycleCrossover

      public CycleCrossover()
      Constructs a cycle crossover (CX) operator.
  • Method Details

    • cross

      public void cross(Permutation c1, Permutation c2)
      Description copied from interface: CrossoverOperator
      Performs a crossover for an evolutionary algorithm, such that crossover forms two children from two parents. Implementations of this method modify the parameters, transforming the parents into the children.
      Specified by:
      cross in interface CrossoverOperator<Permutation>
      Parameters:
      c1 - A candidate solution subject to the crossover. This method changes the state of c1.
      c2 - A candidate solution subject to the crossover. This method changes the state of c2.
    • split

      public CycleCrossover split()
      Description copied from interface: Splittable
      Generates a functionally identical copy of this object, for use in multithreaded implementations of search algorithms. The state of the object that is returned may or may not be identical to that of the original. Thus, this is a distinct concept from the functionality of the Copyable interface. Classes that implement this interface must ensure that the object returned performs the same functionality, and that it does not share any state data that would be either unsafe or inefficient for concurrent access by multiple threads. The split method is allowed to simply return the this reference, provided that it is both safe and efficient for multiple threads to share a single copy of the Splittable object. The intention is to provide a multithreaded search with the capability to provide spawned threads with their own distinct search operators. Such multithreaded algorithms can call the split method for each thread it spawns to generate a functionally identical copy of the operator, but with independent state.
      Specified by:
      split in interface Splittable<CrossoverOperator<Permutation>>
      Returns:
      A functionally identical copy of the object, or a reference to this if it is both safe and efficient for multiple threads to share a single instance of this Splittable object.
    • apply

      public void apply(int[] raw1, int[] raw2, Permutation p1, Permutation p2)
      See PermutationFullBinaryOperator for details of this method. This method is not intended for direct usage. Use the cross(org.cicirello.permutations.Permutation, org.cicirello.permutations.Permutation) method instead.
      Specified by:
      apply in interface PermutationFullBinaryOperator
      Parameters:
      raw1 - The raw representation of the first permutation.
      raw2 - The raw representation of the second permutation.
      p1 - The first permutation.
      p2 - The second permutation.