- java.lang.Object
-
- org.cicirello.permutations.distance.KCycleDistance
-
- All Implemented Interfaces:
NormalizedPermutationDistanceMeasurer,NormalizedPermutationDistanceMeasurerDouble,PermutationDistanceMeasurer,PermutationDistanceMeasurerDouble
public final class KCycleDistance extends Object implements NormalizedPermutationDistanceMeasurer
K-Cycle distance is the count of the number of non-singleton permutation cycles of length at most K. Specifically, each non-singleton cycle contributes to the total distance the number of cycles of length at most K necessary to transform the cycle to all fixed points. K-cycle distance is a metric provided that K ≤ 4. However, if K > 4, it is only a semi-metric because it fails to satisfy the triangle inequality when K ≥ 5.
K-Cycle distance was introduced in the following article:
Vincent A. Cicirello. 2022. Cycle Mutation: Evolving Permutations via Cycle Induction, Applied Sciences, 12(11), Article 5506 (June 2022). doi:10.3390/app12115506
Runtime: O(n), where n is the permutation length.
-
-
Constructor Summary
Constructors Constructor Description KCycleDistance(int k)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.intmax(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
-
KCycleDistance
public KCycleDistance(int k)
Constructs the distance measurer as specified in the class documentation.- Parameters:
k- The maximum length cycle that is considered an atomic edit operation, such that k is greater than or equal to 2.- Throws:
IllegalArgumentException- if k is less than 2
-
-
Method Detail
-
distance
public int distance(Permutation p1, Permutation p2)
Measures the distance between two permutations.- Specified by:
distancein 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:NormalizedPermutationDistanceMeasurerComputes the maximum possible distance between permutations of a specified length.- Specified by:
maxin interfaceNormalizedPermutationDistanceMeasurer- Parameters:
length- Permutation length.- Returns:
- the maximum distance between a pair of permutations of the specified length.
-
-