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 {
/**
* 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<Object>,
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<Object>,
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<Object>,
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<Object>,
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++) {

View File

@@ -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);

View File

@@ -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,22 +102,38 @@ 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";
}
@@ -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).";
}
@Override
/*
* (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<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(
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;
}

View File

@@ -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<vec.length; i++) {
vec[i] *= scale;
}
}
}