- All Implemented Interfaces:
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
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 SummaryConstructorDescriptionConstructs a cycle crossover (CX) operator.
Method SummaryModifier and TypeMethodDescription
PermutationFullBinaryOperatorfor details of this method.
voidPerforms 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.
CycleCrossoverpublic CycleCrossover()Constructs a cycle crossover (CX) operator.
crossDescription copied from interface:
CrossoverOperatorPerforms 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.
splitpublic CycleCrossover split()Description copied from interface:
SplittableGenerates 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
Copyableinterface. 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.
PermutationFullBinaryOperatorfor 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.