- All Implemented Interfaces:
NormalizedPermutationDistanceMeasurer
,NormalizedPermutationDistanceMeasurerDouble
,PermutationDistanceMeasurer
,PermutationDistanceMeasurerDouble
Consider p1 = [0, 1, 2, 3, 4, 5] and p2 = [5, 1, 0, 2, 3, 4]. Element 0 is 2 positions displaced (as in deviation distance). Elements 2, 3, and 4 are a 1 position displaced (as in deviation distance). Element 1 is stationary. Element 5 is 1 position displaced (for Lee Distance) whereas for Deviation Distance it would be 5 positions displaced. For Lee distance, the displacement is the minimum of how far it is displaced in either of the two directions. In this case element 5 is at the right most end in p1 and left most end of p2, which as a cyclic structure are adjacent positions.
Runtime: O(n), where n is the permutation length.
Described in:
C. Lee, "Some properties of nonbinary error-correcting codes," in IRE Transactions on Information
Theory, vol. 4, no. 2, pp. 77-82, June 1958.
-
Constructor Summary
ConstructorDescriptionConstructs the distance measurer as specified in the class documentation. -
Method Summary
Modifier and TypeMethodDescriptionint
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 Details
-
LeeDistance
public LeeDistance()Constructs the distance measurer as specified in the class documentation.
-
-
Method Details
-
distance
Measures the distance between two permutations.- Specified by:
distance
in interfacePermutationDistanceMeasurer
- Parameters:
p1
- first permutationp2
- 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 interfaceNormalizedPermutationDistanceMeasurer
- Parameters:
length
- Permutation length.- Returns:
- the maximum distance between a pair of permutations of the specified length.
-