public final class ReinsertionDistance extends Object
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 and Description |
|---|
ReinsertionDistance()
Constructs the distance measurer as specified in the class documentation.
|
| Modifier and Type | Method and Description |
|---|---|
int |
distance(Permutation p1,
Permutation p2)
Measures the distance between two permutations.
|
double |
distancef(Permutation p1,
Permutation p2)
Measures the distance between two permutations
|
int |
max(int length)
Computes the maximum possible distance between permutations
of a specified length.
|
double |
maxf(int length)
Computes the maximum possible distance between permutations
of a specified length.
|
double |
normalizedDistance(Permutation p1,
Permutation p2)
Measures the distance between two permutations, normalized to the interval [0.0, 1.0].
|
public ReinsertionDistance()
public int distance(Permutation p1, Permutation p2)
p1 - first permutationp2 - second permutationpublic int max(int length)
length - Permutation length.public final double distancef(Permutation p1, Permutation p2)
distancef in interface PermutationDistanceMeasurerDoublep1 - first permutationp2 - second permutationpublic final double maxf(int length)
maxf in interface NormalizedPermutationDistanceMeasurerDoublelength - Permutation length.public final double normalizedDistance(Permutation p1, Permutation p2)
Measures the distance between two permutations, normalized to the interval [0.0, 1.0].
normalizedDistance in interface NormalizedPermutationDistanceMeasurerDoublep1 - first permutationp2 - second permutationCopyright © 2005-2020 Vincent A. Cicirello. All rights reserved.