Class CycleCrossover
 All Implemented Interfaces:
PermutationFullBinaryOperator
,Splittable<CrossoverOperator<Permutation>>
,CrossoverOperator<Permutation>
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. 224230.

Constructor Summary

Method Summary
Modifier and TypeMethodDescriptionvoid
apply
(int[] raw1, int[] raw2, Permutation p1, Permutation p2) SeePermutationFullBinaryOperator
for details of this method.void
cross
(Permutation c1, Permutation c2) Performs a crossover for an evolutionary algorithm, such that crossover forms two children from two parents.split()
Generates a functionally identical copy of this object, for use in multithreaded implementations of search algorithms.

Constructor Details

CycleCrossover
public CycleCrossover()Constructs a cycle crossover (CX) operator.


Method Details

cross
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 interfaceCrossoverOperator<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
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 theCopyable
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 interfaceSplittable<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
SeePermutationFullBinaryOperator
for details of this method. This method is not intended for direct usage. Use thecross(org.cicirello.permutations.Permutation, org.cicirello.permutations.Permutation)
method instead. Specified by:
apply
in interfacePermutationFullBinaryOperator
 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.
