From cde91295554bfdece8c8921de790b82c4ca40f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Dr=C3=A4ger?= Date: Tue, 24 Aug 2010 14:54:26 +0000 Subject: [PATCH] In Java 1.5 @Override tags must not be used when implementing methods from an interface. --- .../IndividualWeightedFitnessComparator.java | 39 ++++- ...ractMultiObjectiveOptimizationProblem.java | 24 ++- .../go/strategies/MultiObjectiveCMAES.java | 158 ++++++++++++++---- src/eva2/tools/math/Mathematics.java | 8 +- 4 files changed, 185 insertions(+), 44 deletions(-) diff --git a/src/eva2/server/go/individuals/IndividualWeightedFitnessComparator.java b/src/eva2/server/go/individuals/IndividualWeightedFitnessComparator.java index 2e39ff4f..c8ffd987 100644 --- a/src/eva2/server/go/individuals/IndividualWeightedFitnessComparator.java +++ b/src/eva2/server/go/individuals/IndividualWeightedFitnessComparator.java @@ -12,12 +12,27 @@ import eva2.tools.EVAERROR; * */ public class IndividualWeightedFitnessComparator implements Comparator, Serializable { + /** + * Generated serial version identifier + */ + private static final long serialVersionUID = 3182129129041083881L; + /** + * + */ private double [] fitWeights = null; + /** + * + * @param weights + */ public IndividualWeightedFitnessComparator(double[] weights) { setFitWeights(weights); } + /* + * (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ @Override public boolean equals(Object obj) { if (obj instanceof IndividualWeightedFitnessComparator) { @@ -35,6 +50,10 @@ public class IndividualWeightedFitnessComparator implements Comparator, return false; } + /* + * (non-Javadoc) + * @see java.lang.Object#hashCode() + */ @Override public int hashCode() { if (fitWeights==null) return super.hashCode(); @@ -45,7 +64,10 @@ public class IndividualWeightedFitnessComparator implements Comparator, return code; } - @Override + /* + * (non-Javadoc) + * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) + */ public int compare(Object o1, Object o2) { double[] f1 = ((AbstractEAIndividual) o1).getFitness(); double[] f2 = ((AbstractEAIndividual) o2).getFitness(); @@ -58,6 +80,11 @@ public class IndividualWeightedFitnessComparator implements Comparator, else return 0; } + /** + * + * @param f + * @return + */ private double calcScore(double[] f) { if (f==null || fitWeights==null) throw new RuntimeException("Error, missing information in " + this.getClass()); if (f.length!=fitWeights.length) { @@ -71,11 +98,21 @@ public class IndividualWeightedFitnessComparator implements Comparator, return s; } + /** + * + * @param indy + * @return + */ public double calcScore(AbstractEAIndividual indy) { double[] f = indy.getFitness(); return calcScore(f); } + /** + * + * @param dim + * @param v + */ public void setAllWeights(int dim, double v) { fitWeights = new double[dim]; for (int i = 0; i < fitWeights.length; i++) { diff --git a/src/eva2/server/go/problems/AbstractMultiObjectiveOptimizationProblem.java b/src/eva2/server/go/problems/AbstractMultiObjectiveOptimizationProblem.java index d1bbcd8a..93972dfd 100644 --- a/src/eva2/server/go/problems/AbstractMultiObjectiveOptimizationProblem.java +++ b/src/eva2/server/go/problems/AbstractMultiObjectiveOptimizationProblem.java @@ -35,6 +35,16 @@ import eva2.tools.chart2d.DPoint; public abstract class AbstractMultiObjectiveOptimizationProblem extends AbstractOptimizationProblem { + /** + * Generated serial version identifier + */ + private static final long serialVersionUID = -6882081673229946521L; + + /** + * + * @author mkron + * + */ class MultiObjectiveEvalThread extends Thread{ AbstractMultiObjectiveOptimizationProblem prob; AbstractEAIndividual ind; @@ -492,6 +502,10 @@ public abstract class AbstractMultiObjectiveOptimizationProblem extends Abstract return ToolBox.appendArrays(result, super.getAdditionalFileStringValue(pop)); } + /* + * (non-Javadoc) + * @see eva2.server.go.problems.AbstractOptimizationProblem#getAdditionalFileStringInfo(eva2.server.go.PopulationInterface) + */ @Override public String[] getAdditionalFileStringInfo(PopulationInterface pop) { String[] superInfo = super.getAdditionalFileStringInfo(pop); @@ -499,12 +513,20 @@ public abstract class AbstractMultiObjectiveOptimizationProblem extends Abstract "Pareto metric on the collected pareto front"}, superInfo); } - @Override + /* + * (non-Javadoc) + * @see eva2.server.go.problems.InterfaceOptimizationProblem#getStringRepresentationForProblem(eva2.server.go.strategies.InterfaceOptimizer) + */ public String getStringRepresentationForProblem(InterfaceOptimizer opt) { // TODO Auto-generated method stub return null; } + /** + * + * @param pop + * @return + */ public double calculateMetric(Population pop) { if (pop==null || (pop.size()==0)) return Double.NaN; return this.m_Metric.calculateMetricOn(pop, this); diff --git a/src/eva2/server/go/strategies/MultiObjectiveCMAES.java b/src/eva2/server/go/strategies/MultiObjectiveCMAES.java index 38b5bb93..280a7085 100644 --- a/src/eva2/server/go/strategies/MultiObjectiveCMAES.java +++ b/src/eva2/server/go/strategies/MultiObjectiveCMAES.java @@ -15,8 +15,23 @@ import eva2.server.go.populations.SolutionSet; import eva2.server.go.problems.AbstractOptimizationProblem; import eva2.server.go.problems.InterfaceOptimizationProblem; +/** + * + * @author mkron + * + */ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable { + /** + * Generated serial version identifier + */ + private static final long serialVersionUID = 1L; + + /** + * + * @author mkron + * + */ class CounterClass { public CounterClass(int i) { value = i; @@ -51,15 +66,28 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable { } public void hideHideable() { - GenericObjectEditor.setHideProperty(this.getClass(), "population", true); + GenericObjectEditor + .setHideProperty(this.getClass(), "population", true); } - - @Override + + /* + * (non-Javadoc) + * + * @see + * eva2.server.go.strategies.InterfaceOptimizer#SetIdentifier(java.lang. + * String) + */ public void SetIdentifier(String name) { m_Identifier = name; } - @Override + /* + * (non-Javadoc) + * + * @see + * eva2.server.go.strategies.InterfaceOptimizer#SetProblem(eva2.server.go + * .problems.InterfaceOptimizationProblem) + */ public void SetProblem(InterfaceOptimizationProblem problem) { m_Problem = (AbstractOptimizationProblem) problem; } @@ -74,41 +102,70 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable { this.m_Listener = ea; } - @Override + /* + * (non-Javadoc) + * + * @see eva2.server.go.strategies.InterfaceOptimizer#freeWilly() + */ public void freeWilly() { } - @Override + /* + * (non-Javadoc) + * + * @see eva2.server.go.strategies.InterfaceOptimizer#getAllSolutions() + */ public InterfaceSolutionSet getAllSolutions() { Population pop = getPopulation(); return new SolutionSet(pop, pop); } - @Override + /* + * (non-Javadoc) + * + * @see eva2.server.go.strategies.InterfaceOptimizer#getIdentifier() + */ public String getIdentifier() { return m_Identifier; } - @Override + /* + * (non-Javadoc) + * + * @see eva2.server.go.strategies.InterfaceOptimizer#getName() + */ public String getName() { return "(1+" + m_lambda + ") MO-CMA-ES"; } - public static String globalInfo() { - return "A multi-objective CMA-ES variant after Igel, Hansen and Roth 2007 (EC 15(1),1-28)."; - } - - @Override + public static String globalInfo() { + return "A multi-objective CMA-ES variant after Igel, Hansen and Roth 2007 (EC 15(1),1-28)."; + } + + /* + * (non-Javadoc) + * + * @see eva2.server.go.strategies.InterfaceOptimizer#getPopulation() + */ public Population getPopulation() { return m_Population; } - @Override + /* + * (non-Javadoc) + * + * @see eva2.server.go.strategies.InterfaceOptimizer#getProblem() + */ public InterfaceOptimizationProblem getProblem() { return m_Problem; } - @Override + /* + * (non-Javadoc) + * + * @see + * eva2.server.go.strategies.InterfaceOptimizer#getStringRepresentation() + */ public String getStringRepresentation() { StringBuilder strB = new StringBuilder(200); strB.append("(1+" + m_lambda + ") MO-CMA-ES:\nOptimization Problem: "); @@ -118,7 +175,11 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable { return strB.toString(); } - @Override + /* + * (non-Javadoc) + * + * @see eva2.server.go.strategies.InterfaceOptimizer#init() + */ public void init() { // initByPopulation(m_Population, true); this.m_Population.setTargetSize(m_lambdamo); @@ -129,7 +190,13 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable { } - @Override + /* + * (non-Javadoc) + * + * @see + * eva2.server.go.strategies.InterfaceOptimizer#initByPopulation(eva2.server + * .go.populations.Population, boolean) + */ public void initByPopulation(Population pop, boolean reset) { setPopulation(pop); if (reset) { @@ -149,7 +216,11 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable { this.m_Problem.evaluate(population); } - @Override + /* + * (non-Javadoc) + * + * @see eva2.server.go.strategies.InterfaceOptimizer#optimize() + */ public void optimize() { HashMap SuccessCounterMap = new HashMap(); @@ -190,8 +261,8 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable { AbstractEAIndividual parent = (AbstractEAIndividual) m_Population .getEAIndividual(j).getData("Parent"); if (m_Population.getEAIndividual(j) != parent) { // Eltern nicht mit - // sich selber - // vergleichen + // sich selber + // vergleichen int parentParetoLevel = ((Integer) parent .getData("ParetoLevel")).intValue(); double parentSMeasure = ((Double) parent.getData("HyperCube")) @@ -214,10 +285,10 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable { m_Population.clear(); for (int i = 0; i < store.length; i++) { if (m_Population.size() + store[i].size() <= m_lambdamo) { // Die - // Front - // passt - // noch - // komplett + // Front + // passt + // noch + // komplett m_Population.addPopulation(store[i]); } else { // die besten aus der aktuellen Front heraussuchen bis voll @@ -225,8 +296,8 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable { AbstractEAIndividual indy = store[i].getEAIndividual(0); double bestMeasure = ((Double) indy.getData("HyperCube")) .doubleValue(); // TODO mal noch effizient machen - // (sortieren und die besten n - // herausholen) + // (sortieren und die besten n + // herausholen) for (int j = 1; j < store[i].size(); j++) { if (bestMeasure < ((Double) store[i].getEAIndividual(j) .getData("HyperCube")).doubleValue()) { @@ -247,15 +318,15 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable { AbstractEAIndividual indy = m_Population.getEAIndividual(j); if (indy.getMutationOperator() instanceof MutateESCovarianceMatrixAdaptionPlus) { // Das - // geht - // nur - // wenn - // wir - // auch - // die - // richtige - // Mutation - // haben + // geht + // nur + // wenn + // wir + // auch + // die + // richtige + // Mutation + // haben AbstractEAIndividual parent = (AbstractEAIndividual) indy .getData("Parent"); MutateESCovarianceMatrixAdaptionPlus muta = (MutateESCovarianceMatrixAdaptionPlus) indy @@ -281,13 +352,25 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable { } - @Override + /* + * (non-Javadoc) + * + * @seeeva2.server.go.strategies.InterfaceOptimizer# + * removePopulationChangedEventListener + * (eva2.server.go.InterfacePopulationChangedEventListener) + */ public boolean removePopulationChangedEventListener( InterfacePopulationChangedEventListener ea) { return false; } - @Override + /* + * (non-Javadoc) + * + * @see + * eva2.server.go.strategies.InterfaceOptimizer#setPopulation(eva2.server + * .go.populations.Population) + */ public void setPopulation(Population pop) { m_Population = pop; m_Population.setNotifyEvalInterval(1); @@ -308,6 +391,7 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable { public int getLambda() { return m_lambda; } + public void setLambda(int mLambda) { m_lambda = mLambda; } diff --git a/src/eva2/tools/math/Mathematics.java b/src/eva2/tools/math/Mathematics.java index 6c6bd3f5..068f7563 100644 --- a/src/eva2/tools/math/Mathematics.java +++ b/src/eva2/tools/math/Mathematics.java @@ -1274,9 +1274,7 @@ public class Mathematics { * @return */ public static double[] zeroes(int n) { - double[] result = new double[n]; - Arrays.fill(result, 0, result.length - 1, 0.); - return result; + return makeVector(0, n); } /** @@ -1299,8 +1297,8 @@ public class Mathematics { * @param vec */ public static void scale(double scale, double[] vec) { - for (double d : vec) { - d *= scale; + for (int i=0; i