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,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<Long, CounterClass> SuccessCounterMap = new HashMap<Long, CounterClass>();
@ -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;
}

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;
}
}
}