Class InterchangeDistance
- java.lang.Object
-
- org.cicirello.permutations.distance.InterchangeDistance
-
- All Implemented Interfaces:
NormalizedPermutationDistanceMeasurer,NormalizedPermutationDistanceMeasurerDouble,PermutationDistanceMeasurer,PermutationDistanceMeasurerDouble
public final class InterchangeDistance extends Object
Interchange Distance:Interchange distance is the minimum number of swaps necessary to transform one permutation into the other.
Interchange distance is computed efficiently by counting the number of permutation cycles between the permutations. A permutation cycle of length k is transformed into k fixed points with k − 1 swaps (a fixed point is a cycle of length 1).
Runtime: O(n), where n is the permutation length.
Computing Interchange distance using cycle lengths is described in:
V.A. Cicirello, "The Permutation in a Haystack Problem and the Calculus of Search Landscapes," IEEE Transactions on Evolutionary Computation, 20(3):434-446, June 2016.
-
-
Constructor Summary
Constructors Constructor Description InterchangeDistance()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().
-
-