Without any loss of functionality, JE2Base can now also be compiled with Java 1.5.

This commit is contained in:
Andreas Dräger 2010-03-29 02:51:13 +00:00
parent 9848734f07
commit df9c625771
2 changed files with 313 additions and 249 deletions

View File

@ -6,190 +6,225 @@ import eva2.server.go.populations.Population;
import eva2.server.go.problems.InterfaceOptimizationProblem; import eva2.server.go.problems.InterfaceOptimizationProblem;
import eva2.tools.math.Jama.Matrix; import eva2.tools.math.Jama.Matrix;
public class MutateESCovarianceMatrixAdaptionPlus extends MutateESCovarianceMatrixAdaption implements InterfaceMutationGenerational public class MutateESCovarianceMatrixAdaptionPlus extends
{ MutateESCovarianceMatrixAdaption implements
InterfaceMutationGenerational {
protected double m_psuccess; protected double m_psuccess;
protected double m_cp; protected double m_cp;
protected double m_psuccesstarget=0.44; protected double m_psuccesstarget = 0.44;
protected double m_stepd; protected double m_stepd;
protected double m_pthresh; protected double m_pthresh;
protected int m_lambda=1; protected int m_lambda = 1;
public MutateESCovarianceMatrixAdaptionPlus() { public MutateESCovarianceMatrixAdaptionPlus() {
super(); super();
} }
public MutateESCovarianceMatrixAdaptionPlus(
public MutateESCovarianceMatrixAdaptionPlus(MutateESCovarianceMatrixAdaptionPlus mutator) { MutateESCovarianceMatrixAdaptionPlus mutator) {
super(mutator); super(mutator);
m_psuccess=mutator.m_psuccess; m_psuccess = mutator.m_psuccess;
m_cp=mutator.m_cp; m_cp = mutator.m_cp;
m_psuccesstarget=mutator.m_psuccesstarget; m_psuccesstarget = mutator.m_psuccesstarget;
m_lambda=mutator.m_lambda; m_lambda = mutator.m_lambda;
m_pthresh=mutator.m_pthresh; m_pthresh = mutator.m_pthresh;
m_stepd=mutator.m_stepd; m_stepd = mutator.m_stepd;
} }
/** This method will enable you to clone a given mutation operator /**
* This method will enable you to clone a given mutation operator
*
* @return The clone * @return The clone
*/ */
public Object clone() { public Object clone() {
return new MutateESCovarianceMatrixAdaptionPlus(this); return new MutateESCovarianceMatrixAdaptionPlus(this);
} }
/**
* This method allows you to init the mutation operator
*
* @param individual
* The individual that will be mutated.
* @param opt
* The optimization problem.
*/
public void init(AbstractEAIndividual individual,
InterfaceOptimizationProblem opt) {
/** This method allows you to init the mutation operator if (!(individual instanceof InterfaceESIndividual))
* @param individual The individual that will be mutated. return;
* @param opt The optimization problem. super.init(individual, opt);
*/ m_psuccesstarget = 1.0 / (5 + Math.sqrt(m_lambda) / 2);
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) { m_psuccess = m_psuccesstarget;
m_stepd = 1.0 + m_D / (2.0 * m_lambda);
m_cp = m_psuccesstarget * m_lambda / (2 + m_psuccesstarget * m_lambda);
m_c = 2.0 / (2.0 + m_D);
this.cov = 2.0 / (6.0 + Math.pow(m_D, 2)); // ATTN: differs from the
// standard CMA-ES
m_pthresh = 0.44;
if (!(individual instanceof InterfaceESIndividual)) return; }
super.init(individual,opt);
m_psuccesstarget=1.0/(5+Math.sqrt(m_lambda)/2);
m_psuccess=m_psuccesstarget;
m_stepd=1.0+m_D/(2.0*m_lambda);
m_cp=m_psuccesstarget*m_lambda/(2+m_psuccesstarget*m_lambda);
m_c=2.0/(2.0+m_D);
this.cov = 2.0/(6.0+Math.pow(m_D, 2)); //ATTN: differs from the standard CMA-ES
m_pthresh=0.44;
} protected void adaptStrategyGen(AbstractEAIndividual child,
AbstractEAIndividual parent) {
if (child.getFitness(0) <= parent.getFitness(0)) {
// updatecov
updateCovariance(child, parent);
// updateCovariance();
}
}
protected void adaptStrategyGen(AbstractEAIndividual child,AbstractEAIndividual parent) {
if(child.getFitness(0)<=parent.getFitness(0)){
//updatecov
updateCovariance(child, parent);
//updateCovariance();
}
}
/** /**
* @param parent * @param parent
* @param child * @param child
*/ */
public void updateCovariance(AbstractEAIndividual child,AbstractEAIndividual parent) { public void updateCovariance(AbstractEAIndividual child,
double[] step=new double[m_D]; AbstractEAIndividual parent) {
for(int i=0;i<m_D;i++){ double[] step = new double[m_D];
step[i]=((InterfaceESIndividual)parent).getDGenotype()[i]-((InterfaceESIndividual)child).getDGenotype()[i]; for (int i = 0; i < m_D; i++) {
} step[i] = ((InterfaceESIndividual) parent).getDGenotype()[i]
- ((InterfaceESIndividual) child).getDGenotype()[i];
}
updateCovariance(step); updateCovariance(step);
} }
public void updateCovariance() { public void updateCovariance() {
double[] step=new double[m_D]; double[] step = new double[m_D];
for(int i=0;i<m_D;i++){ for (int i = 0; i < m_D; i++) {
step[i]=Bz[i]; step[i] = Bz[i];
} }
updateCovariance(step); updateCovariance(step);
} }
/** /**
* @param step * @param step
* *
*/ */
public void updateCovariance(double[] step) { public void updateCovariance(double[] step) {
for(int i=0;i<m_D;i++){ for (int i = 0; i < m_D; i++) {
if(m_psuccess<m_pthresh){ if (m_psuccess < m_pthresh) {
m_PathS[i]=(1.0-m_c)*m_PathS[i]+Math.sqrt(m_c*(2.0-m_c))*(step[i])/m_SigmaGlobal; m_PathS[i] = (1.0 - m_c) * m_PathS[i]
}else{ + Math.sqrt(m_c * (2.0 - m_c)) * (step[i])
m_PathS[i]=(1.0-m_c)*m_PathS[i]; / m_SigmaGlobal;
} } else {
m_PathS[i] = (1.0 - m_c) * m_PathS[i];
}
} }
if(m_psuccess<m_pthresh){ if (m_psuccess < m_pthresh) {
m_C=m_C.multi((1.0-cov)); m_C = m_C.multi((1.0 - cov));
m_C.plusEquals(Matrix.outer(m_PathS, m_PathS).multi(cov)); m_C.plusEquals(Matrix.outer(m_PathS, m_PathS).multi(cov));
}else{ } else {
m_C=m_C.multi((1.0-cov)).plus( m_C = m_C.multi((1.0 - cov)).plus(
(Matrix.outer(m_PathS, m_PathS).plus( (Matrix.outer(m_PathS, m_PathS).plus(
m_C.multi(m_c*(2.0-m_c)) m_C.multi(m_c * (2.0 - m_c))).multi(cov)));
).multi(cov)) }
);
}
} }
protected void adaptStrategy() { protected void adaptStrategy() {
} }
public int getM_lambda() { public int getM_lambda() {
return m_lambda; return m_lambda;
} }
public void setM_lambda(int mLambda) { public void setM_lambda(int mLambda) {
m_lambda = mLambda; m_lambda = mLambda;
} }
@Override
public void crossoverOnStrategyParameters(AbstractEAIndividual indy1,
Population partners) {
// ATTN: Crossover is not defined for this
@Override }
public void crossoverOnStrategyParameters(AbstractEAIndividual indy1,
Population partners) {
// ATTN: Crossover is not defined for this
} // @Override
public void adaptAfterSelection(Population oldPop, Population selectedPop) {
// TODO Auto-generated method stub
@Override }
public void adaptAfterSelection(Population oldPop, Population selectedPop) {
// TODO Auto-generated method stub
} // @Override
public void adaptGenerational(Population selectedPop, Population parentPop,
Population newPop, boolean updateSelected) {
double rate = 0.;
for (int i = 0; i < parentPop.size(); i++) {
// calculate success rate
// System.out.println("new fit / old fit: " +
// BeanInspector.toString(newPop.getEAIndividual(i).getFitness()) +
// " , " +
// BeanInspector.toString(parentPop.getEAIndividual(i).getFitness()));
if (newPop.getEAIndividual(i).getFitness(0) < parentPop
.getEAIndividual(i).getFitness(0))
rate++;
}
rate = rate / parentPop.size();
@Override if (updateSelected)
public void adaptGenerational(Population selectedPop, Population parentPop, Population newPop, boolean updateSelected) { for (int i = 0; i < selectedPop.size(); i++) { // applied to the old
double rate = 0.; // population as
for (int i = 0; i < parentPop.size(); i++) { // well in case of
// calculate success rate // plus strategy
// System.out.println("new fit / old fit: " + BeanInspector.toString(newPop.getEAIndividual(i).getFitness()) + " , " + BeanInspector.toString(parentPop.getEAIndividual(i).getFitness())); MutateESCovarianceMatrixAdaptionPlus mutator = (MutateESCovarianceMatrixAdaptionPlus) ((AbstractEAIndividual) selectedPop
if (newPop.getEAIndividual(i).getFitness(0) < parentPop.getEAIndividual(i).getFitness(0)) rate++; .get(i)).getMutationOperator();
} updateMutator(rate, mutator);
rate = rate / parentPop.size(); if (selectedPop.getEAIndividual(i).getFitness(0) <= parentPop
.getEAIndividual(0).getFitness(0)) {
mutator.adaptStrategyGen(selectedPop.getEAIndividual(i),
parentPop.getEAIndividual(0));
}
// System.out.println("old pop step size " + mutator.getSigma()+
// " (" + mutator+ ")");
}
for (int i = 0; i < newPop.size(); i++) {
MutateESCovarianceMatrixAdaptionPlus mutator = (MutateESCovarianceMatrixAdaptionPlus) ((AbstractEAIndividual) newPop
.get(i)).getMutationOperator();
updateMutator(rate, mutator);
if (newPop.getEAIndividual(i).getFitness(0) <= parentPop
.getEAIndividual(0).getFitness(0)) {
mutator.adaptStrategyGen(newPop.getEAIndividual(i), parentPop
.getEAIndividual(0));
}
// System.out.println("new pop step size " + mutator.getSigma()+
// " (" + mutator+ ")");
}
}
if (updateSelected) for (int i = 0; i < selectedPop.size(); i++) { // applied to the old population as well in case of plus strategy private void updateMutator(double rate,
MutateESCovarianceMatrixAdaptionPlus mutator = (MutateESCovarianceMatrixAdaptionPlus)((AbstractEAIndividual)selectedPop.get(i)).getMutationOperator(); MutateESCovarianceMatrixAdaptionPlus mutator) {
updateMutator(rate, mutator); mutator.updateStepSize(rate);
if(selectedPop.getEAIndividual(i).getFitness(0)<=parentPop.getEAIndividual(0).getFitness(0)){ }
mutator.adaptStrategyGen(selectedPop.getEAIndividual(i),parentPop.getEAIndividual(0));
}
// System.out.println("old pop step size " + mutator.getSigma()+ " (" + mutator+ ")");
}
for (int i = 0; i < newPop.size(); i++) {
MutateESCovarianceMatrixAdaptionPlus mutator = (MutateESCovarianceMatrixAdaptionPlus)((AbstractEAIndividual)newPop.get(i)).getMutationOperator();
updateMutator(rate, mutator);
if(newPop.getEAIndividual(i).getFitness(0)<=parentPop.getEAIndividual(0).getFitness(0)){
mutator.adaptStrategyGen(newPop.getEAIndividual(i),parentPop.getEAIndividual(0));
}
// System.out.println("new pop step size " + mutator.getSigma()+ " (" + mutator+ ")");
}
}
private void updateMutator(double rate, MutateESCovarianceMatrixAdaptionPlus mutator) { public double getM_psuccess() {
mutator.updateStepSize(rate); return m_psuccess;
} }
public double getM_psuccess() {
return m_psuccess;
}
public void updateStepSize(double psuccess) {
this.m_psuccess=(1-m_cp)*m_psuccess+m_cp*psuccess;
m_SigmaGlobal=m_SigmaGlobal*Math.exp(1/m_stepd*(m_psuccess-m_psuccesstarget)/(1-m_psuccesstarget));
}
public String getName() { public void updateStepSize(double psuccess) {
return "CMA mutation for plus Strategies"; this.m_psuccess = (1 - m_cp) * m_psuccess + m_cp * psuccess;
} m_SigmaGlobal = m_SigmaGlobal
/** This method returns a global info string * Math.exp(1 / m_stepd * (m_psuccess - m_psuccesstarget)
* @return description / (1 - m_psuccesstarget));
*/ }
public static String globalInfo() {
return "This is the CMA mutation according to Igel,Hansen,Roth 2007";
}
@Override public String getName() {
public String getStringRepresentation() { return "CMA mutation for plus Strategies";
// TODO Auto-generated method stub }
return "CMA-plus mutation";
} /**
* This method returns a global info string
*
* @return description
*/
public static String globalInfo() {
return "This is the CMA mutation according to Igel,Hansen,Roth 2007";
}
@Override
public String getStringRepresentation() {
// TODO Auto-generated method stub
return "CMA-plus mutation";
}
} }

View File

@ -26,44 +26,39 @@ 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;
import eva2.tools.math.Mathematics; import eva2.tools.math.Mathematics;
import eva2.tools.math.RNG; import eva2.tools.math.RNG;
import eva2.tools.math.Jama.EigenvalueDecomposition; import eva2.tools.math.Jama.EigenvalueDecomposition;
import eva2.tools.math.Jama.Matrix; import eva2.tools.math.Jama.Matrix;
public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
{
class CounterClass{ class CounterClass {
public CounterClass(int i) { public CounterClass(int i) {
value=i; value = i;
} }
public int value; public int value;
public boolean seen=false; public boolean seen = false;
} }
private String m_Identifier = "NelderMeadSimplex"; private String m_Identifier = "NelderMeadSimplex";
private Population m_Population; private Population m_Population;
private AbstractOptimizationProblem m_Problem; private AbstractOptimizationProblem m_Problem;
transient private InterfacePopulationChangedEventListener m_Listener; transient private InterfacePopulationChangedEventListener m_Listener;
private int m_lambda = 1; private int m_lambda = 1;
private int m_lambdamo=1; private int m_lambdamo = 1;
public MultiObjectiveCMAES() { public MultiObjectiveCMAES() {
m_Population=new Population(m_lambdamo); m_Population = new Population(m_lambdamo);
} }
public MultiObjectiveCMAES(MultiObjectiveCMAES a) { public MultiObjectiveCMAES(MultiObjectiveCMAES a) {
m_Problem = (AbstractOptimizationProblem)a.m_Problem.clone(); m_Problem = (AbstractOptimizationProblem) a.m_Problem.clone();
setPopulation((Population)a.m_Population.clone()); setPopulation((Population) a.m_Population.clone());
m_lambda = a.m_lambda; m_lambda = a.m_lambda;
m_Identifier = a.m_Identifier; m_Identifier = a.m_Identifier;
} }
@ -72,80 +67,79 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable
return new MultiObjectiveCMAES(this); return new MultiObjectiveCMAES(this);
} }
// @Override
@Override
public void SetIdentifier(String name) { public void SetIdentifier(String name) {
m_Identifier=name; m_Identifier = name;
} }
@Override // @Override
public void SetProblem(InterfaceOptimizationProblem problem) { public void SetProblem(InterfaceOptimizationProblem problem) {
m_Problem = (AbstractOptimizationProblem)problem; m_Problem = (AbstractOptimizationProblem) problem;
} }
/** This method allows you to add the LectureGUI as listener to the Optimizer /**
* This method allows you to add the LectureGUI as listener to the Optimizer
*
* @param ea * @param ea
*/ */
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) { public void addPopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea; this.m_Listener = ea;
} }
// @Override
@Override
public void freeWilly() { public void freeWilly() {
} }
@Override // @Override
public InterfaceSolutionSet getAllSolutions() { public InterfaceSolutionSet getAllSolutions() {
Population pop = getPopulation(); Population pop = getPopulation();
return new SolutionSet(pop, pop); return new SolutionSet(pop, pop);
} }
@Override // @Override
public String getIdentifier() { public String getIdentifier() {
return m_Identifier; return m_Identifier;
} }
@Override // @Override
public String getName() { public String getName() {
return "(1+"+m_lambda+") MO-CMA-ES"; return "(1+" + m_lambda + ") MO-CMA-ES";
} }
@Override // @Override
public Population getPopulation() { public Population getPopulation() {
return m_Population; return m_Population;
} }
@Override // @Override
public InterfaceOptimizationProblem getProblem() { public InterfaceOptimizationProblem getProblem() {
return m_Problem; return m_Problem;
} }
@Override // @Override
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: ");
strB.append(this.m_Problem.getStringRepresentationForProblem(this)); strB.append(this.m_Problem.getStringRepresentationForProblem(this));
strB.append("\n"); strB.append("\n");
strB.append(this.m_Population.getStringRepresentation()); strB.append(this.m_Population.getStringRepresentation());
return strB.toString(); return strB.toString();
} }
@Override // @Override
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);
this.m_Problem.initPopulation(this.m_Population); this.m_Problem.initPopulation(this.m_Population);
// children = new Population(m_Population.size()); // children = new Population(m_Population.size());
this.evaluatePopulation(this.m_Population); this.evaluatePopulation(this.m_Population);
this.firePropertyChangedEvent(Population.nextGenerationPerformed); this.firePropertyChangedEvent(Population.nextGenerationPerformed);
} }
// @Override
@Override
public void initByPopulation(Population pop, boolean reset) { public void initByPopulation(Population pop, boolean reset) {
setPopulation(pop); setPopulation(pop);
if (reset) { if (reset) {
@ -155,78 +149,100 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable
} }
} }
/** This method will evaluate the current population using the /**
* given problem. * This method will evaluate the current population using the given problem.
* @param population The population that is to be evaluated *
* @param population
* The population that is to be evaluated
*/ */
private void evaluatePopulation(Population population) { private void evaluatePopulation(Population population) {
this.m_Problem.evaluate(population); this.m_Problem.evaluate(population);
} }
@Override // @Override
public void optimize() { public void optimize() {
HashMap<Long, CounterClass> SuccessCounterMap=new HashMap<Long, CounterClass>(); HashMap<Long, CounterClass> SuccessCounterMap = new HashMap<Long, CounterClass>();
//Eltern markieren und für die Zählung vorbereiten // Eltern markieren und f<EFBFBD>r die Z<EFBFBD>hlung vorbereiten
for(int j=0;j<m_lambdamo&&j<m_Population.size();j++){ for (int j = 0; j < m_lambdamo && j < m_Population.size(); j++) {
m_Population.getEAIndividual(j).putData("Parent",m_Population.getEAIndividual(j) ); m_Population.getEAIndividual(j).putData("Parent",
SuccessCounterMap.put(m_Population.getEAIndividual(j).getIndyID(),new CounterClass(0)); m_Population.getEAIndividual(j));
SuccessCounterMap.put(m_Population.getEAIndividual(j).getIndyID(),
new CounterClass(0));
} }
//Kinder erzeugen // Kinder erzeugen
Population children=new Population(m_lambdamo*m_lambda); Population children = new Population(m_lambdamo * m_lambda);
children.setGenerationTo(m_Population.getGeneration()); children.setGenerationTo(m_Population.getGeneration());
for(int j=0;j<children.getTargetSize();j++){ for (int j = 0; j < children.getTargetSize(); j++) {
AbstractEAIndividual parent=m_Population.getEAIndividual(j%m_lambdamo); AbstractEAIndividual parent = m_Population.getEAIndividual(j
AbstractEAIndividual indy=(AbstractEAIndividual)parent.clone(); % m_lambdamo);
AbstractEAIndividual indy = (AbstractEAIndividual) parent.clone();
indy.mutate(); indy.mutate();
indy.putData("Parent", parent); indy.putData("Parent", parent);
children.add(indy); children.add(indy);
} }
evaluatePopulation(children); evaluatePopulation(children);
m_Population.addPopulation(children); m_Population.addPopulation(children);
//Ranking // Ranking
ArchivingNSGAII dummyArchive=new ArchivingNSGAIISMeasure(); ArchivingNSGAII dummyArchive = new ArchivingNSGAIISMeasure();
Population []store=dummyArchive.getNonDomiatedSortedFronts(m_Population); Population[] store = dummyArchive
store=dummyArchive.getNonDomiatedSortedFronts(m_Population); .getNonDomiatedSortedFronts(m_Population);
store = dummyArchive.getNonDomiatedSortedFronts(m_Population);
dummyArchive.calculateCrowdingDistance(store); dummyArchive.calculateCrowdingDistance(store);
//Vergleichen und den Successcounter hochzählen wenn wir besser als unser Elter sind // Vergleichen und den Successcounter hochz<EFBFBD>hlen wenn wir besser als
for(int j=0;j<m_Population.size();j++){ // unser Elter sind
AbstractEAIndividual parent= (AbstractEAIndividual) m_Population.getEAIndividual(j).getData("Parent"); for (int j = 0; j < m_Population.size(); j++) {
if(m_Population.getEAIndividual(j)!=parent){ //Eltern nicht mit sich selber vergleichen AbstractEAIndividual parent = (AbstractEAIndividual) m_Population
int parentParetoLevel=((Integer) parent.getData("ParetoLevel")).intValue(); .getEAIndividual(j).getData("Parent");
double parentSMeasure=((Double) parent.getData("HyperCube")).doubleValue(); if (m_Population.getEAIndividual(j) != parent) { // Eltern nicht mit
int childParetoLevel=((Integer) m_Population.getEAIndividual(j).getData("ParetoLevel")).intValue(); // sich selber
double childSMeasure=((Double) m_Population.getEAIndividual(j).getData("HyperCube")).doubleValue(); // vergleichen
if( childParetoLevel<parentParetoLevel||((childParetoLevel==parentParetoLevel)&&childSMeasure>parentSMeasure ) ){ int parentParetoLevel = ((Integer) parent
.getData("ParetoLevel")).intValue();
double parentSMeasure = ((Double) parent.getData("HyperCube"))
.doubleValue();
int childParetoLevel = ((Integer) m_Population.getEAIndividual(
j).getData("ParetoLevel")).intValue();
double childSMeasure = ((Double) m_Population
.getEAIndividual(j).getData("HyperCube")).doubleValue();
if (childParetoLevel < parentParetoLevel
|| ((childParetoLevel == parentParetoLevel) && childSMeasure > parentSMeasure)) {
SuccessCounterMap.get(parent.getIndyID()).value++; SuccessCounterMap.get(parent.getIndyID()).value++;
} }
}else{ //Debug } else { // Debug
SuccessCounterMap.get(parent.getIndyID()).seen=true; SuccessCounterMap.get(parent.getIndyID()).seen = true;
} }
} }
// Selection
//Selection
m_Population.clear(); m_Population.clear();
for(int i=0;i<store.length;i++){ for (int i = 0; i < store.length; i++) {
if(m_Population.size()+store[i].size()<=m_lambdamo){ //Die Front passt noch komplett if (m_Population.size() + store[i].size() <= m_lambdamo) { // Die
// Front
// passt
// noch
// komplett
m_Population.addPopulation(store[i]); m_Population.addPopulation(store[i]);
}else{ //die besten aus der aktuellen Front heraussuchen bis voll } else { // die besten aus der aktuellen Front heraussuchen bis voll
while(store[i].size()>0&&m_Population.size()<m_lambdamo){ while (store[i].size() > 0 && m_Population.size() < m_lambdamo) {
AbstractEAIndividual indy=store[i].getEAIndividual(0); AbstractEAIndividual indy = store[i].getEAIndividual(0);
double bestMeasure=((Double) indy.getData("HyperCube")).doubleValue(); //TODO mal noch effizient machen (sortieren und die besten n herausholen) double bestMeasure = ((Double) indy.getData("HyperCube"))
for(int j=1;j<store[i].size();j++ ){ .doubleValue(); // TODO mal noch effizient machen
if(bestMeasure<((Double) store[i].getEAIndividual(j).getData("HyperCube")).doubleValue()){ // (sortieren und die besten n
bestMeasure=((Double) store[i].getEAIndividual(j).getData("HyperCube")).doubleValue(); // herausholen)
indy=store[i].getEAIndividual(j); for (int j = 1; j < store[i].size(); j++) {
if (bestMeasure < ((Double) store[i].getEAIndividual(j)
.getData("HyperCube")).doubleValue()) {
bestMeasure = ((Double) store[i].getEAIndividual(j)
.getData("HyperCube")).doubleValue();
indy = store[i].getEAIndividual(j);
} }
} }
m_Population.add(indy); m_Population.add(indy);
@ -236,23 +252,36 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable
} }
//Strategieparemeter updaten // Strategieparemeter updaten
for(int j=0;j<m_Population.size();j++){ for (int j = 0; j < m_Population.size(); j++) {
AbstractEAIndividual indy=m_Population.getEAIndividual(j); AbstractEAIndividual indy = m_Population.getEAIndividual(j);
if(indy.getMutationOperator() instanceof MutateESCovarianceMatrixAdaptionPlus ){ //Das geht nur wenn wir auch die richtige Mutation haben if (indy.getMutationOperator() instanceof MutateESCovarianceMatrixAdaptionPlus) { // Das
AbstractEAIndividual parent=(AbstractEAIndividual)indy.getData("Parent"); // geht
MutateESCovarianceMatrixAdaptionPlus muta=(MutateESCovarianceMatrixAdaptionPlus) indy.getMutationOperator(); // nur
double rate=((double) SuccessCounterMap.get(parent.getIndyID()).value)/((double) m_lambda); // wenn
// wir
// auch
// die
// richtige
// Mutation
// haben
AbstractEAIndividual parent = (AbstractEAIndividual) indy
.getData("Parent");
MutateESCovarianceMatrixAdaptionPlus muta = (MutateESCovarianceMatrixAdaptionPlus) indy
.getMutationOperator();
double rate = ((double) SuccessCounterMap.get(parent
.getIndyID()).value)
/ ((double) m_lambda);
if(indy!=parent){ if (indy != parent) {
muta.updateCovariance(); muta.updateCovariance();
} }
muta.updateStepSize(rate); muta.updateStepSize(rate);
} }
} }
for(int j=0;j<children.size();j++){ for (int j = 0; j < children.size(); j++) {
children.getEAIndividual(j).putData("Parent", null); children.getEAIndividual(j).putData("Parent", null);
} }
@ -262,25 +291,28 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable
} }
@Override // @Override
public boolean removePopulationChangedEventListener( public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
return false; return false;
} }
@Override // @Override
public void setPopulation(Population pop) { public void setPopulation(Population pop) {
m_Population = pop; m_Population = pop;
m_Population.setNotifyEvalInterval(1); m_Population.setNotifyEvalInterval(1);
m_lambdamo=m_Population.getTargetSize(); m_lambdamo = m_Population.getTargetSize();
} }
/** Something has changed /**
* Something has changed
*
* @param name * @param name
*/ */
protected void firePropertyChangedEvent (String name) { protected void firePropertyChangedEvent(String name) {
if (this.m_Listener != null) this.m_Listener.registerPopulationStateChanged(this, name); if (this.m_Listener != null)
this.m_Listener.registerPopulationStateChanged(this, name);
} }
public int getLambda() { public int getLambda() {
@ -291,13 +323,10 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable
m_lambda = mLambda; m_lambda = mLambda;
} }
/*public int getLambdaMo() { /*
return m_lambdamo; * public int getLambdaMo() { return m_lambdamo; }
} *
* public void setLambdaMo(int mLambda) { m_lambdamo = mLambda; }
public void setLambdaMo(int mLambda) { */
m_lambdamo = mLambda;
}*/
} }