Refactored all m_ from eva2.optimization.strategies

This commit is contained in:
Fabian Becker 2014-01-28 20:37:15 +01:00
parent 22fafe185a
commit 53b5111df7
36 changed files with 1195 additions and 1286 deletions

View File

@ -97,6 +97,6 @@ public class GPNodeOutput extends AbstractGPNode implements java.io.Serializable
// * @return string // * @return string
// */ // */
// public String getStringRepresentation() { // public String getStringRepresentation() {
// return ("( A:" +this.m_Identifier + " )"); // return ("( A:" +this.identifier + " )");
// } // }
} }

View File

@ -642,7 +642,7 @@ public class MOCCOViewer extends JPanel implements InterfaceRefSolutionListener,
// gbc.gridx = 3; // gbc.gridx = 3;
// gbc.gridy = i+1; // gbc.gridy = i+1;
// this.m_JCShow[i] = new JCheckBox(); // this.m_JCShow[i] = new JCheckBox();
// this.m_JCShow[i].setSelected(this.m_MOCCO.m_State.m_Show[i]); // this.m_JCShow[i].setSelected(this.m_MOCCO.m_State.show[i]);
// this.m_JCShow[i].addActionListener(showModeChanged); // this.m_JCShow[i].addActionListener(showModeChanged);
// this.m_History.add(this.m_JCShow[i], gbc); // this.m_History.add(this.m_JCShow[i], gbc);
// gbc.gridx = 4; // gbc.gridx = 4;
@ -663,7 +663,7 @@ public class MOCCOViewer extends JPanel implements InterfaceRefSolutionListener,
// ActionListener showModeChanged = new ActionListener() { // ActionListener showModeChanged = new ActionListener() {
// public void actionPerformed(ActionEvent event) { // public void actionPerformed(ActionEvent event) {
// for (int i = 0; i < m_JCShow.length; i++) { // for (int i = 0; i < m_JCShow.length; i++) {
// m_MOCCO.m_State.m_Show[i] = m_JCShow[i].isSelected(); // m_MOCCO.m_State.show[i] = m_JCShow[i].isSelected();
// } // }
// view.updateView(); // view.updateView();
// } // }

View File

@ -197,7 +197,7 @@ public class ParetoFrontView2D extends JPanel implements InterfaceParetoFrontVie
// first plot the populations // first plot the populations
if (false) { if (false) {
for (int i = 0; i < this.m_MOCCOViewer.m_MOCCO.m_State.m_PopulationHistory.length; i++) { for (int i = 0; i < this.m_MOCCOViewer.m_MOCCO.m_State.m_PopulationHistory.length; i++) {
//System.out.println("Population " + i+" show " +this.m_MOCCOViewer.m_MOCCO.m_State.m_Show[i]); //System.out.println("Population " + i+" show " +this.m_MOCCOViewer.m_MOCCO.m_State.show[i]);
if (this.m_MOCCOViewer.m_MOCCO.m_State.m_Show[i]) { if (this.m_MOCCOViewer.m_MOCCO.m_State.m_Show[i]) {
mySet = new GraphPointSet(i + 10, this.m_Area); mySet = new GraphPointSet(i + 10, this.m_Area);
mySet.setConnectedMode(false); mySet.setConnectedMode(false);

View File

@ -175,10 +175,10 @@ public abstract class AbstractArchiving implements InterfaceArchiving, java.io.S
// * @param b True in case of the debug mode. // * @param b True in case of the debug mode.
// */ // */
// public void setDebugFront(boolean b) { // public void setDebugFront(boolean b) {
// this.m_Debug = b; // this.debug = b;
// } // }
// public boolean getDebugFront() { // public boolean getDebugFront() {
// return this.m_Debug; // return this.debug;
// } // }
// public String debugFrontTipText() { // public String debugFrontTipText() {
// return "Toggles the debug mode."; // return "Toggles the debug mode.";

View File

@ -32,7 +32,7 @@ import java.io.IOException;
*/ */
public class MOClusteringSeparation implements InterfaceMigration, java.io.Serializable { public class MOClusteringSeparation implements InterfaceMigration, java.io.Serializable {
public boolean m_Debug = false; public boolean debug = false;
private ClusteringKMeans m_KMeans = new ClusteringKMeans(); private ClusteringKMeans m_KMeans = new ClusteringKMeans();
private ArchivingNSGAII m_NSGAII = new ArchivingNSGAII(); private ArchivingNSGAII m_NSGAII = new ArchivingNSGAII();
private boolean m_UseConstraints = true; private boolean m_UseConstraints = true;
@ -44,7 +44,7 @@ public class MOClusteringSeparation implements InterfaceMigration, java.io.Seria
} }
public MOClusteringSeparation(MOClusteringSeparation b) { public MOClusteringSeparation(MOClusteringSeparation b) {
this.m_Debug = b.m_Debug; this.debug = b.debug;
this.m_UseConstraints = b.m_UseConstraints; this.m_UseConstraints = b.m_UseConstraints;
if (b.m_KMeans != null) { if (b.m_KMeans != null) {
this.m_KMeans = (ClusteringKMeans) b.m_KMeans.clone(); this.m_KMeans = (ClusteringKMeans) b.m_KMeans.clone();
@ -98,7 +98,7 @@ public class MOClusteringSeparation implements InterfaceMigration, java.io.Seria
// collect the populations // collect the populations
for (int i = 0; i < islands.length; i++) { for (int i = 0; i < islands.length; i++) {
oldIPOP[i] = islands[i].getPopulation(); oldIPOP[i] = islands[i].getPopulation();
if (this.m_Debug) { if (this.debug) {
System.out.println("Got population from " + i + " of size " + oldIPOP[i].size()); System.out.println("Got population from " + i + " of size " + oldIPOP[i].size());
} }
collector.addPopulation((Population) oldIPOP[i].clone()); collector.addPopulation((Population) oldIPOP[i].clone());
@ -106,7 +106,7 @@ public class MOClusteringSeparation implements InterfaceMigration, java.io.Seria
} }
memory = (Population) collector.clone(); memory = (Population) collector.clone();
// if (this.m_Debug) { // if (this.debug) {
// // let's see how they arrive here // // let's see how they arrive here
// Plot plot; // Plot plot;
// double[] tmpD = new double[2]; // double[] tmpD = new double[2];
@ -146,7 +146,7 @@ public class MOClusteringSeparation implements InterfaceMigration, java.io.Seria
double[][] c = this.m_KMeans.getC(); double[][] c = this.m_KMeans.getC();
newIPOP = this.m_KMeans.cluster(collector, c); newIPOP = this.m_KMeans.cluster(collector, c);
if (this.m_Debug) { if (this.debug) {
Plot plot; Plot plot;
double[] tmpD = new double[2]; double[] tmpD = new double[2];
tmpD[0] = 0; tmpD[0] = 0;
@ -199,7 +199,7 @@ public class MOClusteringSeparation implements InterfaceMigration, java.io.Seria
} }
ConstBelongsToDifferentClass b = new ConstBelongsToDifferentClass(myClass, myOtherClass, this.m_KMeans.getUseSearchSpace()); ConstBelongsToDifferentClass b = new ConstBelongsToDifferentClass(myClass, myOtherClass, this.m_KMeans.getUseSearchSpace());
((AbstractMultiObjectiveOptimizationProblem) prob).m_AreaConst4Parallelization.add(b); ((AbstractMultiObjectiveOptimizationProblem) prob).m_AreaConst4Parallelization.add(b);
// if (this.m_Debug) { // if (this.debug) {
// String out = ""; // String out = "";
// out += i+ ". MyClass: {"; // out += i+ ". MyClass: {";
// for (int j = 0; j < myClass.length; j++) out += myClass[j]+"; "; // for (int j = 0; j < myClass.length; j++) out += myClass[j]+"; ";
@ -228,7 +228,7 @@ public class MOClusteringSeparation implements InterfaceMigration, java.io.Seria
if (!oldIPOP[i].targetSizeReached()) { if (!oldIPOP[i].targetSizeReached()) {
oldIPOP[i].addPopulation(this.m_Selection.selectFrom(memory, oldIPOP[i].getTargetSize() - oldIPOP[i].size())); oldIPOP[i].addPopulation(this.m_Selection.selectFrom(memory, oldIPOP[i].getTargetSize() - oldIPOP[i].size()));
} }
if (this.m_Debug) { if (this.debug) {
System.out.println("Setting " + i + " to population size " + oldIPOP[i].size()); System.out.println("Setting " + i + " to population size " + oldIPOP[i].size());
} }
islands[i].setPopulation(oldIPOP[i]); islands[i].setPopulation(oldIPOP[i]);

View File

@ -34,7 +34,7 @@ import java.io.IOException;
*/ */
public class MOConeSeparation implements InterfaceMigration, java.io.Serializable { public class MOConeSeparation implements InterfaceMigration, java.io.Serializable {
public boolean m_Debug = false; public boolean debug = false;
private boolean m_UseAllToDetermineR = false; // since i'm only interessted in the pareto-front this should be set to false!! private boolean m_UseAllToDetermineR = false; // since i'm only interessted in the pareto-front this should be set to false!!
private boolean m_UseConstraints = true; private boolean m_UseConstraints = true;
private InterfaceSelection m_Selection = new SelectRandom(); private InterfaceSelection m_Selection = new SelectRandom();
@ -45,7 +45,7 @@ public class MOConeSeparation implements InterfaceMigration, java.io.Serializabl
} }
public MOConeSeparation(MOConeSeparation b) { public MOConeSeparation(MOConeSeparation b) {
this.m_Debug = b.m_Debug; this.debug = b.debug;
this.m_UseConstraints = b.m_UseConstraints; this.m_UseConstraints = b.m_UseConstraints;
this.m_UseAllToDetermineR = b.m_UseAllToDetermineR; this.m_UseAllToDetermineR = b.m_UseAllToDetermineR;
if (b.m_Selection != null) { if (b.m_Selection != null) {
@ -91,7 +91,7 @@ public class MOConeSeparation implements InterfaceMigration, java.io.Serializabl
// collect the populations // collect the populations
for (int i = 0; i < islands.length; i++) { for (int i = 0; i < islands.length; i++) {
oldIPOP[i] = islands[i].getPopulation(); oldIPOP[i] = islands[i].getPopulation();
if (this.m_Debug) { if (this.debug) {
System.out.println("Got population from " + i + " of size " + oldIPOP[i].size()); System.out.println("Got population from " + i + " of size " + oldIPOP[i].size());
} }
collector.addPopulation((Population) oldIPOP[i].clone()); collector.addPopulation((Population) oldIPOP[i].clone());
@ -118,7 +118,7 @@ public class MOConeSeparation implements InterfaceMigration, java.io.Serializabl
if (!oldIPOP[i].targetSizeReached()) { if (!oldIPOP[i].targetSizeReached()) {
oldIPOP[i].addPopulation(this.m_Selection.selectFrom(memory, oldIPOP[i].getTargetSize() - oldIPOP[i].size())); oldIPOP[i].addPopulation(this.m_Selection.selectFrom(memory, oldIPOP[i].getTargetSize() - oldIPOP[i].size()));
} }
if (this.m_Debug) { if (this.debug) {
System.out.println("Setting island " + i + " to population size " + oldIPOP[i].size()); System.out.println("Setting island " + i + " to population size " + oldIPOP[i].size());
} }
allDom.addElementsToArchive(oldIPOP[i]); allDom.addElementsToArchive(oldIPOP[i]);
@ -136,7 +136,7 @@ public class MOConeSeparation implements InterfaceMigration, java.io.Serializabl
private void coneSeparation2D(Population collector, Population[] newIPOP, InterfaceOptimizer[] islands) { private void coneSeparation2D(Population collector, Population[] newIPOP, InterfaceOptimizer[] islands) {
AbstractEAIndividual indy; AbstractEAIndividual indy;
// if (this.m_Debug) { // if (this.debug) {
// // let's see how they arrive here // // let's see how they arrive here
// // This shows that the Drecksbeutels // // This shows that the Drecksbeutels
// // indeed spread out, even within // // indeed spread out, even within
@ -212,7 +212,7 @@ public class MOConeSeparation implements InterfaceMigration, java.io.Serializabl
// the rest belongs to newIPOP.length-1 // the rest belongs to newIPOP.length-1
newIPOP[newIPOP.length - 1].addPopulation(collector); newIPOP[newIPOP.length - 1].addPopulation(collector);
if (this.m_Debug) { if (this.debug) {
Plot plot; Plot plot;
double[] tmpD = new double[2]; double[] tmpD = new double[2];
tmpD[0] = 0; tmpD[0] = 0;

View File

@ -103,7 +103,7 @@ public class MOXMeansSeparation implements InterfaceMigration, java.io.Serializa
} }
memory = (Population) collector.clone(); memory = (Population) collector.clone();
// if (this.m_Debug) { // if (this.debug) {
// // let's see how they arrive here // // let's see how they arrive here
// Plot plot; // Plot plot;
// double[] tmpD = new double[2]; // double[] tmpD = new double[2];
@ -201,7 +201,7 @@ public class MOXMeansSeparation implements InterfaceMigration, java.io.Serializa
} }
ConstBelongsToDifferentClass b = new ConstBelongsToDifferentClass(myClass, myOtherClass, this.m_XMeans.getUseSearchSpace()); ConstBelongsToDifferentClass b = new ConstBelongsToDifferentClass(myClass, myOtherClass, this.m_XMeans.getUseSearchSpace());
((AbstractMultiObjectiveOptimizationProblem) prob).m_AreaConst4Parallelization.add(b); ((AbstractMultiObjectiveOptimizationProblem) prob).m_AreaConst4Parallelization.add(b);
// if (this.m_Debug) { // if (this.debug) {
// String out = ""; // String out = "";
// out += i+ ". MyClass: {"; // out += i+ ". MyClass: {";
// for (int j = 0; j < myClass.length; j++) out += myClass[j]+"; "; // for (int j = 0; j < myClass.length; j++) out += myClass[j]+"; ";

View File

@ -76,11 +76,11 @@ public class MOSOMaxiMin implements InterfaceMOSOConverter, java.io.Serializable
} }
//////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////
// if (false) { // if (false) {
// this.m_Plot = new eva2.gui.plot.Plot("Debug MaxiMin", "Y1", "Y2"); // this.plot = new eva2.gui.plot.Plot("Debug MaxiMin", "Y1", "Y2");
// this.m_Plot.setUnconnectedPoint(0, 0, 11); // this.plot.setUnconnectedPoint(0, 0, 11);
// this.m_Plot.setUnconnectedPoint(1.2, 2.0, 11); // this.plot.setUnconnectedPoint(1.2, 2.0, 11);
// double[][] trueFitness, moFitness; // double[][] trueFitness, moFitness;
// GraphPointSet mySet = new GraphPointSet(10, this.m_Plot.getFunctionArea()); // GraphPointSet mySet = new GraphPointSet(10, this.plot.getFunctionArea());
// DPoint myPoint; // DPoint myPoint;
// double tmp1, tmp2; // double tmp1, tmp2;
// Chart2DDPointIconText tmp; // Chart2DDPointIconText tmp;

View File

@ -381,7 +381,7 @@ public abstract class AbstractMultiObjectiveOptimizationProblem extends Abstract
Population tmpPop = null; Population tmpPop = null;
if (p.getGeneration() > 2) { if (p.getGeneration() > 2) {
// m_Plot = new eva2.gui.plot.Plot("Multiobjective Optimization", "Y1", "Y2"); // plot = new eva2.gui.plot.Plot("Multiobjective Optimization", "Y1", "Y2");
// i want to plot the pareto front for MOEA and other strategies // i want to plot the pareto front for MOEA and other strategies
// but i have to differentiate between the case where // but i have to differentiate between the case where
// there is a true MOEA at work and where the // there is a true MOEA at work and where the

View File

@ -554,7 +554,7 @@ public class ANPSO extends NichePSO implements InterfaceOptimizer, InterfaceAddi
if (reinitSuperfl) { if (reinitSuperfl) {
for (int i = 0; i < tmpPop.size(); i++) { for (int i = 0; i < tmpPop.size(); i++) {
AbstractEAIndividual indy = tmpPop.getEAIndividual(i); AbstractEAIndividual indy = tmpPop.getEAIndividual(i);
indy.init(m_Problem); indy.init(optimizationProblem);
indy.resetFitness(Double.MAX_VALUE); // TODO this is not so nice... they should be collected in a reinit-list and inserted at the beginning of the next optimize step indy.resetFitness(Double.MAX_VALUE); // TODO this is not so nice... they should be collected in a reinit-list and inserted at the beginning of the next optimize step
ParticleSwarmOptimization.initIndividualDefaults(indy, 0.2); ParticleSwarmOptimization.initIndividualDefaults(indy, 0.2);
ParticleSwarmOptimization.initIndividualMemory(indy); ParticleSwarmOptimization.initIndividualMemory(indy);
@ -802,10 +802,10 @@ public class ANPSO extends NichePSO implements InterfaceOptimizer, InterfaceAddi
// } // }
for (int i = 0; i < getSubSwarms().size(); ++i) { for (int i = 0; i < getSubSwarms().size(); ++i) {
AbstractEAIndividual bestSS = ((ParticleSubSwarmOptimization) getSubSwarms().get(i)).getBestIndividual(); AbstractEAIndividual bestSS = ((ParticleSubSwarmOptimization) getSubSwarms().get(i)).getBestIndividual();
elitePop.addIndividual((AbstractEAIndividual) ((ParticleSubSwarmOptimization) getSubSwarms().get(i)).m_BestIndividual.clone()); elitePop.addIndividual((AbstractEAIndividual) ((ParticleSubSwarmOptimization) getSubSwarms().get(i)).bestIndividual.clone());
} }
for (int i = 0; i < inactiveSubSwarms.size(); ++i) { for (int i = 0; i < inactiveSubSwarms.size(); ++i) {
elitePop.addIndividual((AbstractEAIndividual) ((ParticleSubSwarmOptimization) inactiveSubSwarms.get(i)).m_BestIndividual.clone()); elitePop.addIndividual((AbstractEAIndividual) ((ParticleSubSwarmOptimization) inactiveSubSwarms.get(i)).bestIndividual.clone());
} }
return elitePop; return elitePop;
} }
@ -830,7 +830,7 @@ public class ANPSO extends NichePSO implements InterfaceOptimizer, InterfaceAddi
*/ */
@Override @Override
protected void plotSubSwarms() { protected void plotSubSwarms() {
if (this.m_Problem instanceof Interface2DBorderProblem) { if (this.optimizationProblem instanceof Interface2DBorderProblem) {
//DPointSet popRep = new DPointSet(); //DPointSet popRep = new DPointSet();
InterfaceDataTypeDouble tmpIndy1; InterfaceDataTypeDouble tmpIndy1;
@ -839,7 +839,7 @@ public class ANPSO extends NichePSO implements InterfaceOptimizer, InterfaceAddi
// for all inactive SubSwarms from ANPSO... // for all inactive SubSwarms from ANPSO...
for (int i = 0; i < this.inactiveSubSwarms.size(); i++) { for (int i = 0; i < this.inactiveSubSwarms.size(); i++) {
ParticleSubSwarmOptimization currentsubswarm = this.inactiveSubSwarms.get(i); ParticleSubSwarmOptimization currentsubswarm = this.inactiveSubSwarms.get(i);
InterfaceDataTypeDouble best = (InterfaceDataTypeDouble) currentsubswarm.m_BestIndividual; InterfaceDataTypeDouble best = (InterfaceDataTypeDouble) currentsubswarm.bestIndividual;
plotCircleForIndy((AbstractEAIndividual) best, "[I]"); plotCircleForIndy((AbstractEAIndividual) best, "[I]");
} }
@ -848,7 +848,7 @@ public class ANPSO extends NichePSO implements InterfaceOptimizer, InterfaceAddi
ParticleSubSwarmOptimization currentsubswarm = this.getSubSwarms().get(i); ParticleSubSwarmOptimization currentsubswarm = this.getSubSwarms().get(i);
Population currentsubswarmpop = (Population) currentsubswarm.getPopulation(); Population currentsubswarmpop = (Population) currentsubswarm.getPopulation();
//InterfaceDataTypeDouble best = (InterfaceDataTypeDouble)currentsubswarmpop.getBestIndividual(); //InterfaceDataTypeDouble best = (InterfaceDataTypeDouble)currentsubswarmpop.getBestIndividual();
InterfaceDataTypeDouble best = (InterfaceDataTypeDouble) currentsubswarm.m_BestIndividual; InterfaceDataTypeDouble best = (InterfaceDataTypeDouble) currentsubswarm.bestIndividual;
DPointSet popRep = new DPointSet(); DPointSet popRep = new DPointSet();
//...draw SubSwarm as points //...draw SubSwarm as points
@ -857,7 +857,7 @@ public class ANPSO extends NichePSO implements InterfaceOptimizer, InterfaceAddi
tmpIndy1 = (InterfaceDataTypeDouble) currentsubswarmpop.get(j); tmpIndy1 = (InterfaceDataTypeDouble) currentsubswarmpop.get(j);
popRep.addDPoint(new DPoint(tmpIndy1.getDoubleData()[0], tmpIndy1.getDoubleData()[1])); popRep.addDPoint(new DPoint(tmpIndy1.getDoubleData()[0], tmpIndy1.getDoubleData()[1]));
} }
this.m_TopologySwarm.getFunctionArea().addDElement(popRep); // time consuming this.topoPlot.getFunctionArea().addDElement(popRep); // time consuming
//...draw circle for best //...draw circle for best
if (!currentsubswarm.isActive()) { if (!currentsubswarm.isActive()) {
@ -886,7 +886,7 @@ public class ANPSO extends NichePSO implements InterfaceOptimizer, InterfaceAddi
popRep.addDPoint(new DPoint(tmpIndy1.getDoubleData()[0], tmpIndy1.getDoubleData()[1])); popRep.addDPoint(new DPoint(tmpIndy1.getDoubleData()[0], tmpIndy1.getDoubleData()[1]));
popRep.addDPoint(new DPoint(best.getDoubleData()[0], best.getDoubleData()[1])); popRep.addDPoint(new DPoint(best.getDoubleData()[0], best.getDoubleData()[1]));
} }
this.m_TopologySwarm.getFunctionArea().addDElement(popRep); // time consuming this.topoPlot.getFunctionArea().addDElement(popRep); // time consuming
} }
} // endif } // endif
} }

View File

@ -37,8 +37,8 @@ import java.util.logging.Logger;
@Description(value = "Basic implementation of the Bayesian Optimization Algorithm based on the works by Martin Pelikan and David E. Goldberg.") @Description(value = "Basic implementation of the Bayesian Optimization Algorithm based on the works by Martin Pelikan and David E. Goldberg.")
public class BOA implements InterfaceOptimizer, java.io.Serializable { public class BOA implements InterfaceOptimizer, java.io.Serializable {
private static final Logger LOGGER = Logger.getLogger(BOA.class.getName()); private static final Logger LOGGER = Logger.getLogger(BOA.class.getName());
transient private InterfacePopulationChangedEventListener m_Listener = null; transient private InterfacePopulationChangedEventListener populationChangedEventListener = null;
private String m_Identifier = "BOA"; private String identifier = "BOA";
private int probDim = 8; private int probDim = 8;
private int fitCrit = -1; private int fitCrit = -1;
private int PopSize = 50; private int PopSize = 50;
@ -82,8 +82,8 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
} }
public BOA(BOA b) { public BOA(BOA b) {
this.m_Listener = b.m_Listener; this.populationChangedEventListener = b.populationChangedEventListener;
this.m_Identifier = b.m_Identifier; this.identifier = b.identifier;
this.probDim = b.probDim; this.probDim = b.probDim;
this.fitCrit = b.fitCrit; this.fitCrit = b.fitCrit;
this.PopSize = b.PopSize; this.PopSize = b.PopSize;
@ -126,7 +126,7 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
@Override @Override
public void addPopulationChangedEventListener( public void addPopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea; this.populationChangedEventListener = ea;
} }
private void createDirectoryIfNeeded(String directoryName) { private void createDirectoryIfNeeded(String directoryName) {
@ -141,8 +141,8 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
@Override @Override
public boolean removePopulationChangedEventListener( public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
if (m_Listener == ea) { if (populationChangedEventListener == ea) {
m_Listener = null; populationChangedEventListener = null;
return true; return true;
} else { } else {
return false; return false;
@ -546,8 +546,8 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
* Something has changed * Something has changed
*/ */
protected void firePropertyChangedEvent(String name) { protected void firePropertyChangedEvent(String name) {
if (this.m_Listener != null) { if (this.populationChangedEventListener != null) {
this.m_Listener.registerPopulationStateChanged(this, name); this.populationChangedEventListener.registerPopulationStateChanged(this, name);
} }
} }
@ -568,12 +568,12 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
@Override @Override
public void setIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.identifier = name;
} }
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return this.m_Identifier; return this.identifier;
} }
@Override @Override

View File

@ -32,8 +32,8 @@ import java.util.BitSet;
public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializable, InterfacePopulationChangedEventListener { public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializable, InterfacePopulationChangedEventListener {
private static boolean TRACE = false; private static boolean TRACE = false;
transient private InterfacePopulationChangedEventListener m_Listener = null; transient private InterfacePopulationChangedEventListener populationChangedEventListener = null;
private String m_Identifier = "BinaryScatterSearch"; private String identifier = "BinaryScatterSearch";
private int MaxImpIter = 5; private int MaxImpIter = 5;
private int poolSize = 100; private int poolSize = 100;
private int refSetSize = 10; private int refSetSize = 10;
@ -64,8 +64,8 @@ public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializ
* @param b * @param b
*/ */
public BinaryScatterSearch(BinaryScatterSearch b) { public BinaryScatterSearch(BinaryScatterSearch b) {
this.m_Listener = b.m_Listener; this.populationChangedEventListener = b.populationChangedEventListener;
this.m_Identifier = b.m_Identifier; this.identifier = b.identifier;
this.MaxImpIter = b.MaxImpIter; this.MaxImpIter = b.MaxImpIter;
this.poolSize = b.poolSize; this.poolSize = b.poolSize;
this.refSetSize = b.refSetSize; this.refSetSize = b.refSetSize;
@ -153,14 +153,14 @@ public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializ
@Override @Override
public void addPopulationChangedEventListener( public void addPopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea; this.populationChangedEventListener = ea;
} }
@Override @Override
public boolean removePopulationChangedEventListener( public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
if (m_Listener == ea) { if (populationChangedEventListener == ea) {
m_Listener = null; populationChangedEventListener = null;
return true; return true;
} else { } else {
return false; return false;
@ -773,12 +773,12 @@ public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializ
@Override @Override
public void setIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.identifier = name;
} }
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return this.m_Identifier; return this.identifier;
} }
@Override @Override
@ -797,8 +797,8 @@ public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializ
} }
protected void firePropertyChangedEvent(String name) { protected void firePropertyChangedEvent(String name) {
if (this.m_Listener != null) { if (this.populationChangedEventListener != null) {
this.m_Listener.registerPopulationStateChanged(this, name); this.populationChangedEventListener.registerPopulationStateChanged(this, name);
} }
} }

View File

@ -574,7 +574,7 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
// if (isActive(curSpecies)) { // Lets have only active species... // if (isActive(curSpecies)) { // Lets have only active species...
if ((haltingWindow > 0) && (this.testSpeciesForConvergence(curSpecies))) { if ((haltingWindow > 0) && (this.testSpeciesForConvergence(curSpecies))) {
///////////////////////////////////////////// Halting Window ///////////////////////////////////////////////// ///////////////////////////////////////////// Halting Window /////////////////////////////////////////////////
// if (this.m_Debug) { // if (this.debug) {
// System.out.println("Undiff.Size: " + this.undifferentiatedPopulation.size() +"/"+this.undifferentiatedPopulation.getPopulationSize()); // System.out.println("Undiff.Size: " + this.undifferentiatedPopulation.size() +"/"+this.undifferentiatedPopulation.getPopulationSize());
// System.out.println("Diff.Size : " + ((Population)this.species.get(i)).size() +"/"+((Population)this.species.get(i)).getPopulationSize()); // System.out.println("Diff.Size : " + ((Population)this.species.get(i)).size() +"/"+((Population)this.species.get(i)).getPopulationSize());
// } // }
@ -617,11 +617,11 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
undifferentiatedPopulation.addPopulation(initializeIndividuals(toReinit)); undifferentiatedPopulation.addPopulation(initializeIndividuals(toReinit));
undifferentiatedPopulation.incrFunctionCallsBy(toReinit); undifferentiatedPopulation.incrFunctionCallsBy(toReinit);
// if (this.m_Debug) { // if (this.debug) {
// System.out.println("Undiff.Size: " + this.undifferentiatedPopulation.size() +"/"+this.undifferentiatedPopulation.getPopulationSize()); // System.out.println("Undiff.Size: " + this.undifferentiatedPopulation.size() +"/"+this.undifferentiatedPopulation.getPopulationSize());
// System.out.println("Diff.Size : " + ((Population)this.species.get(i)).size() +"/"+((Population)this.species.get(i)).getPopulationSize()); // System.out.println("Diff.Size : " + ((Population)this.species.get(i)).size() +"/"+((Population)this.species.get(i)).getPopulationSize());
// } // }
// if (this.m_Debug) System.out.println("--------------------------End converged"); // if (this.debug) System.out.println("--------------------------End converged");
////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////
} else { } else {
// actually optimize D_i // actually optimize D_i
@ -718,7 +718,7 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
printState("---After differentiation", reinitPop); printState("---After differentiation", reinitPop);
} }
//if (this.m_Show) this.plot(); //if (this.show) this.plot();
} // end of species differentiation } // end of species differentiation
// plot the populations // plot the populations

View File

@ -39,12 +39,12 @@ import java.io.Serializable;
public class ClusteringHillClimbing implements InterfacePopulationChangedEventListener, public class ClusteringHillClimbing implements InterfacePopulationChangedEventListener,
InterfaceOptimizer, Serializable, InterfaceAdditionalPopulationInformer { InterfaceOptimizer, Serializable, InterfaceAdditionalPopulationInformer {
transient private InterfacePopulationChangedEventListener m_Listener; transient private InterfacePopulationChangedEventListener populationChangedEventListener;
public static final boolean TRACE = false; public static final boolean TRACE = false;
transient private String m_Identifier = ""; transient private String identifier = "";
private Population m_Population = new Population(); private Population population = new Population();
private transient Population archive = new Population(); private transient Population archive = new Population();
private InterfaceOptimizationProblem m_Problem = new F1Problem(); private InterfaceOptimizationProblem optimizationProblem = new F1Problem();
private int hcEvalCycle = 1000; private int hcEvalCycle = 1000;
private int initialPopSize = 100; private int initialPopSize = 100;
private int loopCnt = 0; private int loopCnt = 0;
@ -72,8 +72,8 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
public ClusteringHillClimbing(ClusteringHillClimbing other) { public ClusteringHillClimbing(ClusteringHillClimbing other) {
hideHideable(); hideHideable();
m_Population = (Population) other.m_Population.clone(); population = (Population) other.population.clone();
m_Problem = (InterfaceOptimizationProblem) other.m_Problem.clone(); optimizationProblem = (InterfaceOptimizationProblem) other.optimizationProblem.clone();
hcEvalCycle = other.hcEvalCycle; hcEvalCycle = other.hcEvalCycle;
initialPopSize = other.initialPopSize; initialPopSize = other.initialPopSize;
@ -103,12 +103,12 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
@Override @Override
public void setIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.identifier = name;
} }
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return this.m_Identifier; return this.identifier;
} }
/** /**
@ -118,24 +118,24 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
*/ */
@Override @Override
public void setProblem(InterfaceOptimizationProblem problem) { public void setProblem(InterfaceOptimizationProblem problem) {
this.m_Problem = problem; this.optimizationProblem = problem;
} }
@Override @Override
public InterfaceOptimizationProblem getProblem() { public InterfaceOptimizationProblem getProblem() {
return this.m_Problem; return this.optimizationProblem;
} }
@Override @Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) { public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea; this.populationChangedEventListener = ea;
} }
@Override @Override
public boolean removePopulationChangedEventListener( public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
if (m_Listener == ea) { if (populationChangedEventListener == ea) {
m_Listener = null; populationChangedEventListener = null;
return true; return true;
} else { } else {
return false; return false;
@ -148,10 +148,10 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
mutator = new MutateESFixedStepSize(initialStepSize); mutator = new MutateESFixedStepSize(initialStepSize);
archive = new Population(); archive = new Population();
hideHideable(); hideHideable();
m_Population.setTargetSize(initialPopSize); population.setTargetSize(initialPopSize);
this.m_Problem.initializePopulation(this.m_Population); this.optimizationProblem.initializePopulation(this.population);
m_Population.addPopulationChangedEventListener(null); // noone will be notified directly on pop changes population.addPopulationChangedEventListener(null); // noone will be notified directly on pop changes
this.m_Problem.evaluate(this.m_Population); this.optimizationProblem.evaluate(this.population);
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
} }
@ -164,11 +164,11 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
@Override @Override
public void initByPopulation(Population pop, boolean reset) { public void initByPopulation(Population pop, boolean reset) {
loopCnt = 0; loopCnt = 0;
this.m_Population = (Population) pop.clone(); this.population = (Population) pop.clone();
m_Population.addPopulationChangedEventListener(null); population.addPopulationChangedEventListener(null);
if (reset) { if (reset) {
this.m_Population.init(); this.population.init();
this.m_Problem.evaluate(this.m_Population); this.optimizationProblem.evaluate(this.population);
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
} }
} }
@ -177,8 +177,8 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
* Something has changed * Something has changed
*/ */
protected void firePropertyChangedEvent(String name) { protected void firePropertyChangedEvent(String name) {
if (this.m_Listener != null) { if (this.populationChangedEventListener != null) {
this.m_Listener.registerPopulationStateChanged(this, name); this.populationChangedEventListener.registerPopulationStateChanged(this, name);
} }
} }
@ -187,13 +187,13 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
double improvement; double improvement;
loopCnt++; loopCnt++;
m_Population.addPopulationChangedEventListener(this); population.addPopulationChangedEventListener(this);
m_Population.setNotifyEvalInterval(notifyGuiEvery); population.setNotifyEvalInterval(notifyGuiEvery);
Pair<Population, Double> popD; Pair<Population, Double> popD;
int funCallsBefore = m_Population.getFunctionCalls(); int funCallsBefore = population.getFunctionCalls();
int evalsNow, lastOverhead = (m_Population.getFunctionCalls() % hcEvalCycle); int evalsNow, lastOverhead = (population.getFunctionCalls() % hcEvalCycle);
if (lastOverhead > 0) { if (lastOverhead > 0) {
evalsNow = (2 * hcEvalCycle - (m_Population.getFunctionCalls() % hcEvalCycle)); evalsNow = (2 * hcEvalCycle - (population.getFunctionCalls() % hcEvalCycle));
} else { } else {
evalsNow = hcEvalCycle; evalsNow = hcEvalCycle;
} }
@ -201,7 +201,7 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
if (TRACE) { if (TRACE) {
System.out.println("evalCycle: " + hcEvalCycle + ", evals now: " + evalsNow); System.out.println("evalCycle: " + hcEvalCycle + ", evals now: " + evalsNow);
} }
popD = PostProcess.clusterLocalSearch(localSearchMethod, m_Population, (AbstractOptimizationProblem) m_Problem, sigmaClust, evalsNow, 0.5, mutator); popD = PostProcess.clusterLocalSearch(localSearchMethod, population, (AbstractOptimizationProblem) optimizationProblem, sigmaClust, evalsNow, 0.5, mutator);
// (population, (AbstractOptimizationProblem)problem, sigmaClust, hcEvalCycle - (population.getFunctionCalls() % hcEvalCycle), 0.5); // (population, (AbstractOptimizationProblem)problem, sigmaClust, hcEvalCycle - (population.getFunctionCalls() % hcEvalCycle), 0.5);
if (popD.head().getFunctionCalls() == funCallsBefore) { if (popD.head().getFunctionCalls() == funCallsBefore) {
System.err.println("Bad case, increasing allowed evaluations!"); System.err.println("Bad case, increasing allowed evaluations!");
@ -209,12 +209,12 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
} }
} while (popD.head().getFunctionCalls() == funCallsBefore); } while (popD.head().getFunctionCalls() == funCallsBefore);
improvement = popD.tail(); improvement = popD.tail();
m_Population = popD.head(); population = popD.head();
if (TRACE) { if (TRACE) {
System.out.println("num inds after clusterLS: " + m_Population.size()); System.out.println("num inds after clusterLS: " + population.size());
} }
popD.head().setGeneration(m_Population.getGeneration() + 1); popD.head().setGeneration(population.getGeneration() + 1);
if (doReinitialization && (improvement < minImprovement)) { if (doReinitialization && (improvement < minImprovement)) {
if (TRACE) { if (TRACE) {
@ -231,21 +231,21 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
} }
// store results // store results
archive.setFunctionCalls(m_Population.getFunctionCalls()); archive.setFunctionCalls(population.getFunctionCalls());
archive.addPopulation(m_Population); archive.addPopulation(population);
Population tmpPop = new Population(); Population tmpPop = new Population();
tmpPop.addPopulationChangedEventListener(null); tmpPop.addPopulationChangedEventListener(null);
tmpPop.setTargetSize(initialPopSize); tmpPop.setTargetSize(initialPopSize);
this.m_Problem.initializePopulation(tmpPop); this.optimizationProblem.initializePopulation(tmpPop);
tmpPop.setSameParams(m_Population); tmpPop.setSameParams(population);
tmpPop.setTargetSize(initialPopSize); tmpPop.setTargetSize(initialPopSize);
this.m_Problem.evaluate(tmpPop); this.optimizationProblem.evaluate(tmpPop);
// reset population while keeping function calls etc. // reset population while keeping function calls etc.
m_Population.clear(); population.clear();
m_Population.addPopulation(tmpPop); population.addPopulation(tmpPop);
m_Population.incrFunctionCallsBy(tmpPop.size()); population.incrFunctionCallsBy(tmpPop.size());
} else { // decrease step size for hc } else { // decrease step size for hc
if (localSearchMethod != PostProcessMethod.hillClimber) { if (localSearchMethod != PostProcessMethod.hillClimber) {
@ -270,7 +270,7 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
// System.out.println("bla"); // System.out.println("bla");
// } // }
// set funcalls to real value // set funcalls to real value
m_Population.setFunctionCalls(((Population) source).getFunctionCalls()); population.setFunctionCalls(((Population) source).getFunctionCalls());
// System.out.println("FunCallIntervalReached at " + (((Population)source).getFunctionCalls())); // System.out.println("FunCallIntervalReached at " + (((Population)source).getFunctionCalls()));
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
} }
@ -288,12 +288,12 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
*/ */
@Override @Override
public Population getPopulation() { public Population getPopulation() {
return this.m_Population; return this.population;
} }
@Override @Override
public void setPopulation(Population pop) { public void setPopulation(Population pop) {
this.m_Population = pop; this.population = pop;
} }
public String populationTipText() { public String populationTipText() {
@ -304,11 +304,11 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
public InterfaceSolutionSet getAllSolutions() { public InterfaceSolutionSet getAllSolutions() {
Population tmp = new Population(); Population tmp = new Population();
tmp.addPopulation(archive); tmp.addPopulation(archive);
tmp.addPopulation(m_Population); tmp.addPopulation(population);
tmp.setFunctionCalls(m_Population.getFunctionCalls()); tmp.setFunctionCalls(population.getFunctionCalls());
tmp.setGeneration(m_Population.getGeneration()); tmp.setGeneration(population.getGeneration());
// tmp = PostProcessInterim.clusterBest(tmp, sigma, 0, PostProcessInterim.KEEP_LONERS, PostProcessInterim.BEST_ONLY); // tmp = PostProcessInterim.clusterBest(tmp, sigma, 0, PostProcessInterim.KEEP_LONERS, PostProcessInterim.BEST_ONLY);
return new SolutionSet(m_Population, tmp); return new SolutionSet(population, tmp);
} }
/** /**
@ -323,8 +323,8 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
sbuf.append(", initial pop size: "); sbuf.append(", initial pop size: ");
sbuf.append(getPopulation().getTargetSize()); sbuf.append(getPopulation().getTargetSize());
sbuf.append("Optimization Problem: "); sbuf.append("Optimization Problem: ");
sbuf.append(this.m_Problem.getStringRepresentationForProblem(this)); sbuf.append(this.optimizationProblem.getStringRepresentationForProblem(this));
sbuf.append(this.m_Population.getStringRepresentation()); sbuf.append(this.population.getStringRepresentation());
return sbuf.toString(); return sbuf.toString();
} }
@ -485,7 +485,7 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
@Override @Override
public Object[] getAdditionalDataValue(PopulationInterface pop) { public Object[] getAdditionalDataValue(PopulationInterface pop) {
return new Object[]{m_Population.size(), mutator.getSigma(), archive.size(), archive.getPopulationMeasures()[0]}; return new Object[]{population.size(), mutator.getSigma(), archive.size(), archive.getPopulationMeasures()[0]};
} }
public boolean isDoReinitialization() { public boolean isDoReinitialization() {

View File

@ -52,7 +52,7 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
@Parameter(name = "Lambda", description = "Enhance greediness through amplification of the differential vector to the best individual for DE2.") @Parameter(name = "Lambda", description = "Enhance greediness through amplification of the differential vector to the best individual for DE2.")
private double lambda = 0.6; private double lambda = 0.6;
private double m_Mt = 0.05; private double mt = 0.05;
private int maximumAge = -1; private int maximumAge = -1;
private boolean reEvaluate = false; private boolean reEvaluate = false;
// to log the parents of a newly created indy. // to log the parents of a newly created indy.
@ -60,8 +60,8 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
private transient Vector<AbstractEAIndividual> parents = null; private transient Vector<AbstractEAIndividual> parents = null;
private boolean randomizeFKLambda = false; private boolean randomizeFKLambda = false;
private boolean generational = true; private boolean generational = true;
private String m_Identifier = ""; private String identifier = "";
transient private Vector<InterfacePopulationChangedEventListener> m_Listener = new Vector<InterfacePopulationChangedEventListener>(); transient private Vector<InterfacePopulationChangedEventListener> populationChangedEventListeners = new Vector<>();
private boolean forceRange = true; private boolean forceRange = true;
private boolean cyclePop = false; // if true, individuals are used as parents in a cyclic sequence - otherwise randomly private boolean cyclePop = false; // if true, individuals are used as parents in a cyclic sequence - otherwise randomly
private boolean compareToParent = true; // if true, the challenge indy is compared to its parent, otherwise to a random individual private boolean compareToParent = true; // if true, the challenge indy is compared to its parent, otherwise to a random individual
@ -80,7 +80,7 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
differentialWeight = f; differentialWeight = f;
crossoverRate = k; crossoverRate = k;
this.lambda = lambda; this.lambda = lambda;
m_Mt = mt; this.mt = mt;
} }
/** /**
@ -92,11 +92,11 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
this.DEType = a.DEType; this.DEType = a.DEType;
this.population = (Population) a.population.clone(); this.population = (Population) a.population.clone();
this.optimizationProblem = (AbstractOptimizationProblem) a.optimizationProblem.clone(); this.optimizationProblem = (AbstractOptimizationProblem) a.optimizationProblem.clone();
this.m_Identifier = a.m_Identifier; this.identifier = a.identifier;
this.differentialWeight = a.differentialWeight; this.differentialWeight = a.differentialWeight;
this.crossoverRate = a.crossoverRate; this.crossoverRate = a.crossoverRate;
this.lambda = a.lambda; this.lambda = a.lambda;
this.m_Mt = a.m_Mt; this.mt = a.mt;
this.maximumAge = a.maximumAge; this.maximumAge = a.maximumAge;
this.randomizeFKLambda = a.randomizeFKLambda; this.randomizeFKLambda = a.randomizeFKLambda;
@ -393,7 +393,7 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
if (parents != null) { if (parents != null) {
parents.add(pop.getEAIndividual(parentIndex)); parents.add(pop.getEAIndividual(parentIndex));
} // Add wherever oX is used directly } // Add wherever oX is used directly
if (RNG.flipCoin(this.m_Mt)) { if (RNG.flipCoin(this.mt)) {
double[] xk, xl; double[] xk, xl;
double p, pj, pk, pl; double p, pj, pk, pl;
InterfaceDataTypeDouble indy1 = null, indy2 = null; InterfaceDataTypeDouble indy1 = null, indy2 = null;
@ -679,16 +679,16 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
*/ */
@Override @Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) { public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
if (this.m_Listener == null) { if (this.populationChangedEventListeners == null) {
this.m_Listener = new Vector<InterfacePopulationChangedEventListener>(); this.populationChangedEventListeners = new Vector<InterfacePopulationChangedEventListener>();
} }
this.m_Listener.add(ea); this.populationChangedEventListeners.add(ea);
} }
@Override @Override
public boolean removePopulationChangedEventListener( public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
if (m_Listener != null && m_Listener.removeElement(ea)) { if (populationChangedEventListeners != null && populationChangedEventListeners.removeElement(ea)) {
return true; return true;
} else { } else {
@ -702,9 +702,9 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
* @param name * @param name
*/ */
protected void firePropertyChangedEvent(String name) { protected void firePropertyChangedEvent(String name) {
if (this.m_Listener != null) { if (this.populationChangedEventListeners != null) {
for (int i = 0; i < this.m_Listener.size(); i++) { for (int i = 0; i < this.populationChangedEventListeners.size(); i++) {
this.m_Listener.get(i).registerPopulationStateChanged(this, name); this.populationChangedEventListeners.get(i).registerPopulationStateChanged(this, name);
} }
} }
} }
@ -747,12 +747,12 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
*/ */
@Override @Override
public void setIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.identifier = name;
} }
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return this.m_Identifier; return this.identifier;
} }
/** /**
@ -854,17 +854,17 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
* @param l * @param l
*/ */
public void setMt(double l) { public void setMt(double l) {
this.m_Mt = l; this.mt = l;
if (this.m_Mt < 0) { if (this.mt < 0) {
this.m_Mt = 0; this.mt = 0;
} }
if (this.m_Mt > 1) { if (this.mt > 1) {
this.m_Mt = 1; this.mt = 1;
} }
} }
public double getMt() { public double getMt() {
return this.m_Mt; return this.mt;
} }
public String mtTipText() { public String mtTipText() {

View File

@ -164,44 +164,44 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
resetFitness(indy); resetFitness(indy);
plotIndy(position, null, (Integer) (indy.getData(indexKey))); plotIndy(position, null, (Integer) (indy.getData(indexKey)));
// if (this.m_Show) { // if (this.show) {
// this.m_Plot.setUnconnectedPoint(position[0], position[1], (Integer)(indy.getData(indexKey))); // this.plot.setUnconnectedPoint(position[0], position[1], (Integer)(indy.getData(indexKey)));
//this.m_Plot.setConnectedPoint(curPosition[0] + curVelocity[0], curPosition[1] + curVelocity[1], index+1); //this.plot.setConnectedPoint(curPosition[0] + curVelocity[0], curPosition[1] + curVelocity[1], index+1);
// } // }
//System.out.println("quantum particle " + index + " set to " + newPos[0] + "/" + newPos[1]); //System.out.println("quantum particle " + index + " set to " + newPos[0] + "/" + newPos[1]);
} }
private void plotBestIndy() { private void plotBestIndy() {
if (m_Plot != null) { if (plot != null) {
double[] curPosition = ((InterfaceDataTypeDouble) population.getBestEAIndividual()).getDoubleData(); double[] curPosition = ((InterfaceDataTypeDouble) population.getBestEAIndividual()).getDoubleData();
if (lastBestPlot != null) { if (lastBestPlot != null) {
this.m_Plot.setConnectedPoint(lastBestPlot[0], lastBestPlot[1], 0); this.plot.setConnectedPoint(lastBestPlot[0], lastBestPlot[1], 0);
} }
this.m_Plot.setConnectedPoint(curPosition[0], curPosition[1], 0); this.plot.setConnectedPoint(curPosition[0], curPosition[1], 0);
lastBestPlot = curPosition.clone(); lastBestPlot = curPosition.clone();
} }
} }
@Override @Override
protected void plotIndy(double[] curPosition, double[] curVelocity, int index) { protected void plotIndy(double[] curPosition, double[] curVelocity, int index) {
if (this.m_Show) { if (this.show) {
if (plotBestOnly) { if (plotBestOnly) {
if (index != ((Integer) (population.getBestEAIndividual().getData(indexKey)))) { if (index != ((Integer) (population.getBestEAIndividual().getData(indexKey)))) {
return; return;
} else { } else {
// if (lastBestPlot != null) this.m_Plot.setConnectedPoint(lastBestPlot[0], lastBestPlot[1], index); // if (lastBestPlot != null) this.plot.setConnectedPoint(lastBestPlot[0], lastBestPlot[1], index);
// this.m_Plot.setConnectedPoint(curPosition[0], curPosition[1], index); // this.plot.setConnectedPoint(curPosition[0], curPosition[1], index);
this.m_Plot.setUnconnectedPoint(curPosition[0], curPosition[1], index); this.plot.setUnconnectedPoint(curPosition[0], curPosition[1], index);
lastBestPlot = curPosition.clone(); lastBestPlot = curPosition.clone();
} }
} else { } else {
if (curVelocity == null) { if (curVelocity == null) {
this.m_Plot.setUnconnectedPoint(curPosition[0], curPosition[1], index); this.plot.setUnconnectedPoint(curPosition[0], curPosition[1], index);
} else { } else {
this.m_Plot.setConnectedPoint(curPosition[0], curPosition[1], index); this.plot.setConnectedPoint(curPosition[0], curPosition[1], index);
this.m_Plot.setConnectedPoint(curPosition[0] + curVelocity[0], curPosition[1] + curVelocity[1], index); this.plot.setConnectedPoint(curPosition[0] + curVelocity[0], curPosition[1] + curVelocity[1], index);
} }
} }
} }
@ -253,14 +253,6 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
if (envHasChanged) { if (envHasChanged) {
double chi; double chi;
double[] curVelocity = new double[lastVelocity.length]; double[] curVelocity = new double[lastVelocity.length];
/* old ways
curVelocity[i] = this.m_Inertness * velocity[i];
curVelocity[i] += (this.phi1 * getSpeedLimit(index) * (range[i][1] - range[i][0]) * RNG.randomDouble(-1., 1.));
// the component from the social model
curVelocity[i] += this.phi2*RNG.randomDouble(0,1)*(localBestPos[i]-curPosition[i]);
*/
for (int i = 0; i < lastVelocity.length; i++) { for (int i = 0; i < lastVelocity.length; i++) {
// the component from the old velocity // the component from the old velocity
curVelocity[i] = this.inertnessOrChi * lastVelocity[i]; curVelocity[i] = this.inertnessOrChi * lastVelocity[i];
@ -401,7 +393,7 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
protected void evaluatePopulation(Population population) { protected void evaluatePopulation(Population population) {
envHasChanged = false; envHasChanged = false;
super.evaluatePopulation(population); super.evaluatePopulation(population);
if (m_Show && plotBestOnly) { if (show && plotBestOnly) {
plotBestIndy(); plotBestIndy();
} }
@ -427,11 +419,11 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
@Override @Override
protected void logBestIndividual() { protected void logBestIndividual() {
// log the best individual of the population // log the best individual of the population
if (envHasChanged || (this.population.getBestEAIndividual().isDominatingDebConstraints(this.m_BestIndividual))) { if (envHasChanged || (this.population.getBestEAIndividual().isDominatingDebConstraints(this.bestIndividual))) {
this.m_BestIndividual = (AbstractEAIndividual) this.population.getBestEAIndividual().clone(); this.bestIndividual = (AbstractEAIndividual) this.population.getBestEAIndividual().clone();
this.m_BestIndividual.putData(partBestFitKey, this.m_BestIndividual.getFitness()); this.bestIndividual.putData(partBestFitKey, this.bestIndividual.getFitness());
this.m_BestIndividual.putData(partBestPosKey, ((InterfaceDataTypeDouble) this.m_BestIndividual).getDoubleData()); this.bestIndividual.putData(partBestPosKey, ((InterfaceDataTypeDouble) this.bestIndividual).getDoubleData());
//System.out.println("-- best ind set to " + ((InterfaceDataTypeDouble)this.m_BestIndividual).getDoubleData()[0] + "/" + ((InterfaceDataTypeDouble)this.m_BestIndividual).getDoubleData()[1]); //System.out.println("-- best ind set to " + ((InterfaceDataTypeDouble)this.bestIndividual).getDoubleData()[0] + "/" + ((InterfaceDataTypeDouble)this.bestIndividual).getDoubleData()[1]);
} }
} }
@ -499,7 +491,7 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
public String getStringRepresentation() { public String getStringRepresentation() {
StringBuilder strB = new StringBuilder(200); StringBuilder strB = new StringBuilder(200);
strB.append("Dynamic Particle Swarm Optimization:\nOptimization Problem: "); strB.append("Dynamic Particle Swarm Optimization:\nOptimization Problem: ");
strB.append(this.m_Problem.getStringRepresentationForProblem(this)); strB.append(this.optimizationProblem.getStringRepresentationForProblem(this));
strB.append("\n"); strB.append("\n");
strB.append(this.population.getStringRepresentation()); strB.append(this.population.getStringRepresentation());
return strB.toString(); return strB.toString();
@ -686,7 +678,7 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
} }
public Plot getPlot() { public Plot getPlot() {
return m_Plot; return plot;
} }
/** /**

View File

@ -23,28 +23,28 @@ import eva2.util.annotation.Description;
public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable { public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable {
// These variables are necessary for the simple testcase // These variables are necessary for the simple testcase
private InterfaceOptimizationProblem m_Problem = new B1Problem(); private InterfaceOptimizationProblem optimizationProblem = new B1Problem();
private int m_MultiRuns = 100; private int multiRuns = 100;
private int m_FitnessCalls = 100; private int fitnessCalls = 100;
private int m_FitnessCallsNeeded = 0; private int fitnessCallsNeeded = 0;
GAIndividualBinaryData m_Best, m_Test; GAIndividualBinaryData bestIndividual, testIndividual;
public double m_InitialFloodPeak = 2000.0, m_CurrentFloodPeak; public double initialFloodPeak = 2000.0, currentFloodPeak;
public double m_DrainRate = 1.0; public double drainRate = 1.0;
// These variables are necessary for the more complex LectureGUI enviroment // These variables are necessary for the more complex LectureGUI enviroment
transient private String m_Identifier = ""; transient private String identifier = "";
transient private InterfacePopulationChangedEventListener m_Listener; transient private InterfacePopulationChangedEventListener listener;
private Population m_Population; private Population population;
public FloodAlgorithm() { public FloodAlgorithm() {
this.m_Population = new Population(); this.population = new Population();
this.m_Population.setTargetSize(10); this.population.setTargetSize(10);
} }
public FloodAlgorithm(FloodAlgorithm a) { public FloodAlgorithm(FloodAlgorithm a) {
this.m_Population = (Population) a.m_Population.clone(); this.population = (Population) a.population.clone();
this.m_Problem = (InterfaceOptimizationProblem) a.m_Problem.clone(); this.optimizationProblem = (InterfaceOptimizationProblem) a.optimizationProblem.clone();
this.m_InitialFloodPeak = a.m_InitialFloodPeak; this.initialFloodPeak = a.initialFloodPeak;
this.m_DrainRate = a.m_DrainRate; this.drainRate = a.drainRate;
} }
@Override @Override
@ -57,9 +57,9 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
*/ */
@Override @Override
public void init() { public void init() {
this.m_Problem.initializePopulation(this.m_Population); this.optimizationProblem.initializePopulation(this.population);
this.m_Problem.evaluate(this.m_Population); this.optimizationProblem.evaluate(this.population);
this.m_CurrentFloodPeak = this.m_InitialFloodPeak; this.currentFloodPeak = this.initialFloodPeak;
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
} }
@ -70,13 +70,13 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
*/ */
@Override @Override
public void initByPopulation(Population pop, boolean reset) { public void initByPopulation(Population pop, boolean reset) {
this.m_Population = (Population) pop.clone(); this.population = (Population) pop.clone();
if (reset) { if (reset) {
this.m_Population.init(); this.population.init();
this.m_Problem.evaluate(this.m_Population); this.optimizationProblem.evaluate(this.population);
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
} }
this.m_CurrentFloodPeak = this.m_InitialFloodPeak; this.currentFloodPeak = this.initialFloodPeak;
} }
/** /**
@ -85,26 +85,26 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
@Override @Override
public void optimize() { public void optimize() {
AbstractEAIndividual indy; AbstractEAIndividual indy;
Population original = (Population) this.m_Population.clone(); Population original = (Population) this.population.clone();
double[] fitness; double[] fitness;
for (int i = 0; i < this.m_Population.size(); i++) { for (int i = 0; i < this.population.size(); i++) {
indy = ((AbstractEAIndividual) this.m_Population.get(i)); indy = ((AbstractEAIndividual) this.population.get(i));
double tmpD = indy.getMutationProbability(); double tmpD = indy.getMutationProbability();
indy.setMutationProbability(1.0); indy.setMutationProbability(1.0);
indy.mutate(); indy.mutate();
indy.setMutationProbability(tmpD); indy.setMutationProbability(tmpD);
} }
this.m_Problem.evaluate(this.m_Population); this.optimizationProblem.evaluate(this.population);
for (int i = 0; i < this.m_Population.size(); i++) { for (int i = 0; i < this.population.size(); i++) {
fitness = ((AbstractEAIndividual) this.m_Population.get(i)).getFitness(); fitness = ((AbstractEAIndividual) this.population.get(i)).getFitness();
if (fitness[0] > this.m_CurrentFloodPeak) { if (fitness[0] > this.currentFloodPeak) {
this.m_Population.remove(i); this.population.remove(i);
this.m_Population.add(i, original.get(i)); this.population.add(i, original.get(i));
} }
} }
this.m_CurrentFloodPeak -= this.m_DrainRate; this.currentFloodPeak -= this.drainRate;
this.m_Population.incrGeneration(); this.population.incrGeneration();
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
} }
@ -132,36 +132,36 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
*/ */
@Override @Override
public void setProblem(InterfaceOptimizationProblem problem) { public void setProblem(InterfaceOptimizationProblem problem) {
this.m_Problem = problem; this.optimizationProblem = problem;
} }
@Override @Override
public InterfaceOptimizationProblem getProblem() { public InterfaceOptimizationProblem getProblem() {
return this.m_Problem; return this.optimizationProblem;
} }
/** /**
* This method will init the HillClimber * This method will init the HillClimber
*/ */
public void defaultInit() { public void defaultInit() {
this.m_FitnessCallsNeeded = 0; this.fitnessCallsNeeded = 0;
this.m_Best = new GAIndividualBinaryData(); this.bestIndividual = new GAIndividualBinaryData();
this.m_Best.defaultInit(m_Problem); this.bestIndividual.defaultInit(optimizationProblem);
} }
/** /**
* This method will optimize * This method will optimize
*/ */
public void defaultOptimize() { public void defaultOptimize() {
for (int i = 0; i < m_FitnessCalls; i++) { for (int i = 0; i < fitnessCalls; i++) {
this.m_Test = (GAIndividualBinaryData) ((this.m_Best).clone()); this.testIndividual = (GAIndividualBinaryData) ((this.bestIndividual).clone());
this.m_Test.defaultMutate(); this.testIndividual.defaultMutate();
if (this.m_Test.defaultEvaulateAsMiniBits() < this.m_Best.defaultEvaulateAsMiniBits()) { if (this.testIndividual.defaultEvaulateAsMiniBits() < this.bestIndividual.defaultEvaulateAsMiniBits()) {
this.m_Best = this.m_Test; this.bestIndividual = this.testIndividual;
} }
this.m_FitnessCallsNeeded = i; this.fitnessCallsNeeded = i;
if (this.m_Best.defaultEvaulateAsMiniBits() == 0) { if (this.bestIndividual.defaultEvaulateAsMiniBits() == 0) {
i = this.m_FitnessCalls + 1; i = this.fitnessCalls + 1;
} }
} }
} }
@ -174,15 +174,15 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
public static void main(String[] args) { public static void main(String[] args) {
FloodAlgorithm program = new FloodAlgorithm(); FloodAlgorithm program = new FloodAlgorithm();
int TmpMeanCalls = 0, TmpMeanFitness = 0; int TmpMeanCalls = 0, TmpMeanFitness = 0;
for (int i = 0; i < program.m_MultiRuns; i++) { for (int i = 0; i < program.multiRuns; i++) {
program.defaultInit(); program.defaultInit();
program.defaultOptimize(); program.defaultOptimize();
TmpMeanCalls += program.m_FitnessCallsNeeded; TmpMeanCalls += program.fitnessCallsNeeded;
TmpMeanFitness += program.m_Best.defaultEvaulateAsMiniBits(); TmpMeanFitness += program.bestIndividual.defaultEvaulateAsMiniBits();
} }
TmpMeanCalls /= program.m_MultiRuns; TmpMeanCalls /= program.multiRuns;
TmpMeanFitness /= program.m_MultiRuns; TmpMeanFitness /= program.multiRuns;
System.out.println("(" + program.m_MultiRuns + "/" + program.m_FitnessCalls + ") Mean Fitness : " + TmpMeanFitness + " Mean Calls needed: " + TmpMeanCalls); System.out.println("(" + program.multiRuns + "/" + program.fitnessCalls + ") Mean Fitness : " + TmpMeanFitness + " Mean Calls needed: " + TmpMeanCalls);
} }
/** /**
@ -192,14 +192,14 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
*/ */
@Override @Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) { public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea; this.listener = ea;
} }
@Override @Override
public boolean removePopulationChangedEventListener( public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
if (m_Listener == ea) { if (listener == ea) {
m_Listener = null; listener = null;
return true; return true;
} else { } else {
return false; return false;
@ -210,8 +210,8 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
* Something has changed * Something has changed
*/ */
protected void firePropertyChangedEvent(String name) { protected void firePropertyChangedEvent(String name) {
if (this.m_Listener != null) { if (this.listener != null) {
this.m_Listener.registerPopulationStateChanged(this, name); this.listener.registerPopulationStateChanged(this, name);
} }
} }
@ -224,14 +224,14 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
@Override @Override
public String getStringRepresentation() { public String getStringRepresentation() {
String result = ""; String result = "";
if (this.m_Population.size() > 1) { if (this.population.size() > 1) {
result += "Multi(" + this.m_Population.size() + ")-Start Hill Climbing:\n"; result += "Multi(" + this.population.size() + ")-Start Hill Climbing:\n";
} else { } else {
result += "Simulated Annealing:\n"; result += "Simulated Annealing:\n";
} }
result += "Optimization Problem: "; result += "Optimization Problem: ";
result += this.m_Problem.getStringRepresentationForProblem(this) + "\n"; result += this.optimizationProblem.getStringRepresentationForProblem(this) + "\n";
result += this.m_Population.getStringRepresentation(); result += this.population.getStringRepresentation();
return result; return result;
} }
@ -242,12 +242,12 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
*/ */
@Override @Override
public void setIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.identifier = name;
} }
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return this.m_Identifier; return this.identifier;
} }
/** /**
@ -269,12 +269,12 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
*/ */
@Override @Override
public Population getPopulation() { public Population getPopulation() {
return this.m_Population; return this.population;
} }
@Override @Override
public void setPopulation(Population pop) { public void setPopulation(Population pop) {
this.m_Population = pop; this.population = pop;
} }
public String populationTipText() { public String populationTipText() {
@ -293,11 +293,11 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
* @return The initial flood level. * @return The initial flood level.
*/ */
public double getInitialFloodPeak() { public double getInitialFloodPeak() {
return this.m_InitialFloodPeak; return this.initialFloodPeak;
} }
public void setInitialFloodPeak(double pop) { public void setInitialFloodPeak(double pop) {
this.m_InitialFloodPeak = pop; this.initialFloodPeak = pop;
} }
public String initialFloodPeakTipText() { public String initialFloodPeakTipText() {
@ -311,13 +311,13 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
* @return The drain rate. * @return The drain rate.
*/ */
public double getDrainRate() { public double getDrainRate() {
return this.m_DrainRate; return this.drainRate;
} }
public void setDrainRate(double a) { public void setDrainRate(double a) {
this.m_DrainRate = a; this.drainRate = a;
if (this.m_DrainRate < 0) { if (this.drainRate < 0) {
this.m_DrainRate = 0.0; this.drainRate = 0.0;
} }
} }

View File

@ -24,8 +24,8 @@ import eva2.util.annotation.Description;
@Description("Gradient Descent can be applied to derivable functions (InterfaceFirstOrderDerivableProblem).") @Description("Gradient Descent can be applied to derivable functions (InterfaceFirstOrderDerivableProblem).")
public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Serializable { public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Serializable {
private InterfaceOptimizationProblem m_Problem; private InterfaceOptimizationProblem optimizationProblem;
InterfaceDataTypeDouble m_Best, m_Test; InterfaceDataTypeDouble bestDataTypeDouble, testDataTypeDouble;
private int iterations = 1; private int iterations = 1;
private double wDecreaseStepSize = 0.5; private double wDecreaseStepSize = 0.5;
private double wIncreaseStepSize = 1.1; private double wIncreaseStepSize = 1.1;
@ -41,12 +41,12 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
double localmaxstepsize = 10; double localmaxstepsize = 10;
double localminstepsize = 1e-10; double localminstepsize = 1e-10;
private boolean momentumterm = false; private boolean momentumterm = false;
transient private InterfacePopulationChangedEventListener m_Listener; transient private InterfacePopulationChangedEventListener populationChangedEventListener;
public double maximumabsolutechange = 0.2; public double maximumabsolutechange = 0.2;
// Hashtable indyhash; // Hashtable indyhash;
// These variables are necessary for the more complex LectureGUI enviroment // These variables are necessary for the more complex LectureGUI enviroment
transient private String m_Identifier = ""; transient private String identifier = "";
private Population m_Population; private Population population;
private static boolean TRACE = false; private static boolean TRACE = false;
private static final String lockKey = "gdaLockDataKey"; private static final String lockKey = "gdaLockDataKey";
private static final String lastFitnessKey = "gdaLastFitDataKey"; private static final String lastFitnessKey = "gdaLastFitDataKey";
@ -61,7 +61,7 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
this.setPopulation((Population) pop.clone()); this.setPopulation((Population) pop.clone());
if (reset) { if (reset) {
this.getPopulation().init(); this.getPopulation().init();
this.m_Problem.evaluate(this.getPopulation()); this.optimizationProblem.evaluate(this.getPopulation());
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
} }
//System.out.println("initByPopulation() called"); //System.out.println("initByPopulation() called");
@ -70,8 +70,8 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
public GradientDescentAlgorithm() { public GradientDescentAlgorithm() {
// indyhash = new Hashtable(); // indyhash = new Hashtable();
this.m_Population = new Population(); this.population = new Population();
this.m_Population.setTargetSize(1); this.population.setTargetSize(1);
} }
/** /**
@ -108,8 +108,8 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
public void init() { public void init() {
//System.out.println("init() called "); //System.out.println("init() called ");
// indyhash = new Hashtable(); // indyhash = new Hashtable();
this.m_Problem.initializePopulation(this.m_Population); this.optimizationProblem.initializePopulation(this.population);
this.m_Problem.evaluate(this.m_Population); this.optimizationProblem.evaluate(this.population);
} }
public double signum(double val) { public double signum(double val) {
@ -122,8 +122,8 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
AbstractEAIndividual indy; AbstractEAIndividual indy;
// if ((this.indyhash == null) || (this.indyhash.size() <1)) init(); // if ((this.indyhash == null) || (this.indyhash.size() <1)) init();
for (int i = 0; i < this.m_Population.size(); i++) { for (int i = 0; i < this.population.size(); i++) {
indy = ((AbstractEAIndividual) this.m_Population.get(i)); indy = ((AbstractEAIndividual) this.population.get(i));
if (!indy.hasData(gradientKey)) { if (!indy.hasData(gradientKey)) {
//System.out.println("new indy to hash"); //System.out.println("new indy to hash");
// Hashtable history = new Hashtable(); // Hashtable history = new Hashtable();
@ -146,9 +146,9 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
} }
} }
// System.out.println("hashtable built"); // System.out.println("hashtable built");
for (int i = 0; i < this.m_Population.size(); i++) { for (int i = 0; i < this.population.size(); i++) {
indy = ((AbstractEAIndividual) this.m_Population.get(i)); indy = ((AbstractEAIndividual) this.population.get(i));
double[][] range = ((InterfaceDataTypeDouble) indy).getDoubleRange(); double[][] range = ((InterfaceDataTypeDouble) indy).getDoubleRange();
double[] params = ((InterfaceDataTypeDouble) indy).getDoubleData(); double[] params = ((InterfaceDataTypeDouble) indy).getDoubleData();
indy.putData(oldParamsKey, params); indy.putData(oldParamsKey, params);
@ -157,7 +157,7 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
double indystepsize = ((Double) indy.getData(stepSizeKey)).doubleValue(); double indystepsize = ((Double) indy.getData(stepSizeKey)).doubleValue();
// System.out.println("indystepsize" + indystepsize); // System.out.println("indystepsize" + indystepsize);
if ((this.m_Problem instanceof InterfaceFirstOrderDerivableProblem) && (indy instanceof InterfaceDataTypeDouble)) { if ((this.optimizationProblem instanceof InterfaceFirstOrderDerivableProblem) && (indy instanceof InterfaceDataTypeDouble)) {
// Hashtable history = (Hashtable) indyhash.get(indy); // Hashtable history = (Hashtable) indyhash.get(indy);
for (int iterations = 0; iterations < this.iterations; iterations++) { for (int iterations = 0; iterations < this.iterations; iterations++) {
@ -165,7 +165,7 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
double[] wstepsize = (double[]) indy.getData(wStepSizeKey); double[] wstepsize = (double[]) indy.getData(wStepSizeKey);
double[] oldchange = null; double[] oldchange = null;
double[] gradient = ((InterfaceFirstOrderDerivableProblem) m_Problem).getFirstOrderGradients(params); double[] gradient = ((InterfaceFirstOrderDerivableProblem) optimizationProblem).getFirstOrderGradients(params);
if (TRACE) { if (TRACE) {
System.out.println("GDA: " + BeanInspector.toString(params) + ", grad: " + BeanInspector.toString(gradient)); System.out.println("GDA: " + BeanInspector.toString(params) + ", grad: " + BeanInspector.toString(gradient));
} }
@ -245,12 +245,12 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
} }
} // for loop population size } // for loop population size
this.m_Problem.evaluate(this.m_Population); this.optimizationProblem.evaluate(this.population);
m_Population.incrGeneration(); population.incrGeneration();
if (this.recovery) { if (this.recovery) {
for (int i = 0; i < this.m_Population.size(); i++) { for (int i = 0; i < this.population.size(); i++) {
indy = ((AbstractEAIndividual) this.m_Population.get(i)); indy = ((AbstractEAIndividual) this.population.get(i));
// Hashtable history = (Hashtable) indyhash.get(indy); // Hashtable history = (Hashtable) indyhash.get(indy);
if (indy.getFitness()[0] > recoverythreshold) { if (indy.getFitness()[0] > recoverythreshold) {
if (TRACE) { if (TRACE) {
@ -273,15 +273,15 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
} else { } else {
} }
} }
this.m_Problem.evaluate(this.m_Population); this.optimizationProblem.evaluate(this.population);
m_Population.incrGeneration(); population.incrGeneration();
} }
if (this.globalStepSizeAdaption) { if (this.globalStepSizeAdaption) {
//System.out.println("gsa main"); //System.out.println("gsa main");
for (int i = 0; i < this.m_Population.size(); i++) { for (int i = 0; i < this.population.size(); i++) {
indy = ((AbstractEAIndividual) this.m_Population.get(i)); indy = ((AbstractEAIndividual) this.population.get(i));
// Hashtable history = (Hashtable) indyhash.get(indy); // Hashtable history = (Hashtable) indyhash.get(indy);
// if (history == null) break; // if (history == null) break;
if (indy.getData(lastFitnessKey) != null) { if (indy.getData(lastFitnessKey) != null) {
@ -312,14 +312,14 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
private double momentumweigth = 0.1; private double momentumweigth = 0.1;
protected void firePropertyChangedEvent(String name) { protected void firePropertyChangedEvent(String name) {
if (this.m_Listener != null) { if (this.populationChangedEventListener != null) {
this.m_Listener.registerPopulationStateChanged(this, name); this.populationChangedEventListener.registerPopulationStateChanged(this, name);
} }
} }
@Override @Override
public Population getPopulation() { public Population getPopulation() {
return this.m_Population; return this.population;
} }
@Override @Override
@ -334,7 +334,7 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
// if (indyhash.contains(pop.get(i))) newindyhash.put(pop.get(i), indyhash.get(pop.get(i))); // if (indyhash.contains(pop.get(i))) newindyhash.put(pop.get(i), indyhash.get(pop.get(i)));
// } // }
// indyhash = newindyhash; // indyhash = newindyhash;
this.m_Population = pop; this.population = pop;
} }
/** /**
@ -344,23 +344,23 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
*/ */
@Override @Override
public void setIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.identifier = name;
} }
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return this.m_Identifier; return this.identifier;
} }
@Override @Override
public void setProblem(InterfaceOptimizationProblem problem) { public void setProblem(InterfaceOptimizationProblem problem) {
m_Problem = problem; optimizationProblem = problem;
} }
@Override @Override
public InterfaceOptimizationProblem getProblem() { public InterfaceOptimizationProblem getProblem() {
return m_Problem; return optimizationProblem;
} }
@Override @Override
@ -370,14 +370,14 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
@Override @Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) { public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea; this.populationChangedEventListener = ea;
} }
@Override @Override
public boolean removePopulationChangedEventListener( public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
if (m_Listener == ea) { if (populationChangedEventListener == ea) {
m_Listener = null; populationChangedEventListener = null;
return true; return true;
} else { } else {
return false; return false;

View File

@ -140,43 +140,6 @@ public class HillClimbing implements InterfaceOptimizer, java.io.Serializable {
return this.optimizationProblem; return this.optimizationProblem;
} }
// /** This method will init the HillClimber
// */
// public void defaultInit() {
// this.m_FitnessCallsNeeded = 0;
// this.m_Best = new GAIndividualBinaryData();
// this.m_Best.defaultInit();
// }
//
// /** This method will optimize
// */
// public void defaultOptimize() {
// for (int i = 0; i < maxFitnessCalls; i++) {
// this.m_Test = (GAIndividualBinaryData)((this.m_Best).clone());
// this.m_Test.defaultMutate();
// if (this.m_Test.defaultEvaulateAsMiniBits() < this.m_Best.defaultEvaulateAsMiniBits()) this.m_Best = this.m_Test;
// this.m_FitnessCallsNeeded = i;
// if (this.m_Best.defaultEvaulateAsMiniBits() == 0) i = this.maxFitnessCalls +1;
// }
// }
// /** This main method will start a simple hillclimber.
// * No arguments necessary.
// * @param args
// */
// public static void main(String[] args) {
// HillClimbing program = new HillClimbing();
// int TmpMeanCalls = 0, TmpMeanFitness = 0;
// for (int i = 0; i < program.m_MultiRuns; i++) {
// program.defaultInit();
// program.defaultOptimize();
// TmpMeanCalls += program.m_FitnessCallsNeeded;
// TmpMeanFitness += program.m_Best.defaultEvaulateAsMiniBits();
// }
// TmpMeanCalls = TmpMeanCalls/program.m_MultiRuns;
// TmpMeanFitness = TmpMeanFitness/program.m_MultiRuns;
// System.out.println("("+program.m_MultiRuns+"/"+program.maxFitnessCalls+") Mean Fitness : " + TmpMeanFitness + " Mean Calls needed: " + TmpMeanCalls);
// }
/** /**
* 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
* *

View File

@ -34,37 +34,37 @@ import eva2.util.annotation.Description;
@Description("This is an island model EA distributing the individuals across several (remote) CPUs for optimization.") @Description("This is an island model EA distributing the individuals across several (remote) CPUs for optimization.")
public class IslandModelEA implements InterfacePopulationChangedEventListener, InterfaceOptimizer, java.io.Serializable { public class IslandModelEA implements InterfacePopulationChangedEventListener, InterfaceOptimizer, java.io.Serializable {
private Population m_Population = new Population(); private Population population = new Population();
private InterfaceOptimizer m_Optimizer = new GeneticAlgorithm(); private InterfaceOptimizer optimizer = new GeneticAlgorithm();
private InterfaceMigration m_Migration = new SOBestMigration(); private InterfaceMigration migration = new SOBestMigration();
private InterfaceOptimizationProblem m_Problem = new F8Problem(); private InterfaceOptimizationProblem optimizationProblem = new F8Problem();
// private String[] m_NodesList; // private String[] m_NodesList;
private int m_MigrationRate = 10; private int migrationRate = 10;
private boolean heterogeneousProblems = false; private boolean heterogeneousProblems = false;
// These are the processor to run on // These are the processor to run on
private int m_numLocalCPUs = 1; private int numLocalCPUs = 1;
private boolean m_localOnly = false; private boolean numLocalOnly = false;
transient private InterfaceOptimizer[] m_Islands; transient private InterfaceOptimizer[] islands;
// This is for debugging // This is for debugging
private boolean m_LogLocalChanges = true; private boolean logLocalChanges = true;
private boolean m_Show = false; private boolean show = false;
transient private Plot m_Plot = null; transient private Plot plot = null;
transient private String m_Identifier = ""; transient private String identifier = "";
transient private InterfacePopulationChangedEventListener m_Listener; transient private InterfacePopulationChangedEventListener populationChangedEventListener;
transient private final boolean TRACE = false; transient private final boolean TRACE = false;
public IslandModelEA() { public IslandModelEA() {
} }
public IslandModelEA(IslandModelEA a) { public IslandModelEA(IslandModelEA a) {
this.m_Population = (Population) a.m_Population.clone(); this.population = (Population) a.population.clone();
this.m_Problem = (InterfaceOptimizationProblem) a.m_Problem.clone(); this.optimizationProblem = (InterfaceOptimizationProblem) a.optimizationProblem.clone();
this.m_Optimizer = (InterfaceOptimizer) a.m_Optimizer.clone(); this.optimizer = (InterfaceOptimizer) a.optimizer.clone();
this.m_Migration = (InterfaceMigration) a.m_Migration.clone(); this.migration = (InterfaceMigration) a.migration.clone();
this.m_MigrationRate = a.m_MigrationRate; this.migrationRate = a.migrationRate;
this.heterogeneousProblems = a.heterogeneousProblems; this.heterogeneousProblems = a.heterogeneousProblems;
this.m_numLocalCPUs = a.m_numLocalCPUs; this.numLocalCPUs = a.numLocalCPUs;
this.m_localOnly = a.m_localOnly; this.numLocalOnly = a.numLocalOnly;
} }
@Override @Override
@ -74,31 +74,31 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
@Override @Override
public void init() { public void init() {
if (this.m_Show) { if (this.show) {
if (this.m_Plot == null) { if (this.plot == null) {
double[] tmpD = new double[2]; double[] tmpD = new double[2];
tmpD[0] = 0; tmpD[0] = 0;
tmpD[1] = 0; tmpD[1] = 0;
this.m_Plot = new Plot("Island Model EA", "FitnessCalls", "Fitness", tmpD, tmpD); this.plot = new Plot("Island Model EA", "FitnessCalls", "Fitness", tmpD, tmpD);
} }
} }
// this.population = new Population(); // this.population = new Population();
this.m_Population.clear(); this.population.clear();
this.m_Population.init(); this.population.init();
this.m_Optimizer.init(); this.optimizer.init();
this.m_Optimizer.setProblem(this.m_Problem); this.optimizer.setProblem(this.optimizationProblem);
this.m_Optimizer.setPopulation((Population) m_Population.clone()); this.optimizer.setPopulation((Population) population.clone());
InterfacePopulationChangedEventListener myLocal = null; InterfacePopulationChangedEventListener myLocal = null;
if (this.m_localOnly) { if (this.numLocalOnly) {
// this is running on the local machine // this is running on the local machine
this.m_Islands = new InterfaceOptimizer[this.m_numLocalCPUs]; this.islands = new InterfaceOptimizer[this.numLocalCPUs];
for (int i = 0; i < this.m_numLocalCPUs; i++) { for (int i = 0; i < this.numLocalCPUs; i++) {
this.m_Islands[i] = (InterfaceOptimizer) this.m_Optimizer.clone(); this.islands[i] = (InterfaceOptimizer) this.optimizer.clone();
this.m_Islands[i].setIdentifier("" + i); this.islands[i].setIdentifier("" + i);
this.m_Islands[i].init(); this.islands[i].init();
if (this.m_LogLocalChanges) { if (this.logLocalChanges) {
this.m_Islands[i].addPopulationChangedEventListener(this); this.islands[i].addPopulationChangedEventListener(this);
} }
} }
} else { } else {
@ -116,30 +116,30 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
if ((nodesList == null) || (nodesList.length == 0)) { if ((nodesList == null) || (nodesList.length == 0)) {
throw new RuntimeException("Error, no active remote servers available! Activate servers or use localOnly mode."); throw new RuntimeException("Error, no active remote servers available! Activate servers or use localOnly mode.");
} }
this.m_Islands = new InterfaceOptimizer[nodesList.length]; this.islands = new InterfaceOptimizer[nodesList.length];
for (int i = 0; i < nodesList.length; i++) { for (int i = 0; i < nodesList.length; i++) {
this.m_Islands[i] = (InterfaceOptimizer) RMIProxyRemoteThread.newInstance(this.optimizer, nodesList[i]); this.islands[i] = (InterfaceOptimizer) RMIProxyRemoteThread.newInstance(this.optimizer, nodesList[i]);
this.m_Islands[i].setIdentifier(""+i); this.islands[i].setIdentifier(""+i);
this.m_Islands[i].init(); this.islands[i].init();
if (this.m_LogLocalChanges) { if (this.logLocalChanges) {
this.m_Islands[i].addPopulationChangedEventListener(myLocal); this.islands[i].addPopulationChangedEventListener(myLocal);
} }
}*/ }*/
} }
this.m_Migration.initMigration(this.m_Islands); this.migration.initMigration(this.islands);
Population pop; Population pop;
this.m_Population.incrGeneration(); // the island-initialization has increased the island-pop generations. this.population.incrGeneration(); // the island-initialization has increased the island-pop generations.
for (int i = 0; i < this.m_Islands.length; i++) { for (int i = 0; i < this.islands.length; i++) {
pop = (Population) this.m_Islands[i].getPopulation().clone(); pop = (Population) this.islands[i].getPopulation().clone();
this.m_Population.addPopulation(pop); this.population.addPopulation(pop);
this.m_Population.incrFunctionCallsBy(pop.getFunctionCalls()); this.population.incrFunctionCallsBy(pop.getFunctionCalls());
if (m_Islands[i].getPopulation().getGeneration() != m_Population.getGeneration()) { if (islands[i].getPopulation().getGeneration() != population.getGeneration()) {
System.err.println("Error, inconsistent generations!"); System.err.println("Error, inconsistent generations!");
} }
} }
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED, this.m_Optimizer.getPopulation()); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED, this.optimizer.getPopulation());
} }
/** /**
@ -150,32 +150,32 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
@Override @Override
public void initByPopulation(Population tpop, boolean reset) { public void initByPopulation(Population tpop, boolean reset) {
// TODO this is again evil copy&paste style // TODO this is again evil copy&paste style
if (this.m_Show) { if (this.show) {
if (this.m_Plot == null) { if (this.plot == null) {
double[] tmpD = new double[2]; double[] tmpD = new double[2];
tmpD[0] = 0; tmpD[0] = 0;
tmpD[1] = 0; tmpD[1] = 0;
this.m_Plot = new Plot("Island Model EA", "FitnessCalls", "Fitness", tmpD, tmpD); this.plot = new Plot("Island Model EA", "FitnessCalls", "Fitness", tmpD, tmpD);
} }
} }
this.m_Population = (Population) tpop.clone(); this.population = (Population) tpop.clone();
if (reset) { if (reset) {
this.m_Population.init(); this.population.init();
this.m_Population.incrGeneration(); this.population.incrGeneration();
} }
this.m_Optimizer.init(); this.optimizer.init();
this.m_Optimizer.setProblem(this.m_Problem); this.optimizer.setProblem(this.optimizationProblem);
InterfacePopulationChangedEventListener myLocal = null; InterfacePopulationChangedEventListener myLocal = null;
if (this.m_localOnly) { if (this.numLocalOnly) {
// this is running on the local machine // this is running on the local machine
this.m_Islands = new InterfaceOptimizer[this.m_numLocalCPUs]; this.islands = new InterfaceOptimizer[this.numLocalCPUs];
for (int i = 0; i < this.m_numLocalCPUs; i++) { for (int i = 0; i < this.numLocalCPUs; i++) {
this.m_Islands[i] = (InterfaceOptimizer) this.m_Optimizer.clone(); this.islands[i] = (InterfaceOptimizer) this.optimizer.clone();
this.m_Islands[i].setIdentifier("" + i); this.islands[i].setIdentifier("" + i);
this.m_Islands[i].init(); this.islands[i].init();
if (this.m_LogLocalChanges) { if (this.logLocalChanges) {
this.m_Islands[i].addPopulationChangedEventListener(this); this.islands[i].addPopulationChangedEventListener(this);
} }
} }
} else { } else {
@ -194,25 +194,25 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
if ((nodesList == null) || (nodesList.length == 0)) { if ((nodesList == null) || (nodesList.length == 0)) {
return; return;
} }
this.m_Islands = new InterfaceOptimizer[nodesList.length]; this.islands = new InterfaceOptimizer[nodesList.length];
for (int i = 0; i < nodesList.length; i++) { for (int i = 0; i < nodesList.length; i++) {
this.m_Islands[i] = (InterfaceOptimizer) RMIProxyRemoteThread.newInstance(this.optimizer, nodesList[i]); this.islands[i] = (InterfaceOptimizer) RMIProxyRemoteThread.newInstance(this.optimizer, nodesList[i]);
this.m_Islands[i].setIdentifier(""+i); this.islands[i].setIdentifier(""+i);
this.m_Islands[i].init(); this.islands[i].init();
if (this.m_LogLocalChanges) { if (this.logLocalChanges) {
this.m_Islands[i].addPopulationChangedEventListener(myLocal); this.islands[i].addPopulationChangedEventListener(myLocal);
} }
}*/ }*/
} }
this.m_Migration.initMigration(this.m_Islands); this.migration.initMigration(this.islands);
Population pop; Population pop;
for (int i = 0; i < this.m_Islands.length; i++) { for (int i = 0; i < this.islands.length; i++) {
pop = (Population) this.m_Islands[i].getPopulation().clone(); pop = (Population) this.islands[i].getPopulation().clone();
this.m_Population.addPopulation(pop); this.population.addPopulation(pop);
this.m_Population.incrFunctionCallsBy(pop.getFunctionCalls()); this.population.incrFunctionCallsBy(pop.getFunctionCalls());
} }
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED, this.m_Optimizer.getPopulation()); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED, this.optimizer.getPopulation());
} }
/** /**
@ -220,27 +220,27 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
*/ */
@Override @Override
public void optimize() { public void optimize() {
for (int i = 0; i < this.m_Islands.length; i++) { for (int i = 0; i < this.islands.length; i++) {
if (this.m_Islands[i].getPopulation().size() > 0) { if (this.islands[i].getPopulation().size() > 0) {
this.m_Islands[i].optimize(); this.islands[i].optimize();
if (TRACE) { if (TRACE) {
System.out.println(BeanInspector.toString(m_Islands[i].getPopulation())); System.out.println(BeanInspector.toString(islands[i].getPopulation()));
} }
} else { } else {
this.m_Islands[i].getPopulation().incrGeneration(); this.islands[i].getPopulation().incrGeneration();
} }
if (TRACE) { if (TRACE) {
System.out.println("----"); System.out.println("----");
} }
} }
this.m_Population.incrGeneration(); this.population.incrGeneration();
if ((this.m_Population.getGeneration() % this.m_MigrationRate) == 0) { if ((this.population.getGeneration() % this.migrationRate) == 0) {
this.communicate(); this.communicate();
} }
// this is necessary for heterogeneous islands // this is necessary for heterogeneous islands
if (this.heterogeneousProblems) { if (this.heterogeneousProblems) {
for (int i = 0; i < this.m_Islands.length; i++) { for (int i = 0; i < this.islands.length; i++) {
this.m_Islands[i].getProblem().evaluate(this.m_Islands[i].getPopulation()); this.islands[i].getProblem().evaluate(this.islands[i].getPopulation());
} }
} }
System.gc(); System.gc();
@ -252,13 +252,13 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
private void communicate() { private void communicate() {
// Here i'll have to wait until all islands are finished // Here i'll have to wait until all islands are finished
boolean allReachedG = false; boolean allReachedG = false;
int G = this.m_Population.getGeneration(); int G = this.population.getGeneration();
while (!allReachedG) { while (!allReachedG) {
allReachedG = true; allReachedG = true;
String gen = "["; String gen = "[";
for (int i = 0; i < this.m_Islands.length; i++) { for (int i = 0; i < this.islands.length; i++) {
gen += this.m_Islands[i].getPopulation().getGeneration() + "; "; gen += this.islands[i].getPopulation().getGeneration() + "; ";
if (this.m_Islands[i].getPopulation().getGeneration() != G) { if (this.islands[i].getPopulation().getGeneration() != G) {
allReachedG = false; allReachedG = false;
} }
} }
@ -271,22 +271,22 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
} }
} }
} }
this.m_Population.clear(); this.population.clear();
this.m_Population.setFunctionCalls(0); this.population.setFunctionCalls(0);
Population pop; Population pop;
for (int i = 0; i < this.m_Islands.length; i++) { for (int i = 0; i < this.islands.length; i++) {
pop = (Population) this.m_Islands[i].getPopulation().clone(); pop = (Population) this.islands[i].getPopulation().clone();
this.m_Population.addPopulation(pop); this.population.addPopulation(pop);
this.m_Population.incrFunctionCallsBy(pop.getFunctionCalls()); this.population.incrFunctionCallsBy(pop.getFunctionCalls());
} }
// System.out.println("Fitnesscalls :" + this.population.getFunctionCalls()); // System.out.println("Fitnesscalls :" + this.population.getFunctionCalls());
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED, this.m_Optimizer.getPopulation()); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED, this.optimizer.getPopulation());
double plotValue = (this.m_Problem.getDoublePlotValue(this.m_Population)).doubleValue(); double plotValue = (this.optimizationProblem.getDoublePlotValue(this.population)).doubleValue();
if (this.m_Show) { if (this.show) {
this.m_Plot.setConnectedPoint(this.m_Population.getFunctionCalls(), plotValue, 0); this.plot.setConnectedPoint(this.population.getFunctionCalls(), plotValue, 0);
} }
// now they are synchronized // now they are synchronized
this.m_Migration.migrate(this.m_Islands); this.migration.migrate(this.islands);
} }
/** /**
@ -296,14 +296,14 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
*/ */
@Override @Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) { public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea; this.populationChangedEventListener = ea;
} }
@Override @Override
public boolean removePopulationChangedEventListener( public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
if (m_Listener == ea) { if (populationChangedEventListener == ea) {
m_Listener = null; populationChangedEventListener = null;
return true; return true;
} else { } else {
return false; return false;
@ -314,8 +314,8 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
* Something has changed * Something has changed
*/ */
protected void firePropertyChangedEvent(String name, Population population) { protected void firePropertyChangedEvent(String name, Population population) {
if (this.m_Listener != null) { if (this.populationChangedEventListener != null) {
this.m_Listener.registerPopulationStateChanged(this, name); this.populationChangedEventListener.registerPopulationStateChanged(this, name);
} }
} }
@ -326,13 +326,13 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
*/ */
@Override @Override
public void setProblem(InterfaceOptimizationProblem problem) { public void setProblem(InterfaceOptimizationProblem problem) {
this.m_Problem = problem; this.optimizationProblem = problem;
this.m_Optimizer.setProblem(problem); this.optimizer.setProblem(problem);
} }
@Override @Override
public InterfaceOptimizationProblem getProblem() { public InterfaceOptimizationProblem getProblem() {
return this.m_Problem; return this.optimizationProblem;
} }
/** /**
@ -346,18 +346,18 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
String result = ""; String result = "";
result += "Island Model Evolutionary Algorithm:\n"; result += "Island Model Evolutionary Algorithm:\n";
result += "Using:\n"; result += "Using:\n";
result += " Migration Strategy = " + this.m_Migration.getClass().toString() + "\n"; result += " Migration Strategy = " + this.migration.getClass().toString() + "\n";
result += " Migration rate = " + this.m_MigrationRate + "\n"; result += " Migration rate = " + this.migrationRate + "\n";
result += " Local only = " + this.m_localOnly + "\n"; result += " Local only = " + this.numLocalOnly + "\n";
result += " Het. Problems = " + this.heterogeneousProblems + "\n"; result += " Het. Problems = " + this.heterogeneousProblems + "\n";
if (this.heterogeneousProblems) { if (this.heterogeneousProblems) {
result += " Heterogenuous Optimizers: \n"; result += " Heterogenuous Optimizers: \n";
for (int i = 0; i < this.m_Islands.length; i++) { for (int i = 0; i < this.islands.length; i++) {
result += this.m_Islands[i].getStringRepresentation() + "\n"; result += this.islands[i].getStringRepresentation() + "\n";
} }
} else { } else {
result += " Homogeneous Optimizer = " + this.m_Optimizer.getClass().toString() + "\n"; result += " Homogeneous Optimizer = " + this.optimizer.getClass().toString() + "\n";
result += this.m_Optimizer.getStringRepresentation() + "\n"; result += this.optimizer.getStringRepresentation() + "\n";
} }
//result += "=> The Optimization Problem: "; //result += "=> The Optimization Problem: ";
//result += this.problem.getStringRepresentationForProblem(this) +"\n"; //result += this.problem.getStringRepresentationForProblem(this) +"\n";
@ -374,14 +374,14 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
// @todo die ServerStarter muss ich noch hin kriegen // @todo die ServerStarter muss ich noch hin kriegen
// @todo Wichtig ich brauche den eva2.tools.jproxy.RMIServer! // @todo Wichtig ich brauche den eva2.tools.jproxy.RMIServer!
IslandModelEA imea = new IslandModelEA(); IslandModelEA imea = new IslandModelEA();
imea.m_Show = true; imea.show = true;
imea.m_localOnly = false; imea.numLocalOnly = false;
if (false) { if (false) {
imea.m_Optimizer = new MultiObjectiveEA(); imea.optimizer = new MultiObjectiveEA();
((MultiObjectiveEA) imea.m_Optimizer).setArchiveSize(25); ((MultiObjectiveEA) imea.optimizer).setArchiveSize(25);
((MultiObjectiveEA) imea.m_Optimizer).getPopulation().setTargetSize(50); ((MultiObjectiveEA) imea.optimizer).getPopulation().setTargetSize(50);
imea.m_Problem = new TF1Problem(); imea.optimizationProblem = new TF1Problem();
((TF1Problem) imea.m_Problem).setEAIndividual(new ESIndividualDoubleData()); ((TF1Problem) imea.optimizationProblem).setEAIndividual(new ESIndividualDoubleData());
// ((TF1Problem)imea.problem).setEAIndividual(new ESIndividualDoubleData()); // ((TF1Problem)imea.problem).setEAIndividual(new ESIndividualDoubleData());
// imea.problem = new TFPortfolioSelectionProblem(); // imea.problem = new TFPortfolioSelectionProblem();
// ((TFPortfolioSelectionProblem)imea.problem).setEAIndividual(new ESIndividualDoubleData()); // ((TFPortfolioSelectionProblem)imea.problem).setEAIndividual(new ESIndividualDoubleData());
@ -389,23 +389,23 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
MOClusteringSeparation c = new MOClusteringSeparation(); MOClusteringSeparation c = new MOClusteringSeparation();
c.getKMeans().setUseSearchSpace(false); c.getKMeans().setUseSearchSpace(false);
c.setUseConstraints(true); c.setUseConstraints(true);
c.m_Debug = true; c.debug = true;
imea.m_Migration = c; imea.migration = c;
} }
if (false) { if (false) {
MOConeSeparation c = new MOConeSeparation(); MOConeSeparation c = new MOConeSeparation();
c.setUseConstraints(true); c.setUseConstraints(true);
c.m_Debug = true; c.debug = true;
imea.m_Migration = c; imea.migration = c;
} }
if (true) { if (true) {
imea.m_Migration = new MOBestMigration(); imea.migration = new MOBestMigration();
} }
} else { } else {
imea.m_Problem = new F8Problem(); imea.optimizationProblem = new F8Problem();
((F1Problem) imea.m_Problem).setEAIndividual(new ESIndividualDoubleData()); ((F1Problem) imea.optimizationProblem).setEAIndividual(new ESIndividualDoubleData());
} }
imea.m_MigrationRate = 15; imea.migrationRate = 15;
imea.init(); imea.init();
while (imea.getPopulation().getFunctionCalls() < 25000) { while (imea.getPopulation().getFunctionCalls() < 25000) {
imea.optimize(); imea.optimize();
@ -421,12 +421,12 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
*/ */
@Override @Override
public void setIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.identifier = name;
} }
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return this.m_Identifier; return this.identifier;
} }
/** /**
@ -435,7 +435,7 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
* @return An array of optimizers * @return An array of optimizers
*/ */
public InterfaceOptimizer[] getOptimizers() { public InterfaceOptimizer[] getOptimizers() {
return this.m_Islands; return this.islands;
} }
/** /**
@ -464,14 +464,11 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
InterfaceOptimizer opt = (InterfaceOptimizer) source; InterfaceOptimizer opt = (InterfaceOptimizer) source;
int sourceID = new Integer(opt.getIdentifier()).intValue(); int sourceID = new Integer(opt.getIdentifier()).intValue();
double cFCOpt = opt.getPopulation().getFunctionCalls(); double cFCOpt = opt.getPopulation().getFunctionCalls();
double plotValue = (this.m_Problem.getDoublePlotValue(opt.getPopulation())).doubleValue(); double plotValue = (this.optimizationProblem.getDoublePlotValue(opt.getPopulation())).doubleValue();
if (this.m_Show) { if (this.show) {
this.m_Plot.setConnectedPoint(cFCOpt, plotValue, (sourceID + 1)); this.plot.setConnectedPoint(cFCOpt, plotValue, (sourceID + 1));
} }
//System.out.println("Someone has finished, ("+this.m_Generation+"/"+this.m_Performed+")");
//System.out.println(sourceID + " is at generation "+ opt.getPopulation().getGeneration() +" i'm at " +this.m_Generation);
} }
@ -494,10 +491,10 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
// TODO Deactivated from GUI because the current implementation does not really parallelize on a multicore. // TODO Deactivated from GUI because the current implementation does not really parallelize on a multicore.
// Instead, the new direct problem parallelization can be used. // Instead, the new direct problem parallelization can be used.
// public boolean isLocalOnly() { // public boolean isLocalOnly() {
// return this.m_localOnly; // return this.numLocalOnly;
// } // }
public void setLocalOnly(boolean b) { public void setLocalOnly(boolean b) {
this.m_localOnly = b; this.numLocalOnly = b;
} }
public String localOnlyTipText() { public String localOnlyTipText() {
@ -510,12 +507,12 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
* @return The current optimzation mode * @return The current optimzation mode
*/ */
public boolean getShow() { public boolean getShow() {
return this.m_Show; return this.show;
} }
public void setShow(boolean b) { public void setShow(boolean b) {
this.m_Show = b; this.show = b;
this.m_LogLocalChanges = b; this.logLocalChanges = b;
} }
public String showTipText() { public String showTipText() {
@ -528,11 +525,11 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
* @return The current optimizing method * @return The current optimizing method
*/ */
public InterfaceOptimizer getOptimizer() { public InterfaceOptimizer getOptimizer() {
return this.m_Optimizer; return this.optimizer;
} }
public void setOptimizer(InterfaceOptimizer b) { public void setOptimizer(InterfaceOptimizer b) {
this.m_Optimizer = b; this.optimizer = b;
} }
public String optimizerTipText() { public String optimizerTipText() {
@ -545,11 +542,11 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
* @return The current migration strategy * @return The current migration strategy
*/ */
public InterfaceMigration getMigrationStrategy() { public InterfaceMigration getMigrationStrategy() {
return this.m_Migration; return this.migration;
} }
public void setMigrationStrategy(InterfaceMigration b) { public void setMigrationStrategy(InterfaceMigration b) {
this.m_Migration = b; this.migration = b;
} }
public String migrationStrategyTipText() { public String migrationStrategyTipText() {
@ -562,11 +559,11 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
* @return The current migration rate * @return The current migration rate
*/ */
public int getMigrationRate() { public int getMigrationRate() {
return this.m_MigrationRate; return this.migrationRate;
} }
public void setMigrationRate(int b) { public void setMigrationRate(int b) {
this.m_MigrationRate = b; this.migrationRate = b;
} }
public String migrationRateTipText() { public String migrationRateTipText() {
@ -586,13 +583,13 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
*/ */
@Override @Override
public Population getPopulation() { public Population getPopulation() {
return this.m_Population; return this.population;
} }
@Override @Override
public void setPopulation(Population pop) { public void setPopulation(Population pop) {
// @todo Jetzt m<EFBFBD>sste ich die pop auch auf die Rechner verteilen... // @todo Jetzt m<EFBFBD>sste ich die pop auch auf die Rechner verteilen...
this.m_Population = pop; this.population = pop;
} }
public String populationTipText() { public String populationTipText() {
@ -611,7 +608,7 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
*/ */
public void setNumberLocalCPUs(int n) { public void setNumberLocalCPUs(int n) {
if (n >= 1) { if (n >= 1) {
this.m_numLocalCPUs = n; this.numLocalCPUs = n;
} else { } else {
System.err.println("Number of CPUs must be at least 1!"); System.err.println("Number of CPUs must be at least 1!");
} }

View File

@ -27,7 +27,7 @@ public class LTGA implements InterfaceOptimizer, java.io.Serializable, Interface
private static final Logger LOGGER = Logger.getLogger(LTGA.class.getName()); private static final Logger LOGGER = Logger.getLogger(LTGA.class.getName());
transient private InterfacePopulationChangedEventListener populationChangedEventListener = null; transient private InterfacePopulationChangedEventListener populationChangedEventListener = null;
private String m_Identifier = "LTGA"; private String identifier = "LTGA";
private int probDim = 8; private int probDim = 8;
private int fitCrit = -1; private int fitCrit = -1;
private int popSize = 50; private int popSize = 50;
@ -42,7 +42,7 @@ public class LTGA implements InterfaceOptimizer, java.io.Serializable, Interface
public LTGA(LTGA l) { public LTGA(LTGA l) {
this.populationChangedEventListener = l.populationChangedEventListener; this.populationChangedEventListener = l.populationChangedEventListener;
this.m_Identifier = l.m_Identifier; this.identifier = l.identifier;
this.probDim = l.probDim; this.probDim = l.probDim;
this.popSize = l.popSize; this.popSize = l.popSize;
this.population = (Population) l.population.clone(); this.population = (Population) l.population.clone();
@ -328,12 +328,12 @@ public class LTGA implements InterfaceOptimizer, java.io.Serializable, Interface
@Override @Override
public void setIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.identifier = name;
} }
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return this.m_Identifier; return this.identifier;
} }
@Override @Override

View File

@ -24,8 +24,8 @@ import java.util.logging.Logger;
public class MLTGA implements InterfaceOptimizer, java.io.Serializable, InterfacePopulationChangedEventListener { public class MLTGA implements InterfaceOptimizer, java.io.Serializable, InterfacePopulationChangedEventListener {
private static final Logger LOGGER = Logger.getLogger(MLTGA.class.getName()); private static final Logger LOGGER = Logger.getLogger(MLTGA.class.getName());
transient private InterfacePopulationChangedEventListener m_Listener = null; transient private InterfacePopulationChangedEventListener populationChangedEventListener = null;
private String m_Identifier = "LTGA"; private String identifier = "MLTGA";
private int probDim = 8; private int probDim = 8;
private int fitCrit = -1; private int fitCrit = -1;
private int popSize = 50; private int popSize = 50;
@ -39,8 +39,8 @@ public class MLTGA implements InterfaceOptimizer, java.io.Serializable, Interfac
} }
public MLTGA(MLTGA l) { public MLTGA(MLTGA l) {
this.m_Listener = l.m_Listener; this.populationChangedEventListener = l.populationChangedEventListener;
this.m_Identifier = l.m_Identifier; this.identifier = l.identifier;
this.probDim = l.probDim; this.probDim = l.probDim;
this.popSize = l.popSize; this.popSize = l.popSize;
this.population = (Population) l.population.clone(); this.population = (Population) l.population.clone();
@ -65,15 +65,15 @@ public class MLTGA implements InterfaceOptimizer, java.io.Serializable, Interfac
@Override @Override
public void addPopulationChangedEventListener( public void addPopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea; this.populationChangedEventListener = ea;
} }
@Override @Override
public boolean removePopulationChangedEventListener( public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
if (m_Listener == ea) { if (populationChangedEventListener == ea) {
m_Listener = null; populationChangedEventListener = null;
return true; return true;
} else { } else {
return false; return false;
@ -287,8 +287,8 @@ public class MLTGA implements InterfaceOptimizer, java.io.Serializable, Interfac
* Something has changed * Something has changed
*/ */
protected void firePropertyChangedEvent(String name) { protected void firePropertyChangedEvent(String name) {
if (this.m_Listener != null) { if (this.populationChangedEventListener != null) {
this.m_Listener.registerPopulationStateChanged(this, name); this.populationChangedEventListener.registerPopulationStateChanged(this, name);
} }
} }
@ -309,12 +309,12 @@ public class MLTGA implements InterfaceOptimizer, java.io.Serializable, Interfac
@Override @Override
public void setIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.identifier = name;
} }
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return this.m_Identifier; return this.identifier;
} }
@Override @Override

View File

@ -19,7 +19,6 @@ import java.util.Hashtable;
* be applied to problems which implement the InterfaceLocalSearchable else the * be applied to problems which implement the InterfaceLocalSearchable else the
* local search will not be activated at all. * local search will not be activated at all.
* *
* @version 1.0
*/ */
@Description("This is a basic generational Memetic Algorithm. Local search steps are performed on a selected subset " @Description("This is a basic generational Memetic Algorithm. Local search steps are performed on a selected subset "
+ "of individuals after certain numbers of global search iterations. Note " + "of individuals after certain numbers of global search iterations. Note "
@ -38,21 +37,21 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
// int counter = 0; !? // int counter = 0; !?
// int maxfunctioncalls = 1000; !? // int maxfunctioncalls = 1000; !?
private boolean TRACE = false; private boolean TRACE = false;
private String m_Identifier = ""; private String identifier = "";
private InterfaceOptimizationProblem m_Problem = new F1Problem(); private InterfaceOptimizationProblem optimizationProblem = new F1Problem();
private InterfaceOptimizer m_GlobalOptimizer = new GeneticAlgorithm(); private InterfaceOptimizer globalOptimizer = new GeneticAlgorithm();
private InterfaceSelection selectorPlug = new SelectBestIndividuals(); private InterfaceSelection selectorPlug = new SelectBestIndividuals();
transient private InterfacePopulationChangedEventListener m_Listener; transient private InterfacePopulationChangedEventListener populationChangedEventListener;
public MemeticAlgorithm() { public MemeticAlgorithm() {
} }
public MemeticAlgorithm(MemeticAlgorithm a) { public MemeticAlgorithm(MemeticAlgorithm a) {
// this.population = (Population)a.population.clone(); // this.population = (Population)a.population.clone();
this.m_Problem = (InterfaceLocalSearchable) a.m_Problem.clone(); this.optimizationProblem = (InterfaceLocalSearchable) a.optimizationProblem.clone();
this.m_GlobalOptimizer = (InterfaceOptimizer) a.m_GlobalOptimizer; this.globalOptimizer = (InterfaceOptimizer) a.globalOptimizer;
this.selectorPlug = (InterfaceSelection) a.selectorPlug; this.selectorPlug = (InterfaceSelection) a.selectorPlug;
this.m_Identifier = a.m_Identifier; this.identifier = a.identifier;
this.localSearchSteps = a.localSearchSteps; this.localSearchSteps = a.localSearchSteps;
this.subsetsize = a.subsetsize; this.subsetsize = a.subsetsize;
this.globalSearchIterations = a.globalSearchIterations; this.globalSearchIterations = a.globalSearchIterations;
@ -69,7 +68,7 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
this.setPopulation((Population) pop.clone()); this.setPopulation((Population) pop.clone());
if (reset) { if (reset) {
this.getPopulation().init(); this.getPopulation().init();
this.m_Problem.evaluate(this.getPopulation()); this.optimizationProblem.evaluate(this.getPopulation());
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
} }
} }
@ -77,9 +76,9 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
@Override @Override
public void init() { public void init() {
// counter = 0; // counter = 0;
this.m_GlobalOptimizer.setProblem(this.m_Problem); this.globalOptimizer.setProblem(this.optimizationProblem);
this.m_GlobalOptimizer.init(); this.globalOptimizer.init();
this.evaluatePopulation(this.m_GlobalOptimizer.getPopulation()); this.evaluatePopulation(this.globalOptimizer.getPopulation());
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
} }
@ -89,7 +88,7 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
* @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.optimizationProblem.evaluate(population);
population.incrGeneration(); population.incrGeneration();
} }
@ -99,17 +98,17 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
if (TRACE) { if (TRACE) {
System.out.println("global search"); System.out.println("global search");
} }
this.m_GlobalOptimizer.optimize(); this.globalOptimizer.optimize();
if ((globalSearchIterations > 0) && (((this.m_GlobalOptimizer.getPopulation().getGeneration() % this.globalSearchIterations) == 0)) if ((globalSearchIterations > 0) && (((this.globalOptimizer.getPopulation().getGeneration() % this.globalSearchIterations) == 0))
&& (this.localSearchSteps > 0) && (this.localSearchSteps > 0)
&& (this.m_Problem instanceof InterfaceLocalSearchable)) { && (this.optimizationProblem instanceof InterfaceLocalSearchable)) {
// here the local search is performed // here the local search is performed
if (TRACE) { if (TRACE) {
System.out.println("Performing local search on " + subsetsize System.out.println("Performing local search on " + subsetsize
+ " individuals."); + " individuals.");
} }
Population gop = this.m_GlobalOptimizer.getPopulation(); Population gop = this.globalOptimizer.getPopulation();
Population subset = selectorPlug.selectFrom(gop, subsetsize); Population subset = selectorPlug.selectFrom(gop, subsetsize);
Population subsetclone = new Population(); Population subsetclone = new Population();
for (int i = 0; i < subset.size(); i++) { for (int i = 0; i < subset.size(); i++) {
@ -129,7 +128,7 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
} }
// int dosearchsteps = this.localSearchSteps; // int dosearchsteps = this.localSearchSteps;
double cost = ((InterfaceLocalSearchable) this.m_Problem) double cost = ((InterfaceLocalSearchable) this.optimizationProblem)
.getLocalSearchStepFunctionCallEquivalent(); .getLocalSearchStepFunctionCallEquivalent();
// int calls = gop.getFunctionCalls() + (int) Math.round(localSearchSteps // int calls = gop.getFunctionCalls() + (int) Math.round(localSearchSteps
// * cost * subset.size()); // * cost * subset.size());
@ -143,9 +142,9 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
// stopit = true; // stopit = true;
// } // }
for (int i = 0; i < localSearchSteps; i++) { for (int i = 0; i < localSearchSteps; i++) {
((InterfaceLocalSearchable) this.m_Problem).doLocalSearch(subsetclone); ((InterfaceLocalSearchable) this.optimizationProblem).doLocalSearch(subsetclone);
} }
this.m_Problem.evaluate(subsetclone); this.optimizationProblem.evaluate(subsetclone);
if (this.lamarckism) { if (this.lamarckism) {
gop.removeAll(subset); gop.removeAll(subset);
gop.addPopulation(subsetclone); gop.addPopulation(subsetclone);
@ -174,7 +173,7 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
if (TRACE) { if (TRACE) {
System.out.println("function calls" System.out.println("function calls"
+ this.m_GlobalOptimizer.getPopulation().getFunctionCalls()); + this.globalOptimizer.getPopulation().getFunctionCalls());
} }
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
} }
@ -187,14 +186,14 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
@Override @Override
public void addPopulationChangedEventListener( public void addPopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea; this.populationChangedEventListener = ea;
} }
@Override @Override
public boolean removePopulationChangedEventListener( public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
if (m_Listener == ea) { if (populationChangedEventListener == ea) {
m_Listener = null; populationChangedEventListener = null;
return true; return true;
} else { } else {
return false; return false;
@ -205,11 +204,11 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
* Something has changed * Something has changed
*/ */
protected void firePropertyChangedEvent(String name) { protected void firePropertyChangedEvent(String name) {
if (this.m_Listener != null) { if (this.populationChangedEventListener != null) {
if (TRACE) { if (TRACE) {
System.out.println("firePropertyChangedEvent MA"); System.out.println("firePropertyChangedEvent MA");
} }
this.m_Listener.registerPopulationStateChanged(this, name); this.populationChangedEventListener.registerPopulationStateChanged(this, name);
} }
} }
@ -220,13 +219,13 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
*/ */
@Override @Override
public void setProblem(InterfaceOptimizationProblem problem) { public void setProblem(InterfaceOptimizationProblem problem) {
this.m_Problem = problem; this.optimizationProblem = problem;
this.m_GlobalOptimizer.setProblem(this.m_Problem); this.globalOptimizer.setProblem(this.optimizationProblem);
} }
@Override @Override
public InterfaceOptimizationProblem getProblem() { public InterfaceOptimizationProblem getProblem() {
return this.m_Problem; return this.optimizationProblem;
} }
/** /**
@ -240,8 +239,8 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
String result = ""; String result = "";
result += "Memetic Algorithm:\n"; result += "Memetic Algorithm:\n";
result += "Optimization Problem: "; result += "Optimization Problem: ";
result += this.m_Problem.getStringRepresentationForProblem(this) + "\n"; result += this.optimizationProblem.getStringRepresentationForProblem(this) + "\n";
result += this.m_GlobalOptimizer.getStringRepresentation(); result += this.globalOptimizer.getStringRepresentation();
return result; return result;
} }
@ -252,12 +251,12 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
*/ */
@Override @Override
public void setIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.identifier = name;
} }
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return this.m_Identifier; return this.identifier;
} }
@ -280,12 +279,12 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
*/ */
@Override @Override
public Population getPopulation() { public Population getPopulation() {
return this.m_GlobalOptimizer.getPopulation(); return this.globalOptimizer.getPopulation();
} }
@Override @Override
public void setPopulation(Population pop) { public void setPopulation(Population pop) {
this.m_GlobalOptimizer.setPopulation(pop); this.globalOptimizer.setPopulation(pop);
} }
public String populationTipText() { public String populationTipText() {
@ -295,16 +294,16 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
/** /**
* Choose the global optimization strategy to use * Choose the global optimization strategy to use
* *
* @param m_GlobalOptimizer * @param globalOptimizer
*/ */
public void setGlobalOptimizer(InterfaceOptimizer m_GlobalOptimizer) { public void setGlobalOptimizer(InterfaceOptimizer globalOptimizer) {
this.m_GlobalOptimizer = m_GlobalOptimizer; this.globalOptimizer = globalOptimizer;
this.m_GlobalOptimizer.setProblem(this.getProblem()); this.globalOptimizer.setProblem(this.getProblem());
this.init(); this.init();
} }
public InterfaceOptimizer getGlobalOptimizer() { public InterfaceOptimizer getGlobalOptimizer() {
return m_GlobalOptimizer; return globalOptimizer;
} }
public String globalOptimizerTipText() { public String globalOptimizerTipText() {

View File

@ -40,21 +40,21 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
public boolean seen = false; public boolean seen = false;
} }
private String m_Identifier = "MOCMAES"; private String identifier = "MOCMAES";
private Population m_Population; private Population population;
private AbstractOptimizationProblem m_Problem; private AbstractOptimizationProblem optimizationProblem;
transient private InterfacePopulationChangedEventListener m_Listener; transient private InterfacePopulationChangedEventListener populationChangedEventListener;
private int m_lambda = 1; private int lambda = 1;
private int m_lambdamo = 1; private int lambdaMO = 1;
public MultiObjectiveCMAES() { public MultiObjectiveCMAES() {
m_Population = new Population(m_lambdamo); population = new Population(lambdaMO);
} }
public MultiObjectiveCMAES(MultiObjectiveCMAES a) { public MultiObjectiveCMAES(MultiObjectiveCMAES a) {
m_Problem = (AbstractOptimizationProblem) a.m_Problem.clone(); optimizationProblem = (AbstractOptimizationProblem) a.optimizationProblem.clone();
setPopulation((Population) a.m_Population.clone()); setPopulation((Population) a.population.clone());
m_lambda = a.m_lambda; lambda = a.lambda;
} }
@Override @Override
@ -76,7 +76,7 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
*/ */
@Override @Override
public void setIdentifier(String name) { public void setIdentifier(String name) {
m_Identifier = name; identifier = name;
} }
/* /*
@ -88,7 +88,7 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
*/ */
@Override @Override
public void setProblem(InterfaceOptimizationProblem problem) { public void setProblem(InterfaceOptimizationProblem problem) {
m_Problem = (AbstractOptimizationProblem) problem; optimizationProblem = (AbstractOptimizationProblem) problem;
} }
/** /**
@ -99,7 +99,7 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
@Override @Override
public void addPopulationChangedEventListener( public void addPopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea; this.populationChangedEventListener = ea;
} }
/* /*
@ -120,7 +120,7 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
*/ */
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return m_Identifier; return identifier;
} }
/* /*
@ -130,7 +130,7 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
*/ */
@Override @Override
public String getName() { public String getName() {
return "(1+" + m_lambda + ") MO-CMA-ES"; return "(1+" + lambda + ") MO-CMA-ES";
} }
/* /*
@ -140,7 +140,7 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
*/ */
@Override @Override
public Population getPopulation() { public Population getPopulation() {
return m_Population; return population;
} }
/* /*
@ -150,7 +150,7 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
*/ */
@Override @Override
public InterfaceOptimizationProblem getProblem() { public InterfaceOptimizationProblem getProblem() {
return m_Problem; return optimizationProblem;
} }
/* /*
@ -162,10 +162,10 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
@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+" + lambda + ") MO-CMA-ES:\nOptimization Problem: ");
strB.append(this.m_Problem.getStringRepresentationForProblem(this)); strB.append(this.optimizationProblem.getStringRepresentationForProblem(this));
strB.append("\n"); strB.append("\n");
strB.append(this.m_Population.getStringRepresentation()); strB.append(this.population.getStringRepresentation());
return strB.toString(); return strB.toString();
} }
@ -177,10 +177,10 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
@Override @Override
public void init() { public void init() {
// initByPopulation(population, true); // initByPopulation(population, true);
this.m_Population.setTargetSize(m_lambdamo); this.population.setTargetSize(lambdaMO);
this.m_Problem.initializePopulation(this.m_Population); this.optimizationProblem.initializePopulation(this.population);
// children = new Population(population.size()); // children = new Population(population.size());
this.evaluatePopulation(this.m_Population); this.evaluatePopulation(this.population);
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
} }
@ -196,8 +196,8 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
public void initByPopulation(Population pop, boolean reset) { public void initByPopulation(Population pop, boolean reset) {
setPopulation(pop); setPopulation(pop);
if (reset) { if (reset) {
m_Problem.initializePopulation(m_Population); optimizationProblem.initializePopulation(population);
m_Problem.evaluate(m_Population); optimizationProblem.evaluate(population);
} }
} }
@ -208,7 +208,7 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
* @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.optimizationProblem.evaluate(population);
} }
/* /*
@ -222,20 +222,20 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
HashMap<Long, CounterClass> SuccessCounterMap = new HashMap<Long, CounterClass>(); HashMap<Long, CounterClass> SuccessCounterMap = new HashMap<Long, CounterClass>();
// Eltern markieren und f<EFBFBD>r die Z<EFBFBD>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 < lambdaMO && j < population.size(); j++) {
m_Population.getEAIndividual(j).putData("Parent", population.getEAIndividual(j).putData("Parent",
m_Population.getEAIndividual(j)); population.getEAIndividual(j));
SuccessCounterMap.put(m_Population.getEAIndividual(j).getIndyID(), SuccessCounterMap.put(population.getEAIndividual(j).getIndyID(),
new CounterClass(0)); new CounterClass(0));
} }
// Kinder erzeugen // Kinder erzeugen
Population children = new Population(m_lambdamo * m_lambda); Population children = new Population(lambdaMO * lambda);
children.setGeneration(m_Population.getGeneration()); children.setGeneration(population.getGeneration());
for (int j = 0; j < children.getTargetSize(); j++) { for (int j = 0; j < children.getTargetSize(); j++) {
AbstractEAIndividual parent = m_Population.getEAIndividual(j AbstractEAIndividual parent = population.getEAIndividual(j
% m_lambdamo); % lambdaMO);
AbstractEAIndividual indy = (AbstractEAIndividual) parent.clone(); AbstractEAIndividual indy = (AbstractEAIndividual) parent.clone();
indy.mutate(); indy.mutate();
indy.putData("Parent", parent); indy.putData("Parent", parent);
@ -243,29 +243,29 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
} }
evaluatePopulation(children); evaluatePopulation(children);
m_Population.addPopulation(children); population.addPopulation(children);
// Ranking // Ranking
ArchivingNSGAII dummyArchive = new ArchivingNSGAIISMeasure(); ArchivingNSGAII dummyArchive = new ArchivingNSGAIISMeasure();
Population[] store = dummyArchive Population[] store = dummyArchive
.getNonDominatedSortedFronts(m_Population); .getNonDominatedSortedFronts(population);
store = dummyArchive.getNonDominatedSortedFronts(m_Population); store = dummyArchive.getNonDominatedSortedFronts(population);
dummyArchive.calculateCrowdingDistance(store); dummyArchive.calculateCrowdingDistance(store);
// Vergleichen und den Successcounter hochz<EFBFBD>hlen wenn wir besser als // Vergleichen und den Successcounter hochz<EFBFBD>hlen wenn wir besser als
// unser Elter sind // unser Elter sind
for (int j = 0; j < m_Population.size(); j++) { for (int j = 0; j < population.size(); j++) {
AbstractEAIndividual parent = (AbstractEAIndividual) m_Population AbstractEAIndividual parent = (AbstractEAIndividual) population
.getEAIndividual(j).getData("Parent"); .getEAIndividual(j).getData("Parent");
if (m_Population.getEAIndividual(j) != parent) { // Eltern nicht mit if (population.getEAIndividual(j) != parent) { // Eltern nicht mit
// sich selber // sich selber
// vergleichen // vergleichen
int parentParetoLevel = ((Integer) parent int parentParetoLevel = ((Integer) parent
.getData("ParetoLevel")).intValue(); .getData("ParetoLevel")).intValue();
double parentSMeasure = ((Double) parent.getData("HyperCube")) double parentSMeasure = ((Double) parent.getData("HyperCube"))
.doubleValue(); .doubleValue();
int childParetoLevel = ((Integer) m_Population.getEAIndividual( int childParetoLevel = ((Integer) population.getEAIndividual(
j).getData("ParetoLevel")).intValue(); j).getData("ParetoLevel")).intValue();
double childSMeasure = ((Double) m_Population double childSMeasure = ((Double) population
.getEAIndividual(j).getData("HyperCube")).doubleValue(); .getEAIndividual(j).getData("HyperCube")).doubleValue();
if (childParetoLevel < parentParetoLevel if (childParetoLevel < parentParetoLevel
|| ((childParetoLevel == parentParetoLevel) && childSMeasure > parentSMeasure)) { || ((childParetoLevel == parentParetoLevel) && childSMeasure > parentSMeasure)) {
@ -278,17 +278,17 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
} }
// Selection // Selection
m_Population.clear(); 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 if (population.size() + store[i].size() <= lambdaMO) { // Die
// Front // Front
// passt // passt
// noch // noch
// komplett // komplett
m_Population.addPopulation(store[i]); 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 && population.size() < lambdaMO) {
AbstractEAIndividual indy = store[i].getEAIndividual(0); AbstractEAIndividual indy = store[i].getEAIndividual(0);
double bestMeasure = ((Double) indy.getData("HyperCube")) double bestMeasure = ((Double) indy.getData("HyperCube"))
.doubleValue(); // TODO mal noch effizient machen .doubleValue(); // TODO mal noch effizient machen
@ -302,7 +302,7 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
indy = store[i].getEAIndividual(j); indy = store[i].getEAIndividual(j);
} }
} }
m_Population.add(indy); population.add(indy);
store[i].removeMember(indy); store[i].removeMember(indy);
} }
} }
@ -310,9 +310,9 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
} }
// Strategieparemeter updaten // Strategieparemeter updaten
for (int j = 0; j < m_Population.size(); j++) { for (int j = 0; j < population.size(); j++) {
AbstractEAIndividual indy = m_Population.getEAIndividual(j); AbstractEAIndividual indy = population.getEAIndividual(j);
if (indy.getMutationOperator() instanceof MutateESCovarianceMatrixAdaptionPlus) { // Das if (indy.getMutationOperator() instanceof MutateESCovarianceMatrixAdaptionPlus) { // Das
// geht // geht
// nur // nur
@ -329,7 +329,7 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
.getMutationOperator(); .getMutationOperator();
double rate = ((double) SuccessCounterMap.get(parent double rate = ((double) SuccessCounterMap.get(parent
.getIndyID()).value) .getIndyID()).value)
/ ((double) m_lambda); / ((double) lambda);
if (indy != parent) { if (indy != parent) {
muta.updateCovariance(); muta.updateCovariance();
@ -342,8 +342,8 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
children.getEAIndividual(j).putData("Parent", null); children.getEAIndividual(j).putData("Parent", null);
} }
m_Population.incrFunctionCallsBy(children.size()); population.incrFunctionCallsBy(children.size());
m_Population.incrGeneration(); population.incrGeneration();
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
} }
@ -370,9 +370,9 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
*/ */
@Override @Override
public void setPopulation(Population pop) { public void setPopulation(Population pop) {
m_Population = pop; population = pop;
m_Population.setNotifyEvalInterval(1); population.setNotifyEvalInterval(1);
m_lambdamo = m_Population.getTargetSize(); lambdaMO = population.getTargetSize();
} }
@ -382,22 +382,22 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
* @param name * @param name
*/ */
protected void firePropertyChangedEvent(String name) { protected void firePropertyChangedEvent(String name) {
if (this.m_Listener != null) { if (this.populationChangedEventListener != null) {
this.m_Listener.registerPopulationStateChanged(this, name); this.populationChangedEventListener.registerPopulationStateChanged(this, name);
} }
} }
public int getLambda() { public int getLambda() {
return m_lambda; return lambda;
} }
public void setLambda(int mLambda) { public void setLambda(int mLambda) {
m_lambda = mLambda; lambda = mLambda;
} }
/* /*
* public int getLambdaMo() { return m_lambdamo; } * public int getLambdaMo() { return lambdaMO; }
* *
* public void setLambdaMo(int mLambda) { m_lambdamo = mLambda; } * public void setLambdaMo(int mLambda) { lambdaMO = mLambda; }
*/ */
} }

View File

@ -30,24 +30,24 @@ import eva2.util.annotation.Description;
@Description("This is a general Multi-objective Evolutionary Optimization Framework.") @Description("This is a general Multi-objective Evolutionary Optimization Framework.")
public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializable { public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializable {
private InterfaceOptimizer m_Optimizer = new GeneticAlgorithm(); private InterfaceOptimizer optimizer = new GeneticAlgorithm();
private InterfaceArchiving m_Archiver = new ArchivingNSGAII(); private InterfaceArchiving archiver = new ArchivingNSGAII();
private InterfaceInformationRetrieval m_InformationRetrieval = new InformationRetrievalInserting(); private InterfaceInformationRetrieval informationRetrieval = new InformationRetrievalInserting();
private InterfaceOptimizationProblem m_Problem = new FM0Problem(); private InterfaceOptimizationProblem optimizationProblem = new FM0Problem();
private String m_Identifier = ""; private String identifier = "";
transient private InterfacePopulationChangedEventListener m_Listener; transient private InterfacePopulationChangedEventListener populationChangedEventListener;
public MultiObjectiveEA() { public MultiObjectiveEA() {
this.m_Optimizer.getPopulation().setTargetSize(100); this.optimizer.getPopulation().setTargetSize(100);
((GeneticAlgorithm) this.m_Optimizer).setParentSelection(new SelectMONonDominated()); ((GeneticAlgorithm) this.optimizer).setParentSelection(new SelectMONonDominated());
((GeneticAlgorithm) this.m_Optimizer).setPartnerSelection(new SelectMONonDominated()); ((GeneticAlgorithm) this.optimizer).setPartnerSelection(new SelectMONonDominated());
} }
public MultiObjectiveEA(MultiObjectiveEA a) { public MultiObjectiveEA(MultiObjectiveEA a) {
this.m_Problem = (InterfaceOptimizationProblem) a.m_Problem.clone(); this.optimizationProblem = (InterfaceOptimizationProblem) a.optimizationProblem.clone();
this.m_Optimizer = (InterfaceOptimizer) a.m_Optimizer.clone(); this.optimizer = (InterfaceOptimizer) a.optimizer.clone();
this.m_Archiver = (InterfaceArchiving) a.m_Archiver.clone(); this.archiver = (InterfaceArchiving) a.archiver.clone();
this.m_InformationRetrieval = (InterfaceInformationRetrieval) a.m_InformationRetrieval.clone(); this.informationRetrieval = (InterfaceInformationRetrieval) a.informationRetrieval.clone();
} }
public MultiObjectiveEA(InterfaceOptimizer subOpt, InterfaceArchiving archiving, int archiveSize, public MultiObjectiveEA(InterfaceOptimizer subOpt, InterfaceArchiving archiving, int archiveSize,
@ -66,8 +66,8 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
@Override @Override
public void init() { public void init() {
this.m_Optimizer.init(); this.optimizer.init();
this.m_Archiver.addElementsToArchive(this.m_Optimizer.getPopulation()); this.archiver.addElementsToArchive(this.optimizer.getPopulation());
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
} }
@ -79,8 +79,8 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
*/ */
@Override @Override
public void initByPopulation(Population pop, boolean reset) { public void initByPopulation(Population pop, boolean reset) {
this.m_Optimizer.initByPopulation(pop, reset); this.optimizer.initByPopulation(pop, reset);
this.m_Archiver.addElementsToArchive(this.m_Optimizer.getPopulation()); this.archiver.addElementsToArchive(this.optimizer.getPopulation());
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
} }
@ -91,11 +91,11 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
public void optimize() { public void optimize() {
// double[][] may = this.showMay(this.optimizer.getPopulation()); // double[][] may = this.showMay(this.optimizer.getPopulation());
// This is in total compliance with Koch's framework nice isn't it? // This is in total compliance with Koch's framework nice isn't it?
this.m_Optimizer.optimize(); this.optimizer.optimize();
// now comes all the multiobjective optimization stuff // now comes all the multiobjective optimization stuff
// This is the Environment Selection // This is the Environment Selection
this.m_Archiver.addElementsToArchive(this.m_Optimizer.getPopulation()); this.archiver.addElementsToArchive(this.optimizer.getPopulation());
//if (true) this.m_Archiver.plotArchive(this.optimizer.getPopulation()); //if (true) this.archiver.plotArchive(this.optimizer.getPopulation());
// if (false) { // if (false) {
// int popSize = this.optimizer.getPopulation().size(); // int popSize = this.optimizer.getPopulation().size();
// int archiveSize = this.optimizer.getPopulation().getArchive().size(); // int archiveSize = this.optimizer.getPopulation().getArchive().size();
@ -112,7 +112,7 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
// The InformationRetrieval will choose from the archive and the current population // The InformationRetrieval will choose from the archive and the current population
// the population from which in the next generation the parents will be selected. // the population from which in the next generation the parents will be selected.
this.m_InformationRetrieval.retrieveInformationFrom(this.m_Optimizer.getPopulation()); this.informationRetrieval.retrieveInformationFrom(this.optimizer.getPopulation());
// double[][] mayday = this.showMay(this.optimizer.getPopulation()); // double[][] mayday = this.showMay(this.optimizer.getPopulation());
// if ((mayday[0][0] > may[0][0]) || (mayday[1][1] > may[1][1])) { // if ((mayday[0][0] > may[0][0]) || (mayday[1][1] > may[1][1])) {
@ -157,14 +157,14 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
@Override @Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) { public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea; this.populationChangedEventListener = ea;
} }
@Override @Override
public boolean removePopulationChangedEventListener( public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
if (m_Listener == ea) { if (populationChangedEventListener == ea) {
m_Listener = null; populationChangedEventListener = null;
return true; return true;
} else { } else {
return false; return false;
@ -172,8 +172,8 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
} }
protected void firePropertyChangedEvent(String name) { protected void firePropertyChangedEvent(String name) {
if (this.m_Listener != null) { if (this.populationChangedEventListener != null) {
this.m_Listener.registerPopulationStateChanged(this, name); this.populationChangedEventListener.registerPopulationStateChanged(this, name);
} }
} }
@ -184,13 +184,13 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
*/ */
@Override @Override
public void setProblem(InterfaceOptimizationProblem problem) { public void setProblem(InterfaceOptimizationProblem problem) {
this.m_Problem = problem; this.optimizationProblem = problem;
this.m_Optimizer.setProblem(problem); this.optimizer.setProblem(problem);
} }
@Override @Override
public InterfaceOptimizationProblem getProblem() { public InterfaceOptimizationProblem getProblem() {
return this.m_Problem; return this.optimizationProblem;
} }
/** /**
@ -204,11 +204,11 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
String result = ""; String result = "";
result += "Multi-Objective Evolutionary Algorithm:\n"; result += "Multi-Objective Evolutionary Algorithm:\n";
result += "Using:\n"; result += "Using:\n";
result += " Archiving Strategy = " + this.m_Archiver.getClass().toString() + "\n"; result += " Archiving Strategy = " + this.archiver.getClass().toString() + "\n";
result += " Information Retrieval = " + this.m_InformationRetrieval.getClass().toString() + "\n"; result += " Information Retrieval = " + this.informationRetrieval.getClass().toString() + "\n";
result += " Information Retrieval = " + this.getClass().toString() + "\n"; result += " Information Retrieval = " + this.getClass().toString() + "\n";
result += " Optimizer = " + this.m_Optimizer.getClass().toString() + "\n"; result += " Optimizer = " + this.optimizer.getClass().toString() + "\n";
result += this.m_Optimizer.getStringRepresentation() + "\n"; result += this.optimizer.getStringRepresentation() + "\n";
//result += "=> The Optimization Problem: "; //result += "=> The Optimization Problem: ";
//result += this.problem.getStringRepresentationForProblem(this) +"\n"; //result += this.problem.getStringRepresentationForProblem(this) +"\n";
//result += this.population.getStringRepresentation(); //result += this.population.getStringRepresentation();
@ -222,12 +222,12 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
*/ */
@Override @Override
public void setIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.identifier = name;
} }
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return this.m_Identifier; return this.identifier;
} }
/** /**
@ -249,12 +249,12 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
*/ */
@Override @Override
public Population getPopulation() { public Population getPopulation() {
return this.m_Optimizer.getPopulation(); return this.optimizer.getPopulation();
} }
@Override @Override
public void setPopulation(Population pop) { public void setPopulation(Population pop) {
this.m_Optimizer.setPopulation(pop); this.optimizer.setPopulation(pop);
} }
public String populationTipText() { public String populationTipText() {
@ -272,11 +272,11 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
* @return The current optimizing method * @return The current optimizing method
*/ */
public InterfaceOptimizer getOptimizer() { public InterfaceOptimizer getOptimizer() {
return this.m_Optimizer; return this.optimizer;
} }
public void setOptimizer(InterfaceOptimizer b) { public void setOptimizer(InterfaceOptimizer b) {
this.m_Optimizer = b; this.optimizer = b;
} }
public String optimizerTipText() { public String optimizerTipText() {
@ -289,11 +289,11 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
* @return The current optimizing method * @return The current optimizing method
*/ */
public InterfaceArchiving getArchivingStrategy() { public InterfaceArchiving getArchivingStrategy() {
return this.m_Archiver; return this.archiver;
} }
public void setArchivingStrategy(InterfaceArchiving b) { public void setArchivingStrategy(InterfaceArchiving b) {
this.m_Archiver = b; this.archiver = b;
} }
public String archivingStrategyTipText() { public String archivingStrategyTipText() {
@ -307,11 +307,11 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
* @return The current optimizing method * @return The current optimizing method
*/ */
public InterfaceInformationRetrieval getInformationRetrieval() { public InterfaceInformationRetrieval getInformationRetrieval() {
return this.m_InformationRetrieval; return this.informationRetrieval;
} }
public void setInformationRetrieval(InterfaceInformationRetrieval b) { public void setInformationRetrieval(InterfaceInformationRetrieval b) {
this.m_InformationRetrieval = b; this.informationRetrieval = b;
} }
public String informationRetrievalTipText() { public String informationRetrievalTipText() {
@ -324,19 +324,19 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
* @return The current optimizing method * @return The current optimizing method
*/ */
public int getArchiveSize() { public int getArchiveSize() {
Population archive = this.m_Optimizer.getPopulation().getArchive(); Population archive = this.optimizer.getPopulation().getArchive();
if (archive == null) { if (archive == null) {
archive = new Population(); archive = new Population();
this.m_Optimizer.getPopulation().SetArchive(archive); this.optimizer.getPopulation().SetArchive(archive);
} }
return archive.getTargetSize(); return archive.getTargetSize();
} }
public void setArchiveSize(int b) { public void setArchiveSize(int b) {
Population archive = this.m_Optimizer.getPopulation().getArchive(); Population archive = this.optimizer.getPopulation().getArchive();
if (archive == null) { if (archive == null) {
archive = new Population(); archive = new Population();
this.m_Optimizer.getPopulation().SetArchive(archive); this.optimizer.getPopulation().SetArchive(archive);
} }
archive.setTargetSize(b); archive.setTargetSize(b);
} }

View File

@ -28,10 +28,10 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
// simulating the generational cycle. Set rather small (eg 5) for use as local search, higher for global search (eg 50) // simulating the generational cycle. Set rather small (eg 5) for use as local search, higher for global search (eg 50)
private int generationCycle = 50; private int generationCycle = 50;
private int fitIndex = 0; // choose criterion for multi objective functions private int fitIndex = 0; // choose criterion for multi objective functions
private Population m_Population; private Population population;
private AbstractOptimizationProblem m_Problem; private AbstractOptimizationProblem optimizationProblem;
private transient Vector<InterfacePopulationChangedEventListener> m_Listener; private transient Vector<InterfacePopulationChangedEventListener> populationChangedEventListeners;
private String m_Identifier = "NelderMeadSimplex"; private String identifier = "NelderMeadSimplex";
private boolean checkConstraints = true; private boolean checkConstraints = true;
public NelderMeadSimplex() { public NelderMeadSimplex() {
@ -44,11 +44,11 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
} }
public NelderMeadSimplex(NelderMeadSimplex a) { public NelderMeadSimplex(NelderMeadSimplex a) {
m_Problem = (AbstractOptimizationProblem) a.m_Problem.clone(); optimizationProblem = (AbstractOptimizationProblem) a.optimizationProblem.clone();
setPopulation((Population) a.m_Population.clone()); setPopulation((Population) a.population.clone());
populationSize = a.populationSize; populationSize = a.populationSize;
generationCycle = a.generationCycle; generationCycle = a.generationCycle;
m_Identifier = a.m_Identifier; identifier = a.identifier;
} }
@Override @Override
@ -58,17 +58,17 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
@Override @Override
public void setIdentifier(String name) { public void setIdentifier(String name) {
m_Identifier = name; identifier = name;
} }
@Override @Override
public void setProblem(InterfaceOptimizationProblem problem) { public void setProblem(InterfaceOptimizationProblem problem) {
m_Problem = (AbstractOptimizationProblem) problem; optimizationProblem = (AbstractOptimizationProblem) problem;
} }
public boolean setProblemAndPopSize(InterfaceOptimizationProblem problem) { public boolean setProblemAndPopSize(InterfaceOptimizationProblem problem) {
setProblem(problem); setProblem(problem);
if (m_Problem instanceof AbstractProblemDouble) { if (optimizationProblem instanceof AbstractProblemDouble) {
setPopulationSize(((AbstractProblemDouble) problem).getProblemDimension() + 1); setPopulationSize(((AbstractProblemDouble) problem).getProblemDimension() + 1);
return true; return true;
} else { } else {
@ -85,11 +85,11 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
public void addPopulationChangedEventListener( public void addPopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
if (ea != null) { if (ea != null) {
if (m_Listener == null) { if (populationChangedEventListeners == null) {
m_Listener = new Vector<InterfacePopulationChangedEventListener>(); populationChangedEventListeners = new Vector<InterfacePopulationChangedEventListener>();
} }
if (!m_Listener.contains(ea)) { if (!populationChangedEventListeners.contains(ea)) {
m_Listener.add(ea); populationChangedEventListeners.add(ea);
} }
} }
} }
@ -97,10 +97,10 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
@Override @Override
public boolean removePopulationChangedEventListener( public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
if (m_Listener == null) { if (populationChangedEventListeners == null) {
return false; return false;
} else { } else {
return m_Listener.remove(ea); return populationChangedEventListeners.remove(ea);
} }
} }
@ -167,7 +167,7 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
// //
// problem.evaluate(reflectedInd); // problem.evaluate(reflectedInd);
AbstractEAIndividual reflectedInd = createEvalIndy(bestpop, r); AbstractEAIndividual reflectedInd = createEvalIndy(bestpop, r);
this.m_Population.incrFunctionCalls(); this.population.incrFunctionCalls();
if (firstIsBetter(best, reflectedInd) && firstIsBetter(reflectedInd, bestpop.getWorstEAIndividual(fitIndex))) { if (firstIsBetter(best, reflectedInd) && firstIsBetter(reflectedInd, bestpop.getWorstEAIndividual(fitIndex))) {
return reflectedInd; return reflectedInd;
@ -181,7 +181,7 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
} }
AbstractEAIndividual e_ind = createEvalIndy(bestpop, e); AbstractEAIndividual e_ind = createEvalIndy(bestpop, e);
this.m_Population.incrFunctionCalls(); this.population.incrFunctionCalls();
if (firstIsBetter(e_ind, reflectedInd)) { //expandiertes ist besser als reflektiertes if (firstIsBetter(e_ind, reflectedInd)) { //expandiertes ist besser als reflektiertes
return e_ind; return e_ind;
@ -202,7 +202,7 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
// ((InterfaceDataTypeDouble)c_ind).setDoubleGenotype(c); // ((InterfaceDataTypeDouble)c_ind).setDoubleGenotype(c);
// problem.evaluate(c_ind); // problem.evaluate(c_ind);
AbstractEAIndividual c_ind = createEvalIndy(bestpop, c); AbstractEAIndividual c_ind = createEvalIndy(bestpop, c);
this.m_Population.incrFunctionCalls(); this.population.incrFunctionCalls();
if (firstIsBetterEqual(c_ind, worst)) { if (firstIsBetterEqual(c_ind, worst)) {
return c_ind; return c_ind;
} }
@ -214,46 +214,46 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
AbstractEAIndividual e_ind = (AbstractEAIndividual) ((AbstractEAIndividual) pop.getIndividual(1)).clone(); AbstractEAIndividual e_ind = (AbstractEAIndividual) ((AbstractEAIndividual) pop.getIndividual(1)).clone();
((InterfaceDataTypeDouble) e_ind).setDoubleGenotype(newGenotype); ((InterfaceDataTypeDouble) e_ind).setDoubleGenotype(newGenotype);
e_ind.resetConstraintViolation(); e_ind.resetConstraintViolation();
m_Problem.evaluate(e_ind); optimizationProblem.evaluate(e_ind);
if (e_ind.getFitness(0) < 6000) { if (e_ind.getFitness(0) < 6000) {
m_Problem.evaluate(e_ind); optimizationProblem.evaluate(e_ind);
} }
return e_ind; return e_ind;
} }
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return m_Identifier; return identifier;
} }
@Override @Override
public String getName() { public String getName() {
return m_Identifier; return identifier;
} }
@Override @Override
public Population getPopulation() { public Population getPopulation() {
return m_Population; return population;
} }
@Override @Override
public InterfaceOptimizationProblem getProblem() { public InterfaceOptimizationProblem getProblem() {
return m_Problem; return optimizationProblem;
} }
@Override @Override
public String getStringRepresentation() { public String getStringRepresentation() {
StringBuilder strB = new StringBuilder(200); StringBuilder strB = new StringBuilder(200);
strB.append("Nelder-Mead-Simplex Strategy:\nOptimization Problem: "); strB.append("Nelder-Mead-Simplex Strategy:\nOptimization Problem: ");
strB.append(this.m_Problem.getStringRepresentationForProblem(this)); strB.append(this.optimizationProblem.getStringRepresentationForProblem(this));
strB.append("\n"); strB.append("\n");
strB.append(this.m_Population.getStringRepresentation()); strB.append(this.population.getStringRepresentation());
return strB.toString(); return strB.toString();
} }
@Override @Override
public void init() { public void init() {
initByPopulation(m_Population, true); initByPopulation(population, true);
} }
@Override @Override
@ -261,16 +261,16 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
setPopulation(pop); setPopulation(pop);
pop.addPopulationChangedEventListener(this); pop.addPopulationChangedEventListener(this);
if (reset) { if (reset) {
m_Problem.initializePopulation(m_Population); optimizationProblem.initializePopulation(population);
m_Problem.evaluate(m_Population); optimizationProblem.evaluate(population);
} }
// fireNextGenerationPerformed(); // fireNextGenerationPerformed();
} }
private void fireNextGenerationPerformed() { private void fireNextGenerationPerformed() {
if (m_Listener != null) { if (populationChangedEventListeners != null) {
for (int i = 0; i < m_Listener.size(); i++) { for (int i = 0; i < populationChangedEventListeners.size(); i++) {
m_Listener.elementAt(i).registerPopulationStateChanged(this, Population.NEXT_GENERATION_PERFORMED); populationChangedEventListeners.elementAt(i).registerPopulationStateChanged(this, Population.NEXT_GENERATION_PERFORMED);
} }
} }
} }
@ -279,11 +279,11 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
public void optimize() { public void optimize() {
// make at least as many calls as there are individuals within the population. // make at least as many calls as there are individuals within the population.
// this simulates the generational loop expected by some other modules // this simulates the generational loop expected by some other modules
int evalCntStart = m_Population.getFunctionCalls(); int evalCntStart = population.getFunctionCalls();
int evalsDone = 0; int evalsDone = 0;
m_Problem.evaluatePopulationStart(m_Population); optimizationProblem.evaluatePopulationStart(population);
do { do {
AbstractEAIndividual ind = simplexStep(m_Population); AbstractEAIndividual ind = simplexStep(population);
if (ind != null) { //Verbesserung gefunden if (ind != null) { //Verbesserung gefunden
double[] x = ((InterfaceDataTypeDouble) ind).getDoubleData(); double[] x = ((InterfaceDataTypeDouble) ind).getDoubleData();
double[][] range = ((InterfaceDataTypeDouble) ind).getDoubleRange(); double[][] range = ((InterfaceDataTypeDouble) ind).getDoubleRange();
@ -294,32 +294,32 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
// problem.evaluate(ind); // problem.evaluate(ind);
// this.population.incrFunctionCalls(); // this.population.incrFunctionCalls();
} }
m_Population.set(m_Population.getIndexOfWorstIndividualNoConstr(fitIndex), ind, fitIndex); population.set(population.getIndexOfWorstIndividualNoConstr(fitIndex), ind, fitIndex);
} else {//keine Verbesserung gefunden shrink!! } else {//keine Verbesserung gefunden shrink!!
double[] u_1 = ((InterfaceDataTypeDouble) m_Population.getBestEAIndividual(fitIndex)).getDoubleData(); double[] u_1 = ((InterfaceDataTypeDouble) population.getBestEAIndividual(fitIndex)).getDoubleData();
for (int j = 0; j < m_Population.size(); j++) { for (int j = 0; j < population.size(); j++) {
double[] c = ((InterfaceDataTypeDouble) m_Population.getEAIndividual(j)).getDoubleData(); double[] c = ((InterfaceDataTypeDouble) population.getEAIndividual(j)).getDoubleData();
for (int i = 0; i < c.length; i++) { for (int i = 0; i < c.length; i++) {
c[i] = 0.5 * c[i] + 0.5 * u_1[i]; c[i] = 0.5 * c[i] + 0.5 * u_1[i];
} }
((InterfaceDataTypeDouble) m_Population.getEAIndividual(j)).setDoubleGenotype(c); ((InterfaceDataTypeDouble) population.getEAIndividual(j)).setDoubleGenotype(c);
// population.getEAIndividual(j).resetConstraintViolation(); // not a good idea because during evaluation, a stats update may be performed which mustnt see indies which are evaluated, but possible constraints have been reset. // population.getEAIndividual(j).resetConstraintViolation(); // not a good idea because during evaluation, a stats update may be performed which mustnt see indies which are evaluated, but possible constraints have been reset.
} }
m_Problem.evaluate(m_Population); optimizationProblem.evaluate(population);
} }
evalsDone = m_Population.getFunctionCalls() - evalCntStart; evalsDone = population.getFunctionCalls() - evalCntStart;
} while (evalsDone < generationCycle); } while (evalsDone < generationCycle);
m_Problem.evaluatePopulationEnd(m_Population); optimizationProblem.evaluatePopulationEnd(population);
this.m_Population.incrGeneration(); this.population.incrGeneration();
} }
@Override @Override
public void setPopulation(Population pop) { public void setPopulation(Population pop) {
m_Population = pop; population = pop;
m_Population.addPopulationChangedEventListener(this); population.addPopulationChangedEventListener(this);
m_Population.setNotifyEvalInterval(populationSize); population.setNotifyEvalInterval(populationSize);
} }
@Override @Override
@ -340,9 +340,9 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
*/ */
public void setPopulationSize(int populationSize) { public void setPopulationSize(int populationSize) {
this.populationSize = populationSize; this.populationSize = populationSize;
if (m_Population != null) { if (population != null) {
m_Population.setTargetSize(populationSize); population.setTargetSize(populationSize);
m_Population.setNotifyEvalInterval(m_Population.getTargetSize()); population.setNotifyEvalInterval(population.getTargetSize());
} }
} }

View File

@ -119,16 +119,16 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
protected InterfaceAbsorptionStrategy absorptionStrategy = new StandardAbsorptionStrategy(); protected InterfaceAbsorptionStrategy absorptionStrategy = new StandardAbsorptionStrategy();
protected InterfaceSubswarmCreationStrategy subswarmCreationStrategy = new StandardSubswarmCreationStrategy(); protected InterfaceSubswarmCreationStrategy subswarmCreationStrategy = new StandardSubswarmCreationStrategy();
// the problem // the problem
protected InterfaceOptimizationProblem m_Problem = new FM0Problem(); protected InterfaceOptimizationProblem optimizationProblem = new FM0Problem();
// only used by island model ? // only used by island model ?
protected String m_Identifier = ""; protected String identifier = "";
// eventListener // eventListener
transient protected InterfacePopulationChangedEventListener m_Listener; transient protected InterfacePopulationChangedEventListener populationChangedEventListener;
// for debugging: file containing the output // for debugging: file containing the output
transient protected BufferedWriter outputFile = null; transient protected BufferedWriter outputFile = null;
// for debugging and plotting ----------------------------------------------- // for debugging and plotting -----------------------------------------------
transient protected TopoPlot m_TopologySwarm; transient protected TopoPlot topoPlot;
transient protected boolean m_shownextplot = false; transient protected boolean showNextPlot = false;
transient protected boolean deactivationOccured = false; transient protected boolean deactivationOccured = false;
transient protected boolean mergingOccurd = false; transient protected boolean mergingOccurd = false;
transient protected boolean absorbtionOccurd = false; transient protected boolean absorbtionOccurd = false;
@ -214,9 +214,9 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
this.absorptionStrategy = (InterfaceAbsorptionStrategy) a.absorptionStrategy.clone(); this.absorptionStrategy = (InterfaceAbsorptionStrategy) a.absorptionStrategy.clone();
this.subswarmCreationStrategy = (InterfaceSubswarmCreationStrategy) a.subswarmCreationStrategy.clone(); this.subswarmCreationStrategy = (InterfaceSubswarmCreationStrategy) a.subswarmCreationStrategy.clone();
this.m_Problem = (InterfaceOptimizationProblem) a.m_Problem.clone(); this.optimizationProblem = (InterfaceOptimizationProblem) a.optimizationProblem.clone();
this.m_Identifier = a.m_Identifier; this.identifier = a.identifier;
} }
/** /**
@ -239,7 +239,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
protected void initMainSwarm() { protected void initMainSwarm() {
// pass NichePSO parameter on to the mainswarmoptimzer // pass NichePSO parameter on to the mainswarmoptimzer
setMainSwarmSize(mainSwarmSize); // (particles are initialized later via init) setMainSwarmSize(mainSwarmSize); // (particles are initialized later via init)
getMainSwarm().setProblem(m_Problem); getMainSwarm().setProblem(optimizationProblem);
getMainSwarm().SetMaxAllowedSwarmRadius(maxAllowedSwarmRadius); getMainSwarm().SetMaxAllowedSwarmRadius(maxAllowedSwarmRadius);
getMainSwarm().getPopulation().setGeneration(0); getMainSwarm().getPopulation().setGeneration(0);
@ -267,7 +267,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
*/ */
protected void initSubswarmOptimizerTemplate() { protected void initSubswarmOptimizerTemplate() {
// pass on the parameters set via NichePSO (done in the analogous nichePSO-Setters as well -> no init() necessary) // pass on the parameters set via NichePSO (done in the analogous nichePSO-Setters as well -> no init() necessary)
getSubswarmOptimizerTemplate().setProblem(m_Problem); getSubswarmOptimizerTemplate().setProblem(optimizationProblem);
getSubswarmOptimizerTemplate().SetMaxAllowedSwarmRadius(maxAllowedSwarmRadius); getSubswarmOptimizerTemplate().SetMaxAllowedSwarmRadius(maxAllowedSwarmRadius);
// choose PSO-type for the subswarmoptimizer // choose PSO-type for the subswarmoptimizer
@ -294,7 +294,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
public ParticleSubSwarmOptimization getNewSubSwarmOptimizer() { public ParticleSubSwarmOptimization getNewSubSwarmOptimizer() {
//initSubswarmOptimizerTemplate(); //initSubswarmOptimizerTemplate();
ParticleSubSwarmOptimization template = (ParticleSubSwarmOptimization) getSubswarmOptimizerTemplate().clone(); // this implicitely clones the problem but does not initialize it again... ParticleSubSwarmOptimization template = (ParticleSubSwarmOptimization) getSubswarmOptimizerTemplate().clone(); // this implicitely clones the problem but does not initialize it again...
template.setProblem(this.m_Problem); //... let all subswarms use the same correct initialised problem instance template.setProblem(this.optimizationProblem); //... let all subswarms use the same correct initialised problem instance
return template; return template;
} }
@ -459,8 +459,8 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
} }
protected void doPlot() { protected void doPlot() {
m_shownextplot = (deactivationOccured || mergingOccurd || absorbtionOccurd || creationOccurd);// repopoccurd || reinitoccurd); showNextPlot = (deactivationOccured || mergingOccurd || absorbtionOccurd || creationOccurd);// repopoccurd || reinitoccurd);
if (this.getMainSwarm().getPopulation().getGeneration() % this.getShowCycle() == 0) {// || m_shownextplot){ if (this.getMainSwarm().getPopulation().getGeneration() % this.getShowCycle() == 0) {// || showNextPlot){
// plot merging step // plot merging step
if (mergingOccurd) { if (mergingOccurd) {
plotMainSwarm(false); plotMainSwarm(false);
@ -476,7 +476,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
} }
} }
// plot main step // plot main step
synchronized (m_TopologySwarm.getClass()) { synchronized (topoPlot.getClass()) {
plotMainSwarm(false); plotMainSwarm(false);
plotSubSwarms(); plotSubSwarms();
//plotAdditionalInfo(); //plotAdditionalInfo();
@ -494,7 +494,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
} }
//plotBoundStdDevInMainSwarm(0.5); //plotBoundStdDevInMainSwarm(0.5);
m_shownextplot = false; showNextPlot = false;
} }
} }
@ -572,8 +572,8 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
this.borg.add((ParticleSubSwarmOptimization) borg.clone()); // for plotting only this.borg.add((ParticleSubSwarmOptimization) borg.clone()); // for plotting only
this.others.add((ParticleSubSwarmOptimization) others.clone()); // for plotting only this.others.add((ParticleSubSwarmOptimization) others.clone()); // for plotting only
mergingOccurd = true; mergingOccurd = true;
this.borgbest.add(borg.m_BestIndividual); // for plotting only this.borgbest.add(borg.bestIndividual); // for plotting only
this.othersbest.add(others.m_BestIndividual); // for plotting only this.othersbest.add(others.bestIndividual); // for plotting only
} }
/** /**
@ -705,8 +705,8 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
* @tested Something has changed * @tested Something has changed
*/ */
protected void firePropertyChangedEvent(String name) { protected void firePropertyChangedEvent(String name) {
if (this.m_Listener != null) { if (this.populationChangedEventListener != null) {
this.m_Listener.registerPopulationStateChanged(this, name); this.populationChangedEventListener.registerPopulationStateChanged(this, name);
} }
} }
@ -718,14 +718,14 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
@Override @Override
public void addPopulationChangedEventListener( public void addPopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea; this.populationChangedEventListener = ea;
} }
@Override @Override
public boolean removePopulationChangedEventListener( public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
if (m_Listener == ea) { if (populationChangedEventListener == ea) {
m_Listener = null; populationChangedEventListener = null;
return true; return true;
} else { } else {
return false; return false;
@ -906,11 +906,11 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
// AbstractEAIndividual[] representatives = new AbstractEAIndividual[getSubSwarms().size()+1]; // AbstractEAIndividual[] representatives = new AbstractEAIndividual[getSubSwarms().size()+1];
for (int i = 0; i < getSubSwarms().size(); ++i) { for (int i = 0; i < getSubSwarms().size(); ++i) {
if (!onlyInactive || (!subSwarms.get(i).isActive())) { if (!onlyInactive || (!subSwarms.get(i).isActive())) {
representatives.add((AbstractEAIndividual) (subSwarms.get(i)).m_BestIndividual.clone()); representatives.add((AbstractEAIndividual) (subSwarms.get(i)).bestIndividual.clone());
} }
} }
if (!onlyInactive && (getMainSwarm().getPopulation().size() != 0)) { if (!onlyInactive && (getMainSwarm().getPopulation().size() != 0)) {
representatives.add((AbstractEAIndividual) getMainSwarm().m_BestIndividual.clone()); // assures at least one solution, even if no subswarm has been created representatives.add((AbstractEAIndividual) getMainSwarm().bestIndividual.clone()); // assures at least one solution, even if no subswarm has been created
} }
return representatives; return representatives;
} }
@ -1275,7 +1275,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
*/ */
@Override @Override
public InterfaceOptimizationProblem getProblem() { public InterfaceOptimizationProblem getProblem() {
return this.m_Problem; return this.optimizationProblem;
} }
/** /**
@ -1285,7 +1285,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
@Override @Override
public void setProblem(InterfaceOptimizationProblem problem) { public void setProblem(InterfaceOptimizationProblem problem) {
// set member // set member
this.m_Problem = problem; this.optimizationProblem = problem;
// pass on to the main- and subswarm optimizers // pass on to the main- and subswarm optimizers
getMainSwarm().setProblem(problem); getMainSwarm().setProblem(problem);
for (int i = 0; i < getSubSwarms().size(); ++i) { for (int i = 0; i < getSubSwarms().size(); ++i) {
@ -1300,7 +1300,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
*/ */
@Override @Override
public void setIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.identifier = name;
} }
/** /**
@ -1309,7 +1309,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
*/ */
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return this.m_Identifier; return this.identifier;
} }
/** /**
@ -1456,7 +1456,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
* @tested emp * @tested emp
*/ */
public String getPerformanceAsString() { public String getPerformanceAsString() {
if (!(m_Problem instanceof InterfaceMultimodalProblem)) { if (!(optimizationProblem instanceof InterfaceMultimodalProblem)) {
System.out.println("getPerformanceAsString: problem not instanceof InterfaceMultimodalProblem"); System.out.println("getPerformanceAsString: problem not instanceof InterfaceMultimodalProblem");
return ""; return "";
} }
@ -1467,10 +1467,10 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
Population elitepop = getSubswarmRepresentatives(false); Population elitepop = getSubswarmRepresentatives(false);
// use elite population to compute performance // use elite population to compute performance
if (m_Problem instanceof InterfaceMultimodalProblem) { if (optimizationProblem instanceof InterfaceMultimodalProblem) {
result += ((InterfaceMultimodalProblemKnown) m_Problem).getNumberOfFoundOptima(elitepop); result += ((InterfaceMultimodalProblemKnown) optimizationProblem).getNumberOfFoundOptima(elitepop);
result += "(" + ((InterfaceMultimodalProblemKnown) m_Problem).getRealOptima().size() + ")\t"; result += "(" + ((InterfaceMultimodalProblemKnown) optimizationProblem).getRealOptima().size() + ")\t";
result += ((InterfaceMultimodalProblemKnown) m_Problem).getMaximumPeakRatio(elitepop) + "\t"; result += ((InterfaceMultimodalProblemKnown) optimizationProblem).getMaximumPeakRatio(elitepop) + "\t";
//boolean[] opts = ((InterfaceMultimodalProblem)problem).whichOptimaAreFound(elitepop); //boolean[] opts = ((InterfaceMultimodalProblem)problem).whichOptimaAreFound(elitepop);
//result += "Optima:"; //result += "Optima:";
//for (int i = 0; i < opts.length; ++i){ //for (int i = 0; i < opts.length; ++i){
@ -1516,13 +1516,10 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
outputPath.mkdirs(); outputPath.mkdirs();
} }
//String outputPath = getDirForCurrentExperiment()+"/NichePSO-LogFiles/";
//OutputPath = OutputPath + dirForCurrentExperiment+"\\NichePSO-LogFiles\\";
// file name // file name
SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd'_'HH.mm.ss'_'E"); SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd'_'HH.mm.ss'_'E");
String m_StartDate = formatter.format(new Date()); String startDate = formatter.format(new Date());
String name = "NichePSO-LogFile" + "__" + m_StartDate + ".dat"; String name = "NichePSO-LogFile" + "__" + startDate + ".dat";
File f = new File(outputPath, name); // plattform independent representation... File f = new File(outputPath, name); // plattform independent representation...
@ -1634,10 +1631,10 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
double[] a = new double[2]; double[] a = new double[2];
a[0] = 0.0; a[0] = 0.0;
a[1] = 0.0; a[1] = 0.0;
this.m_TopologySwarm = new TopoPlot("NichePSO-MainSwarm", "x", "y", a, a); this.topoPlot = new TopoPlot("NichePSO-MainSwarm", "x", "y", a, a);
this.m_TopologySwarm.setParams(60, 60); this.topoPlot.setParams(60, 60);
if (m_Problem instanceof Interface2DBorderProblem) { if (optimizationProblem instanceof Interface2DBorderProblem) {
this.m_TopologySwarm.setTopology((Interface2DBorderProblem) this.m_Problem); this.topoPlot.setTopology((Interface2DBorderProblem) this.optimizationProblem);
} // draws colored plot } // draws colored plot
} }
@ -1646,12 +1643,12 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
*/ */
protected void cleanPlotSwarm() { protected void cleanPlotSwarm() {
// delete all previous points // delete all previous points
DElement[] elements = this.m_TopologySwarm.getFunctionArea().getDElements(); DElement[] elements = this.topoPlot.getFunctionArea().getDElements();
int lastIndex = elements.length - 1; int lastIndex = elements.length - 1;
DElement last = elements[lastIndex]; DElement last = elements[lastIndex];
while (last instanceof DPointSet || last instanceof DPoint || last instanceof DPointIcon) { while (last instanceof DPointSet || last instanceof DPoint || last instanceof DPointIcon) {
this.m_TopologySwarm.getFunctionArea().removeDElement(last); this.topoPlot.getFunctionArea().removeDElement(last);
// elements = this.m_TopologySwarm.getFunctionArea().getDElements(); // elements = this.topoPlot.getFunctionArea().getDElements();
lastIndex--; lastIndex--;
last = elements[lastIndex]; last = elements[lastIndex];
} }
@ -1678,23 +1675,8 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
DPointIcon icon = new Chart2DDPointIconText(id + ds); DPointIcon icon = new Chart2DDPointIconText(id + ds);
((Chart2DDPointIconText) icon).setIcon(new Chart2DDPointIconCircle()); ((Chart2DDPointIconText) icon).setIcon(new Chart2DDPointIconCircle());
point.setIcon(icon); point.setIcon(icon);
this.m_TopologySwarm.getFunctionArea().addDElement(point); this.topoPlot.getFunctionArea().addDElement(point);
} }
//try to add further information to MainSwarm-Plot at once
/* popRep = new DPointSet();
for (int i = 0; i < mainpop.size(); ++i){
tmpIndy1 = (InterfaceDataTypeDouble)mainpop.get(i);
DPoint point = new DPoint(tmpIndy1.getDoubleData()[0], tmpIndy1.getDoubleData()[1]);
double[] da = (double[])(((AbstractEAIndividual)tmpIndy1).getData("StdDevKey"));//Math.round(100*((AbstractEAIndividual)tmpIndy1).getFitness(0))/(double)100;
double d = da[0];
String ds = String.format("%6.2f", d);
DPointIcon icon = new Chart2DDPointIconText(ds);
((Chart2DDPointIconText)icon).setIcon(new Chart2DDPointIconCircle());
point.setIcon(icon);
popRep.addDPoint(point);
}
this.m_TopologyMainSwarm.plotArea.addDElement(popRep); */
} }
/** /**
@ -1712,7 +1694,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
DPointIcon icon = new Chart2DDPointIconText(ds); DPointIcon icon = new Chart2DDPointIconText(ds);
((Chart2DDPointIconText) icon).setIcon(new Chart2DDPointIconCircle()); ((Chart2DDPointIconText) icon).setIcon(new Chart2DDPointIconCircle());
point.setIcon(icon); point.setIcon(icon);
this.m_TopologySwarm.getFunctionArea().addDElement(point); this.topoPlot.getFunctionArea().addDElement(point);
} }
/** /**
@ -1737,7 +1719,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
((Chart2DDPointIconText) icon).setIcon(new Chart2DDPointIconCircle()); ((Chart2DDPointIconText) icon).setIcon(new Chart2DDPointIconCircle());
point.setIcon(icon); point.setIcon(icon);
if (d < boundary) { if (d < boundary) {
this.m_TopologySwarm.getFunctionArea().addDElement(point); this.topoPlot.getFunctionArea().addDElement(point);
} }
} }
} }
@ -1754,7 +1736,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
DPointIcon icon = new Chart2DDPointIconText(text); DPointIcon icon = new Chart2DDPointIconText(text);
((Chart2DDPointIconText) icon).setIcon(new Chart2DDPointIconCircle()); ((Chart2DDPointIconText) icon).setIcon(new Chart2DDPointIconCircle());
point.setIcon(icon); point.setIcon(icon);
this.m_TopologySwarm.getFunctionArea().addDElement(point); this.topoPlot.getFunctionArea().addDElement(point);
} }
/** /**
@ -1768,14 +1750,14 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
DPointIcon icon = new Chart2DDPointIconText(text); DPointIcon icon = new Chart2DDPointIconText(text);
((Chart2DDPointIconText) icon).setIcon(new Chart2DDPointIconCircle()); ((Chart2DDPointIconText) icon).setIcon(new Chart2DDPointIconCircle());
point.setIcon(icon); point.setIcon(icon);
this.m_TopologySwarm.getFunctionArea().addDElement(point); this.topoPlot.getFunctionArea().addDElement(point);
} }
/** /**
* @tested cleans the previous plot and plots the mainswarm as points * @tested cleans the previous plot and plots the mainswarm as points
*/ */
protected void plotMainSwarm(boolean withIDs) { protected void plotMainSwarm(boolean withIDs) {
if (this.m_Problem instanceof Interface2DBorderProblem) { if (this.optimizationProblem instanceof Interface2DBorderProblem) {
DPointSet popRep = new DPointSet(); DPointSet popRep = new DPointSet();
InterfaceDataTypeDouble tmpIndy1; InterfaceDataTypeDouble tmpIndy1;
@ -1787,7 +1769,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
tmpIndy1 = (InterfaceDataTypeDouble) mainpop.get(i); tmpIndy1 = (InterfaceDataTypeDouble) mainpop.get(i);
popRep.addDPoint(new DPoint(tmpIndy1.getDoubleData()[0], tmpIndy1.getDoubleData()[1])); popRep.addDPoint(new DPoint(tmpIndy1.getDoubleData()[0], tmpIndy1.getDoubleData()[1]));
} }
this.m_TopologySwarm.getFunctionArea().addDElement(popRep); // time consuming this.topoPlot.getFunctionArea().addDElement(popRep); // time consuming
// identify every particle in the main swarm // identify every particle in the main swarm
if (withIDs) { if (withIDs) {
@ -1821,10 +1803,10 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
for (int i = 0; i < this.getSubSwarms().size(); ++i) { for (int i = 0; i < this.getSubSwarms().size(); ++i) {
ParticleSubSwarmOptimization currentsub = this.getSubSwarms().get(i); ParticleSubSwarmOptimization currentsub = this.getSubSwarms().get(i);
if (!currentsub.isActive() && plotInactive) { if (!currentsub.isActive() && plotInactive) {
plotCircleForIndy(currentsub.m_BestIndividual, String.valueOf(i) + "[I]"); plotCircleForIndy(currentsub.bestIndividual, String.valueOf(i) + "[I]");
} }
if (currentsub.isActive() && plotActive) { if (currentsub.isActive() && plotActive) {
plotCircleForIndy(currentsub.m_BestIndividual, String.valueOf(i)); plotCircleForIndy(currentsub.bestIndividual, String.valueOf(i));
} }
} }
} }
@ -1848,7 +1830,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
protected void plotSwarmToMerge(ParticleSubSwarmOptimization swarm, int index) { protected void plotSwarmToMerge(ParticleSubSwarmOptimization swarm, int index) {
InterfaceDataTypeDouble tmpIndy1; InterfaceDataTypeDouble tmpIndy1;
Population swarmpop = (Population) swarm.getPopulation(); Population swarmpop = (Population) swarm.getPopulation();
InterfaceDataTypeDouble best = (InterfaceDataTypeDouble) swarm.m_BestIndividual; InterfaceDataTypeDouble best = (InterfaceDataTypeDouble) swarm.bestIndividual;
DPointSet popRep = new DPointSet(); DPointSet popRep = new DPointSet();
//...draw SubSwarm as points //...draw SubSwarm as points
@ -1857,7 +1839,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
tmpIndy1 = (InterfaceDataTypeDouble) swarmpop.get(j); tmpIndy1 = (InterfaceDataTypeDouble) swarmpop.get(j);
popRep.addDPoint(new DPoint(tmpIndy1.getDoubleData()[0], tmpIndy1.getDoubleData()[1])); popRep.addDPoint(new DPoint(tmpIndy1.getDoubleData()[0], tmpIndy1.getDoubleData()[1]));
} }
this.m_TopologySwarm.getFunctionArea().addDElement(popRep); // time consuming this.topoPlot.getFunctionArea().addDElement(popRep); // time consuming
//...draw circle for best //...draw circle for best
if (!swarm.isActive()) { if (!swarm.isActive()) {
@ -1874,7 +1856,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
popRep.addDPoint(new DPoint(tmpIndy1.getDoubleData()[0], tmpIndy1.getDoubleData()[1])); popRep.addDPoint(new DPoint(tmpIndy1.getDoubleData()[0], tmpIndy1.getDoubleData()[1]));
popRep.addDPoint(new DPoint(best.getDoubleData()[0], best.getDoubleData()[1])); popRep.addDPoint(new DPoint(best.getDoubleData()[0], best.getDoubleData()[1]));
} }
this.m_TopologySwarm.getFunctionArea().addDElement(popRep); // time consuming this.topoPlot.getFunctionArea().addDElement(popRep); // time consuming
} }
@ -1883,7 +1865,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
* individual * individual
*/ */
protected void plotSubSwarms() { protected void plotSubSwarms() {
if (this.m_Problem instanceof Interface2DBorderProblem) { if (this.optimizationProblem instanceof Interface2DBorderProblem) {
//DPointSet popRep = new DPointSet(); //DPointSet popRep = new DPointSet();
InterfaceDataTypeDouble tmpIndy1; InterfaceDataTypeDouble tmpIndy1;
@ -1894,7 +1876,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
ParticleSubSwarmOptimization currentsubswarm = this.getSubSwarms().get(i); ParticleSubSwarmOptimization currentsubswarm = this.getSubSwarms().get(i);
Population currentsubswarmpop = (Population) currentsubswarm.getPopulation(); Population currentsubswarmpop = (Population) currentsubswarm.getPopulation();
//InterfaceDataTypeDouble best = (InterfaceDataTypeDouble)currentsubswarmpop.getBestIndividual(); //InterfaceDataTypeDouble best = (InterfaceDataTypeDouble)currentsubswarmpop.getBestIndividual();
InterfaceDataTypeDouble best = (InterfaceDataTypeDouble) currentsubswarm.m_BestIndividual; InterfaceDataTypeDouble best = (InterfaceDataTypeDouble) currentsubswarm.bestIndividual;
DPointSet popRep = new DPointSet(); DPointSet popRep = new DPointSet();
//...draw SubSwarm as points //...draw SubSwarm as points
@ -1903,7 +1885,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
tmpIndy1 = (InterfaceDataTypeDouble) currentsubswarmpop.get(j); tmpIndy1 = (InterfaceDataTypeDouble) currentsubswarmpop.get(j);
popRep.addDPoint(new DPoint(tmpIndy1.getDoubleData()[0], tmpIndy1.getDoubleData()[1])); popRep.addDPoint(new DPoint(tmpIndy1.getDoubleData()[0], tmpIndy1.getDoubleData()[1]));
} }
this.m_TopologySwarm.getFunctionArea().addDElement(popRep); // time consuming this.topoPlot.getFunctionArea().addDElement(popRep); // time consuming
//...draw circle for best //...draw circle for best
if (!currentsubswarm.isActive()) { if (!currentsubswarm.isActive()) {
@ -1932,7 +1914,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
popRep.addDPoint(new DPoint(tmpIndy1.getDoubleData()[0], tmpIndy1.getDoubleData()[1])); popRep.addDPoint(new DPoint(tmpIndy1.getDoubleData()[0], tmpIndy1.getDoubleData()[1]));
popRep.addDPoint(new DPoint(best.getDoubleData()[0], best.getDoubleData()[1])); popRep.addDPoint(new DPoint(best.getDoubleData()[0], best.getDoubleData()[1]));
} }
this.m_TopologySwarm.getFunctionArea().addDElement(popRep); // time consuming this.topoPlot.getFunctionArea().addDElement(popRep); // time consuming
} }
} // endif } // endif
} }
@ -1985,7 +1967,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
// from deactivation and reinit // from deactivation and reinit
if (deactivationOccured) { if (deactivationOccured) {
for (int i = 0; i < deactivatedSwarm.size(); ++i) { for (int i = 0; i < deactivatedSwarm.size(); ++i) {
plotCircleForIndy(deactivatedSwarm.get(i).m_BestIndividual, " deac"); plotCircleForIndy(deactivatedSwarm.get(i).bestIndividual, " deac");
} }
// for (int i = 0; i < reinitedSwarm.size(); ++i){ // for (int i = 0; i < reinitedSwarm.size(); ++i){
// plotSwarm(reinitedSwarm.get(i)," reinit"); // plotSwarm(reinitedSwarm.get(i)," reinit");
@ -2029,7 +2011,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
DPointIcon icon = new Chart2DDPointIconText(""); DPointIcon icon = new Chart2DDPointIconText("");
((Chart2DDPointIconText) icon).setIcon(new Chart2DDPointIconPoint()); ((Chart2DDPointIconText) icon).setIcon(new Chart2DDPointIconPoint());
point.setIcon(icon); point.setIcon(icon);
this.m_TopologySwarm.getFunctionArea().addDElement(point); this.topoPlot.getFunctionArea().addDElement(point);
//plot oldPos //plot oldPos
if (!(indy.getData("oldPosition") == null)) { if (!(indy.getData("oldPosition") == null)) {
@ -2038,7 +2020,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
icon = new Chart2DDPointIconText(""); icon = new Chart2DDPointIconText("");
((Chart2DDPointIconText) icon).setIcon(new Chart2DDPointIconCross()); ((Chart2DDPointIconText) icon).setIcon(new Chart2DDPointIconCross());
point.setIcon(icon); point.setIcon(icon);
this.m_TopologySwarm.getFunctionArea().addDElement(point); this.topoPlot.getFunctionArea().addDElement(point);
} }
//plot personalBestPos //plot personalBestPos
@ -2047,7 +2029,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
icon = new Chart2DDPointIconText(""); icon = new Chart2DDPointIconText("");
((Chart2DDPointIconText) icon).setIcon(new Chart2DDPointIconCircle()); ((Chart2DDPointIconText) icon).setIcon(new Chart2DDPointIconCircle());
point.setIcon(icon); point.setIcon(icon);
this.m_TopologySwarm.getFunctionArea().addDElement(point); this.topoPlot.getFunctionArea().addDElement(point);
//plot neighbourBestPos //plot neighbourBestPos
double[] neighbourBestPos = (double[]) indy.getData("neighbourBestPos"); double[] neighbourBestPos = (double[]) indy.getData("neighbourBestPos");
@ -2055,7 +2037,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
icon = new Chart2DDPointIconText(""); icon = new Chart2DDPointIconText("");
((Chart2DDPointIconText) icon).setIcon(new Chart2DDPointIconContent()); ((Chart2DDPointIconText) icon).setIcon(new Chart2DDPointIconContent());
point.setIcon(icon); point.setIcon(icon);
this.m_TopologySwarm.getFunctionArea().addDElement(point); this.topoPlot.getFunctionArea().addDElement(point);
} }
// protected void saveCurrentPlotAsJPG(String filename){ // protected void saveCurrentPlotAsJPG(String filename){
@ -2077,16 +2059,16 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
// //
// File f = new File(outputPath,name); // File f = new File(outputPath,name);
// //
// synchronized(m_TopologySwarm){ // synchronized(topoPlot){
// try { // try {
// JFrame frame = m_TopologySwarm.internalFrame; // JFrame frame = topoPlot.internalFrame;
// Robot robot = new Robot(); // Robot robot = new Robot();
// Rectangle area; // Rectangle area;
// area = frame.getBounds(); // area = frame.getBounds();
// BufferedImage bufferedImage = robot.createScreenCapture(area); // BufferedImage bufferedImage = robot.createScreenCapture(area);
// //
// // JFileChooser fc = new JFileChooser(); // // JFileChooser fc = new JFileChooser();
// // if (fc.showSaveDialog(m_TopologySwarm.internalFrame) != JFileChooser.APPROVE_OPTION) return; // // if (fc.showSaveDialog(topoPlot.internalFrame) != JFileChooser.APPROVE_OPTION) return;
// System.out.println("Name " + f.getName()); // System.out.println("Name " + f.getName());
// try { // try {
// FileOutputStream fos = new FileOutputStream(f); // FileOutputStream fos = new FileOutputStream(f);

View File

@ -33,10 +33,10 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
* <code>serialVersionUID</code> * <code>serialVersionUID</code>
*/ */
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private Population m_Population = new Population(); private Population population = new Population();
private InterfaceOptimizationProblem m_Problem = new F1Problem(); private InterfaceOptimizationProblem optimizationProblem = new F1Problem();
private InterfaceSelection m_ParentSelection = new SelectParticleWheel(0.5); private InterfaceSelection parentSelection = new SelectParticleWheel(0.5);
private String m_Identifier = ""; private String identifier = "";
private boolean withShow = false; private boolean withShow = false;
private double mutationSigma = 0.01; private double mutationSigma = 0.01;
private double randomImmigrationQuota = 0.05; private double randomImmigrationQuota = 0.05;
@ -45,7 +45,7 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
private int popSize = 300; private int popSize = 300;
private int sleepTime = 0; private int sleepTime = 0;
transient private int indCount = 0; transient private int indCount = 0;
transient private InterfacePopulationChangedEventListener m_Listener; transient private InterfacePopulationChangedEventListener populationChangedEventListener;
transient Plot myPlot = null; transient Plot myPlot = null;
public static final boolean TRACE = false; public static final boolean TRACE = false;
@ -60,20 +60,17 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
initialVelocity = vInit; initialVelocity = vInit;
randomImmigrationQuota = immiQuote; randomImmigrationQuota = immiQuote;
rotationDeg = rotDeg; rotationDeg = rotDeg;
m_ParentSelection = new SelectParticleWheel(selScaling); parentSelection = new SelectParticleWheel(selScaling);
if (withShow) { if (withShow) {
setWithShow(true); setWithShow(true);
} }
} }
public ParticleFilterOptimization(ParticleFilterOptimization a) { public ParticleFilterOptimization(ParticleFilterOptimization a) {
this.m_Population = (Population) a.m_Population.clone(); this.population = (Population) a.population.clone();
this.m_Problem = (InterfaceOptimizationProblem) a.m_Problem.clone(); this.optimizationProblem = (InterfaceOptimizationProblem) a.optimizationProblem.clone();
this.m_Identifier = a.m_Identifier; this.identifier = a.identifier;
//this.m_Plague = a.m_Plague; this.parentSelection = (InterfaceSelection) a.parentSelection.clone();
//this.m_NumberOfPartners = a.m_NumberOfPartners;
//this.m_UseElitism = a.m_UseElitism;
this.m_ParentSelection = (InterfaceSelection) a.m_ParentSelection.clone();
if (a.withShow) { if (a.withShow) {
setWithShow(true); setWithShow(true);
} }
@ -94,16 +91,16 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
//System.out.println("pops targ is " + population.getPopulationSize()); //System.out.println("pops targ is " + population.getPopulationSize());
if (initialVelocity <= 0.) { if (initialVelocity <= 0.) {
(((AbstractOptimizationProblem) m_Problem).getIndividualTemplate()).setMutationOperator(new MutateESFixedStepSize(mutationSigma)); (((AbstractOptimizationProblem) optimizationProblem).getIndividualTemplate()).setMutationOperator(new MutateESFixedStepSize(mutationSigma));
} else { } else {
(((AbstractOptimizationProblem) m_Problem).getIndividualTemplate()).setMutationOperator(new MutateESCorrVector(mutationSigma, initialVelocity, rotationDeg)); (((AbstractOptimizationProblem) optimizationProblem).getIndividualTemplate()).setMutationOperator(new MutateESCorrVector(mutationSigma, initialVelocity, rotationDeg));
} }
m_Population.setTargetSize(popSize); population.setTargetSize(popSize);
this.m_Problem.initializePopulation(this.m_Population); this.optimizationProblem.initializePopulation(this.population);
setWithShow(withShow); setWithShow(withShow);
this.evaluatePopulation(this.m_Population); this.evaluatePopulation(this.population);
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
} }
@ -115,10 +112,10 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
*/ */
@Override @Override
public void initByPopulation(Population pop, boolean reset) { public void initByPopulation(Population pop, boolean reset) {
this.m_Population = (Population) pop.clone(); this.population = (Population) pop.clone();
if (reset) { if (reset) {
this.m_Population.init(); this.population.init();
this.evaluatePopulation(this.m_Population); this.evaluatePopulation(this.population);
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
} }
} }
@ -129,7 +126,7 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
* @param population The population that is to be evaluated * @param population The population that is to be evaluated
*/ */
private Population evaluatePopulation(Population population) { private Population evaluatePopulation(Population population) {
this.m_Problem.evaluate(population); this.optimizationProblem.evaluate(population);
population.incrGeneration(); population.incrGeneration();
return population; return population;
} }
@ -141,24 +138,24 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
Population parents; Population parents;
boolean doImmigr = false; boolean doImmigr = false;
this.m_ParentSelection.prepareSelection(pop); this.parentSelection.prepareSelection(pop);
// Generate a Population of Parents with Parantselectionmethod. // Generate a Population of Parents with Parantselectionmethod.
// DONT forget cloning -> selection does only shallow copies! // DONT forget cloning -> selection does only shallow copies!
int targetSize = this.m_Population.getTargetSize(); int targetSize = this.population.getTargetSize();
if (randomImmigrationQuota > 0) { if (randomImmigrationQuota > 0) {
if (randomImmigrationQuota > 1.) { if (randomImmigrationQuota > 1.) {
System.err.println("Error, invalid immigration quota!"); System.err.println("Error, invalid immigration quota!");
} else { } else {
targetSize = (int) (this.m_Population.getTargetSize() * (1. - randomImmigrationQuota)); targetSize = (int) (this.population.getTargetSize() * (1. - randomImmigrationQuota));
targetSize = Math.max(1, targetSize); // guarantee at least one to be selected targetSize = Math.max(1, targetSize); // guarantee at least one to be selected
if (targetSize < this.m_Population.getTargetSize()) { if (targetSize < this.population.getTargetSize()) {
doImmigr = true; doImmigr = true;
} }
} }
} }
parents = (Population) (this.m_ParentSelection.selectFrom(pop, targetSize)).clone(); parents = (Population) (this.parentSelection.selectFrom(pop, targetSize)).clone();
if (doImmigr) { if (doImmigr) {
// add immigrants // add immigrants
@ -238,7 +235,7 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
//AbstractEAIndividual elite; //AbstractEAIndividual elite;
// resample using selection // resample using selection
nextGeneration = resample(m_Population); nextGeneration = resample(population);
if (sleepTime > 0) { if (sleepTime > 0) {
try { try {
@ -253,10 +250,10 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
// predict step // predict step
predict(nextGeneration); predict(nextGeneration);
if (TRACE) { if (TRACE) {
System.out.println("Speed is " + BeanInspector.toString(ParticleSwarmOptimization.getPopulationVelSpeed(m_Population, 3, MutateESCorrVector.vectorKey, null, null)) + " popM " + BeanInspector.toString(m_Population.getPopulationMeasures(new EuclideanMetric()))); System.out.println("Speed is " + BeanInspector.toString(ParticleSwarmOptimization.getPopulationVelSpeed(population, 3, MutateESCorrVector.vectorKey, null, null)) + " popM " + BeanInspector.toString(population.getPopulationMeasures(new EuclideanMetric())));
} }
m_Population = evaluatePopulation(nextGeneration); population = evaluatePopulation(nextGeneration);
// collectStatistics(population); // collectStatistics(population);
@ -266,14 +263,14 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
@Override @Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) { public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea; this.populationChangedEventListener = ea;
} }
@Override @Override
public boolean removePopulationChangedEventListener( public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
if (m_Listener == ea) { if (populationChangedEventListener == ea) {
m_Listener = null; populationChangedEventListener = null;
return true; return true;
} else { } else {
return false; return false;
@ -281,8 +278,8 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
} }
protected void firePropertyChangedEvent(String name) { protected void firePropertyChangedEvent(String name) {
if (this.m_Listener != null) { if (this.populationChangedEventListener != null) {
this.m_Listener.registerPopulationStateChanged(this, name); this.populationChangedEventListener.registerPopulationStateChanged(this, name);
} }
} }
@ -293,7 +290,7 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
*/ */
@Override @Override
public void setProblem(InterfaceOptimizationProblem problem) { public void setProblem(InterfaceOptimizationProblem problem) {
this.m_Problem = problem; this.optimizationProblem = problem;
if (problem instanceof AbstractOptimizationProblem) { if (problem instanceof AbstractOptimizationProblem) {
((AbstractOptimizationProblem) problem).informAboutOptimizer(this); ((AbstractOptimizationProblem) problem).informAboutOptimizer(this);
} }
@ -301,7 +298,7 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
@Override @Override
public InterfaceOptimizationProblem getProblem() { public InterfaceOptimizationProblem getProblem() {
return this.m_Problem; return this.optimizationProblem;
} }
/** /**
@ -314,9 +311,9 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
public String getStringRepresentation() { public String getStringRepresentation() {
StringBuilder strB = new StringBuilder(200); StringBuilder strB = new StringBuilder(200);
strB.append("Particle Filter:\nOptimization Problem: "); strB.append("Particle Filter:\nOptimization Problem: ");
strB.append(this.m_Problem.getStringRepresentationForProblem(this)); strB.append(this.optimizationProblem.getStringRepresentationForProblem(this));
strB.append("\n"); strB.append("\n");
strB.append(this.m_Population.getStringRepresentation()); strB.append(this.population.getStringRepresentation());
return strB.toString(); return strB.toString();
} }
@ -327,12 +324,12 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
*/ */
@Override @Override
public void setIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.identifier = name;
} }
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return this.m_Identifier; return this.identifier;
} }
/** /**
@ -354,12 +351,12 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
*/ */
@Override @Override
public Population getPopulation() { public Population getPopulation() {
return this.m_Population; return this.population;
} }
@Override @Override
public void setPopulation(Population pop) { public void setPopulation(Population pop) {
this.m_Population = pop; this.population = pop;
} }
public String populationTipText() { public String populationTipText() {
@ -377,11 +374,11 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
* @param selection * @param selection
*/ */
public void setParentSelection(InterfaceSelection selection) { public void setParentSelection(InterfaceSelection selection) {
this.m_ParentSelection = selection; this.parentSelection = selection;
} }
public InterfaceSelection getParentSelection() { public InterfaceSelection getParentSelection() {
return this.m_ParentSelection; return this.parentSelection;
} }
public String parentSelectionTipText() { public String parentSelectionTipText() {
@ -403,8 +400,8 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
if (myPlot != null) { if (myPlot != null) {
myPlot.clearAll(); myPlot.clearAll();
double[][] range = null; double[][] range = null;
if ((m_Population != null) && (m_Population.size() > 0)) { if ((population != null) && (population.size() > 0)) {
range = ((InterfaceDataTypeDouble) this.m_Population.get(0)).getDoubleRange(); range = ((InterfaceDataTypeDouble) this.population.get(0)).getDoubleRange();
} }
if (range != null) { if (range != null) {
myPlot.setCornerPoints(range, 0); myPlot.setCornerPoints(range, 0);
@ -421,8 +418,8 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
myPlot = null; myPlot = null;
} else { } else {
double[][] range; double[][] range;
if ((m_Population != null) && (m_Population.size() > 0)) { if ((population != null) && (population.size() > 0)) {
range = ((InterfaceDataTypeDouble) this.m_Population.get(0)).getDoubleRange(); range = ((InterfaceDataTypeDouble) this.population.get(0)).getDoubleRange();
} else { } else {
range = new double[2][]; range = new double[2][];
range[0] = new double[2]; range[0] = new double[2];
@ -504,6 +501,6 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
public void setPopSize(int popSize) { public void setPopSize(int popSize) {
this.popSize = popSize; this.popSize = popSize;
m_Population.setTargetSize(popSize); population.setTargetSize(popSize);
} }
} }

View File

@ -54,8 +54,8 @@ public class ParticleSubSwarmOptimization extends ParticleSwarmOptimizationGCPSO
*/ */
public ParticleSubSwarmOptimization(ParticleSubSwarmOptimization a) { public ParticleSubSwarmOptimization(ParticleSubSwarmOptimization a) {
super(a); super(a);
if (a.m_BestIndividual != null) { if (a.bestIndividual != null) {
m_BestIndividual = (AbstractEAIndividual) a.m_BestIndividual.clone(); bestIndividual = (AbstractEAIndividual) a.bestIndividual.clone();
} }
maxAllowedSwarmRadiusNormal = a.maxAllowedSwarmRadiusNormal; maxAllowedSwarmRadiusNormal = a.maxAllowedSwarmRadiusNormal;
@ -250,7 +250,7 @@ public class ParticleSubSwarmOptimization extends ParticleSwarmOptimizationGCPSO
/** /**
* @tested junit& * @tested junit&
* updates the m_BestIndividual member which represents the gbest individual * updates the bestIndividual member which represents the gbest individual
* (i.e. the best position and fitness encountered by any particle of the swarm) * (i.e. the best position and fitness encountered by any particle of the swarm)
* Beware: if a particle enters the swarm its knowledge about its pbest enters the swarm, * Beware: if a particle enters the swarm its knowledge about its pbest enters the swarm,
* on the other side: if a particle leaves the swarm its knowledge leaves the swarm as well. * on the other side: if a particle leaves the swarm its knowledge leaves the swarm as well.
@ -259,18 +259,18 @@ public class ParticleSubSwarmOptimization extends ParticleSwarmOptimizationGCPSO
if (getPopulation().size() == 0) { if (getPopulation().size() == 0) {
return; return;
} }
// First: set m_BestIndividual to any personal best position in the swarm (-> bestindypbest). // First: set bestIndividual to any personal best position in the swarm (-> bestindypbest).
// This is necessary because the current m_BestIndividual my came from // This is necessary because the current bestIndividual my came from
// an individual that left the swarm and would never be replaced if it // an individual that left the swarm and would never be replaced if it
// would dominate all remaining positions in the swarm. // would dominate all remaining positions in the swarm.
AbstractEAIndividual bestindy = getPopulation().getBestEAIndividual(); AbstractEAIndividual bestindy = getPopulation().getBestEAIndividual();
AbstractEAIndividual bestindypbest = (AbstractEAIndividual) bestindy.getData("PersonalBestKey"); AbstractEAIndividual bestindypbest = (AbstractEAIndividual) bestindy.getData("PersonalBestKey");
m_BestIndividual = (AbstractEAIndividual) bestindypbest.clone(); bestIndividual = (AbstractEAIndividual) bestindypbest.clone();
for (int i = 0; i < getPopulation().size(); ++i) { for (int i = 0; i < getPopulation().size(); ++i) {
AbstractEAIndividual currentindy = getPopulation().getEAIndividual(i); AbstractEAIndividual currentindy = getPopulation().getEAIndividual(i);
AbstractEAIndividual currentindypbest = (AbstractEAIndividual) currentindy.getData("PersonalBestKey"); AbstractEAIndividual currentindypbest = (AbstractEAIndividual) currentindy.getData("PersonalBestKey");
if (currentindypbest.isDominating(m_BestIndividual)) { if (currentindypbest.isDominating(bestIndividual)) {
m_BestIndividual = (AbstractEAIndividual) currentindypbest.clone(); bestIndividual = (AbstractEAIndividual) currentindypbest.clone();
// ++gbestImprovmentsInARow; // ++gbestImprovmentsInARow;
} //else gbestImprovmentsInARow = 0; } //else gbestImprovmentsInARow = 0;
} }
@ -347,7 +347,7 @@ public class ParticleSubSwarmOptimization extends ParticleSwarmOptimizationGCPSO
*/ */
public void updateMaxPosDist() { public void updateMaxPosDist() {
// compute the maximal possible distance in the search space: // compute the maximal possible distance in the search space:
AbstractOptimizationProblem prob = (AbstractOptimizationProblem) m_Problem; AbstractOptimizationProblem prob = (AbstractOptimizationProblem) optimizationProblem;
// problem must have called initializeProblem, so that the template is set correctly. This shouls always be the case here... // problem must have called initializeProblem, so that the template is set correctly. This shouls always be the case here...
AbstractEAIndividual template = prob.getIndividualTemplate(); AbstractEAIndividual template = prob.getIndividualTemplate();
if (template == null) { if (template == null) {
@ -481,7 +481,7 @@ public class ParticleSubSwarmOptimization extends ParticleSwarmOptimizationGCPSO
Population tmp = new Population(); Population tmp = new Population();
tmp.setTargetSize(particleIndices.length); tmp.setTargetSize(particleIndices.length);
////////////// //////////////
AbstractOptimizationProblem prob = (AbstractOptimizationProblem) m_Problem; AbstractOptimizationProblem prob = (AbstractOptimizationProblem) optimizationProblem;
AbstractEAIndividual template = prob.getIndividualTemplate(); // problem must be inited at this point AbstractEAIndividual template = prob.getIndividualTemplate(); // problem must be inited at this point
AbstractEAIndividual tmpIndy; AbstractEAIndividual tmpIndy;
@ -494,7 +494,7 @@ public class ParticleSubSwarmOptimization extends ParticleSwarmOptimizationGCPSO
/////////// ///////////
ParticleSubSwarmOptimization tmpopt = new ParticleSubSwarmOptimization(); ParticleSubSwarmOptimization tmpopt = new ParticleSubSwarmOptimization();
tmpopt.setProblem(this.m_Problem); tmpopt.setProblem(this.optimizationProblem);
tmpopt.evaluatePopulation(tmp); tmpopt.evaluatePopulation(tmp);
tmpopt.initByPopulation(tmp, false); // + size FCs tmpopt.initByPopulation(tmp, false); // + size FCs
@ -605,7 +605,7 @@ public class ParticleSubSwarmOptimization extends ParticleSwarmOptimizationGCPSO
*/ */
@Override @Override
public void setProblem(InterfaceOptimizationProblem problem) { public void setProblem(InterfaceOptimizationProblem problem) {
this.m_Problem = problem; this.optimizationProblem = problem;
updateMaxPosDist(); updateMaxPosDist();
} }
@ -623,11 +623,11 @@ public class ParticleSubSwarmOptimization extends ParticleSwarmOptimizationGCPSO
for (int i = 0; i < population.size(); ++i) { for (int i = 0; i < population.size(); ++i) {
AbstractEAIndividual indy = population.getEAIndividual(i); AbstractEAIndividual indy = population.getEAIndividual(i);
//double dist = metric.distance(m_BestIndividual, indy); //double dist = metric.distance(bestIndividual, indy);
double sqrdDist = EuclideanMetric.squaredEuclideanDistance(AbstractEAIndividual.getDoublePositionShallow(m_BestIndividual), double sqrdDist = EuclideanMetric.squaredEuclideanDistance(AbstractEAIndividual.getDoublePositionShallow(bestIndividual),
AbstractEAIndividual.getDoublePositionShallow(indy)); AbstractEAIndividual.getDoublePositionShallow(indy));
//dist = distance(m_BestIndividual, indy); //dist = distance(bestIndividual, indy);
if (sqrdDist > max) { if (sqrdDist > max) {
max = sqrdDist; max = sqrdDist;
} }
@ -773,7 +773,7 @@ public class ParticleSubSwarmOptimization extends ParticleSwarmOptimizationGCPSO
} }
public AbstractEAIndividual getGBestIndividual() { public AbstractEAIndividual getGBestIndividual() {
return m_BestIndividual; return bestIndividual;
} }
/** /**

View File

@ -48,8 +48,8 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
private static final long serialVersionUID = -149996122795669589L; private static final long serialVersionUID = -149996122795669589L;
protected Population population = new Population(); protected Population population = new Population();
Object[] sortedPop = null; Object[] sortedPop = null;
protected AbstractEAIndividual m_BestIndividual = null; protected AbstractEAIndividual bestIndividual = null;
protected InterfaceOptimizationProblem m_Problem = new F1Problem(); protected InterfaceOptimizationProblem optimizationProblem = new F1Problem();
protected boolean checkRange = true; protected boolean checkRange = true;
protected boolean checkSpeedLimit = false; protected boolean checkSpeedLimit = false;
protected boolean useAlternative = false; protected boolean useAlternative = false;
@ -93,7 +93,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
transient final static String indexKey = "particleIndex"; transient final static String indexKey = "particleIndex";
transient final static String sortedIndexKey = "sortedParticleIndex"; transient final static String sortedIndexKey = "sortedParticleIndex";
transient final static String dmsGroupIndexKey = "dmsGroupIndex"; transient final static String dmsGroupIndexKey = "dmsGroupIndex";
protected String m_Identifier = ""; protected String indentifier = "";
transient private Vector<InterfacePopulationChangedEventListener> changeListener; transient private Vector<InterfacePopulationChangedEventListener> changeListener;
transient private TopoPlot topoPlot = null; transient private TopoPlot topoPlot = null;
/// sleep time so that visual plot can be followed easier /// sleep time so that visual plot can be followed easier
@ -104,15 +104,13 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
private int emaPeriods = 0; private int emaPeriods = 0;
// for debugging only // for debugging only
transient private static boolean TRACE = false; transient private static boolean TRACE = false;
transient protected boolean m_Show = false; transient protected boolean show = false;
transient protected Plot m_Plot; transient protected Plot plot;
private boolean externalInitialPop = false; private boolean externalInitialPop = false;
private static String lastSuccessKey = "successfulUpdate"; private static String lastSuccessKey = "successfulUpdate";
// private double lsCandidateRatio=0.25; // private double lsCandidateRatio=0.25;
public ParticleSwarmOptimization() { public ParticleSwarmOptimization() {
// this.m_Topology = new SelectedTag( "Linear", "Grid", "Star", "Multi-Swarm", "Tree", "HPSO", "Random" );
// m_Topology.setSelectedTag(1);
topology = PSOTopologyEnum.grid; topology = PSOTopologyEnum.grid;
algType = new SelectedTag("Inertness", "Constriction"); algType = new SelectedTag("Inertness", "Constriction");
algType.setSelectedTag(1); algType.setSelectedTag(1);
@ -123,14 +121,12 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
public ParticleSwarmOptimization(ParticleSwarmOptimization a) { public ParticleSwarmOptimization(ParticleSwarmOptimization a) {
topology = a.topology; topology = a.topology;
// if (a.m_Topology != null)
// this.m_Topology = (SelectedTag)a.m_Topology.clone();
if (a.algType != null) { if (a.algType != null) {
this.algType = (SelectedTag) a.algType.clone(); this.algType = (SelectedTag) a.algType.clone();
} }
this.population = (Population) a.population.clone(); this.population = (Population) a.population.clone();
this.m_Problem = a.m_Problem; this.optimizationProblem = a.optimizationProblem;
this.m_Identifier = a.m_Identifier; this.indentifier = a.indentifier;
this.initialVelocity = a.initialVelocity; this.initialVelocity = a.initialVelocity;
this.speedLimit = a.speedLimit; this.speedLimit = a.speedLimit;
this.phi1 = a.phi1; this.phi1 = a.phi1;
@ -195,9 +191,9 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
@Override @Override
public void init() { public void init() {
if (m_Plot != null) { if (plot != null) {
// m_Plot.dispose(); // plot.dispose();
m_Plot = null; plot = null;
} }
if (topoPlot != null) { if (topoPlot != null) {
// topoPlot.dispose(); // topoPlot.dispose();
@ -205,13 +201,13 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
} }
tracedVelocity = null; tracedVelocity = null;
if (!externalInitialPop) { if (!externalInitialPop) {
this.m_Problem.initializePopulation(this.population); this.optimizationProblem.initializePopulation(this.population);
} }
// evaluation needs to be done here now, as its omitted if reset is false // evaluation needs to be done here now, as its omitted if reset is false
initDefaults(this.population); initDefaults(this.population);
this.evaluatePopulation(this.population); this.evaluatePopulation(this.population);
if (m_BestIndividual == null) { if (bestIndividual == null) {
m_BestIndividual = population.getBestEAIndividual(); bestIndividual = population.getBestEAIndividual();
} }
initByPopulation(null, false); initByPopulation(null, false);
externalInitialPop = false; externalInitialPop = false;
@ -282,7 +278,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
addMovingAverage(tracedVelocity, curAvVelAndSpeed, 2. / (emaPeriods + 1)); addMovingAverage(tracedVelocity, curAvVelAndSpeed, 2. / (emaPeriods + 1));
} }
} }
if (m_Show) { if (show) {
System.out.println(population.getGeneration() + " - abs avg " + curAvVelAndSpeed[curAvVelAndSpeed.length - 1] + ", vect " + Mathematics.getRelativeLength(curAvVelAndSpeed, range) + ", rel " + (curAvVelAndSpeed[curAvVelAndSpeed.length - 1] / Mathematics.getRelativeLength(curAvVelAndSpeed, range))); System.out.println(population.getGeneration() + " - abs avg " + curAvVelAndSpeed[curAvVelAndSpeed.length - 1] + ", vect " + Mathematics.getRelativeLength(curAvVelAndSpeed, range) + ", rel " + (curAvVelAndSpeed[curAvVelAndSpeed.length - 1] / Mathematics.getRelativeLength(curAvVelAndSpeed, range)));
} }
} }
@ -472,7 +468,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
} }
} }
this.m_BestIndividual = (AbstractEAIndividual) this.population.getBestEAIndividual().clone(); this.bestIndividual = (AbstractEAIndividual) this.population.getBestEAIndividual().clone();
if (reset) { if (reset) {
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
@ -538,7 +534,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
* @param population The population that is to be evaluated * @param population The population that is to be evaluated
*/ */
protected void evaluatePopulation(Population population) { protected void evaluatePopulation(Population population) {
this.m_Problem.evaluate(population); this.optimizationProblem.evaluate(population);
population.incrGeneration(); population.incrGeneration();
if (emaPeriods > 0) { if (emaPeriods > 0) {
traceEMA(population); traceEMA(population);
@ -678,37 +674,37 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
} }
protected void plotIndy(double[] curPosition, double[] curVelocity, int index) { protected void plotIndy(double[] curPosition, double[] curVelocity, int index) {
if (this.m_Show) { if (this.show) {
if (curVelocity == null) { if (curVelocity == null) {
this.m_Plot.setUnconnectedPoint(curPosition[0], curPosition[1], index); this.plot.setUnconnectedPoint(curPosition[0], curPosition[1], index);
} else { } else {
this.m_Plot.setConnectedPoint(curPosition[0], curPosition[1], index); this.plot.setConnectedPoint(curPosition[0], curPosition[1], index);
this.m_Plot.setConnectedPoint(curPosition[0] + curVelocity[0], curPosition[1] + curVelocity[1], index); this.plot.setConnectedPoint(curPosition[0] + curVelocity[0], curPosition[1] + curVelocity[1], index);
} }
// m_Plot = null; // plot = null;
// show(); // show();
// if (pop.getGeneration()%15 == 0) { // if (pop.getGeneration()%15 == 0) {
// this.m_Plot.clearAll(); // this.plot.clearAll();
// m_Plot.setUnconnectedPoint(-10, -10, 0); // plot.setUnconnectedPoint(-10, -10, 0);
// m_Plot.setUnconnectedPoint(10, 10, 0); // plot.setUnconnectedPoint(10, 10, 0);
// } // }
// if (index != 0) return; // if (index != 0) return;
// double[] bestPosition = (double[])m_BestIndividual.getData(partBestPosKey); // double[] bestPosition = (double[])bestIndividual.getData(partBestPosKey);
// double[] localBestPos = findNeighbourhoodOptimum(index, population); // double[] localBestPos = findNeighbourhoodOptimum(index, population);
// this.m_Plot.setConnectedPoint(curPosition[0], curPosition[1], index+1); // this.plot.setConnectedPoint(curPosition[0], curPosition[1], index+1);
// this.m_Plot.setConnectedPoint(curPosition[0] + curVelocity[0], curPosition[1] + curVelocity[1], index+1); // this.plot.setConnectedPoint(curPosition[0] + curVelocity[0], curPosition[1] + curVelocity[1], index+1);
// this.m_Plot.setConnectedPoint(curPosition[0], curPosition[1], index+2); // this.plot.setConnectedPoint(curPosition[0], curPosition[1], index+2);
// this.m_Plot.setConnectedPoint(bestPosition[0], bestPosition[1], index+2); // this.plot.setConnectedPoint(bestPosition[0], bestPosition[1], index+2);
// this.m_Plot.setConnectedPoint(curPosition[0], curPosition[1], index+3); // this.plot.setConnectedPoint(curPosition[0], curPosition[1], index+3);
// this.m_Plot.setConnectedPoint(localBestPos[0], localBestPos[1], index+3); // this.plot.setConnectedPoint(localBestPos[0], localBestPos[1], index+3);
// this.m_Plot.setConnectedPoint(curPosition[0], curPosition[1], index+1); // this.plot.setConnectedPoint(curPosition[0], curPosition[1], index+1);
// this.m_Plot.setConnectedPoint(localBestPosition[0], localBestPosition[1], index+1); // this.plot.setConnectedPoint(localBestPosition[0], localBestPosition[1], index+1);
// this.m_Plot.setConnectedPoint(curPosition[0], curPosition[1], index+1); // this.plot.setConnectedPoint(curPosition[0], curPosition[1], index+1);
// this.m_Plot.setConnectedPoint(bestPosition[0], bestPosition[1], index+1); // this.plot.setConnectedPoint(bestPosition[0], bestPosition[1], index+1);
// this.m_Plot.setUnconnectedPoint(curPosition[0], curPosition[1], 100*index+1); // this.plot.setUnconnectedPoint(curPosition[0], curPosition[1], 100*index+1);
} }
} }
@ -1037,7 +1033,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
localBestFitness = ((double[]) (indy).getData(partBestFitKey)).clone(); localBestFitness = ((double[]) (indy).getData(partBestFitKey)).clone();
localBestPosition = ((double[]) (indy).getData(partBestPosKey)).clone(); localBestPosition = ((double[]) (indy).getData(partBestPosKey)).clone();
if (useHistoric) { if (useHistoric) {
bestIndy = m_BestIndividual; bestIndy = bestIndividual;
} else { } else {
bestIndy = pop.getBestEAIndividual(); bestIndy = pop.getBestEAIndividual();
} }
@ -1403,11 +1399,11 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
} }
protected void maybeClearPlot() { protected void maybeClearPlot() {
if (((population.getGeneration() % 23) == 0) && isShow() && (m_Plot != null)) { if (((population.getGeneration() % 23) == 0) && isShow() && (plot != null)) {
m_Plot.clearAll(); plot.clearAll();
InterfaceDataTypeDouble indy = (InterfaceDataTypeDouble) this.population.get(0); InterfaceDataTypeDouble indy = (InterfaceDataTypeDouble) this.population.get(0);
double[][] range = indy.getDoubleRange(); double[][] range = indy.getDoubleRange();
m_Plot.setCornerPoints(range, 0); plot.setCornerPoints(range, 0);
} }
} }
@ -1424,7 +1420,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
System.out.println(BeanInspector.toString(indy.getData(partVelKey))); System.out.println(BeanInspector.toString(indy.getData(partVelKey)));
} }
} }
if (this.m_Show) { if (this.show) {
this.show(); this.show();
} }
sortedPop = null;// to make sure that the last sorted version is not reused sortedPop = null;// to make sure that the last sorted version is not reused
@ -1434,11 +1430,11 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
* Log the best individual so far. * Log the best individual so far.
*/ */
protected void logBestIndividual() { protected void logBestIndividual() {
if (this.population.getBestEAIndividual().isDominatingDebConstraints(this.m_BestIndividual)) { if (this.population.getBestEAIndividual().isDominatingDebConstraints(this.bestIndividual)) {
this.m_BestIndividual = (AbstractEAIndividual) this.population.getBestEAIndividual().clone(); this.bestIndividual = (AbstractEAIndividual) this.population.getBestEAIndividual().clone();
this.m_BestIndividual.putData(partBestFitKey, this.m_BestIndividual.getFitness().clone()); this.bestIndividual.putData(partBestFitKey, this.bestIndividual.getFitness().clone());
this.m_BestIndividual.putData(partBestPosKey, ((InterfaceDataTypeDouble) this.m_BestIndividual).getDoubleData()); this.bestIndividual.putData(partBestPosKey, ((InterfaceDataTypeDouble) this.bestIndividual).getDoubleData());
// System.out.println("new best: "+m_BestIndividual.toString()); // System.out.println("new best: "+bestIndividual.toString());
} }
} }
@ -1453,8 +1449,8 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
this.updateIndividual(i, (AbstractEAIndividual) population.get(i), this.population); this.updateIndividual(i, (AbstractEAIndividual) population.get(i), this.population);
} }
if (m_Show) { if (show) {
if (this.m_Problem instanceof Interface2DBorderProblem) { if (this.optimizationProblem instanceof Interface2DBorderProblem) {
DPointSet popRep = new DPointSet(); DPointSet popRep = new DPointSet();
InterfaceDataTypeDouble tmpIndy1; InterfaceDataTypeDouble tmpIndy1;
@ -1464,7 +1460,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
if (topoPlot == null) { if (topoPlot == null) {
this.topoPlot = new TopoPlot("CBN-Species", "x", "y", a, a); this.topoPlot = new TopoPlot("CBN-Species", "x", "y", a, a);
this.topoPlot.setParams(60, 60); this.topoPlot.setParams(60, 60);
this.topoPlot.setTopology((Interface2DBorderProblem) this.m_Problem); this.topoPlot.setTopology((Interface2DBorderProblem) this.optimizationProblem);
} }
for (int i = 0; i < this.population.size(); i++) { for (int i = 0; i < this.population.size(); i++) {
@ -1487,8 +1483,6 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
} }
protected void updateTopology(Population pop) { protected void updateTopology(Population pop) {
// int topoID = this.m_Topology.getSelectedTag().getID();
// this.m_Topology = new SelectedTag( "Linear", "Grid", "Star", "Multi-Swarm", "Tree", "HPSO", "Random" );
if (topology == PSOTopologyEnum.dms) { // Dynamic multi-swarm after Liang & Suganthan if (topology == PSOTopologyEnum.dms) { // Dynamic multi-swarm after Liang & Suganthan
if (pop.getGeneration() % getDmsRegroupGens() == 0) { if (pop.getGeneration() % getDmsRegroupGens() == 0) {
dmsLinks = regroupSwarm(pop, getTopologyRange()); dmsLinks = regroupSwarm(pop, getTopologyRange());
@ -1650,12 +1644,12 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
* This method is simply for debugging. * This method is simply for debugging.
*/ */
protected void show() { protected void show() {
if (this.m_Plot == null) { if (this.plot == null) {
InterfaceDataTypeDouble indy = (InterfaceDataTypeDouble) this.population.get(0); InterfaceDataTypeDouble indy = (InterfaceDataTypeDouble) this.population.get(0);
double[][] range = indy.getDoubleRange(); double[][] range = indy.getDoubleRange();
this.m_Plot = new Plot("PSO " + population.getGeneration(), "x1", "x2", range[0], range[1]); this.plot = new Plot("PSO " + population.getGeneration(), "x1", "x2", range[0], range[1]);
// this.m_Plot.setUnconnectedPoint(range[0][0], range[1][0], 0); // this.plot.setUnconnectedPoint(range[0][0], range[1][0], 0);
// this.m_Plot.setUnconnectedPoint(range[0][1], range[1][1], 0); // this.plot.setUnconnectedPoint(range[0][1], range[1][1], 0);
} }
} }
@ -1702,12 +1696,12 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
*/ */
@Override @Override
public void setProblem(InterfaceOptimizationProblem problem) { public void setProblem(InterfaceOptimizationProblem problem) {
this.m_Problem = problem; this.optimizationProblem = problem;
} }
@Override @Override
public InterfaceOptimizationProblem getProblem() { public InterfaceOptimizationProblem getProblem() {
return this.m_Problem; return this.optimizationProblem;
} }
/** /**
@ -1721,7 +1715,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
String result = ""; String result = "";
result += "Particle Swarm Optimization:\n"; result += "Particle Swarm Optimization:\n";
result += "Optimization Problem: "; result += "Optimization Problem: ";
result += this.m_Problem.getStringRepresentationForProblem(this) + "\n"; result += this.optimizationProblem.getStringRepresentationForProblem(this) + "\n";
result += this.population.getStringRepresentation(); result += this.population.getStringRepresentation();
return result; return result;
} }
@ -1733,12 +1727,12 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
*/ */
@Override @Override
public void setIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.indentifier = name;
} }
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return this.m_Identifier; return this.indentifier;
} }
/** /**
@ -1779,7 +1773,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
} }
} }
} }
m_BestIndividual = pop.getBestEAIndividual(); bestIndividual = pop.getBestEAIndividual();
} }
public String populationTipText() { public String populationTipText() {
@ -1792,7 +1786,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
} }
public AbstractEAIndividual getBestIndividual() { public AbstractEAIndividual getBestIndividual() {
return m_BestIndividual; return bestIndividual;
} }
/** /**
@ -1970,7 +1964,6 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
} }
public void setGOEShowProperties(Class<?> cls) { public void setGOEShowProperties(Class<?> cls) {
// this.m_Topology = new SelectedTag( "Linear", "Grid", "Star", "Multi-Swarm", "Tree", "HPSO", "Random" );
// linear, grid, random // linear, grid, random
GenericObjectEditor.setShowProperty(cls, "topologyRange", (topology == PSOTopologyEnum.linear) || (topology == PSOTopologyEnum.grid) || (topology == PSOTopologyEnum.random) || (topology == PSOTopologyEnum.tree) || (topology == PSOTopologyEnum.hpso) || (topology == PSOTopologyEnum.dms)); GenericObjectEditor.setShowProperty(cls, "topologyRange", (topology == PSOTopologyEnum.linear) || (topology == PSOTopologyEnum.grid) || (topology == PSOTopologyEnum.random) || (topology == PSOTopologyEnum.tree) || (topology == PSOTopologyEnum.hpso) || (topology == PSOTopologyEnum.dms));
@ -2054,16 +2047,16 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
* @return true if swarm visualization is turned on * @return true if swarm visualization is turned on
*/ */
public boolean isShow() { public boolean isShow() {
return m_Show; return show;
} }
/** /**
* @param set swarm visualization (2D) * @param set swarm visualization (2D)
*/ */
public void setShow(boolean show) { public void setShow(boolean show) {
m_Show = show; this.show = show;
if (!show) { if (!show) {
m_Plot = null; plot = null;
} }
} }
@ -2215,9 +2208,9 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
double relDiff; double relDiff;
if (personalBestfit[0] != 0) { if (personalBestfit[0] != 0) {
relDiff = (personalBestfit[0] - ((InterfaceProblemDouble) m_Problem).evaluate(personalBestPos)[0]) / personalBestfit[0]; relDiff = (personalBestfit[0] - ((InterfaceProblemDouble) optimizationProblem).evaluate(personalBestPos)[0]) / personalBestfit[0];
} else { } else {
relDiff = (personalBestfit[0] - ((InterfaceProblemDouble) m_Problem).evaluate(personalBestPos)[0]); // absolute diff in this case relDiff = (personalBestfit[0] - ((InterfaceProblemDouble) optimizationProblem).evaluate(personalBestPos)[0]); // absolute diff in this case
}// if (personalBestfit[0]!=((InterfaceProblemDouble)problem).evaluate(personalBestPos)[0]) { }// if (personalBestfit[0]!=((InterfaceProblemDouble)problem).evaluate(personalBestPos)[0]) {
if (Math.abs(relDiff) > 1e-20) { if (Math.abs(relDiff) > 1e-20) {
System.err.println("Warning: mismatching best fitness by " + relDiff); System.err.println("Warning: mismatching best fitness by " + relDiff);
@ -2225,7 +2218,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
} }
if (Math.abs(relDiff) > 1e-10) { if (Math.abs(relDiff) > 1e-10) {
System.err.println("partInfo: " + i + " - " + getParticleInfo(population.getEAIndividual(i))); System.err.println("partInfo: " + i + " - " + getParticleInfo(population.getEAIndividual(i)));
throw new RuntimeException("Mismatching best fitness!! " + personalBestfit[0] + " vs. " + ((InterfaceProblemDouble) m_Problem).evaluate(personalBestPos)[0]); throw new RuntimeException("Mismatching best fitness!! " + personalBestfit[0] + " vs. " + ((InterfaceProblemDouble) optimizationProblem).evaluate(personalBestPos)[0]);
} }
((InterfaceDataTypeDouble) indy).setDoubleGenotype(personalBestPos); ((InterfaceDataTypeDouble) indy).setDoubleGenotype(personalBestPos);
indy.setFitness(personalBestfit); indy.setFitness(personalBestfit);

View File

@ -28,30 +28,30 @@ import eva2.util.annotation.Description;
public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, java.io.Serializable { public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, java.io.Serializable {
// These variables are necessary for the simple testcase // These variables are necessary for the simple testcase
private InterfaceOptimizationProblem m_Problem = new B1Problem(); private InterfaceOptimizationProblem optimizationProblem = new B1Problem();
private boolean m_UseElitism = true; private boolean useElitism = true;
private InterfaceSelection m_SelectionOperator = new SelectBestIndividuals(); private InterfaceSelection selectionOperator = new SelectBestIndividuals();
transient private String m_Identifier = ""; transient private String identifier = "";
transient private InterfacePopulationChangedEventListener m_Listener; transient private InterfacePopulationChangedEventListener populationChangedEventListener;
private Population m_Population = new PBILPopulation(); private Population population = new PBILPopulation();
private double m_LearningRate = 0.04; private double learningRate = 0.04;
private double m_MutationRate = 0.5; private double mutationRate = 0.5;
private double m_MutateSigma = 0.01; private double mutateSigma = 0.01;
private int m_NumberOfPositiveSamples = 1; private int numberOfPositiveSamples = 1;
private double[] m_initialProbabilities = ((PBILPopulation) m_Population).getProbabilityVector(); private double[] initialProbabilities = ((PBILPopulation) population).getProbabilityVector();
public PopulationBasedIncrementalLearning() { public PopulationBasedIncrementalLearning() {
} }
public PopulationBasedIncrementalLearning(PopulationBasedIncrementalLearning a) { public PopulationBasedIncrementalLearning(PopulationBasedIncrementalLearning a) {
this.m_Population = (Population) a.m_Population.clone(); this.population = (Population) a.population.clone();
this.m_Problem = (InterfaceOptimizationProblem) a.m_Problem.clone(); this.optimizationProblem = (InterfaceOptimizationProblem) a.optimizationProblem.clone();
this.m_LearningRate = a.m_LearningRate; this.learningRate = a.learningRate;
this.m_MutationRate = a.m_MutationRate; this.mutationRate = a.mutationRate;
this.m_MutateSigma = a.m_MutateSigma; this.mutateSigma = a.mutateSigma;
this.m_NumberOfPositiveSamples = a.m_NumberOfPositiveSamples; this.numberOfPositiveSamples = a.numberOfPositiveSamples;
this.m_UseElitism = a.m_UseElitism; this.useElitism = a.useElitism;
this.m_SelectionOperator = (InterfaceSelection) a.m_SelectionOperator.clone(); this.selectionOperator = (InterfaceSelection) a.selectionOperator.clone();
} }
@Override @Override
@ -61,15 +61,15 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
@Override @Override
public void init() { public void init() {
this.m_Problem.initializePopulation(this.m_Population); this.optimizationProblem.initializePopulation(this.population);
if ((m_initialProbabilities != null) && (m_initialProbabilities.length == ((PBILPopulation) m_Population).getProbabilityVector().length)) { if ((initialProbabilities != null) && (initialProbabilities.length == ((PBILPopulation) population).getProbabilityVector().length)) {
((PBILPopulation) m_Population).setProbabilityVector(m_initialProbabilities); ((PBILPopulation) population).setProbabilityVector(initialProbabilities);
} else { } else {
if (m_initialProbabilities != null) { if (initialProbabilities != null) {
System.err.println("Warning: initial probability vector doesnt match in length!"); System.err.println("Warning: initial probability vector doesnt match in length!");
} }
} }
this.evaluatePopulation(this.m_Population); this.evaluatePopulation(this.population);
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
} }
@ -84,13 +84,13 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
if (!(pop.getEAIndividual(0) instanceof InterfaceGAIndividual)) { if (!(pop.getEAIndividual(0) instanceof InterfaceGAIndividual)) {
System.err.println("Error: PBIL only works with GAIndividuals!"); System.err.println("Error: PBIL only works with GAIndividuals!");
} }
this.m_Population = new PBILPopulation(); this.population = new PBILPopulation();
this.m_Population.addPopulation((Population) pop.clone()); this.population.addPopulation((Population) pop.clone());
if (reset) { if (reset) {
this.m_Population.init(); this.population.init();
this.evaluatePopulation(this.m_Population); this.evaluatePopulation(this.population);
} }
((PBILPopulation) this.m_Population).buildProbabilityVector(); ((PBILPopulation) this.population).buildProbabilityVector();
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
} }
@ -100,7 +100,7 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
* @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.optimizationProblem.evaluate(population);
population.incrGeneration(); population.incrGeneration();
} }
@ -109,16 +109,14 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
* population of evaluated individuals. * population of evaluated individuals.
*/ */
private Population generateChildren() { private Population generateChildren() {
PBILPopulation result = (PBILPopulation) this.m_Population.clone(); PBILPopulation result = (PBILPopulation) this.population.clone();
Population examples; Population examples;
// this.m_NormationOperator.computeSelectionProbability(this.population, "Fitness");
//System.out.println("Population:"+this.population.getSolutionRepresentationFor()); this.selectionOperator.prepareSelection(this.population);
this.m_SelectionOperator.prepareSelection(this.m_Population); examples = this.selectionOperator.selectFrom(this.population, this.numberOfPositiveSamples);
examples = this.m_SelectionOperator.selectFrom(this.m_Population, this.m_NumberOfPositiveSamples); result.learnFrom(examples, this.learningRate);
//System.out.println("Parents:"+parents.getSolutionRepresentationFor()); result.mutateProbabilityVector(this.mutationRate, this.mutateSigma);
result.learnFrom(examples, this.m_LearningRate);
result.mutateProbabilityVector(this.m_MutationRate, this.m_MutateSigma);
result.initPBIL(); result.initPBIL();
return result; return result;
} }
@ -130,12 +128,12 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
nextGeneration = this.generateChildren(); nextGeneration = this.generateChildren();
this.evaluatePopulation(nextGeneration); this.evaluatePopulation(nextGeneration);
if (this.m_UseElitism) { if (this.useElitism) {
elite = this.m_Population.getBestEAIndividual(); elite = this.population.getBestEAIndividual();
this.m_Population = nextGeneration; this.population = nextGeneration;
this.m_Population.add(0, elite); this.population.add(0, elite);
} else { } else {
this.m_Population = nextGeneration; this.population = nextGeneration;
} }
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
} }
@ -147,9 +145,9 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
*/ */
@Override @Override
public void setProblem(InterfaceOptimizationProblem problem) { public void setProblem(InterfaceOptimizationProblem problem) {
this.m_Problem = problem; this.optimizationProblem = problem;
if (m_Problem instanceof AbstractOptimizationProblem) { if (optimizationProblem instanceof AbstractOptimizationProblem) {
if (!(((AbstractOptimizationProblem) m_Problem).getIndividualTemplate() instanceof InterfaceGAIndividual)) { if (!(((AbstractOptimizationProblem) optimizationProblem).getIndividualTemplate() instanceof InterfaceGAIndividual)) {
System.err.println("Error: PBIL only works with GAIndividuals!"); System.err.println("Error: PBIL only works with GAIndividuals!");
} }
} }
@ -157,19 +155,19 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
@Override @Override
public InterfaceOptimizationProblem getProblem() { public InterfaceOptimizationProblem getProblem() {
return this.m_Problem; return this.optimizationProblem;
} }
@Override @Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) { public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea; this.populationChangedEventListener = ea;
} }
@Override @Override
public boolean removePopulationChangedEventListener( public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
if (m_Listener == ea) { if (populationChangedEventListener == ea) {
m_Listener = null; populationChangedEventListener = null;
return true; return true;
} else { } else {
return false; return false;
@ -180,8 +178,8 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
* Something has changed * Something has changed
*/ */
protected void firePropertyChangedEvent(String name) { protected void firePropertyChangedEvent(String name) {
if (this.m_Listener != null) { if (this.populationChangedEventListener != null) {
this.m_Listener.registerPopulationStateChanged(this, name); this.populationChangedEventListener.registerPopulationStateChanged(this, name);
} }
} }
@ -196,8 +194,8 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
String result = ""; String result = "";
result += "Population Based Incremental Learning:\n"; result += "Population Based Incremental Learning:\n";
result += "Optimization Problem: "; result += "Optimization Problem: ";
result += this.m_Problem.getStringRepresentationForProblem(this) + "\n"; result += this.optimizationProblem.getStringRepresentationForProblem(this) + "\n";
result += this.m_Population.getStringRepresentation(); result += this.population.getStringRepresentation();
return result; return result;
} }
@ -208,12 +206,12 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
*/ */
@Override @Override
public void setIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.identifier = name;
} }
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return this.m_Identifier; return this.identifier;
} }
/** /**
@ -235,12 +233,12 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
*/ */
@Override @Override
public Population getPopulation() { public Population getPopulation() {
return this.m_Population; return this.population;
} }
@Override @Override
public void setPopulation(Population pop) { public void setPopulation(Population pop) {
this.m_Population = pop; this.population = pop;
} }
public String populationTipText() { public String populationTipText() {
@ -251,18 +249,6 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
public InterfaceSolutionSet getAllSolutions() { public InterfaceSolutionSet getAllSolutions() {
return new SolutionSet(getPopulation()); return new SolutionSet(getPopulation());
} }
// /** This method will set the normation method that is to be used.
// * @param normation
// */
// public void setNormationMethod (InterfaceNormation normation) {
// this.m_NormationOperator = normation;
// }
// public InterfaceNormation getNormationMethod () {
// return this.m_NormationOperator;
// }
// public String normationMethodTipText() {
// return "Select the normation method.";
// }
/** /**
* This method will set the selection method that is to be used * This method will set the selection method that is to be used
@ -270,11 +256,11 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
* @param selection * @param selection
*/ */
public void setSelectionMethod(InterfaceSelection selection) { public void setSelectionMethod(InterfaceSelection selection) {
this.m_SelectionOperator = selection; this.selectionOperator = selection;
} }
public InterfaceSelection getSelectionMethod() { public InterfaceSelection getSelectionMethod() {
return this.m_SelectionOperator; return this.selectionOperator;
} }
public String selectionMethodTipText() { public String selectionMethodTipText() {
@ -287,11 +273,11 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
* @param elitism * @param elitism
*/ */
public void setElitism(boolean elitism) { public void setElitism(boolean elitism) {
this.m_UseElitism = elitism; this.useElitism = elitism;
} }
public boolean getElitism() { public boolean getElitism() {
return this.m_UseElitism; return this.useElitism;
} }
public String elitismTipText() { public String elitismTipText() {
@ -304,14 +290,14 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
* @param LearningRate * @param LearningRate
*/ */
public void setLearningRate(double LearningRate) { public void setLearningRate(double LearningRate) {
this.m_LearningRate = LearningRate; this.learningRate = LearningRate;
if (this.m_LearningRate < 0) { if (this.learningRate < 0) {
this.m_LearningRate = 0; this.learningRate = 0;
} }
} }
public double getLearningRate() { public double getLearningRate() {
return this.m_LearningRate; return this.learningRate;
} }
public String learningRateTipText() { public String learningRateTipText() {
@ -324,17 +310,17 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
* @param m * @param m
*/ */
public void setMutationRate(double m) { public void setMutationRate(double m) {
this.m_MutationRate = m; this.mutationRate = m;
if (this.m_MutationRate < 0) { if (this.mutationRate < 0) {
this.m_MutationRate = 0; this.mutationRate = 0;
} }
if (this.m_MutationRate > 1) { if (this.mutationRate > 1) {
this.m_MutationRate = 1; this.mutationRate = 1;
} }
} }
public double getMutationRate() { public double getMutationRate() {
return this.m_MutationRate; return this.mutationRate;
} }
public String mutationRateTipText() { public String mutationRateTipText() {
@ -347,14 +333,14 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
* @param m * @param m
*/ */
public void setMutateSigma(double m) { public void setMutateSigma(double m) {
this.m_MutateSigma = m; this.mutateSigma = m;
if (this.m_MutateSigma < 0) { if (this.mutateSigma < 0) {
this.m_MutateSigma = 0; this.mutateSigma = 0;
} }
} }
public double getMutateSigma() { public double getMutateSigma() {
return this.m_MutateSigma; return this.mutateSigma;
} }
public String mutateSigmaTipText() { public String mutateSigmaTipText() {
@ -367,14 +353,14 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
* @param PositiveSamples * @param PositiveSamples
*/ */
public void setPositiveSamples(int PositiveSamples) { public void setPositiveSamples(int PositiveSamples) {
this.m_NumberOfPositiveSamples = PositiveSamples; this.numberOfPositiveSamples = PositiveSamples;
if (this.m_NumberOfPositiveSamples < 1) { if (this.numberOfPositiveSamples < 1) {
this.m_NumberOfPositiveSamples = 1; this.numberOfPositiveSamples = 1;
} }
} }
public int getPositiveSamples() { public int getPositiveSamples() {
return this.m_NumberOfPositiveSamples; return this.numberOfPositiveSamples;
} }
public String positiveSamplesTipText() { public String positiveSamplesTipText() {
@ -382,10 +368,10 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
} }
public double[] getInitialProbabilities() { public double[] getInitialProbabilities() {
return m_initialProbabilities; return initialProbabilities;
} }
public void setInitialProbabilities(double[] probabilities) { public void setInitialProbabilities(double[] probabilities) {
m_initialProbabilities = probabilities; initialProbabilities = probabilities;
} }
} }

View File

@ -44,9 +44,9 @@ import java.util.ArrayList;
@Description("A scatter search variant after Rodiguez-Fernandez, J.Egea and J.Banga: Novel metaheuristic for parameter estimation in nonlinear dynamic biological systems, BMC Bioinf. 2006") @Description("A scatter search variant after Rodiguez-Fernandez, J.Egea and J.Banga: Novel metaheuristic for parameter estimation in nonlinear dynamic biological systems, BMC Bioinf. 2006")
public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable, InterfacePopulationChangedEventListener { public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable, InterfacePopulationChangedEventListener {
transient private InterfacePopulationChangedEventListener m_Listener = null; transient private InterfacePopulationChangedEventListener listener = null;
private String m_Identifier = "ScatterSearch"; private String identifier = "ScatterSearch";
private AbstractOptimizationProblem problem = new F1Problem(); private AbstractOptimizationProblem optimizationProblem = new F1Problem();
private Population oldRefSet, refSet = new Population(10); private Population oldRefSet, refSet = new Population(10);
private transient Population combinations = null; private transient Population combinations = null;
private AbstractEAIndividual template = null; private AbstractEAIndividual template = null;
@ -79,7 +79,7 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
public ScatterSearch(ScatterSearch o) { public ScatterSearch(ScatterSearch o) {
this.refSet = (Population) o.refSet.clone(); this.refSet = (Population) o.refSet.clone();
this.problem = (AbstractOptimizationProblem) o.problem.clone(); this.optimizationProblem = (AbstractOptimizationProblem) o.optimizationProblem.clone();
this.template = (AbstractEAIndividual) o.template.clone(); this.template = (AbstractEAIndividual) o.template.clone();
this.range = ((InterfaceDataTypeDouble) template).getDoubleRange(); this.range = ((InterfaceDataTypeDouble) template).getDoubleRange();
this.refSetSize = o.refSetSize; this.refSetSize = o.refSetSize;
@ -104,7 +104,7 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
@Override @Override
public void setProblem(InterfaceOptimizationProblem problem) { public void setProblem(InterfaceOptimizationProblem problem) {
this.problem = (AbstractOptimizationProblem) problem; this.optimizationProblem = (AbstractOptimizationProblem) problem;
} }
@Override @Override
@ -136,7 +136,7 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
* @param pop * @param pop
*/ */
private void initRefSet(Population pop) { private void initRefSet(Population pop) {
problem.evaluate(pop); optimizationProblem.evaluate(pop);
if (TRACE) { if (TRACE) {
System.out.println("building ref set from pop with avg dist " + pop.getPopulationMeasures()[0]); System.out.println("building ref set from pop with avg dist " + pop.getPopulationMeasures()[0]);
} }
@ -156,11 +156,11 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
firstTime = true; firstTime = true;
refSet = null; refSet = null;
combinations = null; combinations = null;
template = problem.getIndividualTemplate(); template = optimizationProblem.getIndividualTemplate();
if (!(template instanceof InterfaceDataTypeDouble)) { if (!(template instanceof InterfaceDataTypeDouble)) {
System.err.println("Requiring double data!"); System.err.println("Requiring double data!");
} else { } else {
Object dim = BeanInspector.callIfAvailable(problem, "getProblemDimension", null); Object dim = BeanInspector.callIfAvailable(optimizationProblem, "getProblemDimension", null);
if (dim == null) { if (dim == null) {
System.err.println("Couldnt get problem dimension!"); System.err.println("Couldnt get problem dimension!");
} }
@ -176,15 +176,15 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
* Something has changed * Something has changed
*/ */
protected void firePropertyChangedEvent(String name) { protected void firePropertyChangedEvent(String name) {
if (this.m_Listener != null) { if (this.listener != null) {
this.m_Listener.registerPopulationStateChanged(this, name); this.listener.registerPopulationStateChanged(this, name);
} }
} }
// public double evaluate(double[] x) { // public double evaluate(double[] x) {
// AbstractEAIndividual indy = (AbstractEAIndividual)template.clone(); // AbstractEAIndividual indy = (AbstractEAIndividual)template.clone();
// ((InterfaceDataTypeDouble)indy).setDoubleGenotype(x); // ((InterfaceDataTypeDouble)indy).setDoubleGenotype(x);
// problem.evaluate(indy); // optimizationProblem.evaluate(indy);
// return indy.getFitness(0); // return indy.getFitness(0);
// } // }
@Override @Override
@ -224,7 +224,7 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
} }
firstTime = false; firstTime = false;
problem.evaluatePopulationStart(refSet); optimizationProblem.evaluatePopulationStart(refSet);
int funCallsStart = refSet.getFunctionCalls(); int funCallsStart = refSet.getFunctionCalls();
do { do {
if (combinations == null || combinations.size() == 0) { if (combinations == null || combinations.size() == 0) {
@ -243,7 +243,7 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
updateRefSet(refSet, combinations, oldRefSet); updateRefSet(refSet, combinations, oldRefSet);
} }
} while (refSet.getFunctionCalls() - funCallsStart < generationCycle); } while (refSet.getFunctionCalls() - funCallsStart < generationCycle);
problem.evaluatePopulationEnd(refSet); optimizationProblem.evaluatePopulationEnd(refSet);
if (TRACE) { if (TRACE) {
System.out.println("Improvements: " + lastImprovementCount); System.out.println("Improvements: " + lastImprovementCount);
@ -302,7 +302,7 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
} }
AbstractEAIndividual winner = diversifiedPop.getEAIndividual(sel); AbstractEAIndividual winner = diversifiedPop.getEAIndividual(sel);
// evaluate the new indy // evaluate the new indy
problem.evaluate(winner); optimizationProblem.evaluate(winner);
// add it to the newRefSet, increase h // add it to the newRefSet, increase h
newRefSet.add(winner); newRefSet.add(winner);
newRefSet.incrFunctionCalls(); newRefSet.incrFunctionCalls();
@ -416,7 +416,7 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
if (localSearchMethod.getSelectedTagID() == 0) { if (localSearchMethod.getSelectedTagID() == 0) {
return localSolverHC(cand, hcSteps); return localSolverHC(cand, hcSteps);
} else { } else {
return PostProcess.localSolverNMS(cand, hcSteps, nelderMeadInitPerturbation, problem); return PostProcess.localSolverNMS(cand, hcSteps, nelderMeadInitPerturbation, optimizationProblem);
} }
} }
@ -425,7 +425,7 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
// double[] fitBefore = cand.getFitness(); // double[] fitBefore = cand.getFitness();
Population hcPop = new Population(1); Population hcPop = new Population(1);
hcPop.add(cand); hcPop.add(cand);
int stepsDone = PostProcess.processWithHC(hcPop, problem, hcSteps); int stepsDone = PostProcess.processWithHC(hcPop, optimizationProblem, hcSteps);
return new Pair<AbstractEAIndividual, Integer>(hcPop.getEAIndividual(0), stepsDone); return new Pair<AbstractEAIndividual, Integer>(hcPop.getEAIndividual(0), stepsDone);
} }
@ -548,7 +548,7 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
Mathematics.projectToRange(combi, range); Mathematics.projectToRange(combi, range);
} }
((InterfaceDataTypeDouble) resIndy).setDoubleGenotype(combi); ((InterfaceDataTypeDouble) resIndy).setDoubleGenotype(combi);
problem.evaluate(resIndy); optimizationProblem.evaluate(resIndy);
refSet.incrFunctionCalls(); refSet.incrFunctionCalls();
return resIndy; return resIndy;
} }
@ -735,12 +735,12 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
///////////// Trivials... ///////////// Trivials...
@Override @Override
public void setIdentifier(String name) { public void setIdentifier(String name) {
m_Identifier = name; identifier = name;
} }
@Override @Override
public InterfaceOptimizationProblem getProblem() { public InterfaceOptimizationProblem getProblem() {
return problem; return optimizationProblem;
} }
@Override @Override
@ -751,14 +751,14 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
@Override @Override
public void addPopulationChangedEventListener( public void addPopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
m_Listener = ea; listener = ea;
} }
@Override @Override
public boolean removePopulationChangedEventListener( public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
if (m_Listener == ea) { if (listener == ea) {
m_Listener = null; listener = null;
return true; return true;
} else { } else {
return false; return false;
@ -767,7 +767,7 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return m_Identifier; return identifier;
} }
@Override @Override
@ -872,7 +872,7 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
InterfaceTerminator term, String dataPrefix, InterfaceTerminator term, String dataPrefix,
AbstractOptimizationProblem problem, InterfacePopulationChangedEventListener listener) { AbstractOptimizationProblem problem, InterfacePopulationChangedEventListener listener) {
// problem.initializeProblem(); // optimizationProblem.initializeProblem();
OptimizationParameters params = specialSS(localSearchSteps, localSearchFitnessFilter, nmInitPerturb, relativeFitCrit, refSetSize, problem, term); OptimizationParameters params = specialSS(localSearchSteps, localSearchFitnessFilter, nmInitPerturb, relativeFitCrit, refSetSize, problem, term);

View File

@ -21,29 +21,29 @@ import eva2.util.annotation.Description;
public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializable { public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializable {
// These variables are necessary for the simple testcase // These variables are necessary for the simple testcase
private InterfaceOptimizationProblem m_Problem = new B1Problem(); private InterfaceOptimizationProblem optimizationProblem = new B1Problem();
private int m_MultiRuns = 100; private int multiRuns = 100;
private int m_FitnessCalls = 100; private int fitnessCalls = 100;
private int m_FitnessCallsNeeded = 0; private int fitnessCallsNeeded = 0;
GAIndividualBinaryData m_Best, m_Test; GAIndividualBinaryData bestIndividual, testIndividual;
public double m_InitialTemperature = 2, m_CurrentTemperature; public double initialTemperature = 2, currentTemperature;
public double m_Alpha = 0.9; public double alpha = 0.9;
// These variables are necessary for the more complex LectureGUI enviroment // These variables are necessary for the more complex LectureGUI enviroment
transient private String m_Identifier = ""; transient private String identifier = "";
transient private InterfacePopulationChangedEventListener m_Listener; transient private InterfacePopulationChangedEventListener populationChangedEventListener;
private Population m_Population; private Population population;
public SimulatedAnnealing() { public SimulatedAnnealing() {
this.m_Population = new Population(); this.population = new Population();
this.m_Population.setTargetSize(10); this.population.setTargetSize(10);
} }
public SimulatedAnnealing(SimulatedAnnealing a) { public SimulatedAnnealing(SimulatedAnnealing a) {
this.m_Population = (Population) a.m_Population.clone(); this.population = (Population) a.population.clone();
this.m_Problem = (InterfaceOptimizationProblem) a.m_Problem.clone(); this.optimizationProblem = (InterfaceOptimizationProblem) a.optimizationProblem.clone();
this.m_InitialTemperature = a.m_InitialTemperature; this.initialTemperature = a.initialTemperature;
this.m_CurrentTemperature = a.m_CurrentTemperature; this.currentTemperature = a.currentTemperature;
this.m_Alpha = a.m_Alpha; this.alpha = a.alpha;
} }
@Override @Override
@ -56,9 +56,9 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
*/ */
@Override @Override
public void init() { public void init() {
this.m_Problem.initializePopulation(this.m_Population); this.optimizationProblem.initializePopulation(this.population);
this.m_Problem.evaluate(this.m_Population); this.optimizationProblem.evaluate(this.population);
this.m_CurrentTemperature = this.m_InitialTemperature; this.currentTemperature = this.initialTemperature;
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
} }
@ -70,11 +70,11 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
*/ */
@Override @Override
public void initByPopulation(Population pop, boolean reset) { public void initByPopulation(Population pop, boolean reset) {
this.m_Population = (Population) pop.clone(); this.population = (Population) pop.clone();
this.m_CurrentTemperature = this.m_InitialTemperature; this.currentTemperature = this.initialTemperature;
if (reset) { if (reset) {
this.m_Population.init(); this.population.init();
this.m_Problem.evaluate(this.m_Population); this.optimizationProblem.evaluate(this.population);
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
} }
} }
@ -85,32 +85,32 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
@Override @Override
public void optimize() { public void optimize() {
AbstractEAIndividual indy; AbstractEAIndividual indy;
Population original = (Population) this.m_Population.clone(); Population original = (Population) this.population.clone();
double delta; double delta;
for (int i = 0; i < this.m_Population.size(); i++) { for (int i = 0; i < this.population.size(); i++) {
indy = ((AbstractEAIndividual) this.m_Population.get(i)); indy = ((AbstractEAIndividual) this.population.get(i));
double tmpD = indy.getMutationProbability(); double tmpD = indy.getMutationProbability();
indy.setMutationProbability(1.0); indy.setMutationProbability(1.0);
indy.mutate(); indy.mutate();
indy.setMutationProbability(tmpD); indy.setMutationProbability(tmpD);
} }
this.m_Problem.evaluate(this.m_Population); this.optimizationProblem.evaluate(this.population);
for (int i = 0; i < this.m_Population.size(); i++) { for (int i = 0; i < this.population.size(); i++) {
if (((AbstractEAIndividual) original.get(i)).isDominatingDebConstraints(((AbstractEAIndividual) this.m_Population.get(i)))) { if (((AbstractEAIndividual) original.get(i)).isDominatingDebConstraints(((AbstractEAIndividual) this.population.get(i)))) {
this.m_Population.remove(i); this.population.remove(i);
this.m_Population.add(i, original.get(i)); this.population.add(i, original.get(i));
} else { } else {
delta = this.calculateDelta(((AbstractEAIndividual) original.get(i)), ((AbstractEAIndividual) this.m_Population.get(i))); delta = this.calculateDelta(((AbstractEAIndividual) original.get(i)), ((AbstractEAIndividual) this.population.get(i)));
//System.out.println("delta: " + delta); //System.out.println("delta: " + delta);
if (Math.exp(-delta / this.m_CurrentTemperature) > RNG.randomInt(0, 1)) { if (Math.exp(-delta / this.currentTemperature) > RNG.randomInt(0, 1)) {
this.m_Population.remove(i); this.population.remove(i);
this.m_Population.add(i, original.get(i)); this.population.add(i, original.get(i));
} }
} }
} }
this.m_CurrentTemperature = this.m_Alpha * this.m_CurrentTemperature; this.currentTemperature = this.alpha * this.currentTemperature;
this.m_Population.incrGeneration(); this.population.incrGeneration();
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
} }
@ -138,36 +138,36 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
*/ */
@Override @Override
public void setProblem(InterfaceOptimizationProblem problem) { public void setProblem(InterfaceOptimizationProblem problem) {
this.m_Problem = problem; this.optimizationProblem = problem;
} }
@Override @Override
public InterfaceOptimizationProblem getProblem() { public InterfaceOptimizationProblem getProblem() {
return this.m_Problem; return this.optimizationProblem;
} }
/** /**
* This method will init the HillClimber * This method will init the HillClimber
*/ */
public void defaultInit() { public void defaultInit() {
this.m_FitnessCallsNeeded = 0; this.fitnessCallsNeeded = 0;
this.m_Best = new GAIndividualBinaryData(); this.bestIndividual = new GAIndividualBinaryData();
this.m_Best.defaultInit(m_Problem); this.bestIndividual.defaultInit(optimizationProblem);
} }
/** /**
* This method will optimize * This method will optimize
*/ */
public void defaultOptimize() { public void defaultOptimize() {
for (int i = 0; i < m_FitnessCalls; i++) { for (int i = 0; i < fitnessCalls; i++) {
this.m_Test = (GAIndividualBinaryData) ((this.m_Best).clone()); this.testIndividual = (GAIndividualBinaryData) ((this.bestIndividual).clone());
this.m_Test.defaultMutate(); this.testIndividual.defaultMutate();
if (this.m_Test.defaultEvaulateAsMiniBits() < this.m_Best.defaultEvaulateAsMiniBits()) { if (this.testIndividual.defaultEvaulateAsMiniBits() < this.bestIndividual.defaultEvaulateAsMiniBits()) {
this.m_Best = this.m_Test; this.bestIndividual = this.testIndividual;
} }
this.m_FitnessCallsNeeded = i; this.fitnessCallsNeeded = i;
if (this.m_Best.defaultEvaulateAsMiniBits() == 0) { if (this.bestIndividual.defaultEvaulateAsMiniBits() == 0) {
i = this.m_FitnessCalls + 1; i = this.fitnessCalls + 1;
} }
} }
} }
@ -180,27 +180,27 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
public static void main(String[] args) { public static void main(String[] args) {
SimulatedAnnealing program = new SimulatedAnnealing(); SimulatedAnnealing program = new SimulatedAnnealing();
int TmpMeanCalls = 0, TmpMeanFitness = 0; int TmpMeanCalls = 0, TmpMeanFitness = 0;
for (int i = 0; i < program.m_MultiRuns; i++) { for (int i = 0; i < program.multiRuns; i++) {
program.defaultInit(); program.defaultInit();
program.defaultOptimize(); program.defaultOptimize();
TmpMeanCalls += program.m_FitnessCallsNeeded; TmpMeanCalls += program.fitnessCallsNeeded;
TmpMeanFitness += program.m_Best.defaultEvaulateAsMiniBits(); TmpMeanFitness += program.bestIndividual.defaultEvaulateAsMiniBits();
} }
TmpMeanCalls /= program.m_MultiRuns; TmpMeanCalls /= program.multiRuns;
TmpMeanFitness /= program.m_MultiRuns; TmpMeanFitness /= program.multiRuns;
System.out.println("(" + program.m_MultiRuns + "/" + program.m_FitnessCalls + ") Mean Fitness : " + TmpMeanFitness + " Mean Calls needed: " + TmpMeanCalls); System.out.println("(" + program.multiRuns + "/" + program.fitnessCalls + ") Mean Fitness : " + TmpMeanFitness + " Mean Calls needed: " + TmpMeanCalls);
} }
@Override @Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) { public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea; this.populationChangedEventListener = ea;
} }
@Override @Override
public boolean removePopulationChangedEventListener( public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
if (m_Listener == ea) { if (populationChangedEventListener == ea) {
m_Listener = null; populationChangedEventListener = null;
return true; return true;
} else { } else {
return false; return false;
@ -208,8 +208,8 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
} }
protected void firePropertyChangedEvent(String name) { protected void firePropertyChangedEvent(String name) {
if (this.m_Listener != null) { if (this.populationChangedEventListener != null) {
this.m_Listener.registerPopulationStateChanged(this, name); this.populationChangedEventListener.registerPopulationStateChanged(this, name);
} }
} }
@ -222,14 +222,14 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
@Override @Override
public String getStringRepresentation() { public String getStringRepresentation() {
String result = ""; String result = "";
if (this.m_Population.size() > 1) { if (this.population.size() > 1) {
result += "Multi(" + this.m_Population.size() + ")-Start Hill Climbing:\n"; result += "Multi(" + this.population.size() + ")-Start Hill Climbing:\n";
} else { } else {
result += "Simulated Annealing:\n"; result += "Simulated Annealing:\n";
} }
result += "Optimization Problem: "; result += "Optimization Problem: ";
result += this.m_Problem.getStringRepresentationForProblem(this) + "\n"; result += this.optimizationProblem.getStringRepresentationForProblem(this) + "\n";
result += this.m_Population.getStringRepresentation(); result += this.population.getStringRepresentation();
return result; return result;
} }
@ -240,12 +240,12 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
*/ */
@Override @Override
public void setIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.identifier = name;
} }
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return this.m_Identifier; return this.identifier;
} }
@ -268,12 +268,12 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
*/ */
@Override @Override
public Population getPopulation() { public Population getPopulation() {
return this.m_Population; return this.population;
} }
@Override @Override
public void setPopulation(Population pop) { public void setPopulation(Population pop) {
this.m_Population = pop; this.population = pop;
} }
public String populationTipText() { public String populationTipText() {
@ -291,11 +291,11 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
* @return The initial temperature. * @return The initial temperature.
*/ */
public double getInitialTemperature() { public double getInitialTemperature() {
return this.m_InitialTemperature; return this.initialTemperature;
} }
public void setInitialTemperature(double pop) { public void setInitialTemperature(double pop) {
this.m_InitialTemperature = pop; this.initialTemperature = pop;
} }
public String initialTemperatureTipText() { public String initialTemperatureTipText() {
@ -308,13 +308,13 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
* @return The cooling rate. * @return The cooling rate.
*/ */
public double getAlpha() { public double getAlpha() {
return this.m_Alpha; return this.alpha;
} }
public void setAlpha(double a) { public void setAlpha(double a) {
this.m_Alpha = a; this.alpha = a;
if (this.m_Alpha > 1) { if (this.alpha > 1) {
this.m_Alpha = 1.0; this.alpha = 1.0;
} }
} }

View File

@ -18,29 +18,29 @@ import eva2.util.annotation.Description;
public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializable { public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializable {
// These variables are necessary for the simple testcase // These variables are necessary for the simple testcase
private InterfaceOptimizationProblem m_Problem = new B1Problem(); private InterfaceOptimizationProblem optimizationProblem = new B1Problem();
private int m_MultiRuns = 100; private int multiRuns = 100;
private int m_FitnessCalls = 100; private int fitnessCalls = 100;
private int m_FitnessCallsNeeded = 0; private int fitnessCallsNeeded = 0;
GAIndividualBinaryData m_Best, m_Test; GAIndividualBinaryData bestIndividual, testIndividual;
public double m_InitialT = 2, m_CurrentT; public double initialT = 2, currentT;
public double m_Alpha = 0.9; public double alpha = 0.9;
// These variables are necessary for the more complex LectureGUI enviroment // These variables are necessary for the more complex LectureGUI enviroment
transient private String m_Identifier = ""; transient private String indentifier = "";
transient private InterfacePopulationChangedEventListener m_Listener; transient private InterfacePopulationChangedEventListener populationChangedEventListener;
private Population m_Population; private Population population;
public ThresholdAlgorithm() { public ThresholdAlgorithm() {
this.m_Population = new Population(); this.population = new Population();
this.m_Population.setTargetSize(10); this.population.setTargetSize(10);
} }
public ThresholdAlgorithm(ThresholdAlgorithm a) { public ThresholdAlgorithm(ThresholdAlgorithm a) {
this.m_Population = (Population) a.m_Population.clone(); this.population = (Population) a.population.clone();
this.m_Problem = (InterfaceOptimizationProblem) a.m_Problem.clone(); this.optimizationProblem = (InterfaceOptimizationProblem) a.optimizationProblem.clone();
this.m_InitialT = a.m_InitialT; this.initialT = a.initialT;
this.m_CurrentT = a.m_CurrentT; this.currentT = a.currentT;
this.m_Alpha = a.m_Alpha; this.alpha = a.alpha;
} }
@Override @Override
@ -53,9 +53,9 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
*/ */
@Override @Override
public void init() { public void init() {
this.m_Problem.initializePopulation(this.m_Population); this.optimizationProblem.initializePopulation(this.population);
this.m_Problem.evaluate(this.m_Population); this.optimizationProblem.evaluate(this.population);
this.m_CurrentT = this.m_InitialT; this.currentT = this.initialT;
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
} }
@ -67,11 +67,11 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
*/ */
@Override @Override
public void initByPopulation(Population pop, boolean reset) { public void initByPopulation(Population pop, boolean reset) {
this.m_Population = (Population) pop.clone(); this.population = (Population) pop.clone();
this.m_CurrentT = this.m_InitialT; this.currentT = this.initialT;
if (reset) { if (reset) {
this.m_Population.init(); this.population.init();
this.m_Problem.evaluate(this.m_Population); this.optimizationProblem.evaluate(this.population);
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
} }
} }
@ -82,26 +82,26 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
@Override @Override
public void optimize() { public void optimize() {
AbstractEAIndividual indy; AbstractEAIndividual indy;
Population original = (Population) this.m_Population.clone(); Population original = (Population) this.population.clone();
double delta; double delta;
for (int i = 0; i < this.m_Population.size(); i++) { for (int i = 0; i < this.population.size(); i++) {
indy = ((AbstractEAIndividual) this.m_Population.get(i)); indy = ((AbstractEAIndividual) this.population.get(i));
double tmpD = indy.getMutationProbability(); double tmpD = indy.getMutationProbability();
indy.setMutationProbability(1.0); indy.setMutationProbability(1.0);
indy.mutate(); indy.mutate();
indy.setMutationProbability(tmpD); indy.setMutationProbability(tmpD);
} }
this.m_Problem.evaluate(this.m_Population); this.optimizationProblem.evaluate(this.population);
for (int i = 0; i < this.m_Population.size(); i++) { for (int i = 0; i < this.population.size(); i++) {
delta = this.calculateDelta(((AbstractEAIndividual) original.get(i)), ((AbstractEAIndividual) this.m_Population.get(i))); delta = this.calculateDelta(((AbstractEAIndividual) original.get(i)), ((AbstractEAIndividual) this.population.get(i)));
if (delta < this.m_CurrentT) { if (delta < this.currentT) {
this.m_Population.remove(i); this.population.remove(i);
this.m_Population.add(i, original.get(i)); this.population.add(i, original.get(i));
} }
} }
this.m_CurrentT = this.m_Alpha * this.m_CurrentT; this.currentT = this.alpha * this.currentT;
this.m_Population.incrGeneration(); this.population.incrGeneration();
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
} }
@ -129,36 +129,36 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
*/ */
@Override @Override
public void setProblem(InterfaceOptimizationProblem problem) { public void setProblem(InterfaceOptimizationProblem problem) {
this.m_Problem = problem; this.optimizationProblem = problem;
} }
@Override @Override
public InterfaceOptimizationProblem getProblem() { public InterfaceOptimizationProblem getProblem() {
return this.m_Problem; return this.optimizationProblem;
} }
/** /**
* This method will init the HillClimber * This method will init the HillClimber
*/ */
public void defaultInit() { public void defaultInit() {
this.m_FitnessCallsNeeded = 0; this.fitnessCallsNeeded = 0;
this.m_Best = new GAIndividualBinaryData(); this.bestIndividual = new GAIndividualBinaryData();
this.m_Best.defaultInit(m_Problem); this.bestIndividual.defaultInit(optimizationProblem);
} }
/** /**
* This method will optimize * This method will optimize
*/ */
public void defaultOptimize() { public void defaultOptimize() {
for (int i = 0; i < m_FitnessCalls; i++) { for (int i = 0; i < fitnessCalls; i++) {
this.m_Test = (GAIndividualBinaryData) ((this.m_Best).clone()); this.testIndividual = (GAIndividualBinaryData) ((this.bestIndividual).clone());
this.m_Test.defaultMutate(); this.testIndividual.defaultMutate();
if (this.m_Test.defaultEvaulateAsMiniBits() < this.m_Best.defaultEvaulateAsMiniBits()) { if (this.testIndividual.defaultEvaulateAsMiniBits() < this.bestIndividual.defaultEvaulateAsMiniBits()) {
this.m_Best = this.m_Test; this.bestIndividual = this.testIndividual;
} }
this.m_FitnessCallsNeeded = i; this.fitnessCallsNeeded = i;
if (this.m_Best.defaultEvaulateAsMiniBits() == 0) { if (this.bestIndividual.defaultEvaulateAsMiniBits() == 0) {
i = this.m_FitnessCalls + 1; i = this.fitnessCalls + 1;
} }
} }
} }
@ -171,27 +171,27 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
public static void main(String[] args) { public static void main(String[] args) {
ThresholdAlgorithm program = new ThresholdAlgorithm(); ThresholdAlgorithm program = new ThresholdAlgorithm();
int TmpMeanCalls = 0, TmpMeanFitness = 0; int TmpMeanCalls = 0, TmpMeanFitness = 0;
for (int i = 0; i < program.m_MultiRuns; i++) { for (int i = 0; i < program.multiRuns; i++) {
program.defaultInit(); program.defaultInit();
program.defaultOptimize(); program.defaultOptimize();
TmpMeanCalls += program.m_FitnessCallsNeeded; TmpMeanCalls += program.fitnessCallsNeeded;
TmpMeanFitness += program.m_Best.defaultEvaulateAsMiniBits(); TmpMeanFitness += program.bestIndividual.defaultEvaulateAsMiniBits();
} }
TmpMeanCalls /= program.m_MultiRuns; TmpMeanCalls /= program.multiRuns;
TmpMeanFitness /= program.m_MultiRuns; TmpMeanFitness /= program.multiRuns;
System.out.println("(" + program.m_MultiRuns + "/" + program.m_FitnessCalls + ") Mean Fitness : " + TmpMeanFitness + " Mean Calls needed: " + TmpMeanCalls); System.out.println("(" + program.multiRuns + "/" + program.fitnessCalls + ") Mean Fitness : " + TmpMeanFitness + " Mean Calls needed: " + TmpMeanCalls);
} }
@Override @Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) { public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea; this.populationChangedEventListener = ea;
} }
@Override @Override
public boolean removePopulationChangedEventListener( public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
if (m_Listener == ea) { if (populationChangedEventListener == ea) {
m_Listener = null; populationChangedEventListener = null;
return true; return true;
} else { } else {
return false; return false;
@ -199,8 +199,8 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
} }
protected void firePropertyChangedEvent(String name) { protected void firePropertyChangedEvent(String name) {
if (this.m_Listener != null) { if (this.populationChangedEventListener != null) {
this.m_Listener.registerPopulationStateChanged(this, name); this.populationChangedEventListener.registerPopulationStateChanged(this, name);
} }
} }
@ -213,14 +213,14 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
@Override @Override
public String getStringRepresentation() { public String getStringRepresentation() {
String result = ""; String result = "";
if (this.m_Population.size() > 1) { if (this.population.size() > 1) {
result += "Multi(" + this.m_Population.size() + ")-Start Hill Climbing:\n"; result += "Multi(" + this.population.size() + ")-Start Hill Climbing:\n";
} else { } else {
result += "Threshold Algorithm:\n"; result += "Threshold Algorithm:\n";
} }
result += "Optimization Problem: "; result += "Optimization Problem: ";
result += this.m_Problem.getStringRepresentationForProblem(this) + "\n"; result += this.optimizationProblem.getStringRepresentationForProblem(this) + "\n";
result += this.m_Population.getStringRepresentation(); result += this.population.getStringRepresentation();
return result; return result;
} }
@ -231,12 +231,12 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
*/ */
@Override @Override
public void setIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.indentifier = name;
} }
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return this.m_Identifier; return this.indentifier;
} }
/** /**
@ -258,12 +258,12 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
*/ */
@Override @Override
public Population getPopulation() { public Population getPopulation() {
return this.m_Population; return this.population;
} }
@Override @Override
public void setPopulation(Population pop) { public void setPopulation(Population pop) {
this.m_Population = pop; this.population = pop;
} }
public String populationTipText() { public String populationTipText() {
@ -281,11 +281,11 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
* @return The initial temperature. * @return The initial temperature.
*/ */
public double getInitialT() { public double getInitialT() {
return this.m_InitialT; return this.initialT;
} }
public void setInitialT(double pop) { public void setInitialT(double pop) {
this.m_InitialT = pop; this.initialT = pop;
} }
public String initialTTipText() { public String initialTTipText() {
@ -298,13 +298,13 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
* @return The initial temperature. * @return The initial temperature.
*/ */
public double getAlpha() { public double getAlpha() {
return this.m_Alpha; return this.alpha;
} }
public void setAlpha(double a) { public void setAlpha(double a) {
this.m_Alpha = a; this.alpha = a;
if (this.m_Alpha > 1) { if (this.alpha > 1) {
this.m_Alpha = 1.0; this.alpha = 1.0;
} }
} }

View File

@ -135,9 +135,9 @@ import java.util.List;
public class Tribes implements InterfaceOptimizer, java.io.Serializable { public class Tribes implements InterfaceOptimizer, java.io.Serializable {
public static final boolean TRACE = false; public static final boolean TRACE = false;
protected String m_Identifier = "TRIBES"; protected String identifier = "TRIBES";
transient private InterfacePopulationChangedEventListener m_Listener = null; transient private InterfacePopulationChangedEventListener listener = null;
protected AbstractOptimizationProblem m_problem; protected AbstractOptimizationProblem optimizationProblem;
protected Population population; protected Population population;
public static int maxExplorerNb = 200; public static int maxExplorerNb = 200;
public static int maxMemoryNb = 300; public static int maxMemoryNb = 300;
@ -165,8 +165,8 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
protected int initExplorerNb = 3; // Number of explorers at the very beginning protected int initExplorerNb = 3; // Number of explorers at the very beginning
// use full range (0) or subspace (1) for init options 0 and 1 // use full range (0) or subspace (1) for init options 0 and 1
protected int rangeInitType = 1; protected int rangeInitType = 1;
private boolean m_Show = false; private boolean show = false;
transient protected Plot m_Plot = null; transient protected Plot plot = null;
// private int useAnchors = 0; // use anchors to detect environment changes? // private int useAnchors = 0; // use anchors to detect environment changes?
@Override @Override
@ -200,7 +200,7 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
@Override @Override
public void setProblem(InterfaceOptimizationProblem problem) { public void setProblem(InterfaceOptimizationProblem problem) {
// System.out.println("TRIBES.SetProblem()"); // System.out.println("TRIBES.SetProblem()");
m_problem = (AbstractOptimizationProblem) problem; optimizationProblem = (AbstractOptimizationProblem) problem;
range = null; range = null;
if (problem instanceof InterfaceHasInitRange) { if (problem instanceof InterfaceHasInitRange) {
initRange = (double[][]) ((InterfaceHasInitRange) problem).getInitRange(); initRange = (double[][]) ((InterfaceHasInitRange) problem).getInitRange();
@ -215,7 +215,7 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
// System.out.println("TRIBES.init()"); // System.out.println("TRIBES.init()");
// Generate a swarm // Generate a swarm
swarm = new TribesSwarm(this, range, initRange); // TODO initRange is hard coded equal to problem range swarm = new TribesSwarm(this, range, initRange); // TODO initRange is hard coded equal to problem range
//swarm.generateSwarm(initExplorerNb, initType, m_problem); //swarm.generateSwarm(initExplorerNb, initType, optimizationProblem);
// swarm.displaySwarm(swarm,out); // swarm.displaySwarm(swarm,out);
// print("\n Best after init: "+swarm.Best.position.fitness,out); // print("\n Best after init: "+swarm.Best.position.fitness,out);
@ -232,7 +232,7 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
population.addAll(swarm.toPopulation()); population.addAll(swarm.toPopulation());
population.init(); // necessary to allow for multi-runs population.init(); // necessary to allow for multi-runs
if (m_Show) { if (show) {
show(); show();
} }
@ -274,15 +274,15 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
} }
//* initOption Options: 0 - random, 1 - on the bounds, 2 - sunny spell, 3 - around a center //* initOption Options: 0 - random, 1 - on the bounds, 2 - sunny spell, 3 - around a center
//* rangeInitType for options 0,1: 1 means use initRange, 0 use default range //* rangeInitType for options 0,1: 1 means use initRange, 0 use default range
swarm.generateSwarm(initExplorerNb, initOption, rangeInitType, m_problem); swarm.generateSwarm(initExplorerNb, initOption, rangeInitType, optimizationProblem);
} }
iter++; iter++;
m_problem.evaluatePopulationStart(population); optimizationProblem.evaluatePopulationStart(population);
swarm.setSwarmSize(); swarm.setSwarmSize();
// swarm.Best.positionPrev = swarm.Best.position; // swarm.Best.positionPrev = swarm.Best.position;
swarm.moveSwarm(range, new TribesParam(), informOption, m_problem); //*** HERE IT MOVES and EVALUATES swarm.moveSwarm(range, new TribesParam(), informOption, optimizationProblem); //*** HERE IT MOVES and EVALUATES
//public void moveSwarm(double[][] range, int fitnessSize, TribesParam pb, TribesSwarm swarm, //public void moveSwarm(double[][] range, int fitnessSize, TribesParam pb, TribesSwarm swarm,
// int informOption, AbstractOptimizationProblem prob) { // int informOption, AbstractOptimizationProblem prob) {
@ -297,7 +297,7 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
adapt = iter; // Memorize at which iteration adaptation occurs adapt = iter; // Memorize at which iteration adaptation occurs
for (int i = 0; i < swarm.getTribeCnt(); i++) { for (int i = 0; i < swarm.getTribeCnt(); i++) {
swarm.reinitTribe(i, rangeInitType, m_problem); swarm.reinitTribe(i, rangeInitType, optimizationProblem);
} }
} }
} }
@ -311,16 +311,16 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
if (adaptThreshold >= adaptMax) { if (adaptThreshold >= adaptMax) {
adapt = iter; // Memorize at which iteration adaptation occurs adapt = iter; // Memorize at which iteration adaptation occurs
swarm.adaptSwarm(rangeInitType, m_problem); // Re´alise l'adaptation swarm.adaptSwarm(rangeInitType, optimizationProblem); // Re´alise l'adaptation
} }
} }
} }
population.clear(); population.clear();
population.addAll(swarm.toPopulation()); population.addAll(swarm.toPopulation());
if (m_Show) { if (show) {
plotAll(population); plotAll(population);
} }
m_problem.evaluatePopulationEnd(population); optimizationProblem.evaluatePopulationEnd(population);
// this.population.incrFunctionCallsby(evals); // this.population.incrFunctionCallsby(evals);
this.population.incrGeneration(); this.population.incrGeneration();
@ -348,12 +348,12 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
// TODO // TODO
private void plotIndy(double[] curPosition, double[] curVelocity, int index) { private void plotIndy(double[] curPosition, double[] curVelocity, int index) {
if (this.m_Show) { if (this.show) {
if (curVelocity == null) { if (curVelocity == null) {
this.m_Plot.setUnconnectedPoint(curPosition[0], curPosition[1], index); this.plot.setUnconnectedPoint(curPosition[0], curPosition[1], index);
} else { } else {
this.m_Plot.setConnectedPoint(curPosition[0], curPosition[1], index); this.plot.setConnectedPoint(curPosition[0], curPosition[1], index);
this.m_Plot.setConnectedPoint(curPosition[0] + curVelocity[0], curPosition[1] + curVelocity[1], index); this.plot.setConnectedPoint(curPosition[0] + curVelocity[0], curPosition[1] + curVelocity[1], index);
} }
} }
} }
@ -362,14 +362,14 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
* This method is simply for debugging. * This method is simply for debugging.
*/ */
protected void show() { protected void show() {
if (this.m_Plot == null) { if (this.plot == null) {
// InterfaceDataTypeDouble indy = (InterfaceDataTypeDouble)this.population.get(0); // InterfaceDataTypeDouble indy = (InterfaceDataTypeDouble)this.population.get(0);
// double[][] range = indy.getDoubleRange(); // double[][] range = indy.getDoubleRange();
// double[] tmpD = new double[2]; // double[] tmpD = new double[2];
// tmpD[0] = 0; // tmpD[0] = 0;
// tmpD[1] = 0; // tmpD[1] = 0;
this.m_Plot = new Plot("TRIBES " + population.getGeneration(), "x1", "x2", range[0], range[1]); this.plot = new Plot("TRIBES " + population.getGeneration(), "x1", "x2", range[0], range[1]);
// this.m_Plot.setCornerPoints(range, 0); // this.plot.setCornerPoints(range, 0);
} }
} }
@ -623,14 +623,14 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
*/ */
@Override @Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) { public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea; this.listener = ea;
} }
@Override @Override
public boolean removePopulationChangedEventListener( public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
if (m_Listener == ea) { if (listener == ea) {
m_Listener = null; listener = null;
return true; return true;
} else { } else {
return false; return false;
@ -638,8 +638,8 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
} }
protected void firePropertyChangedEvent(String name) { protected void firePropertyChangedEvent(String name) {
if (this.m_Listener != null) { if (this.listener != null) {
this.m_Listener.registerPopulationStateChanged(this, name); this.listener.registerPopulationStateChanged(this, name);
} }
} }
@ -649,12 +649,12 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
@Override @Override
public void setIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.identifier = name;
} }
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return m_Identifier; return identifier;
} }
@Override @Override
@ -664,7 +664,7 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
@Override @Override
public InterfaceOptimizationProblem getProblem() { public InterfaceOptimizationProblem getProblem() {
return m_problem; return optimizationProblem;
} }
@Override @Override
@ -730,19 +730,19 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
// } // }
/** /**
* @return the m_Show * @return the show
*/ */
public boolean isShow() { public boolean isShow() {
return m_Show; return show;
} }
/** /**
* @param show the m_Show to set * @param show the show to set
*/ */
public void setShow(boolean show) { public void setShow(boolean show) {
m_Show = show; this.show = show;
if (!show) { if (!show) {
m_Plot = null; plot = null;
} }
} }
} }

View File

@ -22,31 +22,31 @@ import eva2.util.annotation.Description;
@Description("This is Evolutionary Multi-Criteria Optimization Algorithm hybridized with Local Searchers to span the Pareto-Front.") @Description("This is Evolutionary Multi-Criteria Optimization Algorithm hybridized with Local Searchers to span the Pareto-Front.")
public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Serializable { public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Serializable {
private InterfaceOptimizer m_MOOptimizer = new MultiObjectiveEA(); private InterfaceOptimizer multiObjectiveEA = new MultiObjectiveEA();
private InterfaceOptimizer m_SOOptimizer = new GeneticAlgorithm(); private InterfaceOptimizer singleObjectiveEA = new GeneticAlgorithm();
private InterfaceOptimizer[] m_SOOptimizers; private InterfaceOptimizer[] singleObjectiveOptimizers;
private Population m_Population = new Population(); private Population population = new Population();
private int m_MigrationRate = 5; private int migrationRate = 5;
private int m_OutputDimension = 2; private int outputDimension = 2;
private InterfaceOptimizationProblem m_Problem = new FM0Problem(); private InterfaceOptimizationProblem optimizationProblem = new FM0Problem();
private String m_Identifier = ""; private String identifier = "";
transient private InterfacePopulationChangedEventListener m_Listener; transient private InterfacePopulationChangedEventListener populationChangedEventListener;
public WingedMultiObjectiveEA() { public WingedMultiObjectiveEA() {
} }
public WingedMultiObjectiveEA(WingedMultiObjectiveEA a) { public WingedMultiObjectiveEA(WingedMultiObjectiveEA a) {
this.m_Problem = (InterfaceOptimizationProblem) a.m_Problem.clone(); this.optimizationProblem = (InterfaceOptimizationProblem) a.optimizationProblem.clone();
this.m_MOOptimizer = (InterfaceOptimizer) a.m_MOOptimizer.clone(); this.multiObjectiveEA = (InterfaceOptimizer) a.multiObjectiveEA.clone();
this.m_SOOptimizer = (InterfaceOptimizer) a.m_SOOptimizer.clone(); this.singleObjectiveEA = (InterfaceOptimizer) a.singleObjectiveEA.clone();
if (a.m_SOOptimizers != null) { if (a.singleObjectiveOptimizers != null) {
this.m_SOOptimizers = new InterfaceOptimizer[a.m_SOOptimizers.length]; this.singleObjectiveOptimizers = new InterfaceOptimizer[a.singleObjectiveOptimizers.length];
for (int i = 0; i < this.m_SOOptimizers.length; i++) { for (int i = 0; i < this.singleObjectiveOptimizers.length; i++) {
this.m_SOOptimizers[i] = (InterfaceOptimizer) a.m_SOOptimizers[i].clone(); this.singleObjectiveOptimizers[i] = (InterfaceOptimizer) a.singleObjectiveOptimizers[i].clone();
} }
} }
this.m_MigrationRate = a.m_MigrationRate; this.migrationRate = a.migrationRate;
this.m_Population = (Population) a.m_Population.clone(); this.population = (Population) a.population.clone();
} }
@Override @Override
@ -56,19 +56,19 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
@Override @Override
public void init() { public void init() {
if (this.m_Problem instanceof AbstractMultiObjectiveOptimizationProblem) { if (this.optimizationProblem instanceof AbstractMultiObjectiveOptimizationProblem) {
AbstractMultiObjectiveOptimizationProblem tmpProb = (AbstractMultiObjectiveOptimizationProblem) this.m_Problem; AbstractMultiObjectiveOptimizationProblem tmpProb = (AbstractMultiObjectiveOptimizationProblem) this.optimizationProblem;
AbstractMultiObjectiveOptimizationProblem tmpP; AbstractMultiObjectiveOptimizationProblem tmpP;
MOSOWeightedFitness tmpWF; MOSOWeightedFitness tmpWF;
PropertyDoubleArray tmpDA; PropertyDoubleArray tmpDA;
int dim = this.m_OutputDimension; int dim = this.outputDimension;
double[] weights; double[] weights;
// dim = tmpProb.getOutputDimension(); // dim = tmpProb.getOutputDimension();
this.m_MOOptimizer.setProblem((InterfaceOptimizationProblem) this.m_Problem.clone()); this.multiObjectiveEA.setProblem((InterfaceOptimizationProblem) this.optimizationProblem.clone());
this.m_MOOptimizer.init(); this.multiObjectiveEA.init();
this.m_SOOptimizers = new InterfaceOptimizer[dim]; this.singleObjectiveOptimizers = new InterfaceOptimizer[dim];
for (int i = 0; i < dim; i++) { for (int i = 0; i < dim; i++) {
tmpP = (AbstractMultiObjectiveOptimizationProblem) this.m_Problem.clone(); tmpP = (AbstractMultiObjectiveOptimizationProblem) this.optimizationProblem.clone();
weights = new double[dim]; weights = new double[dim];
for (int j = 0; j < dim; j++) { for (int j = 0; j < dim; j++) {
weights[j] = 0; weights[j] = 0;
@ -78,13 +78,13 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
tmpWF = new MOSOWeightedFitness(); tmpWF = new MOSOWeightedFitness();
tmpWF.setWeights(tmpDA); tmpWF.setWeights(tmpDA);
tmpP.setMOSOConverter(tmpWF); tmpP.setMOSOConverter(tmpWF);
this.m_SOOptimizers[i] = (InterfaceOptimizer) this.m_SOOptimizer.clone(); this.singleObjectiveOptimizers[i] = (InterfaceOptimizer) this.singleObjectiveEA.clone();
this.m_SOOptimizers[i].setProblem(tmpP); this.singleObjectiveOptimizers[i].setProblem(tmpP);
this.m_SOOptimizers[i].init(); this.singleObjectiveOptimizers[i].init();
} }
} else { } else {
this.m_SOOptimizer.setProblem(this.m_Problem); this.singleObjectiveEA.setProblem(this.optimizationProblem);
this.m_SOOptimizer.init(); this.singleObjectiveEA.init();
} }
this.communicate(); this.communicate();
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
@ -98,19 +98,19 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
*/ */
@Override @Override
public void initByPopulation(Population pop, boolean reset) { public void initByPopulation(Population pop, boolean reset) {
if (this.m_Problem instanceof AbstractMultiObjectiveOptimizationProblem) { if (this.optimizationProblem instanceof AbstractMultiObjectiveOptimizationProblem) {
AbstractMultiObjectiveOptimizationProblem tmpProb = (AbstractMultiObjectiveOptimizationProblem) this.m_Problem; AbstractMultiObjectiveOptimizationProblem tmpProb = (AbstractMultiObjectiveOptimizationProblem) this.optimizationProblem;
AbstractMultiObjectiveOptimizationProblem tmpP; AbstractMultiObjectiveOptimizationProblem tmpP;
MOSOWeightedFitness tmpWF; MOSOWeightedFitness tmpWF;
PropertyDoubleArray tmpDA; PropertyDoubleArray tmpDA;
int dim = 2; int dim = 2;
double[] weights; double[] weights;
// dim = tmpProb.getOutputDimension(); // dim = tmpProb.getOutputDimension();
this.m_MOOptimizer.setProblem((InterfaceOptimizationProblem) this.m_Problem.clone()); this.multiObjectiveEA.setProblem((InterfaceOptimizationProblem) this.optimizationProblem.clone());
this.m_MOOptimizer.initByPopulation(pop, reset); this.multiObjectiveEA.initByPopulation(pop, reset);
this.m_SOOptimizers = new InterfaceOptimizer[dim]; this.singleObjectiveOptimizers = new InterfaceOptimizer[dim];
for (int i = 0; i < dim; i++) { for (int i = 0; i < dim; i++) {
tmpP = (AbstractMultiObjectiveOptimizationProblem) this.m_Problem.clone(); tmpP = (AbstractMultiObjectiveOptimizationProblem) this.optimizationProblem.clone();
weights = new double[dim]; weights = new double[dim];
for (int j = 0; j < dim; j++) { for (int j = 0; j < dim; j++) {
weights[j] = 0; weights[j] = 0;
@ -120,13 +120,13 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
tmpWF = new MOSOWeightedFitness(); tmpWF = new MOSOWeightedFitness();
tmpWF.setWeights(tmpDA); tmpWF.setWeights(tmpDA);
tmpP.setMOSOConverter(tmpWF); tmpP.setMOSOConverter(tmpWF);
this.m_SOOptimizers[i] = (InterfaceOptimizer) this.m_SOOptimizer.clone(); this.singleObjectiveOptimizers[i] = (InterfaceOptimizer) this.singleObjectiveEA.clone();
this.m_SOOptimizers[i].setProblem(tmpP); this.singleObjectiveOptimizers[i].setProblem(tmpP);
this.m_SOOptimizers[i].initByPopulation(pop, reset); this.singleObjectiveOptimizers[i].initByPopulation(pop, reset);
} }
} else { } else {
this.m_SOOptimizer.setProblem(this.m_Problem); this.singleObjectiveEA.setProblem(this.optimizationProblem);
this.m_SOOptimizer.initByPopulation(pop, reset); this.singleObjectiveEA.initByPopulation(pop, reset);
} }
this.communicate(); this.communicate();
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
@ -138,12 +138,12 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
@Override @Override
public void optimize() { public void optimize() {
this.m_MOOptimizer.optimize(); this.multiObjectiveEA.optimize();
for (int i = 0; i < this.m_SOOptimizers.length; i++) { for (int i = 0; i < this.singleObjectiveOptimizers.length; i++) {
this.m_SOOptimizers[i].optimize(); this.singleObjectiveOptimizers[i].optimize();
} }
this.m_Population.incrGeneration(); this.population.incrGeneration();
if ((this.m_Population.getGeneration() % this.m_MigrationRate) == 0) { if ((this.population.getGeneration() % this.migrationRate) == 0) {
this.communicate(); this.communicate();
} }
@ -157,21 +157,21 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
*/ */
private void communicate() { private void communicate() {
int oldFunctionCalls; int oldFunctionCalls;
this.m_Population.clear(); this.population.clear();
this.m_Population.setFunctionCalls(0); this.population.setFunctionCalls(0);
Population pop; Population pop;
// first collect all the data // first collect all the data
pop = (Population) this.m_MOOptimizer.getPopulation().clone(); pop = (Population) this.multiObjectiveEA.getPopulation().clone();
this.m_Population.addPopulation(pop); this.population.addPopulation(pop);
this.m_Population.incrFunctionCallsBy(pop.getFunctionCalls()); this.population.incrFunctionCallsBy(pop.getFunctionCalls());
for (int i = 0; i < this.m_SOOptimizers.length; i++) { for (int i = 0; i < this.singleObjectiveOptimizers.length; i++) {
pop = (Population) this.m_SOOptimizers[i].getPopulation().clone(); pop = (Population) this.singleObjectiveOptimizers[i].getPopulation().clone();
this.m_Population.addPopulation(pop); this.population.addPopulation(pop);
this.m_Population.incrFunctionCallsBy(pop.getFunctionCalls()); this.population.incrFunctionCallsBy(pop.getFunctionCalls());
} }
oldFunctionCalls = this.m_Population.getFunctionCalls(); oldFunctionCalls = this.population.getFunctionCalls();
this.m_Problem.evaluate(this.m_Population); this.optimizationProblem.evaluate(this.population);
this.m_Population.setFunctionCalls(oldFunctionCalls); this.population.setFunctionCalls(oldFunctionCalls);
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED); this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
// double plotValue = (this.problem.getDoublePlotValue(this.population)).doubleValue(); // double plotValue = (this.problem.getDoublePlotValue(this.population)).doubleValue();
// now they are synchronized lets migrate // now they are synchronized lets migrate
@ -182,29 +182,29 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
* This method implements the migration between the optimzers * This method implements the migration between the optimzers
*/ */
private void migrate() { private void migrate() {
AbstractEAIndividual[] bestIndys = new AbstractEAIndividual[this.m_OutputDimension]; AbstractEAIndividual[] bestIndys = new AbstractEAIndividual[this.outputDimension];
double tmpF1, tmpF2; double tmpF1, tmpF2;
// for each dimension find the best // for each dimension find the best
for (int i = 0; i < this.m_OutputDimension; i++) { for (int i = 0; i < this.outputDimension; i++) {
bestIndys[i] = (AbstractEAIndividual) ((AbstractEAIndividual) this.m_Population.get(0)).clone(); bestIndys[i] = (AbstractEAIndividual) ((AbstractEAIndividual) this.population.get(0)).clone();
tmpF1 = bestIndys[i].getFitness(i); tmpF1 = bestIndys[i].getFitness(i);
// for each individual find the best // for each individual find the best
for (int j = 0; j < this.m_Population.size(); j++) { for (int j = 0; j < this.population.size(); j++) {
if (((AbstractEAIndividual) this.m_Population.get(j)).getFitness(i) < tmpF1) { if (((AbstractEAIndividual) this.population.get(j)).getFitness(i) < tmpF1) {
bestIndys[i] = (AbstractEAIndividual) ((AbstractEAIndividual) this.m_Population.get(j)).clone(); bestIndys[i] = (AbstractEAIndividual) ((AbstractEAIndividual) this.population.get(j)).clone();
tmpF1 = bestIndys[i].getFitness(i); tmpF1 = bestIndys[i].getFitness(i);
} }
} }
} }
// now perform the migration // now perform the migration
AbstractEAIndividual tmpIndy; AbstractEAIndividual tmpIndy;
for (int i = 0; i < this.m_OutputDimension; i++) { for (int i = 0; i < this.outputDimension; i++) {
tmpIndy = (AbstractEAIndividual) bestIndys[i].clone(); tmpIndy = (AbstractEAIndividual) bestIndys[i].clone();
this.m_MOOptimizer.getProblem().evaluate(tmpIndy); this.multiObjectiveEA.getProblem().evaluate(tmpIndy);
this.m_MOOptimizer.getPopulation().set(i, tmpIndy); this.multiObjectiveEA.getPopulation().set(i, tmpIndy);
tmpIndy = (AbstractEAIndividual) bestIndys[i].clone(); tmpIndy = (AbstractEAIndividual) bestIndys[i].clone();
this.m_SOOptimizers[i].getProblem().evaluate(tmpIndy); this.singleObjectiveOptimizers[i].getProblem().evaluate(tmpIndy);
this.m_SOOptimizers[i].getPopulation().set(0, bestIndys[i]); this.singleObjectiveOptimizers[i].getPopulation().set(0, bestIndys[i]);
} }
} }
@ -215,14 +215,14 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
*/ */
@Override @Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) { public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea; this.populationChangedEventListener = ea;
} }
@Override @Override
public boolean removePopulationChangedEventListener( public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
if (m_Listener == ea) { if (populationChangedEventListener == ea) {
m_Listener = null; populationChangedEventListener = null;
return true; return true;
} else { } else {
return false; return false;
@ -233,8 +233,8 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
* Something has changed * Something has changed
*/ */
protected void firePropertyChangedEvent(String name) { protected void firePropertyChangedEvent(String name) {
if (this.m_Listener != null) { if (this.populationChangedEventListener != null) {
this.m_Listener.registerPopulationStateChanged(this, name); this.populationChangedEventListener.registerPopulationStateChanged(this, name);
} }
} }
@ -245,12 +245,12 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
*/ */
@Override @Override
public void setProblem(InterfaceOptimizationProblem problem) { public void setProblem(InterfaceOptimizationProblem problem) {
this.m_Problem = problem; this.optimizationProblem = problem;
} }
@Override @Override
public InterfaceOptimizationProblem getProblem() { public InterfaceOptimizationProblem getProblem() {
return this.m_Problem; return this.optimizationProblem;
} }
/** /**
@ -264,8 +264,8 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
String result = ""; String result = "";
result += "EMO:\n"; result += "EMO:\n";
result += "Optimization Problem: "; result += "Optimization Problem: ";
result += this.m_Problem.getStringRepresentationForProblem(this) + "\n"; result += this.optimizationProblem.getStringRepresentationForProblem(this) + "\n";
result += this.m_Population.getStringRepresentation(); result += this.population.getStringRepresentation();
return result; return result;
} }
@ -276,12 +276,12 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
*/ */
@Override @Override
public void setIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.identifier = name;
} }
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return this.m_Identifier; return this.identifier;
} }
/** /**
@ -303,12 +303,12 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
*/ */
@Override @Override
public Population getPopulation() { public Population getPopulation() {
return this.m_Population; return this.population;
} }
@Override @Override
public void setPopulation(Population pop) { public void setPopulation(Population pop) {
this.m_Population = pop; this.population = pop;
} }
public String populationTipText() { public String populationTipText() {
@ -326,11 +326,11 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
* @return The current optimizing method * @return The current optimizing method
*/ */
public InterfaceOptimizer getMOOptimizer() { public InterfaceOptimizer getMOOptimizer() {
return this.m_MOOptimizer; return this.multiObjectiveEA;
} }
public void setMOOptimizer(InterfaceOptimizer b) { public void setMOOptimizer(InterfaceOptimizer b) {
this.m_MOOptimizer = b; this.multiObjectiveEA = b;
} }
public String mOOptimizerTipText() { public String mOOptimizerTipText() {
@ -343,11 +343,11 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
* @return The current optimizing method * @return The current optimizing method
*/ */
public InterfaceOptimizer getSOOptimizer() { public InterfaceOptimizer getSOOptimizer() {
return this.m_SOOptimizer; return this.singleObjectiveEA;
} }
public void setSOOptimizer(InterfaceOptimizer b) { public void setSOOptimizer(InterfaceOptimizer b) {
this.m_SOOptimizer = b; this.singleObjectiveEA = b;
} }
public String sOOptimizerTipText() { public String sOOptimizerTipText() {
@ -360,11 +360,11 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
* @return The current optimizing method * @return The current optimizing method
*/ */
public int getMigrationRate() { public int getMigrationRate() {
return this.m_MigrationRate; return this.migrationRate;
} }
public void setMigrationRate(int b) { public void setMigrationRate(int b) {
this.m_MigrationRate = b; this.migrationRate = b;
} }
public String migrationRateTipText() { public String migrationRateTipText() {