Skip to content

Commit bf85c7c

Browse files
authored
Merge pull request #118 from cicirello/refactor-interfaces
Refactor permutation and sequence distance interfaces and classes
2 parents 3c6eac3 + a19dfbe commit bf85c7c

32 files changed

+214
-395
lines changed

CHANGELOG.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,25 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## [Unreleased] - 2021-03-31
7+
## [Unreleased] - 2021-04-02
88

99
### Added
1010
* Added the `Permutation.Mechanic.set(Permutation, int[], int, int, int)` method.
1111

1212
### Changed
13+
* Refactored the SequenceDistanceMeasurer and SequenceDistanceMeasurerDouble interfaces
14+
into a hierarchy, eliminated an abstract base class made obsolete by that change, and
15+
changed all sequence distances in the library to use the new hierarchy. This is a non-breaking
16+
change, as the only thing removed was a package-private abstract class, and the
17+
change to the SequenceDistanceMeasurer interface was done in such a way that all inherited
18+
methods have default implementations.
19+
* Refactored the PermutationDistanceMeasurer, PermutationDistanceMeasurerDouble,
20+
NormalizedPermutationDistanceMeasurer, and NormalizedPermutationDistanceMeasurerDouble
21+
interfaces, and all of the classes that implement them, to move default implementations
22+
from an abstract base class into the appropriate subinterfaces in hierarchy. This is a
23+
non-breaking change, as the only thing removed was a package-private abstract class, and the
24+
changes to interfaces were done in such a way that all inherited methods have default
25+
implementations.
1326

1427
### Deprecated
1528

src/org/cicirello/permutations/distance/AbstractPermutationDistanceMeasurer.java

Lines changed: 0 additions & 61 deletions
This file was deleted.

src/org/cicirello/permutations/distance/AcyclicEdgeDistance.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242
* S. Ronald, "Distance functions for order-based encodings," in Proc. IEEE CEC. IEEE Press, 1997, pp. 49–54.</p>
4343
*
4444
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
45-
* @version 1.28.2021
45+
* @version 4.2.2021
4646
*/
47-
public final class AcyclicEdgeDistance extends AbstractPermutationDistanceMeasurer {
47+
public final class AcyclicEdgeDistance implements NormalizedPermutationDistanceMeasurer {
4848

4949
/**
5050
* Constructs the distance measurer as specified in the class documentation.

src/org/cicirello/permutations/distance/BlockInterchangeDistance.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
* <p>Runtime: O(n), where n is the permutation length.</p>
4141
*
4242
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
43-
* @version 1.28.2021
43+
* @version 4.2.2021
4444
*/
45-
public class BlockInterchangeDistance extends AbstractPermutationDistanceMeasurer {
45+
public class BlockInterchangeDistance implements NormalizedPermutationDistanceMeasurer {
4646

4747
/**
4848
* Constructs the distance measurer as specified in the class documentation.

src/org/cicirello/permutations/distance/CyclicEdgeDistance.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242
* S. Ronald, "Distance functions for order-based encodings," in Proc. IEEE CEC. IEEE Press, 1997, pp. 49–54.</p>
4343
*
4444
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
45-
* @version 1.28.2021
45+
* @version 4.2.2021
4646
*/
47-
public final class CyclicEdgeDistance extends AbstractPermutationDistanceMeasurer {
47+
public final class CyclicEdgeDistance implements NormalizedPermutationDistanceMeasurer {
4848

4949
/**
5050
* Constructs the distance measurer as specified in the class documentation.

src/org/cicirello/permutations/distance/CyclicIndependentDistance.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* the constructor.</p>
3333
*
3434
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
35-
* @version 1.28.2021
35+
* @version 4.2.2021
3636
*
3737
*/
3838
public final class CyclicIndependentDistance implements PermutationDistanceMeasurer {
@@ -68,19 +68,4 @@ public int distance(Permutation p1, Permutation p2) {
6868
}
6969
return result;
7070
}
71-
72-
/**
73-
* Measures the distance between two permutations, with cyclic independence:
74-
* distance = min_{i in [0,N)} distance(p1,rotate(p2,i))
75-
*
76-
* @param p1 first permutation
77-
* @param p2 second permutation
78-
* @return distance between p1 and p2
79-
* @throws IllegalArgumentException if p1.length() is not equal to p2.length().
80-
*/
81-
@Override
82-
public final double distancef(Permutation p1, Permutation p2) {
83-
return distance(p1,p2);
84-
}
85-
8671
}

src/org/cicirello/permutations/distance/CyclicRTypeDistance.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
* IEEE Transactions on Evolutionary Computation, 20(3):434-446, June 2016.</p>
4545
*
4646
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
47-
* @version 1.28.2021
47+
* @version 4.2.2021
4848
*/
49-
public final class CyclicRTypeDistance extends AbstractPermutationDistanceMeasurer {
49+
public final class CyclicRTypeDistance implements NormalizedPermutationDistanceMeasurer {
5050

5151
/**
5252
* Constructs the distance measurer as specified in the class documentation.

src/org/cicirello/permutations/distance/CyclicReversalIndependentDistance.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* the constructor.</p>
3434
*
3535
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
36-
* @version 1.28.2021
36+
* @version 4.2.2021
3737
*
3838
*/
3939
public final class CyclicReversalIndependentDistance implements PermutationDistanceMeasurer {
@@ -83,19 +83,4 @@ public int distance(Permutation p1, Permutation p2) {
8383
}
8484
return result;
8585
}
86-
87-
/**
88-
* Measures the distance between two permutations, with cyclic and reversal independence:
89-
* distance = min_{i in [0,N)} { distance(p1,rotate(p2,i)), distance(p1,rotate(reverse(p2),i)) }
90-
*
91-
* @param p1 first permutation
92-
* @param p2 second permutation
93-
* @return distance between p1 and p2
94-
* @throws IllegalArgumentException if p1.length() is not equal to p2.length().
95-
*/
96-
@Override
97-
public final double distancef(Permutation p1, Permutation p2) {
98-
return distance(p1,p2);
99-
}
100-
10186
}

src/org/cicirello/permutations/distance/DeviationDistance.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
* S. Ronald, "More distance functions for order-based encodings," in Proc. IEEE CEC. IEEE Press, 1998, pp. 558–563.</p>
4343
*
4444
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
45-
* @version 1.28.2021
45+
* @version 4.2.2021
4646
*
4747
*/
48-
public final class DeviationDistance extends AbstractPermutationDistanceMeasurer {
48+
public final class DeviationDistance implements NormalizedPermutationDistanceMeasurer {
4949

5050
/**
5151
* Constructs the distance measurer as specified in the class documentation.

src/org/cicirello/permutations/distance/DeviationDistanceNormalized.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@
4848
* Proc. IEEE CEC. IEEE Press, 1998, pp. 558–563.</p>
4949
*
5050
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
51-
* @version 1.28.2021
51+
* @version 4.2.2021
5252
*
5353
*/
54-
public final class DeviationDistanceNormalized implements PermutationDistanceMeasurerDouble, NormalizedPermutationDistanceMeasurerDouble {
54+
public final class DeviationDistanceNormalized implements NormalizedPermutationDistanceMeasurerDouble {
5555

5656
private DeviationDistance devDistance;
5757

@@ -81,17 +81,4 @@ public double maxf(int length) {
8181
if (length <= 1) return 0;
8282
return (length * length - (length & 1)) / (2.0 * (length-1));
8383
}
84-
85-
/**
86-
* {@inheritDoc}
87-
*
88-
* @throws IllegalArgumentException if p1.length() is not equal to p2.length().
89-
*/
90-
@Override
91-
public double normalizedDistance(Permutation p1, Permutation p2) {
92-
double m = maxf(p1.length());
93-
if (m == 0.0) return 0;
94-
return distancef(p1,p2) / m;
95-
}
96-
9784
}

0 commit comments

Comments
 (0)