java.lang.Object
org.cicirello.permutations.distance.CycleDistance
- All Implemented Interfaces:
NormalizedPermutationDistanceMeasurer,NormalizedPermutationDistanceMeasurerDouble,PermutationDistanceMeasurer,PermutationDistanceMeasurerDouble
Cycle distance is the count of the number of non-singleton permutation cycles between a pair of
permutations. Cycle distance is a semi-metric, satisfying all of the metric properties except for
the triangle inequality.
It 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
ConstructorsConstructorDescriptionConstructs the distance measurer as specified in the class documentation. -
Method Summary
Modifier and TypeMethodDescriptionintdistance(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, waitMethods inherited from interface org.cicirello.permutations.distance.NormalizedPermutationDistanceMeasurer
maxf, normalizedDistanceMethods inherited from interface org.cicirello.permutations.distance.PermutationDistanceMeasurer
distancef
-
Constructor Details
-
CycleDistance
public CycleDistance()Constructs the distance measurer as specified in the class documentation.
-
-
Method Details
-
distance
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.
-