Class LeeDistance
- java.lang.Object
-
- org.cicirello.permutations.distance.LeeDistance
-
- All Implemented Interfaces:
NormalizedPermutationDistanceMeasurer,NormalizedPermutationDistanceMeasurerDouble,PermutationDistanceMeasurer,PermutationDistanceMeasurerDouble
public final class LeeDistance extends Object
Lee Distance:Lee Distance is closely related to deviation distance. However, Lee Distance considers the permutation to be a cyclic structure when computing positional deviations. That is, an element's deviation between permutations is the minimum of its deviation to the right or to the left (wrapping around ends cyclicly).
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
Constructors Constructor Description LeeDistance()Constructs the distance measurer as specified in the class documentation.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intdistance(Permutation p1, Permutation p2)Measures the distance between two permutations.doubledistancef(Permutation p1, Permutation p2)Measures the distance between two permutationsintmax(int length)Computes the maximum possible distance between permutations of a specified length.doublemaxf(int length)Computes the maximum possible distance between permutations of a specified length.doublenormalizedDistance(Permutation p1, Permutation p2)Measures the distance between two permutations, normalized to the interval [0.0, 1.0].
-
-
-
Method Detail
-
distance
public int distance(Permutation p1, Permutation p2)
Measures the distance between two permutations.- 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:NormalizedPermutationDistanceMeasurerComputes 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.
-
distancef
public final double distancef(Permutation p1, Permutation p2)
Measures the distance between two permutations- Specified by:
distancefin interfacePermutationDistanceMeasurerDouble- Parameters:
p1- first permutationp2- second permutation- Returns:
- distance between p1 and p2
- Throws:
IllegalArgumentException- if p1.length() is not equal to p2.length().
-
maxf
public final double maxf(int length)
Description copied from interface:NormalizedPermutationDistanceMeasurerDoubleComputes the maximum possible distance between permutations of a specified length.- Specified by:
maxfin interfaceNormalizedPermutationDistanceMeasurerDouble- Parameters:
length- Permutation length.- Returns:
- the maximum distance between a pair of permutations of the specified length.
-
normalizedDistance
public final double normalizedDistance(Permutation p1, Permutation p2)
Measures the distance between two permutations, normalized to the interval [0.0, 1.0].
- Specified by:
normalizedDistancein interfaceNormalizedPermutationDistanceMeasurerDouble- Parameters:
p1- first permutationp2- second permutation- Returns:
- distance between p1 and p2 normalized to the interval [0.0, 1.0]
- Throws:
IllegalArgumentException- if p1.length() is not equal to p2.length().
-
-