Class DeviationDistance

  • All Implemented Interfaces:
    NormalizedPermutationDistanceMeasurer, NormalizedPermutationDistanceMeasurerDouble, PermutationDistanceMeasurer, PermutationDistanceMeasurerDouble

    public final class DeviationDistance
    extends Object
    Deviation Distance:

    Deviation distance is the sum of the positional deviation of the permutation elements. The positional deviation of an element is the difference in its location in the two permutations.

    For example, consider p1 = [0, 1, 2, 3, 4, 5] and p2 = [1, 0, 5, 2, 4, 3]. Element 0 is displaced by 1 position. Likewise for elements 1 and 2. Element 3 is displaced by 2 positions. Element 4 is in the same position in both. Element 5 is displaced by 3 positions.

    Sum the deviations: 1 + 1 + 1 + 2 + 0 + 3 = 8. And that is the distance.

    Runtime: O(n), where n is the permutation length.

    Deviation distance was introduced in:
    S. Ronald, "More distance functions for order-based encodings," in Proc. IEEE CEC. IEEE Press, 1998, pp. 558–563.

    • Constructor Detail

      • DeviationDistance

        public DeviationDistance()
        Constructs the distance measurer as specified in the class documentation.
    • Method Detail

      • distance

        public int distance​(Permutation p1,
                            Permutation p2)
        Measures the distance between two permutations.
        Parameters:
        p1 - first permutation
        p2 - second permutation
        Returns:
        distance between p1 and p2
        Throws:
        IllegalArgumentException - if p1.length() is not equal to p2.length().
      • max

        public int max​(int length)
        Description copied from interface: NormalizedPermutationDistanceMeasurer
        Computes the maximum possible distance between permutations of a specified length.
        Parameters:
        length - Permutation length.
        Returns:
        the maximum distance between a pair of permutations of the specified length.