All Implemented Interfaces:
PermutationBinaryOperator, Splittable<CrossoverOperator<Permutation>>, CrossoverOperator<Permutation>

public final class EdgeRecombination extends Object implements CrossoverOperator<Permutation>, PermutationBinaryOperator
Implementation of the Edge Recombination operator, a crossover operator for permutations. Edge Recombination assumes that the permutations represent a cyclic sequence of edges. That is, if 3 follows 5 in the permutation, then that corresponds to an undirected edge between 3 and 5. Given this assumption, it is suitable for problems where permutations do represent a sequence of edges such as the traveling salesperson. However, the Chips-n-Salsa library does not limit its use to such problems, and you can use it on any problem with solutions represented as permutations.

Imagine a hypothetical graph consisting of the n elements of a permutation of length n as the n vertexes of the graph. The edge set begins with the n adjacent pairs from parent p1. For example, if p1 = [3, 0, 2, 1, 4], then the edge set of this graph is initialized with the undirected edges: (3, 0), (0, 2), (2, 1), (1, 4), and (4, 3). Now add to that edge set any edges, determined in a similar way, from parent p2, provided it doesn't already contain the relevant edge. Consider p2 = [4, 3, 2, 1, 0]. Thus, we would add (3, 2), (1, 0),and (0, 4) to get an undirected edge set of: { (3, 0), (0, 2), (2, 1), (1, 4), (4, 3), (3, 2), (1, 0), (0, 4) }. Child c1 is initialized with the first element of parent p1, in this example p1 = [3]. We then examine the adjacent vertexes to the most recently added element. The 3 is adjacent to 0, 4, and 2. We'll pick one of these to add in the next spot of the permutation. We'll pick the one that is adjacent to the fewest elements not yet used. 0 is adjacent to 2, 1, and 4. 4 is adjacent to 1 and 0. 2 is adjacent to 0 and 1. When there is a tie, such as here with the 2 and 4, the tie is broken at random. Imagine that the random tie breaker gave us 4. We now have p1 = [3, 4]. We now consider the adjacent elements of 4 that are not yet in the permutation, which in this case is 0 and 1. We pick the one with the fewest adjacent elements not yet in the permutation. The 0 is adjacent to 1 and 2. The 1 is adjacent to 0 and 2. Since we have a tie, we pick randomly. Consider for the example that the random choice have us 1. We now have p1 = [3, 4, 1]. We now examine the adjacent elements of 1 that are not yet in the permutation. The 1 is adjacent to 0 and 2. We pick the one that is adjacent to the fewest not yet used elements. They are the only two remaining and they are adjacent to each other. We thus pick randomly. Consider that the random element is 0, and we now have p1 = [3, 4, 1, 0]. And at this point, there is only one element left, so the final permutation is p1 = [3, 4, 1, 0, 2]. We can form the other child in a similar way, but initialized with the first element of the other parent.

The Edge Recombination operator uses a special data structure that its creators, Whitley et al, call an edge map for efficient implementation.

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

The edge recombination operator was introduced in the following paper:
D. Whitley, T. Starkweather, and D. Fuquay. Scheduling Problems and Traveling Salesmen: The Genetic Edge Recombination Operator. Proceedings of the International Conference on Genetic Algorithms, 1989, pp. 133-140.

  • Constructor Details

    • EdgeRecombination

      public EdgeRecombination()
      Constructs a edge recombination 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>
      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 EdgeRecombination 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>>
      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)
      See PermutationBinaryOperator 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 PermutationBinaryOperator
      raw1 - The raw representation of the first permutation.
      raw2 - The raw representation of the second permutation.