Merge branch '61-terminators' into 'master'
Tests for Terminators See merge request !12
This commit is contained in:
commit
a4f10c8b71
56
build.gradle
56
build.gradle
@ -1,7 +1,8 @@
|
|||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
apply plugin: 'maven'
|
apply plugin: 'maven'
|
||||||
|
apply plugin: 'com.bmuschko.nexus'
|
||||||
|
|
||||||
group = 'eva2'
|
group = 'de.openea'
|
||||||
version = '2.2.0'
|
version = '2.2.0'
|
||||||
|
|
||||||
description = """EvA2"""
|
description = """EvA2"""
|
||||||
@ -25,9 +26,62 @@ task fatJar(type: Jar) {
|
|||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile group: 'javax.help', name: 'javahelp', version: '2.0.05'
|
compile group: 'javax.help', name: 'javahelp', version: '2.0.05'
|
||||||
compile group: 'org.yaml', name: 'snakeyaml', version: '1.16'
|
compile group: 'org.yaml', name: 'snakeyaml', version: '1.16'
|
||||||
compile group: 'gov.nist.math', name: 'jama', version: '1.0.3'
|
compile group: 'gov.nist.math', name: 'jama', version: '1.0.3'
|
||||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
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[])
|
* @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.")
|
@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.
|
// flag whether a data field should be used.
|
||||||
private String indyDataKey = "";
|
private String indyDataKey = "";
|
||||||
private int fitCriterion = -1;
|
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
|
* @return -1 if the first is dominant, 1 if the second is dominant, otherwise 0
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int compare(Object o1, Object o2) {
|
public int compare(AbstractEAIndividual o1, AbstractEAIndividual o2) {
|
||||||
boolean o1domO2, o2domO1;
|
boolean o1domO2, o2domO1;
|
||||||
|
|
||||||
if (preferFeasible) { // check constraint violation first?
|
if (preferFeasible) { // check constraint violation first?
|
||||||
|
@ -237,10 +237,6 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
|
|||||||
this.firstindex = firstindex;
|
this.firstindex = firstindex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************************
|
|
||||||
* AbstractEAIndividual methods
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will initialize the individual with a given value for the
|
* This method will initialize the individual with a given value for the
|
||||||
* phenotype.
|
* 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;
|
int sumentries = 0;
|
||||||
for (int i = 0; i < matrix.length; i++) {
|
for (int i = 0; i < matrix.length; i++) {
|
||||||
sumentries += matrix[i].length;
|
sumentries += matrix[i].length;
|
||||||
@ -321,7 +317,7 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double[][] mapVectorToMatrix(double[] vector, int[] sizes) {
|
public static double[][] mapVectorToMatrix(double[] vector, int[] sizes) {
|
||||||
double[][] matrix = new double[sizes.length][];
|
double[][] matrix = new double[sizes.length][];
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
for (int i = 0; i < sizes.length; i++) {
|
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.
|
* Compare two AbstractEAIndividuals by their distance to a reference individual.
|
||||||
* Usable to sort by a distance.
|
* 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 AbstractEAIndividual refIndy = null;
|
||||||
private InterfaceDistanceMetric distMetric = null;
|
private InterfaceDistanceMetric distMetric = null;
|
||||||
@ -30,9 +30,9 @@ public class IndividualDistanceComparator implements Comparator<Object>, Seriali
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(Object o1, Object o2) {
|
public int compare(AbstractEAIndividual o1, AbstractEAIndividual o2) {
|
||||||
double d1 = distMetric.distance((AbstractEAIndividual) o1, refIndy);
|
double d1 = distMetric.distance(o1, refIndy);
|
||||||
double d2 = distMetric.distance((AbstractEAIndividual) o2, refIndy);
|
double d2 = distMetric.distance(o2, refIndy);
|
||||||
|
|
||||||
if (d1 == d2) {
|
if (d1 == d2) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package eva2.optimization.individuals;
|
package eva2.optimization.individuals;
|
||||||
|
|
||||||
import eva2.tools.EVAERROR;
|
import eva2.tools.EVAERROR;
|
||||||
|
import eva2.util.annotation.Parameter;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
@ -10,7 +11,7 @@ import java.util.Comparator;
|
|||||||
*
|
*
|
||||||
* @author mkron
|
* @author mkron
|
||||||
*/
|
*/
|
||||||
public class IndividualWeightedFitnessComparator implements Comparator<Object>, Serializable {
|
public class IndividualWeightedFitnessComparator implements Comparator<AbstractEAIndividual>, Serializable {
|
||||||
/**
|
/**
|
||||||
* Generated serial version identifier
|
* 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)
|
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int compare(Object o1, Object o2) {
|
public int compare(AbstractEAIndividual o1, AbstractEAIndividual o2) {
|
||||||
double[] f1 = ((AbstractEAIndividual) o1).getFitness();
|
double[] f1 = o1.getFitness();
|
||||||
double[] f2 = ((AbstractEAIndividual) o2).getFitness();
|
double[] f2 = o2.getFitness();
|
||||||
|
|
||||||
double score1 = calcScore(f1);
|
double score1 = calculateScore(f1);
|
||||||
double score2 = calcScore(f2);
|
double score2 = calculateScore(f2);
|
||||||
|
|
||||||
if (score1 < score2) {
|
if (score1 < score2) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -95,7 +96,7 @@ public class IndividualWeightedFitnessComparator implements Comparator<Object>,
|
|||||||
* @param f
|
* @param f
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private double calcScore(double[] f) {
|
private double calculateScore(double[] f) {
|
||||||
if (f == null || fitWeights == null) {
|
if (f == null || fitWeights == null) {
|
||||||
throw new RuntimeException("Error, missing information in " + this.getClass());
|
throw new RuntimeException("Error, missing information in " + this.getClass());
|
||||||
}
|
}
|
||||||
@ -117,9 +118,9 @@ public class IndividualWeightedFitnessComparator implements Comparator<Object>,
|
|||||||
* @param indy
|
* @param indy
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public double calcScore(AbstractEAIndividual indy) {
|
public double calculateScore(AbstractEAIndividual indy) {
|
||||||
double[] f = indy.getFitness();
|
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) {
|
public void setFitWeights(double[] fitWeights) {
|
||||||
this.fitWeights = fitWeights;
|
this.fitWeights = fitWeights;
|
||||||
}
|
}
|
||||||
@ -140,23 +142,4 @@ public class IndividualWeightedFitnessComparator implements Comparator<Object>,
|
|||||||
public double[] getFitWeights() {
|
public double[] getFitWeights() {
|
||||||
return fitWeights;
|
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) {
|
public void calculateCrowdingDistance(Population front) {
|
||||||
|
|
||||||
Object[] frontArray = front.toArray();
|
AbstractEAIndividual[] frontArray = front.toArray(new AbstractEAIndividual[front.size()]);
|
||||||
boolean[] assigned = new boolean[frontArray.length];
|
boolean[] assigned = new boolean[frontArray.length];
|
||||||
|
|
||||||
double[] v = new double[frontArray.length];
|
double[] v = new double[frontArray.length];
|
||||||
@ -68,8 +68,8 @@ public class ArchivingNSGAIISMeasure extends ArchivingNSGAII {
|
|||||||
Arrays.sort(frontArray, new EAIndividualComparator(0));
|
Arrays.sort(frontArray, new EAIndividualComparator(0));
|
||||||
|
|
||||||
|
|
||||||
((AbstractEAIndividual) frontArray[0]).putData("HyperCube", Double.MAX_VALUE); //die beiden aussen bekommen maximal wert als measure
|
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[frontArray.length - 1].putData("HyperCube", Double.MAX_VALUE);
|
||||||
v[0] = Double.MAX_VALUE;
|
v[0] = Double.MAX_VALUE;
|
||||||
v[frontArray.length - 1] = 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.EVAERROR;
|
||||||
import eva2.tools.math.Mathematics;
|
import eva2.tools.math.Mathematics;
|
||||||
import eva2.util.annotation.Description;
|
import eva2.util.annotation.Description;
|
||||||
|
import eva2.util.annotation.Parameter;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
@ -19,8 +20,7 @@ import java.io.Serializable;
|
|||||||
public class DoubleIntegralMetric implements InterfaceDistanceMetric, Serializable {
|
public class DoubleIntegralMetric implements InterfaceDistanceMetric, Serializable {
|
||||||
boolean oneNormed = true; // if true, the vectors are normed to unity sum before comparison.
|
boolean oneNormed = true; // if true, the vectors are normed to unity sum before comparison.
|
||||||
|
|
||||||
public DoubleIntegralMetric() {
|
public DoubleIntegralMetric() {}
|
||||||
}
|
|
||||||
|
|
||||||
public DoubleIntegralMetric(boolean normed) {
|
public DoubleIntegralMetric(boolean normed) {
|
||||||
oneNormed = normed;
|
oneNormed = normed;
|
||||||
@ -35,10 +35,8 @@ public class DoubleIntegralMetric implements InterfaceDistanceMetric, Serializab
|
|||||||
public double distance(AbstractEAIndividual indy1, AbstractEAIndividual indy2) {
|
public double distance(AbstractEAIndividual indy1, AbstractEAIndividual indy2) {
|
||||||
double[] dIndy1 = null, dIndy2 = null;
|
double[] dIndy1 = null, dIndy2 = null;
|
||||||
|
|
||||||
if (dIndy1 == null || dIndy2 == null) {
|
dIndy1 = AbstractEAIndividual.getDoublePositionShallow(indy1);
|
||||||
dIndy1 = AbstractEAIndividual.getDoublePositionShallow(indy1);
|
dIndy2 = AbstractEAIndividual.getDoublePositionShallow(indy2);
|
||||||
dIndy2 = AbstractEAIndividual.getDoublePositionShallow(indy2);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oneNormed) {
|
if (oneNormed) {
|
||||||
double l1 = Mathematics.sum(dIndy1);
|
double l1 = Mathematics.sum(dIndy1);
|
||||||
@ -53,9 +51,8 @@ public class DoubleIntegralMetric implements InterfaceDistanceMetric, Serializab
|
|||||||
}
|
}
|
||||||
|
|
||||||
double sum1 = 0, sum2 = 0;
|
double sum1 = 0, sum2 = 0;
|
||||||
double tmpDiff = 0, sqrDiffSum = 0;
|
double tmpDiff, sqrDiffSum = 0;
|
||||||
// System.out.println(Mathematics.sum(dIndy1));
|
|
||||||
// System.out.println(Mathematics.sum(dIndy2));
|
|
||||||
for (int i = 0; (i < dIndy1.length) && (i < dIndy2.length); i++) {
|
for (int i = 0; (i < dIndy1.length) && (i < dIndy2.length); i++) {
|
||||||
sum1 += dIndy1[i];
|
sum1 += dIndy1[i];
|
||||||
sum2 += dIndy2[i];
|
sum2 += dIndy2[i];
|
||||||
@ -73,12 +70,8 @@ public class DoubleIntegralMetric implements InterfaceDistanceMetric, Serializab
|
|||||||
return oneNormed;
|
return oneNormed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Parameter(description = "If true, both vectors are normed to unity sum before comparison.")
|
||||||
public void setOneNormed(boolean normedByLength) {
|
public void setOneNormed(boolean normedByLength) {
|
||||||
this.oneNormed = 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.")
|
@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 class GenotypeMetricBitSet implements InterfaceDistanceMetric, java.io.Serializable {
|
||||||
|
|
||||||
public GenotypeMetricBitSet() {
|
public GenotypeMetricBitSet() {}
|
||||||
}
|
|
||||||
|
|
||||||
public GenotypeMetricBitSet(GenotypeMetricBitSet a) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object clone() {
|
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.gui.BeanInspector;
|
||||||
import eva2.optimization.individuals.*;
|
import eva2.optimization.individuals.*;
|
||||||
|
import eva2.tools.math.Mathematics;
|
||||||
import eva2.util.annotation.Description;
|
import eva2.util.annotation.Description;
|
||||||
|
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
@ -15,15 +16,11 @@ public class PhenotypeMetric implements InterfaceDistanceMetric, java.io.Seriali
|
|||||||
private static PhenotypeMetric pMetric = null;
|
private static PhenotypeMetric pMetric = null;
|
||||||
private static GenotypeMetricBitSet bitMetric = null;
|
private static GenotypeMetricBitSet bitMetric = null;
|
||||||
|
|
||||||
public PhenotypeMetric() {
|
public PhenotypeMetric() {}
|
||||||
}
|
|
||||||
|
|
||||||
public PhenotypeMetric(PhenotypeMetric a) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
return new PhenotypeMetric(this);
|
return new PhenotypeMetric();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int min(int a, int b, int c) {
|
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();
|
r2 = ((InterfaceDataTypeInteger) indy2).getIntRange();
|
||||||
for (int i = 0; (i < d1.length) && (i < d2.length); i++) {
|
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.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);
|
result += Math.sqrt(tmpResult);
|
||||||
}
|
}
|
||||||
@ -130,7 +126,6 @@ public class PhenotypeMetric implements InterfaceDistanceMetric, java.io.Seriali
|
|||||||
if ((indy1 instanceof InterfaceDataTypePermutation) && (indy2 instanceof InterfaceDataTypePermutation)) {
|
if ((indy1 instanceof InterfaceDataTypePermutation) && (indy2 instanceof InterfaceDataTypePermutation)) {
|
||||||
int[] dIndy1, dIndy2;
|
int[] dIndy1, dIndy2;
|
||||||
String s1 = "", s2 = "";
|
String s1 = "", s2 = "";
|
||||||
// double tmpResult = 0;
|
|
||||||
for (int p = 0; p < ((InterfaceDataTypePermutation) indy1).getPermutationData().length; p++) {
|
for (int p = 0; p < ((InterfaceDataTypePermutation) indy1).getPermutationData().length; p++) {
|
||||||
dIndy1 = ((InterfaceDataTypePermutation) indy1).getPermutationData()[p];
|
dIndy1 = ((InterfaceDataTypePermutation) indy1).getPermutationData()[p];
|
||||||
dIndy2 = ((InterfaceDataTypePermutation) indy2).getPermutationData()[p];
|
dIndy2 = ((InterfaceDataTypePermutation) indy2).getPermutationData()[p];
|
||||||
@ -192,7 +187,7 @@ public class PhenotypeMetric implements InterfaceDistanceMetric, java.io.Seriali
|
|||||||
return result / d1.length;
|
return result / d1.length;
|
||||||
}
|
}
|
||||||
if (indy instanceof InterfaceDataTypeDouble) {
|
if (indy instanceof InterfaceDataTypeDouble) {
|
||||||
result = norm(((InterfaceDataTypeDouble) indy).getDoubleData());
|
result = Mathematics.norm(((InterfaceDataTypeDouble) indy).getDoubleData());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if (indy instanceof InterfaceDataTypePermutation) {
|
if (indy instanceof InterfaceDataTypePermutation) {
|
||||||
@ -208,20 +203,6 @@ public class PhenotypeMetric implements InterfaceDistanceMetric, java.io.Seriali
|
|||||||
return 0;
|
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
|
* 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.")
|
@Description("This is an experimental method for individuals using global ES mutation.")
|
||||||
public class SigmaSingleMetricGlobalMutation implements InterfaceDistanceMetric, java.io.Serializable {
|
public class SigmaSingleMetricGlobalMutation implements InterfaceDistanceMetric, java.io.Serializable {
|
||||||
|
|
||||||
public SigmaSingleMetricGlobalMutation() {
|
public SigmaSingleMetricGlobalMutation() {}
|
||||||
}
|
|
||||||
|
|
||||||
public SigmaSingleMetricGlobalMutation(SigmaSingleMetricGlobalMutation a) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
return new SigmaSingleMetricGlobalMutation(this);
|
return new SigmaSingleMetricGlobalMutation();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -248,9 +248,9 @@ public class PostProcess {
|
|||||||
Population result = new Population();
|
Population result = new Population();
|
||||||
for (int i = 0; i < pop.size(); i++) {
|
for (int i = 0; i < pop.size(); i++) {
|
||||||
indy = pop.getEAIndividual(i);
|
indy = pop.getEAIndividual(i);
|
||||||
if (bSmallerEq && (PhenotypeMetric.norm(indy.getFitness()) <= fitNorm)) {
|
if (bSmallerEq && (Mathematics.norm(indy.getFitness()) <= fitNorm)) {
|
||||||
result.add(indy);
|
result.add(indy);
|
||||||
} else if (!bSmallerEq && (PhenotypeMetric.norm(indy.getFitness()) > fitNorm)) {
|
} else if (!bSmallerEq && (Mathematics.norm(indy.getFitness()) > fitNorm)) {
|
||||||
result.add(indy);
|
result.add(indy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -279,7 +279,7 @@ public class PostProcess {
|
|||||||
if ((crit >= 0) && (crit < indy.getFitness().length)) {
|
if ((crit >= 0) && (crit < indy.getFitness().length)) {
|
||||||
curFit = indy.getFitness(crit);
|
curFit = indy.getFitness(crit);
|
||||||
} else {
|
} else {
|
||||||
curFit = PhenotypeMetric.norm(indy.getFitness());
|
curFit = Mathematics.norm(indy.getFitness());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bSmallerEq && (curFit <= fitThresh)) {
|
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);
|
plot = draw("After " + stepsDone + " steps (" + params.getPPMethod() + ")" + ((params.getPostProcessClusterSigma() > 0) ? " and second clustering" : ""), null, outputPop, null, problem);
|
||||||
}
|
}
|
||||||
// ##### some statistics
|
// ##### 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));
|
upBnd = Math.pow(10, Math.floor(Math.log10(upBnd) + 1));
|
||||||
double lowBnd = 0;
|
double lowBnd = 0;
|
||||||
int fitCrit = 0; // use first fitness criterion
|
int fitCrit = 0; // use first fitness criterion
|
||||||
|
@ -3,6 +3,7 @@ package eva2.optimization.operator.selection;
|
|||||||
import eva2.optimization.individuals.AbstractEAIndividual;
|
import eva2.optimization.individuals.AbstractEAIndividual;
|
||||||
import eva2.optimization.population.Population;
|
import eva2.optimization.population.Population;
|
||||||
import eva2.util.annotation.Description;
|
import eva2.util.annotation.Description;
|
||||||
|
import eva2.util.annotation.Parameter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple method to select all.
|
* Simple method to select all.
|
||||||
@ -14,8 +15,7 @@ public class SelectAll implements InterfaceSelection, java.io.Serializable {
|
|||||||
|
|
||||||
private boolean obeyDebsConstViolationPrinciple = true;
|
private boolean obeyDebsConstViolationPrinciple = true;
|
||||||
|
|
||||||
public SelectAll() {
|
public SelectAll() {}
|
||||||
}
|
|
||||||
|
|
||||||
public SelectAll(SelectAll a) {
|
public SelectAll(SelectAll a) {
|
||||||
this.obeyDebsConstViolationPrinciple = a.obeyDebsConstViolationPrinciple;
|
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
|
* 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.
|
* individual.
|
||||||
*
|
*
|
||||||
* @param population The source population where to select from
|
* @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
|
* @param b The new state
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Parameter(description = "Toggle the use of Deb's constraint violation principle.")
|
||||||
public void setObeyDebsConstViolationPrinciple(boolean b) {
|
public void setObeyDebsConstViolationPrinciple(boolean b) {
|
||||||
this.obeyDebsConstViolationPrinciple = b;
|
this.obeyDebsConstViolationPrinciple = b;
|
||||||
}
|
}
|
||||||
@ -112,8 +113,4 @@ public class SelectAll implements InterfaceSelection, java.io.Serializable {
|
|||||||
public boolean getObeyDebsConstViolationPrinciple() {
|
public boolean getObeyDebsConstViolationPrinciple() {
|
||||||
return this.obeyDebsConstViolationPrinciple;
|
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.individuals.AbstractEAIndividual;
|
||||||
import eva2.optimization.operator.selection.probability.InterfaceSelectionProbability;
|
import eva2.optimization.operator.selection.probability.InterfaceSelectionProbability;
|
||||||
import eva2.optimization.operator.selection.probability.SelProbStandard;
|
import eva2.optimization.operator.selection.probability.SelectionProbabilityStandard;
|
||||||
import eva2.optimization.operator.selection.probability.SelProbStandardScaling;
|
import eva2.optimization.operator.selection.probability.SelectionProbabilityStandardScaling;
|
||||||
import eva2.optimization.population.Population;
|
import eva2.optimization.population.Population;
|
||||||
import eva2.tools.math.RNG;
|
import eva2.tools.math.RNG;
|
||||||
import eva2.util.annotation.Description;
|
import eva2.util.annotation.Description;
|
||||||
@ -23,14 +23,14 @@ public class SelectParticleWheel implements InterfaceSelection, java.io.Serializ
|
|||||||
* Comment for {@code serialVersionUID}
|
* Comment for {@code serialVersionUID}
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private InterfaceSelectionProbability selProbCalculator = new SelProbStandard();
|
private InterfaceSelectionProbability selProbCalculator = new SelectionProbabilityStandard();
|
||||||
private boolean selectFixedSteps = false;
|
private boolean selectFixedSteps = false;
|
||||||
|
|
||||||
public SelectParticleWheel() {
|
public SelectParticleWheel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public SelectParticleWheel(double scalingProb) {
|
public SelectParticleWheel(double scalingProb) {
|
||||||
selProbCalculator = new SelProbStandardScaling(scalingProb);
|
selProbCalculator = new SelectionProbabilityStandardScaling(scalingProb);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SelectParticleWheel(InterfaceSelectionProbability selProb) {
|
public SelectParticleWheel(InterfaceSelectionProbability selProb) {
|
||||||
|
@ -2,7 +2,7 @@ package eva2.optimization.operator.selection;
|
|||||||
|
|
||||||
import eva2.optimization.individuals.AbstractEAIndividual;
|
import eva2.optimization.individuals.AbstractEAIndividual;
|
||||||
import eva2.optimization.operator.selection.probability.InterfaceSelectionProbability;
|
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.optimization.population.Population;
|
||||||
import eva2.tools.math.RNG;
|
import eva2.tools.math.RNG;
|
||||||
import eva2.util.annotation.Description;
|
import eva2.util.annotation.Description;
|
||||||
@ -17,7 +17,7 @@ import eva2.util.annotation.Description;
|
|||||||
public class SelectXProbRouletteWheel implements InterfaceSelection, java.io.Serializable {
|
public class SelectXProbRouletteWheel implements InterfaceSelection, java.io.Serializable {
|
||||||
|
|
||||||
private transient TreeElement[] treeRoot = null;
|
private transient TreeElement[] treeRoot = null;
|
||||||
private InterfaceSelectionProbability selectionProbability = new SelProbStandard();
|
private InterfaceSelectionProbability selectionProbability = new SelectionProbabilityStandard();
|
||||||
private boolean obeyDebsConstViolationPrinciple = true;
|
private boolean obeyDebsConstViolationPrinciple = true;
|
||||||
|
|
||||||
public SelectXProbRouletteWheel() {
|
public SelectXProbRouletteWheel() {
|
||||||
|
@ -11,7 +11,7 @@ import java.util.ArrayList;
|
|||||||
* This abstract implementation gives some general
|
* This abstract implementation gives some general
|
||||||
* methods for retrieving and cleaning fitness values.
|
* 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
|
* 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.
|
* invariant to any linear transition function.
|
||||||
*/
|
*/
|
||||||
@Description("This is the Boltzman Normation.")
|
@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;
|
private double q = 1.0;
|
||||||
|
|
||||||
public SelProbBoltzman() {
|
public SelectionProbabilityBoltzman() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public SelProbBoltzman(double q) {
|
public SelectionProbabilityBoltzman(double q) {
|
||||||
this.q = q;
|
this.q = q;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SelProbBoltzman(SelProbBoltzman a) {
|
public SelectionProbabilityBoltzman(SelectionProbabilityBoltzman a) {
|
||||||
this.q = a.q;
|
this.q = a.q;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object clone() {
|
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.
|
* Here we have the infamous fitness sharing method.
|
||||||
*/
|
*/
|
||||||
@Description("This is a fitness sharing based normation 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 InterfaceDistanceMetric distanceMetric = new PhenotypeMetric();
|
||||||
private double sharingDistance = 0.1;
|
private double sharingDistance = 0.1;
|
||||||
|
|
||||||
public SelProbFitnessSharing() {
|
public SelectionProbabilityFitnessSharing() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public SelProbFitnessSharing(SelProbFitnessSharing a) {
|
public SelectionProbabilityFitnessSharing(SelectionProbabilityFitnessSharing a) {
|
||||||
if (a.basicNormationMethod != null) {
|
if (a.basicNormationMethod != null) {
|
||||||
this.basicNormationMethod = (InterfaceSelectionProbability) a.basicNormationMethod.clone();
|
this.basicNormationMethod = (InterfaceSelectionProbability) a.basicNormationMethod.clone();
|
||||||
}
|
}
|
||||||
@ -31,7 +31,7 @@ public class SelProbFitnessSharing extends AbstractSelProb implements java.io.Se
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
return new SelProbFitnessSharing(this);
|
return new SelectionProbabilityFitnessSharing(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
@ -10,24 +10,24 @@ import eva2.util.annotation.Description;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Description("This is a standard normation method inverted by maximum fitness.")
|
@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.;
|
private double maxFit = 1.;
|
||||||
|
|
||||||
public SelProbInvertByMax() {
|
public SelectionProbabilityInvertByMax() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public SelProbInvertByMax(double mF) {
|
public SelectionProbabilityInvertByMax(double mF) {
|
||||||
maxFit = mF;
|
maxFit = mF;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SelProbInvertByMax(SelProbInvertByMax a) {
|
public SelectionProbabilityInvertByMax(SelectionProbabilityInvertByMax a) {
|
||||||
this.maxFit = a.maxFit;
|
this.maxFit = a.maxFit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
return new SelProbInvertByMax(this);
|
return new SelectionProbabilityInvertByMax(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
@ -7,22 +7,22 @@ import eva2.util.annotation.Description;
|
|||||||
* A linear ranking method with offsets.
|
* A linear ranking method with offsets.
|
||||||
*/
|
*/
|
||||||
@Description("This is linear ranking normation.")
|
@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 nappaPlus = 1.1;
|
||||||
private double nappaMinus = 0.9;
|
private double nappaMinus = 0.9;
|
||||||
|
|
||||||
public SelProbLinearRanking() {
|
public SelectionProbabilityLinearRanking() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public SelProbLinearRanking(SelProbLinearRanking a) {
|
public SelectionProbabilityLinearRanking(SelectionProbabilityLinearRanking a) {
|
||||||
this.nappaPlus = a.nappaPlus;
|
this.nappaPlus = a.nappaPlus;
|
||||||
this.nappaMinus = a.nappaMinus;
|
this.nappaMinus = a.nappaMinus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
return new SelProbLinearRanking(this);
|
return new SelectionProbabilityLinearRanking(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
@ -8,24 +8,24 @@ import eva2.util.annotation.Description;
|
|||||||
* the given optimization problem i guess.
|
* the given optimization problem i guess.
|
||||||
*/
|
*/
|
||||||
@Description("This is non-linear ranking normation.")
|
@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;
|
private double c = 0.04;
|
||||||
|
|
||||||
public SelProbNonLinearRanking() {
|
public SelectionProbabilityNonLinearRanking() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public SelProbNonLinearRanking(double theC) {
|
public SelectionProbabilityNonLinearRanking(double theC) {
|
||||||
this.c = theC;
|
this.c = theC;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SelProbNonLinearRanking(SelProbNonLinearRanking a) {
|
public SelectionProbabilityNonLinearRanking(SelectionProbabilityNonLinearRanking a) {
|
||||||
this.c = a.c;
|
this.c = a.c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
return new SelProbNonLinearRanking(this);
|
return new SelectionProbabilityNonLinearRanking(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
@ -8,17 +8,17 @@ import eva2.util.annotation.Description;
|
|||||||
* This truly scaling invariant.
|
* This truly scaling invariant.
|
||||||
*/
|
*/
|
||||||
@Description("This is ranking normation.")
|
@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
|
@Override
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
return new SelProbRanking(this);
|
return new SelectionProbabilityRanking(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
@ -9,17 +9,17 @@ import eva2.util.annotation.Description;
|
|||||||
* p(i is selected) = exp(-fitness(i))/sum_j(exp(-fitness(j)))
|
* p(i is selected) = exp(-fitness(i))/sum_j(exp(-fitness(j)))
|
||||||
*/
|
*/
|
||||||
@Description("This is a standard normation method using the exp function.")
|
@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
|
@Override
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
return new SelProbStandard(this);
|
return new SelectionProbabilityStandard(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
@ -7,24 +7,24 @@ import eva2.util.annotation.Description;
|
|||||||
* A simple sum with a scaling factor.
|
* A simple sum with a scaling factor.
|
||||||
*/
|
*/
|
||||||
@Description("This is a standard normation method with scaling.")
|
@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;
|
private double Q = 0;
|
||||||
|
|
||||||
public SelProbStandardScaling() {
|
public SelectionProbabilityStandardScaling() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public SelProbStandardScaling(double q) {
|
public SelectionProbabilityStandardScaling(double q) {
|
||||||
Q = q;
|
Q = q;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SelProbStandardScaling(SelProbStandardScaling a) {
|
public SelectionProbabilityStandardScaling(SelectionProbabilityStandardScaling a) {
|
||||||
this.Q = a.Q;
|
this.Q = a.Q;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
return new SelProbStandardScaling(this);
|
return new SelectionProbabilityStandardScaling(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
@ -5,6 +5,7 @@ import eva2.optimization.operator.distancemetric.PhenotypeMetric;
|
|||||||
import eva2.optimization.population.Population;
|
import eva2.optimization.population.Population;
|
||||||
import eva2.optimization.population.PopulationInterface;
|
import eva2.optimization.population.PopulationInterface;
|
||||||
import eva2.util.annotation.Description;
|
import eva2.util.annotation.Description;
|
||||||
|
import eva2.util.annotation.Parameter;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
@ -40,6 +41,7 @@ public class DiversityTerminator extends PopulationMeasureTerminator implements
|
|||||||
/**
|
/**
|
||||||
* @return the metric
|
* @return the metric
|
||||||
*/
|
*/
|
||||||
|
@Parameter(description = "Set the metric to be used to calculate individual distances.")
|
||||||
public InterfaceDistanceMetric getMetric() {
|
public InterfaceDistanceMetric getMetric() {
|
||||||
return metric;
|
return metric;
|
||||||
}
|
}
|
||||||
@ -48,13 +50,10 @@ public class DiversityTerminator extends PopulationMeasureTerminator implements
|
|||||||
this.metric = metric;
|
this.metric = metric;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String metricTipText() {
|
|
||||||
return "Set the metric to be used to calculate individual distances.";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the criterion
|
* @return the criterion
|
||||||
*/
|
*/
|
||||||
|
@Parameter(description = "Define the distance criterion to check for in a population.")
|
||||||
public DiversityCriterion getCriterion() {
|
public DiversityCriterion getCriterion() {
|
||||||
return criterion;
|
return criterion;
|
||||||
}
|
}
|
||||||
@ -63,17 +62,13 @@ public class DiversityTerminator extends PopulationMeasureTerminator implements
|
|||||||
this.criterion = criterion;
|
this.criterion = criterion;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String criterionTipText() {
|
@Override
|
||||||
return "Define the distance criterion to check for in a population.";
|
protected double calculateInitialMeasure(PopulationInterface pop) {
|
||||||
|
return calculatePopulationMeasure(pop);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double calcInitialMeasure(PopulationInterface pop) {
|
protected double calculatePopulationMeasure(PopulationInterface pop) {
|
||||||
return calcPopulationMeasure(pop);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected double calcPopulationMeasure(PopulationInterface pop) {
|
|
||||||
double[] measures = ((Population) pop).getPopulationMeasures(metric);
|
double[] measures = ((Population) pop).getPopulationMeasures(metric);
|
||||||
int measureIndex = criterion.ordinal();
|
int measureIndex = criterion.ordinal();
|
||||||
return measures[measureIndex];
|
return measures[measureIndex];
|
||||||
|
@ -23,8 +23,7 @@ public class EvaluationTerminator implements InterfaceTerminator,
|
|||||||
*/
|
*/
|
||||||
protected int maxFitnessCalls = 1000;
|
protected int maxFitnessCalls = 1000;
|
||||||
|
|
||||||
public EvaluationTerminator() {
|
public EvaluationTerminator() {}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(InterfaceOptimizationProblem prob) {
|
public void initialize(InterfaceOptimizationProblem prob) {
|
||||||
|
@ -30,12 +30,12 @@ public class FitnessConvergenceTerminator extends PopulationMeasureTerminator
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double calcInitialMeasure(PopulationInterface pop) {
|
protected double calculateInitialMeasure(PopulationInterface pop) {
|
||||||
return Mathematics.norm(pop.getBestFitness());
|
return Mathematics.norm(pop.getBestFitness());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double calcPopulationMeasure(PopulationInterface pop) {
|
protected double calculatePopulationMeasure(PopulationInterface pop) {
|
||||||
// if (oldFit==null) return Double.MAX_VALUE;
|
// if (oldFit==null) return Double.MAX_VALUE;
|
||||||
// return EuclideanMetric.euclideanDistance(oldFit, pop.getBestFitness());
|
// return EuclideanMetric.euclideanDistance(oldFit, pop.getBestFitness());
|
||||||
return Mathematics.norm(pop.getBestFitness());
|
return Mathematics.norm(pop.getBestFitness());
|
||||||
|
@ -44,8 +44,8 @@ public class FitnessValueTerminator implements InterfaceTerminator,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isTerminated(PopulationInterface Pop) {
|
public boolean isTerminated(PopulationInterface pop) {
|
||||||
double[] fit = Pop.getBestFitness();
|
double[] fit = pop.getBestFitness();
|
||||||
for (int i = 0; i < fit.length; i++) {
|
for (int i = 0; i < fit.length; i++) {
|
||||||
if (fitnessValue[i] < fit[i]) {
|
if (fitnessValue[i] < fit[i]) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -4,6 +4,7 @@ import eva2.optimization.population.InterfaceSolutionSet;
|
|||||||
import eva2.optimization.population.PopulationInterface;
|
import eva2.optimization.population.PopulationInterface;
|
||||||
import eva2.problems.InterfaceOptimizationProblem;
|
import eva2.problems.InterfaceOptimizationProblem;
|
||||||
import eva2.util.annotation.Description;
|
import eva2.util.annotation.Description;
|
||||||
|
import eva2.util.annotation.Parameter;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
@ -24,8 +25,7 @@ public class GenerationTerminator implements InterfaceTerminator, Serializable {
|
|||||||
msg = "Not terminated.";
|
msg = "Not terminated.";
|
||||||
}
|
}
|
||||||
|
|
||||||
public GenerationTerminator() {
|
public GenerationTerminator() {}
|
||||||
}
|
|
||||||
|
|
||||||
public GenerationTerminator(int gens) {
|
public GenerationTerminator(int gens) {
|
||||||
maxGenerations = gens;
|
maxGenerations = gens;
|
||||||
@ -37,8 +37,8 @@ public class GenerationTerminator implements InterfaceTerminator, Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isTerminated(PopulationInterface Pop) {
|
public boolean isTerminated(PopulationInterface pop) {
|
||||||
if (maxGenerations < Pop.getGeneration()) {
|
if (maxGenerations < pop.getGeneration()) {
|
||||||
msg = maxGenerations + " generations reached.";
|
msg = maxGenerations + " generations reached.";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -52,10 +52,10 @@ public class GenerationTerminator implements InterfaceTerminator, Serializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String ret = "Generations calls=" + maxGenerations;
|
return "Generations calls=" + maxGenerations;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Parameter(description = "Number of generations to evaluate.")
|
||||||
public void setGenerations(int x) {
|
public void setGenerations(int x) {
|
||||||
maxGenerations = x;
|
maxGenerations = x;
|
||||||
}
|
}
|
||||||
@ -63,13 +63,4 @@ public class GenerationTerminator implements InterfaceTerminator, Serializable {
|
|||||||
public int getGenerations() {
|
public int getGenerations() {
|
||||||
return maxGenerations;
|
return maxGenerations;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the tip text for this property
|
|
||||||
*
|
|
||||||
* @return tip text for this property
|
|
||||||
*/
|
|
||||||
public String generationsTipText() {
|
|
||||||
return "number of generations to evaluate.";
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -7,6 +7,7 @@ import eva2.problems.InterfaceMultimodalProblemKnown;
|
|||||||
import eva2.problems.InterfaceOptimizationProblem;
|
import eva2.problems.InterfaceOptimizationProblem;
|
||||||
import eva2.tools.EVAERROR;
|
import eva2.tools.EVAERROR;
|
||||||
import eva2.util.annotation.Description;
|
import eva2.util.annotation.Description;
|
||||||
|
import eva2.util.annotation.Parameter;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -25,16 +26,15 @@ public class KnownOptimaFoundTerminator implements InterfaceTerminator, Serializ
|
|||||||
private int reqOptima = 1;
|
private int reqOptima = 1;
|
||||||
private String msg = "";
|
private String msg = "";
|
||||||
|
|
||||||
public KnownOptimaFoundTerminator() {
|
public KnownOptimaFoundTerminator() {}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(InterfaceOptimizationProblem prob) {
|
public void initialize(InterfaceOptimizationProblem prob) throws IllegalArgumentException {
|
||||||
if (prob != null) {
|
if (prob != null) {
|
||||||
if (prob instanceof InterfaceMultimodalProblemKnown) {
|
if (prob instanceof InterfaceMultimodalProblemKnown) {
|
||||||
mProblem = (InterfaceMultimodalProblemKnown) prob;
|
mProblem = (InterfaceMultimodalProblemKnown) prob;
|
||||||
} else {
|
} else {
|
||||||
LOGGER.log(Level.WARNING, "KnownOptimaFoundTerminator only works with InterfaceMultimodalProblemKnown instances!");
|
throw new IllegalArgumentException("KnownOptimaFoundTerminator only works with InterfaceMultimodalProblemKnown instances!");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOGGER.log(Level.WARNING, "KnownOptimaFoundTerminator wont work with null problem!");
|
LOGGER.log(Level.WARNING, "KnownOptimaFoundTerminator wont work with null problem!");
|
||||||
@ -71,21 +71,18 @@ public class KnownOptimaFoundTerminator implements InterfaceTerminator, Serializ
|
|||||||
/**
|
/**
|
||||||
* @return the reqOptima
|
* @return the reqOptima
|
||||||
*/
|
*/
|
||||||
public int getReqOptima() {
|
public int getRequiredOptima() {
|
||||||
return reqOptima;
|
return reqOptima;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param reqOptima the reqOptima to set
|
* @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;
|
this.reqOptima = reqOptima;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String reqOptimaTipText() {
|
|
||||||
return "The number of optima that need to be found to terminate the optimization.";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "KnownOptimaFoundTerminator requiring " + reqOptima + " optima.";
|
return "KnownOptimaFoundTerminator requiring " + reqOptima + " optima.";
|
||||||
|
@ -9,6 +9,7 @@ import eva2.problems.AbstractMultiObjectiveOptimizationProblem;
|
|||||||
import eva2.problems.InterfaceOptimizationProblem;
|
import eva2.problems.InterfaceOptimizationProblem;
|
||||||
import eva2.tools.EVAERROR;
|
import eva2.tools.EVAERROR;
|
||||||
import eva2.util.annotation.Description;
|
import eva2.util.annotation.Description;
|
||||||
|
import eva2.util.annotation.Parameter;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
@ -50,13 +51,12 @@ public class ParetoMetricTerminator extends PopulationMeasureTerminator implemen
|
|||||||
if (prob instanceof AbstractMultiObjectiveOptimizationProblem) {
|
if (prob instanceof AbstractMultiObjectiveOptimizationProblem) {
|
||||||
moProb = (AbstractMultiObjectiveOptimizationProblem) prob;
|
moProb = (AbstractMultiObjectiveOptimizationProblem) prob;
|
||||||
} else {
|
} else {
|
||||||
moProb = null;
|
throw new IllegalArgumentException("Error, " + this.getClass() + " works only with problems inheriting from " + AbstractMultiObjectiveOptimizationProblem.class + "!");
|
||||||
EVAERROR.errorMsgOnce("Error, " + this.getClass() + " works only with problems inheriting from " + AbstractMultiObjectiveOptimizationProblem.class + "!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double calcInitialMeasure(PopulationInterface pop) {
|
protected double calculateInitialMeasure(PopulationInterface pop) {
|
||||||
if (moProb == null) {
|
if (moProb == null) {
|
||||||
return Double.MAX_VALUE;
|
return Double.MAX_VALUE;
|
||||||
} else {
|
} else {
|
||||||
@ -69,8 +69,8 @@ public class ParetoMetricTerminator extends PopulationMeasureTerminator implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double calcPopulationMeasure(PopulationInterface pop) {
|
protected double calculatePopulationMeasure(PopulationInterface pop) {
|
||||||
return calcInitialMeasure(pop);
|
return calculateInitialMeasure(pop);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -89,6 +89,7 @@ public class ParetoMetricTerminator extends PopulationMeasureTerminator implemen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Parameter(description = "The pareto metric to use")
|
||||||
public void setParetoMetric(InterfaceParetoFrontMetric pMetric) {
|
public void setParetoMetric(InterfaceParetoFrontMetric pMetric) {
|
||||||
this.pMetric = pMetric;
|
this.pMetric = pMetric;
|
||||||
}
|
}
|
||||||
@ -97,10 +98,7 @@ public class ParetoMetricTerminator extends PopulationMeasureTerminator implemen
|
|||||||
return pMetric;
|
return pMetric;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String paretoMetricTipText() {
|
@Parameter(description = "If true, the current population is used, otherwise the pareto front of the multi-objective problem instance is used")
|
||||||
return "The pareto metric to use";
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUseCurrentPop(boolean useCurrentPop) {
|
public void setUseCurrentPop(boolean useCurrentPop) {
|
||||||
this.useCurrentPop = useCurrentPop;
|
this.useCurrentPop = useCurrentPop;
|
||||||
}
|
}
|
||||||
@ -108,8 +106,4 @@ public class ParetoMetricTerminator extends PopulationMeasureTerminator implemen
|
|||||||
public boolean isUseCurrentPop() {
|
public boolean isUseCurrentPop() {
|
||||||
return useCurrentPop;
|
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";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -34,13 +34,13 @@ public class PhenotypeConvergenceTerminator extends PopulationMeasureTerminator
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double calcInitialMeasure(PopulationInterface pop) {
|
protected double calculateInitialMeasure(PopulationInterface pop) {
|
||||||
oldIndy = (AbstractEAIndividual) ((AbstractEAIndividual) pop.getBestIndividual()).clone();
|
oldIndy = (AbstractEAIndividual) ((AbstractEAIndividual) pop.getBestIndividual()).clone();
|
||||||
return Double.MAX_VALUE;
|
return Double.MAX_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double calcPopulationMeasure(PopulationInterface pop) {
|
protected double calculatePopulationMeasure(PopulationInterface pop) {
|
||||||
return pMetric.distance(oldIndy, (AbstractEAIndividual) pop.getBestIndividual());
|
return pMetric.distance(oldIndy, (AbstractEAIndividual) pop.getBestIndividual());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import eva2.optimization.individuals.IndividualWeightedFitnessComparator;
|
|||||||
import eva2.optimization.population.Population;
|
import eva2.optimization.population.Population;
|
||||||
import eva2.optimization.population.PopulationInterface;
|
import eva2.optimization.population.PopulationInterface;
|
||||||
import eva2.util.annotation.Description;
|
import eva2.util.annotation.Description;
|
||||||
|
import eva2.util.annotation.Parameter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Terminate if a score based on the archive of the population converges.
|
* 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.});
|
IndividualWeightedFitnessComparator wfComp = new IndividualWeightedFitnessComparator(new double[]{1.});
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double calcInitialMeasure(PopulationInterface pop) {
|
protected double calculateInitialMeasure(PopulationInterface pop) {
|
||||||
Population archive = ((Population) pop).getArchive();
|
Population archive = ((Population) pop).getArchive();
|
||||||
if (archive == null || (archive.size() < 1)) {
|
if (archive == null || (archive.size() < 1)) {
|
||||||
return Double.MAX_VALUE;
|
return Double.MAX_VALUE;
|
||||||
} else {
|
} else {
|
||||||
return wfComp.calcScore(archive.getBestEAIndividual(wfComp));
|
return wfComp.calculateScore(archive.getBestEAIndividual(wfComp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double calcPopulationMeasure(PopulationInterface pop) {
|
protected double calculatePopulationMeasure(PopulationInterface pop) {
|
||||||
Population archive = ((Population) pop).getArchive();
|
Population archive = ((Population) pop).getArchive();
|
||||||
if (archive == null || (archive.size() < 1)) {
|
if (archive == null || (archive.size() < 1)) {
|
||||||
return Double.MAX_VALUE;
|
return Double.MAX_VALUE;
|
||||||
} else {
|
} 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();
|
return wfComp.getFitWeights();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Parameter(description = "Weights of the fitness values in the linear combination")
|
||||||
public void setFitWeights(double[] fWeights) {
|
public void setFitWeights(double[] fWeights) {
|
||||||
wfComp.setFitWeights(fWeights);
|
wfComp.setFitWeights(fWeights);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String fitWeightsTipText() {
|
|
||||||
return wfComp.fitWeightsTipText();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import eva2.optimization.population.PopulationInterface;
|
|||||||
import eva2.optimization.population.InterfaceSolutionSet;
|
import eva2.optimization.population.InterfaceSolutionSet;
|
||||||
import eva2.problems.InterfaceOptimizationProblem;
|
import eva2.problems.InterfaceOptimizationProblem;
|
||||||
import eva2.util.annotation.Description;
|
import eva2.util.annotation.Description;
|
||||||
|
import eva2.util.annotation.Parameter;
|
||||||
|
|
||||||
import java.io.Serializable;
|
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
|
* 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
|
* if the measure m(P) behaved in a certain way for a given time. Convergence may
|
||||||
* be signaled
|
* be signaled
|
||||||
* - if the measure reached absolute values below convThresh (absolute value),
|
* - if the measure reached absolute values below convergenceThresh (absolute value),
|
||||||
* - if the measure remained within m(P)+/-convThresh (absolute change),
|
* - if the measure remained within m(P)+/-convergenceThresh (absolute change),
|
||||||
* - if the measure remained above m(P)-convThresh (absolute change and regard improvement only),
|
* - if the measure remained above m(P)-convergenceThresh (absolute change and regard improvement only),
|
||||||
* - if the measure remained within m(P)*[1-convThresh, 1+convThresh] (relative change),
|
* - if the measure remained within m(P)*[1-convergenceThresh, 1+convergenceThresh] (relative change),
|
||||||
* - if the measure remained above m(P)*(1-convThresh) (relative change and regard improvement only).
|
* - if the measure remained above m(P)*(1-convergenceThresh) (relative change and regard improvement only).
|
||||||
*/
|
*/
|
||||||
@Description("Stop if a convergence criterion has been met.")
|
@Description("Stop if a convergence criterion has been met.")
|
||||||
public abstract class PopulationMeasureTerminator implements InterfaceTerminator, Serializable {
|
public abstract class PopulationMeasureTerminator implements InterfaceTerminator, Serializable {
|
||||||
@ -28,9 +29,9 @@ public abstract class PopulationMeasureTerminator implements InterfaceTerminator
|
|||||||
|
|
||||||
public enum StagnationTypeEnum {fitnessCallBased, generationBased}
|
public enum StagnationTypeEnum {fitnessCallBased, generationBased}
|
||||||
|
|
||||||
private double convThresh = 0.01; //, convThreshLower=0.02;
|
private double convergenceThresh = 0.01;
|
||||||
private double oldMeasure = -1;
|
private double oldMeasure = -1;
|
||||||
private int stagTime = 1000;
|
private int stagnationTime = 1000;
|
||||||
private int oldPopFitCalls = 1000;
|
private int oldPopFitCalls = 1000;
|
||||||
private int oldPopGens = 1000;
|
private int oldPopGens = 1000;
|
||||||
private boolean firstTime = true;
|
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) {
|
public PopulationMeasureTerminator(double convergenceThreshold, int stagnationTime, StagnationTypeEnum stagType, ChangeTypeEnum changeType, DirectionTypeEnum dirType) {
|
||||||
this.convThresh = convergenceThreshold;
|
this.convergenceThresh = convergenceThreshold;
|
||||||
this.stagTime = stagnationTime;
|
this.stagnationTime = stagnationTime;
|
||||||
this.stagnationMeasure = stagType;
|
this.stagnationMeasure = stagType;
|
||||||
this.changeType = changeType;
|
this.changeType = changeType;
|
||||||
this.condDirection = dirType;
|
this.condDirection = dirType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PopulationMeasureTerminator(PopulationMeasureTerminator o) {
|
public PopulationMeasureTerminator(PopulationMeasureTerminator o) {
|
||||||
convThresh = o.convThresh;
|
convergenceThresh = o.convergenceThresh;
|
||||||
stagTime = o.stagTime;
|
stagnationTime = o.stagnationTime;
|
||||||
oldPopFitCalls = o.oldPopFitCalls;
|
oldPopFitCalls = o.oldPopFitCalls;
|
||||||
oldPopGens = o.oldPopGens;
|
oldPopGens = o.oldPopGens;
|
||||||
firstTime = o.firstTime;
|
firstTime = o.firstTime;
|
||||||
@ -80,16 +81,16 @@ public abstract class PopulationMeasureTerminator implements InterfaceTerminator
|
|||||||
if (!firstTime && isStillConverged(pop)) {
|
if (!firstTime && isStillConverged(pop)) {
|
||||||
|
|
||||||
if (stagnationTimeHasPassed(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();
|
msg = getTerminationMessage();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// population hasnt changed much for i<max time, keep running
|
// population hasn't changed much for i<max time, keep running
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// first call at all - or population improved more than "allowed" to terminate
|
// first call at all - or population improved more than "allowed" to terminate
|
||||||
oldMeasure = calcInitialMeasure(pop);
|
oldMeasure = calculateInitialMeasure(pop);
|
||||||
saveState(pop);
|
saveState(pop);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -100,7 +101,7 @@ public abstract class PopulationMeasureTerminator implements InterfaceTerminator
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected abstract double calcInitialMeasure(PopulationInterface pop);
|
protected abstract double calculateInitialMeasure(PopulationInterface pop);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String lastTerminationMessage() {
|
public String lastTerminationMessage() {
|
||||||
@ -114,7 +115,6 @@ public abstract class PopulationMeasureTerminator implements InterfaceTerminator
|
|||||||
*/
|
*/
|
||||||
protected String getTerminationMessage() {
|
protected String getTerminationMessage() {
|
||||||
StringBuilder sb = new StringBuilder(getMeasureName());
|
StringBuilder sb = new StringBuilder(getMeasureName());
|
||||||
// if (convergenceCondition.isSelectedString("Relative")) sb.append(" converged relatively ");
|
|
||||||
switch (changeType) {
|
switch (changeType) {
|
||||||
case absoluteChange:
|
case absoluteChange:
|
||||||
sb.append(" changed absolutely ");
|
sb.append(" changed absolutely ");
|
||||||
@ -128,15 +128,13 @@ public abstract class PopulationMeasureTerminator implements InterfaceTerminator
|
|||||||
}
|
}
|
||||||
if (doCheckImprovement()) {
|
if (doCheckImprovement()) {
|
||||||
sb.append("less than ");
|
sb.append("less than ");
|
||||||
sb.append(convThresh);
|
sb.append(convergenceThresh);
|
||||||
} else {
|
} else {
|
||||||
sb.append("within +/-");
|
sb.append("within +/-");
|
||||||
// sb.append(convThreshLower);
|
sb.append(convergenceThresh);
|
||||||
// sb.append("/");
|
|
||||||
sb.append(convThresh);
|
|
||||||
}
|
}
|
||||||
sb.append(" for ");
|
sb.append(" for ");
|
||||||
sb.append(stagTime);
|
sb.append(stagnationTime);
|
||||||
if (stagnationMeasure == StagnationTypeEnum.generationBased) {
|
if (stagnationMeasure == StagnationTypeEnum.generationBased) {
|
||||||
sb.append(" generations.");
|
sb.append(" generations.");
|
||||||
} else {
|
} else {
|
||||||
@ -159,8 +157,7 @@ public abstract class PopulationMeasureTerminator implements InterfaceTerminator
|
|||||||
* @param pop
|
* @param pop
|
||||||
*/
|
*/
|
||||||
protected void saveState(PopulationInterface pop) {
|
protected void saveState(PopulationInterface pop) {
|
||||||
// oldFit = pop.getBestFitness().clone();
|
oldMeasure = calculatePopulationMeasure(pop);
|
||||||
oldMeasure = calcPopulationMeasure(pop);
|
|
||||||
oldPopFitCalls = pop.getFunctionCalls();
|
oldPopFitCalls = pop.getFunctionCalls();
|
||||||
oldPopGens = pop.getGeneration();
|
oldPopGens = pop.getGeneration();
|
||||||
firstTime = false;
|
firstTime = false;
|
||||||
@ -173,7 +170,7 @@ public abstract class PopulationMeasureTerminator implements InterfaceTerminator
|
|||||||
* @param pop
|
* @param pop
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected abstract double calcPopulationMeasure(PopulationInterface pop);
|
protected abstract double calculatePopulationMeasure(PopulationInterface pop);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true if the population measure did not exceed the
|
* Return true if the population measure did not exceed the
|
||||||
@ -183,22 +180,21 @@ public abstract class PopulationMeasureTerminator implements InterfaceTerminator
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected boolean isStillConverged(PopulationInterface pop) {
|
protected boolean isStillConverged(PopulationInterface pop) {
|
||||||
double measure = calcPopulationMeasure(pop);
|
double measure = calculatePopulationMeasure(pop);
|
||||||
double allowedLower = Double.NEGATIVE_INFINITY, allowedUpper = Double.POSITIVE_INFINITY;
|
double allowedLower = Double.NEGATIVE_INFINITY, allowedUpper = Double.POSITIVE_INFINITY;
|
||||||
boolean ret;
|
boolean ret;
|
||||||
switch (changeType) {
|
switch (changeType) {
|
||||||
case absoluteChange:
|
case absoluteChange:
|
||||||
allowedLower = oldMeasure - convThresh;
|
allowedLower = oldMeasure - convergenceThresh;
|
||||||
if (!doCheckImprovement()) {
|
if (!doCheckImprovement()) {
|
||||||
allowedUpper = oldMeasure + convThresh;
|
allowedUpper = oldMeasure + convergenceThresh;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case absoluteValue:
|
case absoluteValue:
|
||||||
allowedUpper = convThresh;
|
allowedUpper = convergenceThresh;
|
||||||
// if (!doCheckImprovement()) allowedUpper = convThreshUpper;
|
|
||||||
break;
|
break;
|
||||||
case relativeChange:
|
case relativeChange:
|
||||||
double delta = oldMeasure * convThresh;
|
double delta = oldMeasure * convergenceThresh;
|
||||||
allowedLower = oldMeasure - delta;
|
allowedLower = oldMeasure - delta;
|
||||||
if (!doCheckImprovement()) {
|
if (!doCheckImprovement()) {
|
||||||
allowedUpper = oldMeasure + delta;
|
allowedUpper = oldMeasure + delta;
|
||||||
@ -211,7 +207,6 @@ public abstract class PopulationMeasureTerminator implements InterfaceTerminator
|
|||||||
|
|
||||||
public boolean doCheckImprovement() {
|
public boolean doCheckImprovement() {
|
||||||
return (condDirection == DirectionTypeEnum.decrease);
|
return (condDirection == DirectionTypeEnum.decrease);
|
||||||
// return condImprovementOrChange.isSelectedString("Improvement");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRelativeConvergence() {
|
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
|
* 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
|
* @param pop
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private boolean stagnationTimeHasPassed(PopulationInterface pop) {
|
private boolean stagnationTimeHasPassed(PopulationInterface pop) {
|
||||||
if (stagnationMeasure == StagnationTypeEnum.fitnessCallBased) { // by fitness calls
|
if (stagnationMeasure == StagnationTypeEnum.fitnessCallBased) { // by fitness calls
|
||||||
return (pop.getFunctionCalls() - oldPopFitCalls) >= stagTime;
|
return (pop.getFunctionCalls() - oldPopFitCalls) >= stagnationTime;
|
||||||
} else {// by generation
|
} 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) {
|
public void setConvergenceThreshold(double x) {
|
||||||
convThresh = x;
|
convergenceThresh = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getConvergenceThreshold() {
|
public double getConvergenceThreshold() {
|
||||||
return convThresh;
|
return convergenceThresh;
|
||||||
}
|
|
||||||
|
|
||||||
public String convergenceThresholdTipText() {
|
|
||||||
return "Ratio of improvement/change or absolute value of improvement/change to determine convergence.";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Parameter(description = "Terminate if the population has not improved/changed for this time")
|
||||||
public void setStagnationTime(int k) {
|
public void setStagnationTime(int k) {
|
||||||
stagTime = k;
|
stagnationTime = k;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStagnationTime() {
|
public int getStagnationTime() {
|
||||||
return stagTime;
|
return stagnationTime;
|
||||||
}
|
|
||||||
|
|
||||||
public String stagnationTimeTipText() {
|
|
||||||
return "Terminate if the population has not improved/changed for this time";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Parameter(description = "Stagnation time is measured in fitness calls or generations")
|
||||||
public StagnationTypeEnum getStagnationMeasure() {
|
public StagnationTypeEnum getStagnationMeasure() {
|
||||||
return stagnationMeasure;
|
return stagnationMeasure;
|
||||||
}
|
}
|
||||||
@ -265,31 +255,21 @@ public abstract class PopulationMeasureTerminator implements InterfaceTerminator
|
|||||||
this.stagnationMeasure = stagnationTimeIn;
|
this.stagnationMeasure = stagnationTimeIn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String stagnationMeasureTipText() {
|
|
||||||
return "Stagnation time is measured in fitness calls or generations";
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChangeTypeEnum getConvergenceCondition() {
|
public ChangeTypeEnum getConvergenceCondition() {
|
||||||
return changeType;
|
return changeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Parameter(description = "Select absolute or relative convergence condition")
|
||||||
public void setConvergenceCondition(ChangeTypeEnum convergenceCondition) {
|
public void setConvergenceCondition(ChangeTypeEnum convergenceCondition) {
|
||||||
this.changeType = convergenceCondition;
|
this.changeType = convergenceCondition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String convergenceConditionTipText() {
|
|
||||||
return "Select absolute or relative convergence condition";
|
|
||||||
}
|
|
||||||
|
|
||||||
public DirectionTypeEnum getCheckType() {
|
public DirectionTypeEnum getCheckType() {
|
||||||
return condDirection;
|
return condDirection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Parameter(description = "Detect improvement only (decreasing measure) or change in both directions (decrease and increase)")
|
||||||
public void setCheckType(DirectionTypeEnum dt) {
|
public void setCheckType(DirectionTypeEnum dt) {
|
||||||
this.condDirection = dt;
|
this.condDirection = dt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String checkTypeTipText() {
|
|
||||||
return "Detect improvement only (decreasing measure) or change in both directions (decrease and increase)";
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -7,7 +7,7 @@ import eva2.optimization.operator.distancemetric.EuclideanMetric;
|
|||||||
import eva2.optimization.operator.distancemetric.InterfaceDistanceMetric;
|
import eva2.optimization.operator.distancemetric.InterfaceDistanceMetric;
|
||||||
import eva2.optimization.operator.distancemetric.PhenotypeMetric;
|
import eva2.optimization.operator.distancemetric.PhenotypeMetric;
|
||||||
import eva2.optimization.operator.postprocess.PostProcess;
|
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.EVAERROR;
|
||||||
import eva2.tools.Pair;
|
import eva2.tools.Pair;
|
||||||
import eva2.tools.Serializer;
|
import eva2.tools.Serializer;
|
||||||
@ -722,9 +722,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
|
|||||||
this.historyList.add((AbstractEAIndividual) this.getBestEAIndividual().clone());
|
this.historyList.add((AbstractEAIndividual) this.getBestEAIndividual().clone());
|
||||||
}
|
}
|
||||||
if (isAutoAging()) {
|
if (isAutoAging()) {
|
||||||
for (AbstractEAIndividual individual : this) {
|
this.forEach(AbstractEAIndividual::incrAge);
|
||||||
individual.incrAge();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.generationCount++;
|
this.generationCount++;
|
||||||
firePropertyChangedEvent(NEXT_GENERATION_PERFORMED);
|
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
|
* @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
|
* @param comparator indicate whether constraints should be regarded
|
||||||
* @return The index of the best (worst) individual.
|
* @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);
|
ArrayList<?> sorted = getSorted(comparator);
|
||||||
if (bBest) {
|
if (bBest) {
|
||||||
return indexOf(sorted.get(0));
|
return indexOf(sorted.get(0));
|
||||||
@ -1053,7 +1051,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
|
|||||||
return getIndexOfBestOrWorstIndividual(true, comparator);
|
return getIndexOfBestOrWorstIndividual(true, comparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractEAIndividual getBestEAIndividual(Comparator<Object> comparator) {
|
public AbstractEAIndividual getBestEAIndividual(Comparator<AbstractEAIndividual> comparator) {
|
||||||
int index = getIndexOfBestOrWorstIndividual(true, comparator);
|
int index = getIndexOfBestOrWorstIndividual(true, comparator);
|
||||||
return getEAIndividual(index);
|
return getEAIndividual(index);
|
||||||
}
|
}
|
||||||
@ -1201,7 +1199,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
|
|||||||
* fitness first
|
* fitness first
|
||||||
* @see #getSortedNIndividuals(int, boolean, Population, Comparator)
|
* @see #getSortedNIndividuals(int, boolean, Population, Comparator)
|
||||||
*/
|
*/
|
||||||
public Population getSortedBestFirst(Comparator<Object> comp) {
|
public Population getSortedBestFirst(Comparator<AbstractEAIndividual> comp) {
|
||||||
Population result = this.cloneWithoutInds();
|
Population result = this.cloneWithoutInds();
|
||||||
getSortedNIndividuals(size(), true, result, comp);
|
getSortedNIndividuals(size(), true, result, comp);
|
||||||
result.synchSize();
|
result.synchSize();
|
||||||
@ -1221,7 +1219,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
|
|||||||
* @param comp the Comparator to use with individuals
|
* @param comp the Comparator to use with individuals
|
||||||
* @param res The m sorted best or worst individuals, where m <= n (will be added to res)
|
* @param res The m sorted best or worst individuals, where m <= 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())) {
|
if ((n < 0) || (n > super.size())) {
|
||||||
// this may happen, treat it gracefully
|
// this may happen, treat it gracefully
|
||||||
//System.err.println("invalid request to getSortedNIndividuals: n="+n + ", size is " + super.size());
|
//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.
|
* on AbstractEAIndividual instances.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected ArrayList<AbstractEAIndividual> sortBy(Comparator<Object> comp) {
|
protected ArrayList<AbstractEAIndividual> sortBy(Comparator<AbstractEAIndividual> comp) {
|
||||||
if (super.isEmpty()) {
|
if (super.isEmpty()) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
@ -1322,7 +1320,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
|
|||||||
* @param comp The comparator
|
* @param comp The comparator
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public ArrayList<AbstractEAIndividual> getSorted(Comparator<Object> comp) {
|
public ArrayList<AbstractEAIndividual> getSorted(Comparator<AbstractEAIndividual> comp) {
|
||||||
if (!comp.equals(lastSortingComparator) || (sortedArr == null) || (super.modCount != lastQModCount)) {
|
if (!comp.equals(lastSortingComparator) || (sortedArr == null) || (super.modCount != lastQModCount)) {
|
||||||
ArrayList<AbstractEAIndividual> sArr = sortBy(comp);
|
ArrayList<AbstractEAIndividual> sArr = sortBy(comp);
|
||||||
if (sortedArr == null) {
|
if (sortedArr == null) {
|
||||||
@ -1342,7 +1340,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
|
|||||||
*
|
*
|
||||||
* @see #getSorted(java.util.Comparator)
|
* @see #getSorted(java.util.Comparator)
|
||||||
*/
|
*/
|
||||||
public Population getSortedPop(Comparator<Object> comp) {
|
public Population getSortedPop(Comparator<AbstractEAIndividual> comp) {
|
||||||
Population pop = this.cloneWithoutInds();
|
Population pop = this.cloneWithoutInds();
|
||||||
ArrayList<AbstractEAIndividual> sortedIndies = getSorted(comp);
|
ArrayList<AbstractEAIndividual> sortedIndies = getSorted(comp);
|
||||||
pop.addAll(sortedIndies);
|
pop.addAll(sortedIndies);
|
||||||
@ -2093,7 +2091,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
|
|||||||
*/
|
*/
|
||||||
public double[] getCenter() {
|
public double[] getCenter() {
|
||||||
if (size() == 0) {
|
if (size() == 0) {
|
||||||
EVAERROR.errorMsgOnce("Invalid pop size in DistractingPopulation:getCenter!");
|
return null;
|
||||||
}
|
}
|
||||||
double[] centerPos = AbstractEAIndividual.getDoublePosition(getEAIndividual(0));
|
double[] centerPos = AbstractEAIndividual.getDoublePosition(getEAIndividual(0));
|
||||||
for (int i = 1; i < size(); i++) {
|
for (int i = 1; i < size(); i++) {
|
||||||
@ -2125,7 +2123,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
|
|||||||
*/
|
*/
|
||||||
public double[] getCenterWeighted(double[] weights) {
|
public double[] getCenterWeighted(double[] weights) {
|
||||||
if (size() == 0 || (weights.length > size()) || (weights.length == 0)) {
|
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));
|
double[] centerPos = AbstractEAIndividual.getDoublePosition(getEAIndividual(0));
|
||||||
Mathematics.svMult(weights[0], centerPos, centerPos);
|
Mathematics.svMult(weights[0], centerPos, centerPos);
|
||||||
@ -2145,7 +2143,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
|
|||||||
* @param criterion
|
* @param criterion
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public double[] getCenterWeighted(AbstractSelProb selProb, int criterion, boolean obeyConst) {
|
public double[] getCenterWeighted(AbstractSelectionProbability selProb, int criterion, boolean obeyConst) {
|
||||||
selProb.computeSelectionProbability(this, "Fitness", obeyConst);
|
selProb.computeSelectionProbability(this, "Fitness", obeyConst);
|
||||||
double[] mean = AbstractEAIndividual.getDoublePosition(getEAIndividual(0));
|
double[] mean = AbstractEAIndividual.getDoublePosition(getEAIndividual(0));
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ import java.util.Vector;
|
|||||||
public class ParticleSwarmOptimization extends AbstractOptimizer implements java.io.Serializable, InterfaceAdditionalPopulationInformer {
|
public class ParticleSwarmOptimization extends AbstractOptimizer implements java.io.Serializable, InterfaceAdditionalPopulationInformer {
|
||||||
|
|
||||||
public enum PSOType { Inertness, Constriction }
|
public enum PSOType { Inertness, Constriction }
|
||||||
Object[] sortedPop = null;
|
AbstractEAIndividual[] sortedPop = null;
|
||||||
protected AbstractEAIndividual bestIndividual = null;
|
protected AbstractEAIndividual bestIndividual = null;
|
||||||
protected boolean checkRange = true;
|
protected boolean checkRange = true;
|
||||||
protected boolean checkSpeedLimit = false;
|
protected boolean checkSpeedLimit = false;
|
||||||
@ -1299,7 +1299,7 @@ public class ParticleSwarmOptimization extends AbstractOptimizer implements java
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((topology == PSOTopology.multiSwarm) || (topology == PSOTopology.tree)) {
|
if ((topology == PSOTopology.multiSwarm) || (topology == PSOTopology.tree)) {
|
||||||
sortedPop = pop.toArray();
|
sortedPop = pop.toArray(new AbstractEAIndividual[pop.size()]);
|
||||||
if ((topology == PSOTopology.multiSwarm) || (treeStruct >= 2)) {
|
if ((topology == PSOTopology.multiSwarm) || (treeStruct >= 2)) {
|
||||||
Arrays.sort(sortedPop, new EAIndividualComparator());
|
Arrays.sort(sortedPop, new EAIndividualComparator());
|
||||||
} else {
|
} else {
|
||||||
|
@ -3,9 +3,6 @@ package eva2.tools;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by halfdan on 17/12/15.
|
|
||||||
*/
|
|
||||||
public class Primitives {
|
public class Primitives {
|
||||||
public static Class<?> unwrap(Class<?> clazz) {
|
public static Class<?> unwrap(Class<?> clazz) {
|
||||||
return getWrapperTypes().get(clazz);
|
return getWrapperTypes().get(clazz);
|
||||||
|
@ -71,9 +71,6 @@ public class SelectedTag implements java.io.Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//~ Methods ////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the selected tag by index.
|
* Set the selected tag by index.
|
||||||
*
|
*
|
||||||
@ -197,23 +194,5 @@ public class SelectedTag implements java.io.Serializable {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return tags[selectedId].getString();
|
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,18 +2,43 @@ package eva2.optimization.individuals;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public class AbstractEAIndividualTest {
|
public class AbstractEAIndividualTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsDominatingFitness() throws Exception {
|
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
|
@Test
|
||||||
public void testIsDominatingFitnessNotEqual() throws Exception {
|
public void testIsDominatingFitnessNotEqual() throws Exception {
|
||||||
|
// Single objective
|
||||||
|
double[] fit1 = new double[]{415.231322};
|
||||||
|
|
||||||
|
// Is not dominating itself
|
||||||
|
assertFalse(AbstractEAIndividual.isDominatingFitnessNotEqual(fit1, fit1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -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}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -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 {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,14 @@
|
|||||||
package eva2.optimization.population;
|
package eva2.optimization.population;
|
||||||
|
|
||||||
|
import com.sun.org.apache.bcel.internal.generic.POP;
|
||||||
|
import eva2.optimization.individuals.AbstractEAIndividual;
|
||||||
import eva2.optimization.individuals.ESIndividualDoubleData;
|
import eva2.optimization.individuals.ESIndividualDoubleData;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.*;
|
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 {
|
public class PopulationTest {
|
||||||
Population emptyPopulation;
|
Population emptyPopulation;
|
||||||
@ -18,11 +23,6 @@ public class PopulationTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testPutData() throws Exception {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetData() throws Exception {
|
public void testGetData() throws Exception {
|
||||||
// Simple data
|
// Simple data
|
||||||
@ -182,8 +182,13 @@ public class PopulationTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testIncrGeneration() throws Exception {
|
public void testIncrGeneration() throws Exception {
|
||||||
int currentGeneration = emptyPopulation.getGeneration();
|
int currentGeneration = emptyPopulation.getGeneration();
|
||||||
|
InterfacePopulationChangedEventListener listener = mock(InterfacePopulationChangedEventListener.class);
|
||||||
|
|
||||||
|
emptyPopulation.addPopulationChangedEventListener(listener);
|
||||||
emptyPopulation.incrGeneration();
|
emptyPopulation.incrGeneration();
|
||||||
|
|
||||||
|
verify(listener).registerPopulationStateChanged(emptyPopulation, Population.NEXT_GENERATION_PERFORMED);
|
||||||
|
|
||||||
assertEquals(currentGeneration + 1, emptyPopulation.getGeneration());
|
assertEquals(currentGeneration + 1, emptyPopulation.getGeneration());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,11 +209,6 @@ public class PopulationTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testAddPopulation1() throws Exception {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResetFitness() throws Exception {
|
public void testResetFitness() throws Exception {
|
||||||
|
|
||||||
@ -219,11 +219,6 @@ public class PopulationTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetDominatingSet1() throws Exception {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetIndexOfBestIndividualPrefFeasible() throws Exception {
|
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
|
@Test
|
||||||
public void testMoveNInds() throws Exception {
|
public void testMoveNInds() throws Exception {
|
||||||
|
|
||||||
@ -319,11 +304,6 @@ public class PopulationTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetCorrelations1() throws Exception {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetFitnessMeasures() throws Exception {
|
public void testGetFitnessMeasures() throws Exception {
|
||||||
|
|
||||||
@ -331,7 +311,17 @@ public class PopulationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCenter() throws Exception {
|
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
|
@Test
|
||||||
@ -351,7 +341,15 @@ public class PopulationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetFitSum() throws Exception {
|
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
|
@Test
|
||||||
@ -371,7 +369,12 @@ public class PopulationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetFreeSlots() throws Exception {
|
public void testGetFreeSlots() throws Exception {
|
||||||
|
assertEquals(10, emptyPopulation.getFreeSlots());
|
||||||
|
|
||||||
|
ESIndividualDoubleData indy = mock(ESIndividualDoubleData.class);
|
||||||
|
emptyPopulation.add(indy);
|
||||||
|
|
||||||
|
assertEquals(9, emptyPopulation.getFreeSlots());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@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
|
@Test
|
||||||
public void testFilterByFitness() throws Exception {
|
public void testFilterByFitness() throws Exception {
|
||||||
ESIndividualDoubleData indy1, indy2, indy3;
|
ESIndividualDoubleData indy1, indy2, indy3;
|
||||||
@ -401,4 +417,29 @@ public class PopulationTest {
|
|||||||
// Get all individuals with fitness <= 10.0 (first fitness dimension)
|
// Get all individuals with fitness <= 10.0 (first fitness dimension)
|
||||||
assertEquals(2, emptyPopulation.filterByFitness(10.0, 0).size());
|
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 {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user