Refactored all m_ from eva2.optimization.strategies
This commit is contained in:
parent
22fafe185a
commit
53b5111df7
@ -97,6 +97,6 @@ public class GPNodeOutput extends AbstractGPNode implements java.io.Serializable
|
||||
// * @return string
|
||||
// */
|
||||
// public String getStringRepresentation() {
|
||||
// return ("( A:" +this.m_Identifier + " )");
|
||||
// return ("( A:" +this.identifier + " )");
|
||||
// }
|
||||
}
|
@ -642,7 +642,7 @@ public class MOCCOViewer extends JPanel implements InterfaceRefSolutionListener,
|
||||
// gbc.gridx = 3;
|
||||
// gbc.gridy = i+1;
|
||||
// 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_History.add(this.m_JCShow[i], gbc);
|
||||
// gbc.gridx = 4;
|
||||
@ -663,7 +663,7 @@ public class MOCCOViewer extends JPanel implements InterfaceRefSolutionListener,
|
||||
// ActionListener showModeChanged = new ActionListener() {
|
||||
// public void actionPerformed(ActionEvent event) {
|
||||
// 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();
|
||||
// }
|
||||
|
@ -197,7 +197,7 @@ public class ParetoFrontView2D extends JPanel implements InterfaceParetoFrontVie
|
||||
// first plot the populations
|
||||
if (false) {
|
||||
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]) {
|
||||
mySet = new GraphPointSet(i + 10, this.m_Area);
|
||||
mySet.setConnectedMode(false);
|
||||
|
@ -175,10 +175,10 @@ public abstract class AbstractArchiving implements InterfaceArchiving, java.io.S
|
||||
// * @param b True in case of the debug mode.
|
||||
// */
|
||||
// public void setDebugFront(boolean b) {
|
||||
// this.m_Debug = b;
|
||||
// this.debug = b;
|
||||
// }
|
||||
// public boolean getDebugFront() {
|
||||
// return this.m_Debug;
|
||||
// return this.debug;
|
||||
// }
|
||||
// public String debugFrontTipText() {
|
||||
// return "Toggles the debug mode.";
|
||||
|
@ -32,7 +32,7 @@ import java.io.IOException;
|
||||
*/
|
||||
public class MOClusteringSeparation implements InterfaceMigration, java.io.Serializable {
|
||||
|
||||
public boolean m_Debug = false;
|
||||
public boolean debug = false;
|
||||
private ClusteringKMeans m_KMeans = new ClusteringKMeans();
|
||||
private ArchivingNSGAII m_NSGAII = new ArchivingNSGAII();
|
||||
private boolean m_UseConstraints = true;
|
||||
@ -44,7 +44,7 @@ public class MOClusteringSeparation implements InterfaceMigration, java.io.Seria
|
||||
}
|
||||
|
||||
public MOClusteringSeparation(MOClusteringSeparation b) {
|
||||
this.m_Debug = b.m_Debug;
|
||||
this.debug = b.debug;
|
||||
this.m_UseConstraints = b.m_UseConstraints;
|
||||
if (b.m_KMeans != null) {
|
||||
this.m_KMeans = (ClusteringKMeans) b.m_KMeans.clone();
|
||||
@ -98,7 +98,7 @@ public class MOClusteringSeparation implements InterfaceMigration, java.io.Seria
|
||||
// collect the populations
|
||||
for (int i = 0; i < islands.length; i++) {
|
||||
oldIPOP[i] = islands[i].getPopulation();
|
||||
if (this.m_Debug) {
|
||||
if (this.debug) {
|
||||
System.out.println("Got population from " + i + " of size " + oldIPOP[i].size());
|
||||
}
|
||||
collector.addPopulation((Population) oldIPOP[i].clone());
|
||||
@ -106,7 +106,7 @@ public class MOClusteringSeparation implements InterfaceMigration, java.io.Seria
|
||||
}
|
||||
memory = (Population) collector.clone();
|
||||
|
||||
// if (this.m_Debug) {
|
||||
// if (this.debug) {
|
||||
// // let's see how they arrive here
|
||||
// Plot plot;
|
||||
// double[] tmpD = new double[2];
|
||||
@ -146,7 +146,7 @@ public class MOClusteringSeparation implements InterfaceMigration, java.io.Seria
|
||||
double[][] c = this.m_KMeans.getC();
|
||||
newIPOP = this.m_KMeans.cluster(collector, c);
|
||||
|
||||
if (this.m_Debug) {
|
||||
if (this.debug) {
|
||||
Plot plot;
|
||||
double[] tmpD = new double[2];
|
||||
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());
|
||||
((AbstractMultiObjectiveOptimizationProblem) prob).m_AreaConst4Parallelization.add(b);
|
||||
// if (this.m_Debug) {
|
||||
// if (this.debug) {
|
||||
// String out = "";
|
||||
// out += i+ ". MyClass: {";
|
||||
// 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()) {
|
||||
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());
|
||||
}
|
||||
islands[i].setPopulation(oldIPOP[i]);
|
||||
|
@ -34,7 +34,7 @@ import java.io.IOException;
|
||||
*/
|
||||
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_UseConstraints = true;
|
||||
private InterfaceSelection m_Selection = new SelectRandom();
|
||||
@ -45,7 +45,7 @@ public class MOConeSeparation implements InterfaceMigration, java.io.Serializabl
|
||||
}
|
||||
|
||||
public MOConeSeparation(MOConeSeparation b) {
|
||||
this.m_Debug = b.m_Debug;
|
||||
this.debug = b.debug;
|
||||
this.m_UseConstraints = b.m_UseConstraints;
|
||||
this.m_UseAllToDetermineR = b.m_UseAllToDetermineR;
|
||||
if (b.m_Selection != null) {
|
||||
@ -91,7 +91,7 @@ public class MOConeSeparation implements InterfaceMigration, java.io.Serializabl
|
||||
// collect the populations
|
||||
for (int i = 0; i < islands.length; i++) {
|
||||
oldIPOP[i] = islands[i].getPopulation();
|
||||
if (this.m_Debug) {
|
||||
if (this.debug) {
|
||||
System.out.println("Got population from " + i + " of size " + oldIPOP[i].size());
|
||||
}
|
||||
collector.addPopulation((Population) oldIPOP[i].clone());
|
||||
@ -118,7 +118,7 @@ public class MOConeSeparation implements InterfaceMigration, java.io.Serializabl
|
||||
if (!oldIPOP[i].targetSizeReached()) {
|
||||
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());
|
||||
}
|
||||
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) {
|
||||
AbstractEAIndividual indy;
|
||||
|
||||
// if (this.m_Debug) {
|
||||
// if (this.debug) {
|
||||
// // let's see how they arrive here
|
||||
// // This shows that the Drecksbeutels
|
||||
// // indeed spread out, even within
|
||||
@ -212,7 +212,7 @@ public class MOConeSeparation implements InterfaceMigration, java.io.Serializabl
|
||||
// the rest belongs to newIPOP.length-1
|
||||
newIPOP[newIPOP.length - 1].addPopulation(collector);
|
||||
|
||||
if (this.m_Debug) {
|
||||
if (this.debug) {
|
||||
Plot plot;
|
||||
double[] tmpD = new double[2];
|
||||
tmpD[0] = 0;
|
||||
|
@ -103,7 +103,7 @@ public class MOXMeansSeparation implements InterfaceMigration, java.io.Serializa
|
||||
}
|
||||
memory = (Population) collector.clone();
|
||||
|
||||
// if (this.m_Debug) {
|
||||
// if (this.debug) {
|
||||
// // let's see how they arrive here
|
||||
// Plot plot;
|
||||
// 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());
|
||||
((AbstractMultiObjectiveOptimizationProblem) prob).m_AreaConst4Parallelization.add(b);
|
||||
// if (this.m_Debug) {
|
||||
// if (this.debug) {
|
||||
// String out = "";
|
||||
// out += i+ ". MyClass: {";
|
||||
// for (int j = 0; j < myClass.length; j++) out += myClass[j]+"; ";
|
||||
|
@ -76,11 +76,11 @@ public class MOSOMaxiMin implements InterfaceMOSOConverter, java.io.Serializable
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
// if (false) {
|
||||
// this.m_Plot = new eva2.gui.plot.Plot("Debug MaxiMin", "Y1", "Y2");
|
||||
// this.m_Plot.setUnconnectedPoint(0, 0, 11);
|
||||
// this.m_Plot.setUnconnectedPoint(1.2, 2.0, 11);
|
||||
// this.plot = new eva2.gui.plot.Plot("Debug MaxiMin", "Y1", "Y2");
|
||||
// this.plot.setUnconnectedPoint(0, 0, 11);
|
||||
// this.plot.setUnconnectedPoint(1.2, 2.0, 11);
|
||||
// double[][] trueFitness, moFitness;
|
||||
// GraphPointSet mySet = new GraphPointSet(10, this.m_Plot.getFunctionArea());
|
||||
// GraphPointSet mySet = new GraphPointSet(10, this.plot.getFunctionArea());
|
||||
// DPoint myPoint;
|
||||
// double tmp1, tmp2;
|
||||
// Chart2DDPointIconText tmp;
|
||||
|
@ -381,7 +381,7 @@ public abstract class AbstractMultiObjectiveOptimizationProblem extends Abstract
|
||||
Population tmpPop = null;
|
||||
|
||||
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
|
||||
// but i have to differentiate between the case where
|
||||
// there is a true MOEA at work and where the
|
||||
|
@ -554,7 +554,7 @@ public class ANPSO extends NichePSO implements InterfaceOptimizer, InterfaceAddi
|
||||
if (reinitSuperfl) {
|
||||
for (int i = 0; i < tmpPop.size(); 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
|
||||
ParticleSwarmOptimization.initIndividualDefaults(indy, 0.2);
|
||||
ParticleSwarmOptimization.initIndividualMemory(indy);
|
||||
@ -802,10 +802,10 @@ public class ANPSO extends NichePSO implements InterfaceOptimizer, InterfaceAddi
|
||||
// }
|
||||
for (int i = 0; i < getSubSwarms().size(); ++i) {
|
||||
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) {
|
||||
elitePop.addIndividual((AbstractEAIndividual) ((ParticleSubSwarmOptimization) inactiveSubSwarms.get(i)).m_BestIndividual.clone());
|
||||
elitePop.addIndividual((AbstractEAIndividual) ((ParticleSubSwarmOptimization) inactiveSubSwarms.get(i)).bestIndividual.clone());
|
||||
}
|
||||
return elitePop;
|
||||
}
|
||||
@ -830,7 +830,7 @@ public class ANPSO extends NichePSO implements InterfaceOptimizer, InterfaceAddi
|
||||
*/
|
||||
@Override
|
||||
protected void plotSubSwarms() {
|
||||
if (this.m_Problem instanceof Interface2DBorderProblem) {
|
||||
if (this.optimizationProblem instanceof Interface2DBorderProblem) {
|
||||
//DPointSet popRep = new DPointSet();
|
||||
InterfaceDataTypeDouble tmpIndy1;
|
||||
|
||||
@ -839,7 +839,7 @@ public class ANPSO extends NichePSO implements InterfaceOptimizer, InterfaceAddi
|
||||
// for all inactive SubSwarms from ANPSO...
|
||||
for (int i = 0; i < this.inactiveSubSwarms.size(); i++) {
|
||||
ParticleSubSwarmOptimization currentsubswarm = this.inactiveSubSwarms.get(i);
|
||||
InterfaceDataTypeDouble best = (InterfaceDataTypeDouble) currentsubswarm.m_BestIndividual;
|
||||
InterfaceDataTypeDouble best = (InterfaceDataTypeDouble) currentsubswarm.bestIndividual;
|
||||
plotCircleForIndy((AbstractEAIndividual) best, "[I]");
|
||||
}
|
||||
|
||||
@ -848,7 +848,7 @@ public class ANPSO extends NichePSO implements InterfaceOptimizer, InterfaceAddi
|
||||
ParticleSubSwarmOptimization currentsubswarm = this.getSubSwarms().get(i);
|
||||
Population currentsubswarmpop = (Population) currentsubswarm.getPopulation();
|
||||
//InterfaceDataTypeDouble best = (InterfaceDataTypeDouble)currentsubswarmpop.getBestIndividual();
|
||||
InterfaceDataTypeDouble best = (InterfaceDataTypeDouble) currentsubswarm.m_BestIndividual;
|
||||
InterfaceDataTypeDouble best = (InterfaceDataTypeDouble) currentsubswarm.bestIndividual;
|
||||
DPointSet popRep = new DPointSet();
|
||||
|
||||
//...draw SubSwarm as points
|
||||
@ -857,7 +857,7 @@ public class ANPSO extends NichePSO implements InterfaceOptimizer, InterfaceAddi
|
||||
tmpIndy1 = (InterfaceDataTypeDouble) currentsubswarmpop.get(j);
|
||||
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
|
||||
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(best.getDoubleData()[0], best.getDoubleData()[1]));
|
||||
}
|
||||
this.m_TopologySwarm.getFunctionArea().addDElement(popRep); // time consuming
|
||||
this.topoPlot.getFunctionArea().addDElement(popRep); // time consuming
|
||||
}
|
||||
} // endif
|
||||
}
|
||||
|
@ -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.")
|
||||
public class BOA implements InterfaceOptimizer, java.io.Serializable {
|
||||
private static final Logger LOGGER = Logger.getLogger(BOA.class.getName());
|
||||
transient private InterfacePopulationChangedEventListener m_Listener = null;
|
||||
private String m_Identifier = "BOA";
|
||||
transient private InterfacePopulationChangedEventListener populationChangedEventListener = null;
|
||||
private String identifier = "BOA";
|
||||
private int probDim = 8;
|
||||
private int fitCrit = -1;
|
||||
private int PopSize = 50;
|
||||
@ -82,8 +82,8 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
|
||||
}
|
||||
|
||||
public BOA(BOA b) {
|
||||
this.m_Listener = b.m_Listener;
|
||||
this.m_Identifier = b.m_Identifier;
|
||||
this.populationChangedEventListener = b.populationChangedEventListener;
|
||||
this.identifier = b.identifier;
|
||||
this.probDim = b.probDim;
|
||||
this.fitCrit = b.fitCrit;
|
||||
this.PopSize = b.PopSize;
|
||||
@ -126,7 +126,7 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
|
||||
@Override
|
||||
public void addPopulationChangedEventListener(
|
||||
InterfacePopulationChangedEventListener ea) {
|
||||
this.m_Listener = ea;
|
||||
this.populationChangedEventListener = ea;
|
||||
}
|
||||
|
||||
private void createDirectoryIfNeeded(String directoryName) {
|
||||
@ -141,8 +141,8 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
|
||||
@Override
|
||||
public boolean removePopulationChangedEventListener(
|
||||
InterfacePopulationChangedEventListener ea) {
|
||||
if (m_Listener == ea) {
|
||||
m_Listener = null;
|
||||
if (populationChangedEventListener == ea) {
|
||||
populationChangedEventListener = null;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@ -546,8 +546,8 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
|
||||
* Something has changed
|
||||
*/
|
||||
protected void firePropertyChangedEvent(String name) {
|
||||
if (this.m_Listener != null) {
|
||||
this.m_Listener.registerPopulationStateChanged(this, name);
|
||||
if (this.populationChangedEventListener != null) {
|
||||
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -568,12 +568,12 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
|
||||
|
||||
@Override
|
||||
public void setIdentifier(String name) {
|
||||
this.m_Identifier = name;
|
||||
this.identifier = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return this.m_Identifier;
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,8 +32,8 @@ import java.util.BitSet;
|
||||
public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializable, InterfacePopulationChangedEventListener {
|
||||
|
||||
private static boolean TRACE = false;
|
||||
transient private InterfacePopulationChangedEventListener m_Listener = null;
|
||||
private String m_Identifier = "BinaryScatterSearch";
|
||||
transient private InterfacePopulationChangedEventListener populationChangedEventListener = null;
|
||||
private String identifier = "BinaryScatterSearch";
|
||||
private int MaxImpIter = 5;
|
||||
private int poolSize = 100;
|
||||
private int refSetSize = 10;
|
||||
@ -64,8 +64,8 @@ public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializ
|
||||
* @param b
|
||||
*/
|
||||
public BinaryScatterSearch(BinaryScatterSearch b) {
|
||||
this.m_Listener = b.m_Listener;
|
||||
this.m_Identifier = b.m_Identifier;
|
||||
this.populationChangedEventListener = b.populationChangedEventListener;
|
||||
this.identifier = b.identifier;
|
||||
this.MaxImpIter = b.MaxImpIter;
|
||||
this.poolSize = b.poolSize;
|
||||
this.refSetSize = b.refSetSize;
|
||||
@ -153,14 +153,14 @@ public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializ
|
||||
@Override
|
||||
public void addPopulationChangedEventListener(
|
||||
InterfacePopulationChangedEventListener ea) {
|
||||
this.m_Listener = ea;
|
||||
this.populationChangedEventListener = ea;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removePopulationChangedEventListener(
|
||||
InterfacePopulationChangedEventListener ea) {
|
||||
if (m_Listener == ea) {
|
||||
m_Listener = null;
|
||||
if (populationChangedEventListener == ea) {
|
||||
populationChangedEventListener = null;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@ -773,12 +773,12 @@ public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializ
|
||||
|
||||
@Override
|
||||
public void setIdentifier(String name) {
|
||||
this.m_Identifier = name;
|
||||
this.identifier = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return this.m_Identifier;
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -797,8 +797,8 @@ public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializ
|
||||
}
|
||||
|
||||
protected void firePropertyChangedEvent(String name) {
|
||||
if (this.m_Listener != null) {
|
||||
this.m_Listener.registerPopulationStateChanged(this, name);
|
||||
if (this.populationChangedEventListener != null) {
|
||||
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -574,7 +574,7 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
|
||||
// if (isActive(curSpecies)) { // Lets have only active species...
|
||||
if ((haltingWindow > 0) && (this.testSpeciesForConvergence(curSpecies))) {
|
||||
///////////////////////////////////////////// Halting Window /////////////////////////////////////////////////
|
||||
// if (this.m_Debug) {
|
||||
// if (this.debug) {
|
||||
// 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());
|
||||
// }
|
||||
@ -617,11 +617,11 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
|
||||
undifferentiatedPopulation.addPopulation(initializeIndividuals(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("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 {
|
||||
// actually optimize D_i
|
||||
@ -718,7 +718,7 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
|
||||
printState("---After differentiation", reinitPop);
|
||||
}
|
||||
|
||||
//if (this.m_Show) this.plot();
|
||||
//if (this.show) this.plot();
|
||||
} // end of species differentiation
|
||||
|
||||
// plot the populations
|
||||
|
@ -39,12 +39,12 @@ import java.io.Serializable;
|
||||
public class ClusteringHillClimbing implements InterfacePopulationChangedEventListener,
|
||||
InterfaceOptimizer, Serializable, InterfaceAdditionalPopulationInformer {
|
||||
|
||||
transient private InterfacePopulationChangedEventListener m_Listener;
|
||||
transient private InterfacePopulationChangedEventListener populationChangedEventListener;
|
||||
public static final boolean TRACE = false;
|
||||
transient private String m_Identifier = "";
|
||||
private Population m_Population = new Population();
|
||||
transient private String identifier = "";
|
||||
private Population population = 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 initialPopSize = 100;
|
||||
private int loopCnt = 0;
|
||||
@ -72,8 +72,8 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
|
||||
|
||||
public ClusteringHillClimbing(ClusteringHillClimbing other) {
|
||||
hideHideable();
|
||||
m_Population = (Population) other.m_Population.clone();
|
||||
m_Problem = (InterfaceOptimizationProblem) other.m_Problem.clone();
|
||||
population = (Population) other.population.clone();
|
||||
optimizationProblem = (InterfaceOptimizationProblem) other.optimizationProblem.clone();
|
||||
|
||||
hcEvalCycle = other.hcEvalCycle;
|
||||
initialPopSize = other.initialPopSize;
|
||||
@ -103,12 +103,12 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
|
||||
|
||||
@Override
|
||||
public void setIdentifier(String name) {
|
||||
this.m_Identifier = name;
|
||||
this.identifier = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return this.m_Identifier;
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -118,24 +118,24 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
|
||||
*/
|
||||
@Override
|
||||
public void setProblem(InterfaceOptimizationProblem problem) {
|
||||
this.m_Problem = problem;
|
||||
this.optimizationProblem = problem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InterfaceOptimizationProblem getProblem() {
|
||||
return this.m_Problem;
|
||||
return this.optimizationProblem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
|
||||
this.m_Listener = ea;
|
||||
this.populationChangedEventListener = ea;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removePopulationChangedEventListener(
|
||||
InterfacePopulationChangedEventListener ea) {
|
||||
if (m_Listener == ea) {
|
||||
m_Listener = null;
|
||||
if (populationChangedEventListener == ea) {
|
||||
populationChangedEventListener = null;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@ -148,10 +148,10 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
|
||||
mutator = new MutateESFixedStepSize(initialStepSize);
|
||||
archive = new Population();
|
||||
hideHideable();
|
||||
m_Population.setTargetSize(initialPopSize);
|
||||
this.m_Problem.initializePopulation(this.m_Population);
|
||||
m_Population.addPopulationChangedEventListener(null); // noone will be notified directly on pop changes
|
||||
this.m_Problem.evaluate(this.m_Population);
|
||||
population.setTargetSize(initialPopSize);
|
||||
this.optimizationProblem.initializePopulation(this.population);
|
||||
population.addPopulationChangedEventListener(null); // noone will be notified directly on pop changes
|
||||
this.optimizationProblem.evaluate(this.population);
|
||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
|
||||
}
|
||||
|
||||
@ -164,11 +164,11 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
|
||||
@Override
|
||||
public void initByPopulation(Population pop, boolean reset) {
|
||||
loopCnt = 0;
|
||||
this.m_Population = (Population) pop.clone();
|
||||
m_Population.addPopulationChangedEventListener(null);
|
||||
this.population = (Population) pop.clone();
|
||||
population.addPopulationChangedEventListener(null);
|
||||
if (reset) {
|
||||
this.m_Population.init();
|
||||
this.m_Problem.evaluate(this.m_Population);
|
||||
this.population.init();
|
||||
this.optimizationProblem.evaluate(this.population);
|
||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
|
||||
}
|
||||
}
|
||||
@ -177,8 +177,8 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
|
||||
* Something has changed
|
||||
*/
|
||||
protected void firePropertyChangedEvent(String name) {
|
||||
if (this.m_Listener != null) {
|
||||
this.m_Listener.registerPopulationStateChanged(this, name);
|
||||
if (this.populationChangedEventListener != null) {
|
||||
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -187,13 +187,13 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
|
||||
double improvement;
|
||||
|
||||
loopCnt++;
|
||||
m_Population.addPopulationChangedEventListener(this);
|
||||
m_Population.setNotifyEvalInterval(notifyGuiEvery);
|
||||
population.addPopulationChangedEventListener(this);
|
||||
population.setNotifyEvalInterval(notifyGuiEvery);
|
||||
Pair<Population, Double> popD;
|
||||
int funCallsBefore = m_Population.getFunctionCalls();
|
||||
int evalsNow, lastOverhead = (m_Population.getFunctionCalls() % hcEvalCycle);
|
||||
int funCallsBefore = population.getFunctionCalls();
|
||||
int evalsNow, lastOverhead = (population.getFunctionCalls() % hcEvalCycle);
|
||||
if (lastOverhead > 0) {
|
||||
evalsNow = (2 * hcEvalCycle - (m_Population.getFunctionCalls() % hcEvalCycle));
|
||||
evalsNow = (2 * hcEvalCycle - (population.getFunctionCalls() % hcEvalCycle));
|
||||
} else {
|
||||
evalsNow = hcEvalCycle;
|
||||
}
|
||||
@ -201,7 +201,7 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
|
||||
if (TRACE) {
|
||||
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);
|
||||
if (popD.head().getFunctionCalls() == funCallsBefore) {
|
||||
System.err.println("Bad case, increasing allowed evaluations!");
|
||||
@ -209,12 +209,12 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
|
||||
}
|
||||
} while (popD.head().getFunctionCalls() == funCallsBefore);
|
||||
improvement = popD.tail();
|
||||
m_Population = popD.head();
|
||||
population = popD.head();
|
||||
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 (TRACE) {
|
||||
@ -231,21 +231,21 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
|
||||
}
|
||||
|
||||
// store results
|
||||
archive.setFunctionCalls(m_Population.getFunctionCalls());
|
||||
archive.addPopulation(m_Population);
|
||||
archive.setFunctionCalls(population.getFunctionCalls());
|
||||
archive.addPopulation(population);
|
||||
|
||||
Population tmpPop = new Population();
|
||||
tmpPop.addPopulationChangedEventListener(null);
|
||||
tmpPop.setTargetSize(initialPopSize);
|
||||
this.m_Problem.initializePopulation(tmpPop);
|
||||
tmpPop.setSameParams(m_Population);
|
||||
this.optimizationProblem.initializePopulation(tmpPop);
|
||||
tmpPop.setSameParams(population);
|
||||
tmpPop.setTargetSize(initialPopSize);
|
||||
this.m_Problem.evaluate(tmpPop);
|
||||
this.optimizationProblem.evaluate(tmpPop);
|
||||
|
||||
// reset population while keeping function calls etc.
|
||||
m_Population.clear();
|
||||
m_Population.addPopulation(tmpPop);
|
||||
m_Population.incrFunctionCallsBy(tmpPop.size());
|
||||
population.clear();
|
||||
population.addPopulation(tmpPop);
|
||||
population.incrFunctionCallsBy(tmpPop.size());
|
||||
|
||||
} else { // decrease step size for hc
|
||||
if (localSearchMethod != PostProcessMethod.hillClimber) {
|
||||
@ -270,7 +270,7 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
|
||||
// System.out.println("bla");
|
||||
// }
|
||||
// set funcalls to real value
|
||||
m_Population.setFunctionCalls(((Population) source).getFunctionCalls());
|
||||
population.setFunctionCalls(((Population) source).getFunctionCalls());
|
||||
// System.out.println("FunCallIntervalReached at " + (((Population)source).getFunctionCalls()));
|
||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
|
||||
}
|
||||
@ -288,12 +288,12 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
|
||||
*/
|
||||
@Override
|
||||
public Population getPopulation() {
|
||||
return this.m_Population;
|
||||
return this.population;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPopulation(Population pop) {
|
||||
this.m_Population = pop;
|
||||
this.population = pop;
|
||||
}
|
||||
|
||||
public String populationTipText() {
|
||||
@ -304,11 +304,11 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
|
||||
public InterfaceSolutionSet getAllSolutions() {
|
||||
Population tmp = new Population();
|
||||
tmp.addPopulation(archive);
|
||||
tmp.addPopulation(m_Population);
|
||||
tmp.setFunctionCalls(m_Population.getFunctionCalls());
|
||||
tmp.setGeneration(m_Population.getGeneration());
|
||||
tmp.addPopulation(population);
|
||||
tmp.setFunctionCalls(population.getFunctionCalls());
|
||||
tmp.setGeneration(population.getGeneration());
|
||||
// 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(getPopulation().getTargetSize());
|
||||
sbuf.append("Optimization Problem: ");
|
||||
sbuf.append(this.m_Problem.getStringRepresentationForProblem(this));
|
||||
sbuf.append(this.m_Population.getStringRepresentation());
|
||||
sbuf.append(this.optimizationProblem.getStringRepresentationForProblem(this));
|
||||
sbuf.append(this.population.getStringRepresentation());
|
||||
return sbuf.toString();
|
||||
}
|
||||
|
||||
@ -485,7 +485,7 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
|
||||
|
||||
@Override
|
||||
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() {
|
||||
|
@ -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.")
|
||||
private double lambda = 0.6;
|
||||
|
||||
private double m_Mt = 0.05;
|
||||
private double mt = 0.05;
|
||||
private int maximumAge = -1;
|
||||
private boolean reEvaluate = false;
|
||||
// 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 boolean randomizeFKLambda = false;
|
||||
private boolean generational = true;
|
||||
private String m_Identifier = "";
|
||||
transient private Vector<InterfacePopulationChangedEventListener> m_Listener = new Vector<InterfacePopulationChangedEventListener>();
|
||||
private String identifier = "";
|
||||
transient private Vector<InterfacePopulationChangedEventListener> populationChangedEventListeners = new Vector<>();
|
||||
private boolean forceRange = true;
|
||||
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
|
||||
@ -80,7 +80,7 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
|
||||
differentialWeight = f;
|
||||
crossoverRate = k;
|
||||
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.population = (Population) a.population.clone();
|
||||
this.optimizationProblem = (AbstractOptimizationProblem) a.optimizationProblem.clone();
|
||||
this.m_Identifier = a.m_Identifier;
|
||||
this.identifier = a.identifier;
|
||||
this.differentialWeight = a.differentialWeight;
|
||||
this.crossoverRate = a.crossoverRate;
|
||||
this.lambda = a.lambda;
|
||||
this.m_Mt = a.m_Mt;
|
||||
this.mt = a.mt;
|
||||
|
||||
this.maximumAge = a.maximumAge;
|
||||
this.randomizeFKLambda = a.randomizeFKLambda;
|
||||
@ -393,7 +393,7 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
|
||||
if (parents != null) {
|
||||
parents.add(pop.getEAIndividual(parentIndex));
|
||||
} // Add wherever oX is used directly
|
||||
if (RNG.flipCoin(this.m_Mt)) {
|
||||
if (RNG.flipCoin(this.mt)) {
|
||||
double[] xk, xl;
|
||||
double p, pj, pk, pl;
|
||||
InterfaceDataTypeDouble indy1 = null, indy2 = null;
|
||||
@ -679,16 +679,16 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
|
||||
*/
|
||||
@Override
|
||||
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
|
||||
if (this.m_Listener == null) {
|
||||
this.m_Listener = new Vector<InterfacePopulationChangedEventListener>();
|
||||
if (this.populationChangedEventListeners == null) {
|
||||
this.populationChangedEventListeners = new Vector<InterfacePopulationChangedEventListener>();
|
||||
}
|
||||
this.m_Listener.add(ea);
|
||||
this.populationChangedEventListeners.add(ea);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removePopulationChangedEventListener(
|
||||
InterfacePopulationChangedEventListener ea) {
|
||||
if (m_Listener != null && m_Listener.removeElement(ea)) {
|
||||
if (populationChangedEventListeners != null && populationChangedEventListeners.removeElement(ea)) {
|
||||
|
||||
return true;
|
||||
} else {
|
||||
@ -702,9 +702,9 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
|
||||
* @param name
|
||||
*/
|
||||
protected void firePropertyChangedEvent(String name) {
|
||||
if (this.m_Listener != null) {
|
||||
for (int i = 0; i < this.m_Listener.size(); i++) {
|
||||
this.m_Listener.get(i).registerPopulationStateChanged(this, name);
|
||||
if (this.populationChangedEventListeners != null) {
|
||||
for (int i = 0; i < this.populationChangedEventListeners.size(); i++) {
|
||||
this.populationChangedEventListeners.get(i).registerPopulationStateChanged(this, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -747,12 +747,12 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
|
||||
*/
|
||||
@Override
|
||||
public void setIdentifier(String name) {
|
||||
this.m_Identifier = name;
|
||||
this.identifier = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return this.m_Identifier;
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -854,17 +854,17 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
|
||||
* @param l
|
||||
*/
|
||||
public void setMt(double l) {
|
||||
this.m_Mt = l;
|
||||
if (this.m_Mt < 0) {
|
||||
this.m_Mt = 0;
|
||||
this.mt = l;
|
||||
if (this.mt < 0) {
|
||||
this.mt = 0;
|
||||
}
|
||||
if (this.m_Mt > 1) {
|
||||
this.m_Mt = 1;
|
||||
if (this.mt > 1) {
|
||||
this.mt = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public double getMt() {
|
||||
return this.m_Mt;
|
||||
return this.mt;
|
||||
}
|
||||
|
||||
public String mtTipText() {
|
||||
|
@ -164,44 +164,44 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
|
||||
resetFitness(indy);
|
||||
|
||||
plotIndy(position, null, (Integer) (indy.getData(indexKey)));
|
||||
// if (this.m_Show) {
|
||||
// this.m_Plot.setUnconnectedPoint(position[0], position[1], (Integer)(indy.getData(indexKey)));
|
||||
//this.m_Plot.setConnectedPoint(curPosition[0] + curVelocity[0], curPosition[1] + curVelocity[1], index+1);
|
||||
// if (this.show) {
|
||||
// this.plot.setUnconnectedPoint(position[0], position[1], (Integer)(indy.getData(indexKey)));
|
||||
//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]);
|
||||
}
|
||||
|
||||
private void plotBestIndy() {
|
||||
if (m_Plot != null) {
|
||||
if (plot != null) {
|
||||
double[] curPosition = ((InterfaceDataTypeDouble) population.getBestEAIndividual()).getDoubleData();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void plotIndy(double[] curPosition, double[] curVelocity, int index) {
|
||||
if (this.m_Show) {
|
||||
if (this.show) {
|
||||
if (plotBestOnly) {
|
||||
if (index != ((Integer) (population.getBestEAIndividual().getData(indexKey)))) {
|
||||
return;
|
||||
} else {
|
||||
// if (lastBestPlot != null) this.m_Plot.setConnectedPoint(lastBestPlot[0], lastBestPlot[1], index);
|
||||
// this.m_Plot.setConnectedPoint(curPosition[0], curPosition[1], index);
|
||||
this.m_Plot.setUnconnectedPoint(curPosition[0], curPosition[1], index);
|
||||
// if (lastBestPlot != null) this.plot.setConnectedPoint(lastBestPlot[0], lastBestPlot[1], index);
|
||||
// this.plot.setConnectedPoint(curPosition[0], curPosition[1], index);
|
||||
this.plot.setUnconnectedPoint(curPosition[0], curPosition[1], index);
|
||||
lastBestPlot = curPosition.clone();
|
||||
}
|
||||
} else {
|
||||
if (curVelocity == null) {
|
||||
|
||||
this.m_Plot.setUnconnectedPoint(curPosition[0], curPosition[1], index);
|
||||
this.plot.setUnconnectedPoint(curPosition[0], curPosition[1], index);
|
||||
} else {
|
||||
this.m_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], curPosition[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) {
|
||||
double chi;
|
||||
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++) {
|
||||
// the component from the old velocity
|
||||
curVelocity[i] = this.inertnessOrChi * lastVelocity[i];
|
||||
@ -401,7 +393,7 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
|
||||
protected void evaluatePopulation(Population population) {
|
||||
envHasChanged = false;
|
||||
super.evaluatePopulation(population);
|
||||
if (m_Show && plotBestOnly) {
|
||||
if (show && plotBestOnly) {
|
||||
plotBestIndy();
|
||||
}
|
||||
|
||||
@ -427,11 +419,11 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
|
||||
@Override
|
||||
protected void logBestIndividual() {
|
||||
// log the best individual of the population
|
||||
if (envHasChanged || (this.population.getBestEAIndividual().isDominatingDebConstraints(this.m_BestIndividual))) {
|
||||
this.m_BestIndividual = (AbstractEAIndividual) this.population.getBestEAIndividual().clone();
|
||||
this.m_BestIndividual.putData(partBestFitKey, this.m_BestIndividual.getFitness());
|
||||
this.m_BestIndividual.putData(partBestPosKey, ((InterfaceDataTypeDouble) this.m_BestIndividual).getDoubleData());
|
||||
//System.out.println("-- best ind set to " + ((InterfaceDataTypeDouble)this.m_BestIndividual).getDoubleData()[0] + "/" + ((InterfaceDataTypeDouble)this.m_BestIndividual).getDoubleData()[1]);
|
||||
if (envHasChanged || (this.population.getBestEAIndividual().isDominatingDebConstraints(this.bestIndividual))) {
|
||||
this.bestIndividual = (AbstractEAIndividual) this.population.getBestEAIndividual().clone();
|
||||
this.bestIndividual.putData(partBestFitKey, this.bestIndividual.getFitness());
|
||||
this.bestIndividual.putData(partBestPosKey, ((InterfaceDataTypeDouble) this.bestIndividual).getDoubleData());
|
||||
//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() {
|
||||
StringBuilder strB = new StringBuilder(200);
|
||||
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(this.population.getStringRepresentation());
|
||||
return strB.toString();
|
||||
@ -686,7 +678,7 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
|
||||
}
|
||||
|
||||
public Plot getPlot() {
|
||||
return m_Plot;
|
||||
return plot;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -23,28 +23,28 @@ import eva2.util.annotation.Description;
|
||||
public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable {
|
||||
// These variables are necessary for the simple testcase
|
||||
|
||||
private InterfaceOptimizationProblem m_Problem = new B1Problem();
|
||||
private int m_MultiRuns = 100;
|
||||
private int m_FitnessCalls = 100;
|
||||
private int m_FitnessCallsNeeded = 0;
|
||||
GAIndividualBinaryData m_Best, m_Test;
|
||||
public double m_InitialFloodPeak = 2000.0, m_CurrentFloodPeak;
|
||||
public double m_DrainRate = 1.0;
|
||||
private InterfaceOptimizationProblem optimizationProblem = new B1Problem();
|
||||
private int multiRuns = 100;
|
||||
private int fitnessCalls = 100;
|
||||
private int fitnessCallsNeeded = 0;
|
||||
GAIndividualBinaryData bestIndividual, testIndividual;
|
||||
public double initialFloodPeak = 2000.0, currentFloodPeak;
|
||||
public double drainRate = 1.0;
|
||||
// These variables are necessary for the more complex LectureGUI enviroment
|
||||
transient private String m_Identifier = "";
|
||||
transient private InterfacePopulationChangedEventListener m_Listener;
|
||||
private Population m_Population;
|
||||
transient private String identifier = "";
|
||||
transient private InterfacePopulationChangedEventListener listener;
|
||||
private Population population;
|
||||
|
||||
public FloodAlgorithm() {
|
||||
this.m_Population = new Population();
|
||||
this.m_Population.setTargetSize(10);
|
||||
this.population = new Population();
|
||||
this.population.setTargetSize(10);
|
||||
}
|
||||
|
||||
public FloodAlgorithm(FloodAlgorithm a) {
|
||||
this.m_Population = (Population) a.m_Population.clone();
|
||||
this.m_Problem = (InterfaceOptimizationProblem) a.m_Problem.clone();
|
||||
this.m_InitialFloodPeak = a.m_InitialFloodPeak;
|
||||
this.m_DrainRate = a.m_DrainRate;
|
||||
this.population = (Population) a.population.clone();
|
||||
this.optimizationProblem = (InterfaceOptimizationProblem) a.optimizationProblem.clone();
|
||||
this.initialFloodPeak = a.initialFloodPeak;
|
||||
this.drainRate = a.drainRate;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -57,9 +57,9 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
|
||||
*/
|
||||
@Override
|
||||
public void init() {
|
||||
this.m_Problem.initializePopulation(this.m_Population);
|
||||
this.m_Problem.evaluate(this.m_Population);
|
||||
this.m_CurrentFloodPeak = this.m_InitialFloodPeak;
|
||||
this.optimizationProblem.initializePopulation(this.population);
|
||||
this.optimizationProblem.evaluate(this.population);
|
||||
this.currentFloodPeak = this.initialFloodPeak;
|
||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
|
||||
}
|
||||
|
||||
@ -70,13 +70,13 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
|
||||
*/
|
||||
@Override
|
||||
public void initByPopulation(Population pop, boolean reset) {
|
||||
this.m_Population = (Population) pop.clone();
|
||||
this.population = (Population) pop.clone();
|
||||
if (reset) {
|
||||
this.m_Population.init();
|
||||
this.m_Problem.evaluate(this.m_Population);
|
||||
this.population.init();
|
||||
this.optimizationProblem.evaluate(this.population);
|
||||
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
|
||||
public void optimize() {
|
||||
AbstractEAIndividual indy;
|
||||
Population original = (Population) this.m_Population.clone();
|
||||
Population original = (Population) this.population.clone();
|
||||
double[] fitness;
|
||||
|
||||
for (int i = 0; i < this.m_Population.size(); i++) {
|
||||
indy = ((AbstractEAIndividual) this.m_Population.get(i));
|
||||
for (int i = 0; i < this.population.size(); i++) {
|
||||
indy = ((AbstractEAIndividual) this.population.get(i));
|
||||
double tmpD = indy.getMutationProbability();
|
||||
indy.setMutationProbability(1.0);
|
||||
indy.mutate();
|
||||
indy.setMutationProbability(tmpD);
|
||||
}
|
||||
this.m_Problem.evaluate(this.m_Population);
|
||||
for (int i = 0; i < this.m_Population.size(); i++) {
|
||||
fitness = ((AbstractEAIndividual) this.m_Population.get(i)).getFitness();
|
||||
if (fitness[0] > this.m_CurrentFloodPeak) {
|
||||
this.m_Population.remove(i);
|
||||
this.m_Population.add(i, original.get(i));
|
||||
this.optimizationProblem.evaluate(this.population);
|
||||
for (int i = 0; i < this.population.size(); i++) {
|
||||
fitness = ((AbstractEAIndividual) this.population.get(i)).getFitness();
|
||||
if (fitness[0] > this.currentFloodPeak) {
|
||||
this.population.remove(i);
|
||||
this.population.add(i, original.get(i));
|
||||
}
|
||||
}
|
||||
this.m_CurrentFloodPeak -= this.m_DrainRate;
|
||||
this.m_Population.incrGeneration();
|
||||
this.currentFloodPeak -= this.drainRate;
|
||||
this.population.incrGeneration();
|
||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
|
||||
}
|
||||
|
||||
@ -132,36 +132,36 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
|
||||
*/
|
||||
@Override
|
||||
public void setProblem(InterfaceOptimizationProblem problem) {
|
||||
this.m_Problem = problem;
|
||||
this.optimizationProblem = problem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InterfaceOptimizationProblem getProblem() {
|
||||
return this.m_Problem;
|
||||
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(m_Problem);
|
||||
this.fitnessCallsNeeded = 0;
|
||||
this.bestIndividual = new GAIndividualBinaryData();
|
||||
this.bestIndividual.defaultInit(optimizationProblem);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will optimize
|
||||
*/
|
||||
public void defaultOptimize() {
|
||||
for (int i = 0; i < m_FitnessCalls; 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;
|
||||
for (int i = 0; i < fitnessCalls; i++) {
|
||||
this.testIndividual = (GAIndividualBinaryData) ((this.bestIndividual).clone());
|
||||
this.testIndividual.defaultMutate();
|
||||
if (this.testIndividual.defaultEvaulateAsMiniBits() < this.bestIndividual.defaultEvaulateAsMiniBits()) {
|
||||
this.bestIndividual = this.testIndividual;
|
||||
}
|
||||
this.m_FitnessCallsNeeded = i;
|
||||
if (this.m_Best.defaultEvaulateAsMiniBits() == 0) {
|
||||
i = this.m_FitnessCalls + 1;
|
||||
this.fitnessCallsNeeded = i;
|
||||
if (this.bestIndividual.defaultEvaulateAsMiniBits() == 0) {
|
||||
i = this.fitnessCalls + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -174,15 +174,15 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
|
||||
public static void main(String[] args) {
|
||||
FloodAlgorithm program = new FloodAlgorithm();
|
||||
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.defaultOptimize();
|
||||
TmpMeanCalls += program.m_FitnessCallsNeeded;
|
||||
TmpMeanFitness += program.m_Best.defaultEvaulateAsMiniBits();
|
||||
TmpMeanCalls += program.fitnessCallsNeeded;
|
||||
TmpMeanFitness += program.bestIndividual.defaultEvaulateAsMiniBits();
|
||||
}
|
||||
TmpMeanCalls /= program.m_MultiRuns;
|
||||
TmpMeanFitness /= program.m_MultiRuns;
|
||||
System.out.println("(" + program.m_MultiRuns + "/" + program.m_FitnessCalls + ") Mean Fitness : " + TmpMeanFitness + " Mean Calls needed: " + TmpMeanCalls);
|
||||
TmpMeanCalls /= program.multiRuns;
|
||||
TmpMeanFitness /= program.multiRuns;
|
||||
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
|
||||
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
|
||||
this.m_Listener = ea;
|
||||
this.listener = ea;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removePopulationChangedEventListener(
|
||||
InterfacePopulationChangedEventListener ea) {
|
||||
if (m_Listener == ea) {
|
||||
m_Listener = null;
|
||||
if (listener == ea) {
|
||||
listener = null;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@ -210,8 +210,8 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
|
||||
* Something has changed
|
||||
*/
|
||||
protected void firePropertyChangedEvent(String name) {
|
||||
if (this.m_Listener != null) {
|
||||
this.m_Listener.registerPopulationStateChanged(this, name);
|
||||
if (this.listener != null) {
|
||||
this.listener.registerPopulationStateChanged(this, name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -224,14 +224,14 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
|
||||
@Override
|
||||
public String getStringRepresentation() {
|
||||
String result = "";
|
||||
if (this.m_Population.size() > 1) {
|
||||
result += "Multi(" + this.m_Population.size() + ")-Start Hill Climbing:\n";
|
||||
if (this.population.size() > 1) {
|
||||
result += "Multi(" + this.population.size() + ")-Start Hill Climbing:\n";
|
||||
} else {
|
||||
result += "Simulated Annealing:\n";
|
||||
}
|
||||
result += "Optimization Problem: ";
|
||||
result += this.m_Problem.getStringRepresentationForProblem(this) + "\n";
|
||||
result += this.m_Population.getStringRepresentation();
|
||||
result += this.optimizationProblem.getStringRepresentationForProblem(this) + "\n";
|
||||
result += this.population.getStringRepresentation();
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -242,12 +242,12 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
|
||||
*/
|
||||
@Override
|
||||
public void setIdentifier(String name) {
|
||||
this.m_Identifier = name;
|
||||
this.identifier = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return this.m_Identifier;
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -269,12 +269,12 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
|
||||
*/
|
||||
@Override
|
||||
public Population getPopulation() {
|
||||
return this.m_Population;
|
||||
return this.population;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPopulation(Population pop) {
|
||||
this.m_Population = pop;
|
||||
this.population = pop;
|
||||
}
|
||||
|
||||
public String populationTipText() {
|
||||
@ -293,11 +293,11 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
|
||||
* @return The initial flood level.
|
||||
*/
|
||||
public double getInitialFloodPeak() {
|
||||
return this.m_InitialFloodPeak;
|
||||
return this.initialFloodPeak;
|
||||
}
|
||||
|
||||
public void setInitialFloodPeak(double pop) {
|
||||
this.m_InitialFloodPeak = pop;
|
||||
this.initialFloodPeak = pop;
|
||||
}
|
||||
|
||||
public String initialFloodPeakTipText() {
|
||||
@ -311,13 +311,13 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
|
||||
* @return The drain rate.
|
||||
*/
|
||||
public double getDrainRate() {
|
||||
return this.m_DrainRate;
|
||||
return this.drainRate;
|
||||
}
|
||||
|
||||
public void setDrainRate(double a) {
|
||||
this.m_DrainRate = a;
|
||||
if (this.m_DrainRate < 0) {
|
||||
this.m_DrainRate = 0.0;
|
||||
this.drainRate = a;
|
||||
if (this.drainRate < 0) {
|
||||
this.drainRate = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,8 +24,8 @@ import eva2.util.annotation.Description;
|
||||
@Description("Gradient Descent can be applied to derivable functions (InterfaceFirstOrderDerivableProblem).")
|
||||
public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Serializable {
|
||||
|
||||
private InterfaceOptimizationProblem m_Problem;
|
||||
InterfaceDataTypeDouble m_Best, m_Test;
|
||||
private InterfaceOptimizationProblem optimizationProblem;
|
||||
InterfaceDataTypeDouble bestDataTypeDouble, testDataTypeDouble;
|
||||
private int iterations = 1;
|
||||
private double wDecreaseStepSize = 0.5;
|
||||
private double wIncreaseStepSize = 1.1;
|
||||
@ -41,12 +41,12 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
|
||||
double localmaxstepsize = 10;
|
||||
double localminstepsize = 1e-10;
|
||||
private boolean momentumterm = false;
|
||||
transient private InterfacePopulationChangedEventListener m_Listener;
|
||||
transient private InterfacePopulationChangedEventListener populationChangedEventListener;
|
||||
public double maximumabsolutechange = 0.2;
|
||||
// Hashtable indyhash;
|
||||
// These variables are necessary for the more complex LectureGUI enviroment
|
||||
transient private String m_Identifier = "";
|
||||
private Population m_Population;
|
||||
transient private String identifier = "";
|
||||
private Population population;
|
||||
private static boolean TRACE = false;
|
||||
private static final String lockKey = "gdaLockDataKey";
|
||||
private static final String lastFitnessKey = "gdaLastFitDataKey";
|
||||
@ -61,7 +61,7 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
|
||||
this.setPopulation((Population) pop.clone());
|
||||
if (reset) {
|
||||
this.getPopulation().init();
|
||||
this.m_Problem.evaluate(this.getPopulation());
|
||||
this.optimizationProblem.evaluate(this.getPopulation());
|
||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
|
||||
}
|
||||
//System.out.println("initByPopulation() called");
|
||||
@ -70,8 +70,8 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
|
||||
|
||||
public GradientDescentAlgorithm() {
|
||||
// indyhash = new Hashtable();
|
||||
this.m_Population = new Population();
|
||||
this.m_Population.setTargetSize(1);
|
||||
this.population = new Population();
|
||||
this.population.setTargetSize(1);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -108,8 +108,8 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
|
||||
public void init() {
|
||||
//System.out.println("init() called ");
|
||||
// indyhash = new Hashtable();
|
||||
this.m_Problem.initializePopulation(this.m_Population);
|
||||
this.m_Problem.evaluate(this.m_Population);
|
||||
this.optimizationProblem.initializePopulation(this.population);
|
||||
this.optimizationProblem.evaluate(this.population);
|
||||
}
|
||||
|
||||
public double signum(double val) {
|
||||
@ -122,8 +122,8 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
|
||||
AbstractEAIndividual indy;
|
||||
// if ((this.indyhash == null) || (this.indyhash.size() <1)) init();
|
||||
|
||||
for (int i = 0; i < this.m_Population.size(); i++) {
|
||||
indy = ((AbstractEAIndividual) this.m_Population.get(i));
|
||||
for (int i = 0; i < this.population.size(); i++) {
|
||||
indy = ((AbstractEAIndividual) this.population.get(i));
|
||||
if (!indy.hasData(gradientKey)) {
|
||||
//System.out.println("new indy to hash");
|
||||
// Hashtable history = new Hashtable();
|
||||
@ -146,9 +146,9 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
|
||||
}
|
||||
}
|
||||
// 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[] params = ((InterfaceDataTypeDouble) indy).getDoubleData();
|
||||
indy.putData(oldParamsKey, params);
|
||||
@ -157,7 +157,7 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
|
||||
double indystepsize = ((Double) indy.getData(stepSizeKey)).doubleValue();
|
||||
// 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);
|
||||
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[] oldchange = null;
|
||||
|
||||
double[] gradient = ((InterfaceFirstOrderDerivableProblem) m_Problem).getFirstOrderGradients(params);
|
||||
double[] gradient = ((InterfaceFirstOrderDerivableProblem) optimizationProblem).getFirstOrderGradients(params);
|
||||
if (TRACE) {
|
||||
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
|
||||
|
||||
this.m_Problem.evaluate(this.m_Population);
|
||||
m_Population.incrGeneration();
|
||||
this.optimizationProblem.evaluate(this.population);
|
||||
population.incrGeneration();
|
||||
|
||||
if (this.recovery) {
|
||||
for (int i = 0; i < this.m_Population.size(); i++) {
|
||||
indy = ((AbstractEAIndividual) this.m_Population.get(i));
|
||||
for (int i = 0; i < this.population.size(); i++) {
|
||||
indy = ((AbstractEAIndividual) this.population.get(i));
|
||||
// Hashtable history = (Hashtable) indyhash.get(indy);
|
||||
if (indy.getFitness()[0] > recoverythreshold) {
|
||||
if (TRACE) {
|
||||
@ -273,15 +273,15 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
|
||||
} else {
|
||||
}
|
||||
}
|
||||
this.m_Problem.evaluate(this.m_Population);
|
||||
m_Population.incrGeneration();
|
||||
this.optimizationProblem.evaluate(this.population);
|
||||
population.incrGeneration();
|
||||
}
|
||||
|
||||
if (this.globalStepSizeAdaption) {
|
||||
|
||||
//System.out.println("gsa main");
|
||||
for (int i = 0; i < this.m_Population.size(); i++) {
|
||||
indy = ((AbstractEAIndividual) this.m_Population.get(i));
|
||||
for (int i = 0; i < this.population.size(); i++) {
|
||||
indy = ((AbstractEAIndividual) this.population.get(i));
|
||||
// Hashtable history = (Hashtable) indyhash.get(indy);
|
||||
// if (history == null) break;
|
||||
if (indy.getData(lastFitnessKey) != null) {
|
||||
@ -312,14 +312,14 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
|
||||
private double momentumweigth = 0.1;
|
||||
|
||||
protected void firePropertyChangedEvent(String name) {
|
||||
if (this.m_Listener != null) {
|
||||
this.m_Listener.registerPopulationStateChanged(this, name);
|
||||
if (this.populationChangedEventListener != null) {
|
||||
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Population getPopulation() {
|
||||
return this.m_Population;
|
||||
return this.population;
|
||||
}
|
||||
|
||||
@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)));
|
||||
// }
|
||||
// indyhash = newindyhash;
|
||||
this.m_Population = pop;
|
||||
this.population = pop;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -344,23 +344,23 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
|
||||
*/
|
||||
@Override
|
||||
public void setIdentifier(String name) {
|
||||
this.m_Identifier = name;
|
||||
this.identifier = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return this.m_Identifier;
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProblem(InterfaceOptimizationProblem problem) {
|
||||
|
||||
m_Problem = problem;
|
||||
optimizationProblem = problem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InterfaceOptimizationProblem getProblem() {
|
||||
return m_Problem;
|
||||
return optimizationProblem;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -370,14 +370,14 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
|
||||
|
||||
@Override
|
||||
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
|
||||
this.m_Listener = ea;
|
||||
this.populationChangedEventListener = ea;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removePopulationChangedEventListener(
|
||||
InterfacePopulationChangedEventListener ea) {
|
||||
if (m_Listener == ea) {
|
||||
m_Listener = null;
|
||||
if (populationChangedEventListener == ea) {
|
||||
populationChangedEventListener = null;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -140,43 +140,6 @@ public class HillClimbing implements InterfaceOptimizer, java.io.Serializable {
|
||||
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
|
||||
*
|
||||
|
@ -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.")
|
||||
public class IslandModelEA implements InterfacePopulationChangedEventListener, InterfaceOptimizer, java.io.Serializable {
|
||||
|
||||
private Population m_Population = new Population();
|
||||
private InterfaceOptimizer m_Optimizer = new GeneticAlgorithm();
|
||||
private InterfaceMigration m_Migration = new SOBestMigration();
|
||||
private InterfaceOptimizationProblem m_Problem = new F8Problem();
|
||||
private Population population = new Population();
|
||||
private InterfaceOptimizer optimizer = new GeneticAlgorithm();
|
||||
private InterfaceMigration migration = new SOBestMigration();
|
||||
private InterfaceOptimizationProblem optimizationProblem = new F8Problem();
|
||||
// private String[] m_NodesList;
|
||||
private int m_MigrationRate = 10;
|
||||
private int migrationRate = 10;
|
||||
private boolean heterogeneousProblems = false;
|
||||
// These are the processor to run on
|
||||
private int m_numLocalCPUs = 1;
|
||||
private boolean m_localOnly = false;
|
||||
transient private InterfaceOptimizer[] m_Islands;
|
||||
private int numLocalCPUs = 1;
|
||||
private boolean numLocalOnly = false;
|
||||
transient private InterfaceOptimizer[] islands;
|
||||
// This is for debugging
|
||||
private boolean m_LogLocalChanges = true;
|
||||
private boolean m_Show = false;
|
||||
transient private Plot m_Plot = null;
|
||||
transient private String m_Identifier = "";
|
||||
transient private InterfacePopulationChangedEventListener m_Listener;
|
||||
private boolean logLocalChanges = true;
|
||||
private boolean show = false;
|
||||
transient private Plot plot = null;
|
||||
transient private String identifier = "";
|
||||
transient private InterfacePopulationChangedEventListener populationChangedEventListener;
|
||||
transient private final boolean TRACE = false;
|
||||
|
||||
public IslandModelEA() {
|
||||
}
|
||||
|
||||
public IslandModelEA(IslandModelEA a) {
|
||||
this.m_Population = (Population) a.m_Population.clone();
|
||||
this.m_Problem = (InterfaceOptimizationProblem) a.m_Problem.clone();
|
||||
this.m_Optimizer = (InterfaceOptimizer) a.m_Optimizer.clone();
|
||||
this.m_Migration = (InterfaceMigration) a.m_Migration.clone();
|
||||
this.m_MigrationRate = a.m_MigrationRate;
|
||||
this.population = (Population) a.population.clone();
|
||||
this.optimizationProblem = (InterfaceOptimizationProblem) a.optimizationProblem.clone();
|
||||
this.optimizer = (InterfaceOptimizer) a.optimizer.clone();
|
||||
this.migration = (InterfaceMigration) a.migration.clone();
|
||||
this.migrationRate = a.migrationRate;
|
||||
this.heterogeneousProblems = a.heterogeneousProblems;
|
||||
this.m_numLocalCPUs = a.m_numLocalCPUs;
|
||||
this.m_localOnly = a.m_localOnly;
|
||||
this.numLocalCPUs = a.numLocalCPUs;
|
||||
this.numLocalOnly = a.numLocalOnly;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -74,31 +74,31 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
if (this.m_Show) {
|
||||
if (this.m_Plot == null) {
|
||||
if (this.show) {
|
||||
if (this.plot == null) {
|
||||
double[] tmpD = new double[2];
|
||||
tmpD[0] = 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.m_Population.clear();
|
||||
this.m_Population.init();
|
||||
this.m_Optimizer.init();
|
||||
this.m_Optimizer.setProblem(this.m_Problem);
|
||||
this.m_Optimizer.setPopulation((Population) m_Population.clone());
|
||||
this.population.clear();
|
||||
this.population.init();
|
||||
this.optimizer.init();
|
||||
this.optimizer.setProblem(this.optimizationProblem);
|
||||
this.optimizer.setPopulation((Population) population.clone());
|
||||
InterfacePopulationChangedEventListener myLocal = null;
|
||||
if (this.m_localOnly) {
|
||||
if (this.numLocalOnly) {
|
||||
// this is running on the local machine
|
||||
this.m_Islands = new InterfaceOptimizer[this.m_numLocalCPUs];
|
||||
for (int i = 0; i < this.m_numLocalCPUs; i++) {
|
||||
this.m_Islands[i] = (InterfaceOptimizer) this.m_Optimizer.clone();
|
||||
this.m_Islands[i].setIdentifier("" + i);
|
||||
this.m_Islands[i].init();
|
||||
if (this.m_LogLocalChanges) {
|
||||
this.m_Islands[i].addPopulationChangedEventListener(this);
|
||||
this.islands = new InterfaceOptimizer[this.numLocalCPUs];
|
||||
for (int i = 0; i < this.numLocalCPUs; i++) {
|
||||
this.islands[i] = (InterfaceOptimizer) this.optimizer.clone();
|
||||
this.islands[i].setIdentifier("" + i);
|
||||
this.islands[i].init();
|
||||
if (this.logLocalChanges) {
|
||||
this.islands[i].addPopulationChangedEventListener(this);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -116,30 +116,30 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
|
||||
if ((nodesList == null) || (nodesList.length == 0)) {
|
||||
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++) {
|
||||
this.m_Islands[i] = (InterfaceOptimizer) RMIProxyRemoteThread.newInstance(this.optimizer, nodesList[i]);
|
||||
this.m_Islands[i].setIdentifier(""+i);
|
||||
this.m_Islands[i].init();
|
||||
if (this.m_LogLocalChanges) {
|
||||
this.m_Islands[i].addPopulationChangedEventListener(myLocal);
|
||||
this.islands[i] = (InterfaceOptimizer) RMIProxyRemoteThread.newInstance(this.optimizer, nodesList[i]);
|
||||
this.islands[i].setIdentifier(""+i);
|
||||
this.islands[i].init();
|
||||
if (this.logLocalChanges) {
|
||||
this.islands[i].addPopulationChangedEventListener(myLocal);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
this.m_Migration.initMigration(this.m_Islands);
|
||||
this.migration.initMigration(this.islands);
|
||||
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++) {
|
||||
pop = (Population) this.m_Islands[i].getPopulation().clone();
|
||||
this.m_Population.addPopulation(pop);
|
||||
this.m_Population.incrFunctionCallsBy(pop.getFunctionCalls());
|
||||
if (m_Islands[i].getPopulation().getGeneration() != m_Population.getGeneration()) {
|
||||
for (int i = 0; i < this.islands.length; i++) {
|
||||
pop = (Population) this.islands[i].getPopulation().clone();
|
||||
this.population.addPopulation(pop);
|
||||
this.population.incrFunctionCallsBy(pop.getFunctionCalls());
|
||||
if (islands[i].getPopulation().getGeneration() != population.getGeneration()) {
|
||||
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
|
||||
public void initByPopulation(Population tpop, boolean reset) {
|
||||
// TODO this is again evil copy&paste style
|
||||
if (this.m_Show) {
|
||||
if (this.m_Plot == null) {
|
||||
if (this.show) {
|
||||
if (this.plot == null) {
|
||||
double[] tmpD = new double[2];
|
||||
tmpD[0] = 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) {
|
||||
this.m_Population.init();
|
||||
this.m_Population.incrGeneration();
|
||||
this.population.init();
|
||||
this.population.incrGeneration();
|
||||
}
|
||||
this.m_Optimizer.init();
|
||||
this.m_Optimizer.setProblem(this.m_Problem);
|
||||
this.optimizer.init();
|
||||
this.optimizer.setProblem(this.optimizationProblem);
|
||||
InterfacePopulationChangedEventListener myLocal = null;
|
||||
if (this.m_localOnly) {
|
||||
if (this.numLocalOnly) {
|
||||
// this is running on the local machine
|
||||
this.m_Islands = new InterfaceOptimizer[this.m_numLocalCPUs];
|
||||
for (int i = 0; i < this.m_numLocalCPUs; i++) {
|
||||
this.m_Islands[i] = (InterfaceOptimizer) this.m_Optimizer.clone();
|
||||
this.m_Islands[i].setIdentifier("" + i);
|
||||
this.m_Islands[i].init();
|
||||
if (this.m_LogLocalChanges) {
|
||||
this.m_Islands[i].addPopulationChangedEventListener(this);
|
||||
this.islands = new InterfaceOptimizer[this.numLocalCPUs];
|
||||
for (int i = 0; i < this.numLocalCPUs; i++) {
|
||||
this.islands[i] = (InterfaceOptimizer) this.optimizer.clone();
|
||||
this.islands[i].setIdentifier("" + i);
|
||||
this.islands[i].init();
|
||||
if (this.logLocalChanges) {
|
||||
this.islands[i].addPopulationChangedEventListener(this);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -194,25 +194,25 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
|
||||
if ((nodesList == null) || (nodesList.length == 0)) {
|
||||
return;
|
||||
}
|
||||
this.m_Islands = new InterfaceOptimizer[nodesList.length];
|
||||
this.islands = new InterfaceOptimizer[nodesList.length];
|
||||
for (int i = 0; i < nodesList.length; i++) {
|
||||
this.m_Islands[i] = (InterfaceOptimizer) RMIProxyRemoteThread.newInstance(this.optimizer, nodesList[i]);
|
||||
this.m_Islands[i].setIdentifier(""+i);
|
||||
this.m_Islands[i].init();
|
||||
if (this.m_LogLocalChanges) {
|
||||
this.m_Islands[i].addPopulationChangedEventListener(myLocal);
|
||||
this.islands[i] = (InterfaceOptimizer) RMIProxyRemoteThread.newInstance(this.optimizer, nodesList[i]);
|
||||
this.islands[i].setIdentifier(""+i);
|
||||
this.islands[i].init();
|
||||
if (this.logLocalChanges) {
|
||||
this.islands[i].addPopulationChangedEventListener(myLocal);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
this.m_Migration.initMigration(this.m_Islands);
|
||||
this.migration.initMigration(this.islands);
|
||||
Population pop;
|
||||
for (int i = 0; i < this.m_Islands.length; i++) {
|
||||
pop = (Population) this.m_Islands[i].getPopulation().clone();
|
||||
this.m_Population.addPopulation(pop);
|
||||
this.m_Population.incrFunctionCallsBy(pop.getFunctionCalls());
|
||||
for (int i = 0; i < this.islands.length; i++) {
|
||||
pop = (Population) this.islands[i].getPopulation().clone();
|
||||
this.population.addPopulation(pop);
|
||||
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
|
||||
public void optimize() {
|
||||
for (int i = 0; i < this.m_Islands.length; i++) {
|
||||
if (this.m_Islands[i].getPopulation().size() > 0) {
|
||||
this.m_Islands[i].optimize();
|
||||
for (int i = 0; i < this.islands.length; i++) {
|
||||
if (this.islands[i].getPopulation().size() > 0) {
|
||||
this.islands[i].optimize();
|
||||
if (TRACE) {
|
||||
System.out.println(BeanInspector.toString(m_Islands[i].getPopulation()));
|
||||
System.out.println(BeanInspector.toString(islands[i].getPopulation()));
|
||||
}
|
||||
} else {
|
||||
this.m_Islands[i].getPopulation().incrGeneration();
|
||||
this.islands[i].getPopulation().incrGeneration();
|
||||
}
|
||||
if (TRACE) {
|
||||
System.out.println("----");
|
||||
}
|
||||
}
|
||||
this.m_Population.incrGeneration();
|
||||
if ((this.m_Population.getGeneration() % this.m_MigrationRate) == 0) {
|
||||
this.population.incrGeneration();
|
||||
if ((this.population.getGeneration() % this.migrationRate) == 0) {
|
||||
this.communicate();
|
||||
}
|
||||
// this is necessary for heterogeneous islands
|
||||
if (this.heterogeneousProblems) {
|
||||
for (int i = 0; i < this.m_Islands.length; i++) {
|
||||
this.m_Islands[i].getProblem().evaluate(this.m_Islands[i].getPopulation());
|
||||
for (int i = 0; i < this.islands.length; i++) {
|
||||
this.islands[i].getProblem().evaluate(this.islands[i].getPopulation());
|
||||
}
|
||||
}
|
||||
System.gc();
|
||||
@ -252,13 +252,13 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
|
||||
private void communicate() {
|
||||
// Here i'll have to wait until all islands are finished
|
||||
boolean allReachedG = false;
|
||||
int G = this.m_Population.getGeneration();
|
||||
int G = this.population.getGeneration();
|
||||
while (!allReachedG) {
|
||||
allReachedG = true;
|
||||
String gen = "[";
|
||||
for (int i = 0; i < this.m_Islands.length; i++) {
|
||||
gen += this.m_Islands[i].getPopulation().getGeneration() + "; ";
|
||||
if (this.m_Islands[i].getPopulation().getGeneration() != G) {
|
||||
for (int i = 0; i < this.islands.length; i++) {
|
||||
gen += this.islands[i].getPopulation().getGeneration() + "; ";
|
||||
if (this.islands[i].getPopulation().getGeneration() != G) {
|
||||
allReachedG = false;
|
||||
}
|
||||
}
|
||||
@ -271,22 +271,22 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
|
||||
}
|
||||
}
|
||||
}
|
||||
this.m_Population.clear();
|
||||
this.m_Population.setFunctionCalls(0);
|
||||
this.population.clear();
|
||||
this.population.setFunctionCalls(0);
|
||||
Population pop;
|
||||
for (int i = 0; i < this.m_Islands.length; i++) {
|
||||
pop = (Population) this.m_Islands[i].getPopulation().clone();
|
||||
this.m_Population.addPopulation(pop);
|
||||
this.m_Population.incrFunctionCallsBy(pop.getFunctionCalls());
|
||||
for (int i = 0; i < this.islands.length; i++) {
|
||||
pop = (Population) this.islands[i].getPopulation().clone();
|
||||
this.population.addPopulation(pop);
|
||||
this.population.incrFunctionCallsBy(pop.getFunctionCalls());
|
||||
}
|
||||
// System.out.println("Fitnesscalls :" + this.population.getFunctionCalls());
|
||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED, this.m_Optimizer.getPopulation());
|
||||
double plotValue = (this.m_Problem.getDoublePlotValue(this.m_Population)).doubleValue();
|
||||
if (this.m_Show) {
|
||||
this.m_Plot.setConnectedPoint(this.m_Population.getFunctionCalls(), plotValue, 0);
|
||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED, this.optimizer.getPopulation());
|
||||
double plotValue = (this.optimizationProblem.getDoublePlotValue(this.population)).doubleValue();
|
||||
if (this.show) {
|
||||
this.plot.setConnectedPoint(this.population.getFunctionCalls(), plotValue, 0);
|
||||
}
|
||||
// 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
|
||||
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
|
||||
this.m_Listener = ea;
|
||||
this.populationChangedEventListener = ea;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removePopulationChangedEventListener(
|
||||
InterfacePopulationChangedEventListener ea) {
|
||||
if (m_Listener == ea) {
|
||||
m_Listener = null;
|
||||
if (populationChangedEventListener == ea) {
|
||||
populationChangedEventListener = null;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@ -314,8 +314,8 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
|
||||
* Something has changed
|
||||
*/
|
||||
protected void firePropertyChangedEvent(String name, Population population) {
|
||||
if (this.m_Listener != null) {
|
||||
this.m_Listener.registerPopulationStateChanged(this, name);
|
||||
if (this.populationChangedEventListener != null) {
|
||||
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -326,13 +326,13 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
|
||||
*/
|
||||
@Override
|
||||
public void setProblem(InterfaceOptimizationProblem problem) {
|
||||
this.m_Problem = problem;
|
||||
this.m_Optimizer.setProblem(problem);
|
||||
this.optimizationProblem = problem;
|
||||
this.optimizer.setProblem(problem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InterfaceOptimizationProblem getProblem() {
|
||||
return this.m_Problem;
|
||||
return this.optimizationProblem;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -346,18 +346,18 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
|
||||
String result = "";
|
||||
result += "Island Model Evolutionary Algorithm:\n";
|
||||
result += "Using:\n";
|
||||
result += " Migration Strategy = " + this.m_Migration.getClass().toString() + "\n";
|
||||
result += " Migration rate = " + this.m_MigrationRate + "\n";
|
||||
result += " Local only = " + this.m_localOnly + "\n";
|
||||
result += " Migration Strategy = " + this.migration.getClass().toString() + "\n";
|
||||
result += " Migration rate = " + this.migrationRate + "\n";
|
||||
result += " Local only = " + this.numLocalOnly + "\n";
|
||||
result += " Het. Problems = " + this.heterogeneousProblems + "\n";
|
||||
if (this.heterogeneousProblems) {
|
||||
result += " Heterogenuous Optimizers: \n";
|
||||
for (int i = 0; i < this.m_Islands.length; i++) {
|
||||
result += this.m_Islands[i].getStringRepresentation() + "\n";
|
||||
for (int i = 0; i < this.islands.length; i++) {
|
||||
result += this.islands[i].getStringRepresentation() + "\n";
|
||||
}
|
||||
} else {
|
||||
result += " Homogeneous Optimizer = " + this.m_Optimizer.getClass().toString() + "\n";
|
||||
result += this.m_Optimizer.getStringRepresentation() + "\n";
|
||||
result += " Homogeneous Optimizer = " + this.optimizer.getClass().toString() + "\n";
|
||||
result += this.optimizer.getStringRepresentation() + "\n";
|
||||
}
|
||||
//result += "=> The Optimization Problem: ";
|
||||
//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 Wichtig ich brauche den eva2.tools.jproxy.RMIServer!
|
||||
IslandModelEA imea = new IslandModelEA();
|
||||
imea.m_Show = true;
|
||||
imea.m_localOnly = false;
|
||||
imea.show = true;
|
||||
imea.numLocalOnly = false;
|
||||
if (false) {
|
||||
imea.m_Optimizer = new MultiObjectiveEA();
|
||||
((MultiObjectiveEA) imea.m_Optimizer).setArchiveSize(25);
|
||||
((MultiObjectiveEA) imea.m_Optimizer).getPopulation().setTargetSize(50);
|
||||
imea.m_Problem = new TF1Problem();
|
||||
((TF1Problem) imea.m_Problem).setEAIndividual(new ESIndividualDoubleData());
|
||||
imea.optimizer = new MultiObjectiveEA();
|
||||
((MultiObjectiveEA) imea.optimizer).setArchiveSize(25);
|
||||
((MultiObjectiveEA) imea.optimizer).getPopulation().setTargetSize(50);
|
||||
imea.optimizationProblem = new TF1Problem();
|
||||
((TF1Problem) imea.optimizationProblem).setEAIndividual(new ESIndividualDoubleData());
|
||||
// ((TF1Problem)imea.problem).setEAIndividual(new ESIndividualDoubleData());
|
||||
// imea.problem = new TFPortfolioSelectionProblem();
|
||||
// ((TFPortfolioSelectionProblem)imea.problem).setEAIndividual(new ESIndividualDoubleData());
|
||||
@ -389,23 +389,23 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
|
||||
MOClusteringSeparation c = new MOClusteringSeparation();
|
||||
c.getKMeans().setUseSearchSpace(false);
|
||||
c.setUseConstraints(true);
|
||||
c.m_Debug = true;
|
||||
imea.m_Migration = c;
|
||||
c.debug = true;
|
||||
imea.migration = c;
|
||||
}
|
||||
if (false) {
|
||||
MOConeSeparation c = new MOConeSeparation();
|
||||
c.setUseConstraints(true);
|
||||
c.m_Debug = true;
|
||||
imea.m_Migration = c;
|
||||
c.debug = true;
|
||||
imea.migration = c;
|
||||
}
|
||||
if (true) {
|
||||
imea.m_Migration = new MOBestMigration();
|
||||
imea.migration = new MOBestMigration();
|
||||
}
|
||||
} else {
|
||||
imea.m_Problem = new F8Problem();
|
||||
((F1Problem) imea.m_Problem).setEAIndividual(new ESIndividualDoubleData());
|
||||
imea.optimizationProblem = new F8Problem();
|
||||
((F1Problem) imea.optimizationProblem).setEAIndividual(new ESIndividualDoubleData());
|
||||
}
|
||||
imea.m_MigrationRate = 15;
|
||||
imea.migrationRate = 15;
|
||||
imea.init();
|
||||
while (imea.getPopulation().getFunctionCalls() < 25000) {
|
||||
imea.optimize();
|
||||
@ -421,12 +421,12 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
|
||||
*/
|
||||
@Override
|
||||
public void setIdentifier(String name) {
|
||||
this.m_Identifier = name;
|
||||
this.identifier = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
*/
|
||||
public InterfaceOptimizer[] getOptimizers() {
|
||||
return this.m_Islands;
|
||||
return this.islands;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -464,14 +464,11 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
|
||||
InterfaceOptimizer opt = (InterfaceOptimizer) source;
|
||||
int sourceID = new Integer(opt.getIdentifier()).intValue();
|
||||
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) {
|
||||
this.m_Plot.setConnectedPoint(cFCOpt, plotValue, (sourceID + 1));
|
||||
if (this.show) {
|
||||
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.
|
||||
// Instead, the new direct problem parallelization can be used.
|
||||
// public boolean isLocalOnly() {
|
||||
// return this.m_localOnly;
|
||||
// return this.numLocalOnly;
|
||||
// }
|
||||
public void setLocalOnly(boolean b) {
|
||||
this.m_localOnly = b;
|
||||
this.numLocalOnly = b;
|
||||
}
|
||||
|
||||
public String localOnlyTipText() {
|
||||
@ -510,12 +507,12 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
|
||||
* @return The current optimzation mode
|
||||
*/
|
||||
public boolean getShow() {
|
||||
return this.m_Show;
|
||||
return this.show;
|
||||
}
|
||||
|
||||
public void setShow(boolean b) {
|
||||
this.m_Show = b;
|
||||
this.m_LogLocalChanges = b;
|
||||
this.show = b;
|
||||
this.logLocalChanges = b;
|
||||
}
|
||||
|
||||
public String showTipText() {
|
||||
@ -528,11 +525,11 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
|
||||
* @return The current optimizing method
|
||||
*/
|
||||
public InterfaceOptimizer getOptimizer() {
|
||||
return this.m_Optimizer;
|
||||
return this.optimizer;
|
||||
}
|
||||
|
||||
public void setOptimizer(InterfaceOptimizer b) {
|
||||
this.m_Optimizer = b;
|
||||
this.optimizer = b;
|
||||
}
|
||||
|
||||
public String optimizerTipText() {
|
||||
@ -545,11 +542,11 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
|
||||
* @return The current migration strategy
|
||||
*/
|
||||
public InterfaceMigration getMigrationStrategy() {
|
||||
return this.m_Migration;
|
||||
return this.migration;
|
||||
}
|
||||
|
||||
public void setMigrationStrategy(InterfaceMigration b) {
|
||||
this.m_Migration = b;
|
||||
this.migration = b;
|
||||
}
|
||||
|
||||
public String migrationStrategyTipText() {
|
||||
@ -562,11 +559,11 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
|
||||
* @return The current migration rate
|
||||
*/
|
||||
public int getMigrationRate() {
|
||||
return this.m_MigrationRate;
|
||||
return this.migrationRate;
|
||||
}
|
||||
|
||||
public void setMigrationRate(int b) {
|
||||
this.m_MigrationRate = b;
|
||||
this.migrationRate = b;
|
||||
}
|
||||
|
||||
public String migrationRateTipText() {
|
||||
@ -586,13 +583,13 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
|
||||
*/
|
||||
@Override
|
||||
public Population getPopulation() {
|
||||
return this.m_Population;
|
||||
return this.population;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPopulation(Population pop) {
|
||||
// @todo Jetzt m<EFBFBD>sste ich die pop auch auf die Rechner verteilen...
|
||||
this.m_Population = pop;
|
||||
this.population = pop;
|
||||
}
|
||||
|
||||
public String populationTipText() {
|
||||
@ -611,7 +608,7 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
|
||||
*/
|
||||
public void setNumberLocalCPUs(int n) {
|
||||
if (n >= 1) {
|
||||
this.m_numLocalCPUs = n;
|
||||
this.numLocalCPUs = n;
|
||||
} else {
|
||||
System.err.println("Number of CPUs must be at least 1!");
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class LTGA implements InterfaceOptimizer, java.io.Serializable, Interface
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(LTGA.class.getName());
|
||||
transient private InterfacePopulationChangedEventListener populationChangedEventListener = null;
|
||||
private String m_Identifier = "LTGA";
|
||||
private String identifier = "LTGA";
|
||||
private int probDim = 8;
|
||||
private int fitCrit = -1;
|
||||
private int popSize = 50;
|
||||
@ -42,7 +42,7 @@ public class LTGA implements InterfaceOptimizer, java.io.Serializable, Interface
|
||||
|
||||
public LTGA(LTGA l) {
|
||||
this.populationChangedEventListener = l.populationChangedEventListener;
|
||||
this.m_Identifier = l.m_Identifier;
|
||||
this.identifier = l.identifier;
|
||||
this.probDim = l.probDim;
|
||||
this.popSize = l.popSize;
|
||||
this.population = (Population) l.population.clone();
|
||||
@ -328,12 +328,12 @@ public class LTGA implements InterfaceOptimizer, java.io.Serializable, Interface
|
||||
|
||||
@Override
|
||||
public void setIdentifier(String name) {
|
||||
this.m_Identifier = name;
|
||||
this.identifier = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return this.m_Identifier;
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,8 +24,8 @@ import java.util.logging.Logger;
|
||||
public class MLTGA implements InterfaceOptimizer, java.io.Serializable, InterfacePopulationChangedEventListener {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(MLTGA.class.getName());
|
||||
transient private InterfacePopulationChangedEventListener m_Listener = null;
|
||||
private String m_Identifier = "LTGA";
|
||||
transient private InterfacePopulationChangedEventListener populationChangedEventListener = null;
|
||||
private String identifier = "MLTGA";
|
||||
private int probDim = 8;
|
||||
private int fitCrit = -1;
|
||||
private int popSize = 50;
|
||||
@ -39,8 +39,8 @@ public class MLTGA implements InterfaceOptimizer, java.io.Serializable, Interfac
|
||||
}
|
||||
|
||||
public MLTGA(MLTGA l) {
|
||||
this.m_Listener = l.m_Listener;
|
||||
this.m_Identifier = l.m_Identifier;
|
||||
this.populationChangedEventListener = l.populationChangedEventListener;
|
||||
this.identifier = l.identifier;
|
||||
this.probDim = l.probDim;
|
||||
this.popSize = l.popSize;
|
||||
this.population = (Population) l.population.clone();
|
||||
@ -65,15 +65,15 @@ public class MLTGA implements InterfaceOptimizer, java.io.Serializable, Interfac
|
||||
@Override
|
||||
public void addPopulationChangedEventListener(
|
||||
InterfacePopulationChangedEventListener ea) {
|
||||
this.m_Listener = ea;
|
||||
this.populationChangedEventListener = ea;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removePopulationChangedEventListener(
|
||||
InterfacePopulationChangedEventListener ea) {
|
||||
if (m_Listener == ea) {
|
||||
m_Listener = null;
|
||||
if (populationChangedEventListener == ea) {
|
||||
populationChangedEventListener = null;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@ -287,8 +287,8 @@ public class MLTGA implements InterfaceOptimizer, java.io.Serializable, Interfac
|
||||
* Something has changed
|
||||
*/
|
||||
protected void firePropertyChangedEvent(String name) {
|
||||
if (this.m_Listener != null) {
|
||||
this.m_Listener.registerPopulationStateChanged(this, name);
|
||||
if (this.populationChangedEventListener != null) {
|
||||
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -309,12 +309,12 @@ public class MLTGA implements InterfaceOptimizer, java.io.Serializable, Interfac
|
||||
|
||||
@Override
|
||||
public void setIdentifier(String name) {
|
||||
this.m_Identifier = name;
|
||||
this.identifier = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return this.m_Identifier;
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,7 +19,6 @@ import java.util.Hashtable;
|
||||
* be applied to problems which implement the InterfaceLocalSearchable else the
|
||||
* 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 "
|
||||
+ "of individuals after certain numbers of global search iterations. Note "
|
||||
@ -38,21 +37,21 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
|
||||
// int counter = 0; !?
|
||||
// int maxfunctioncalls = 1000; !?
|
||||
private boolean TRACE = false;
|
||||
private String m_Identifier = "";
|
||||
private InterfaceOptimizationProblem m_Problem = new F1Problem();
|
||||
private InterfaceOptimizer m_GlobalOptimizer = new GeneticAlgorithm();
|
||||
private String identifier = "";
|
||||
private InterfaceOptimizationProblem optimizationProblem = new F1Problem();
|
||||
private InterfaceOptimizer globalOptimizer = new GeneticAlgorithm();
|
||||
private InterfaceSelection selectorPlug = new SelectBestIndividuals();
|
||||
transient private InterfacePopulationChangedEventListener m_Listener;
|
||||
transient private InterfacePopulationChangedEventListener populationChangedEventListener;
|
||||
|
||||
public MemeticAlgorithm() {
|
||||
}
|
||||
|
||||
public MemeticAlgorithm(MemeticAlgorithm a) {
|
||||
// this.population = (Population)a.population.clone();
|
||||
this.m_Problem = (InterfaceLocalSearchable) a.m_Problem.clone();
|
||||
this.m_GlobalOptimizer = (InterfaceOptimizer) a.m_GlobalOptimizer;
|
||||
this.optimizationProblem = (InterfaceLocalSearchable) a.optimizationProblem.clone();
|
||||
this.globalOptimizer = (InterfaceOptimizer) a.globalOptimizer;
|
||||
this.selectorPlug = (InterfaceSelection) a.selectorPlug;
|
||||
this.m_Identifier = a.m_Identifier;
|
||||
this.identifier = a.identifier;
|
||||
this.localSearchSteps = a.localSearchSteps;
|
||||
this.subsetsize = a.subsetsize;
|
||||
this.globalSearchIterations = a.globalSearchIterations;
|
||||
@ -69,7 +68,7 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
|
||||
this.setPopulation((Population) pop.clone());
|
||||
if (reset) {
|
||||
this.getPopulation().init();
|
||||
this.m_Problem.evaluate(this.getPopulation());
|
||||
this.optimizationProblem.evaluate(this.getPopulation());
|
||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
|
||||
}
|
||||
}
|
||||
@ -77,9 +76,9 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
|
||||
@Override
|
||||
public void init() {
|
||||
// counter = 0;
|
||||
this.m_GlobalOptimizer.setProblem(this.m_Problem);
|
||||
this.m_GlobalOptimizer.init();
|
||||
this.evaluatePopulation(this.m_GlobalOptimizer.getPopulation());
|
||||
this.globalOptimizer.setProblem(this.optimizationProblem);
|
||||
this.globalOptimizer.init();
|
||||
this.evaluatePopulation(this.globalOptimizer.getPopulation());
|
||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
|
||||
}
|
||||
|
||||
@ -89,7 +88,7 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
|
||||
* @param population The population that is to be evaluated
|
||||
*/
|
||||
private void evaluatePopulation(Population population) {
|
||||
this.m_Problem.evaluate(population);
|
||||
this.optimizationProblem.evaluate(population);
|
||||
population.incrGeneration();
|
||||
}
|
||||
|
||||
@ -99,17 +98,17 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
|
||||
if (TRACE) {
|
||||
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.m_Problem instanceof InterfaceLocalSearchable)) {
|
||||
&& (this.optimizationProblem instanceof InterfaceLocalSearchable)) {
|
||||
// here the local search is performed
|
||||
if (TRACE) {
|
||||
System.out.println("Performing local search on " + subsetsize
|
||||
+ " individuals.");
|
||||
}
|
||||
Population gop = this.m_GlobalOptimizer.getPopulation();
|
||||
Population gop = this.globalOptimizer.getPopulation();
|
||||
Population subset = selectorPlug.selectFrom(gop, subsetsize);
|
||||
Population subsetclone = new Population();
|
||||
for (int i = 0; i < subset.size(); i++) {
|
||||
@ -129,7 +128,7 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
|
||||
}
|
||||
|
||||
// int dosearchsteps = this.localSearchSteps;
|
||||
double cost = ((InterfaceLocalSearchable) this.m_Problem)
|
||||
double cost = ((InterfaceLocalSearchable) this.optimizationProblem)
|
||||
.getLocalSearchStepFunctionCallEquivalent();
|
||||
// int calls = gop.getFunctionCalls() + (int) Math.round(localSearchSteps
|
||||
// * cost * subset.size());
|
||||
@ -143,9 +142,9 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
|
||||
// stopit = true;
|
||||
// }
|
||||
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) {
|
||||
gop.removeAll(subset);
|
||||
gop.addPopulation(subsetclone);
|
||||
@ -174,7 +173,7 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
|
||||
|
||||
if (TRACE) {
|
||||
System.out.println("function calls"
|
||||
+ this.m_GlobalOptimizer.getPopulation().getFunctionCalls());
|
||||
+ this.globalOptimizer.getPopulation().getFunctionCalls());
|
||||
}
|
||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
|
||||
}
|
||||
@ -187,14 +186,14 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
|
||||
@Override
|
||||
public void addPopulationChangedEventListener(
|
||||
InterfacePopulationChangedEventListener ea) {
|
||||
this.m_Listener = ea;
|
||||
this.populationChangedEventListener = ea;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removePopulationChangedEventListener(
|
||||
InterfacePopulationChangedEventListener ea) {
|
||||
if (m_Listener == ea) {
|
||||
m_Listener = null;
|
||||
if (populationChangedEventListener == ea) {
|
||||
populationChangedEventListener = null;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@ -205,11 +204,11 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
|
||||
* Something has changed
|
||||
*/
|
||||
protected void firePropertyChangedEvent(String name) {
|
||||
if (this.m_Listener != null) {
|
||||
if (this.populationChangedEventListener != null) {
|
||||
if (TRACE) {
|
||||
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
|
||||
public void setProblem(InterfaceOptimizationProblem problem) {
|
||||
this.m_Problem = problem;
|
||||
this.m_GlobalOptimizer.setProblem(this.m_Problem);
|
||||
this.optimizationProblem = problem;
|
||||
this.globalOptimizer.setProblem(this.optimizationProblem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InterfaceOptimizationProblem getProblem() {
|
||||
return this.m_Problem;
|
||||
return this.optimizationProblem;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -240,8 +239,8 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
|
||||
String result = "";
|
||||
result += "Memetic Algorithm:\n";
|
||||
result += "Optimization Problem: ";
|
||||
result += this.m_Problem.getStringRepresentationForProblem(this) + "\n";
|
||||
result += this.m_GlobalOptimizer.getStringRepresentation();
|
||||
result += this.optimizationProblem.getStringRepresentationForProblem(this) + "\n";
|
||||
result += this.globalOptimizer.getStringRepresentation();
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -252,12 +251,12 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
|
||||
*/
|
||||
@Override
|
||||
public void setIdentifier(String name) {
|
||||
this.m_Identifier = name;
|
||||
this.identifier = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return this.m_Identifier;
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
|
||||
@ -280,12 +279,12 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
|
||||
*/
|
||||
@Override
|
||||
public Population getPopulation() {
|
||||
return this.m_GlobalOptimizer.getPopulation();
|
||||
return this.globalOptimizer.getPopulation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPopulation(Population pop) {
|
||||
this.m_GlobalOptimizer.setPopulation(pop);
|
||||
this.globalOptimizer.setPopulation(pop);
|
||||
}
|
||||
|
||||
public String populationTipText() {
|
||||
@ -295,16 +294,16 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
|
||||
/**
|
||||
* Choose the global optimization strategy to use
|
||||
*
|
||||
* @param m_GlobalOptimizer
|
||||
* @param globalOptimizer
|
||||
*/
|
||||
public void setGlobalOptimizer(InterfaceOptimizer m_GlobalOptimizer) {
|
||||
this.m_GlobalOptimizer = m_GlobalOptimizer;
|
||||
this.m_GlobalOptimizer.setProblem(this.getProblem());
|
||||
public void setGlobalOptimizer(InterfaceOptimizer globalOptimizer) {
|
||||
this.globalOptimizer = globalOptimizer;
|
||||
this.globalOptimizer.setProblem(this.getProblem());
|
||||
this.init();
|
||||
}
|
||||
|
||||
public InterfaceOptimizer getGlobalOptimizer() {
|
||||
return m_GlobalOptimizer;
|
||||
return globalOptimizer;
|
||||
}
|
||||
|
||||
public String globalOptimizerTipText() {
|
||||
|
@ -40,21 +40,21 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
|
||||
public boolean seen = false;
|
||||
}
|
||||
|
||||
private String m_Identifier = "MOCMAES";
|
||||
private Population m_Population;
|
||||
private AbstractOptimizationProblem m_Problem;
|
||||
transient private InterfacePopulationChangedEventListener m_Listener;
|
||||
private int m_lambda = 1;
|
||||
private int m_lambdamo = 1;
|
||||
private String identifier = "MOCMAES";
|
||||
private Population population;
|
||||
private AbstractOptimizationProblem optimizationProblem;
|
||||
transient private InterfacePopulationChangedEventListener populationChangedEventListener;
|
||||
private int lambda = 1;
|
||||
private int lambdaMO = 1;
|
||||
|
||||
public MultiObjectiveCMAES() {
|
||||
m_Population = new Population(m_lambdamo);
|
||||
population = new Population(lambdaMO);
|
||||
}
|
||||
|
||||
public MultiObjectiveCMAES(MultiObjectiveCMAES a) {
|
||||
m_Problem = (AbstractOptimizationProblem) a.m_Problem.clone();
|
||||
setPopulation((Population) a.m_Population.clone());
|
||||
m_lambda = a.m_lambda;
|
||||
optimizationProblem = (AbstractOptimizationProblem) a.optimizationProblem.clone();
|
||||
setPopulation((Population) a.population.clone());
|
||||
lambda = a.lambda;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -76,7 +76,7 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
|
||||
*/
|
||||
@Override
|
||||
public void setIdentifier(String name) {
|
||||
m_Identifier = name;
|
||||
identifier = name;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -88,7 +88,7 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
|
||||
*/
|
||||
@Override
|
||||
public void setProblem(InterfaceOptimizationProblem problem) {
|
||||
m_Problem = (AbstractOptimizationProblem) problem;
|
||||
optimizationProblem = (AbstractOptimizationProblem) problem;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -99,7 +99,7 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
|
||||
@Override
|
||||
public void addPopulationChangedEventListener(
|
||||
InterfacePopulationChangedEventListener ea) {
|
||||
this.m_Listener = ea;
|
||||
this.populationChangedEventListener = ea;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -120,7 +120,7 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
|
||||
*/
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return m_Identifier;
|
||||
return identifier;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -130,7 +130,7 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
|
||||
*/
|
||||
@Override
|
||||
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
|
||||
public Population getPopulation() {
|
||||
return m_Population;
|
||||
return population;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -150,7 +150,7 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
|
||||
*/
|
||||
@Override
|
||||
public InterfaceOptimizationProblem getProblem() {
|
||||
return m_Problem;
|
||||
return optimizationProblem;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -162,10 +162,10 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
|
||||
@Override
|
||||
public String getStringRepresentation() {
|
||||
StringBuilder strB = new StringBuilder(200);
|
||||
strB.append("(1+" + m_lambda + ") MO-CMA-ES:\nOptimization Problem: ");
|
||||
strB.append(this.m_Problem.getStringRepresentationForProblem(this));
|
||||
strB.append("(1+" + lambda + ") MO-CMA-ES:\nOptimization Problem: ");
|
||||
strB.append(this.optimizationProblem.getStringRepresentationForProblem(this));
|
||||
strB.append("\n");
|
||||
strB.append(this.m_Population.getStringRepresentation());
|
||||
strB.append(this.population.getStringRepresentation());
|
||||
return strB.toString();
|
||||
}
|
||||
|
||||
@ -177,10 +177,10 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
|
||||
@Override
|
||||
public void init() {
|
||||
// initByPopulation(population, true);
|
||||
this.m_Population.setTargetSize(m_lambdamo);
|
||||
this.m_Problem.initializePopulation(this.m_Population);
|
||||
this.population.setTargetSize(lambdaMO);
|
||||
this.optimizationProblem.initializePopulation(this.population);
|
||||
// children = new Population(population.size());
|
||||
this.evaluatePopulation(this.m_Population);
|
||||
this.evaluatePopulation(this.population);
|
||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
|
||||
|
||||
}
|
||||
@ -196,8 +196,8 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
|
||||
public void initByPopulation(Population pop, boolean reset) {
|
||||
setPopulation(pop);
|
||||
if (reset) {
|
||||
m_Problem.initializePopulation(m_Population);
|
||||
m_Problem.evaluate(m_Population);
|
||||
optimizationProblem.initializePopulation(population);
|
||||
optimizationProblem.evaluate(population);
|
||||
|
||||
}
|
||||
}
|
||||
@ -208,7 +208,7 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
|
||||
* @param population The population that is to be evaluated
|
||||
*/
|
||||
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>();
|
||||
|
||||
// Eltern markieren und f<EFBFBD>r die Z<EFBFBD>hlung vorbereiten
|
||||
for (int j = 0; j < m_lambdamo && j < m_Population.size(); j++) {
|
||||
m_Population.getEAIndividual(j).putData("Parent",
|
||||
m_Population.getEAIndividual(j));
|
||||
SuccessCounterMap.put(m_Population.getEAIndividual(j).getIndyID(),
|
||||
for (int j = 0; j < lambdaMO && j < population.size(); j++) {
|
||||
population.getEAIndividual(j).putData("Parent",
|
||||
population.getEAIndividual(j));
|
||||
SuccessCounterMap.put(population.getEAIndividual(j).getIndyID(),
|
||||
new CounterClass(0));
|
||||
}
|
||||
|
||||
// Kinder erzeugen
|
||||
Population children = new Population(m_lambdamo * m_lambda);
|
||||
children.setGeneration(m_Population.getGeneration());
|
||||
Population children = new Population(lambdaMO * lambda);
|
||||
children.setGeneration(population.getGeneration());
|
||||
|
||||
for (int j = 0; j < children.getTargetSize(); j++) {
|
||||
AbstractEAIndividual parent = m_Population.getEAIndividual(j
|
||||
% m_lambdamo);
|
||||
AbstractEAIndividual parent = population.getEAIndividual(j
|
||||
% lambdaMO);
|
||||
AbstractEAIndividual indy = (AbstractEAIndividual) parent.clone();
|
||||
indy.mutate();
|
||||
indy.putData("Parent", parent);
|
||||
@ -243,29 +243,29 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
|
||||
}
|
||||
evaluatePopulation(children);
|
||||
|
||||
m_Population.addPopulation(children);
|
||||
population.addPopulation(children);
|
||||
// Ranking
|
||||
ArchivingNSGAII dummyArchive = new ArchivingNSGAIISMeasure();
|
||||
Population[] store = dummyArchive
|
||||
.getNonDominatedSortedFronts(m_Population);
|
||||
store = dummyArchive.getNonDominatedSortedFronts(m_Population);
|
||||
.getNonDominatedSortedFronts(population);
|
||||
store = dummyArchive.getNonDominatedSortedFronts(population);
|
||||
dummyArchive.calculateCrowdingDistance(store);
|
||||
|
||||
// Vergleichen und den Successcounter hochz<EFBFBD>hlen wenn wir besser als
|
||||
// unser Elter sind
|
||||
for (int j = 0; j < m_Population.size(); j++) {
|
||||
AbstractEAIndividual parent = (AbstractEAIndividual) m_Population
|
||||
for (int j = 0; j < population.size(); j++) {
|
||||
AbstractEAIndividual parent = (AbstractEAIndividual) population
|
||||
.getEAIndividual(j).getData("Parent");
|
||||
if (m_Population.getEAIndividual(j) != parent) { // Eltern nicht mit
|
||||
if (population.getEAIndividual(j) != parent) { // Eltern nicht mit
|
||||
// sich selber
|
||||
// vergleichen
|
||||
int parentParetoLevel = ((Integer) parent
|
||||
.getData("ParetoLevel")).intValue();
|
||||
double parentSMeasure = ((Double) parent.getData("HyperCube"))
|
||||
.doubleValue();
|
||||
int childParetoLevel = ((Integer) m_Population.getEAIndividual(
|
||||
int childParetoLevel = ((Integer) population.getEAIndividual(
|
||||
j).getData("ParetoLevel")).intValue();
|
||||
double childSMeasure = ((Double) m_Population
|
||||
double childSMeasure = ((Double) population
|
||||
.getEAIndividual(j).getData("HyperCube")).doubleValue();
|
||||
if (childParetoLevel < parentParetoLevel
|
||||
|| ((childParetoLevel == parentParetoLevel) && childSMeasure > parentSMeasure)) {
|
||||
@ -278,17 +278,17 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
|
||||
}
|
||||
|
||||
// Selection
|
||||
m_Population.clear();
|
||||
population.clear();
|
||||
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
|
||||
// passt
|
||||
// noch
|
||||
// komplett
|
||||
m_Population.addPopulation(store[i]);
|
||||
population.addPopulation(store[i]);
|
||||
|
||||
} 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);
|
||||
double bestMeasure = ((Double) indy.getData("HyperCube"))
|
||||
.doubleValue(); // TODO mal noch effizient machen
|
||||
@ -302,7 +302,7 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
|
||||
indy = store[i].getEAIndividual(j);
|
||||
}
|
||||
}
|
||||
m_Population.add(indy);
|
||||
population.add(indy);
|
||||
store[i].removeMember(indy);
|
||||
}
|
||||
}
|
||||
@ -310,9 +310,9 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
|
||||
}
|
||||
|
||||
// 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
|
||||
// geht
|
||||
// nur
|
||||
@ -329,7 +329,7 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
|
||||
.getMutationOperator();
|
||||
double rate = ((double) SuccessCounterMap.get(parent
|
||||
.getIndyID()).value)
|
||||
/ ((double) m_lambda);
|
||||
/ ((double) lambda);
|
||||
|
||||
if (indy != parent) {
|
||||
muta.updateCovariance();
|
||||
@ -342,8 +342,8 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
|
||||
children.getEAIndividual(j).putData("Parent", null);
|
||||
}
|
||||
|
||||
m_Population.incrFunctionCallsBy(children.size());
|
||||
m_Population.incrGeneration();
|
||||
population.incrFunctionCallsBy(children.size());
|
||||
population.incrGeneration();
|
||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
|
||||
|
||||
}
|
||||
@ -370,9 +370,9 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
|
||||
*/
|
||||
@Override
|
||||
public void setPopulation(Population pop) {
|
||||
m_Population = pop;
|
||||
m_Population.setNotifyEvalInterval(1);
|
||||
m_lambdamo = m_Population.getTargetSize();
|
||||
population = pop;
|
||||
population.setNotifyEvalInterval(1);
|
||||
lambdaMO = population.getTargetSize();
|
||||
|
||||
}
|
||||
|
||||
@ -382,22 +382,22 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
|
||||
* @param name
|
||||
*/
|
||||
protected void firePropertyChangedEvent(String name) {
|
||||
if (this.m_Listener != null) {
|
||||
this.m_Listener.registerPopulationStateChanged(this, name);
|
||||
if (this.populationChangedEventListener != null) {
|
||||
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
|
||||
}
|
||||
}
|
||||
|
||||
public int getLambda() {
|
||||
return m_lambda;
|
||||
return lambda;
|
||||
}
|
||||
|
||||
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; }
|
||||
*/
|
||||
}
|
||||
|
@ -30,24 +30,24 @@ import eva2.util.annotation.Description;
|
||||
@Description("This is a general Multi-objective Evolutionary Optimization Framework.")
|
||||
public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializable {
|
||||
|
||||
private InterfaceOptimizer m_Optimizer = new GeneticAlgorithm();
|
||||
private InterfaceArchiving m_Archiver = new ArchivingNSGAII();
|
||||
private InterfaceInformationRetrieval m_InformationRetrieval = new InformationRetrievalInserting();
|
||||
private InterfaceOptimizationProblem m_Problem = new FM0Problem();
|
||||
private String m_Identifier = "";
|
||||
transient private InterfacePopulationChangedEventListener m_Listener;
|
||||
private InterfaceOptimizer optimizer = new GeneticAlgorithm();
|
||||
private InterfaceArchiving archiver = new ArchivingNSGAII();
|
||||
private InterfaceInformationRetrieval informationRetrieval = new InformationRetrievalInserting();
|
||||
private InterfaceOptimizationProblem optimizationProblem = new FM0Problem();
|
||||
private String identifier = "";
|
||||
transient private InterfacePopulationChangedEventListener populationChangedEventListener;
|
||||
|
||||
public MultiObjectiveEA() {
|
||||
this.m_Optimizer.getPopulation().setTargetSize(100);
|
||||
((GeneticAlgorithm) this.m_Optimizer).setParentSelection(new SelectMONonDominated());
|
||||
((GeneticAlgorithm) this.m_Optimizer).setPartnerSelection(new SelectMONonDominated());
|
||||
this.optimizer.getPopulation().setTargetSize(100);
|
||||
((GeneticAlgorithm) this.optimizer).setParentSelection(new SelectMONonDominated());
|
||||
((GeneticAlgorithm) this.optimizer).setPartnerSelection(new SelectMONonDominated());
|
||||
}
|
||||
|
||||
public MultiObjectiveEA(MultiObjectiveEA a) {
|
||||
this.m_Problem = (InterfaceOptimizationProblem) a.m_Problem.clone();
|
||||
this.m_Optimizer = (InterfaceOptimizer) a.m_Optimizer.clone();
|
||||
this.m_Archiver = (InterfaceArchiving) a.m_Archiver.clone();
|
||||
this.m_InformationRetrieval = (InterfaceInformationRetrieval) a.m_InformationRetrieval.clone();
|
||||
this.optimizationProblem = (InterfaceOptimizationProblem) a.optimizationProblem.clone();
|
||||
this.optimizer = (InterfaceOptimizer) a.optimizer.clone();
|
||||
this.archiver = (InterfaceArchiving) a.archiver.clone();
|
||||
this.informationRetrieval = (InterfaceInformationRetrieval) a.informationRetrieval.clone();
|
||||
}
|
||||
|
||||
public MultiObjectiveEA(InterfaceOptimizer subOpt, InterfaceArchiving archiving, int archiveSize,
|
||||
@ -66,8 +66,8 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
this.m_Optimizer.init();
|
||||
this.m_Archiver.addElementsToArchive(this.m_Optimizer.getPopulation());
|
||||
this.optimizer.init();
|
||||
this.archiver.addElementsToArchive(this.optimizer.getPopulation());
|
||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
|
||||
}
|
||||
|
||||
@ -79,8 +79,8 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
|
||||
*/
|
||||
@Override
|
||||
public void initByPopulation(Population pop, boolean reset) {
|
||||
this.m_Optimizer.initByPopulation(pop, reset);
|
||||
this.m_Archiver.addElementsToArchive(this.m_Optimizer.getPopulation());
|
||||
this.optimizer.initByPopulation(pop, reset);
|
||||
this.archiver.addElementsToArchive(this.optimizer.getPopulation());
|
||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
|
||||
}
|
||||
|
||||
@ -91,11 +91,11 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
|
||||
public void optimize() {
|
||||
// double[][] may = this.showMay(this.optimizer.getPopulation());
|
||||
// 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
|
||||
// This is the Environment Selection
|
||||
this.m_Archiver.addElementsToArchive(this.m_Optimizer.getPopulation());
|
||||
//if (true) this.m_Archiver.plotArchive(this.optimizer.getPopulation());
|
||||
this.archiver.addElementsToArchive(this.optimizer.getPopulation());
|
||||
//if (true) this.archiver.plotArchive(this.optimizer.getPopulation());
|
||||
// if (false) {
|
||||
// int popSize = this.optimizer.getPopulation().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 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());
|
||||
// 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
|
||||
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
|
||||
this.m_Listener = ea;
|
||||
this.populationChangedEventListener = ea;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removePopulationChangedEventListener(
|
||||
InterfacePopulationChangedEventListener ea) {
|
||||
if (m_Listener == ea) {
|
||||
m_Listener = null;
|
||||
if (populationChangedEventListener == ea) {
|
||||
populationChangedEventListener = null;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@ -172,8 +172,8 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
|
||||
}
|
||||
|
||||
protected void firePropertyChangedEvent(String name) {
|
||||
if (this.m_Listener != null) {
|
||||
this.m_Listener.registerPopulationStateChanged(this, name);
|
||||
if (this.populationChangedEventListener != null) {
|
||||
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -184,13 +184,13 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
|
||||
*/
|
||||
@Override
|
||||
public void setProblem(InterfaceOptimizationProblem problem) {
|
||||
this.m_Problem = problem;
|
||||
this.m_Optimizer.setProblem(problem);
|
||||
this.optimizationProblem = problem;
|
||||
this.optimizer.setProblem(problem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InterfaceOptimizationProblem getProblem() {
|
||||
return this.m_Problem;
|
||||
return this.optimizationProblem;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -204,11 +204,11 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
|
||||
String result = "";
|
||||
result += "Multi-Objective Evolutionary Algorithm:\n";
|
||||
result += "Using:\n";
|
||||
result += " Archiving Strategy = " + this.m_Archiver.getClass().toString() + "\n";
|
||||
result += " Information Retrieval = " + this.m_InformationRetrieval.getClass().toString() + "\n";
|
||||
result += " Archiving Strategy = " + this.archiver.getClass().toString() + "\n";
|
||||
result += " Information Retrieval = " + this.informationRetrieval.getClass().toString() + "\n";
|
||||
result += " Information Retrieval = " + this.getClass().toString() + "\n";
|
||||
result += " Optimizer = " + this.m_Optimizer.getClass().toString() + "\n";
|
||||
result += this.m_Optimizer.getStringRepresentation() + "\n";
|
||||
result += " Optimizer = " + this.optimizer.getClass().toString() + "\n";
|
||||
result += this.optimizer.getStringRepresentation() + "\n";
|
||||
//result += "=> The Optimization Problem: ";
|
||||
//result += this.problem.getStringRepresentationForProblem(this) +"\n";
|
||||
//result += this.population.getStringRepresentation();
|
||||
@ -222,12 +222,12 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
|
||||
*/
|
||||
@Override
|
||||
public void setIdentifier(String name) {
|
||||
this.m_Identifier = name;
|
||||
this.identifier = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return this.m_Identifier;
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -249,12 +249,12 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
|
||||
*/
|
||||
@Override
|
||||
public Population getPopulation() {
|
||||
return this.m_Optimizer.getPopulation();
|
||||
return this.optimizer.getPopulation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPopulation(Population pop) {
|
||||
this.m_Optimizer.setPopulation(pop);
|
||||
this.optimizer.setPopulation(pop);
|
||||
}
|
||||
|
||||
public String populationTipText() {
|
||||
@ -272,11 +272,11 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
|
||||
* @return The current optimizing method
|
||||
*/
|
||||
public InterfaceOptimizer getOptimizer() {
|
||||
return this.m_Optimizer;
|
||||
return this.optimizer;
|
||||
}
|
||||
|
||||
public void setOptimizer(InterfaceOptimizer b) {
|
||||
this.m_Optimizer = b;
|
||||
this.optimizer = b;
|
||||
}
|
||||
|
||||
public String optimizerTipText() {
|
||||
@ -289,11 +289,11 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
|
||||
* @return The current optimizing method
|
||||
*/
|
||||
public InterfaceArchiving getArchivingStrategy() {
|
||||
return this.m_Archiver;
|
||||
return this.archiver;
|
||||
}
|
||||
|
||||
public void setArchivingStrategy(InterfaceArchiving b) {
|
||||
this.m_Archiver = b;
|
||||
this.archiver = b;
|
||||
}
|
||||
|
||||
public String archivingStrategyTipText() {
|
||||
@ -307,11 +307,11 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
|
||||
* @return The current optimizing method
|
||||
*/
|
||||
public InterfaceInformationRetrieval getInformationRetrieval() {
|
||||
return this.m_InformationRetrieval;
|
||||
return this.informationRetrieval;
|
||||
}
|
||||
|
||||
public void setInformationRetrieval(InterfaceInformationRetrieval b) {
|
||||
this.m_InformationRetrieval = b;
|
||||
this.informationRetrieval = b;
|
||||
}
|
||||
|
||||
public String informationRetrievalTipText() {
|
||||
@ -324,19 +324,19 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
|
||||
* @return The current optimizing method
|
||||
*/
|
||||
public int getArchiveSize() {
|
||||
Population archive = this.m_Optimizer.getPopulation().getArchive();
|
||||
Population archive = this.optimizer.getPopulation().getArchive();
|
||||
if (archive == null) {
|
||||
archive = new Population();
|
||||
this.m_Optimizer.getPopulation().SetArchive(archive);
|
||||
this.optimizer.getPopulation().SetArchive(archive);
|
||||
}
|
||||
return archive.getTargetSize();
|
||||
}
|
||||
|
||||
public void setArchiveSize(int b) {
|
||||
Population archive = this.m_Optimizer.getPopulation().getArchive();
|
||||
Population archive = this.optimizer.getPopulation().getArchive();
|
||||
if (archive == null) {
|
||||
archive = new Population();
|
||||
this.m_Optimizer.getPopulation().SetArchive(archive);
|
||||
this.optimizer.getPopulation().SetArchive(archive);
|
||||
}
|
||||
archive.setTargetSize(b);
|
||||
}
|
||||
|
@ -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)
|
||||
private int generationCycle = 50;
|
||||
private int fitIndex = 0; // choose criterion for multi objective functions
|
||||
private Population m_Population;
|
||||
private AbstractOptimizationProblem m_Problem;
|
||||
private transient Vector<InterfacePopulationChangedEventListener> m_Listener;
|
||||
private String m_Identifier = "NelderMeadSimplex";
|
||||
private Population population;
|
||||
private AbstractOptimizationProblem optimizationProblem;
|
||||
private transient Vector<InterfacePopulationChangedEventListener> populationChangedEventListeners;
|
||||
private String identifier = "NelderMeadSimplex";
|
||||
private boolean checkConstraints = true;
|
||||
|
||||
public NelderMeadSimplex() {
|
||||
@ -44,11 +44,11 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
|
||||
}
|
||||
|
||||
public NelderMeadSimplex(NelderMeadSimplex a) {
|
||||
m_Problem = (AbstractOptimizationProblem) a.m_Problem.clone();
|
||||
setPopulation((Population) a.m_Population.clone());
|
||||
optimizationProblem = (AbstractOptimizationProblem) a.optimizationProblem.clone();
|
||||
setPopulation((Population) a.population.clone());
|
||||
populationSize = a.populationSize;
|
||||
generationCycle = a.generationCycle;
|
||||
m_Identifier = a.m_Identifier;
|
||||
identifier = a.identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -58,17 +58,17 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
|
||||
|
||||
@Override
|
||||
public void setIdentifier(String name) {
|
||||
m_Identifier = name;
|
||||
identifier = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProblem(InterfaceOptimizationProblem problem) {
|
||||
m_Problem = (AbstractOptimizationProblem) problem;
|
||||
optimizationProblem = (AbstractOptimizationProblem) problem;
|
||||
}
|
||||
|
||||
public boolean setProblemAndPopSize(InterfaceOptimizationProblem problem) {
|
||||
setProblem(problem);
|
||||
if (m_Problem instanceof AbstractProblemDouble) {
|
||||
if (optimizationProblem instanceof AbstractProblemDouble) {
|
||||
setPopulationSize(((AbstractProblemDouble) problem).getProblemDimension() + 1);
|
||||
return true;
|
||||
} else {
|
||||
@ -85,11 +85,11 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
|
||||
public void addPopulationChangedEventListener(
|
||||
InterfacePopulationChangedEventListener ea) {
|
||||
if (ea != null) {
|
||||
if (m_Listener == null) {
|
||||
m_Listener = new Vector<InterfacePopulationChangedEventListener>();
|
||||
if (populationChangedEventListeners == null) {
|
||||
populationChangedEventListeners = new Vector<InterfacePopulationChangedEventListener>();
|
||||
}
|
||||
if (!m_Listener.contains(ea)) {
|
||||
m_Listener.add(ea);
|
||||
if (!populationChangedEventListeners.contains(ea)) {
|
||||
populationChangedEventListeners.add(ea);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -97,10 +97,10 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
|
||||
@Override
|
||||
public boolean removePopulationChangedEventListener(
|
||||
InterfacePopulationChangedEventListener ea) {
|
||||
if (m_Listener == null) {
|
||||
if (populationChangedEventListeners == null) {
|
||||
return false;
|
||||
} else {
|
||||
return m_Listener.remove(ea);
|
||||
return populationChangedEventListeners.remove(ea);
|
||||
}
|
||||
}
|
||||
|
||||
@ -167,7 +167,7 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
|
||||
//
|
||||
// problem.evaluate(reflectedInd);
|
||||
AbstractEAIndividual reflectedInd = createEvalIndy(bestpop, r);
|
||||
this.m_Population.incrFunctionCalls();
|
||||
this.population.incrFunctionCalls();
|
||||
|
||||
if (firstIsBetter(best, reflectedInd) && firstIsBetter(reflectedInd, bestpop.getWorstEAIndividual(fitIndex))) {
|
||||
return reflectedInd;
|
||||
@ -181,7 +181,7 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
|
||||
}
|
||||
|
||||
AbstractEAIndividual e_ind = createEvalIndy(bestpop, e);
|
||||
this.m_Population.incrFunctionCalls();
|
||||
this.population.incrFunctionCalls();
|
||||
|
||||
if (firstIsBetter(e_ind, reflectedInd)) { //expandiertes ist besser als reflektiertes
|
||||
return e_ind;
|
||||
@ -202,7 +202,7 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
|
||||
// ((InterfaceDataTypeDouble)c_ind).setDoubleGenotype(c);
|
||||
// problem.evaluate(c_ind);
|
||||
AbstractEAIndividual c_ind = createEvalIndy(bestpop, c);
|
||||
this.m_Population.incrFunctionCalls();
|
||||
this.population.incrFunctionCalls();
|
||||
if (firstIsBetterEqual(c_ind, worst)) {
|
||||
return c_ind;
|
||||
}
|
||||
@ -214,46 +214,46 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
|
||||
AbstractEAIndividual e_ind = (AbstractEAIndividual) ((AbstractEAIndividual) pop.getIndividual(1)).clone();
|
||||
((InterfaceDataTypeDouble) e_ind).setDoubleGenotype(newGenotype);
|
||||
e_ind.resetConstraintViolation();
|
||||
m_Problem.evaluate(e_ind);
|
||||
optimizationProblem.evaluate(e_ind);
|
||||
if (e_ind.getFitness(0) < 6000) {
|
||||
m_Problem.evaluate(e_ind);
|
||||
optimizationProblem.evaluate(e_ind);
|
||||
}
|
||||
return e_ind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return m_Identifier;
|
||||
return identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return m_Identifier;
|
||||
return identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Population getPopulation() {
|
||||
return m_Population;
|
||||
return population;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InterfaceOptimizationProblem getProblem() {
|
||||
return m_Problem;
|
||||
return optimizationProblem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStringRepresentation() {
|
||||
StringBuilder strB = new StringBuilder(200);
|
||||
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(this.m_Population.getStringRepresentation());
|
||||
strB.append(this.population.getStringRepresentation());
|
||||
return strB.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
initByPopulation(m_Population, true);
|
||||
initByPopulation(population, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -261,16 +261,16 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
|
||||
setPopulation(pop);
|
||||
pop.addPopulationChangedEventListener(this);
|
||||
if (reset) {
|
||||
m_Problem.initializePopulation(m_Population);
|
||||
m_Problem.evaluate(m_Population);
|
||||
optimizationProblem.initializePopulation(population);
|
||||
optimizationProblem.evaluate(population);
|
||||
}
|
||||
// fireNextGenerationPerformed();
|
||||
}
|
||||
|
||||
private void fireNextGenerationPerformed() {
|
||||
if (m_Listener != null) {
|
||||
for (int i = 0; i < m_Listener.size(); i++) {
|
||||
m_Listener.elementAt(i).registerPopulationStateChanged(this, Population.NEXT_GENERATION_PERFORMED);
|
||||
if (populationChangedEventListeners != null) {
|
||||
for (int i = 0; i < populationChangedEventListeners.size(); i++) {
|
||||
populationChangedEventListeners.elementAt(i).registerPopulationStateChanged(this, Population.NEXT_GENERATION_PERFORMED);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -279,11 +279,11 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
|
||||
public void optimize() {
|
||||
// make at least as many calls as there are individuals within the population.
|
||||
// this simulates the generational loop expected by some other modules
|
||||
int evalCntStart = m_Population.getFunctionCalls();
|
||||
int evalCntStart = population.getFunctionCalls();
|
||||
int evalsDone = 0;
|
||||
m_Problem.evaluatePopulationStart(m_Population);
|
||||
optimizationProblem.evaluatePopulationStart(population);
|
||||
do {
|
||||
AbstractEAIndividual ind = simplexStep(m_Population);
|
||||
AbstractEAIndividual ind = simplexStep(population);
|
||||
if (ind != null) { //Verbesserung gefunden
|
||||
double[] x = ((InterfaceDataTypeDouble) ind).getDoubleData();
|
||||
double[][] range = ((InterfaceDataTypeDouble) ind).getDoubleRange();
|
||||
@ -294,32 +294,32 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
|
||||
// problem.evaluate(ind);
|
||||
// this.population.incrFunctionCalls();
|
||||
}
|
||||
m_Population.set(m_Population.getIndexOfWorstIndividualNoConstr(fitIndex), ind, fitIndex);
|
||||
population.set(population.getIndexOfWorstIndividualNoConstr(fitIndex), ind, fitIndex);
|
||||
} 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++) {
|
||||
double[] c = ((InterfaceDataTypeDouble) m_Population.getEAIndividual(j)).getDoubleData();
|
||||
for (int j = 0; j < population.size(); j++) {
|
||||
double[] c = ((InterfaceDataTypeDouble) population.getEAIndividual(j)).getDoubleData();
|
||||
for (int i = 0; i < c.length; 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.
|
||||
}
|
||||
m_Problem.evaluate(m_Population);
|
||||
optimizationProblem.evaluate(population);
|
||||
}
|
||||
evalsDone = m_Population.getFunctionCalls() - evalCntStart;
|
||||
evalsDone = population.getFunctionCalls() - evalCntStart;
|
||||
} while (evalsDone < generationCycle);
|
||||
m_Problem.evaluatePopulationEnd(m_Population);
|
||||
this.m_Population.incrGeneration();
|
||||
optimizationProblem.evaluatePopulationEnd(population);
|
||||
this.population.incrGeneration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPopulation(Population pop) {
|
||||
m_Population = pop;
|
||||
m_Population.addPopulationChangedEventListener(this);
|
||||
m_Population.setNotifyEvalInterval(populationSize);
|
||||
population = pop;
|
||||
population.addPopulationChangedEventListener(this);
|
||||
population.setNotifyEvalInterval(populationSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -340,9 +340,9 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
|
||||
*/
|
||||
public void setPopulationSize(int populationSize) {
|
||||
this.populationSize = populationSize;
|
||||
if (m_Population != null) {
|
||||
m_Population.setTargetSize(populationSize);
|
||||
m_Population.setNotifyEvalInterval(m_Population.getTargetSize());
|
||||
if (population != null) {
|
||||
population.setTargetSize(populationSize);
|
||||
population.setNotifyEvalInterval(population.getTargetSize());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,16 +119,16 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
protected InterfaceAbsorptionStrategy absorptionStrategy = new StandardAbsorptionStrategy();
|
||||
protected InterfaceSubswarmCreationStrategy subswarmCreationStrategy = new StandardSubswarmCreationStrategy();
|
||||
// the problem
|
||||
protected InterfaceOptimizationProblem m_Problem = new FM0Problem();
|
||||
protected InterfaceOptimizationProblem optimizationProblem = new FM0Problem();
|
||||
// only used by island model ?
|
||||
protected String m_Identifier = "";
|
||||
protected String identifier = "";
|
||||
// eventListener
|
||||
transient protected InterfacePopulationChangedEventListener m_Listener;
|
||||
transient protected InterfacePopulationChangedEventListener populationChangedEventListener;
|
||||
// for debugging: file containing the output
|
||||
transient protected BufferedWriter outputFile = null;
|
||||
// for debugging and plotting -----------------------------------------------
|
||||
transient protected TopoPlot m_TopologySwarm;
|
||||
transient protected boolean m_shownextplot = false;
|
||||
transient protected TopoPlot topoPlot;
|
||||
transient protected boolean showNextPlot = false;
|
||||
transient protected boolean deactivationOccured = false;
|
||||
transient protected boolean mergingOccurd = false;
|
||||
transient protected boolean absorbtionOccurd = false;
|
||||
@ -214,9 +214,9 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
this.absorptionStrategy = (InterfaceAbsorptionStrategy) a.absorptionStrategy.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() {
|
||||
// pass NichePSO parameter on to the mainswarmoptimzer
|
||||
setMainSwarmSize(mainSwarmSize); // (particles are initialized later via init)
|
||||
getMainSwarm().setProblem(m_Problem);
|
||||
getMainSwarm().setProblem(optimizationProblem);
|
||||
getMainSwarm().SetMaxAllowedSwarmRadius(maxAllowedSwarmRadius);
|
||||
getMainSwarm().getPopulation().setGeneration(0);
|
||||
|
||||
@ -267,7 +267,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
*/
|
||||
protected void initSubswarmOptimizerTemplate() {
|
||||
// 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);
|
||||
|
||||
// choose PSO-type for the subswarmoptimizer
|
||||
@ -294,7 +294,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
public ParticleSubSwarmOptimization getNewSubSwarmOptimizer() {
|
||||
//initSubswarmOptimizerTemplate();
|
||||
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;
|
||||
}
|
||||
|
||||
@ -459,8 +459,8 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
}
|
||||
|
||||
protected void doPlot() {
|
||||
m_shownextplot = (deactivationOccured || mergingOccurd || absorbtionOccurd || creationOccurd);// repopoccurd || reinitoccurd);
|
||||
if (this.getMainSwarm().getPopulation().getGeneration() % this.getShowCycle() == 0) {// || m_shownextplot){
|
||||
showNextPlot = (deactivationOccured || mergingOccurd || absorbtionOccurd || creationOccurd);// repopoccurd || reinitoccurd);
|
||||
if (this.getMainSwarm().getPopulation().getGeneration() % this.getShowCycle() == 0) {// || showNextPlot){
|
||||
// plot merging step
|
||||
if (mergingOccurd) {
|
||||
plotMainSwarm(false);
|
||||
@ -476,7 +476,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
}
|
||||
}
|
||||
// plot main step
|
||||
synchronized (m_TopologySwarm.getClass()) {
|
||||
synchronized (topoPlot.getClass()) {
|
||||
plotMainSwarm(false);
|
||||
plotSubSwarms();
|
||||
//plotAdditionalInfo();
|
||||
@ -494,7 +494,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
}
|
||||
|
||||
//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.others.add((ParticleSubSwarmOptimization) others.clone()); // for plotting only
|
||||
mergingOccurd = true;
|
||||
this.borgbest.add(borg.m_BestIndividual); // for plotting only
|
||||
this.othersbest.add(others.m_BestIndividual); // for plotting only
|
||||
this.borgbest.add(borg.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
|
||||
*/
|
||||
protected void firePropertyChangedEvent(String name) {
|
||||
if (this.m_Listener != null) {
|
||||
this.m_Listener.registerPopulationStateChanged(this, name);
|
||||
if (this.populationChangedEventListener != null) {
|
||||
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -718,14 +718,14 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
@Override
|
||||
public void addPopulationChangedEventListener(
|
||||
InterfacePopulationChangedEventListener ea) {
|
||||
this.m_Listener = ea;
|
||||
this.populationChangedEventListener = ea;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removePopulationChangedEventListener(
|
||||
InterfacePopulationChangedEventListener ea) {
|
||||
if (m_Listener == ea) {
|
||||
m_Listener = null;
|
||||
if (populationChangedEventListener == ea) {
|
||||
populationChangedEventListener = null;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@ -906,11 +906,11 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
// AbstractEAIndividual[] representatives = new AbstractEAIndividual[getSubSwarms().size()+1];
|
||||
for (int i = 0; i < getSubSwarms().size(); ++i) {
|
||||
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)) {
|
||||
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;
|
||||
}
|
||||
@ -1275,7 +1275,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
*/
|
||||
@Override
|
||||
public InterfaceOptimizationProblem getProblem() {
|
||||
return this.m_Problem;
|
||||
return this.optimizationProblem;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1285,7 +1285,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
@Override
|
||||
public void setProblem(InterfaceOptimizationProblem problem) {
|
||||
// set member
|
||||
this.m_Problem = problem;
|
||||
this.optimizationProblem = problem;
|
||||
// pass on to the main- and subswarm optimizers
|
||||
getMainSwarm().setProblem(problem);
|
||||
for (int i = 0; i < getSubSwarms().size(); ++i) {
|
||||
@ -1300,7 +1300,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
*/
|
||||
@Override
|
||||
public void setIdentifier(String name) {
|
||||
this.m_Identifier = name;
|
||||
this.identifier = name;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1309,7 +1309,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
*/
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return this.m_Identifier;
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1456,7 +1456,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
* @tested emp
|
||||
*/
|
||||
public String getPerformanceAsString() {
|
||||
if (!(m_Problem instanceof InterfaceMultimodalProblem)) {
|
||||
if (!(optimizationProblem instanceof InterfaceMultimodalProblem)) {
|
||||
System.out.println("getPerformanceAsString: problem not instanceof InterfaceMultimodalProblem");
|
||||
return "";
|
||||
}
|
||||
@ -1467,10 +1467,10 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
Population elitepop = getSubswarmRepresentatives(false);
|
||||
|
||||
// use elite population to compute performance
|
||||
if (m_Problem instanceof InterfaceMultimodalProblem) {
|
||||
result += ((InterfaceMultimodalProblemKnown) m_Problem).getNumberOfFoundOptima(elitepop);
|
||||
result += "(" + ((InterfaceMultimodalProblemKnown) m_Problem).getRealOptima().size() + ")\t";
|
||||
result += ((InterfaceMultimodalProblemKnown) m_Problem).getMaximumPeakRatio(elitepop) + "\t";
|
||||
if (optimizationProblem instanceof InterfaceMultimodalProblem) {
|
||||
result += ((InterfaceMultimodalProblemKnown) optimizationProblem).getNumberOfFoundOptima(elitepop);
|
||||
result += "(" + ((InterfaceMultimodalProblemKnown) optimizationProblem).getRealOptima().size() + ")\t";
|
||||
result += ((InterfaceMultimodalProblemKnown) optimizationProblem).getMaximumPeakRatio(elitepop) + "\t";
|
||||
//boolean[] opts = ((InterfaceMultimodalProblem)problem).whichOptimaAreFound(elitepop);
|
||||
//result += "Optima:";
|
||||
//for (int i = 0; i < opts.length; ++i){
|
||||
@ -1516,13 +1516,10 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
outputPath.mkdirs();
|
||||
}
|
||||
|
||||
//String outputPath = getDirForCurrentExperiment()+"/NichePSO-LogFiles/";
|
||||
//OutputPath = OutputPath + dirForCurrentExperiment+"\\NichePSO-LogFiles\\";
|
||||
|
||||
// file name
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd'_'HH.mm.ss'_'E");
|
||||
String m_StartDate = formatter.format(new Date());
|
||||
String name = "NichePSO-LogFile" + "__" + m_StartDate + ".dat";
|
||||
String startDate = formatter.format(new Date());
|
||||
String name = "NichePSO-LogFile" + "__" + startDate + ".dat";
|
||||
|
||||
File f = new File(outputPath, name); // plattform independent representation...
|
||||
|
||||
@ -1634,10 +1631,10 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
double[] a = new double[2];
|
||||
a[0] = 0.0;
|
||||
a[1] = 0.0;
|
||||
this.m_TopologySwarm = new TopoPlot("NichePSO-MainSwarm", "x", "y", a, a);
|
||||
this.m_TopologySwarm.setParams(60, 60);
|
||||
if (m_Problem instanceof Interface2DBorderProblem) {
|
||||
this.m_TopologySwarm.setTopology((Interface2DBorderProblem) this.m_Problem);
|
||||
this.topoPlot = new TopoPlot("NichePSO-MainSwarm", "x", "y", a, a);
|
||||
this.topoPlot.setParams(60, 60);
|
||||
if (optimizationProblem instanceof Interface2DBorderProblem) {
|
||||
this.topoPlot.setTopology((Interface2DBorderProblem) this.optimizationProblem);
|
||||
} // draws colored plot
|
||||
}
|
||||
|
||||
@ -1646,12 +1643,12 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
*/
|
||||
protected void cleanPlotSwarm() {
|
||||
// delete all previous points
|
||||
DElement[] elements = this.m_TopologySwarm.getFunctionArea().getDElements();
|
||||
DElement[] elements = this.topoPlot.getFunctionArea().getDElements();
|
||||
int lastIndex = elements.length - 1;
|
||||
DElement last = elements[lastIndex];
|
||||
while (last instanceof DPointSet || last instanceof DPoint || last instanceof DPointIcon) {
|
||||
this.m_TopologySwarm.getFunctionArea().removeDElement(last);
|
||||
// elements = this.m_TopologySwarm.getFunctionArea().getDElements();
|
||||
this.topoPlot.getFunctionArea().removeDElement(last);
|
||||
// elements = this.topoPlot.getFunctionArea().getDElements();
|
||||
lastIndex--;
|
||||
last = elements[lastIndex];
|
||||
}
|
||||
@ -1678,23 +1675,8 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
DPointIcon icon = new Chart2DDPointIconText(id + ds);
|
||||
((Chart2DDPointIconText) icon).setIcon(new Chart2DDPointIconCircle());
|
||||
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);
|
||||
((Chart2DDPointIconText) icon).setIcon(new Chart2DDPointIconCircle());
|
||||
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());
|
||||
point.setIcon(icon);
|
||||
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);
|
||||
((Chart2DDPointIconText) icon).setIcon(new Chart2DDPointIconCircle());
|
||||
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);
|
||||
((Chart2DDPointIconText) icon).setIcon(new Chart2DDPointIconCircle());
|
||||
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
|
||||
*/
|
||||
protected void plotMainSwarm(boolean withIDs) {
|
||||
if (this.m_Problem instanceof Interface2DBorderProblem) {
|
||||
if (this.optimizationProblem instanceof Interface2DBorderProblem) {
|
||||
DPointSet popRep = new DPointSet();
|
||||
InterfaceDataTypeDouble tmpIndy1;
|
||||
|
||||
@ -1787,7 +1769,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
tmpIndy1 = (InterfaceDataTypeDouble) mainpop.get(i);
|
||||
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
|
||||
if (withIDs) {
|
||||
@ -1821,10 +1803,10 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
for (int i = 0; i < this.getSubSwarms().size(); ++i) {
|
||||
ParticleSubSwarmOptimization currentsub = this.getSubSwarms().get(i);
|
||||
if (!currentsub.isActive() && plotInactive) {
|
||||
plotCircleForIndy(currentsub.m_BestIndividual, String.valueOf(i) + "[I]");
|
||||
plotCircleForIndy(currentsub.bestIndividual, String.valueOf(i) + "[I]");
|
||||
}
|
||||
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) {
|
||||
InterfaceDataTypeDouble tmpIndy1;
|
||||
Population swarmpop = (Population) swarm.getPopulation();
|
||||
InterfaceDataTypeDouble best = (InterfaceDataTypeDouble) swarm.m_BestIndividual;
|
||||
InterfaceDataTypeDouble best = (InterfaceDataTypeDouble) swarm.bestIndividual;
|
||||
DPointSet popRep = new DPointSet();
|
||||
|
||||
//...draw SubSwarm as points
|
||||
@ -1857,7 +1839,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
tmpIndy1 = (InterfaceDataTypeDouble) swarmpop.get(j);
|
||||
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
|
||||
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(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
|
||||
*/
|
||||
protected void plotSubSwarms() {
|
||||
if (this.m_Problem instanceof Interface2DBorderProblem) {
|
||||
if (this.optimizationProblem instanceof Interface2DBorderProblem) {
|
||||
//DPointSet popRep = new DPointSet();
|
||||
InterfaceDataTypeDouble tmpIndy1;
|
||||
|
||||
@ -1894,7 +1876,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
ParticleSubSwarmOptimization currentsubswarm = this.getSubSwarms().get(i);
|
||||
Population currentsubswarmpop = (Population) currentsubswarm.getPopulation();
|
||||
//InterfaceDataTypeDouble best = (InterfaceDataTypeDouble)currentsubswarmpop.getBestIndividual();
|
||||
InterfaceDataTypeDouble best = (InterfaceDataTypeDouble) currentsubswarm.m_BestIndividual;
|
||||
InterfaceDataTypeDouble best = (InterfaceDataTypeDouble) currentsubswarm.bestIndividual;
|
||||
DPointSet popRep = new DPointSet();
|
||||
|
||||
//...draw SubSwarm as points
|
||||
@ -1903,7 +1885,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
tmpIndy1 = (InterfaceDataTypeDouble) currentsubswarmpop.get(j);
|
||||
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
|
||||
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(best.getDoubleData()[0], best.getDoubleData()[1]));
|
||||
}
|
||||
this.m_TopologySwarm.getFunctionArea().addDElement(popRep); // time consuming
|
||||
this.topoPlot.getFunctionArea().addDElement(popRep); // time consuming
|
||||
}
|
||||
} // endif
|
||||
}
|
||||
@ -1985,7 +1967,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
// from deactivation and reinit
|
||||
if (deactivationOccured) {
|
||||
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){
|
||||
// plotSwarm(reinitedSwarm.get(i)," reinit");
|
||||
@ -2029,7 +2011,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
DPointIcon icon = new Chart2DDPointIconText("");
|
||||
((Chart2DDPointIconText) icon).setIcon(new Chart2DDPointIconPoint());
|
||||
point.setIcon(icon);
|
||||
this.m_TopologySwarm.getFunctionArea().addDElement(point);
|
||||
this.topoPlot.getFunctionArea().addDElement(point);
|
||||
|
||||
//plot oldPos
|
||||
if (!(indy.getData("oldPosition") == null)) {
|
||||
@ -2038,7 +2020,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
icon = new Chart2DDPointIconText("");
|
||||
((Chart2DDPointIconText) icon).setIcon(new Chart2DDPointIconCross());
|
||||
point.setIcon(icon);
|
||||
this.m_TopologySwarm.getFunctionArea().addDElement(point);
|
||||
this.topoPlot.getFunctionArea().addDElement(point);
|
||||
}
|
||||
|
||||
//plot personalBestPos
|
||||
@ -2047,7 +2029,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
icon = new Chart2DDPointIconText("");
|
||||
((Chart2DDPointIconText) icon).setIcon(new Chart2DDPointIconCircle());
|
||||
point.setIcon(icon);
|
||||
this.m_TopologySwarm.getFunctionArea().addDElement(point);
|
||||
this.topoPlot.getFunctionArea().addDElement(point);
|
||||
|
||||
//plot neighbourBestPos
|
||||
double[] neighbourBestPos = (double[]) indy.getData("neighbourBestPos");
|
||||
@ -2055,7 +2037,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
icon = new Chart2DDPointIconText("");
|
||||
((Chart2DDPointIconText) icon).setIcon(new Chart2DDPointIconContent());
|
||||
point.setIcon(icon);
|
||||
this.m_TopologySwarm.getFunctionArea().addDElement(point);
|
||||
this.topoPlot.getFunctionArea().addDElement(point);
|
||||
}
|
||||
|
||||
// protected void saveCurrentPlotAsJPG(String filename){
|
||||
@ -2077,16 +2059,16 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
//
|
||||
// File f = new File(outputPath,name);
|
||||
//
|
||||
// synchronized(m_TopologySwarm){
|
||||
// synchronized(topoPlot){
|
||||
// try {
|
||||
// JFrame frame = m_TopologySwarm.internalFrame;
|
||||
// JFrame frame = topoPlot.internalFrame;
|
||||
// Robot robot = new Robot();
|
||||
// Rectangle area;
|
||||
// area = frame.getBounds();
|
||||
// BufferedImage bufferedImage = robot.createScreenCapture(area);
|
||||
//
|
||||
// // 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());
|
||||
// try {
|
||||
// FileOutputStream fos = new FileOutputStream(f);
|
||||
|
@ -33,10 +33,10 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
|
||||
* <code>serialVersionUID</code>
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Population m_Population = new Population();
|
||||
private InterfaceOptimizationProblem m_Problem = new F1Problem();
|
||||
private InterfaceSelection m_ParentSelection = new SelectParticleWheel(0.5);
|
||||
private String m_Identifier = "";
|
||||
private Population population = new Population();
|
||||
private InterfaceOptimizationProblem optimizationProblem = new F1Problem();
|
||||
private InterfaceSelection parentSelection = new SelectParticleWheel(0.5);
|
||||
private String identifier = "";
|
||||
private boolean withShow = false;
|
||||
private double mutationSigma = 0.01;
|
||||
private double randomImmigrationQuota = 0.05;
|
||||
@ -45,7 +45,7 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
|
||||
private int popSize = 300;
|
||||
private int sleepTime = 0;
|
||||
transient private int indCount = 0;
|
||||
transient private InterfacePopulationChangedEventListener m_Listener;
|
||||
transient private InterfacePopulationChangedEventListener populationChangedEventListener;
|
||||
transient Plot myPlot = null;
|
||||
public static final boolean TRACE = false;
|
||||
|
||||
@ -60,20 +60,17 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
|
||||
initialVelocity = vInit;
|
||||
randomImmigrationQuota = immiQuote;
|
||||
rotationDeg = rotDeg;
|
||||
m_ParentSelection = new SelectParticleWheel(selScaling);
|
||||
parentSelection = new SelectParticleWheel(selScaling);
|
||||
if (withShow) {
|
||||
setWithShow(true);
|
||||
}
|
||||
}
|
||||
|
||||
public ParticleFilterOptimization(ParticleFilterOptimization a) {
|
||||
this.m_Population = (Population) a.m_Population.clone();
|
||||
this.m_Problem = (InterfaceOptimizationProblem) a.m_Problem.clone();
|
||||
this.m_Identifier = a.m_Identifier;
|
||||
//this.m_Plague = a.m_Plague;
|
||||
//this.m_NumberOfPartners = a.m_NumberOfPartners;
|
||||
//this.m_UseElitism = a.m_UseElitism;
|
||||
this.m_ParentSelection = (InterfaceSelection) a.m_ParentSelection.clone();
|
||||
this.population = (Population) a.population.clone();
|
||||
this.optimizationProblem = (InterfaceOptimizationProblem) a.optimizationProblem.clone();
|
||||
this.identifier = a.identifier;
|
||||
this.parentSelection = (InterfaceSelection) a.parentSelection.clone();
|
||||
if (a.withShow) {
|
||||
setWithShow(true);
|
||||
}
|
||||
@ -94,16 +91,16 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
|
||||
//System.out.println("pops targ is " + population.getPopulationSize());
|
||||
|
||||
if (initialVelocity <= 0.) {
|
||||
(((AbstractOptimizationProblem) m_Problem).getIndividualTemplate()).setMutationOperator(new MutateESFixedStepSize(mutationSigma));
|
||||
(((AbstractOptimizationProblem) optimizationProblem).getIndividualTemplate()).setMutationOperator(new MutateESFixedStepSize(mutationSigma));
|
||||
} else {
|
||||
(((AbstractOptimizationProblem) m_Problem).getIndividualTemplate()).setMutationOperator(new MutateESCorrVector(mutationSigma, initialVelocity, rotationDeg));
|
||||
(((AbstractOptimizationProblem) optimizationProblem).getIndividualTemplate()).setMutationOperator(new MutateESCorrVector(mutationSigma, initialVelocity, rotationDeg));
|
||||
}
|
||||
m_Population.setTargetSize(popSize);
|
||||
this.m_Problem.initializePopulation(this.m_Population);
|
||||
population.setTargetSize(popSize);
|
||||
this.optimizationProblem.initializePopulation(this.population);
|
||||
|
||||
setWithShow(withShow);
|
||||
|
||||
this.evaluatePopulation(this.m_Population);
|
||||
this.evaluatePopulation(this.population);
|
||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
|
||||
}
|
||||
|
||||
@ -115,10 +112,10 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
|
||||
*/
|
||||
@Override
|
||||
public void initByPopulation(Population pop, boolean reset) {
|
||||
this.m_Population = (Population) pop.clone();
|
||||
this.population = (Population) pop.clone();
|
||||
if (reset) {
|
||||
this.m_Population.init();
|
||||
this.evaluatePopulation(this.m_Population);
|
||||
this.population.init();
|
||||
this.evaluatePopulation(this.population);
|
||||
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
|
||||
*/
|
||||
private Population evaluatePopulation(Population population) {
|
||||
this.m_Problem.evaluate(population);
|
||||
this.optimizationProblem.evaluate(population);
|
||||
population.incrGeneration();
|
||||
return population;
|
||||
}
|
||||
@ -141,24 +138,24 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
|
||||
Population parents;
|
||||
boolean doImmigr = false;
|
||||
|
||||
this.m_ParentSelection.prepareSelection(pop);
|
||||
this.parentSelection.prepareSelection(pop);
|
||||
|
||||
// Generate a Population of Parents with Parantselectionmethod.
|
||||
// DONT forget cloning -> selection does only shallow copies!
|
||||
int targetSize = this.m_Population.getTargetSize();
|
||||
int targetSize = this.population.getTargetSize();
|
||||
if (randomImmigrationQuota > 0) {
|
||||
if (randomImmigrationQuota > 1.) {
|
||||
System.err.println("Error, invalid immigration quota!");
|
||||
} 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
|
||||
if (targetSize < this.m_Population.getTargetSize()) {
|
||||
if (targetSize < this.population.getTargetSize()) {
|
||||
doImmigr = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parents = (Population) (this.m_ParentSelection.selectFrom(pop, targetSize)).clone();
|
||||
parents = (Population) (this.parentSelection.selectFrom(pop, targetSize)).clone();
|
||||
|
||||
if (doImmigr) {
|
||||
// add immigrants
|
||||
@ -238,7 +235,7 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
|
||||
//AbstractEAIndividual elite;
|
||||
|
||||
// resample using selection
|
||||
nextGeneration = resample(m_Population);
|
||||
nextGeneration = resample(population);
|
||||
|
||||
if (sleepTime > 0) {
|
||||
try {
|
||||
@ -253,10 +250,10 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
|
||||
// predict step
|
||||
predict(nextGeneration);
|
||||
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);
|
||||
|
||||
@ -266,14 +263,14 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
|
||||
|
||||
@Override
|
||||
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
|
||||
this.m_Listener = ea;
|
||||
this.populationChangedEventListener = ea;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removePopulationChangedEventListener(
|
||||
InterfacePopulationChangedEventListener ea) {
|
||||
if (m_Listener == ea) {
|
||||
m_Listener = null;
|
||||
if (populationChangedEventListener == ea) {
|
||||
populationChangedEventListener = null;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@ -281,8 +278,8 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
|
||||
}
|
||||
|
||||
protected void firePropertyChangedEvent(String name) {
|
||||
if (this.m_Listener != null) {
|
||||
this.m_Listener.registerPopulationStateChanged(this, name);
|
||||
if (this.populationChangedEventListener != null) {
|
||||
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -293,7 +290,7 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
|
||||
*/
|
||||
@Override
|
||||
public void setProblem(InterfaceOptimizationProblem problem) {
|
||||
this.m_Problem = problem;
|
||||
this.optimizationProblem = problem;
|
||||
if (problem instanceof AbstractOptimizationProblem) {
|
||||
((AbstractOptimizationProblem) problem).informAboutOptimizer(this);
|
||||
}
|
||||
@ -301,7 +298,7 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
|
||||
|
||||
@Override
|
||||
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() {
|
||||
StringBuilder strB = new StringBuilder(200);
|
||||
strB.append("Particle Filter:\nOptimization Problem: ");
|
||||
strB.append(this.m_Problem.getStringRepresentationForProblem(this));
|
||||
strB.append(this.optimizationProblem.getStringRepresentationForProblem(this));
|
||||
strB.append("\n");
|
||||
strB.append(this.m_Population.getStringRepresentation());
|
||||
strB.append(this.population.getStringRepresentation());
|
||||
return strB.toString();
|
||||
}
|
||||
|
||||
@ -327,12 +324,12 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
|
||||
*/
|
||||
@Override
|
||||
public void setIdentifier(String name) {
|
||||
this.m_Identifier = name;
|
||||
this.identifier = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return this.m_Identifier;
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -354,12 +351,12 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
|
||||
*/
|
||||
@Override
|
||||
public Population getPopulation() {
|
||||
return this.m_Population;
|
||||
return this.population;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPopulation(Population pop) {
|
||||
this.m_Population = pop;
|
||||
this.population = pop;
|
||||
}
|
||||
|
||||
public String populationTipText() {
|
||||
@ -377,11 +374,11 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
|
||||
* @param selection
|
||||
*/
|
||||
public void setParentSelection(InterfaceSelection selection) {
|
||||
this.m_ParentSelection = selection;
|
||||
this.parentSelection = selection;
|
||||
}
|
||||
|
||||
public InterfaceSelection getParentSelection() {
|
||||
return this.m_ParentSelection;
|
||||
return this.parentSelection;
|
||||
}
|
||||
|
||||
public String parentSelectionTipText() {
|
||||
@ -403,8 +400,8 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
|
||||
if (myPlot != null) {
|
||||
myPlot.clearAll();
|
||||
double[][] range = null;
|
||||
if ((m_Population != null) && (m_Population.size() > 0)) {
|
||||
range = ((InterfaceDataTypeDouble) this.m_Population.get(0)).getDoubleRange();
|
||||
if ((population != null) && (population.size() > 0)) {
|
||||
range = ((InterfaceDataTypeDouble) this.population.get(0)).getDoubleRange();
|
||||
}
|
||||
if (range != null) {
|
||||
myPlot.setCornerPoints(range, 0);
|
||||
@ -421,8 +418,8 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
|
||||
myPlot = null;
|
||||
} else {
|
||||
double[][] range;
|
||||
if ((m_Population != null) && (m_Population.size() > 0)) {
|
||||
range = ((InterfaceDataTypeDouble) this.m_Population.get(0)).getDoubleRange();
|
||||
if ((population != null) && (population.size() > 0)) {
|
||||
range = ((InterfaceDataTypeDouble) this.population.get(0)).getDoubleRange();
|
||||
} else {
|
||||
range = 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) {
|
||||
this.popSize = popSize;
|
||||
m_Population.setTargetSize(popSize);
|
||||
population.setTargetSize(popSize);
|
||||
}
|
||||
}
|
||||
|
@ -54,8 +54,8 @@ public class ParticleSubSwarmOptimization extends ParticleSwarmOptimizationGCPSO
|
||||
*/
|
||||
public ParticleSubSwarmOptimization(ParticleSubSwarmOptimization a) {
|
||||
super(a);
|
||||
if (a.m_BestIndividual != null) {
|
||||
m_BestIndividual = (AbstractEAIndividual) a.m_BestIndividual.clone();
|
||||
if (a.bestIndividual != null) {
|
||||
bestIndividual = (AbstractEAIndividual) a.bestIndividual.clone();
|
||||
}
|
||||
|
||||
maxAllowedSwarmRadiusNormal = a.maxAllowedSwarmRadiusNormal;
|
||||
@ -250,7 +250,7 @@ public class ParticleSubSwarmOptimization extends ParticleSwarmOptimizationGCPSO
|
||||
|
||||
/**
|
||||
* @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)
|
||||
* 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.
|
||||
@ -259,18 +259,18 @@ public class ParticleSubSwarmOptimization extends ParticleSwarmOptimizationGCPSO
|
||||
if (getPopulation().size() == 0) {
|
||||
return;
|
||||
}
|
||||
// First: set m_BestIndividual to any personal best position in the swarm (-> bestindypbest).
|
||||
// This is necessary because the current m_BestIndividual my came from
|
||||
// First: set bestIndividual to any personal best position in the swarm (-> bestindypbest).
|
||||
// This is necessary because the current bestIndividual my came from
|
||||
// an individual that left the swarm and would never be replaced if it
|
||||
// would dominate all remaining positions in the swarm.
|
||||
AbstractEAIndividual bestindy = getPopulation().getBestEAIndividual();
|
||||
AbstractEAIndividual bestindypbest = (AbstractEAIndividual) bestindy.getData("PersonalBestKey");
|
||||
m_BestIndividual = (AbstractEAIndividual) bestindypbest.clone();
|
||||
bestIndividual = (AbstractEAIndividual) bestindypbest.clone();
|
||||
for (int i = 0; i < getPopulation().size(); ++i) {
|
||||
AbstractEAIndividual currentindy = getPopulation().getEAIndividual(i);
|
||||
AbstractEAIndividual currentindypbest = (AbstractEAIndividual) currentindy.getData("PersonalBestKey");
|
||||
if (currentindypbest.isDominating(m_BestIndividual)) {
|
||||
m_BestIndividual = (AbstractEAIndividual) currentindypbest.clone();
|
||||
if (currentindypbest.isDominating(bestIndividual)) {
|
||||
bestIndividual = (AbstractEAIndividual) currentindypbest.clone();
|
||||
// ++gbestImprovmentsInARow;
|
||||
} //else gbestImprovmentsInARow = 0;
|
||||
}
|
||||
@ -347,7 +347,7 @@ public class ParticleSubSwarmOptimization extends ParticleSwarmOptimizationGCPSO
|
||||
*/
|
||||
public void updateMaxPosDist() {
|
||||
// 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...
|
||||
AbstractEAIndividual template = prob.getIndividualTemplate();
|
||||
if (template == null) {
|
||||
@ -481,7 +481,7 @@ public class ParticleSubSwarmOptimization extends ParticleSwarmOptimizationGCPSO
|
||||
Population tmp = new Population();
|
||||
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 tmpIndy;
|
||||
|
||||
@ -494,7 +494,7 @@ public class ParticleSubSwarmOptimization extends ParticleSwarmOptimizationGCPSO
|
||||
///////////
|
||||
|
||||
ParticleSubSwarmOptimization tmpopt = new ParticleSubSwarmOptimization();
|
||||
tmpopt.setProblem(this.m_Problem);
|
||||
tmpopt.setProblem(this.optimizationProblem);
|
||||
tmpopt.evaluatePopulation(tmp);
|
||||
tmpopt.initByPopulation(tmp, false); // + size FCs
|
||||
|
||||
@ -605,7 +605,7 @@ public class ParticleSubSwarmOptimization extends ParticleSwarmOptimizationGCPSO
|
||||
*/
|
||||
@Override
|
||||
public void setProblem(InterfaceOptimizationProblem problem) {
|
||||
this.m_Problem = problem;
|
||||
this.optimizationProblem = problem;
|
||||
updateMaxPosDist();
|
||||
}
|
||||
|
||||
@ -623,11 +623,11 @@ public class ParticleSubSwarmOptimization extends ParticleSwarmOptimizationGCPSO
|
||||
|
||||
for (int i = 0; i < population.size(); ++i) {
|
||||
AbstractEAIndividual indy = population.getEAIndividual(i);
|
||||
//double dist = metric.distance(m_BestIndividual, indy);
|
||||
double sqrdDist = EuclideanMetric.squaredEuclideanDistance(AbstractEAIndividual.getDoublePositionShallow(m_BestIndividual),
|
||||
//double dist = metric.distance(bestIndividual, indy);
|
||||
double sqrdDist = EuclideanMetric.squaredEuclideanDistance(AbstractEAIndividual.getDoublePositionShallow(bestIndividual),
|
||||
AbstractEAIndividual.getDoublePositionShallow(indy));
|
||||
|
||||
//dist = distance(m_BestIndividual, indy);
|
||||
//dist = distance(bestIndividual, indy);
|
||||
if (sqrdDist > max) {
|
||||
max = sqrdDist;
|
||||
}
|
||||
@ -773,7 +773,7 @@ public class ParticleSubSwarmOptimization extends ParticleSwarmOptimizationGCPSO
|
||||
}
|
||||
|
||||
public AbstractEAIndividual getGBestIndividual() {
|
||||
return m_BestIndividual;
|
||||
return bestIndividual;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,8 +48,8 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
||||
private static final long serialVersionUID = -149996122795669589L;
|
||||
protected Population population = new Population();
|
||||
Object[] sortedPop = null;
|
||||
protected AbstractEAIndividual m_BestIndividual = null;
|
||||
protected InterfaceOptimizationProblem m_Problem = new F1Problem();
|
||||
protected AbstractEAIndividual bestIndividual = null;
|
||||
protected InterfaceOptimizationProblem optimizationProblem = new F1Problem();
|
||||
protected boolean checkRange = true;
|
||||
protected boolean checkSpeedLimit = 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 sortedIndexKey = "sortedParticleIndex";
|
||||
transient final static String dmsGroupIndexKey = "dmsGroupIndex";
|
||||
protected String m_Identifier = "";
|
||||
protected String indentifier = "";
|
||||
transient private Vector<InterfacePopulationChangedEventListener> changeListener;
|
||||
transient private TopoPlot topoPlot = null;
|
||||
/// 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;
|
||||
// for debugging only
|
||||
transient private static boolean TRACE = false;
|
||||
transient protected boolean m_Show = false;
|
||||
transient protected Plot m_Plot;
|
||||
transient protected boolean show = false;
|
||||
transient protected Plot plot;
|
||||
private boolean externalInitialPop = false;
|
||||
private static String lastSuccessKey = "successfulUpdate";
|
||||
// private double lsCandidateRatio=0.25;
|
||||
|
||||
public ParticleSwarmOptimization() {
|
||||
// this.m_Topology = new SelectedTag( "Linear", "Grid", "Star", "Multi-Swarm", "Tree", "HPSO", "Random" );
|
||||
// m_Topology.setSelectedTag(1);
|
||||
topology = PSOTopologyEnum.grid;
|
||||
algType = new SelectedTag("Inertness", "Constriction");
|
||||
algType.setSelectedTag(1);
|
||||
@ -123,14 +121,12 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
||||
|
||||
public ParticleSwarmOptimization(ParticleSwarmOptimization a) {
|
||||
topology = a.topology;
|
||||
// if (a.m_Topology != null)
|
||||
// this.m_Topology = (SelectedTag)a.m_Topology.clone();
|
||||
if (a.algType != null) {
|
||||
this.algType = (SelectedTag) a.algType.clone();
|
||||
}
|
||||
this.population = (Population) a.population.clone();
|
||||
this.m_Problem = a.m_Problem;
|
||||
this.m_Identifier = a.m_Identifier;
|
||||
this.optimizationProblem = a.optimizationProblem;
|
||||
this.indentifier = a.indentifier;
|
||||
this.initialVelocity = a.initialVelocity;
|
||||
this.speedLimit = a.speedLimit;
|
||||
this.phi1 = a.phi1;
|
||||
@ -195,9 +191,9 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
if (m_Plot != null) {
|
||||
// m_Plot.dispose();
|
||||
m_Plot = null;
|
||||
if (plot != null) {
|
||||
// plot.dispose();
|
||||
plot = null;
|
||||
}
|
||||
if (topoPlot != null) {
|
||||
// topoPlot.dispose();
|
||||
@ -205,13 +201,13 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
||||
}
|
||||
tracedVelocity = null;
|
||||
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
|
||||
initDefaults(this.population);
|
||||
this.evaluatePopulation(this.population);
|
||||
if (m_BestIndividual == null) {
|
||||
m_BestIndividual = population.getBestEAIndividual();
|
||||
if (bestIndividual == null) {
|
||||
bestIndividual = population.getBestEAIndividual();
|
||||
}
|
||||
initByPopulation(null, false);
|
||||
externalInitialPop = false;
|
||||
@ -282,7 +278,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
||||
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)));
|
||||
}
|
||||
}
|
||||
@ -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) {
|
||||
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
|
||||
*/
|
||||
protected void evaluatePopulation(Population population) {
|
||||
this.m_Problem.evaluate(population);
|
||||
this.optimizationProblem.evaluate(population);
|
||||
population.incrGeneration();
|
||||
if (emaPeriods > 0) {
|
||||
traceEMA(population);
|
||||
@ -678,37 +674,37 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
||||
}
|
||||
|
||||
protected void plotIndy(double[] curPosition, double[] curVelocity, int index) {
|
||||
if (this.m_Show) {
|
||||
if (this.show) {
|
||||
if (curVelocity == null) {
|
||||
this.m_Plot.setUnconnectedPoint(curPosition[0], curPosition[1], index);
|
||||
this.plot.setUnconnectedPoint(curPosition[0], curPosition[1], index);
|
||||
} else {
|
||||
this.m_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], curPosition[1], index);
|
||||
this.plot.setConnectedPoint(curPosition[0] + curVelocity[0], curPosition[1] + curVelocity[1], index);
|
||||
}
|
||||
|
||||
// m_Plot = null;
|
||||
// plot = null;
|
||||
// show();
|
||||
// if (pop.getGeneration()%15 == 0) {
|
||||
// this.m_Plot.clearAll();
|
||||
// m_Plot.setUnconnectedPoint(-10, -10, 0);
|
||||
// m_Plot.setUnconnectedPoint(10, 10, 0);
|
||||
// this.plot.clearAll();
|
||||
// plot.setUnconnectedPoint(-10, -10, 0);
|
||||
// plot.setUnconnectedPoint(10, 10, 0);
|
||||
// }
|
||||
|
||||
// if (index != 0) return;
|
||||
// double[] bestPosition = (double[])m_BestIndividual.getData(partBestPosKey);
|
||||
// double[] bestPosition = (double[])bestIndividual.getData(partBestPosKey);
|
||||
// double[] localBestPos = findNeighbourhoodOptimum(index, population);
|
||||
// this.m_Plot.setConnectedPoint(curPosition[0], curPosition[1], index+1);
|
||||
// this.m_Plot.setConnectedPoint(curPosition[0] + curVelocity[0], curPosition[1] + curVelocity[1], index+1);
|
||||
// this.m_Plot.setConnectedPoint(curPosition[0], curPosition[1], index+2);
|
||||
// this.m_Plot.setConnectedPoint(bestPosition[0], bestPosition[1], index+2);
|
||||
// this.m_Plot.setConnectedPoint(curPosition[0], curPosition[1], index+3);
|
||||
// this.m_Plot.setConnectedPoint(localBestPos[0], localBestPos[1], index+3);
|
||||
// this.plot.setConnectedPoint(curPosition[0], curPosition[1], index+1);
|
||||
// this.plot.setConnectedPoint(curPosition[0] + curVelocity[0], curPosition[1] + curVelocity[1], index+1);
|
||||
// this.plot.setConnectedPoint(curPosition[0], curPosition[1], index+2);
|
||||
// this.plot.setConnectedPoint(bestPosition[0], bestPosition[1], index+2);
|
||||
// this.plot.setConnectedPoint(curPosition[0], curPosition[1], index+3);
|
||||
// this.plot.setConnectedPoint(localBestPos[0], localBestPos[1], index+3);
|
||||
|
||||
// this.m_Plot.setConnectedPoint(curPosition[0], curPosition[1], index+1);
|
||||
// this.m_Plot.setConnectedPoint(localBestPosition[0], localBestPosition[1], index+1);
|
||||
// this.m_Plot.setConnectedPoint(curPosition[0], curPosition[1], index+1);
|
||||
// this.m_Plot.setConnectedPoint(bestPosition[0], bestPosition[1], index+1);
|
||||
// this.m_Plot.setUnconnectedPoint(curPosition[0], curPosition[1], 100*index+1);
|
||||
// this.plot.setConnectedPoint(curPosition[0], curPosition[1], index+1);
|
||||
// this.plot.setConnectedPoint(localBestPosition[0], localBestPosition[1], index+1);
|
||||
// this.plot.setConnectedPoint(curPosition[0], curPosition[1], index+1);
|
||||
// this.plot.setConnectedPoint(bestPosition[0], bestPosition[1], 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();
|
||||
localBestPosition = ((double[]) (indy).getData(partBestPosKey)).clone();
|
||||
if (useHistoric) {
|
||||
bestIndy = m_BestIndividual;
|
||||
bestIndy = bestIndividual;
|
||||
} else {
|
||||
bestIndy = pop.getBestEAIndividual();
|
||||
}
|
||||
@ -1403,11 +1399,11 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
||||
}
|
||||
|
||||
protected void maybeClearPlot() {
|
||||
if (((population.getGeneration() % 23) == 0) && isShow() && (m_Plot != null)) {
|
||||
m_Plot.clearAll();
|
||||
if (((population.getGeneration() % 23) == 0) && isShow() && (plot != null)) {
|
||||
plot.clearAll();
|
||||
InterfaceDataTypeDouble indy = (InterfaceDataTypeDouble) this.population.get(0);
|
||||
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)));
|
||||
}
|
||||
}
|
||||
if (this.m_Show) {
|
||||
if (this.show) {
|
||||
this.show();
|
||||
}
|
||||
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.
|
||||
*/
|
||||
protected void logBestIndividual() {
|
||||
if (this.population.getBestEAIndividual().isDominatingDebConstraints(this.m_BestIndividual)) {
|
||||
this.m_BestIndividual = (AbstractEAIndividual) this.population.getBestEAIndividual().clone();
|
||||
this.m_BestIndividual.putData(partBestFitKey, this.m_BestIndividual.getFitness().clone());
|
||||
this.m_BestIndividual.putData(partBestPosKey, ((InterfaceDataTypeDouble) this.m_BestIndividual).getDoubleData());
|
||||
// System.out.println("new best: "+m_BestIndividual.toString());
|
||||
if (this.population.getBestEAIndividual().isDominatingDebConstraints(this.bestIndividual)) {
|
||||
this.bestIndividual = (AbstractEAIndividual) this.population.getBestEAIndividual().clone();
|
||||
this.bestIndividual.putData(partBestFitKey, this.bestIndividual.getFitness().clone());
|
||||
this.bestIndividual.putData(partBestPosKey, ((InterfaceDataTypeDouble) this.bestIndividual).getDoubleData());
|
||||
// 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);
|
||||
}
|
||||
|
||||
if (m_Show) {
|
||||
if (this.m_Problem instanceof Interface2DBorderProblem) {
|
||||
if (show) {
|
||||
if (this.optimizationProblem instanceof Interface2DBorderProblem) {
|
||||
DPointSet popRep = new DPointSet();
|
||||
InterfaceDataTypeDouble tmpIndy1;
|
||||
|
||||
@ -1464,7 +1460,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
||||
if (topoPlot == null) {
|
||||
this.topoPlot = new TopoPlot("CBN-Species", "x", "y", a, a);
|
||||
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++) {
|
||||
@ -1487,8 +1483,6 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
||||
}
|
||||
|
||||
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 (pop.getGeneration() % getDmsRegroupGens() == 0) {
|
||||
dmsLinks = regroupSwarm(pop, getTopologyRange());
|
||||
@ -1650,12 +1644,12 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
||||
* This method is simply for debugging.
|
||||
*/
|
||||
protected void show() {
|
||||
if (this.m_Plot == null) {
|
||||
if (this.plot == null) {
|
||||
InterfaceDataTypeDouble indy = (InterfaceDataTypeDouble) this.population.get(0);
|
||||
double[][] range = indy.getDoubleRange();
|
||||
this.m_Plot = new Plot("PSO " + population.getGeneration(), "x1", "x2", range[0], range[1]);
|
||||
// this.m_Plot.setUnconnectedPoint(range[0][0], range[1][0], 0);
|
||||
// this.m_Plot.setUnconnectedPoint(range[0][1], range[1][1], 0);
|
||||
this.plot = new Plot("PSO " + population.getGeneration(), "x1", "x2", range[0], range[1]);
|
||||
// this.plot.setUnconnectedPoint(range[0][0], range[1][0], 0);
|
||||
// this.plot.setUnconnectedPoint(range[0][1], range[1][1], 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1702,12 +1696,12 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
||||
*/
|
||||
@Override
|
||||
public void setProblem(InterfaceOptimizationProblem problem) {
|
||||
this.m_Problem = problem;
|
||||
this.optimizationProblem = problem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InterfaceOptimizationProblem getProblem() {
|
||||
return this.m_Problem;
|
||||
return this.optimizationProblem;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1721,7 +1715,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
||||
String result = "";
|
||||
result += "Particle Swarm Optimization:\n";
|
||||
result += "Optimization Problem: ";
|
||||
result += this.m_Problem.getStringRepresentationForProblem(this) + "\n";
|
||||
result += this.optimizationProblem.getStringRepresentationForProblem(this) + "\n";
|
||||
result += this.population.getStringRepresentation();
|
||||
return result;
|
||||
}
|
||||
@ -1733,12 +1727,12 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
||||
*/
|
||||
@Override
|
||||
public void setIdentifier(String name) {
|
||||
this.m_Identifier = name;
|
||||
this.indentifier = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
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() {
|
||||
@ -1792,7 +1786,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
||||
}
|
||||
|
||||
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) {
|
||||
// this.m_Topology = new SelectedTag( "Linear", "Grid", "Star", "Multi-Swarm", "Tree", "HPSO", "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));
|
||||
@ -2054,16 +2047,16 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
||||
* @return true if swarm visualization is turned on
|
||||
*/
|
||||
public boolean isShow() {
|
||||
return m_Show;
|
||||
return show;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param set swarm visualization (2D)
|
||||
*/
|
||||
public void setShow(boolean show) {
|
||||
m_Show = show;
|
||||
this.show = show;
|
||||
if (!show) {
|
||||
m_Plot = null;
|
||||
plot = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2215,9 +2208,9 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
||||
|
||||
double relDiff;
|
||||
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 {
|
||||
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 (Math.abs(relDiff) > 1e-20) {
|
||||
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) {
|
||||
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);
|
||||
indy.setFitness(personalBestfit);
|
||||
|
@ -28,30 +28,30 @@ import eva2.util.annotation.Description;
|
||||
public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, java.io.Serializable {
|
||||
|
||||
// These variables are necessary for the simple testcase
|
||||
private InterfaceOptimizationProblem m_Problem = new B1Problem();
|
||||
private boolean m_UseElitism = true;
|
||||
private InterfaceSelection m_SelectionOperator = new SelectBestIndividuals();
|
||||
transient private String m_Identifier = "";
|
||||
transient private InterfacePopulationChangedEventListener m_Listener;
|
||||
private Population m_Population = new PBILPopulation();
|
||||
private double m_LearningRate = 0.04;
|
||||
private double m_MutationRate = 0.5;
|
||||
private double m_MutateSigma = 0.01;
|
||||
private int m_NumberOfPositiveSamples = 1;
|
||||
private double[] m_initialProbabilities = ((PBILPopulation) m_Population).getProbabilityVector();
|
||||
private InterfaceOptimizationProblem optimizationProblem = new B1Problem();
|
||||
private boolean useElitism = true;
|
||||
private InterfaceSelection selectionOperator = new SelectBestIndividuals();
|
||||
transient private String identifier = "";
|
||||
transient private InterfacePopulationChangedEventListener populationChangedEventListener;
|
||||
private Population population = new PBILPopulation();
|
||||
private double learningRate = 0.04;
|
||||
private double mutationRate = 0.5;
|
||||
private double mutateSigma = 0.01;
|
||||
private int numberOfPositiveSamples = 1;
|
||||
private double[] initialProbabilities = ((PBILPopulation) population).getProbabilityVector();
|
||||
|
||||
public PopulationBasedIncrementalLearning() {
|
||||
}
|
||||
|
||||
public PopulationBasedIncrementalLearning(PopulationBasedIncrementalLearning a) {
|
||||
this.m_Population = (Population) a.m_Population.clone();
|
||||
this.m_Problem = (InterfaceOptimizationProblem) a.m_Problem.clone();
|
||||
this.m_LearningRate = a.m_LearningRate;
|
||||
this.m_MutationRate = a.m_MutationRate;
|
||||
this.m_MutateSigma = a.m_MutateSigma;
|
||||
this.m_NumberOfPositiveSamples = a.m_NumberOfPositiveSamples;
|
||||
this.m_UseElitism = a.m_UseElitism;
|
||||
this.m_SelectionOperator = (InterfaceSelection) a.m_SelectionOperator.clone();
|
||||
this.population = (Population) a.population.clone();
|
||||
this.optimizationProblem = (InterfaceOptimizationProblem) a.optimizationProblem.clone();
|
||||
this.learningRate = a.learningRate;
|
||||
this.mutationRate = a.mutationRate;
|
||||
this.mutateSigma = a.mutateSigma;
|
||||
this.numberOfPositiveSamples = a.numberOfPositiveSamples;
|
||||
this.useElitism = a.useElitism;
|
||||
this.selectionOperator = (InterfaceSelection) a.selectionOperator.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -61,15 +61,15 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
this.m_Problem.initializePopulation(this.m_Population);
|
||||
if ((m_initialProbabilities != null) && (m_initialProbabilities.length == ((PBILPopulation) m_Population).getProbabilityVector().length)) {
|
||||
((PBILPopulation) m_Population).setProbabilityVector(m_initialProbabilities);
|
||||
this.optimizationProblem.initializePopulation(this.population);
|
||||
if ((initialProbabilities != null) && (initialProbabilities.length == ((PBILPopulation) population).getProbabilityVector().length)) {
|
||||
((PBILPopulation) population).setProbabilityVector(initialProbabilities);
|
||||
} else {
|
||||
if (m_initialProbabilities != null) {
|
||||
if (initialProbabilities != null) {
|
||||
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);
|
||||
}
|
||||
|
||||
@ -84,13 +84,13 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
|
||||
if (!(pop.getEAIndividual(0) instanceof InterfaceGAIndividual)) {
|
||||
System.err.println("Error: PBIL only works with GAIndividuals!");
|
||||
}
|
||||
this.m_Population = new PBILPopulation();
|
||||
this.m_Population.addPopulation((Population) pop.clone());
|
||||
this.population = new PBILPopulation();
|
||||
this.population.addPopulation((Population) pop.clone());
|
||||
if (reset) {
|
||||
this.m_Population.init();
|
||||
this.evaluatePopulation(this.m_Population);
|
||||
this.population.init();
|
||||
this.evaluatePopulation(this.population);
|
||||
}
|
||||
((PBILPopulation) this.m_Population).buildProbabilityVector();
|
||||
((PBILPopulation) this.population).buildProbabilityVector();
|
||||
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
|
||||
*/
|
||||
private void evaluatePopulation(Population population) {
|
||||
this.m_Problem.evaluate(population);
|
||||
this.optimizationProblem.evaluate(population);
|
||||
population.incrGeneration();
|
||||
}
|
||||
|
||||
@ -109,16 +109,14 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
|
||||
* population of evaluated individuals.
|
||||
*/
|
||||
private Population generateChildren() {
|
||||
PBILPopulation result = (PBILPopulation) this.m_Population.clone();
|
||||
PBILPopulation result = (PBILPopulation) this.population.clone();
|
||||
Population examples;
|
||||
|
||||
// this.m_NormationOperator.computeSelectionProbability(this.population, "Fitness");
|
||||
//System.out.println("Population:"+this.population.getSolutionRepresentationFor());
|
||||
this.m_SelectionOperator.prepareSelection(this.m_Population);
|
||||
examples = this.m_SelectionOperator.selectFrom(this.m_Population, this.m_NumberOfPositiveSamples);
|
||||
//System.out.println("Parents:"+parents.getSolutionRepresentationFor());
|
||||
result.learnFrom(examples, this.m_LearningRate);
|
||||
result.mutateProbabilityVector(this.m_MutationRate, this.m_MutateSigma);
|
||||
|
||||
this.selectionOperator.prepareSelection(this.population);
|
||||
examples = this.selectionOperator.selectFrom(this.population, this.numberOfPositiveSamples);
|
||||
result.learnFrom(examples, this.learningRate);
|
||||
result.mutateProbabilityVector(this.mutationRate, this.mutateSigma);
|
||||
result.initPBIL();
|
||||
return result;
|
||||
}
|
||||
@ -130,12 +128,12 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
|
||||
|
||||
nextGeneration = this.generateChildren();
|
||||
this.evaluatePopulation(nextGeneration);
|
||||
if (this.m_UseElitism) {
|
||||
elite = this.m_Population.getBestEAIndividual();
|
||||
this.m_Population = nextGeneration;
|
||||
this.m_Population.add(0, elite);
|
||||
if (this.useElitism) {
|
||||
elite = this.population.getBestEAIndividual();
|
||||
this.population = nextGeneration;
|
||||
this.population.add(0, elite);
|
||||
} else {
|
||||
this.m_Population = nextGeneration;
|
||||
this.population = nextGeneration;
|
||||
}
|
||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
|
||||
}
|
||||
@ -147,9 +145,9 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
|
||||
*/
|
||||
@Override
|
||||
public void setProblem(InterfaceOptimizationProblem problem) {
|
||||
this.m_Problem = problem;
|
||||
if (m_Problem instanceof AbstractOptimizationProblem) {
|
||||
if (!(((AbstractOptimizationProblem) m_Problem).getIndividualTemplate() instanceof InterfaceGAIndividual)) {
|
||||
this.optimizationProblem = problem;
|
||||
if (optimizationProblem instanceof AbstractOptimizationProblem) {
|
||||
if (!(((AbstractOptimizationProblem) optimizationProblem).getIndividualTemplate() instanceof InterfaceGAIndividual)) {
|
||||
System.err.println("Error: PBIL only works with GAIndividuals!");
|
||||
}
|
||||
}
|
||||
@ -157,19 +155,19 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
|
||||
|
||||
@Override
|
||||
public InterfaceOptimizationProblem getProblem() {
|
||||
return this.m_Problem;
|
||||
return this.optimizationProblem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
|
||||
this.m_Listener = ea;
|
||||
this.populationChangedEventListener = ea;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removePopulationChangedEventListener(
|
||||
InterfacePopulationChangedEventListener ea) {
|
||||
if (m_Listener == ea) {
|
||||
m_Listener = null;
|
||||
if (populationChangedEventListener == ea) {
|
||||
populationChangedEventListener = null;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@ -180,8 +178,8 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
|
||||
* Something has changed
|
||||
*/
|
||||
protected void firePropertyChangedEvent(String name) {
|
||||
if (this.m_Listener != null) {
|
||||
this.m_Listener.registerPopulationStateChanged(this, name);
|
||||
if (this.populationChangedEventListener != null) {
|
||||
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -196,8 +194,8 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
|
||||
String result = "";
|
||||
result += "Population Based Incremental Learning:\n";
|
||||
result += "Optimization Problem: ";
|
||||
result += this.m_Problem.getStringRepresentationForProblem(this) + "\n";
|
||||
result += this.m_Population.getStringRepresentation();
|
||||
result += this.optimizationProblem.getStringRepresentationForProblem(this) + "\n";
|
||||
result += this.population.getStringRepresentation();
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -208,12 +206,12 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
|
||||
*/
|
||||
@Override
|
||||
public void setIdentifier(String name) {
|
||||
this.m_Identifier = name;
|
||||
this.identifier = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return this.m_Identifier;
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -235,12 +233,12 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
|
||||
*/
|
||||
@Override
|
||||
public Population getPopulation() {
|
||||
return this.m_Population;
|
||||
return this.population;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPopulation(Population pop) {
|
||||
this.m_Population = pop;
|
||||
this.population = pop;
|
||||
}
|
||||
|
||||
public String populationTipText() {
|
||||
@ -251,18 +249,6 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
|
||||
public InterfaceSolutionSet getAllSolutions() {
|
||||
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
|
||||
@ -270,11 +256,11 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
|
||||
* @param selection
|
||||
*/
|
||||
public void setSelectionMethod(InterfaceSelection selection) {
|
||||
this.m_SelectionOperator = selection;
|
||||
this.selectionOperator = selection;
|
||||
}
|
||||
|
||||
public InterfaceSelection getSelectionMethod() {
|
||||
return this.m_SelectionOperator;
|
||||
return this.selectionOperator;
|
||||
}
|
||||
|
||||
public String selectionMethodTipText() {
|
||||
@ -287,11 +273,11 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
|
||||
* @param elitism
|
||||
*/
|
||||
public void setElitism(boolean elitism) {
|
||||
this.m_UseElitism = elitism;
|
||||
this.useElitism = elitism;
|
||||
}
|
||||
|
||||
public boolean getElitism() {
|
||||
return this.m_UseElitism;
|
||||
return this.useElitism;
|
||||
}
|
||||
|
||||
public String elitismTipText() {
|
||||
@ -304,14 +290,14 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
|
||||
* @param LearningRate
|
||||
*/
|
||||
public void setLearningRate(double LearningRate) {
|
||||
this.m_LearningRate = LearningRate;
|
||||
if (this.m_LearningRate < 0) {
|
||||
this.m_LearningRate = 0;
|
||||
this.learningRate = LearningRate;
|
||||
if (this.learningRate < 0) {
|
||||
this.learningRate = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public double getLearningRate() {
|
||||
return this.m_LearningRate;
|
||||
return this.learningRate;
|
||||
}
|
||||
|
||||
public String learningRateTipText() {
|
||||
@ -324,17 +310,17 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
|
||||
* @param m
|
||||
*/
|
||||
public void setMutationRate(double m) {
|
||||
this.m_MutationRate = m;
|
||||
if (this.m_MutationRate < 0) {
|
||||
this.m_MutationRate = 0;
|
||||
this.mutationRate = m;
|
||||
if (this.mutationRate < 0) {
|
||||
this.mutationRate = 0;
|
||||
}
|
||||
if (this.m_MutationRate > 1) {
|
||||
this.m_MutationRate = 1;
|
||||
if (this.mutationRate > 1) {
|
||||
this.mutationRate = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public double getMutationRate() {
|
||||
return this.m_MutationRate;
|
||||
return this.mutationRate;
|
||||
}
|
||||
|
||||
public String mutationRateTipText() {
|
||||
@ -347,14 +333,14 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
|
||||
* @param m
|
||||
*/
|
||||
public void setMutateSigma(double m) {
|
||||
this.m_MutateSigma = m;
|
||||
if (this.m_MutateSigma < 0) {
|
||||
this.m_MutateSigma = 0;
|
||||
this.mutateSigma = m;
|
||||
if (this.mutateSigma < 0) {
|
||||
this.mutateSigma = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public double getMutateSigma() {
|
||||
return this.m_MutateSigma;
|
||||
return this.mutateSigma;
|
||||
}
|
||||
|
||||
public String mutateSigmaTipText() {
|
||||
@ -367,14 +353,14 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
|
||||
* @param PositiveSamples
|
||||
*/
|
||||
public void setPositiveSamples(int PositiveSamples) {
|
||||
this.m_NumberOfPositiveSamples = PositiveSamples;
|
||||
if (this.m_NumberOfPositiveSamples < 1) {
|
||||
this.m_NumberOfPositiveSamples = 1;
|
||||
this.numberOfPositiveSamples = PositiveSamples;
|
||||
if (this.numberOfPositiveSamples < 1) {
|
||||
this.numberOfPositiveSamples = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public int getPositiveSamples() {
|
||||
return this.m_NumberOfPositiveSamples;
|
||||
return this.numberOfPositiveSamples;
|
||||
}
|
||||
|
||||
public String positiveSamplesTipText() {
|
||||
@ -382,10 +368,10 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
|
||||
}
|
||||
|
||||
public double[] getInitialProbabilities() {
|
||||
return m_initialProbabilities;
|
||||
return initialProbabilities;
|
||||
}
|
||||
|
||||
public void setInitialProbabilities(double[] probabilities) {
|
||||
m_initialProbabilities = probabilities;
|
||||
initialProbabilities = probabilities;
|
||||
}
|
||||
}
|
@ -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")
|
||||
public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable, InterfacePopulationChangedEventListener {
|
||||
|
||||
transient private InterfacePopulationChangedEventListener m_Listener = null;
|
||||
private String m_Identifier = "ScatterSearch";
|
||||
private AbstractOptimizationProblem problem = new F1Problem();
|
||||
transient private InterfacePopulationChangedEventListener listener = null;
|
||||
private String identifier = "ScatterSearch";
|
||||
private AbstractOptimizationProblem optimizationProblem = new F1Problem();
|
||||
private Population oldRefSet, refSet = new Population(10);
|
||||
private transient Population combinations = null;
|
||||
private AbstractEAIndividual template = null;
|
||||
@ -79,7 +79,7 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
|
||||
|
||||
public ScatterSearch(ScatterSearch o) {
|
||||
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.range = ((InterfaceDataTypeDouble) template).getDoubleRange();
|
||||
this.refSetSize = o.refSetSize;
|
||||
@ -104,7 +104,7 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
|
||||
|
||||
@Override
|
||||
public void setProblem(InterfaceOptimizationProblem problem) {
|
||||
this.problem = (AbstractOptimizationProblem) problem;
|
||||
this.optimizationProblem = (AbstractOptimizationProblem) problem;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -136,7 +136,7 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
|
||||
* @param pop
|
||||
*/
|
||||
private void initRefSet(Population pop) {
|
||||
problem.evaluate(pop);
|
||||
optimizationProblem.evaluate(pop);
|
||||
if (TRACE) {
|
||||
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;
|
||||
refSet = null;
|
||||
combinations = null;
|
||||
template = problem.getIndividualTemplate();
|
||||
template = optimizationProblem.getIndividualTemplate();
|
||||
if (!(template instanceof InterfaceDataTypeDouble)) {
|
||||
System.err.println("Requiring double data!");
|
||||
} else {
|
||||
Object dim = BeanInspector.callIfAvailable(problem, "getProblemDimension", null);
|
||||
Object dim = BeanInspector.callIfAvailable(optimizationProblem, "getProblemDimension", null);
|
||||
if (dim == null) {
|
||||
System.err.println("Couldnt get problem dimension!");
|
||||
}
|
||||
@ -176,15 +176,15 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
|
||||
* Something has changed
|
||||
*/
|
||||
protected void firePropertyChangedEvent(String name) {
|
||||
if (this.m_Listener != null) {
|
||||
this.m_Listener.registerPopulationStateChanged(this, name);
|
||||
if (this.listener != null) {
|
||||
this.listener.registerPopulationStateChanged(this, name);
|
||||
}
|
||||
}
|
||||
|
||||
// public double evaluate(double[] x) {
|
||||
// AbstractEAIndividual indy = (AbstractEAIndividual)template.clone();
|
||||
// ((InterfaceDataTypeDouble)indy).setDoubleGenotype(x);
|
||||
// problem.evaluate(indy);
|
||||
// optimizationProblem.evaluate(indy);
|
||||
// return indy.getFitness(0);
|
||||
// }
|
||||
@Override
|
||||
@ -224,7 +224,7 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
|
||||
}
|
||||
firstTime = false;
|
||||
|
||||
problem.evaluatePopulationStart(refSet);
|
||||
optimizationProblem.evaluatePopulationStart(refSet);
|
||||
int funCallsStart = refSet.getFunctionCalls();
|
||||
do {
|
||||
if (combinations == null || combinations.size() == 0) {
|
||||
@ -243,7 +243,7 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
|
||||
updateRefSet(refSet, combinations, oldRefSet);
|
||||
}
|
||||
} while (refSet.getFunctionCalls() - funCallsStart < generationCycle);
|
||||
problem.evaluatePopulationEnd(refSet);
|
||||
optimizationProblem.evaluatePopulationEnd(refSet);
|
||||
|
||||
if (TRACE) {
|
||||
System.out.println("Improvements: " + lastImprovementCount);
|
||||
@ -302,7 +302,7 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
|
||||
}
|
||||
AbstractEAIndividual winner = diversifiedPop.getEAIndividual(sel);
|
||||
// evaluate the new indy
|
||||
problem.evaluate(winner);
|
||||
optimizationProblem.evaluate(winner);
|
||||
// add it to the newRefSet, increase h
|
||||
newRefSet.add(winner);
|
||||
newRefSet.incrFunctionCalls();
|
||||
@ -416,7 +416,7 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
|
||||
if (localSearchMethod.getSelectedTagID() == 0) {
|
||||
return localSolverHC(cand, hcSteps);
|
||||
} 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();
|
||||
Population hcPop = new Population(1);
|
||||
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);
|
||||
}
|
||||
|
||||
@ -548,7 +548,7 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
|
||||
Mathematics.projectToRange(combi, range);
|
||||
}
|
||||
((InterfaceDataTypeDouble) resIndy).setDoubleGenotype(combi);
|
||||
problem.evaluate(resIndy);
|
||||
optimizationProblem.evaluate(resIndy);
|
||||
refSet.incrFunctionCalls();
|
||||
return resIndy;
|
||||
}
|
||||
@ -735,12 +735,12 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
|
||||
///////////// Trivials...
|
||||
@Override
|
||||
public void setIdentifier(String name) {
|
||||
m_Identifier = name;
|
||||
identifier = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InterfaceOptimizationProblem getProblem() {
|
||||
return problem;
|
||||
return optimizationProblem;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -751,14 +751,14 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
|
||||
@Override
|
||||
public void addPopulationChangedEventListener(
|
||||
InterfacePopulationChangedEventListener ea) {
|
||||
m_Listener = ea;
|
||||
listener = ea;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removePopulationChangedEventListener(
|
||||
InterfacePopulationChangedEventListener ea) {
|
||||
if (m_Listener == ea) {
|
||||
m_Listener = null;
|
||||
if (listener == ea) {
|
||||
listener = null;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@ -767,7 +767,7 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return m_Identifier;
|
||||
return identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -872,7 +872,7 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
|
||||
InterfaceTerminator term, String dataPrefix,
|
||||
AbstractOptimizationProblem problem, InterfacePopulationChangedEventListener listener) {
|
||||
|
||||
// problem.initializeProblem();
|
||||
// optimizationProblem.initializeProblem();
|
||||
|
||||
OptimizationParameters params = specialSS(localSearchSteps, localSearchFitnessFilter, nmInitPerturb, relativeFitCrit, refSetSize, problem, term);
|
||||
|
||||
|
@ -21,29 +21,29 @@ import eva2.util.annotation.Description;
|
||||
public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializable {
|
||||
// These variables are necessary for the simple testcase
|
||||
|
||||
private InterfaceOptimizationProblem m_Problem = new B1Problem();
|
||||
private int m_MultiRuns = 100;
|
||||
private int m_FitnessCalls = 100;
|
||||
private int m_FitnessCallsNeeded = 0;
|
||||
GAIndividualBinaryData m_Best, m_Test;
|
||||
public double m_InitialTemperature = 2, m_CurrentTemperature;
|
||||
public double m_Alpha = 0.9;
|
||||
private InterfaceOptimizationProblem optimizationProblem = new B1Problem();
|
||||
private int multiRuns = 100;
|
||||
private int fitnessCalls = 100;
|
||||
private int fitnessCallsNeeded = 0;
|
||||
GAIndividualBinaryData bestIndividual, testIndividual;
|
||||
public double initialTemperature = 2, currentTemperature;
|
||||
public double alpha = 0.9;
|
||||
// These variables are necessary for the more complex LectureGUI enviroment
|
||||
transient private String m_Identifier = "";
|
||||
transient private InterfacePopulationChangedEventListener m_Listener;
|
||||
private Population m_Population;
|
||||
transient private String identifier = "";
|
||||
transient private InterfacePopulationChangedEventListener populationChangedEventListener;
|
||||
private Population population;
|
||||
|
||||
public SimulatedAnnealing() {
|
||||
this.m_Population = new Population();
|
||||
this.m_Population.setTargetSize(10);
|
||||
this.population = new Population();
|
||||
this.population.setTargetSize(10);
|
||||
}
|
||||
|
||||
public SimulatedAnnealing(SimulatedAnnealing a) {
|
||||
this.m_Population = (Population) a.m_Population.clone();
|
||||
this.m_Problem = (InterfaceOptimizationProblem) a.m_Problem.clone();
|
||||
this.m_InitialTemperature = a.m_InitialTemperature;
|
||||
this.m_CurrentTemperature = a.m_CurrentTemperature;
|
||||
this.m_Alpha = a.m_Alpha;
|
||||
this.population = (Population) a.population.clone();
|
||||
this.optimizationProblem = (InterfaceOptimizationProblem) a.optimizationProblem.clone();
|
||||
this.initialTemperature = a.initialTemperature;
|
||||
this.currentTemperature = a.currentTemperature;
|
||||
this.alpha = a.alpha;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -56,9 +56,9 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
|
||||
*/
|
||||
@Override
|
||||
public void init() {
|
||||
this.m_Problem.initializePopulation(this.m_Population);
|
||||
this.m_Problem.evaluate(this.m_Population);
|
||||
this.m_CurrentTemperature = this.m_InitialTemperature;
|
||||
this.optimizationProblem.initializePopulation(this.population);
|
||||
this.optimizationProblem.evaluate(this.population);
|
||||
this.currentTemperature = this.initialTemperature;
|
||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
|
||||
}
|
||||
|
||||
@ -70,11 +70,11 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
|
||||
*/
|
||||
@Override
|
||||
public void initByPopulation(Population pop, boolean reset) {
|
||||
this.m_Population = (Population) pop.clone();
|
||||
this.m_CurrentTemperature = this.m_InitialTemperature;
|
||||
this.population = (Population) pop.clone();
|
||||
this.currentTemperature = this.initialTemperature;
|
||||
if (reset) {
|
||||
this.m_Population.init();
|
||||
this.m_Problem.evaluate(this.m_Population);
|
||||
this.population.init();
|
||||
this.optimizationProblem.evaluate(this.population);
|
||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
|
||||
}
|
||||
}
|
||||
@ -85,32 +85,32 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
|
||||
@Override
|
||||
public void optimize() {
|
||||
AbstractEAIndividual indy;
|
||||
Population original = (Population) this.m_Population.clone();
|
||||
Population original = (Population) this.population.clone();
|
||||
double delta;
|
||||
|
||||
for (int i = 0; i < this.m_Population.size(); i++) {
|
||||
indy = ((AbstractEAIndividual) this.m_Population.get(i));
|
||||
for (int i = 0; i < this.population.size(); i++) {
|
||||
indy = ((AbstractEAIndividual) this.population.get(i));
|
||||
double tmpD = indy.getMutationProbability();
|
||||
indy.setMutationProbability(1.0);
|
||||
indy.mutate();
|
||||
indy.setMutationProbability(tmpD);
|
||||
}
|
||||
this.m_Problem.evaluate(this.m_Population);
|
||||
for (int i = 0; i < this.m_Population.size(); i++) {
|
||||
if (((AbstractEAIndividual) original.get(i)).isDominatingDebConstraints(((AbstractEAIndividual) this.m_Population.get(i)))) {
|
||||
this.m_Population.remove(i);
|
||||
this.m_Population.add(i, original.get(i));
|
||||
this.optimizationProblem.evaluate(this.population);
|
||||
for (int i = 0; i < this.population.size(); i++) {
|
||||
if (((AbstractEAIndividual) original.get(i)).isDominatingDebConstraints(((AbstractEAIndividual) this.population.get(i)))) {
|
||||
this.population.remove(i);
|
||||
this.population.add(i, original.get(i));
|
||||
} 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);
|
||||
if (Math.exp(-delta / this.m_CurrentTemperature) > RNG.randomInt(0, 1)) {
|
||||
this.m_Population.remove(i);
|
||||
this.m_Population.add(i, original.get(i));
|
||||
if (Math.exp(-delta / this.currentTemperature) > RNG.randomInt(0, 1)) {
|
||||
this.population.remove(i);
|
||||
this.population.add(i, original.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
this.m_CurrentTemperature = this.m_Alpha * this.m_CurrentTemperature;
|
||||
this.m_Population.incrGeneration();
|
||||
this.currentTemperature = this.alpha * this.currentTemperature;
|
||||
this.population.incrGeneration();
|
||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
|
||||
}
|
||||
|
||||
@ -138,36 +138,36 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
|
||||
*/
|
||||
@Override
|
||||
public void setProblem(InterfaceOptimizationProblem problem) {
|
||||
this.m_Problem = problem;
|
||||
this.optimizationProblem = problem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InterfaceOptimizationProblem getProblem() {
|
||||
return this.m_Problem;
|
||||
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(m_Problem);
|
||||
this.fitnessCallsNeeded = 0;
|
||||
this.bestIndividual = new GAIndividualBinaryData();
|
||||
this.bestIndividual.defaultInit(optimizationProblem);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will optimize
|
||||
*/
|
||||
public void defaultOptimize() {
|
||||
for (int i = 0; i < m_FitnessCalls; 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;
|
||||
for (int i = 0; i < fitnessCalls; i++) {
|
||||
this.testIndividual = (GAIndividualBinaryData) ((this.bestIndividual).clone());
|
||||
this.testIndividual.defaultMutate();
|
||||
if (this.testIndividual.defaultEvaulateAsMiniBits() < this.bestIndividual.defaultEvaulateAsMiniBits()) {
|
||||
this.bestIndividual = this.testIndividual;
|
||||
}
|
||||
this.m_FitnessCallsNeeded = i;
|
||||
if (this.m_Best.defaultEvaulateAsMiniBits() == 0) {
|
||||
i = this.m_FitnessCalls + 1;
|
||||
this.fitnessCallsNeeded = i;
|
||||
if (this.bestIndividual.defaultEvaulateAsMiniBits() == 0) {
|
||||
i = this.fitnessCalls + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -180,27 +180,27 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
|
||||
public static void main(String[] args) {
|
||||
SimulatedAnnealing program = new SimulatedAnnealing();
|
||||
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.defaultOptimize();
|
||||
TmpMeanCalls += program.m_FitnessCallsNeeded;
|
||||
TmpMeanFitness += program.m_Best.defaultEvaulateAsMiniBits();
|
||||
TmpMeanCalls += program.fitnessCallsNeeded;
|
||||
TmpMeanFitness += program.bestIndividual.defaultEvaulateAsMiniBits();
|
||||
}
|
||||
TmpMeanCalls /= program.m_MultiRuns;
|
||||
TmpMeanFitness /= program.m_MultiRuns;
|
||||
System.out.println("(" + program.m_MultiRuns + "/" + program.m_FitnessCalls + ") Mean Fitness : " + TmpMeanFitness + " Mean Calls needed: " + TmpMeanCalls);
|
||||
TmpMeanCalls /= program.multiRuns;
|
||||
TmpMeanFitness /= program.multiRuns;
|
||||
System.out.println("(" + program.multiRuns + "/" + program.fitnessCalls + ") Mean Fitness : " + TmpMeanFitness + " Mean Calls needed: " + TmpMeanCalls);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
|
||||
this.m_Listener = ea;
|
||||
this.populationChangedEventListener = ea;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removePopulationChangedEventListener(
|
||||
InterfacePopulationChangedEventListener ea) {
|
||||
if (m_Listener == ea) {
|
||||
m_Listener = null;
|
||||
if (populationChangedEventListener == ea) {
|
||||
populationChangedEventListener = null;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@ -208,8 +208,8 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
|
||||
}
|
||||
|
||||
protected void firePropertyChangedEvent(String name) {
|
||||
if (this.m_Listener != null) {
|
||||
this.m_Listener.registerPopulationStateChanged(this, name);
|
||||
if (this.populationChangedEventListener != null) {
|
||||
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -222,14 +222,14 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
|
||||
@Override
|
||||
public String getStringRepresentation() {
|
||||
String result = "";
|
||||
if (this.m_Population.size() > 1) {
|
||||
result += "Multi(" + this.m_Population.size() + ")-Start Hill Climbing:\n";
|
||||
if (this.population.size() > 1) {
|
||||
result += "Multi(" + this.population.size() + ")-Start Hill Climbing:\n";
|
||||
} else {
|
||||
result += "Simulated Annealing:\n";
|
||||
}
|
||||
result += "Optimization Problem: ";
|
||||
result += this.m_Problem.getStringRepresentationForProblem(this) + "\n";
|
||||
result += this.m_Population.getStringRepresentation();
|
||||
result += this.optimizationProblem.getStringRepresentationForProblem(this) + "\n";
|
||||
result += this.population.getStringRepresentation();
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -240,12 +240,12 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
|
||||
*/
|
||||
@Override
|
||||
public void setIdentifier(String name) {
|
||||
this.m_Identifier = name;
|
||||
this.identifier = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return this.m_Identifier;
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
|
||||
@ -268,12 +268,12 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
|
||||
*/
|
||||
@Override
|
||||
public Population getPopulation() {
|
||||
return this.m_Population;
|
||||
return this.population;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPopulation(Population pop) {
|
||||
this.m_Population = pop;
|
||||
this.population = pop;
|
||||
}
|
||||
|
||||
public String populationTipText() {
|
||||
@ -291,11 +291,11 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
|
||||
* @return The initial temperature.
|
||||
*/
|
||||
public double getInitialTemperature() {
|
||||
return this.m_InitialTemperature;
|
||||
return this.initialTemperature;
|
||||
}
|
||||
|
||||
public void setInitialTemperature(double pop) {
|
||||
this.m_InitialTemperature = pop;
|
||||
this.initialTemperature = pop;
|
||||
}
|
||||
|
||||
public String initialTemperatureTipText() {
|
||||
@ -308,13 +308,13 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
|
||||
* @return The cooling rate.
|
||||
*/
|
||||
public double getAlpha() {
|
||||
return this.m_Alpha;
|
||||
return this.alpha;
|
||||
}
|
||||
|
||||
public void setAlpha(double a) {
|
||||
this.m_Alpha = a;
|
||||
if (this.m_Alpha > 1) {
|
||||
this.m_Alpha = 1.0;
|
||||
this.alpha = a;
|
||||
if (this.alpha > 1) {
|
||||
this.alpha = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,29 +18,29 @@ import eva2.util.annotation.Description;
|
||||
public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializable {
|
||||
// These variables are necessary for the simple testcase
|
||||
|
||||
private InterfaceOptimizationProblem m_Problem = new B1Problem();
|
||||
private int m_MultiRuns = 100;
|
||||
private int m_FitnessCalls = 100;
|
||||
private int m_FitnessCallsNeeded = 0;
|
||||
GAIndividualBinaryData m_Best, m_Test;
|
||||
public double m_InitialT = 2, m_CurrentT;
|
||||
public double m_Alpha = 0.9;
|
||||
private InterfaceOptimizationProblem optimizationProblem = new B1Problem();
|
||||
private int multiRuns = 100;
|
||||
private int fitnessCalls = 100;
|
||||
private int fitnessCallsNeeded = 0;
|
||||
GAIndividualBinaryData bestIndividual, testIndividual;
|
||||
public double initialT = 2, currentT;
|
||||
public double alpha = 0.9;
|
||||
// These variables are necessary for the more complex LectureGUI enviroment
|
||||
transient private String m_Identifier = "";
|
||||
transient private InterfacePopulationChangedEventListener m_Listener;
|
||||
private Population m_Population;
|
||||
transient private String indentifier = "";
|
||||
transient private InterfacePopulationChangedEventListener populationChangedEventListener;
|
||||
private Population population;
|
||||
|
||||
public ThresholdAlgorithm() {
|
||||
this.m_Population = new Population();
|
||||
this.m_Population.setTargetSize(10);
|
||||
this.population = new Population();
|
||||
this.population.setTargetSize(10);
|
||||
}
|
||||
|
||||
public ThresholdAlgorithm(ThresholdAlgorithm a) {
|
||||
this.m_Population = (Population) a.m_Population.clone();
|
||||
this.m_Problem = (InterfaceOptimizationProblem) a.m_Problem.clone();
|
||||
this.m_InitialT = a.m_InitialT;
|
||||
this.m_CurrentT = a.m_CurrentT;
|
||||
this.m_Alpha = a.m_Alpha;
|
||||
this.population = (Population) a.population.clone();
|
||||
this.optimizationProblem = (InterfaceOptimizationProblem) a.optimizationProblem.clone();
|
||||
this.initialT = a.initialT;
|
||||
this.currentT = a.currentT;
|
||||
this.alpha = a.alpha;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -53,9 +53,9 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
|
||||
*/
|
||||
@Override
|
||||
public void init() {
|
||||
this.m_Problem.initializePopulation(this.m_Population);
|
||||
this.m_Problem.evaluate(this.m_Population);
|
||||
this.m_CurrentT = this.m_InitialT;
|
||||
this.optimizationProblem.initializePopulation(this.population);
|
||||
this.optimizationProblem.evaluate(this.population);
|
||||
this.currentT = this.initialT;
|
||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
|
||||
}
|
||||
|
||||
@ -67,11 +67,11 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
|
||||
*/
|
||||
@Override
|
||||
public void initByPopulation(Population pop, boolean reset) {
|
||||
this.m_Population = (Population) pop.clone();
|
||||
this.m_CurrentT = this.m_InitialT;
|
||||
this.population = (Population) pop.clone();
|
||||
this.currentT = this.initialT;
|
||||
if (reset) {
|
||||
this.m_Population.init();
|
||||
this.m_Problem.evaluate(this.m_Population);
|
||||
this.population.init();
|
||||
this.optimizationProblem.evaluate(this.population);
|
||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
|
||||
}
|
||||
}
|
||||
@ -82,26 +82,26 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
|
||||
@Override
|
||||
public void optimize() {
|
||||
AbstractEAIndividual indy;
|
||||
Population original = (Population) this.m_Population.clone();
|
||||
Population original = (Population) this.population.clone();
|
||||
double delta;
|
||||
|
||||
for (int i = 0; i < this.m_Population.size(); i++) {
|
||||
indy = ((AbstractEAIndividual) this.m_Population.get(i));
|
||||
for (int i = 0; i < this.population.size(); i++) {
|
||||
indy = ((AbstractEAIndividual) this.population.get(i));
|
||||
double tmpD = indy.getMutationProbability();
|
||||
indy.setMutationProbability(1.0);
|
||||
indy.mutate();
|
||||
indy.setMutationProbability(tmpD);
|
||||
}
|
||||
this.m_Problem.evaluate(this.m_Population);
|
||||
for (int i = 0; i < this.m_Population.size(); i++) {
|
||||
delta = this.calculateDelta(((AbstractEAIndividual) original.get(i)), ((AbstractEAIndividual) this.m_Population.get(i)));
|
||||
if (delta < this.m_CurrentT) {
|
||||
this.m_Population.remove(i);
|
||||
this.m_Population.add(i, original.get(i));
|
||||
this.optimizationProblem.evaluate(this.population);
|
||||
for (int i = 0; i < this.population.size(); i++) {
|
||||
delta = this.calculateDelta(((AbstractEAIndividual) original.get(i)), ((AbstractEAIndividual) this.population.get(i)));
|
||||
if (delta < this.currentT) {
|
||||
this.population.remove(i);
|
||||
this.population.add(i, original.get(i));
|
||||
}
|
||||
}
|
||||
this.m_CurrentT = this.m_Alpha * this.m_CurrentT;
|
||||
this.m_Population.incrGeneration();
|
||||
this.currentT = this.alpha * this.currentT;
|
||||
this.population.incrGeneration();
|
||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
|
||||
}
|
||||
|
||||
@ -129,36 +129,36 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
|
||||
*/
|
||||
@Override
|
||||
public void setProblem(InterfaceOptimizationProblem problem) {
|
||||
this.m_Problem = problem;
|
||||
this.optimizationProblem = problem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InterfaceOptimizationProblem getProblem() {
|
||||
return this.m_Problem;
|
||||
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(m_Problem);
|
||||
this.fitnessCallsNeeded = 0;
|
||||
this.bestIndividual = new GAIndividualBinaryData();
|
||||
this.bestIndividual.defaultInit(optimizationProblem);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will optimize
|
||||
*/
|
||||
public void defaultOptimize() {
|
||||
for (int i = 0; i < m_FitnessCalls; 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;
|
||||
for (int i = 0; i < fitnessCalls; i++) {
|
||||
this.testIndividual = (GAIndividualBinaryData) ((this.bestIndividual).clone());
|
||||
this.testIndividual.defaultMutate();
|
||||
if (this.testIndividual.defaultEvaulateAsMiniBits() < this.bestIndividual.defaultEvaulateAsMiniBits()) {
|
||||
this.bestIndividual = this.testIndividual;
|
||||
}
|
||||
this.m_FitnessCallsNeeded = i;
|
||||
if (this.m_Best.defaultEvaulateAsMiniBits() == 0) {
|
||||
i = this.m_FitnessCalls + 1;
|
||||
this.fitnessCallsNeeded = i;
|
||||
if (this.bestIndividual.defaultEvaulateAsMiniBits() == 0) {
|
||||
i = this.fitnessCalls + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -171,27 +171,27 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
|
||||
public static void main(String[] args) {
|
||||
ThresholdAlgorithm program = new ThresholdAlgorithm();
|
||||
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.defaultOptimize();
|
||||
TmpMeanCalls += program.m_FitnessCallsNeeded;
|
||||
TmpMeanFitness += program.m_Best.defaultEvaulateAsMiniBits();
|
||||
TmpMeanCalls += program.fitnessCallsNeeded;
|
||||
TmpMeanFitness += program.bestIndividual.defaultEvaulateAsMiniBits();
|
||||
}
|
||||
TmpMeanCalls /= program.m_MultiRuns;
|
||||
TmpMeanFitness /= program.m_MultiRuns;
|
||||
System.out.println("(" + program.m_MultiRuns + "/" + program.m_FitnessCalls + ") Mean Fitness : " + TmpMeanFitness + " Mean Calls needed: " + TmpMeanCalls);
|
||||
TmpMeanCalls /= program.multiRuns;
|
||||
TmpMeanFitness /= program.multiRuns;
|
||||
System.out.println("(" + program.multiRuns + "/" + program.fitnessCalls + ") Mean Fitness : " + TmpMeanFitness + " Mean Calls needed: " + TmpMeanCalls);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
|
||||
this.m_Listener = ea;
|
||||
this.populationChangedEventListener = ea;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removePopulationChangedEventListener(
|
||||
InterfacePopulationChangedEventListener ea) {
|
||||
if (m_Listener == ea) {
|
||||
m_Listener = null;
|
||||
if (populationChangedEventListener == ea) {
|
||||
populationChangedEventListener = null;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@ -199,8 +199,8 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
|
||||
}
|
||||
|
||||
protected void firePropertyChangedEvent(String name) {
|
||||
if (this.m_Listener != null) {
|
||||
this.m_Listener.registerPopulationStateChanged(this, name);
|
||||
if (this.populationChangedEventListener != null) {
|
||||
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -213,14 +213,14 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
|
||||
@Override
|
||||
public String getStringRepresentation() {
|
||||
String result = "";
|
||||
if (this.m_Population.size() > 1) {
|
||||
result += "Multi(" + this.m_Population.size() + ")-Start Hill Climbing:\n";
|
||||
if (this.population.size() > 1) {
|
||||
result += "Multi(" + this.population.size() + ")-Start Hill Climbing:\n";
|
||||
} else {
|
||||
result += "Threshold Algorithm:\n";
|
||||
}
|
||||
result += "Optimization Problem: ";
|
||||
result += this.m_Problem.getStringRepresentationForProblem(this) + "\n";
|
||||
result += this.m_Population.getStringRepresentation();
|
||||
result += this.optimizationProblem.getStringRepresentationForProblem(this) + "\n";
|
||||
result += this.population.getStringRepresentation();
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -231,12 +231,12 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
|
||||
*/
|
||||
@Override
|
||||
public void setIdentifier(String name) {
|
||||
this.m_Identifier = name;
|
||||
this.indentifier = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return this.m_Identifier;
|
||||
return this.indentifier;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -258,12 +258,12 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
|
||||
*/
|
||||
@Override
|
||||
public Population getPopulation() {
|
||||
return this.m_Population;
|
||||
return this.population;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPopulation(Population pop) {
|
||||
this.m_Population = pop;
|
||||
this.population = pop;
|
||||
}
|
||||
|
||||
public String populationTipText() {
|
||||
@ -281,11 +281,11 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
|
||||
* @return The initial temperature.
|
||||
*/
|
||||
public double getInitialT() {
|
||||
return this.m_InitialT;
|
||||
return this.initialT;
|
||||
}
|
||||
|
||||
public void setInitialT(double pop) {
|
||||
this.m_InitialT = pop;
|
||||
this.initialT = pop;
|
||||
}
|
||||
|
||||
public String initialTTipText() {
|
||||
@ -298,13 +298,13 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
|
||||
* @return The initial temperature.
|
||||
*/
|
||||
public double getAlpha() {
|
||||
return this.m_Alpha;
|
||||
return this.alpha;
|
||||
}
|
||||
|
||||
public void setAlpha(double a) {
|
||||
this.m_Alpha = a;
|
||||
if (this.m_Alpha > 1) {
|
||||
this.m_Alpha = 1.0;
|
||||
this.alpha = a;
|
||||
if (this.alpha > 1) {
|
||||
this.alpha = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,9 +135,9 @@ import java.util.List;
|
||||
public class Tribes implements InterfaceOptimizer, java.io.Serializable {
|
||||
|
||||
public static final boolean TRACE = false;
|
||||
protected String m_Identifier = "TRIBES";
|
||||
transient private InterfacePopulationChangedEventListener m_Listener = null;
|
||||
protected AbstractOptimizationProblem m_problem;
|
||||
protected String identifier = "TRIBES";
|
||||
transient private InterfacePopulationChangedEventListener listener = null;
|
||||
protected AbstractOptimizationProblem optimizationProblem;
|
||||
protected Population population;
|
||||
public static int maxExplorerNb = 200;
|
||||
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
|
||||
// use full range (0) or subspace (1) for init options 0 and 1
|
||||
protected int rangeInitType = 1;
|
||||
private boolean m_Show = false;
|
||||
transient protected Plot m_Plot = null;
|
||||
private boolean show = false;
|
||||
transient protected Plot plot = null;
|
||||
// private int useAnchors = 0; // use anchors to detect environment changes?
|
||||
|
||||
@Override
|
||||
@ -200,7 +200,7 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
|
||||
@Override
|
||||
public void setProblem(InterfaceOptimizationProblem problem) {
|
||||
// System.out.println("TRIBES.SetProblem()");
|
||||
m_problem = (AbstractOptimizationProblem) problem;
|
||||
optimizationProblem = (AbstractOptimizationProblem) problem;
|
||||
range = null;
|
||||
if (problem instanceof InterfaceHasInitRange) {
|
||||
initRange = (double[][]) ((InterfaceHasInitRange) problem).getInitRange();
|
||||
@ -215,7 +215,7 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
|
||||
// System.out.println("TRIBES.init()");
|
||||
// Generate a swarm
|
||||
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);
|
||||
// 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.init(); // necessary to allow for multi-runs
|
||||
|
||||
if (m_Show) {
|
||||
if (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
|
||||
//* 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++;
|
||||
|
||||
m_problem.evaluatePopulationStart(population);
|
||||
optimizationProblem.evaluatePopulationStart(population);
|
||||
swarm.setSwarmSize();
|
||||
// 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,
|
||||
// int informOption, AbstractOptimizationProblem prob) {
|
||||
|
||||
@ -297,7 +297,7 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
|
||||
adapt = iter; // Memorize at which iteration adaptation occurs
|
||||
|
||||
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) {
|
||||
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.addAll(swarm.toPopulation());
|
||||
if (m_Show) {
|
||||
if (show) {
|
||||
plotAll(population);
|
||||
}
|
||||
m_problem.evaluatePopulationEnd(population);
|
||||
optimizationProblem.evaluatePopulationEnd(population);
|
||||
|
||||
// this.population.incrFunctionCallsby(evals);
|
||||
this.population.incrGeneration();
|
||||
@ -348,12 +348,12 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
|
||||
|
||||
// TODO
|
||||
private void plotIndy(double[] curPosition, double[] curVelocity, int index) {
|
||||
if (this.m_Show) {
|
||||
if (this.show) {
|
||||
if (curVelocity == null) {
|
||||
this.m_Plot.setUnconnectedPoint(curPosition[0], curPosition[1], index);
|
||||
this.plot.setUnconnectedPoint(curPosition[0], curPosition[1], index);
|
||||
} else {
|
||||
this.m_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], curPosition[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.
|
||||
*/
|
||||
protected void show() {
|
||||
if (this.m_Plot == null) {
|
||||
if (this.plot == null) {
|
||||
// InterfaceDataTypeDouble indy = (InterfaceDataTypeDouble)this.population.get(0);
|
||||
// double[][] range = indy.getDoubleRange();
|
||||
// double[] tmpD = new double[2];
|
||||
// tmpD[0] = 0;
|
||||
// tmpD[1] = 0;
|
||||
this.m_Plot = new Plot("TRIBES " + population.getGeneration(), "x1", "x2", range[0], range[1]);
|
||||
// this.m_Plot.setCornerPoints(range, 0);
|
||||
this.plot = new Plot("TRIBES " + population.getGeneration(), "x1", "x2", range[0], range[1]);
|
||||
// this.plot.setCornerPoints(range, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -623,14 +623,14 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
|
||||
*/
|
||||
@Override
|
||||
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
|
||||
this.m_Listener = ea;
|
||||
this.listener = ea;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removePopulationChangedEventListener(
|
||||
InterfacePopulationChangedEventListener ea) {
|
||||
if (m_Listener == ea) {
|
||||
m_Listener = null;
|
||||
if (listener == ea) {
|
||||
listener = null;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@ -638,8 +638,8 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
|
||||
}
|
||||
|
||||
protected void firePropertyChangedEvent(String name) {
|
||||
if (this.m_Listener != null) {
|
||||
this.m_Listener.registerPopulationStateChanged(this, name);
|
||||
if (this.listener != null) {
|
||||
this.listener.registerPopulationStateChanged(this, name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -649,12 +649,12 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
|
||||
|
||||
@Override
|
||||
public void setIdentifier(String name) {
|
||||
this.m_Identifier = name;
|
||||
this.identifier = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return m_Identifier;
|
||||
return identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -664,7 +664,7 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
|
||||
|
||||
@Override
|
||||
public InterfaceOptimizationProblem getProblem() {
|
||||
return m_problem;
|
||||
return optimizationProblem;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -730,19 +730,19 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
|
||||
// }
|
||||
|
||||
/**
|
||||
* @return the m_Show
|
||||
* @return the show
|
||||
*/
|
||||
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) {
|
||||
m_Show = show;
|
||||
this.show = show;
|
||||
if (!show) {
|
||||
m_Plot = null;
|
||||
plot = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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.")
|
||||
public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Serializable {
|
||||
|
||||
private InterfaceOptimizer m_MOOptimizer = new MultiObjectiveEA();
|
||||
private InterfaceOptimizer m_SOOptimizer = new GeneticAlgorithm();
|
||||
private InterfaceOptimizer[] m_SOOptimizers;
|
||||
private Population m_Population = new Population();
|
||||
private int m_MigrationRate = 5;
|
||||
private int m_OutputDimension = 2;
|
||||
private InterfaceOptimizationProblem m_Problem = new FM0Problem();
|
||||
private String m_Identifier = "";
|
||||
transient private InterfacePopulationChangedEventListener m_Listener;
|
||||
private InterfaceOptimizer multiObjectiveEA = new MultiObjectiveEA();
|
||||
private InterfaceOptimizer singleObjectiveEA = new GeneticAlgorithm();
|
||||
private InterfaceOptimizer[] singleObjectiveOptimizers;
|
||||
private Population population = new Population();
|
||||
private int migrationRate = 5;
|
||||
private int outputDimension = 2;
|
||||
private InterfaceOptimizationProblem optimizationProblem = new FM0Problem();
|
||||
private String identifier = "";
|
||||
transient private InterfacePopulationChangedEventListener populationChangedEventListener;
|
||||
|
||||
public WingedMultiObjectiveEA() {
|
||||
}
|
||||
|
||||
public WingedMultiObjectiveEA(WingedMultiObjectiveEA a) {
|
||||
this.m_Problem = (InterfaceOptimizationProblem) a.m_Problem.clone();
|
||||
this.m_MOOptimizer = (InterfaceOptimizer) a.m_MOOptimizer.clone();
|
||||
this.m_SOOptimizer = (InterfaceOptimizer) a.m_SOOptimizer.clone();
|
||||
if (a.m_SOOptimizers != null) {
|
||||
this.m_SOOptimizers = new InterfaceOptimizer[a.m_SOOptimizers.length];
|
||||
for (int i = 0; i < this.m_SOOptimizers.length; i++) {
|
||||
this.m_SOOptimizers[i] = (InterfaceOptimizer) a.m_SOOptimizers[i].clone();
|
||||
this.optimizationProblem = (InterfaceOptimizationProblem) a.optimizationProblem.clone();
|
||||
this.multiObjectiveEA = (InterfaceOptimizer) a.multiObjectiveEA.clone();
|
||||
this.singleObjectiveEA = (InterfaceOptimizer) a.singleObjectiveEA.clone();
|
||||
if (a.singleObjectiveOptimizers != null) {
|
||||
this.singleObjectiveOptimizers = new InterfaceOptimizer[a.singleObjectiveOptimizers.length];
|
||||
for (int i = 0; i < this.singleObjectiveOptimizers.length; i++) {
|
||||
this.singleObjectiveOptimizers[i] = (InterfaceOptimizer) a.singleObjectiveOptimizers[i].clone();
|
||||
}
|
||||
}
|
||||
this.m_MigrationRate = a.m_MigrationRate;
|
||||
this.m_Population = (Population) a.m_Population.clone();
|
||||
this.migrationRate = a.migrationRate;
|
||||
this.population = (Population) a.population.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -56,19 +56,19 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
if (this.m_Problem instanceof AbstractMultiObjectiveOptimizationProblem) {
|
||||
AbstractMultiObjectiveOptimizationProblem tmpProb = (AbstractMultiObjectiveOptimizationProblem) this.m_Problem;
|
||||
if (this.optimizationProblem instanceof AbstractMultiObjectiveOptimizationProblem) {
|
||||
AbstractMultiObjectiveOptimizationProblem tmpProb = (AbstractMultiObjectiveOptimizationProblem) this.optimizationProblem;
|
||||
AbstractMultiObjectiveOptimizationProblem tmpP;
|
||||
MOSOWeightedFitness tmpWF;
|
||||
PropertyDoubleArray tmpDA;
|
||||
int dim = this.m_OutputDimension;
|
||||
int dim = this.outputDimension;
|
||||
double[] weights;
|
||||
// dim = tmpProb.getOutputDimension();
|
||||
this.m_MOOptimizer.setProblem((InterfaceOptimizationProblem) this.m_Problem.clone());
|
||||
this.m_MOOptimizer.init();
|
||||
this.m_SOOptimizers = new InterfaceOptimizer[dim];
|
||||
this.multiObjectiveEA.setProblem((InterfaceOptimizationProblem) this.optimizationProblem.clone());
|
||||
this.multiObjectiveEA.init();
|
||||
this.singleObjectiveOptimizers = new InterfaceOptimizer[dim];
|
||||
for (int i = 0; i < dim; i++) {
|
||||
tmpP = (AbstractMultiObjectiveOptimizationProblem) this.m_Problem.clone();
|
||||
tmpP = (AbstractMultiObjectiveOptimizationProblem) this.optimizationProblem.clone();
|
||||
weights = new double[dim];
|
||||
for (int j = 0; j < dim; j++) {
|
||||
weights[j] = 0;
|
||||
@ -78,13 +78,13 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
|
||||
tmpWF = new MOSOWeightedFitness();
|
||||
tmpWF.setWeights(tmpDA);
|
||||
tmpP.setMOSOConverter(tmpWF);
|
||||
this.m_SOOptimizers[i] = (InterfaceOptimizer) this.m_SOOptimizer.clone();
|
||||
this.m_SOOptimizers[i].setProblem(tmpP);
|
||||
this.m_SOOptimizers[i].init();
|
||||
this.singleObjectiveOptimizers[i] = (InterfaceOptimizer) this.singleObjectiveEA.clone();
|
||||
this.singleObjectiveOptimizers[i].setProblem(tmpP);
|
||||
this.singleObjectiveOptimizers[i].init();
|
||||
}
|
||||
} else {
|
||||
this.m_SOOptimizer.setProblem(this.m_Problem);
|
||||
this.m_SOOptimizer.init();
|
||||
this.singleObjectiveEA.setProblem(this.optimizationProblem);
|
||||
this.singleObjectiveEA.init();
|
||||
}
|
||||
this.communicate();
|
||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
|
||||
@ -98,19 +98,19 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
|
||||
*/
|
||||
@Override
|
||||
public void initByPopulation(Population pop, boolean reset) {
|
||||
if (this.m_Problem instanceof AbstractMultiObjectiveOptimizationProblem) {
|
||||
AbstractMultiObjectiveOptimizationProblem tmpProb = (AbstractMultiObjectiveOptimizationProblem) this.m_Problem;
|
||||
if (this.optimizationProblem instanceof AbstractMultiObjectiveOptimizationProblem) {
|
||||
AbstractMultiObjectiveOptimizationProblem tmpProb = (AbstractMultiObjectiveOptimizationProblem) this.optimizationProblem;
|
||||
AbstractMultiObjectiveOptimizationProblem tmpP;
|
||||
MOSOWeightedFitness tmpWF;
|
||||
PropertyDoubleArray tmpDA;
|
||||
int dim = 2;
|
||||
double[] weights;
|
||||
// dim = tmpProb.getOutputDimension();
|
||||
this.m_MOOptimizer.setProblem((InterfaceOptimizationProblem) this.m_Problem.clone());
|
||||
this.m_MOOptimizer.initByPopulation(pop, reset);
|
||||
this.m_SOOptimizers = new InterfaceOptimizer[dim];
|
||||
this.multiObjectiveEA.setProblem((InterfaceOptimizationProblem) this.optimizationProblem.clone());
|
||||
this.multiObjectiveEA.initByPopulation(pop, reset);
|
||||
this.singleObjectiveOptimizers = new InterfaceOptimizer[dim];
|
||||
for (int i = 0; i < dim; i++) {
|
||||
tmpP = (AbstractMultiObjectiveOptimizationProblem) this.m_Problem.clone();
|
||||
tmpP = (AbstractMultiObjectiveOptimizationProblem) this.optimizationProblem.clone();
|
||||
weights = new double[dim];
|
||||
for (int j = 0; j < dim; j++) {
|
||||
weights[j] = 0;
|
||||
@ -120,13 +120,13 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
|
||||
tmpWF = new MOSOWeightedFitness();
|
||||
tmpWF.setWeights(tmpDA);
|
||||
tmpP.setMOSOConverter(tmpWF);
|
||||
this.m_SOOptimizers[i] = (InterfaceOptimizer) this.m_SOOptimizer.clone();
|
||||
this.m_SOOptimizers[i].setProblem(tmpP);
|
||||
this.m_SOOptimizers[i].initByPopulation(pop, reset);
|
||||
this.singleObjectiveOptimizers[i] = (InterfaceOptimizer) this.singleObjectiveEA.clone();
|
||||
this.singleObjectiveOptimizers[i].setProblem(tmpP);
|
||||
this.singleObjectiveOptimizers[i].initByPopulation(pop, reset);
|
||||
}
|
||||
} else {
|
||||
this.m_SOOptimizer.setProblem(this.m_Problem);
|
||||
this.m_SOOptimizer.initByPopulation(pop, reset);
|
||||
this.singleObjectiveEA.setProblem(this.optimizationProblem);
|
||||
this.singleObjectiveEA.initByPopulation(pop, reset);
|
||||
}
|
||||
this.communicate();
|
||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
|
||||
@ -138,12 +138,12 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
|
||||
@Override
|
||||
public void optimize() {
|
||||
|
||||
this.m_MOOptimizer.optimize();
|
||||
for (int i = 0; i < this.m_SOOptimizers.length; i++) {
|
||||
this.m_SOOptimizers[i].optimize();
|
||||
this.multiObjectiveEA.optimize();
|
||||
for (int i = 0; i < this.singleObjectiveOptimizers.length; i++) {
|
||||
this.singleObjectiveOptimizers[i].optimize();
|
||||
}
|
||||
this.m_Population.incrGeneration();
|
||||
if ((this.m_Population.getGeneration() % this.m_MigrationRate) == 0) {
|
||||
this.population.incrGeneration();
|
||||
if ((this.population.getGeneration() % this.migrationRate) == 0) {
|
||||
this.communicate();
|
||||
}
|
||||
|
||||
@ -157,21 +157,21 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
|
||||
*/
|
||||
private void communicate() {
|
||||
int oldFunctionCalls;
|
||||
this.m_Population.clear();
|
||||
this.m_Population.setFunctionCalls(0);
|
||||
this.population.clear();
|
||||
this.population.setFunctionCalls(0);
|
||||
Population pop;
|
||||
// first collect all the data
|
||||
pop = (Population) this.m_MOOptimizer.getPopulation().clone();
|
||||
this.m_Population.addPopulation(pop);
|
||||
this.m_Population.incrFunctionCallsBy(pop.getFunctionCalls());
|
||||
for (int i = 0; i < this.m_SOOptimizers.length; i++) {
|
||||
pop = (Population) this.m_SOOptimizers[i].getPopulation().clone();
|
||||
this.m_Population.addPopulation(pop);
|
||||
this.m_Population.incrFunctionCallsBy(pop.getFunctionCalls());
|
||||
pop = (Population) this.multiObjectiveEA.getPopulation().clone();
|
||||
this.population.addPopulation(pop);
|
||||
this.population.incrFunctionCallsBy(pop.getFunctionCalls());
|
||||
for (int i = 0; i < this.singleObjectiveOptimizers.length; i++) {
|
||||
pop = (Population) this.singleObjectiveOptimizers[i].getPopulation().clone();
|
||||
this.population.addPopulation(pop);
|
||||
this.population.incrFunctionCallsBy(pop.getFunctionCalls());
|
||||
}
|
||||
oldFunctionCalls = this.m_Population.getFunctionCalls();
|
||||
this.m_Problem.evaluate(this.m_Population);
|
||||
this.m_Population.setFunctionCalls(oldFunctionCalls);
|
||||
oldFunctionCalls = this.population.getFunctionCalls();
|
||||
this.optimizationProblem.evaluate(this.population);
|
||||
this.population.setFunctionCalls(oldFunctionCalls);
|
||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
|
||||
// double plotValue = (this.problem.getDoublePlotValue(this.population)).doubleValue();
|
||||
// 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
|
||||
*/
|
||||
private void migrate() {
|
||||
AbstractEAIndividual[] bestIndys = new AbstractEAIndividual[this.m_OutputDimension];
|
||||
AbstractEAIndividual[] bestIndys = new AbstractEAIndividual[this.outputDimension];
|
||||
double tmpF1, tmpF2;
|
||||
// for each dimension find the best
|
||||
for (int i = 0; i < this.m_OutputDimension; i++) {
|
||||
bestIndys[i] = (AbstractEAIndividual) ((AbstractEAIndividual) this.m_Population.get(0)).clone();
|
||||
for (int i = 0; i < this.outputDimension; i++) {
|
||||
bestIndys[i] = (AbstractEAIndividual) ((AbstractEAIndividual) this.population.get(0)).clone();
|
||||
tmpF1 = bestIndys[i].getFitness(i);
|
||||
// for each individual find the best
|
||||
for (int j = 0; j < this.m_Population.size(); j++) {
|
||||
if (((AbstractEAIndividual) this.m_Population.get(j)).getFitness(i) < tmpF1) {
|
||||
bestIndys[i] = (AbstractEAIndividual) ((AbstractEAIndividual) this.m_Population.get(j)).clone();
|
||||
for (int j = 0; j < this.population.size(); j++) {
|
||||
if (((AbstractEAIndividual) this.population.get(j)).getFitness(i) < tmpF1) {
|
||||
bestIndys[i] = (AbstractEAIndividual) ((AbstractEAIndividual) this.population.get(j)).clone();
|
||||
tmpF1 = bestIndys[i].getFitness(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
// now perform the migration
|
||||
AbstractEAIndividual tmpIndy;
|
||||
for (int i = 0; i < this.m_OutputDimension; i++) {
|
||||
for (int i = 0; i < this.outputDimension; i++) {
|
||||
tmpIndy = (AbstractEAIndividual) bestIndys[i].clone();
|
||||
this.m_MOOptimizer.getProblem().evaluate(tmpIndy);
|
||||
this.m_MOOptimizer.getPopulation().set(i, tmpIndy);
|
||||
this.multiObjectiveEA.getProblem().evaluate(tmpIndy);
|
||||
this.multiObjectiveEA.getPopulation().set(i, tmpIndy);
|
||||
tmpIndy = (AbstractEAIndividual) bestIndys[i].clone();
|
||||
this.m_SOOptimizers[i].getProblem().evaluate(tmpIndy);
|
||||
this.m_SOOptimizers[i].getPopulation().set(0, bestIndys[i]);
|
||||
this.singleObjectiveOptimizers[i].getProblem().evaluate(tmpIndy);
|
||||
this.singleObjectiveOptimizers[i].getPopulation().set(0, bestIndys[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -215,14 +215,14 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
|
||||
*/
|
||||
@Override
|
||||
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
|
||||
this.m_Listener = ea;
|
||||
this.populationChangedEventListener = ea;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removePopulationChangedEventListener(
|
||||
InterfacePopulationChangedEventListener ea) {
|
||||
if (m_Listener == ea) {
|
||||
m_Listener = null;
|
||||
if (populationChangedEventListener == ea) {
|
||||
populationChangedEventListener = null;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@ -233,8 +233,8 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
|
||||
* Something has changed
|
||||
*/
|
||||
protected void firePropertyChangedEvent(String name) {
|
||||
if (this.m_Listener != null) {
|
||||
this.m_Listener.registerPopulationStateChanged(this, name);
|
||||
if (this.populationChangedEventListener != null) {
|
||||
this.populationChangedEventListener.registerPopulationStateChanged(this, name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -245,12 +245,12 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
|
||||
*/
|
||||
@Override
|
||||
public void setProblem(InterfaceOptimizationProblem problem) {
|
||||
this.m_Problem = problem;
|
||||
this.optimizationProblem = problem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InterfaceOptimizationProblem getProblem() {
|
||||
return this.m_Problem;
|
||||
return this.optimizationProblem;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -264,8 +264,8 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
|
||||
String result = "";
|
||||
result += "EMO:\n";
|
||||
result += "Optimization Problem: ";
|
||||
result += this.m_Problem.getStringRepresentationForProblem(this) + "\n";
|
||||
result += this.m_Population.getStringRepresentation();
|
||||
result += this.optimizationProblem.getStringRepresentationForProblem(this) + "\n";
|
||||
result += this.population.getStringRepresentation();
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -276,12 +276,12 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
|
||||
*/
|
||||
@Override
|
||||
public void setIdentifier(String name) {
|
||||
this.m_Identifier = name;
|
||||
this.identifier = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return this.m_Identifier;
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -303,12 +303,12 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
|
||||
*/
|
||||
@Override
|
||||
public Population getPopulation() {
|
||||
return this.m_Population;
|
||||
return this.population;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPopulation(Population pop) {
|
||||
this.m_Population = pop;
|
||||
this.population = pop;
|
||||
}
|
||||
|
||||
public String populationTipText() {
|
||||
@ -326,11 +326,11 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
|
||||
* @return The current optimizing method
|
||||
*/
|
||||
public InterfaceOptimizer getMOOptimizer() {
|
||||
return this.m_MOOptimizer;
|
||||
return this.multiObjectiveEA;
|
||||
}
|
||||
|
||||
public void setMOOptimizer(InterfaceOptimizer b) {
|
||||
this.m_MOOptimizer = b;
|
||||
this.multiObjectiveEA = b;
|
||||
}
|
||||
|
||||
public String mOOptimizerTipText() {
|
||||
@ -343,11 +343,11 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
|
||||
* @return The current optimizing method
|
||||
*/
|
||||
public InterfaceOptimizer getSOOptimizer() {
|
||||
return this.m_SOOptimizer;
|
||||
return this.singleObjectiveEA;
|
||||
}
|
||||
|
||||
public void setSOOptimizer(InterfaceOptimizer b) {
|
||||
this.m_SOOptimizer = b;
|
||||
this.singleObjectiveEA = b;
|
||||
}
|
||||
|
||||
public String sOOptimizerTipText() {
|
||||
@ -360,11 +360,11 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
|
||||
* @return The current optimizing method
|
||||
*/
|
||||
public int getMigrationRate() {
|
||||
return this.m_MigrationRate;
|
||||
return this.migrationRate;
|
||||
}
|
||||
|
||||
public void setMigrationRate(int b) {
|
||||
this.m_MigrationRate = b;
|
||||
this.migrationRate = b;
|
||||
}
|
||||
|
||||
public String migrationRateTipText() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user