Merge branch '61-terminators' into 'master'

Tests for Terminators



See merge request !12
This commit is contained in:
Fabian Becker 2015-12-26 19:17:28 +01:00
commit a4f10c8b71
45 changed files with 693 additions and 346 deletions

View File

@ -1,7 +1,8 @@
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'
}

View File

@ -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?

View File

@ -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
}
}
}
}
/**

View File

@ -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;

View File

@ -1,6 +1,7 @@
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());
// }
}

View File

@ -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;

View File

@ -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.";
}
}

View File

@ -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();
}
/**

View File

@ -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
*

View File

@ -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();
}
/**

View File

@ -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

View File

@ -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.";
}
}

View File

@ -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) {

View File

@ -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() {

View File

@ -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

View File

@ -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);
}
/**

View File

@ -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() {
}
public SelProbFitnessSharing(SelProbFitnessSharing a) {
public SelectionProbabilityFitnessSharing(SelectionProbabilityFitnessSharing a) {
if (a.basicNormationMethod != null) {
this.basicNormationMethod = (InterfaceSelectionProbability) a.basicNormationMethod.clone();
}
@ -31,7 +31,7 @@ public class SelProbFitnessSharing extends AbstractSelProb implements java.io.Se
@Override
public Object clone() {
return new SelProbFitnessSharing(this);
return new SelectionProbabilityFitnessSharing(this);
}
/**

View File

@ -10,24 +10,24 @@ import eva2.util.annotation.Description;
*
*/
@Description("This is a standard normation method inverted by maximum fitness.")
public class SelProbInvertByMax extends AbstractSelProb {
public class SelectionProbabilityInvertByMax extends AbstractSelectionProbability {
private double maxFit = 1.;
public SelProbInvertByMax() {
public SelectionProbabilityInvertByMax() {
}
public SelProbInvertByMax(double mF) {
public SelectionProbabilityInvertByMax(double mF) {
maxFit = mF;
}
public SelProbInvertByMax(SelProbInvertByMax a) {
public SelectionProbabilityInvertByMax(SelectionProbabilityInvertByMax a) {
this.maxFit = a.maxFit;
}
@Override
public Object clone() {
return new SelProbInvertByMax(this);
return new SelectionProbabilityInvertByMax(this);
}
/**

View File

@ -7,22 +7,22 @@ import eva2.util.annotation.Description;
* A linear ranking method with offsets.
*/
@Description("This is linear ranking normation.")
public class SelProbLinearRanking extends AbstractSelProb implements java.io.Serializable {
public class SelectionProbabilityLinearRanking extends AbstractSelectionProbability implements java.io.Serializable {
private double nappaPlus = 1.1;
private double nappaMinus = 0.9;
public SelProbLinearRanking() {
public SelectionProbabilityLinearRanking() {
}
public SelProbLinearRanking(SelProbLinearRanking a) {
public SelectionProbabilityLinearRanking(SelectionProbabilityLinearRanking a) {
this.nappaPlus = a.nappaPlus;
this.nappaMinus = a.nappaMinus;
}
@Override
public Object clone() {
return new SelProbLinearRanking(this);
return new SelectionProbabilityLinearRanking(this);
}
/**

View File

@ -8,24 +8,24 @@ import eva2.util.annotation.Description;
* the given optimization problem i guess.
*/
@Description("This is non-linear ranking normation.")
public class SelProbNonLinearRanking extends AbstractSelProb implements java.io.Serializable {
public class SelectionProbabilityNonLinearRanking extends AbstractSelectionProbability implements java.io.Serializable {
private double c = 0.04;
public SelProbNonLinearRanking() {
public SelectionProbabilityNonLinearRanking() {
}
public SelProbNonLinearRanking(double theC) {
public SelectionProbabilityNonLinearRanking(double theC) {
this.c = theC;
}
public SelProbNonLinearRanking(SelProbNonLinearRanking a) {
public SelectionProbabilityNonLinearRanking(SelectionProbabilityNonLinearRanking a) {
this.c = a.c;
}
@Override
public Object clone() {
return new SelProbNonLinearRanking(this);
return new SelectionProbabilityNonLinearRanking(this);
}
/**

View File

@ -8,17 +8,17 @@ import eva2.util.annotation.Description;
* This truly scaling invariant.
*/
@Description("This is ranking normation.")
public class SelProbRanking extends AbstractSelProb implements java.io.Serializable {
public class SelectionProbabilityRanking extends AbstractSelectionProbability implements java.io.Serializable {
public SelProbRanking() {
public SelectionProbabilityRanking() {
}
public SelProbRanking(SelProbRanking a) {
public SelectionProbabilityRanking(SelectionProbabilityRanking a) {
}
@Override
public Object clone() {
return new SelProbRanking(this);
return new SelectionProbabilityRanking(this);
}
/**

View File

@ -9,17 +9,17 @@ import eva2.util.annotation.Description;
* p(i is selected) = exp(-fitness(i))/sum_j(exp(-fitness(j)))
*/
@Description("This is a standard normation method using the exp function.")
public class SelProbStandard extends AbstractSelProb implements java.io.Serializable {
public class SelectionProbabilityStandard extends AbstractSelectionProbability implements java.io.Serializable {
public SelProbStandard() {
public SelectionProbabilityStandard() {
}
public SelProbStandard(SelProbStandard a) {
public SelectionProbabilityStandard(SelectionProbabilityStandard a) {
}
@Override
public Object clone() {
return new SelProbStandard(this);
return new SelectionProbabilityStandard(this);
}
/**

View File

@ -7,24 +7,24 @@ import eva2.util.annotation.Description;
* A simple sum with a scaling factor.
*/
@Description("This is a standard normation method with scaling.")
public class SelProbStandardScaling extends AbstractSelProb implements java.io.Serializable {
public class SelectionProbabilityStandardScaling extends AbstractSelectionProbability implements java.io.Serializable {
private double Q = 0;
public SelProbStandardScaling() {
public SelectionProbabilityStandardScaling() {
}
public SelProbStandardScaling(double q) {
public SelectionProbabilityStandardScaling(double q) {
Q = q;
}
public SelProbStandardScaling(SelProbStandardScaling a) {
public SelectionProbabilityStandardScaling(SelectionProbabilityStandardScaling a) {
this.Q = a.Q;
}
@Override
public Object clone() {
return new SelProbStandardScaling(this);
return new SelectionProbabilityStandardScaling(this);
}
/**

View File

@ -5,6 +5,7 @@ import eva2.optimization.operator.distancemetric.PhenotypeMetric;
import eva2.optimization.population.Population;
import eva2.optimization.population.PopulationInterface;
import eva2.util.annotation.Description;
import eva2.util.annotation.Parameter;
import java.io.Serializable;
@ -40,6 +41,7 @@ public class DiversityTerminator extends PopulationMeasureTerminator implements
/**
* @return the metric
*/
@Parameter(description = "Set the metric to be used to calculate individual distances.")
public InterfaceDistanceMetric getMetric() {
return metric;
}
@ -48,13 +50,10 @@ public class DiversityTerminator extends PopulationMeasureTerminator implements
this.metric = metric;
}
public String metricTipText() {
return "Set the metric to be used to calculate individual distances.";
}
/**
* @return the criterion
*/
@Parameter(description = "Define the distance criterion to check for in a population.")
public DiversityCriterion getCriterion() {
return criterion;
}
@ -63,17 +62,13 @@ public class DiversityTerminator extends PopulationMeasureTerminator implements
this.criterion = criterion;
}
public String criterionTipText() {
return "Define the distance criterion to check for in a population.";
@Override
protected double calculateInitialMeasure(PopulationInterface pop) {
return calculatePopulationMeasure(pop);
}
@Override
protected double calcInitialMeasure(PopulationInterface pop) {
return calcPopulationMeasure(pop);
}
@Override
protected double calcPopulationMeasure(PopulationInterface pop) {
protected double calculatePopulationMeasure(PopulationInterface pop) {
double[] measures = ((Population) pop).getPopulationMeasures(metric);
int measureIndex = criterion.ordinal();
return measures[measureIndex];

View File

@ -23,8 +23,7 @@ public class EvaluationTerminator implements InterfaceTerminator,
*/
protected int maxFitnessCalls = 1000;
public EvaluationTerminator() {
}
public EvaluationTerminator() {}
@Override
public void initialize(InterfaceOptimizationProblem prob) {

View File

@ -30,12 +30,12 @@ public class FitnessConvergenceTerminator extends PopulationMeasureTerminator
}
@Override
protected double calcInitialMeasure(PopulationInterface pop) {
protected double calculateInitialMeasure(PopulationInterface pop) {
return Mathematics.norm(pop.getBestFitness());
}
@Override
protected double calcPopulationMeasure(PopulationInterface pop) {
protected double calculatePopulationMeasure(PopulationInterface pop) {
// if (oldFit==null) return Double.MAX_VALUE;
// return EuclideanMetric.euclideanDistance(oldFit, pop.getBestFitness());
return Mathematics.norm(pop.getBestFitness());

View File

@ -44,8 +44,8 @@ public class FitnessValueTerminator implements InterfaceTerminator,
}
@Override
public boolean isTerminated(PopulationInterface Pop) {
double[] fit = Pop.getBestFitness();
public boolean isTerminated(PopulationInterface pop) {
double[] fit = pop.getBestFitness();
for (int i = 0; i < fit.length; i++) {
if (fitnessValue[i] < fit[i]) {
return false;

View File

@ -4,6 +4,7 @@ import eva2.optimization.population.InterfaceSolutionSet;
import eva2.optimization.population.PopulationInterface;
import eva2.problems.InterfaceOptimizationProblem;
import eva2.util.annotation.Description;
import eva2.util.annotation.Parameter;
import java.io.Serializable;
@ -24,8 +25,7 @@ public class GenerationTerminator implements InterfaceTerminator, Serializable {
msg = "Not terminated.";
}
public GenerationTerminator() {
}
public GenerationTerminator() {}
public GenerationTerminator(int gens) {
maxGenerations = gens;
@ -37,8 +37,8 @@ public class GenerationTerminator implements InterfaceTerminator, Serializable {
}
@Override
public boolean isTerminated(PopulationInterface Pop) {
if (maxGenerations < Pop.getGeneration()) {
public boolean isTerminated(PopulationInterface pop) {
if (maxGenerations < pop.getGeneration()) {
msg = maxGenerations + " generations reached.";
return true;
}
@ -52,10 +52,10 @@ public class GenerationTerminator implements InterfaceTerminator, Serializable {
@Override
public String toString() {
String ret = "Generations calls=" + maxGenerations;
return ret;
return "Generations calls=" + maxGenerations;
}
@Parameter(description = "Number of generations to evaluate.")
public void setGenerations(int x) {
maxGenerations = x;
}
@ -63,13 +63,4 @@ public class GenerationTerminator implements InterfaceTerminator, Serializable {
public int getGenerations() {
return maxGenerations;
}
/**
* Returns the tip text for this property
*
* @return tip text for this property
*/
public String generationsTipText() {
return "number of generations to evaluate.";
}
}

View File

@ -7,6 +7,7 @@ import eva2.problems.InterfaceMultimodalProblemKnown;
import eva2.problems.InterfaceOptimizationProblem;
import eva2.tools.EVAERROR;
import eva2.util.annotation.Description;
import eva2.util.annotation.Parameter;
import java.io.Serializable;
import java.util.logging.Level;
@ -25,16 +26,15 @@ public class KnownOptimaFoundTerminator implements InterfaceTerminator, Serializ
private int reqOptima = 1;
private String msg = "";
public KnownOptimaFoundTerminator() {
}
public KnownOptimaFoundTerminator() {}
@Override
public void initialize(InterfaceOptimizationProblem prob) {
public void initialize(InterfaceOptimizationProblem prob) throws IllegalArgumentException {
if (prob != null) {
if (prob instanceof InterfaceMultimodalProblemKnown) {
mProblem = (InterfaceMultimodalProblemKnown) prob;
} else {
LOGGER.log(Level.WARNING, "KnownOptimaFoundTerminator only works with InterfaceMultimodalProblemKnown instances!");
throw new IllegalArgumentException("KnownOptimaFoundTerminator only works with InterfaceMultimodalProblemKnown instances!");
}
} else {
LOGGER.log(Level.WARNING, "KnownOptimaFoundTerminator wont work with null problem!");
@ -71,21 +71,18 @@ public class KnownOptimaFoundTerminator implements InterfaceTerminator, Serializ
/**
* @return the reqOptima
*/
public int getReqOptima() {
public int getRequiredOptima() {
return reqOptima;
}
/**
* @param reqOptima the reqOptima to set
*/
public void setReqOptima(int reqOptima) {
@Parameter(description = "The number of optima that need to be found to terminate the optimization.")
public void setRequiredOptima(int reqOptima) {
this.reqOptima = reqOptima;
}
public String reqOptimaTipText() {
return "The number of optima that need to be found to terminate the optimization.";
}
@Override
public String toString() {
return "KnownOptimaFoundTerminator requiring " + reqOptima + " optima.";

View File

@ -9,6 +9,7 @@ import eva2.problems.AbstractMultiObjectiveOptimizationProblem;
import eva2.problems.InterfaceOptimizationProblem;
import eva2.tools.EVAERROR;
import eva2.util.annotation.Description;
import eva2.util.annotation.Parameter;
import java.io.Serializable;
@ -50,13 +51,12 @@ public class ParetoMetricTerminator extends PopulationMeasureTerminator implemen
if (prob instanceof AbstractMultiObjectiveOptimizationProblem) {
moProb = (AbstractMultiObjectiveOptimizationProblem) prob;
} else {
moProb = null;
EVAERROR.errorMsgOnce("Error, " + this.getClass() + " works only with problems inheriting from " + AbstractMultiObjectiveOptimizationProblem.class + "!");
throw new IllegalArgumentException("Error, " + this.getClass() + " works only with problems inheriting from " + AbstractMultiObjectiveOptimizationProblem.class + "!");
}
}
@Override
protected double calcInitialMeasure(PopulationInterface pop) {
protected double calculateInitialMeasure(PopulationInterface pop) {
if (moProb == null) {
return Double.MAX_VALUE;
} else {
@ -69,8 +69,8 @@ public class ParetoMetricTerminator extends PopulationMeasureTerminator implemen
}
@Override
protected double calcPopulationMeasure(PopulationInterface pop) {
return calcInitialMeasure(pop);
protected double calculatePopulationMeasure(PopulationInterface pop) {
return calculateInitialMeasure(pop);
}
@Override
@ -89,6 +89,7 @@ public class ParetoMetricTerminator extends PopulationMeasureTerminator implemen
}
}
@Parameter(description = "The pareto metric to use")
public void setParetoMetric(InterfaceParetoFrontMetric pMetric) {
this.pMetric = pMetric;
}
@ -97,10 +98,7 @@ public class ParetoMetricTerminator extends PopulationMeasureTerminator implemen
return pMetric;
}
public String paretoMetricTipText() {
return "The pareto metric to use";
}
@Parameter(description = "If true, the current population is used, otherwise the pareto front of the multi-objective problem instance is used")
public void setUseCurrentPop(boolean useCurrentPop) {
this.useCurrentPop = useCurrentPop;
}
@ -108,8 +106,4 @@ public class ParetoMetricTerminator extends PopulationMeasureTerminator implemen
public boolean isUseCurrentPop() {
return useCurrentPop;
}
public String useCurrentPopTipText() {
return "If true, the current population is used, otherwise the pareto front of the multi-objective problem instance is used";
}
}

View File

@ -34,13 +34,13 @@ public class PhenotypeConvergenceTerminator extends PopulationMeasureTerminator
}
@Override
protected double calcInitialMeasure(PopulationInterface pop) {
protected double calculateInitialMeasure(PopulationInterface pop) {
oldIndy = (AbstractEAIndividual) ((AbstractEAIndividual) pop.getBestIndividual()).clone();
return Double.MAX_VALUE;
}
@Override
protected double calcPopulationMeasure(PopulationInterface pop) {
protected double calculatePopulationMeasure(PopulationInterface pop) {
return pMetric.distance(oldIndy, (AbstractEAIndividual) pop.getBestIndividual());
}

View File

@ -4,6 +4,7 @@ import eva2.optimization.individuals.IndividualWeightedFitnessComparator;
import eva2.optimization.population.Population;
import eva2.optimization.population.PopulationInterface;
import eva2.util.annotation.Description;
import eva2.util.annotation.Parameter;
/**
* Terminate if a score based on the archive of the population converges.
@ -14,22 +15,22 @@ public class PopulationArchiveTerminator extends PopulationMeasureTerminator {
IndividualWeightedFitnessComparator wfComp = new IndividualWeightedFitnessComparator(new double[]{1.});
@Override
protected double calcInitialMeasure(PopulationInterface pop) {
protected double calculateInitialMeasure(PopulationInterface pop) {
Population archive = ((Population) pop).getArchive();
if (archive == null || (archive.size() < 1)) {
return Double.MAX_VALUE;
} else {
return wfComp.calcScore(archive.getBestEAIndividual(wfComp));
return wfComp.calculateScore(archive.getBestEAIndividual(wfComp));
}
}
@Override
protected double calcPopulationMeasure(PopulationInterface pop) {
protected double calculatePopulationMeasure(PopulationInterface pop) {
Population archive = ((Population) pop).getArchive();
if (archive == null || (archive.size() < 1)) {
return Double.MAX_VALUE;
} else {
return wfComp.calcScore(archive.getBestEAIndividual(wfComp));
return wfComp.calculateScore(archive.getBestEAIndividual(wfComp));
}
}
@ -42,11 +43,8 @@ public class PopulationArchiveTerminator extends PopulationMeasureTerminator {
return wfComp.getFitWeights();
}
@Parameter(description = "Weights of the fitness values in the linear combination")
public void setFitWeights(double[] fWeights) {
wfComp.setFitWeights(fWeights);
}
public String fitWeightsTipText() {
return wfComp.fitWeightsTipText();
}
}

View File

@ -4,6 +4,7 @@ import eva2.optimization.population.PopulationInterface;
import eva2.optimization.population.InterfaceSolutionSet;
import eva2.problems.InterfaceOptimizationProblem;
import eva2.util.annotation.Description;
import eva2.util.annotation.Parameter;
import java.io.Serializable;
@ -14,11 +15,11 @@ import java.io.Serializable;
* The class detects changes of a population measure over time and may signal convergence
* if the measure m(P) behaved in a certain way for a given time. Convergence may
* be signaled
* - if the measure reached absolute values below convThresh (absolute value),
* - if the measure remained within m(P)+/-convThresh (absolute change),
* - if the measure remained above m(P)-convThresh (absolute change and regard improvement only),
* - if the measure remained within m(P)*[1-convThresh, 1+convThresh] (relative change),
* - if the measure remained above m(P)*(1-convThresh) (relative change and regard improvement only).
* - if the measure reached absolute values below convergenceThresh (absolute value),
* - if the measure remained within m(P)+/-convergenceThresh (absolute change),
* - if the measure remained above m(P)-convergenceThresh (absolute change and regard improvement only),
* - if the measure remained within m(P)*[1-convergenceThresh, 1+convergenceThresh] (relative change),
* - if the measure remained above m(P)*(1-convergenceThresh) (relative change and regard improvement only).
*/
@Description("Stop if a convergence criterion has been met.")
public abstract class PopulationMeasureTerminator implements InterfaceTerminator, Serializable {
@ -28,9 +29,9 @@ public abstract class PopulationMeasureTerminator implements InterfaceTerminator
public enum StagnationTypeEnum {fitnessCallBased, generationBased}
private double convThresh = 0.01; //, convThreshLower=0.02;
private double convergenceThresh = 0.01;
private double oldMeasure = -1;
private int stagTime = 1000;
private int stagnationTime = 1000;
private int oldPopFitCalls = 1000;
private int oldPopGens = 1000;
private boolean firstTime = true;
@ -43,16 +44,16 @@ public abstract class PopulationMeasureTerminator implements InterfaceTerminator
}
public PopulationMeasureTerminator(double convergenceThreshold, int stagnationTime, StagnationTypeEnum stagType, ChangeTypeEnum changeType, DirectionTypeEnum dirType) {
this.convThresh = convergenceThreshold;
this.stagTime = stagnationTime;
this.convergenceThresh = convergenceThreshold;
this.stagnationTime = stagnationTime;
this.stagnationMeasure = stagType;
this.changeType = changeType;
this.condDirection = dirType;
}
public PopulationMeasureTerminator(PopulationMeasureTerminator o) {
convThresh = o.convThresh;
stagTime = o.stagTime;
convergenceThresh = o.convergenceThresh;
stagnationTime = o.stagnationTime;
oldPopFitCalls = o.oldPopFitCalls;
oldPopGens = o.oldPopGens;
firstTime = o.firstTime;
@ -80,16 +81,16 @@ public abstract class PopulationMeasureTerminator implements InterfaceTerminator
if (!firstTime && isStillConverged(pop)) {
if (stagnationTimeHasPassed(pop)) {
// population hasnt changed much for max time, criterion is met
// population hasn't changed much for max time, criterion is met
msg = getTerminationMessage();
return true;
} else {
// population hasnt changed much for i<max time, keep running
// population hasn't changed much for i<max time, keep running
return false;
}
} else {
// first call at all - or population improved more than "allowed" to terminate
oldMeasure = calcInitialMeasure(pop);
oldMeasure = calculateInitialMeasure(pop);
saveState(pop);
return false;
}
@ -100,7 +101,7 @@ public abstract class PopulationMeasureTerminator implements InterfaceTerminator
*
* @return
*/
protected abstract double calcInitialMeasure(PopulationInterface pop);
protected abstract double calculateInitialMeasure(PopulationInterface pop);
@Override
public String lastTerminationMessage() {
@ -114,7 +115,6 @@ public abstract class PopulationMeasureTerminator implements InterfaceTerminator
*/
protected String getTerminationMessage() {
StringBuilder sb = new StringBuilder(getMeasureName());
// if (convergenceCondition.isSelectedString("Relative")) sb.append(" converged relatively ");
switch (changeType) {
case absoluteChange:
sb.append(" changed absolutely ");
@ -128,15 +128,13 @@ public abstract class PopulationMeasureTerminator implements InterfaceTerminator
}
if (doCheckImprovement()) {
sb.append("less than ");
sb.append(convThresh);
sb.append(convergenceThresh);
} else {
sb.append("within +/-");
// sb.append(convThreshLower);
// sb.append("/");
sb.append(convThresh);
sb.append(convergenceThresh);
}
sb.append(" for ");
sb.append(stagTime);
sb.append(stagnationTime);
if (stagnationMeasure == StagnationTypeEnum.generationBased) {
sb.append(" generations.");
} else {
@ -159,8 +157,7 @@ public abstract class PopulationMeasureTerminator implements InterfaceTerminator
* @param pop
*/
protected void saveState(PopulationInterface pop) {
// oldFit = pop.getBestFitness().clone();
oldMeasure = calcPopulationMeasure(pop);
oldMeasure = calculatePopulationMeasure(pop);
oldPopFitCalls = pop.getFunctionCalls();
oldPopGens = pop.getGeneration();
firstTime = false;
@ -173,7 +170,7 @@ public abstract class PopulationMeasureTerminator implements InterfaceTerminator
* @param pop
* @return
*/
protected abstract double calcPopulationMeasure(PopulationInterface pop);
protected abstract double calculatePopulationMeasure(PopulationInterface pop);
/**
* Return true if the population measure did not exceed the
@ -183,22 +180,21 @@ public abstract class PopulationMeasureTerminator implements InterfaceTerminator
* @return
*/
protected boolean isStillConverged(PopulationInterface pop) {
double measure = calcPopulationMeasure(pop);
double measure = calculatePopulationMeasure(pop);
double allowedLower = Double.NEGATIVE_INFINITY, allowedUpper = Double.POSITIVE_INFINITY;
boolean ret;
switch (changeType) {
case absoluteChange:
allowedLower = oldMeasure - convThresh;
allowedLower = oldMeasure - convergenceThresh;
if (!doCheckImprovement()) {
allowedUpper = oldMeasure + convThresh;
allowedUpper = oldMeasure + convergenceThresh;
}
break;
case absoluteValue:
allowedUpper = convThresh;
// if (!doCheckImprovement()) allowedUpper = convThreshUpper;
allowedUpper = convergenceThresh;
break;
case relativeChange:
double delta = oldMeasure * convThresh;
double delta = oldMeasure * convergenceThresh;
allowedLower = oldMeasure - delta;
if (!doCheckImprovement()) {
allowedUpper = oldMeasure + delta;
@ -211,7 +207,6 @@ public abstract class PopulationMeasureTerminator implements InterfaceTerminator
public boolean doCheckImprovement() {
return (condDirection == DirectionTypeEnum.decrease);
// return condImprovementOrChange.isSelectedString("Improvement");
}
public boolean isRelativeConvergence() {
@ -220,43 +215,38 @@ public abstract class PopulationMeasureTerminator implements InterfaceTerminator
/**
* Return true if the defined stagnation time (function calls or generations) has passed
* since the last noteable change.
* since the last notable change.
*
* @param pop
* @return
*/
private boolean stagnationTimeHasPassed(PopulationInterface pop) {
if (stagnationMeasure == StagnationTypeEnum.fitnessCallBased) { // by fitness calls
return (pop.getFunctionCalls() - oldPopFitCalls) >= stagTime;
return (pop.getFunctionCalls() - oldPopFitCalls) >= stagnationTime;
} else {// by generation
return (pop.getGeneration() - oldPopGens) >= stagTime;
return (pop.getGeneration() - oldPopGens) >= stagnationTime;
}
}
@Parameter(description = "Ratio of improvement/change or absolute value of improvement/change to determine convergence.")
public void setConvergenceThreshold(double x) {
convThresh = x;
convergenceThresh = x;
}
public double getConvergenceThreshold() {
return convThresh;
}
public String convergenceThresholdTipText() {
return "Ratio of improvement/change or absolute value of improvement/change to determine convergence.";
return convergenceThresh;
}
@Parameter(description = "Terminate if the population has not improved/changed for this time")
public void setStagnationTime(int k) {
stagTime = k;
stagnationTime = k;
}
public int getStagnationTime() {
return stagTime;
}
public String stagnationTimeTipText() {
return "Terminate if the population has not improved/changed for this time";
return stagnationTime;
}
@Parameter(description = "Stagnation time is measured in fitness calls or generations")
public StagnationTypeEnum getStagnationMeasure() {
return stagnationMeasure;
}
@ -265,31 +255,21 @@ public abstract class PopulationMeasureTerminator implements InterfaceTerminator
this.stagnationMeasure = stagnationTimeIn;
}
public String stagnationMeasureTipText() {
return "Stagnation time is measured in fitness calls or generations";
}
public ChangeTypeEnum getConvergenceCondition() {
return changeType;
}
@Parameter(description = "Select absolute or relative convergence condition")
public void setConvergenceCondition(ChangeTypeEnum convergenceCondition) {
this.changeType = convergenceCondition;
}
public String convergenceConditionTipText() {
return "Select absolute or relative convergence condition";
}
public DirectionTypeEnum getCheckType() {
return condDirection;
}
@Parameter(description = "Detect improvement only (decreasing measure) or change in both directions (decrease and increase)")
public void setCheckType(DirectionTypeEnum dt) {
this.condDirection = dt;
}
public String checkTypeTipText() {
return "Detect improvement only (decreasing measure) or change in both directions (decrease and increase)";
}
}

View File

@ -7,7 +7,7 @@ import eva2.optimization.operator.distancemetric.EuclideanMetric;
import eva2.optimization.operator.distancemetric.InterfaceDistanceMetric;
import eva2.optimization.operator.distancemetric.PhenotypeMetric;
import eva2.optimization.operator.postprocess.PostProcess;
import eva2.optimization.operator.selection.probability.AbstractSelProb;
import eva2.optimization.operator.selection.probability.AbstractSelectionProbability;
import eva2.tools.EVAERROR;
import eva2.tools.Pair;
import eva2.tools.Serializer;
@ -722,9 +722,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
this.historyList.add((AbstractEAIndividual) this.getBestEAIndividual().clone());
}
if (isAutoAging()) {
for (AbstractEAIndividual individual : this) {
individual.incrAge();
}
this.forEach(AbstractEAIndividual::incrAge);
}
this.generationCount++;
firePropertyChangedEvent(NEXT_GENERATION_PERFORMED);
@ -885,7 +883,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
}
/**
* Resets the fitnes to the maximum possible value for the given individual.
* Resets the fitness to the maximum possible value for the given individual.
*
* @param indy an individual whose fitness will be reset
*/
@ -1040,7 +1038,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
* @param comparator indicate whether constraints should be regarded
* @return The index of the best (worst) individual.
*/
public int getIndexOfBestOrWorstIndividual(boolean bBest, Comparator<Object> comparator) {
public int getIndexOfBestOrWorstIndividual(boolean bBest, Comparator<AbstractEAIndividual> comparator) {
ArrayList<?> sorted = getSorted(comparator);
if (bBest) {
return indexOf(sorted.get(0));
@ -1053,7 +1051,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
return getIndexOfBestOrWorstIndividual(true, comparator);
}
public AbstractEAIndividual getBestEAIndividual(Comparator<Object> comparator) {
public AbstractEAIndividual getBestEAIndividual(Comparator<AbstractEAIndividual> comparator) {
int index = getIndexOfBestOrWorstIndividual(true, comparator);
return getEAIndividual(index);
}
@ -1201,7 +1199,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
* fitness first
* @see #getSortedNIndividuals(int, boolean, Population, Comparator)
*/
public Population getSortedBestFirst(Comparator<Object> comp) {
public Population getSortedBestFirst(Comparator<AbstractEAIndividual> comp) {
Population result = this.cloneWithoutInds();
getSortedNIndividuals(size(), true, result, comp);
result.synchSize();
@ -1221,7 +1219,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
* @param comp the Comparator to use with individuals
* @param res The m sorted best or worst individuals, where m &lt;= n (will be added to res)
*/
public void getSortedNIndividuals(int n, boolean bBestOrWorst, Population res, Comparator<Object> comp) {
public void getSortedNIndividuals(int n, boolean bBestOrWorst, Population res, Comparator<AbstractEAIndividual> comp) {
if ((n < 0) || (n > super.size())) {
// this may happen, treat it gracefully
//System.err.println("invalid request to getSortedNIndividuals: n="+n + ", size is " + super.size());
@ -1293,7 +1291,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
* on AbstractEAIndividual instances.
* @return
*/
protected ArrayList<AbstractEAIndividual> sortBy(Comparator<Object> comp) {
protected ArrayList<AbstractEAIndividual> sortBy(Comparator<AbstractEAIndividual> comp) {
if (super.isEmpty()) {
return new ArrayList<>();
}
@ -1322,7 +1320,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
* @param comp The comparator
* @return
*/
public ArrayList<AbstractEAIndividual> getSorted(Comparator<Object> comp) {
public ArrayList<AbstractEAIndividual> getSorted(Comparator<AbstractEAIndividual> comp) {
if (!comp.equals(lastSortingComparator) || (sortedArr == null) || (super.modCount != lastQModCount)) {
ArrayList<AbstractEAIndividual> sArr = sortBy(comp);
if (sortedArr == null) {
@ -1342,7 +1340,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
*
* @see #getSorted(java.util.Comparator)
*/
public Population getSortedPop(Comparator<Object> comp) {
public Population getSortedPop(Comparator<AbstractEAIndividual> comp) {
Population pop = this.cloneWithoutInds();
ArrayList<AbstractEAIndividual> sortedIndies = getSorted(comp);
pop.addAll(sortedIndies);
@ -2093,7 +2091,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
*/
public double[] getCenter() {
if (size() == 0) {
EVAERROR.errorMsgOnce("Invalid pop size in DistractingPopulation:getCenter!");
return null;
}
double[] centerPos = AbstractEAIndividual.getDoublePosition(getEAIndividual(0));
for (int i = 1; i < size(); i++) {
@ -2125,7 +2123,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
*/
public double[] getCenterWeighted(double[] weights) {
if (size() == 0 || (weights.length > size()) || (weights.length == 0)) {
EVAERROR.errorMsgOnce("Invalid pop size in DistractingPopulation:getCenterWeighted!");
return null;
}
double[] centerPos = AbstractEAIndividual.getDoublePosition(getEAIndividual(0));
Mathematics.svMult(weights[0], centerPos, centerPos);
@ -2145,7 +2143,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
* @param criterion
* @return
*/
public double[] getCenterWeighted(AbstractSelProb selProb, int criterion, boolean obeyConst) {
public double[] getCenterWeighted(AbstractSelectionProbability selProb, int criterion, boolean obeyConst) {
selProb.computeSelectionProbability(this, "Fitness", obeyConst);
double[] mean = AbstractEAIndividual.getDoublePosition(getEAIndividual(0));

View File

@ -44,7 +44,7 @@ import java.util.Vector;
public class ParticleSwarmOptimization extends AbstractOptimizer implements java.io.Serializable, InterfaceAdditionalPopulationInformer {
public enum PSOType { Inertness, Constriction }
Object[] sortedPop = null;
AbstractEAIndividual[] sortedPop = null;
protected AbstractEAIndividual bestIndividual = null;
protected boolean checkRange = true;
protected boolean checkSpeedLimit = false;
@ -1299,7 +1299,7 @@ public class ParticleSwarmOptimization extends AbstractOptimizer implements java
}
}
if ((topology == PSOTopology.multiSwarm) || (topology == PSOTopology.tree)) {
sortedPop = pop.toArray();
sortedPop = pop.toArray(new AbstractEAIndividual[pop.size()]);
if ((topology == PSOTopology.multiSwarm) || (treeStruct >= 2)) {
Arrays.sort(sortedPop, new EAIndividualComparator());
} else {

View File

@ -3,9 +3,6 @@ package eva2.tools;
import java.util.HashMap;
import java.util.Map;
/**
* Created by halfdan on 17/12/15.
*/
public class Primitives {
public static Class<?> unwrap(Class<?> clazz) {
return getWrapperTypes().get(clazz);

View File

@ -71,9 +71,6 @@ public class SelectedTag implements java.io.Serializable {
}
}
//~ Methods ////////////////////////////////////////////////////////////////
/**
* Set the selected tag by index.
*
@ -197,23 +194,5 @@ public class SelectedTag implements java.io.Serializable {
@Override
public String toString() {
return tags[selectedId].getString();
// Character selSign = '*';
// Character separator = '|';
// StringBuffer sbuf;
// if (selectedId != 0) sbuf = new StringBuffer(tags[0].getString());
// else {
// sbuf = new StringBuffer(selSign.toString());
// sbuf.append(tags[0].getString());
// sbuf.append(selSign);
// }
// for (int i=1; i<tags.length; i++) {
// sbuf.append(separator);
// if (selectedId == i) {
// sbuf.append(selSign);
// sbuf.append(tags[i].getString());
// sbuf.append(selSign);
// } else sbuf.append(tags[i].getString());
// }
// return sbuf.toString();
}
}

View File

@ -2,18 +2,43 @@ package eva2.optimization.individuals;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
*/
public class AbstractEAIndividualTest {
@Test
public void testIsDominatingFitness() throws Exception {
// Single objective
double[] fit1 = new double[]{405.231322};
double[] fit2 = new double[]{123.128371293};
assertTrue(AbstractEAIndividual.isDominatingFitness(fit2, fit1));
assertFalse(AbstractEAIndividual.isDominatingFitness(fit1, fit2));
// Multi objective
fit1 = new double[]{12.0, 10.0, 8.0};
fit2 = new double[]{11.0, 10.0, 9.0};
assertFalse(AbstractEAIndividual.isDominatingFitness(fit1, fit2));
assertFalse(AbstractEAIndividual.isDominatingFitness(fit2, fit1));
fit2 = new double[]{11.0, 9.9, 0.9};
assertTrue(AbstractEAIndividual.isDominatingFitness(fit2, fit1));
// Is dominating itself
assertTrue(AbstractEAIndividual.isDominatingFitness(fit1, fit1));
}
@Test
public void testIsDominatingFitnessNotEqual() throws Exception {
// Single objective
double[] fit1 = new double[]{415.231322};
// Is not dominating itself
assertFalse(AbstractEAIndividual.isDominatingFitnessNotEqual(fit1, fit1));
}
@Test

View File

@ -0,0 +1,30 @@
package eva2.optimization.individuals;
import org.junit.Test;
import static org.junit.Assert.*;
public class ESIndividualPermutationDataTest {
@Test
public void testMapXToY() throws Exception {
double[][] matrix = new double[][]{
{1.2, 2.3, 3.4, 1.2},
{0.2, 0.3, 0.4}
};
// Properly constructs vector from matrix
assertArrayEquals(
new double[]{1.2, 2.3, 3.4, 1.2, 0.2, 0.3, 0.4},
ESIndividualPermutationData.mapMatrixToVector(matrix), 0.0
);
// Properly converts to vector and back to matrix
assertArrayEquals(
matrix,
ESIndividualPermutationData.mapVectorToMatrix(
ESIndividualPermutationData.mapMatrixToVector(matrix), new int[]{4,3}
)
);
}
}

View File

@ -0,0 +1,79 @@
package eva2.optimization.operator.distancemetric;
import eva2.optimization.individuals.*;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class PhenotypeMetricTest {
private PhenotypeMetric metric;
@Before
public void setUp() throws Exception {
metric = new PhenotypeMetric();
}
@Test
public void testDistance() throws Exception {
// DOUBLE
ESIndividualDoubleData dindy1, dindy2;
dindy1 = mock(ESIndividualDoubleData.class);
when(dindy1.getDoubleData()).thenReturn(new double[]{1.0, 1.0, 1.0, 1.0, 1.0});
when(dindy1.getDoubleRange()).thenReturn(new double[][]{
{0.0, 10.0},{0.0, 10.0},{0.0, 10.0},{0.0, 10.0},{0.0, 10.0}
});
dindy2 = mock(ESIndividualDoubleData.class);
when(dindy2.getDoubleData()).thenReturn(new double[]{2.0, 2.0, 2.0, 2.0, 2.0});
when(dindy2.getDoubleRange()).thenReturn(new double[][]{
{0.0, 10.0},{0.0, 10.0},{0.0, 10.0},{0.0, 10.0},{0.0, 10.0}
});
// Should be zero for distance to itself
assertEquals(0.0, metric.distance(dindy1, dindy1), 0.0);
assertEquals(0.2236, metric.distance(dindy1, dindy2), 1E-4);
// INTEGER
ESIndividualIntegerData iindy1, iindy2;
iindy1 = mock(ESIndividualIntegerData.class);
when(iindy1.getIntegerData()).thenReturn(new int[]{1, 1, 1, 1, 1});
when(iindy1.getIntRange()).thenReturn(new int[][]{
{0, 10},{0, 10},{0, 10},{0, 10},{0, 10}
});
iindy2 = mock(ESIndividualIntegerData.class);
when(iindy2.getIntegerData()).thenReturn(new int[]{3, 3, 3, 3, 3});
when(iindy2.getIntRange()).thenReturn(new int[][]{
{0, 10},{0, 10},{0, 10},{0, 10},{0, 10}
});
// Should be zero for distance to itself
assertEquals(0.0, metric.distance(iindy1, iindy1), 0.0);
assertEquals(0.4472, metric.distance(iindy1, iindy2), 1E-4);
// PERMUTATION
ESIndividualPermutationData pindy1, pindy2;
pindy1 = mock(ESIndividualPermutationData.class);
when(pindy1.getPermutationData()).thenReturn(new int[][]{
{0, 1, 2}, {0, 1, 2}, {0, 1, 2}, {0, 1, 2}, {0, 1, 2}, {}
});
pindy2 = mock(ESIndividualPermutationData.class);
when(pindy2.getPermutationData()).thenReturn(new int[][]{
{0, 1, 3}, {0, 1, 1}, {0, 0, 2}, {1, 1, 3}, {}, {1, 2, 3}
});
// Should be zero for distance to itself
assertEquals(0.0, metric.distance(pindy1, pindy1), 0.0);
assertEquals(2.35, metric.distance(pindy1, pindy2), 1E-4);
}
@Test
public void testNorm() throws Exception {
}
}

View File

@ -0,0 +1,94 @@
package eva2.optimization.operator.terminators;
import eva2.optimization.population.PopulationInterface;
import eva2.optimization.population.SolutionSet;
import eva2.problems.InterfaceOptimizationProblem;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
public class CombinedTerminatorTest {
private CombinedTerminator terminator;
private InterfaceTerminator term1;
private InterfaceTerminator term2;
private InterfaceOptimizationProblem prob;
@Before
public void setUp() throws Exception {
terminator = new CombinedTerminator();
term1 = mock(InterfaceTerminator.class);
term2 = mock(InterfaceTerminator.class);
prob = mock(InterfaceOptimizationProblem.class);
terminator.setTerminatorOne(term1);
terminator.setTerminatorTwo(term2);
}
@Test
public void testInitialize() throws Exception {
terminator.initialize(prob);
verify(term1).initialize(prob);
verify(term2).initialize(prob);
}
@Test
public void testIsTerminatedPop() throws Exception {
PopulationInterface pop = mock(PopulationInterface.class);
terminator.isTerminated(pop);
verify(term1).isTerminated(pop);
verify(term2).isTerminated(pop);
reset(term1, term2);
terminator.setLogicalOperator(CombinedTerminator.LogicalOperator.OR);
// Should still call both terminators
terminator.isTerminated(pop);
verify(term1).isTerminated(pop);
verify(term2).isTerminated(pop);
}
@Test
public void testIsTerminatedSolSet() throws Exception {
SolutionSet solutionSet = mock(SolutionSet.class);
terminator.isTerminated(solutionSet);
verify(term1).isTerminated(solutionSet);
verify(term2).isTerminated(solutionSet);
reset(term1, term2);
terminator.setLogicalOperator(CombinedTerminator.LogicalOperator.OR);
// Should still call both terminators
terminator.isTerminated(solutionSet);
verify(term1).isTerminated(solutionSet);
verify(term2).isTerminated(solutionSet);
}
@Test
public void testLastTerminationMessage() throws Exception {
}
@Test
public void testGetLogicalOperator() throws Exception {
// Defaults to an AND
assertEquals(CombinedTerminator.LogicalOperator.AND, terminator.getLogicalOperator());
terminator.setLogicalOperator(CombinedTerminator.LogicalOperator.OR);
assertEquals(CombinedTerminator.LogicalOperator.OR, terminator.getLogicalOperator());
}
@Test
public void testGetTerminatorOne() throws Exception {
assertEquals(term1, terminator.getTerminatorOne());
}
@Test
public void testGetTerminatorTwo() throws Exception {
assertEquals(term2, terminator.getTerminatorTwo());
}
}

View File

@ -0,0 +1,46 @@
package eva2.optimization.operator.terminators;
import eva2.optimization.population.Population;
import eva2.optimization.population.SolutionSet;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class FitnessValueTerminatorTest {
private FitnessValueTerminator terminator;
@Before
public void setUp() throws Exception {
terminator = new FitnessValueTerminator();
}
@Test
public void testIsTerminated() throws Exception {
Population pop = mock(Population.class);
when(pop.getBestFitness()).thenReturn(new double[]{10E-3});
assertFalse(terminator.isTerminated(pop));
when(pop.getBestFitness()).thenReturn(new double[]{10E-5});
assertTrue(terminator.isTerminated(pop));
SolutionSet solSet = mock(SolutionSet.class);
when(solSet.getCurrentPopulation()).thenReturn(pop);
assertTrue(terminator.isTerminated(pop));
}
@Test
public void testSetFitnessValue() throws Exception {
assertArrayEquals(new double[]{10E-4}, terminator.getFitnessValue(), 0.0);
double[] newFitness = {10E-4, 10E-4, 10E-4};
terminator.setFitnessValue(newFitness);
assertEquals(3, terminator.getFitnessValue().length);
assertArrayEquals(newFitness, terminator.getFitnessValue(), 0.0);
}
}

View File

@ -0,0 +1,58 @@
package eva2.optimization.operator.terminators;
import eva2.optimization.population.Population;
import eva2.optimization.population.SolutionSet;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
public class GenerationTerminatorTest {
GenerationTerminator terminator;
@Before
public void setUp() throws Exception {
terminator = new GenerationTerminator();
}
@Test
public void testIsTerminated() throws Exception {
Population pop = new Population();
pop.setGeneration(100);
assertFalse(terminator.isTerminated(pop));
pop.incrGeneration();
assertTrue(terminator.isTerminated(pop));
pop.setGeneration(100);
SolutionSet sset = new SolutionSet(pop);
assertFalse(terminator.isTerminated(sset));
pop.incrGeneration();
assertTrue(terminator.isTerminated(sset));
}
@Test
public void testLastTerminationMessage() throws Exception {
assertNotNull(terminator.toString());
}
@Test
public void testToString() throws Exception {
assertEquals("Generations calls=100", terminator.toString());
}
@Test
public void testSetGenerations() throws Exception {
// Defaults to 100 generations
assertEquals(100, terminator.getGenerations());
terminator.setGenerations(42);
assertEquals(42, terminator.getGenerations());
}
@Test
public void testGetGenerations() throws Exception {
// Defaults to 100 generations
assertEquals(100, terminator.getGenerations());
}
}

View File

@ -0,0 +1,52 @@
package eva2.optimization.operator.terminators;
import eva2.optimization.population.Population;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
public class MaximumTimeTerminatorTest {
MaximumTimeTerminator terminator;
@Before
public void setUp() throws Exception {
terminator = new MaximumTimeTerminator();
terminator.setMaximumTime(1);
}
@Test(timeout = 2500)
public void testIsTerminated() throws Exception {
terminator.initialize(null);
while(!terminator.isTerminated(new Population()));
}
@Test
public void testLastTerminationMessage() throws Exception {
assertNotNull(terminator.lastTerminationMessage());
}
@Test
public void testInitialize() throws Exception {
terminator.initialize(null);
// Should not be terminated after reinitialization
assertFalse(terminator.isTerminated(new Population()));
}
@Test
public void testToString() throws Exception {
assertNotNull(terminator.toString());
}
@Test
public void testGetMaximumTime() throws Exception {
assertEquals(1, terminator.getMaximumTime());
}
@Test
public void testSetMaximumTime() throws Exception {
terminator.setMaximumTime(10);
assertEquals(10, terminator.getMaximumTime());
}
}

View File

@ -1,9 +1,14 @@
package eva2.optimization.population;
import com.sun.org.apache.bcel.internal.generic.POP;
import eva2.optimization.individuals.AbstractEAIndividual;
import eva2.optimization.individuals.ESIndividualDoubleData;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class PopulationTest {
Population emptyPopulation;
@ -18,11 +23,6 @@ public class PopulationTest {
}
@Test
public void testPutData() throws Exception {
}
@Test
public void testGetData() throws Exception {
// Simple data
@ -182,8 +182,13 @@ public class PopulationTest {
@Test
public void testIncrGeneration() throws Exception {
int currentGeneration = emptyPopulation.getGeneration();
InterfacePopulationChangedEventListener listener = mock(InterfacePopulationChangedEventListener.class);
emptyPopulation.addPopulationChangedEventListener(listener);
emptyPopulation.incrGeneration();
verify(listener).registerPopulationStateChanged(emptyPopulation, Population.NEXT_GENERATION_PERFORMED);
assertEquals(currentGeneration + 1, emptyPopulation.getGeneration());
}
@ -204,11 +209,6 @@ public class PopulationTest {
}
@Test
public void testAddPopulation1() throws Exception {
}
@Test
public void testResetFitness() throws Exception {
@ -219,11 +219,6 @@ public class PopulationTest {
}
@Test
public void testGetDominatingSet1() throws Exception {
}
@Test
public void testGetIndexOfBestIndividualPrefFeasible() throws Exception {
@ -234,16 +229,6 @@ public class PopulationTest {
}
@Test
public void testGetIndexOfBestIndividualPrefFeasible1() throws Exception {
}
@Test
public void testGetIndexOfWorstIndividualNoConstr1() throws Exception {
}
@Test
public void testMoveNInds() throws Exception {
@ -319,11 +304,6 @@ public class PopulationTest {
}
@Test
public void testGetCorrelations1() throws Exception {
}
@Test
public void testGetFitnessMeasures() throws Exception {
@ -331,12 +311,22 @@ public class PopulationTest {
@Test
public void testGetCenter() throws Exception {
assertNull(emptyPopulation.getCenter());
for(int i = 0; i < 10; i++) {
ESIndividualDoubleData indy = mock(ESIndividualDoubleData.class);
when(indy.getDGenotype()).thenReturn(new double[]{i, i, i, i, i});
emptyPopulation.add(indy);
}
assertArrayEquals(new double[]{
4.5, 4.5, 4.5, 4.5, 4.5
}, emptyPopulation.getCenter(), 0.0);
}
@Test
public void testGetCenterIndy() throws Exception {
}
@Test
@ -351,7 +341,15 @@ public class PopulationTest {
@Test
public void testGetFitSum() throws Exception {
for(int i = 0; i < 10; i++) {
ESIndividualDoubleData indy = mock(ESIndividualDoubleData.class);
when(indy.getFitness(0)).thenReturn((double)i);
when(indy.getFitness(1)).thenReturn((double)i*2);
emptyPopulation.add(indy);
}
assertEquals(45.0, emptyPopulation.getFitSum(0), 0.0);
assertEquals(90.0, emptyPopulation.getFitSum(1), 0.0);
}
@Test
@ -371,7 +369,12 @@ public class PopulationTest {
@Test
public void testGetFreeSlots() throws Exception {
assertEquals(10, emptyPopulation.getFreeSlots());
ESIndividualDoubleData indy = mock(ESIndividualDoubleData.class);
emptyPopulation.add(indy);
assertEquals(9, emptyPopulation.getFreeSlots());
}
@Test
@ -384,6 +387,19 @@ public class PopulationTest {
}
@Test
public void testPutDataAllIndies() throws Exception {
ESIndividualDoubleData indy1 = mock(ESIndividualDoubleData.class);
ESIndividualDoubleData indy2 = mock(ESIndividualDoubleData.class);
emptyPopulation.add(indy1);
emptyPopulation.add(indy2);
emptyPopulation.putDataAllIndies("test", 12);
verify(indy1).putData("test", 12);
verify(indy2).putData("test", 12);
}
@Test
public void testFilterByFitness() throws Exception {
ESIndividualDoubleData indy1, indy2, indy3;
@ -401,4 +417,29 @@ public class PopulationTest {
// Get all individuals with fitness <= 10.0 (first fitness dimension)
assertEquals(2, emptyPopulation.filterByFitness(10.0, 0).size());
}
@Test
public void testGetBestEAIndividual() throws Exception {
}
@Test
public void testGetBestNIndividuals() throws Exception {
}
@Test
public void testGetWorstNIndividuals() throws Exception {
}
@Test
public void testGetWorstEAIndividual() throws Exception {
}
@Test
public void testRemoveNIndividuals() throws Exception {
}
}