In Java 1.5 @Override tags must not be used when implementing methods from an interface.

This commit is contained in:
Andreas Dräger 2010-08-24 14:54:26 +00:00
parent 500366d036
commit cde9129555
4 changed files with 185 additions and 44 deletions

View File

@ -12,12 +12,27 @@ import eva2.tools.EVAERROR;
* *
*/ */
public class IndividualWeightedFitnessComparator implements Comparator<Object>, Serializable { public class IndividualWeightedFitnessComparator implements Comparator<Object>, Serializable {
/**
* Generated serial version identifier
*/
private static final long serialVersionUID = 3182129129041083881L;
/**
*
*/
private double [] fitWeights = null; private double [] fitWeights = null;
/**
*
* @param weights
*/
public IndividualWeightedFitnessComparator(double[] weights) { public IndividualWeightedFitnessComparator(double[] weights) {
setFitWeights(weights); setFitWeights(weights);
} }
/*
* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj instanceof IndividualWeightedFitnessComparator) { if (obj instanceof IndividualWeightedFitnessComparator) {
@ -35,6 +50,10 @@ public class IndividualWeightedFitnessComparator implements Comparator<Object>,
return false; return false;
} }
/*
* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override @Override
public int hashCode() { public int hashCode() {
if (fitWeights==null) return super.hashCode(); if (fitWeights==null) return super.hashCode();
@ -45,7 +64,10 @@ public class IndividualWeightedFitnessComparator implements Comparator<Object>,
return code; return code;
} }
@Override /*
* (non-Javadoc)
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
public int compare(Object o1, Object o2) { public int compare(Object o1, Object o2) {
double[] f1 = ((AbstractEAIndividual) o1).getFitness(); double[] f1 = ((AbstractEAIndividual) o1).getFitness();
double[] f2 = ((AbstractEAIndividual) o2).getFitness(); double[] f2 = ((AbstractEAIndividual) o2).getFitness();
@ -58,6 +80,11 @@ public class IndividualWeightedFitnessComparator implements Comparator<Object>,
else return 0; else return 0;
} }
/**
*
* @param f
* @return
*/
private double calcScore(double[] f) { private double calcScore(double[] f) {
if (f==null || fitWeights==null) throw new RuntimeException("Error, missing information in " + this.getClass()); if (f==null || fitWeights==null) throw new RuntimeException("Error, missing information in " + this.getClass());
if (f.length!=fitWeights.length) { if (f.length!=fitWeights.length) {
@ -71,11 +98,21 @@ public class IndividualWeightedFitnessComparator implements Comparator<Object>,
return s; return s;
} }
/**
*
* @param indy
* @return
*/
public double calcScore(AbstractEAIndividual indy) { public double calcScore(AbstractEAIndividual indy) {
double[] f = indy.getFitness(); double[] f = indy.getFitness();
return calcScore(f); return calcScore(f);
} }
/**
*
* @param dim
* @param v
*/
public void setAllWeights(int dim, double v) { public void setAllWeights(int dim, double v) {
fitWeights = new double[dim]; fitWeights = new double[dim];
for (int i = 0; i < fitWeights.length; i++) { for (int i = 0; i < fitWeights.length; i++) {

View File

@ -35,6 +35,16 @@ import eva2.tools.chart2d.DPoint;
public abstract class AbstractMultiObjectiveOptimizationProblem extends AbstractOptimizationProblem { public abstract class AbstractMultiObjectiveOptimizationProblem extends AbstractOptimizationProblem {
/**
* Generated serial version identifier
*/
private static final long serialVersionUID = -6882081673229946521L;
/**
*
* @author mkron
*
*/
class MultiObjectiveEvalThread extends Thread{ class MultiObjectiveEvalThread extends Thread{
AbstractMultiObjectiveOptimizationProblem prob; AbstractMultiObjectiveOptimizationProblem prob;
AbstractEAIndividual ind; AbstractEAIndividual ind;
@ -492,6 +502,10 @@ public abstract class AbstractMultiObjectiveOptimizationProblem extends Abstract
return ToolBox.appendArrays(result, super.getAdditionalFileStringValue(pop)); return ToolBox.appendArrays(result, super.getAdditionalFileStringValue(pop));
} }
/*
* (non-Javadoc)
* @see eva2.server.go.problems.AbstractOptimizationProblem#getAdditionalFileStringInfo(eva2.server.go.PopulationInterface)
*/
@Override @Override
public String[] getAdditionalFileStringInfo(PopulationInterface pop) { public String[] getAdditionalFileStringInfo(PopulationInterface pop) {
String[] superInfo = super.getAdditionalFileStringInfo(pop); String[] superInfo = super.getAdditionalFileStringInfo(pop);
@ -499,12 +513,20 @@ public abstract class AbstractMultiObjectiveOptimizationProblem extends Abstract
"Pareto metric on the collected pareto front"}, superInfo); "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) { public String getStringRepresentationForProblem(InterfaceOptimizer opt) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
/**
*
* @param pop
* @return
*/
public double calculateMetric(Population pop) { public double calculateMetric(Population pop) {
if (pop==null || (pop.size()==0)) return Double.NaN; if (pop==null || (pop.size()==0)) return Double.NaN;
return this.m_Metric.calculateMetricOn(pop, this); return this.m_Metric.calculateMetricOn(pop, this);

View File

@ -15,8 +15,23 @@ import eva2.server.go.populations.SolutionSet;
import eva2.server.go.problems.AbstractOptimizationProblem; import eva2.server.go.problems.AbstractOptimizationProblem;
import eva2.server.go.problems.InterfaceOptimizationProblem; import eva2.server.go.problems.InterfaceOptimizationProblem;
/**
*
* @author mkron
*
*/
public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable { public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
/**
* Generated serial version identifier
*/
private static final long serialVersionUID = 1L;
/**
*
* @author mkron
*
*/
class CounterClass { class CounterClass {
public CounterClass(int i) { public CounterClass(int i) {
value = i; value = i;
@ -51,15 +66,28 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
} }
public void hideHideable() { 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) { public void SetIdentifier(String name) {
m_Identifier = name; m_Identifier = name;
} }
@Override /*
* (non-Javadoc)
*
* @see
* eva2.server.go.strategies.InterfaceOptimizer#SetProblem(eva2.server.go
* .problems.InterfaceOptimizationProblem)
*/
public void SetProblem(InterfaceOptimizationProblem problem) { public void SetProblem(InterfaceOptimizationProblem problem) {
m_Problem = (AbstractOptimizationProblem) problem; m_Problem = (AbstractOptimizationProblem) problem;
} }
@ -74,22 +102,38 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
this.m_Listener = ea; this.m_Listener = ea;
} }
@Override /*
* (non-Javadoc)
*
* @see eva2.server.go.strategies.InterfaceOptimizer#freeWilly()
*/
public void freeWilly() { public void freeWilly() {
} }
@Override /*
* (non-Javadoc)
*
* @see eva2.server.go.strategies.InterfaceOptimizer#getAllSolutions()
*/
public InterfaceSolutionSet getAllSolutions() { public InterfaceSolutionSet getAllSolutions() {
Population pop = getPopulation(); Population pop = getPopulation();
return new SolutionSet(pop, pop); return new SolutionSet(pop, pop);
} }
@Override /*
* (non-Javadoc)
*
* @see eva2.server.go.strategies.InterfaceOptimizer#getIdentifier()
*/
public String getIdentifier() { public String getIdentifier() {
return m_Identifier; return m_Identifier;
} }
@Override /*
* (non-Javadoc)
*
* @see eva2.server.go.strategies.InterfaceOptimizer#getName()
*/
public String getName() { public String getName() {
return "(1+" + m_lambda + ") MO-CMA-ES"; return "(1+" + m_lambda + ") MO-CMA-ES";
} }
@ -98,17 +142,30 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
return "A multi-objective CMA-ES variant after Igel, Hansen and Roth 2007 (EC 15(1),1-28)."; return "A multi-objective CMA-ES variant after Igel, Hansen and Roth 2007 (EC 15(1),1-28).";
} }
@Override /*
* (non-Javadoc)
*
* @see eva2.server.go.strategies.InterfaceOptimizer#getPopulation()
*/
public Population getPopulation() { public Population getPopulation() {
return m_Population; return m_Population;
} }
@Override /*
* (non-Javadoc)
*
* @see eva2.server.go.strategies.InterfaceOptimizer#getProblem()
*/
public InterfaceOptimizationProblem getProblem() { public InterfaceOptimizationProblem getProblem() {
return m_Problem; return m_Problem;
} }
@Override /*
* (non-Javadoc)
*
* @see
* eva2.server.go.strategies.InterfaceOptimizer#getStringRepresentation()
*/
public String getStringRepresentation() { public String getStringRepresentation() {
StringBuilder strB = new StringBuilder(200); StringBuilder strB = new StringBuilder(200);
strB.append("(1+" + m_lambda + ") MO-CMA-ES:\nOptimization Problem: "); strB.append("(1+" + m_lambda + ") MO-CMA-ES:\nOptimization Problem: ");
@ -118,7 +175,11 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
return strB.toString(); return strB.toString();
} }
@Override /*
* (non-Javadoc)
*
* @see eva2.server.go.strategies.InterfaceOptimizer#init()
*/
public void init() { public void init() {
// initByPopulation(m_Population, true); // initByPopulation(m_Population, true);
this.m_Population.setTargetSize(m_lambdamo); 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) { public void initByPopulation(Population pop, boolean reset) {
setPopulation(pop); setPopulation(pop);
if (reset) { if (reset) {
@ -149,7 +216,11 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
this.m_Problem.evaluate(population); this.m_Problem.evaluate(population);
} }
@Override /*
* (non-Javadoc)
*
* @see eva2.server.go.strategies.InterfaceOptimizer#optimize()
*/
public void optimize() { public void optimize() {
HashMap<Long, CounterClass> SuccessCounterMap = new HashMap<Long, CounterClass>(); HashMap<Long, CounterClass> SuccessCounterMap = new HashMap<Long, CounterClass>();
@ -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( public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
return false; return false;
} }
@Override /*
* (non-Javadoc)
*
* @see
* eva2.server.go.strategies.InterfaceOptimizer#setPopulation(eva2.server
* .go.populations.Population)
*/
public void setPopulation(Population pop) { public void setPopulation(Population pop) {
m_Population = pop; m_Population = pop;
m_Population.setNotifyEvalInterval(1); m_Population.setNotifyEvalInterval(1);
@ -308,6 +391,7 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
public int getLambda() { public int getLambda() {
return m_lambda; return m_lambda;
} }
public void setLambda(int mLambda) { public void setLambda(int mLambda) {
m_lambda = mLambda; m_lambda = mLambda;
} }

View File

@ -1274,9 +1274,7 @@ public class Mathematics {
* @return * @return
*/ */
public static double[] zeroes(int n) { public static double[] zeroes(int n) {
double[] result = new double[n]; return makeVector(0, n);
Arrays.fill(result, 0, result.length - 1, 0.);
return result;
} }
/** /**
@ -1299,8 +1297,8 @@ public class Mathematics {
* @param vec * @param vec
*/ */
public static void scale(double scale, double[] vec) { public static void scale(double scale, double[] vec) {
for (double d : vec) { for (int i=0; i<vec.length; i++) {
d *= scale; vec[i] *= scale;
} }
} }
} }