Abstract getProblemDimension into InterfaceOptimizationProblem
closes #26 - Clean up problems that implemented getProblemDimension - Move getProblemDimension to Interface and implement it in AbstractOptimizationProblem - Output the problem dimension in the Processor (e.g. when running an optimization)
This commit is contained in:
parent
5799e6bdd2
commit
f43e575b18
@ -19,6 +19,7 @@ import eva2.optimization.statistics.InterfaceStatistics;
|
||||
import eva2.optimization.statistics.InterfaceTextListener;
|
||||
import eva2.optimization.statistics.StatisticsWithGUI;
|
||||
import eva2.optimization.strategies.InterfaceOptimizer;
|
||||
import eva2.problems.InterfaceOptimizationProblem;
|
||||
import eva2.tools.EVAERROR;
|
||||
import eva2.tools.StringTools;
|
||||
import eva2.tools.math.RNG;
|
||||
@ -402,7 +403,9 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
||||
|
||||
@Override
|
||||
public String getInfoString() {
|
||||
return this.optimizationParameters.getProblem().getName() + "+" + this.optimizationParameters.getOptimizer().getName();
|
||||
InterfaceOptimizationProblem problem = this.optimizationParameters.getProblem();
|
||||
|
||||
return problem.getName() + "{" + problem.getProblemDimension() + "}+" + this.optimizationParameters.getOptimizer().getName();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -136,10 +136,6 @@ public abstract class AbstractDynTransProblem extends AbstractSynchronousOptimiz
|
||||
}
|
||||
}
|
||||
|
||||
public int getProblemDimension() {
|
||||
return problemDimension;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStringRepresentationForProblem(InterfaceOptimizer opt) {
|
||||
return "DynTransProblem";
|
||||
|
@ -379,9 +379,4 @@ public abstract class AbstractMultiModalProblemKnown extends AbstractProblemDoub
|
||||
public void setDefaultAccuracy(double epsilon) {
|
||||
super.setDefaultAccuracy(epsilon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProblemDimension() {
|
||||
return problemDimension;
|
||||
}
|
||||
}
|
@ -24,6 +24,7 @@ import eva2.optimization.population.Population;
|
||||
import eva2.optimization.population.PopulationInterface;
|
||||
import eva2.optimization.strategies.InterfaceOptimizer;
|
||||
import eva2.tools.ToolBox;
|
||||
import eva2.util.annotation.Parameter;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@ -71,8 +72,12 @@ public abstract class AbstractOptimizationProblem implements InterfaceOptimizati
|
||||
|
||||
protected AbstractEAIndividual template = null;
|
||||
|
||||
@Parameter(name = "defaultAccuracy", description = "A default threshold to identify optima - e.g. the assumed minimal distance between any two optima.")
|
||||
private double defaultAccuracy = 0.001; // default accuracy for identifying optima.
|
||||
|
||||
@Parameter(name = "problemDimension", description = "Length of the x vector to be optimized.")
|
||||
protected int problemDimension = 10;
|
||||
|
||||
/**
|
||||
* This method returns a deep clone of the problem.
|
||||
*
|
||||
@ -562,10 +567,6 @@ public abstract class AbstractOptimizationProblem implements InterfaceOptimizati
|
||||
defaultAccuracy = defAcc;
|
||||
}
|
||||
|
||||
public String defaultAccuracyTipText() {
|
||||
return "A default threshold to identify optima - e.g. the assumed minimal distance between any two optima.";
|
||||
}
|
||||
|
||||
/**
|
||||
* This method allows the CommonJavaObjectEditorPanel to read the
|
||||
* name to the current object.
|
||||
@ -577,6 +578,11 @@ public abstract class AbstractOptimizationProblem implements InterfaceOptimizati
|
||||
return "AbstractOptimizationProblem";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProblemDimension() {
|
||||
return this.problemDimension;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a global info string
|
||||
*
|
||||
|
@ -54,13 +54,6 @@ public abstract class AbstractProblemBinary extends AbstractOptimizationProblem
|
||||
*/
|
||||
public abstract double[] eval(BitSet bs);
|
||||
|
||||
/**
|
||||
* Get the problem dimension.
|
||||
*
|
||||
* @return the problem dimension
|
||||
*/
|
||||
public abstract int getProblemDimension();
|
||||
|
||||
@Override
|
||||
public void initializePopulation(Population population) {
|
||||
((InterfaceDataTypeBinary) this.template).setBinaryDataLength(this.getProblemDimension());
|
||||
|
@ -202,14 +202,6 @@ public abstract class AbstractProblemDouble extends AbstractOptimizationProblem
|
||||
@Override
|
||||
public abstract double[] evaluate(double[] x);
|
||||
|
||||
/**
|
||||
* Get the problem dimension.
|
||||
*
|
||||
* @return the problem dimension
|
||||
*/
|
||||
@Override
|
||||
public abstract int getProblemDimension();
|
||||
|
||||
@Override
|
||||
public void initializePopulation(Population population) {
|
||||
initTemplate();
|
||||
|
@ -87,14 +87,5 @@ public abstract class AbstractProblemDoubleOffset extends AbstractProblemDouble
|
||||
public void setProblemDimension(int t) {
|
||||
this.problemDimension = t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProblemDimension() {
|
||||
return this.problemDimension;
|
||||
}
|
||||
|
||||
public String problemDimensionTipText() {
|
||||
return "Length of the x vector to be optimized.";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,14 +118,6 @@ public abstract class AbstractProblemInteger extends AbstractOptimizationProblem
|
||||
this.problemDimension = n;
|
||||
}
|
||||
|
||||
public int getProblemDimension() {
|
||||
return this.problemDimension;
|
||||
}
|
||||
|
||||
public String problemDimensionTipText() {
|
||||
return "Length of the integer vector to be optimized";
|
||||
}
|
||||
|
||||
/**
|
||||
* This method allows you to choose the EA individual
|
||||
*
|
||||
|
@ -119,11 +119,6 @@ public class B1Problem extends AbstractProblemBinary implements java.io.Serializ
|
||||
this.problemDimension = dim;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProblemDimension() {
|
||||
return this.problemDimension;
|
||||
}
|
||||
|
||||
public String multiRunsTipText() {
|
||||
return "Length of the BitSet that is to be optimized.";
|
||||
}
|
||||
|
@ -364,15 +364,6 @@ public class ExternalRuntimeProblem extends AbstractOptimizationProblem
|
||||
this.initializationRange.adaptRowCount(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProblemDimension() {
|
||||
return this.problemDimension;
|
||||
}
|
||||
|
||||
public String problemDimensionTipText() {
|
||||
return "Domain dimension of the problem";
|
||||
}
|
||||
|
||||
/**
|
||||
* Length of the x vector at is to be optimized
|
||||
*
|
||||
|
@ -47,11 +47,6 @@ public class F15Problem extends AbstractProblemDouble implements Serializable, I
|
||||
return y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProblemDimension() {
|
||||
return problemDimension;
|
||||
}
|
||||
|
||||
public void setProblemDimension(int d) {
|
||||
problemDimension = d;
|
||||
}
|
||||
|
@ -9,18 +9,18 @@ import eva2.util.annotation.Description;
|
||||
*/
|
||||
@Description("Vincent function: Multiple optima with increasing densitiy near the lower bounds, therefore decreasing attractor size. All have an equal best fitness of zero")
|
||||
public class F16Problem extends AbstractProblemDouble implements InterfaceMultimodalProblem, Interface2DBorderProblem, InterfaceInterestingHistogram {
|
||||
int dim = 10;
|
||||
int problemDimension = 10;
|
||||
|
||||
public F16Problem() {
|
||||
dim = 10;
|
||||
problemDimension = 10;
|
||||
}
|
||||
|
||||
public F16Problem(F16Problem other) {
|
||||
dim = other.dim;
|
||||
problemDimension = other.problemDimension;
|
||||
}
|
||||
|
||||
public F16Problem(int theDim) {
|
||||
this.dim = theDim;
|
||||
this.problemDimension = theDim;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -37,13 +37,8 @@ public class F16Problem extends AbstractProblemDouble implements InterfaceMultim
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProblemDimension() {
|
||||
return dim;
|
||||
}
|
||||
|
||||
public void setProblemDimension(int newDim) {
|
||||
dim = newDim;
|
||||
problemDimension = newDim;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -12,11 +12,11 @@ import eva2.util.annotation.Description;
|
||||
@Description("Bohachevsky function, numerous optima on an oval hyperparabola with similar attractor sizes but decreasing fitness towards the bounds")
|
||||
public class F17Problem extends AbstractProblemDouble implements
|
||||
InterfaceMultimodalProblem, InterfaceInterestingHistogram {
|
||||
int dim = 10;
|
||||
int problemDimension = 10;
|
||||
|
||||
public F17Problem() {
|
||||
setDefaultRange(10.);
|
||||
dim = 10;
|
||||
problemDimension = 10;
|
||||
}
|
||||
|
||||
public F17Problem(int dimension) {
|
||||
@ -26,7 +26,7 @@ public class F17Problem extends AbstractProblemDouble implements
|
||||
|
||||
public F17Problem(F17Problem other) {
|
||||
super(other);
|
||||
dim = other.dim;
|
||||
problemDimension = other.problemDimension;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -42,13 +42,8 @@ public class F17Problem extends AbstractProblemDouble implements
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProblemDimension() {
|
||||
return dim;
|
||||
}
|
||||
|
||||
public void setProblemDimension(int newDim) {
|
||||
dim = newDim;
|
||||
problemDimension = newDim;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -8,15 +8,15 @@ import eva2.util.annotation.Description;
|
||||
@Description("N-Function from Shir&Baeck, PPSN 2006")
|
||||
public class F18Problem extends AbstractProblemDouble implements
|
||||
InterfaceMultimodalProblem {
|
||||
int dim = 10;
|
||||
int problemDimension = 10;
|
||||
double alpha = 1.;
|
||||
|
||||
public F18Problem() {
|
||||
dim = 10;
|
||||
problemDimension = 10;
|
||||
}
|
||||
|
||||
public F18Problem(F18Problem other) {
|
||||
dim = other.dim;
|
||||
problemDimension = other.problemDimension;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -41,13 +41,8 @@ public class F18Problem extends AbstractProblemDouble implements
|
||||
return 1.;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProblemDimension() {
|
||||
return dim;
|
||||
}
|
||||
|
||||
public void setProblemDimension(int newDim) {
|
||||
dim = newDim;
|
||||
problemDimension = newDim;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -15,19 +15,19 @@ import java.util.Random;
|
||||
@Description("Fletcher-Powell function")
|
||||
public class F19Problem extends AbstractProblemDouble implements
|
||||
InterfaceMultimodalProblem, InterfaceInterestingHistogram, InterfaceFirstOrderDerivableProblem {
|
||||
int dim = 10;
|
||||
int problemDimension = 10;
|
||||
transient private double[] alphas, As;
|
||||
transient private int[] A, B;
|
||||
private long randSeed = 23;
|
||||
|
||||
public F19Problem() {
|
||||
alphas = null;
|
||||
dim = 10;
|
||||
problemDimension = 10;
|
||||
setDefaultRange(Math.PI);
|
||||
}
|
||||
|
||||
public F19Problem(F19Problem other) {
|
||||
dim = other.dim;
|
||||
problemDimension = other.problemDimension;
|
||||
alphas = null;
|
||||
}
|
||||
|
||||
@ -42,17 +42,17 @@ public class F19Problem extends AbstractProblemDouble implements
|
||||
// create static random data
|
||||
Random rand = new Random();
|
||||
rand.setSeed(randSeed);
|
||||
alphas = RNG.randomDoubleArray(rand, -Math.PI, Math.PI, dim);
|
||||
A = RNG.randomIntArray(rand, -100, 100, dim * dim);
|
||||
B = RNG.randomIntArray(rand, -100, 100, dim * dim);
|
||||
alphas = RNG.randomDoubleArray(rand, -Math.PI, Math.PI, problemDimension);
|
||||
A = RNG.randomIntArray(rand, -100, 100, problemDimension * problemDimension);
|
||||
B = RNG.randomIntArray(rand, -100, 100, problemDimension * problemDimension);
|
||||
As = transform(alphas);
|
||||
}
|
||||
|
||||
private double[] transform(double[] x) {
|
||||
double[] v = new double[dim];
|
||||
double[] v = new double[problemDimension];
|
||||
Arrays.fill(v, 0.);
|
||||
for (int i = 0; i < dim; i++) {
|
||||
for (int j = 0; j < dim; j++) {
|
||||
for (int i = 0; i < problemDimension; i++) {
|
||||
for (int j = 0; j < problemDimension; j++) {
|
||||
v[i] += get(A, i, j) * Math.sin(x[j]) + get(B, i, j) * Math.cos(x[j]);
|
||||
}
|
||||
}
|
||||
@ -80,7 +80,7 @@ public class F19Problem extends AbstractProblemDouble implements
|
||||
* @return
|
||||
*/
|
||||
private int get(int[] M, int i, int j) {
|
||||
return M[i * dim + j];
|
||||
return M[i * problemDimension + j];
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -97,13 +97,8 @@ public class F19Problem extends AbstractProblemDouble implements
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProblemDimension() {
|
||||
return dim;
|
||||
}
|
||||
|
||||
public void setProblemDimension(int newDim) {
|
||||
dim = newDim;
|
||||
problemDimension = newDim;
|
||||
if (alphas != null && (newDim > alphas.length)) { // only recreate if really necessary
|
||||
alphas = null;
|
||||
A = null;
|
||||
|
@ -21,23 +21,23 @@ import java.io.Serializable;
|
||||
"The minimum fitness f(x*) is close to (n-1)*r for dimension n and default range r, by which " +
|
||||
"this implementation may be shifted to the positive domain.")
|
||||
public class F20Problem extends AbstractProblemDouble implements Serializable, InterfaceInterestingHistogram {
|
||||
private int dim = 10;
|
||||
private int problemDimension = 10;
|
||||
private boolean shiftFit = false;
|
||||
|
||||
public F20Problem() {
|
||||
setDefaultRange(512.);
|
||||
}
|
||||
|
||||
public F20Problem(int dim, boolean rotate) {
|
||||
public F20Problem(int problemDimension, boolean rotate) {
|
||||
this();
|
||||
setProblemDimension(dim);
|
||||
setProblemDimension(problemDimension);
|
||||
setDoRotation(rotate);
|
||||
}
|
||||
|
||||
public F20Problem(F20Problem o) {
|
||||
super(o);
|
||||
setDefaultRange(512);
|
||||
this.dim = o.dim;
|
||||
this.problemDimension = o.problemDimension;
|
||||
this.setShiftFit(o.isShiftFit());
|
||||
}
|
||||
|
||||
@ -70,13 +70,8 @@ public class F20Problem extends AbstractProblemDouble implements Serializable, I
|
||||
return Math.sqrt(Math.abs(x + y + 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProblemDimension() {
|
||||
return dim;
|
||||
}
|
||||
|
||||
public void setProblemDimension(int newDim) {
|
||||
dim = newDim;
|
||||
problemDimension = newDim;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -16,7 +16,7 @@ public class F21Problem extends AbstractProblemDouble implements InterfaceMultim
|
||||
private double[] heights = null; // will receive random positions within the range
|
||||
private double[][] peaks = null; // will receive values in [0,1] as peak height values
|
||||
private static final int rndSeed = 23;
|
||||
private int dim = 2;
|
||||
private int problemDimension = 2;
|
||||
|
||||
public F21Problem() {
|
||||
}
|
||||
@ -76,13 +76,8 @@ public class F21Problem extends AbstractProblemDouble implements InterfaceMultim
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProblemDimension() {
|
||||
return dim;
|
||||
}
|
||||
|
||||
public void setProblemDimension(int d) {
|
||||
dim = d;
|
||||
problemDimension = d;
|
||||
}
|
||||
|
||||
public String problemDimensionTipText() {
|
||||
|
@ -530,14 +530,6 @@ public class FLensProblem extends AbstractOptimizationProblem
|
||||
this.problemDimension = multiruns;
|
||||
}
|
||||
|
||||
public int getProblemDimension() {
|
||||
return this.problemDimension;
|
||||
}
|
||||
|
||||
public String problemDimensionTipText() {
|
||||
return "Length of the x vector at is to be optimized.";
|
||||
}
|
||||
|
||||
/**
|
||||
* This method allows you to toggle the solution representation.
|
||||
*
|
||||
|
@ -17,7 +17,7 @@ public class GPFunctionProblem extends AbstractProblemDouble implements Interfac
|
||||
InterfaceProgram gpProblem = null;
|
||||
GPArea gpArea = new GPArea();
|
||||
double[] pos = null;
|
||||
int dim = 2;
|
||||
int problemDimension = 2;
|
||||
double scalingStart = 10.;
|
||||
double scalingLimit = 20.;
|
||||
|
||||
@ -56,8 +56,8 @@ public class GPFunctionProblem extends AbstractProblemDouble implements Interfac
|
||||
* @param scLim
|
||||
*/
|
||||
public GPFunctionProblem(InterfaceProgram gpProb, GPArea area, int pDim, double scStart, double scLim) {
|
||||
dim = pDim;
|
||||
((ESIndividualDoubleData) template).setDoubleDataLength(dim);
|
||||
problemDimension = pDim;
|
||||
((ESIndividualDoubleData) template).setDoubleDataLength(problemDimension);
|
||||
gpProblem = gpProb;
|
||||
gpArea = area;
|
||||
scalingStart = scStart;
|
||||
@ -65,10 +65,10 @@ public class GPFunctionProblem extends AbstractProblemDouble implements Interfac
|
||||
}
|
||||
|
||||
public GPFunctionProblem(GPFunctionProblem functionProblem) {
|
||||
dim = functionProblem.dim;
|
||||
problemDimension = functionProblem.problemDimension;
|
||||
if (functionProblem.pos != null) {
|
||||
pos = new double[dim];
|
||||
System.arraycopy(functionProblem.pos, 0, pos, 0, dim);
|
||||
pos = new double[problemDimension];
|
||||
System.arraycopy(functionProblem.pos, 0, pos, 0, problemDimension);
|
||||
}
|
||||
gpArea = (GPArea) functionProblem.gpArea.clone();
|
||||
gpProblem = functionProblem.gpProblem;
|
||||
@ -81,7 +81,7 @@ public class GPFunctionProblem extends AbstractProblemDouble implements Interfac
|
||||
|
||||
@Override
|
||||
public double[] evaluate(double[] x) {
|
||||
if (x.length != dim) {
|
||||
if (x.length != problemDimension) {
|
||||
EVAERROR.errorMsgOnce("mismatching dimension of GPFunctionProblem! Setting to " + x.length);
|
||||
setProblemDimension(x.length);
|
||||
}
|
||||
@ -100,8 +100,8 @@ public class GPFunctionProblem extends AbstractProblemDouble implements Interfac
|
||||
* @param newDim
|
||||
*/
|
||||
public void setProblemDimension(int newDim) {
|
||||
dim = newDim;
|
||||
((ESIndividualDoubleData) template).setDoubleDataLength(dim);
|
||||
problemDimension = newDim;
|
||||
((ESIndividualDoubleData) template).setDoubleDataLength(problemDimension);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -125,11 +125,6 @@ public class GPFunctionProblem extends AbstractProblemDouble implements Interfac
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProblemDimension() {
|
||||
return dim;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStringRepresentationForProblem(InterfaceOptimizer opt) {
|
||||
return "GP find a function problem";
|
||||
|
@ -53,8 +53,6 @@ public interface InterfaceOptimizationProblem extends InterfaceAdditionalPopulat
|
||||
*/
|
||||
public void evaluate(AbstractEAIndividual individual);
|
||||
|
||||
/******************** Some output methods *******************************************/
|
||||
|
||||
/**
|
||||
* This method allows the GenericObjectEditorPanel to read the
|
||||
* name to the current object.
|
||||
@ -95,4 +93,11 @@ public interface InterfaceOptimizationProblem extends InterfaceAdditionalPopulat
|
||||
* @return Double value
|
||||
*/
|
||||
public Double getDoublePlotValue(Population pop);
|
||||
|
||||
/**
|
||||
* This method returns the dimension of the problem. Some problem implementations
|
||||
* may add a setProblemDimension() method, but as some problems have a fixed problem
|
||||
* dimension this is not added in this interface.
|
||||
*/
|
||||
public int getProblemDimension();
|
||||
}
|
||||
|
@ -15,13 +15,6 @@ public interface InterfaceProblemDouble {
|
||||
*/
|
||||
public double[] evaluate(double[] x);
|
||||
|
||||
/**
|
||||
* Get the problem dimension.
|
||||
*
|
||||
* @return the problem dimension
|
||||
*/
|
||||
public int getProblemDimension();
|
||||
|
||||
/**
|
||||
* Create a new range array by using the getRangeLowerBound and getRangeUpperBound methods.
|
||||
*
|
||||
|
@ -235,15 +235,6 @@ public class MatlabProblem extends AbstractOptimizationProblem implements Interf
|
||||
this.problemDimension = problemDimension;
|
||||
}
|
||||
|
||||
|
||||
public int getProblemDimension() {
|
||||
return problemDimension;
|
||||
}
|
||||
|
||||
public String problemDimensionTipText() {
|
||||
return "The dimension of the problem.";
|
||||
}
|
||||
|
||||
public void log(String str) {
|
||||
if (dos != null) {
|
||||
dos.print(str);
|
||||
|
@ -333,14 +333,6 @@ public class TF1Problem extends AbstractMultiObjectiveOptimizationProblem implem
|
||||
this.problemDimension = d;
|
||||
}
|
||||
|
||||
public int getProblemDimension() {
|
||||
return this.problemDimension;
|
||||
}
|
||||
|
||||
public String problemDimensionTipText() {
|
||||
return "Length of the x vector at is to be optimized.";
|
||||
}
|
||||
|
||||
/**
|
||||
* This method allows you to choose the EA individual
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user