- java.lang.Object
-
- org.cicirello.permutations.distance.ReinsertionDistance
-
- All Implemented Interfaces:
NormalizedPermutationDistanceMeasurer,NormalizedPermutationDistanceMeasurerDouble,PermutationDistanceMeasurer,PermutationDistanceMeasurerDouble
public final class ReinsertionDistance extends Object implements NormalizedPermutationDistanceMeasurer
Reinsertion Distance:Reinsertion distance is the count of the number of removal/reinsertion operations needed to transform one permutation into the other.
This implementation utilizes the observation that the elements that must be removed and reinserted are exactly those elements that are not in the longest common subsequence.
Runtime: O(n lg n), where n is the permutation length.
Reinsertion distance more generally was described in:
V. A. Cicirello and R. Cernera, "Profiling the distance characteristics of mutation operators for permutation-based genetic algorithms," in Proceedings of the 26th FLAIRS Conference. AAAI Press, May 2013, pp. 46–51.However, in that paper, it was computed, in O(n^2) time, using an adaptation of string Edit Distance.
For description of computing it using the length of the longest common subsequence, see:
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.However, that paper used an O(n^2) time algorithm for longest common subsequence. This class has been updated to use a more efficient O(n lg n) algorithm for longest common subsequence. It is a version of Hunt et al's algorithm that has been optimized to assume permutations of the integers in [0, (n-1)] with unique elements. The original algorithm of Hunt et al was for general strings that could contain duplicates and which could consist of characters of any alphabet. In that more general case, O(n lg n) was the best case runtime. In our special case, O(n lg n) is worst case runtime.
See the following for complete details of Hunt et al's algorithm for longest common subsequence:
J.W. Hunt and T.G. Szymanski, "A fast algorithm for computing longest common subsequences," Communications of the ACM, 20(5):350-353, May, 1977.
-
-
Constructor Summary
Constructors Constructor Description ReinsertionDistance()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.
-
-