- java.lang.Object
-
- org.cicirello.permutations.distance.CycleEditDistance
-
- All Implemented Interfaces:
NormalizedPermutationDistanceMeasurer,NormalizedPermutationDistanceMeasurerDouble,PermutationDistanceMeasurer,PermutationDistanceMeasurerDouble
public final class CycleEditDistance extends Object implements NormalizedPermutationDistanceMeasurer
Cycle edit distance is the minimum number of non-singleton permutation cycles necessary to transform permutation p1 into p2. If p1 equals p2, then this distance is 0. If p1 and p2 have a single permutation cycle, then this distance is clearly 1 since the inverse of that cycle will produce n fixed points. Otherwise, this distance is equal to 2 since it can be shown that at most 2 permutation cycle operations are necessary to transform any permutation of length n into any other. Cycle edit distance satisfies all of the metric properties.
Cycle edit 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 CycleEditDistance()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
-
-
-
-
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.
-
-