## Class SquaredDeviationDistance

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

```public final class SquaredDeviationDistance
extends Object
implements NormalizedPermutationDistanceMeasurer```
Squared Deviation Distance:

Squared Deviation distance is the sum of the squares of the positional deviations 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 squared deviations: 1^2 + 1^2 + 1^2 + 2^2 + 0^2 + 3^2 = 1 + 1 + 1 + 4 + 9 = 16.

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

Squared deviation distance is described in:
M. Sevaux and K. Sorensen, "Permutation distance measures for memetic algorithms with population management," The 6th Metaheuristics International Conference, August, 2005.

• ### Constructor Summary

Constructors
Constructor Description
`SquaredDeviationDistance()`
Constructs the distance measurer as specified in the class documentation.
• ### Method Summary

All Methods
Modifier and Type Method Description
`int` ```distance​(Permutation p1, Permutation p2)```
Measures the distance between two permutations.
`int` `max​(int length)`
Computes the maximum possible distance between permutations of a specified length.
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Methods inherited from interface org.cicirello.permutations.distance.NormalizedPermutationDistanceMeasurer

`maxf, normalizedDistance`
• ### Methods inherited from interface org.cicirello.permutations.distance.PermutationDistanceMeasurer

`distancef`
• ### Constructor Detail

• #### SquaredDeviationDistance

`public SquaredDeviationDistance()`
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.
Specified by:
`distance` in interface `PermutationDistanceMeasurer`
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.
Specified by:
`max` in interface `NormalizedPermutationDistanceMeasurer`
Parameters:
`length` - Permutation length.
Returns:
the maximum distance between a pair of permutations of the specified length.