diff --git a/src/eva2/server/go/problems/AbstractProblemDouble.java b/src/eva2/server/go/problems/AbstractProblemDouble.java index 212c1af9..82d0b28e 100644 --- a/src/eva2/server/go/problems/AbstractProblemDouble.java +++ b/src/eva2/server/go/problems/AbstractProblemDouble.java @@ -24,287 +24,340 @@ import eva2.tools.math.RNG; import eva2.tools.math.Jama.Matrix; /** - * For a double valued problem, there are two main methods to implement: {@link #getProblemDimension()} - * must return the problem dimension, while {@link #eval(double[])} is to evaluate a single double - * vector into the result fitness vector. + * For a double valued problem, there are two main methods to implement: + * {@link #getProblemDimension()} must return the problem dimension, while + * {@link #eval(double[])} is to evaluate a single double vector into the result + * fitness vector. * - * To define the problem range, you may use the default range parameter resulting in a symmetric - * double range [-defaultRange,defaulRange] in all dimensions. - * Or you may implement {@link #getRangeLowerBound(int)} and {@link #getRangeUpperBound(int)} - * to define an arbitrary problem range. In that case, the default range parameter is not used. + * To define the problem range, you may use the default range parameter + * resulting in a symmetric double range [-defaultRange,defaulRange] in all + * dimensions. Or you may implement {@link #getRangeLowerBound(int)} and + * {@link #getRangeUpperBound(int)} to define an arbitrary problem range. In + * that case, the default range parameter is not used. * - * Anything you want to do before any optimization is started on the problem should go into - * {@link #initProblem()}, but remember to call the super-method in your implementation. The - * individual template will be initialized to an ESIndividualDoubleData by then. + * Anything you want to do before any optimization is started on the problem + * should go into {@link #initProblem()}, but remember to call the super-method + * in your implementation. The individual template will be initialized to an + * ESIndividualDoubleData by then. * - * For the GUI, it is also convenient to implement the {@link #globalInfo()} and {@link #getName()} - * methods to provide some distinctive information for the user. + * For the GUI, it is also convenient to implement the {@link #globalInfo()} and + * {@link #getName()} methods to provide some distinctive information for the + * user. * * * @author mkron - * + * */ -public abstract class AbstractProblemDouble extends AbstractOptimizationProblem implements InterfaceProblemDouble, Interface2DBorderProblem/*, InterfaceParamControllable */{ +public abstract class AbstractProblemDouble extends AbstractOptimizationProblem + implements InterfaceProblemDouble, Interface2DBorderProblem/* + * , + * InterfaceParamControllable + */{ + /** + * Generated serial version identifier. + */ + private static final long serialVersionUID = -3904130243174390134L; private double m_DefaultRange = 10; private double m_Noise = 0; private boolean doRotation = false; // should really be false by default - private Matrix rotation; - -// PropertySelectableList constraintList = new PropertySelectableList(new AbstractConstraint[]{new GenericConstraint()}); - private AbstractConstraint[] constraintArray = new AbstractConstraint[]{new GenericConstraint()}; - private boolean withConstraints = false; + private Matrix rotation; + + // PropertySelectableList constraintList = new + // PropertySelectableList(new AbstractConstraint[]{new + // GenericConstraint()}); + private AbstractConstraint[] constraintArray = new AbstractConstraint[] { new GenericConstraint() }; + private boolean withConstraints = false; private transient boolean isShowing = false; - private double rotAngle = 22.5; // for default rotation along every axis - public static String rawFitKey="UnconstrainedFitnessValue"; - + private double rotAngle = 22.5; // for default rotation along every axis + public static String rawFitKey = "UnconstrainedFitnessValue"; + public AbstractProblemDouble() { initTemplate(); } - + public AbstractProblemDouble(AbstractProblemDouble o) { cloneObjects(o); } - + protected void initTemplate() { - if (m_Template == null) m_Template = new ESIndividualDoubleData(); - if (getProblemDimension() > 0) { // avoid evil case setting dim to 0 during object init - ((InterfaceDataTypeDouble)this.m_Template).setDoubleDataLength(getProblemDimension()); - ((InterfaceDataTypeDouble)this.m_Template).SetDoubleRange(makeRange()); + if (m_Template == null) + m_Template = new ESIndividualDoubleData(); + if (getProblemDimension() > 0) { // avoid evil case setting dim to 0 + // during object init + ((InterfaceDataTypeDouble) this.m_Template) + .setDoubleDataLength(getProblemDimension()); + ((InterfaceDataTypeDouble) this.m_Template) + .SetDoubleRange(makeRange()); } } - + public void hideHideable() { setWithConstraints(isWithConstraints()); } - + protected void cloneObjects(AbstractProblemDouble o) { this.m_DefaultRange = o.m_DefaultRange; this.m_Noise = o.m_Noise; this.SetDefaultAccuracy(o.getDefaultAccuracy()); - if (o.m_Template != null) this.m_Template = (AbstractEAIndividual)o.m_Template.clone(); - if (o.constraintArray!=null) { - this.constraintArray=o.constraintArray.clone(); - for (int i=0; i getConstraints() { -// return constraintList; -// } -// -// public void setConstraints(PropertySelectableList constraintArray) { -// this.constraintList = constraintArray; -// } + /** + * This method returns a global info string. + * + * @return description + */ + public static String globalInfo() { + return "The programmer did not give further details."; + } + + /** + * This method returns a string describing the optimization problem. + * + * @param opt + * The Optimizer that is used or had been used. + * @return The description. + */ + public String getStringRepresentationForProblem(InterfaceOptimizer opt) { + StringBuffer sb = new StringBuffer(200); + sb.append("A double valued problem: "); + sb.append(this.getName()); + sb.append("\n"); + sb.append(globalInfo()); + sb.append("Dimension : "); + sb.append(this.getProblemDimension()); + sb.append("\nNoise level : "); + sb.append(this.m_Noise); + return sb.toString(); + } + + // public PropertySelectableList getConstraints() { + // return constraintList; + // } + // + // public void setConstraints(PropertySelectableList + // constraintArray) { + // this.constraintList = constraintArray; + // } public AbstractConstraint[] getConstraints() { return constraintArray; @@ -479,80 +554,101 @@ public abstract class AbstractProblemDouble extends AbstractOptimizationProblem public void setConstraints(AbstractConstraint[] constrArray) { this.constraintArray = constrArray; } - + public String constraintsTipText() { return "Add constraints to the problem."; } - + public boolean isWithConstraints() { return withConstraints; } public void setWithConstraints(boolean withConstraints) { this.withConstraints = withConstraints; - GenericObjectEditor.setShowProperty(this.getClass(), "constraints", withConstraints); + GenericObjectEditor.setShowProperty(this.getClass(), "constraints", + withConstraints); } - + public String withConstraintsTipText() { - return "(De-)Activate constraints for the problem."; + return "(De-)Activate constraints for the problem."; } @Override public String[] getAdditionalFileStringHeader(PopulationInterface pop) { String[] superHeader = super.getAdditionalFileStringHeader(pop); - if (isWithConstraints()) return ToolBox.appendArrays(superHeader, new String[]{"rawFit","numViol","sumViol"}); - else return superHeader; + if (isWithConstraints()) + return ToolBox.appendArrays(superHeader, new String[] { "rawFit", + "numViol", "sumViol" }); + else + return superHeader; } - + @Override public String[] getAdditionalFileStringInfo(PopulationInterface pop) { String[] superInfo = super.getAdditionalFileStringInfo(pop); - if (isWithConstraints()) - return ToolBox.appendArrays(superInfo, new String[]{"Raw fitness (unpenalized) of the current best individual", - "The number of constraints violated by the current best individual", - "The sum of constraint violations of the current best individual"}); - else return superInfo; + if (isWithConstraints()) + return ToolBox + .appendArrays( + superInfo, + new String[] { + "Raw fitness (unpenalized) of the current best individual", + "The number of constraints violated by the current best individual", + "The sum of constraint violations of the current best individual" }); + else + return superInfo; } - + @Override public Object[] getAdditionalFileStringValue(PopulationInterface pop) { Object[] superVal = super.getAdditionalFileStringValue(pop); if (isWithConstraints()) { - AbstractEAIndividual indy = (AbstractEAIndividual)pop.getBestIndividual(); - Pair violation= getConstraintViolation(indy); - return ToolBox.appendArrays(superVal, new Object[]{indy.getData(rawFitKey), - violation.head(), - violation.tail()}); -// return superVal + " \t" + BeanInspector.toString(indy.getData(rawFitKey)) + " \t" + violation.head() + " \t" + violation.tail(); - } else return superVal; + AbstractEAIndividual indy = (AbstractEAIndividual) pop + .getBestIndividual(); + Pair violation = getConstraintViolation(indy); + return ToolBox.appendArrays(superVal, + new Object[] { indy.getData(rawFitKey), violation.head(), + violation.tail() }); + // return superVal + " \t" + + // BeanInspector.toString(indy.getData(rawFitKey)) + " \t" + + // violation.head() + " \t" + violation.tail(); + } else + return superVal; } - protected Pair getConstraintViolation(AbstractEAIndividual indy) { - double sum=0; - int numViol=0; + protected Pair getConstraintViolation( + AbstractEAIndividual indy) { + double sum = 0; + int numViol = 0; for (AbstractConstraint constr : constraintArray) { - double v= constr.getViolation(getEvalArray(indy)); - if (v>0) numViol++; + double v = constr.getViolation(getEvalArray(indy)); + if (v > 0) + numViol++; sum += v; } - return new Pair(numViol, sum); + return new Pair(numViol, sum); } - + public boolean isShowPlot() { - return isShowing ; + return isShowing; } + public void setShowPlot(boolean showP) { if (!isShowing && showP) { TopoPlot plot = new TopoPlot(getName(), "x1", "x2"); - plot.setParams(60,60, ColorBarCalculator.BLUE_TO_RED); + plot.setParams(60, 60, ColorBarCalculator.BLUE_TO_RED); this.initProblem(); plot.setTopology(this, makeRange(), true); - if (this instanceof InterfaceMultimodalProblemKnown && ((InterfaceMultimodalProblemKnown)this).fullListAvailable()) { - plot.drawPopulation("Opt", ((InterfaceMultimodalProblemKnown)this).getRealOptima()); + if (this instanceof InterfaceMultimodalProblemKnown + && ((InterfaceMultimodalProblemKnown) this) + .fullListAvailable()) { + plot.drawPopulation("Opt", + ((InterfaceMultimodalProblemKnown) this) + .getRealOptima()); } } isShowing = showP; } + public String showPlotTipText() { return "Produce an exemplary 2D plot of the function (dimensional cut at x_i=0 for n>1)."; }