Commit b522b109 authored by Fabian Becker's avatar Fabian Becker

Merge branch '61-terminators' into 'master'

Tests for Terminators



See merge request !12
parents b120a486 d6cd41b5
Pipeline #104 passed with stage
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'com.bmuschko.nexus'
group = 'eva2'
group = 'de.openea'
version = '2.2.0'
description = """EvA2"""
......@@ -25,9 +26,62 @@ task fatJar(type: Jar) {
repositories {
mavenCentral()
}
dependencies {
compile group: 'javax.help', name: 'javahelp', version: '2.0.05'
compile group: 'org.yaml', name: 'snakeyaml', version: '1.16'
compile group: 'gov.nist.math', name: 'jama', version: '1.0.3'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.mockito', name: 'mockito-core', version: '1.+'
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.bmuschko:gradle-nexus-plugin:2.3.1'
}
}
modifyPom {
project {
name 'EvA2'
description 'Gradle plugin that provides tasks for configuring and uploading artifacts to Sonatype Nexus.'
url 'http://www.ra.cs.uni-tuebingen.de/software/eva2/'
inceptionYear '2008'
scm {
url 'https://gitlab.cs.uni-tuebingen.de/eva2/eva2/'
connection 'scm:https://gitlab.cs.uni-tuebingen.de/eva2/eva2/.git'
developerConnection 'scm:https://gitlab.cs.uni-tuebingen.de/eva2/eva2/.git'
}
licenses {
license {
name 'GNU Lesser General Public License, Version 3.0'
url 'http://www.gnu.org/licenses/lgpl-3.0.html'
distribution 'repo'
}
}
developers {
developer {
id 'halfdan'
name 'Fabian Becker'
email 'halfdan@xnorfz.de'
}
}
}
}
extraArchive {
sources = true
tests = true
javadoc = true
}
nexus {
repositoryUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2'
snapshotRepositoryUrl = 'https://oss.sonatype.org/content/repositories/snapshots'
}
......@@ -19,7 +19,7 @@ import java.util.Comparator;
* @see AbstractEAIndividual#isDominatingFitness(double[], double[])
*/
@eva2.util.annotation.Description(value = "A comparator class for general EA individuals. Compares individuals based on their fitness in context of minimization.")
public class EAIndividualComparator implements Comparator<Object>, Serializable {
public class EAIndividualComparator implements Comparator<AbstractEAIndividual>, Serializable {
// flag whether a data field should be used.
private String indyDataKey = "";
private int fitCriterion = -1;
......@@ -122,7 +122,7 @@ public class EAIndividualComparator implements Comparator<Object>, Serializable
* @return -1 if the first is dominant, 1 if the second is dominant, otherwise 0
*/
@Override
public int compare(Object o1, Object o2) {
public int compare(AbstractEAIndividual o1, AbstractEAIndividual o2) {
boolean o1domO2, o2domO1;
if (preferFeasible) { // check constraint violation first?
......
......@@ -237,10 +237,6 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
this.firstindex = firstindex;
}
/************************************************************************************
* AbstractEAIndividual methods
*/
/**
* This method will initialize the individual with a given value for the
* phenotype.
......@@ -305,7 +301,7 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
}
public double[] mapMatrixToVector(double[][] matrix) {
public static double[] mapMatrixToVector(double[][] matrix) {
int sumentries = 0;
for (int i = 0; i < matrix.length; i++) {
sumentries += matrix[i].length;
......@@ -321,7 +317,7 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
return res;
}
public double[][] mapVectorToMatrix(double[] vector, int[] sizes) {
public static double[][] mapVectorToMatrix(double[] vector, int[] sizes) {
double[][] matrix = new double[sizes.length][];
int counter = 0;
for (int i = 0; i < sizes.length; i++) {
......@@ -353,8 +349,6 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
}
}
}
}
/**
......
......@@ -9,7 +9,7 @@ import java.util.Comparator;
* Compare two AbstractEAIndividuals by their distance to a reference individual.
* Usable to sort by a distance.
*/
public class IndividualDistanceComparator implements Comparator<Object>, Serializable {
public class IndividualDistanceComparator implements Comparator<AbstractEAIndividual>, Serializable {
private AbstractEAIndividual refIndy = null;
private InterfaceDistanceMetric distMetric = null;
......@@ -30,9 +30,9 @@ public class IndividualDistanceComparator implements Comparator<Object>, Seriali
}
@Override
public int compare(Object o1, Object o2) {
double d1 = distMetric.distance((AbstractEAIndividual) o1, refIndy);
double d2 = distMetric.distance((AbstractEAIndividual) o2, refIndy);
public int compare(AbstractEAIndividual o1, AbstractEAIndividual o2) {
double d1 = distMetric.distance(o1, refIndy);
double d2 = distMetric.distance(o2, refIndy);
if (d1 == d2) {
return 0;
......
package eva2.optimization.individuals;
import eva2.tools.EVAERROR;
import eva2.util.annotation.Parameter;
import java.io.Serializable;
import java.util.Comparator;
......@@ -10,7 +11,7 @@ import java.util.Comparator;
*
* @author mkron
*/
public class IndividualWeightedFitnessComparator implements Comparator<Object>, Serializable {
public class IndividualWeightedFitnessComparator implements Comparator<AbstractEAIndividual>, Serializable {
/**
* Generated serial version identifier
*/
......@@ -75,12 +76,12 @@ public class IndividualWeightedFitnessComparator implements Comparator<Object>,
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
@Override
public int compare(Object o1, Object o2) {
double[] f1 = ((AbstractEAIndividual) o1).getFitness();
double[] f2 = ((AbstractEAIndividual) o2).getFitness();
public int compare(AbstractEAIndividual o1, AbstractEAIndividual o2) {
double[] f1 = o1.getFitness();
double[] f2 = o2.getFitness();
double score1 = calcScore(f1);
double score2 = calcScore(f2);
double score1 = calculateScore(f1);
double score2 = calculateScore(f2);
if (score1 < score2) {
return -1;
......@@ -95,7 +96,7 @@ public class IndividualWeightedFitnessComparator implements Comparator<Object>,
* @param f
* @return
*/
private double calcScore(double[] f) {
private double calculateScore(double[] f) {
if (f == null || fitWeights == null) {
throw new RuntimeException("Error, missing information in " + this.getClass());
}
......@@ -117,9 +118,9 @@ public class IndividualWeightedFitnessComparator implements Comparator<Object>,
* @param indy
* @return
*/
public double calcScore(AbstractEAIndividual indy) {
public double calculateScore(AbstractEAIndividual indy) {
double[] f = indy.getFitness();
return calcScore(f);
return calculateScore(f);
}
/**
......@@ -133,6 +134,7 @@ public class IndividualWeightedFitnessComparator implements Comparator<Object>,
}
}
@Parameter(description = "Weights of the fitness values in the linear combination")
public void setFitWeights(double[] fitWeights) {
this.fitWeights = fitWeights;
}
......@@ -140,23 +142,4 @@ public class IndividualWeightedFitnessComparator implements Comparator<Object>,
public double[] getFitWeights() {
return fitWeights;
}
public String fitWeightsTipText() {
return "Weights of the fitness values in the linear combination";
}
// public static void main(String[] args) {
// TF1Problem prob = new TF1Problem();
// Population pop = new Population(10);
// prob.initializePopulation(pop);
// prob.evaluate(pop);
// System.out.println(pop.getStringRepresentation());
// System.out.println("***");
// IndividualWeightedFitnessComparator wfComp = new IndividualWeightedFitnessComparator(new double[]{0.5,0.5});
// System.out.println("***"); System.out.println(pop.getSortedPop(wfComp).getStringRepresentation());
// wfComp.setFitWeights(new double[] {0.1, 0.9});
// System.out.println("***"); System.out.println(pop.getSortedPop(wfComp).getStringRepresentation());
// wfComp.setFitWeights(new double[] {0.9, 0.1});
// System.out.println("***"); System.out.println(pop.getSortedPop(wfComp).getStringRepresentation());
// }
}
......@@ -52,7 +52,7 @@ public class ArchivingNSGAIISMeasure extends ArchivingNSGAII {
public void calculateCrowdingDistance(Population front) {
Object[] frontArray = front.toArray();
AbstractEAIndividual[] frontArray = front.toArray(new AbstractEAIndividual[front.size()]);
boolean[] assigned = new boolean[frontArray.length];
double[] v = new double[frontArray.length];
......@@ -68,8 +68,8 @@ public class ArchivingNSGAIISMeasure extends ArchivingNSGAII {
Arrays.sort(frontArray, new EAIndividualComparator(0));
((AbstractEAIndividual) frontArray[0]).putData("HyperCube", Double.MAX_VALUE); //die beiden aussen bekommen maximal wert als measure
((AbstractEAIndividual) frontArray[frontArray.length - 1]).putData("HyperCube", Double.MAX_VALUE);
frontArray[0].putData("HyperCube", Double.MAX_VALUE); //die beiden aussen bekommen maximal wert als measure
frontArray[frontArray.length - 1].putData("HyperCube", Double.MAX_VALUE);
v[0] = Double.MAX_VALUE;
v[frontArray.length - 1] = Double.MAX_VALUE;
......
......@@ -4,6 +4,7 @@ import eva2.optimization.individuals.AbstractEAIndividual;
import eva2.tools.EVAERROR;
import eva2.tools.math.Mathematics;
import eva2.util.annotation.Description;
import eva2.util.annotation.Parameter;
import java.io.Serializable;
......@@ -19,8 +20,7 @@ import java.io.Serializable;
public class DoubleIntegralMetric implements InterfaceDistanceMetric, Serializable {
boolean oneNormed = true; // if true, the vectors are normed to unity sum before comparison.
public DoubleIntegralMetric() {
}
public DoubleIntegralMetric() {}
public DoubleIntegralMetric(boolean normed) {
oneNormed = normed;
......@@ -35,10 +35,8 @@ public class DoubleIntegralMetric implements InterfaceDistanceMetric, Serializab
public double distance(AbstractEAIndividual indy1, AbstractEAIndividual indy2) {
double[] dIndy1 = null, dIndy2 = null;
if (dIndy1 == null || dIndy2 == null) {
dIndy1 = AbstractEAIndividual.getDoublePositionShallow(indy1);
dIndy2 = AbstractEAIndividual.getDoublePositionShallow(indy2);
}
dIndy1 = AbstractEAIndividual.getDoublePositionShallow(indy1);
dIndy2 = AbstractEAIndividual.getDoublePositionShallow(indy2);
if (oneNormed) {
double l1 = Mathematics.sum(dIndy1);
......@@ -53,9 +51,8 @@ public class DoubleIntegralMetric implements InterfaceDistanceMetric, Serializab
}
double sum1 = 0, sum2 = 0;
double tmpDiff = 0, sqrDiffSum = 0;
// System.out.println(Mathematics.sum(dIndy1));
// System.out.println(Mathematics.sum(dIndy2));
double tmpDiff, sqrDiffSum = 0;
for (int i = 0; (i < dIndy1.length) && (i < dIndy2.length); i++) {
sum1 += dIndy1[i];
sum2 += dIndy2[i];
......@@ -73,12 +70,8 @@ public class DoubleIntegralMetric implements InterfaceDistanceMetric, Serializab
return oneNormed;
}
@Parameter(description = "If true, both vectors are normed to unity sum before comparison.")
public void setOneNormed(boolean normedByLength) {
this.oneNormed = normedByLength;
}
public String oneNormedTipText() {
return "If true, both vectors are normed to unity sum before comparison.";
}
}
......@@ -13,15 +13,11 @@ import java.util.BitSet;
@Description("This is a genotype based distance metric suited for binary data. The hamming distance is computed and normalized by chromosome length.")
public class GenotypeMetricBitSet implements InterfaceDistanceMetric, java.io.Serializable {
public GenotypeMetricBitSet() {
}
public GenotypeMetricBitSet(GenotypeMetricBitSet a) {
}
public GenotypeMetricBitSet() {}
@Override
public Object clone() {
return new GenotypeMetricBitSet(this);
return new GenotypeMetricBitSet();
}
/**
......
......@@ -3,6 +3,7 @@ package eva2.optimization.operator.distancemetric;
import eva2.gui.BeanInspector;
import eva2.optimization.individuals.*;
import eva2.tools.math.Mathematics;
import eva2.util.annotation.Description;
import java.util.BitSet;
......@@ -15,15 +16,11 @@ public class PhenotypeMetric implements InterfaceDistanceMetric, java.io.Seriali
private static PhenotypeMetric pMetric = null;
private static GenotypeMetricBitSet bitMetric = null;
public PhenotypeMetric() {
}
public PhenotypeMetric(PhenotypeMetric a) {
}
public PhenotypeMetric() {}
@Override
public Object clone() {
return new PhenotypeMetric(this);
return new PhenotypeMetric();
}
private static int min(int a, int b, int c) {
......@@ -109,7 +106,6 @@ public class PhenotypeMetric implements InterfaceDistanceMetric, java.io.Seriali
r2 = ((InterfaceDataTypeInteger) indy2).getIntRange();
for (int i = 0; (i < d1.length) && (i < d2.length); i++) {
tmpResult += Math.pow(((d1[i] - r1[i][0]) / ((double) (r1[i][1] - r1[i][0]))) - ((d2[i] - r2[i][0]) / ((double) (r2[i][1] - r2[i][0]))), 2);
//tmpResult += Math.abs(d1[i] - d2[i])/((double)(r1[i][1]-r1[i][0]));
}
result += Math.sqrt(tmpResult);
}
......@@ -130,7 +126,6 @@ public class PhenotypeMetric implements InterfaceDistanceMetric, java.io.Seriali
if ((indy1 instanceof InterfaceDataTypePermutation) && (indy2 instanceof InterfaceDataTypePermutation)) {
int[] dIndy1, dIndy2;
String s1 = "", s2 = "";
// double tmpResult = 0;
for (int p = 0; p < ((InterfaceDataTypePermutation) indy1).getPermutationData().length; p++) {
dIndy1 = ((InterfaceDataTypePermutation) indy1).getPermutationData()[p];
dIndy2 = ((InterfaceDataTypePermutation) indy2).getPermutationData()[p];
......@@ -192,7 +187,7 @@ public class PhenotypeMetric implements InterfaceDistanceMetric, java.io.Seriali
return result / d1.length;
}
if (indy instanceof InterfaceDataTypeDouble) {
result = norm(((InterfaceDataTypeDouble) indy).getDoubleData());
result = Mathematics.norm(((InterfaceDataTypeDouble) indy).getDoubleData());
return result;
}
if (indy instanceof InterfaceDataTypePermutation) {
......@@ -208,20 +203,6 @@ public class PhenotypeMetric implements InterfaceDistanceMetric, java.io.Seriali
return 0;
}
/**
* Calculates the 2 norm of a given vector.
*
* @param v1
* @return
*/
public static double norm(double[] v1) {
double result = 0;
for (int i = 0; i < v1.length; i++) {
result += Math.pow(v1[i], 2);
}
return Math.sqrt(result);
}
/**
* This method will return a naming String
*
......
......@@ -15,15 +15,11 @@ import eva2.util.annotation.Description;
@Description("This is an experimental method for individuals using global ES mutation.")
public class SigmaSingleMetricGlobalMutation implements InterfaceDistanceMetric, java.io.Serializable {
public SigmaSingleMetricGlobalMutation() {
}
public SigmaSingleMetricGlobalMutation(SigmaSingleMetricGlobalMutation a) {
}
public SigmaSingleMetricGlobalMutation() {}
@Override
public Object clone() {
return new SigmaSingleMetricGlobalMutation(this);
return new SigmaSingleMetricGlobalMutation();
}
/**
......
......@@ -248,9 +248,9 @@ public class PostProcess {
Population result = new Population();
for (int i = 0; i < pop.size(); i++) {
indy = pop.getEAIndividual(i);
if (bSmallerEq && (PhenotypeMetric.norm(indy.getFitness()) <= fitNorm)) {
if (bSmallerEq && (Mathematics.norm(indy.getFitness()) <= fitNorm)) {
result.add(indy);
} else if (!bSmallerEq && (PhenotypeMetric.norm(indy.getFitness()) > fitNorm)) {
} else if (!bSmallerEq && (Mathematics.norm(indy.getFitness()) > fitNorm)) {
result.add(indy);
}
}
......@@ -279,7 +279,7 @@ public class PostProcess {
if ((crit >= 0) && (crit < indy.getFitness().length)) {
curFit = indy.getFitness(crit);
} else {
curFit = PhenotypeMetric.norm(indy.getFitness());
curFit = Mathematics.norm(indy.getFitness());
}
if (bSmallerEq && (curFit <= fitThresh)) {
......@@ -1058,7 +1058,7 @@ public class PostProcess {
plot = draw("After " + stepsDone + " steps (" + params.getPPMethod() + ")" + ((params.getPostProcessClusterSigma() > 0) ? " and second clustering" : ""), null, outputPop, null, problem);
}
// ##### some statistics
double upBnd = PhenotypeMetric.norm(outputPop.getWorstEAIndividual().getFitness()) * 1.1;
double upBnd = Mathematics.norm(outputPop.getWorstEAIndividual().getFitness()) * 1.1;
upBnd = Math.pow(10, Math.floor(Math.log10(upBnd) + 1));
double lowBnd = 0;
int fitCrit = 0; // use first fitness criterion
......
......@@ -3,6 +3,7 @@ package eva2.optimization.operator.selection;
import eva2.optimization.individuals.AbstractEAIndividual;
import eva2.optimization.population.Population;
import eva2.util.annotation.Description;
import eva2.util.annotation.Parameter;
/**
* Simple method to select all.
......@@ -14,8 +15,7 @@ public class SelectAll implements InterfaceSelection, java.io.Serializable {
private boolean obeyDebsConstViolationPrinciple = true;
public SelectAll() {
}
public SelectAll() {}
public SelectAll(SelectAll a) {
this.obeyDebsConstViolationPrinciple = a.obeyDebsConstViolationPrinciple;
......@@ -41,7 +41,7 @@ public class SelectAll implements InterfaceSelection, java.io.Serializable {
/**
* This method will select one Individual from the given
* Population in respect to the selection propability of the
* Population in respect to the selection probability of the
* individual.
*
* @param population The source population where to select from
......@@ -105,6 +105,7 @@ public class SelectAll implements InterfaceSelection, java.io.Serializable {
* @param b The new state
*/
@Override
@Parameter(description = "Toggle the use of Deb's constraint violation principle.")
public void setObeyDebsConstViolationPrinciple(boolean b) {
this.obeyDebsConstViolationPrinciple = b;
}
......@@ -112,8 +113,4 @@ public class SelectAll implements InterfaceSelection, java.io.Serializable {
public boolean getObeyDebsConstViolationPrinciple() {
return this.obeyDebsConstViolationPrinciple;
}
public String obeyDebsConstViolationPrincipleToolTip() {
return "Toggle the use of Deb's coonstraint violation principle.";
}
}
......@@ -2,8 +2,8 @@ package eva2.optimization.operator.selection;
import eva2.optimization.individuals.AbstractEAIndividual;
import eva2.optimization.operator.selection.probability.InterfaceSelectionProbability;
import eva2.optimization.operator.selection.probability.SelProbStandard;
import eva2.optimization.operator.selection.probability.SelProbStandardScaling;
import eva2.optimization.operator.selection.probability.SelectionProbabilityStandard;
import eva2.optimization.operator.selection.probability.SelectionProbabilityStandardScaling;
import eva2.optimization.population.Population;
import eva2.tools.math.RNG;
import eva2.util.annotation.Description;
......@@ -23,14 +23,14 @@ public class SelectParticleWheel implements InterfaceSelection, java.io.Serializ
* Comment for {@code serialVersionUID}
*/
private static final long serialVersionUID = 1L;
private InterfaceSelectionProbability selProbCalculator = new SelProbStandard();
private InterfaceSelectionProbability selProbCalculator = new SelectionProbabilityStandard();
private boolean selectFixedSteps = false;
public SelectParticleWheel() {
}
public SelectParticleWheel(double scalingProb) {
selProbCalculator = new SelProbStandardScaling(scalingProb);
selProbCalculator = new SelectionProbabilityStandardScaling(scalingProb);
}
public SelectParticleWheel(InterfaceSelectionProbability selProb) {
......
......@@ -2,7 +2,7 @@ package eva2.optimization.operator.selection;
import eva2.optimization.individuals.AbstractEAIndividual;
import eva2.optimization.operator.selection.probability.InterfaceSelectionProbability;
import eva2.optimization.operator.selection.probability.SelProbStandard;
import eva2.optimization.operator.selection.probability.SelectionProbabilityStandard;
import eva2.optimization.population.Population;
import eva2.tools.math.RNG;
import eva2.util.annotation.Description;
......@@ -17,7 +17,7 @@ import eva2.util.annotation.Description;
public class SelectXProbRouletteWheel implements InterfaceSelection, java.io.Serializable {
private transient TreeElement[] treeRoot = null;
private InterfaceSelectionProbability selectionProbability = new SelProbStandard();
private InterfaceSelectionProbability selectionProbability = new SelectionProbabilityStandard();
private boolean obeyDebsConstViolationPrinciple = true;
public SelectXProbRouletteWheel() {
......
......@@ -11,7 +11,7 @@ import java.util.ArrayList;
* This abstract implementation gives some general
* methods for retrieving and cleaning fitness values.
*/
public abstract class AbstractSelProb implements InterfaceSelectionProbability, java.io.Serializable {
public abstract class AbstractSelectionProbability implements InterfaceSelectionProbability, java.io.Serializable {
/**
* This method allows you to make a deep clone of
......
......@@ -9,24 +9,24 @@ import eva2.util.annotation.Description;
* invariant to any linear transition function.
*/
@Description("This is the Boltzman Normation.")
public class SelProbBoltzman extends AbstractSelProb implements java.io.Serializable {
public class SelectionProbabilityBoltzman extends AbstractSelectionProbability implements java.io.Serializable {
private double q = 1.0;
public SelProbBoltzman() {
public SelectionProbabilityBoltzman() {
}
public SelProbBoltzman(double q) {
public SelectionProbabilityBoltzman(double q) {
this.q = q;
}
public SelProbBoltzman(SelProbBoltzman a) {
public SelectionProbabilityBoltzman(SelectionProbabilityBoltzman a) {
this.q = a.q;
}
@Override
public Object clone() {
return new SelProbBoltzman(this);
return new SelectionProbabilityBoltzman(this);
}
/**
......
......@@ -10,16 +10,16 @@ import eva2.util.annotation.Description;
* Here we have the infamous fitness sharing method.
*/
@Description("This is a fitness sharing based normation method.")
public class SelProbFitnessSharing extends AbstractSelProb implements java.io.Serializable {
public class SelectionProbabilityFitnessSharing extends AbstractSelectionProbability implements java.io.Serializable {
private InterfaceSelectionProbability basicNormationMethod = new SelProbStandard();
private InterfaceSelectionProbability basicNormationMethod = new SelectionProbabilityStandard();
private InterfaceDistanceMetric distanceMetric = new PhenotypeMetric();
private double sharingDistance = 0.1;
public SelProbFitnessSharing() {
public SelectionProbabilityFitnessSharing() {