Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,40 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased] - 2021-01-27
## [Unreleased] - 2021-01-30

### Added

### Changed
* Modified API documentation website (https://jpt.cicirello.org/) to improve browsing on mobile devices.

### Deprecated

### Removed

### Fixed

### CI/CD


## [2.3.0] - 2021-01-30

### Added
* Test cases added to improve test coverage.

### Changed
* Modified API documentation website (https://jpt.cicirello.org/) to improve browsing on mobile devices.
* Minor optimizations in Permutation class.

### Removed
* Moved the example programs to a new repository. They were previously found in directories examples and replication, both of which have been removed. All of the examples are now located in the repository: https://github.com/cicirello/jpt-examples.
* Removed jars of the library from the repo. These have been available from Maven Central, GitHub Packages, and GitHub Releases, for quite some time. No need to store in repo, and it is inefficient to do so.
* Removed the zip files generated by javadoc of the indexes for the api website. These are not needed for search functionality, as javadoc also stores and uses the js files contained in these zips. Later versions of javadoc no longer generate these. Also gitignored these to prevent future storage.

### Fixed
* Bug in Permutation.toString which was inserting an extra space at end.
* Added validation checking for all permutation distance measures validating same length permutations (except for EditDistance which can handle that case).
* Bug in ReversalDistance.max in case when permutation length is 2, and also added missing parameter validation.
* Minor bug fix in KendallTauSequenceDistance in the case of distance between arrays of floats.

### CI/CD
* Migrated build process from Ant to Maven, including GitHub workflows.
Expand Down
14 changes: 8 additions & 6 deletions src/org/cicirello/permutations/Permutation.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2005, 2010, 2014-2019 Vincent A. Cicirello, <https://www.cicirello.org/>.
* Copyright 2005, 2010, 2014-2021 Vincent A. Cicirello, <https://www.cicirello.org/>.
*
* This file is part of JavaPermutationTools (https://jpt.cicirello.org/).
*
Expand Down Expand Up @@ -38,8 +38,7 @@
* manipulate permutations in a variety of ways.
*
* @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>
* @version 9.23.2019
* @since 1.0
* @version 1.28.2021
*/
public final class Permutation implements Serializable, Iterable<Permutation>, Copyable<Permutation> {

Expand Down Expand Up @@ -777,7 +776,7 @@ public void removeAndInsert(int i, int size, int j) {
System.arraycopy(permutation, j, temp, 0, i-j);
System.arraycopy(permutation, i, permutation, j, size);
System.arraycopy(temp, 0, permutation, j+size, i-j);
} else if (i < j) {
} else { // Condition is implied by above: if (i < j)
int[] temp = new int[size];
System.arraycopy(permutation, i, temp, 0, size);
System.arraycopy(permutation, i+size, permutation, i, j-i);
Expand Down Expand Up @@ -828,8 +827,11 @@ public Iterator<Permutation> iterator() {
@Override
public String toString() {
String permS = "";
for (int i : permutation) {
permS += (i + " ");
if (permutation.length > 0) {
permS += permutation[0];
for (int i = 1; i < permutation.length; i++) {
permS += " " + permutation[i];
}
}
return permS;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010, 2015, 2017-2019 Vincent A. Cicirello, <https://www.cicirello.org/>.
* Copyright 2010, 2015, 2017-2021 Vincent A. Cicirello, <https://www.cicirello.org/>.
*
* This file is part of JavaPermutationTools (https://jpt.cicirello.org/).
*
Expand Down Expand Up @@ -27,30 +27,30 @@
* where distance is an integer value.
*
* @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>
* @version 1.19.6.12
* @since 1.0
* @version 1.28.2021
*
*/
abstract class AbstractPermutationDistanceMeasurer implements PermutationDistanceMeasurer, NormalizedPermutationDistanceMeasurer {

/**
* {@inheritDoc}
*
* @throws IllegalArgumentException if p1.length() is not equal to p2.length().
*/
@Override
public final double distancef(Permutation p1, Permutation p2) {
return distance(p1,p2);
}

/**
* {@inheritDoc}
*/
@Override
public final double maxf(int length) {
return max(length);
}

/**
* {@inheritDoc}
*
* @throws IllegalArgumentException if p1.length() is not equal to p2.length().
*/
@Override
public final double normalizedDistance(Permutation p1, Permutation p2) {
Expand Down
25 changes: 12 additions & 13 deletions src/org/cicirello/permutations/distance/AcyclicEdgeDistance.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2019 Vincent A. Cicirello, <https://www.cicirello.org/>.
* Copyright 2014-2021 Vincent A. Cicirello, <https://www.cicirello.org/>.
*
* This file is part of JavaPermutationTools (https://jpt.cicirello.org/).
*
Expand Down Expand Up @@ -42,8 +42,7 @@
* S. Ronald, "Distance functions for order-based encodings," in Proc. IEEE CEC. IEEE Press, 1997, pp. 49–54.</p>
*
* @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>
* @version 1.19.6.12
* @since 1.0
* @version 1.28.2021
*/
public final class AcyclicEdgeDistance extends AbstractPermutationDistanceMeasurer {

Expand All @@ -54,28 +53,28 @@ public AcyclicEdgeDistance() {}

/**
* {@inheritDoc}
*
* @throws IllegalArgumentException if p1.length() is not equal to p2.length().
*/
@Override
public int distance(Permutation p1, Permutation p2) {
if (p1.length() != p2.length()) {
throw new IllegalArgumentException("Permutations must be the same length");
}
int countNonSharedEdges = 0;
int L1 = p1.length();
int L2 = p2.length();
if (L1==L2 && L1==0) return 0;
int[] successors2 = new int[L2];
for (int i = 0; i < L2 - 1; i++) {
if (p1.length()==0) return 0;
int[] successors2 = new int[p2.length()];
for (int i = 0; i < p2.length() - 1; i++) {
successors2[p2.get(i)] = p2.get(i+1);
}
successors2[p2.get(L2-1)] = -1;
successors2[p2.get(p2.length()-1)] = -1;

for (int i = 0; i < L1 - 1; i++) {
for (int i = 0; i < p1.length() - 1; i++) {
if (p1.get(i+1) != successors2[p1.get(i)] && p1.get(i) != successors2[p1.get(i+1)]) countNonSharedEdges++;
}
return countNonSharedEdges;
}

/**
* {@inheritDoc}
*/
@Override
public int max(int length) {
if (length <= 2) return 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Vincent A. Cicirello, <https://www.cicirello.org/>.
* Copyright 2019, 2021 Vincent A. Cicirello, <https://www.cicirello.org/>.
*
* This file is part of JavaPermutationTools (https://jpt.cicirello.org/).
*
Expand Down Expand Up @@ -40,8 +40,7 @@
* <p>Runtime: O(n), where n is the permutation length.</p>
*
* @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>
* @version 7.26.19
* @since 2.0
* @version 1.28.2021
*/
public class BlockInterchangeDistance extends AbstractPermutationDistanceMeasurer {

Expand All @@ -52,9 +51,14 @@ public BlockInterchangeDistance() {}

/**
* {@inheritDoc}
*
* @throws IllegalArgumentException if p1.length() is not equal to p2.length().
*/
@Override
public int distance(Permutation p1, Permutation p2) {
if (p1.length() != p2.length()) {
throw new IllegalArgumentException("Permutations must be the same length");
}
int[] inv2 = p2.getInverse();
int[] p = new int[inv2.length+2];
int[] inv = new int[p.length];
Expand All @@ -81,9 +85,6 @@ public int distance(Permutation p1, Permutation p2) {
return (p1.length()+1-cycles)/2;
}

/**
* {@inheritDoc}
*/
@Override
public int max(int length) {
return length >> 1;
Expand Down
26 changes: 12 additions & 14 deletions src/org/cicirello/permutations/distance/CyclicEdgeDistance.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2019 Vincent A. Cicirello, <https://www.cicirello.org/>.
* Copyright 2014-2021 Vincent A. Cicirello, <https://www.cicirello.org/>.
*
* This file is part of JavaPermutationTools (https://jpt.cicirello.org/).
*
Expand Down Expand Up @@ -42,8 +42,7 @@
* S. Ronald, "Distance functions for order-based encodings," in Proc. IEEE CEC. IEEE Press, 1997, pp. 49–54.</p>
*
* @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>
* @version 1.19.6.12
* @since 1.0
* @version 1.28.2021
*/
public final class CyclicEdgeDistance extends AbstractPermutationDistanceMeasurer {

Expand All @@ -54,28 +53,27 @@ public CyclicEdgeDistance() {}

/**
* {@inheritDoc}
*
* @throws IllegalArgumentException if p1.length() is not equal to p2.length().
*/
@Override
public int distance(Permutation p1, Permutation p2) {
if (p1.length() != p2.length()) {
throw new IllegalArgumentException("Permutations must be the same length");
}
int countNonSharedEdges = 0;
int L1 = p1.length();
int L2 = p2.length();

int[] successors2 = new int[L2];
for (int i = 0; i < L2; i++) {
successors2[p2.get(i)] = p2.get((i+1) % L2);
int[] successors2 = new int[p2.length()];
for (int i = 0; i < successors2.length; i++) {
successors2[p2.get(i)] = p2.get((i+1) % successors2.length);
}

for (int i = 0; i < L1; i++) {
if (p1.get((i+1) % L1) != successors2[p1.get(i)] && p1.get(i) != successors2[p1.get((i+1) % L1)]) countNonSharedEdges++;
for (int i = 0; i < successors2.length; i++) {
if (p1.get((i+1) % successors2.length) != successors2[p1.get(i)] && p1.get(i) != successors2[p1.get((i+1) % successors2.length)]) countNonSharedEdges++;
}

return countNonSharedEdges;
}

/**
* {@inheritDoc}
*/
@Override
public int max(int length) {
if (length <= 3) return 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019 Vincent A. Cicirello, <https://www.cicirello.org/>.
* Copyright 2018-2021 Vincent A. Cicirello, <https://www.cicirello.org/>.
*
* This file is part of JavaPermutationTools (https://jpt.cicirello.org/).
*
Expand Down Expand Up @@ -32,8 +32,7 @@
* the constructor.</p>
*
* @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>
* @version 1.19.6.12
* @since 1.0
* @version 1.28.2021
*
*/
public final class CyclicIndependentDistance implements PermutationDistanceMeasurer {
Expand All @@ -56,6 +55,7 @@ public CyclicIndependentDistance(PermutationDistanceMeasurer d) {
* @param p1 first permutation
* @param p2 second permutation
* @return distance between p1 and p2
* @throws IllegalArgumentException if p1.length() is not equal to p2.length().
*/
@Override
public int distance(Permutation p1, Permutation p2) {
Expand All @@ -70,7 +70,13 @@ public int distance(Permutation p1, Permutation p2) {
}

/**
* {@inheritDoc}
* Measures the distance between two permutations, with cyclic independence:
* distance = min_{i in [0,N)} distance(p1,rotate(p2,i))
*
* @param p1 first permutation
* @param p2 second permutation
* @return distance between p1 and p2
* @throws IllegalArgumentException if p1.length() is not equal to p2.length().
*/
@Override
public final double distancef(Permutation p1, Permutation p2) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019 Vincent A. Cicirello, <https://www.cicirello.org/>.
* Copyright 2018-2021 Vincent A. Cicirello, <https://www.cicirello.org/>.
*
* This file is part of JavaPermutationTools (https://jpt.cicirello.org/).
*
Expand Down Expand Up @@ -32,8 +32,7 @@
* the constructor.</p>
*
* @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>
* @version 1.19.5.10
* @since 1.0
* @version 1.28.2021
*
*/
public final class CyclicIndependentDistanceDouble implements PermutationDistanceMeasurerDouble {
Expand All @@ -56,6 +55,7 @@ public CyclicIndependentDistanceDouble(PermutationDistanceMeasurerDouble d) {
* @param p1 first permutation
* @param p2 second permutation
* @return distance between p1 and p2
* @throws IllegalArgumentException if p1.length() is not equal to p2.length().
*/
@Override
public double distancef(Permutation p1, Permutation p2) {
Expand Down
26 changes: 12 additions & 14 deletions src/org/cicirello/permutations/distance/CyclicRTypeDistance.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010, 2014-2015, 2017-2019 Vincent A. Cicirello, <https://www.cicirello.org/>.
* Copyright 2010, 2014-2015, 2017-2021 Vincent A. Cicirello, <https://www.cicirello.org/>.
*
* This file is part of JavaPermutationTools (https://jpt.cicirello.org/).
*
Expand Down Expand Up @@ -44,8 +44,7 @@
* IEEE Transactions on Evolutionary Computation, 20(3):434-446, June 2016.</p>
*
* @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>
* @version 1.19.6.12
* @since 1.0
* @version 1.28.2021
*/
public final class CyclicRTypeDistance extends AbstractPermutationDistanceMeasurer {

Expand All @@ -56,27 +55,26 @@ public CyclicRTypeDistance() {}

/**
* {@inheritDoc}
*
* @throws IllegalArgumentException if p1.length() is not equal to p2.length().
*/
@Override
public int distance(Permutation p1, Permutation p2) {
if (p1.length() != p2.length()) {
throw new IllegalArgumentException("Permutations must be the same length");
}
int countNonSharedEdges = 0;
int L1 = p1.length();
int L2 = p2.length();

int[] successors2 = new int[L2];
for (int i = 0; i < L2; i++) {
successors2[p2.get(i)] = p2.get((i+1) % L2);
int[] successors2 = new int[p2.length()];
for (int i = 0; i < successors2.length; i++) {
successors2[p2.get(i)] = p2.get((i+1) % successors2.length);
}

for (int i = 0; i < L1; i++) {
if (p1.get((i+1) % L1) != successors2[p1.get(i)]) countNonSharedEdges++;
for (int i = 0; i < successors2.length; i++) {
if (p1.get((i+1) % successors2.length) != successors2[p1.get(i)]) countNonSharedEdges++;
}
return countNonSharedEdges;
}

/**
* {@inheritDoc}
*/
@Override
public int max(int length) {
if (length <= 2) return 0;
Expand Down
Loading