More refactoring/cleanup.

- Removed commented code
- Added more @Description annotations.
This commit is contained in:
Fabian Becker 2013-12-10 20:51:06 +01:00
parent 6f72d70f94
commit 3f4c033720
16 changed files with 27 additions and 180 deletions

View File

@ -604,31 +604,6 @@ public abstract class AbstractOptimizationProblem implements InterfaceOptimizati
return "A default threshold to identify optima - e.g. the assumed minimal distance between any two optima."; return "A default threshold to identify optima - e.g. the assumed minimal distance between any two optima.";
} }
// /**********************************************************************************************************************
// * These are for InterfaceParamControllable
// */
// public Object[] getParamControl() {
// return null;
// }
//
// public void notifyParamChanged(String member, Object oldVal, Object newVal) {
// if (changeListeners != null) for (ParamChangeListener l : changeListeners) {
// l.notifyChange(this, oldVal, newVal, null);
// }
// }
//
// public void addChangeListener(ParamChangeListener l) {
// if (changeListeners==null) changeListeners = new ArrayList<ParamChangeListener>();
// if (!changeListeners.contains(l)) changeListeners.add(l);
// }
//
// public void removeChangeListener(ParamChangeListener l) {
// if (changeListeners!=null) changeListeners.remove(l);
// }
/**********************************************************************************************************************
* These are for GUI
*/
/** /**
* This method allows the CommonJavaObjectEditorPanel to read the * This method allows the CommonJavaObjectEditorPanel to read the
* name to the current object. * name to the current object.

View File

@ -54,9 +54,6 @@ public abstract class AbstractProblemDouble extends AbstractOptimizationProblem
private boolean doRotation = false; // should really be false by default private boolean doRotation = false; // should really be false by default
private Matrix rotation; private Matrix rotation;
// PropertySelectableList<AbstractConstraint> constraintList = new
// PropertySelectableList<AbstractConstraint>(new AbstractConstraint[]{new
// GenericConstraint()});
private AbstractConstraint[] constraintArray = new AbstractConstraint[]{new GenericConstraint()}; private AbstractConstraint[] constraintArray = new AbstractConstraint[]{new GenericConstraint()};
private boolean withConstraints = false; private boolean withConstraints = false;
private transient boolean isShowing = false; private transient boolean isShowing = false;

View File

@ -59,7 +59,7 @@ public abstract class AbstractProblemInteger extends AbstractOptimizationProblem
x = new int[((InterfaceDataTypeInteger) individual).getIntegerData().length]; x = new int[((InterfaceDataTypeInteger) individual).getIntegerData().length];
System.arraycopy(((InterfaceDataTypeInteger) individual).getIntegerData(), 0, x, 0, x.length); System.arraycopy(((InterfaceDataTypeInteger) individual).getIntegerData(), 0, x, 0, x.length);
fitness = this.eval(x); fitness = this.evaluate(x);
for (int i = 0; i < fitness.length; i++) { for (int i = 0; i < fitness.length; i++) {
// set the fitness of the individual // set the fitness of the individual
individual.SetFitness(i, fitness[i]); individual.SetFitness(i, fitness[i]);
@ -75,7 +75,7 @@ public abstract class AbstractProblemInteger extends AbstractOptimizationProblem
* @param x The n-dimensional input vector * @param x The n-dimensional input vector
* @return The m-dimensional output vector. * @return The m-dimensional output vector.
*/ */
public abstract double[] eval(int[] x); public abstract double[] evaluate(int[] x);
/** /**
* ******************************************************************************************************************* * *******************************************************************************************************************

View File

@ -5,16 +5,14 @@ import eva2.optimization.individuals.AbstractEAIndividual;
import eva2.optimization.individuals.InterfaceDataTypeBinary; import eva2.optimization.individuals.InterfaceDataTypeBinary;
import eva2.optimization.strategies.InterfaceOptimizer; import eva2.optimization.strategies.InterfaceOptimizer;
import eva2.tools.math.RNG; import eva2.tools.math.RNG;
import eva2.util.annotation.Description;
import java.util.BitSet; import java.util.BitSet;
/** /**
* Created by IntelliJ IDEA. * Maximize the value of the knapsack without exceeding the weight limit.
* User: streiche
* Date: 21.03.2003
* Time: 15:12:46
* To change this template use Options | File Templates.
*/ */
@Description("Maximize the value of the knapsack without exceeding the weight limit")
public class BKnapsackProblem extends AbstractProblemBinary implements java.io.Serializable { public class BKnapsackProblem extends AbstractProblemBinary implements java.io.Serializable {
private int m_Limit = 5000; private int m_Limit = 5000;
@ -353,9 +351,6 @@ public class BKnapsackProblem extends AbstractProblemBinary implements java.io.S
return result.toString(); return result.toString();
} }
/**********************************************************************************************************************
* These are for GUI
*/
/** /**
* This method allows the CommonJavaObjectEditorPanel to read the * This method allows the CommonJavaObjectEditorPanel to read the
* name to the current object. * name to the current object.
@ -367,15 +362,6 @@ public class BKnapsackProblem extends AbstractProblemBinary implements java.io.S
return "Single Knapsack Problem"; return "Single Knapsack Problem";
} }
/**
* This method returns a global info string
*
* @return description
*/
public static String globalInfo() {
return "Maximize the value of the knapsack without exceeding the weight limit.";
}
/** /**
* This method allows you to set the number of mulitruns that are to be performed, * This method allows you to set the number of mulitruns that are to be performed,
* necessary for stochastic optimizers to ensure reliable results. * necessary for stochastic optimizers to ensure reliable results.

View File

@ -3,10 +3,15 @@ package eva2.optimization.problems;
import eva2.optimization.operator.constraint.AbstractConstraint; import eva2.optimization.operator.constraint.AbstractConstraint;
import eva2.optimization.operator.constraint.ConstraintCollection; import eva2.optimization.operator.constraint.ConstraintCollection;
import eva2.optimization.operator.constraint.IntervalConstraint; import eva2.optimization.operator.constraint.IntervalConstraint;
import eva2.util.annotation.Description;
import java.io.Serializable; import java.io.Serializable;
import java.util.Vector; import java.util.Vector;
/**
* Himmelblau's nonlinear optimization problem with 5 simple boundary constraints and 3 nonlinear boundary constraints.
*/
@Description("Himmelblau's nonlinear optimization problem")
public class ConstrHimmelblauProblem extends AbstractProblemDouble implements Serializable { public class ConstrHimmelblauProblem extends AbstractProblemDouble implements Serializable {
private static double yOffset = 31025.5602425; // moving the optimum close to zero private static double yOffset = 31025.5602425; // moving the optimum close to zero
private boolean useYOffset = true; private boolean useYOffset = true;
@ -17,8 +22,7 @@ public class ConstrHimmelblauProblem extends AbstractProblemDouble implements Se
setConstraints(new AbstractConstraint[]{new ConstraintCollection(makeDefaultConstraints())}); setConstraints(new AbstractConstraint[]{new ConstraintCollection(makeDefaultConstraints())});
} }
public ConstrHimmelblauProblem( public ConstrHimmelblauProblem(ConstrHimmelblauProblem o) {
ConstrHimmelblauProblem o) {
super(); super();
super.cloneObjects(o); super.cloneObjects(o);
useYOffset = o.useYOffset; useYOffset = o.useYOffset;
@ -29,12 +33,6 @@ public class ConstrHimmelblauProblem extends AbstractProblemDouble implements Se
return new ConstrHimmelblauProblem(this); return new ConstrHimmelblauProblem(this);
} }
// @Override
// public void initializeProblem() {
// super.initializeProblem();
// setConstraints(new AbstractConstraint[]{new ConstraintCollection(makeDefaultConstraints())});
// }
public static AbstractConstraint[] makeDefaultConstraints() { public static AbstractConstraint[] makeDefaultConstraints() {
Vector<AbstractConstraint> constraints = new Vector<AbstractConstraint>(); Vector<AbstractConstraint> constraints = new Vector<AbstractConstraint>();
constraints.add(new IntervalConstraint("+(+(85.334407,*(0.0056858,*(x1,x4))), +(*(0.00026,*(x0,x3)),*(-0.0022053,*(x2,x4))))", 0, 92)); constraints.add(new IntervalConstraint("+(+(85.334407,*(0.0056858,*(x1,x4))), +(*(0.00026,*(x0,x3)),*(-0.0022053,*(x2,x4))))", 0, 92));
@ -69,10 +67,6 @@ public class ConstrHimmelblauProblem extends AbstractProblemDouble implements Se
return "Constrained Himmelblau Problem"; return "Constrained Himmelblau Problem";
} }
public static String globalInfo() {
return "Himmelblau's nonlinear optimization problem with 5 simple boundary constraints and 3 nonlinear boundary constraints.";
}
public boolean isUseYOffset() { public boolean isUseYOffset() {
return useYOffset; return useYOffset;
} }

View File

@ -3,19 +3,20 @@ package eva2.optimization.problems;
import eva2.gui.editor.GenericObjectEditor; import eva2.gui.editor.GenericObjectEditor;
import eva2.optimization.individuals.AbstractEAIndividual; import eva2.optimization.individuals.AbstractEAIndividual;
import eva2.optimization.operator.constraint.*; import eva2.optimization.operator.constraint.*;
import eva2.util.annotation.Description;
import java.util.Vector; import java.util.Vector;
/**
* Minimize the material cost of a pressure vessel.
*/
@Description("Minimize the material cost of a pressure vessel")
public class ConstrPressureVessel extends AbstractProblemDouble { public class ConstrPressureVessel extends AbstractProblemDouble {
private boolean discreteThickness = true; private boolean discreteThickness = true;
private double minThickness = 0.0625; private double minThickness = 0.0625;
private double maxThickness = 2; private double maxThickness = 2;
private double minRad = 10, maxRad = 300; private double minRad = 10, maxRad = 300;
private double minLen = 10, maxLen = 300; private double minLen = 10, maxLen = 300;
// L=200;
// R=40.3239;
// thickS=0.8125;
// thickH=0.4375;
public ConstrPressureVessel() { public ConstrPressureVessel() {
setWithConstraints(true); setWithConstraints(true);
@ -30,17 +31,11 @@ public class ConstrPressureVessel extends AbstractProblemDouble {
public static AbstractConstraint[] makeDefaultConstraints() { public static AbstractConstraint[] makeDefaultConstraints() {
Vector<AbstractConstraint> constraints = new Vector<AbstractConstraint>(); Vector<AbstractConstraint> constraints = new Vector<AbstractConstraint>();
// constraints.add(new IntervalConstraint("+(+(85.334407,*(0.0056858,*(x1,x4))), +(*(0.00026,*(x0,x3)),*(-0.0022053,*(x2,x4))))", 0, 92));
constraints.add(new GenericConstraint("-(*(0.0193,x2),x0)", ConstraintRelationEnum.lessEqZero)); constraints.add(new GenericConstraint("-(*(0.0193,x2),x0)", ConstraintRelationEnum.lessEqZero));
constraints.add(new GenericConstraint("-(*(0.00954,x2),x1)", ConstraintRelationEnum.lessEqZero)); constraints.add(new GenericConstraint("-(*(0.00954,x2),x1)", ConstraintRelationEnum.lessEqZero));
constraints.add(new GenericConstraint("-(1296000, +(*(pi, *(pow2(x2),x3)),*(/(4,3),*(pi,pow3(x2))))))", ConstraintRelationEnum.lessEqZero)); constraints.add(new GenericConstraint("-(1296000, +(*(pi, *(pow2(x2),x3)),*(/(4,3),*(pi,pow3(x2))))))", ConstraintRelationEnum.lessEqZero));
constraints.add(new GenericConstraint("-(x3,240)", ConstraintRelationEnum.lessEqZero)); constraints.add(new GenericConstraint("-(x3,240)", ConstraintRelationEnum.lessEqZero));
// for (Iterator<AbstractConstraint> iterator = constraints.iterator(); iterator.hasNext();) {
// AbstractConstraint constr = iterator.next();
// constr.setHandlingMethod(ConstraintHandlingEnum.penaltyAdditive);
// constr.setPenaltyFactor(10000);
// }
return constraints.toArray(new AbstractConstraint[constraints.size()]); return constraints.toArray(new AbstractConstraint[constraints.size()]);
} }
@ -53,11 +48,6 @@ public class ConstrPressureVessel extends AbstractProblemDouble {
n = (int) (x[1] / minThickness); n = (int) (x[1] / minThickness);
x[1] = n * minThickness; x[1] = n * minThickness;
} }
//double thickS=x[0], thickH=x[1], R=x[2], L=x[3];
// x[0]=0.8125; //thickS=0.8125;
// x[1]=0.4375; //thickH=0.4375;
// x[2]=40.3239; //R=40.3239;
// x[3]=200; //L=200;
return x; return x;
} }
@ -93,8 +83,6 @@ public class ConstrPressureVessel extends AbstractProblemDouble {
} }
System.err.println("Invalid dimension for lower bound (ConstrPressureVessel)"); System.err.println("Invalid dimension for lower bound (ConstrPressureVessel)");
return 0.; return 0.;
// if (dim<=1) return minThickness/2;
// else return minLen;
} }
@Override @Override
@ -110,10 +98,6 @@ public class ConstrPressureVessel extends AbstractProblemDouble {
} }
System.err.println("Invalid dimension for upper bound (ConstrPressureVessel)"); System.err.println("Invalid dimension for upper bound (ConstrPressureVessel)");
return 100.; return 100.;
// if (dim<=1) {
// return maxThickness;
// } else if (dim==2) return maxRad;
// else return maxLen;
} }
@Override @Override
@ -121,10 +105,6 @@ public class ConstrPressureVessel extends AbstractProblemDouble {
return "Constrained-Pressure-Vessel"; return "Constrained-Pressure-Vessel";
} }
public static String globalInfo() {
return "Minimize the material cost of a pressure vessel";
}
@Override @Override
public void hideHideable() { public void hideHideable() {
super.hideHideable(); super.hideHideable();

View File

@ -10,21 +10,23 @@ import eva2.optimization.operator.moso.MOSONoConvert;
import eva2.optimization.population.Population; import eva2.optimization.population.Population;
import eva2.optimization.strategies.InterfaceOptimizer; import eva2.optimization.strategies.InterfaceOptimizer;
import eva2.tools.math.Mathematics; import eva2.tools.math.Mathematics;
import eva2.util.annotation.Description;
import java.io.*; import java.io.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/**
* Use an external command as target function.
*/
@Description("Use an external command as target function.")
public class ExternalRuntimeProblem extends AbstractOptimizationProblem public class ExternalRuntimeProblem extends AbstractOptimizationProblem
implements Interface2DBorderProblem, InterfaceProblemDouble, InterfaceHasInitRange { implements Interface2DBorderProblem, InterfaceProblemDouble, InterfaceHasInitRange {
protected AbstractEAIndividual m_OverallBest = null; protected AbstractEAIndividual m_OverallBest = null;
protected int m_ProblemDimension = 10; protected int m_ProblemDimension = 10;
// protected boolean m_UseTestConstraint = false;
protected String m_Command = ""; protected String m_Command = "";
protected String m_WorkingDir = ""; protected String m_WorkingDir = "";
// protected double m_upperBound = 10;
// protected double m_lowerBound = 0;
PropertyDoubleArray m_Range = new PropertyDoubleArray(m_ProblemDimension, 2, -10, 10); PropertyDoubleArray m_Range = new PropertyDoubleArray(m_ProblemDimension, 2, -10, 10);
PropertyDoubleArray m_initRange = new PropertyDoubleArray(m_ProblemDimension, 2, -10, 10); PropertyDoubleArray m_initRange = new PropertyDoubleArray(m_ProblemDimension, 2, -10, 10);
private String additionalArg = ""; private String additionalArg = "";
@ -344,9 +346,6 @@ public class ExternalRuntimeProblem extends AbstractOptimizationProblem
return sb.toString(); return sb.toString();
} }
/**********************************************************************************************************************
* These are for GUI
*/
/** /**
* This method allows the CommonJavaObjectEditorPanel to read the * This method allows the CommonJavaObjectEditorPanel to read the
* name to the current object. * name to the current object.
@ -358,15 +357,6 @@ public class ExternalRuntimeProblem extends AbstractOptimizationProblem
return "External Runtime Problem"; return "External Runtime Problem";
} }
/**
* This method returns a global info string
*
* @return description
*/
public static String globalInfo() {
return "Use an external command as target function.";
}
public String[] getGOEPropertyUpdateLinks() { public String[] getGOEPropertyUpdateLinks() {
return new String[]{"problemDimension", "initialRange", "problemDimension", "range"}; return new String[]{"problemDimension", "initialRange", "problemDimension", "range"};
} }
@ -426,19 +416,6 @@ public class ExternalRuntimeProblem extends AbstractOptimizationProblem
return "The working directory"; return "The working directory";
} }
// /** This method allows you to toggle the application of a simple test constraint.
// * @param b The mode for the test constraint
// */
// public void setUseTestConstraint(boolean b) {
// this.m_UseTestConstraint = b;
// }
// public boolean getUseTestConstraint() {
// return this.m_UseTestConstraint;
// }
// public String useTestConstraintTipText() {
// return "Just a simple test constraint of x[0] >= 1.";
// }
public InterfaceMOSOConverter getMosoConverter() { public InterfaceMOSOConverter getMosoConverter() {
return m_MosoConverter; return m_MosoConverter;
} }
@ -480,39 +457,6 @@ public class ExternalRuntimeProblem extends AbstractOptimizationProblem
return getRange().getDoubleArrayShallow(); return getRange().getDoubleArrayShallow();
} }
// /**
// * @return the m_upperBound
// */
// public double getRangeUpperBound() {
// return m_upperBound;
// }
// /**
// * @param bound the m_upperBound to set
// */
// public void setRangeUpperBound(double bound) {
// m_upperBound = bound;
// }
//
// public String rangeUpperBoundTipText() {
// return "Upper bound of the search space in any dimension.";
// }
// /**
// * @return the m_lowerBound
// */
// public double getRangeLowerBound() {
// return m_lowerBound;
// }
// /**
// * @param bound the m_lowerBound to set
// */
// public void setRangeLowerBound(double bound) {
// m_lowerBound = bound;
// }
//
// public String rangeLowerBoundTipText() {
// return "Lower bound of the search space in any dimension.";
// }
public String additionalArgumentTipText() { public String additionalArgumentTipText() {
return "Optionally define an additional (first) argument for the command line command."; return "Optionally define an additional (first) argument for the command line command.";
} }

View File

@ -34,7 +34,7 @@ public class I1Problem extends AbstractProblemInteger implements java.io.Seriali
* @return The m-dimensional output vector. * @return The m-dimensional output vector.
*/ */
@Override @Override
public double[] eval(int[] x) { public double[] evaluate(int[] x) {
double[] result = new double[1]; double[] result = new double[1];
result[0] = 0; result[0] = 0;
for (int i = 0; i < x.length; i++) { for (int i = 0; i < x.length; i++) {

View File

@ -5,8 +5,6 @@ import eva2.optimization.operator.postprocess.SolutionHistogram;
/** /**
* Target functions may provide an idea which fitness values are * Target functions may provide an idea which fitness values are
* interesting. * interesting.
*
* @author mkron
*/ */
public interface InterfaceInterestingHistogram { public interface InterfaceInterestingHistogram {
/** /**

View File

@ -3,15 +3,8 @@ package eva2.optimization.problems;
import eva2.optimization.population.Population; import eva2.optimization.population.Population;
/** /**
* <p>Title: EvA2</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* *
* @author planatsc
* @version 1.0
*/ */
public interface InterfaceLocalSearchable extends InterfaceOptimizationProblem { public interface InterfaceLocalSearchable extends InterfaceOptimizationProblem {
/** /**
@ -27,5 +20,4 @@ public interface InterfaceLocalSearchable extends InterfaceOptimizationProblem {
* @return * @return
*/ */
public double getLocalSearchStepFunctionCallEquivalent(); public double getLocalSearchStepFunctionCallEquivalent();
} }

View File

@ -31,12 +31,10 @@ public interface InterfaceOptimizationProblem extends InterfaceAdditionalPopulat
*/ */
public boolean isMultiObjective(); public boolean isMultiObjective();
/******************** The most important methods ****************************************/
/** /**
* This method inits a given population * This method initialized a given population
* *
* @param population The populations that is to be inited * @param population The populations that is to be initialized.
*/ */
public void initializePopulation(Population population); public void initializePopulation(Population population);
@ -58,7 +56,7 @@ public interface InterfaceOptimizationProblem extends InterfaceAdditionalPopulat
/******************** Some output methods *******************************************/ /******************** Some output methods *******************************************/
/** /**
* This method allows the CommonJavaObjectEditorPanel to read the * This method allows the GenericObjectEditorPanel to read the
* name to the current object. * name to the current object.
* *
* @return The name. * @return The name.
@ -97,5 +95,4 @@ public interface InterfaceOptimizationProblem extends InterfaceAdditionalPopulat
* @return Double value * @return Double value
*/ */
public Double getDoublePlotValue(Population pop); public Double getDoublePlotValue(Population pop);
} }

View File

@ -1,11 +1,7 @@
package eva2.optimization.problems; package eva2.optimization.problems;
/** /**
* Created by IntelliJ IDEA. *
* User: streiche
* Date: 14.01.2005
* Time: 17:06:10
* To change this template use File | Settings | File Templates.
*/ */
public interface InterfaceOptimizationTarget { public interface InterfaceOptimizationTarget {

View File

@ -5,7 +5,6 @@ import eva2.optimization.individuals.InterfaceDataTypeDouble;
/** /**
* A minimal interface for double valued problems. * A minimal interface for double valued problems.
* *
* @author mkron
*/ */
public interface InterfaceProblemDouble { public interface InterfaceProblemDouble {
/** /**

View File

@ -3,11 +3,7 @@ package eva2.optimization.problems;
import eva2.optimization.individuals.codings.gp.GPArea; import eva2.optimization.individuals.codings.gp.GPArea;
/** /**
* Created by IntelliJ IDEA. * Interface for Program Problems. Solved by Genetic Programming.
* User: streiche
* Date: 04.04.2003
* Time: 14:43:03
* To change this template use Options | File Templates.
*/ */
public interface InterfaceProgramProblem extends InterfaceOptimizationProblem { public interface InterfaceProgramProblem extends InterfaceOptimizationProblem {

View File

@ -6,7 +6,6 @@ import eva2.optimization.population.Population;
* A standard interface for solution viewers which display a single (best) solution * A standard interface for solution viewers which display a single (best) solution
* or a population of solutions. * or a population of solutions.
* *
* @author mkron
*/ */
public interface InterfaceSolutionViewer { public interface InterfaceSolutionViewer {
/** /**

View File

@ -41,20 +41,14 @@ public class MatlabProblem extends AbstractOptimizationProblem implements Interf
transient PrintStream dos = null; transient PrintStream dos = null;
private double range[][] = null; private double range[][] = null;
private static String defTestOut = "matlabproblem-debug.log"; private static String defTestOut = "matlabproblem-debug.log";
// private static String resOutFile = "matlabproblem-output.txt";
// transient PrintStream resOutStream = null;
int verbosityLevel = 0; int verbosityLevel = 0;
boolean outputAllStatsField = true; boolean outputAllStatsField = true;
private MatlabEvalMediator handler = null; private MatlabEvalMediator handler = null;
// private boolean isDouble = true;
private MatlabProblemDataTypeEnum dataType = MatlabProblemDataTypeEnum.typeDouble; private MatlabProblemDataTypeEnum dataType = MatlabProblemDataTypeEnum.typeDouble;
private double[][] initialRange = null; // the initial range for double-valued problems private double[][] initialRange = null; // the initial range for double-valued problems
public static boolean hideFromGOE = true; public static boolean hideFromGOE = true;
// transient private double[] currArray = null;
// private String mtCmd = null;
public MatlabProblem(MatlabProblem o) { public MatlabProblem(MatlabProblem o) {
this.template = null; this.template = null;
this.handler = o.handler; this.handler = o.handler;