Merging mk branch rev 199, new Population event for initialization (introducing final Strings for the event names), renaming Indy.SetData to putData, replacing static rank-mu-CMA parameters by a population-associated structure; oh and the "Description" button has made room for a "Show Solution" button.

This commit is contained in:
Marcel Kronfeld 2008-09-12 09:57:36 +00:00
parent 137ef279ac
commit bcdc7d254e
52 changed files with 690 additions and 455 deletions

View File

@ -21,9 +21,16 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import eva2.server.go.InterfaceGOParameters;
import eva2.server.go.individuals.AbstractEAIndividual;
import eva2.server.go.problems.AbstractOptimizationProblem;
import eva2.server.go.problems.InterfaceOptimizationProblem;
import eva2.server.go.strategies.InterfaceOptimizer;
import eva2.server.modules.AbstractModuleAdapter;
import eva2.server.modules.ModuleAdapter;
import wsi.ra.jproxy.RMIProxyLocal;
@ -44,6 +51,7 @@ public class JModuleGeneralPanel implements RemoteStateListener, Serializable {
private JButton m_actStop;
// private JButton m_actExitMod;
private JButton m_JHelpButton;
private JButton m_ShowSolButton;
private JPanel m_Panel;
private String m_HelperFileName;
@ -90,10 +98,10 @@ public class JModuleGeneralPanel implements RemoteStateListener, Serializable {
m_RunButton.setEnabled(false);
m_PPButton.setEnabled(false);
// m_RestartButton.setEnabled(false);
m_JHelpButton.setEnabled(true);
// m_JHelpButton.setEnabled(true);
} catch (Exception ee) {
ee.printStackTrace();
System.out.print ("Error in run: " +ee +" : " + ee.getMessage() );
System.err.print ("Error in run: " +ee +" : " + ee.getMessage() );
}
}
}
@ -111,7 +119,7 @@ public class JModuleGeneralPanel implements RemoteStateListener, Serializable {
public void actionPerformed(ActionEvent e){
try {
m_Adapter.stopOpt(); // this means user break
} catch (Exception ee) { System.out.print ("Error in stop: " + ee.getMessage() ); }
} catch (Exception ee) { System.err.print ("Error in stop: " + ee.getMessage() ); }
}
}
);
@ -132,7 +140,7 @@ public class JModuleGeneralPanel implements RemoteStateListener, Serializable {
// m_RunButton.setEnabled(false);
} catch (Exception ee) {
ee.printStackTrace();
System.out.println("Error in run: " +ee +" : " + ee.getMessage() );
System.err.println("Error in run: " +ee +" : " + ee.getMessage() );
}
}
}
@ -140,8 +148,43 @@ public class JModuleGeneralPanel implements RemoteStateListener, Serializable {
m_PPButton.setEnabled(m_StateRunning && m_Adapter.hasPostProcessing());
m_Panel.add(m_PPButton);
makeHelpButton();
if (m_Adapter instanceof AbstractModuleAdapter && (m_Adapter != null)) {
/** This action listener, called by the "show" button will show the
* currently best solution in a frame.
*/
m_ShowSolButton = new JButton("Show Solution");
m_ShowSolButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
InterfaceGOParameters goParams = ((AbstractModuleAdapter)m_Adapter).getGOParameters();
InterfaceOptimizationProblem goProblem = goParams.getProblem();
InterfaceOptimizer opt = goParams.getOptimizer();
AbstractEAIndividual indy = opt.getPopulation().getBestEAIndividual();
if (indy != null) {
JFrame frame = new JFrame();
frame.setTitle("The current best solution for "+goProblem.getName());
frame.setSize(400, 300);
frame.setLocation(450, 250);
frame.getContentPane().add(goProblem.drawIndividual(indy));
frame.validate();
frame.setVisible(true);
} else System.out.println("No current solution available.");
}
}
);
m_ShowSolButton.setEnabled(false);
m_Panel.add(m_ShowSolButton);
}
// m_actExitMod = new JButton("Exit Module");
// m_actExitMod.setToolTipText("todo !!.");// TODO
return m_Panel;
}
private void makeHelpButton() {
///////////////////////////////////////////////////////////////
if (m_HelperFileName.equals("")== false) {
if (m_HelperFileName!=null && (!m_HelperFileName.equals(""))) {
m_JHelpButton= new JButton("Description");
m_JHelpButton.setToolTipText("Description of the current optimization algorithm.");
m_JHelpButton.addActionListener(new ActionListener() {
@ -162,11 +205,8 @@ public class JModuleGeneralPanel implements RemoteStateListener, Serializable {
);
m_Panel.add(m_JHelpButton);
}
// m_actExitMod = new JButton("Exit Module");
// m_actExitMod.setToolTipText("todo !!.");// TODO
return m_Panel;
}
/**
*
*/
@ -180,6 +220,7 @@ public class JModuleGeneralPanel implements RemoteStateListener, Serializable {
}
public void performedStart(String infoString) {
m_ShowSolButton.setEnabled(true);
}
@ -199,7 +240,22 @@ public class JModuleGeneralPanel implements RemoteStateListener, Serializable {
*
*/
public void setHelperFilename (String s) {
m_HelperFileName = s;
if ((s==null) && (s==m_HelperFileName)) return; // both are null, do nothing
if (s!=null) {
if (m_HelperFileName != null) {
if (!m_HelperFileName.equals(s)) {
m_Panel.remove(m_JHelpButton);
m_HelperFileName = s;
makeHelpButton();
} //else // both are equal, do nothing
} else { // only old is null, nothing to be removed
m_HelperFileName = s;
makeHelpButton();
}
} else { // s is null, so just remove
m_Panel.remove(m_JHelpButton);
m_HelperFileName=s;
}
}
}

View File

@ -555,41 +555,43 @@ public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopu
* @param name Could be used to indicate the nature of the event.
*/
public void registerPopulationStateChanged(Object source, String name) {
Population population = ((InterfaceOptimizer)source).getPopulation();
double x = 100/this.m_MultiRuns;
if (this.m_GO.getTerminator() instanceof EvaluationTerminator) {
double y = x/(double)((EvaluationTerminator)this.m_GO.getTerminator()).getFitnessCalls();
currentProgress = (int)(this.currentRun * x + population.getFunctionCalls()*y);
} else {
currentProgress = (int)(this.currentRun * x);
}
updateStatus(currentProgress);
if (name.equals(Population.nextGenerationPerformed)) {
Population population = ((InterfaceOptimizer)source).getPopulation();
double x = 100/this.m_MultiRuns;
if (this.m_GO.getTerminator() instanceof EvaluationTerminator) {
double y = x/(double)((EvaluationTerminator)this.m_GO.getTerminator()).getFitnessCalls();
currentProgress = (int)(this.currentRun * x + population.getFunctionCalls()*y);
} else {
currentProgress = (int)(this.currentRun * x);
}
updateStatus(currentProgress);
// data to be stored in file
double tmpd = 0;
StringBuffer tmpLine = new StringBuffer("");
tmpLine.append(population.getFunctionCalls());
tmpLine.append("\t");
tmpLine.append(population.getBestEAIndividual().getFitness(0));
tmpLine.append("\t");
for (int i = 0; i < population.size(); i++) tmpd += ((AbstractEAIndividual)population.get(i)).getFitness(0)/(double)population.size();
tmpLine.append("\t");
tmpLine.append(tmpd);
tmpLine.append("\t");
tmpLine.append(population.getWorstEAIndividual().getFitness(0));
//tmpLine.append("\t");
//tmpLine.append(this.m_GO.getProblem().getAdditionalFileStringValue(population));
this.writeToFile(tmpLine.toString());
// data to be stored in file
double tmpd = 0;
StringBuffer tmpLine = new StringBuffer("");
tmpLine.append(population.getFunctionCalls());
tmpLine.append("\t");
tmpLine.append(population.getBestEAIndividual().getFitness(0));
tmpLine.append("\t");
for (int i = 0; i < population.size(); i++) tmpd += ((AbstractEAIndividual)population.get(i)).getFitness(0)/(double)population.size();
tmpLine.append("\t");
tmpLine.append(tmpd);
tmpLine.append("\t");
tmpLine.append(population.getWorstEAIndividual().getFitness(0));
//tmpLine.append("\t");
//tmpLine.append(this.m_GO.getProblem().getAdditionalFileStringValue(population));
this.writeToFile(tmpLine.toString());
Double[] tmpData = new Double[2];
tmpData[0] = new Double(population.getFunctionCalls());
// instead of adding simply the best fitness value i'll ask the problem what to show
tmpData[1] = this.m_GO.getProblem().getDoublePlotValue(population);
if (this.m_Plot != null) {
if (this.m_ContinueFlag) this.m_Plot.setConnectedPoint(tmpData[0].doubleValue()+this.m_RecentFC, tmpData[1].doubleValue(), 1000+this.currentRun);
else this.m_Plot.setConnectedPoint(tmpData[0].doubleValue(), tmpData[1].doubleValue(), 1000+this.currentRun);
}
this.m_TmpData.add(tmpData);
Double[] tmpData = new Double[2];
tmpData[0] = new Double(population.getFunctionCalls());
// instead of adding simply the best fitness value i'll ask the problem what to show
tmpData[1] = this.m_GO.getProblem().getDoublePlotValue(population);
if (this.m_Plot != null) {
if (this.m_ContinueFlag) this.m_Plot.setConnectedPoint(tmpData[0].doubleValue()+this.m_RecentFC, tmpData[1].doubleValue(), 1000+this.currentRun);
else this.m_Plot.setConnectedPoint(tmpData[0].doubleValue(), tmpData[1].doubleValue(), 1000+this.currentRun);
}
this.m_TmpData.add(tmpData);
}
}
/** This method writes Data to file.

View File

@ -498,19 +498,21 @@ public class MOCCOStandalone implements InterfaceGOStandalone, InterfacePopulati
* @param name Could be used to indicate the nature of the event.
*/
public void registerPopulationStateChanged(Object source, String name) {
int currentProgress;
if (this.m_State.isVisible) {
Population population = ((InterfaceOptimizer)source).getPopulation();
double x = 100;
if (this.m_State.m_Terminator instanceof EvaluationTerminator) {
double y = x/(double)((EvaluationTerminator)this.m_State.m_Terminator).getFitnessCalls();
currentProgress = (int)(population.getFunctionCalls()*y);
} else {
currentProgress = (int)(0);
}
updateStatus("Optimizing...",currentProgress);
} else {
// perhaps i could write it to file!?
}
int currentProgress;
if (name.equals(Population.nextGenerationPerformed)) {
if (this.m_State.isVisible) {
Population population = ((InterfaceOptimizer)source).getPopulation();
double x = 100;
if (this.m_State.m_Terminator instanceof EvaluationTerminator) {
double y = x/(double)((EvaluationTerminator)this.m_State.m_Terminator).getFitnessCalls();
currentProgress = (int)(population.getFunctionCalls()*y);
} else {
currentProgress = (int)(0);
}
updateStatus("Optimizing...",currentProgress);
} else {
// perhaps i could write it to file!?
}
}
}
}

View File

@ -749,7 +749,7 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
* @param name The identifying name.
* @param obj The object that is to be stored.
*/
public void SetData(String name, Object obj) {
public void putData(String name, Object obj) {
m_dataHash.put(name, obj);
}

View File

@ -118,7 +118,7 @@ public class ArchivingNSGAII extends ArchivingNSGA implements java.io.Serializab
tmpNonDom = new Population();
for (int i = 0; i < tmpPop.size(); i++) {
if (this.isDominant((AbstractEAIndividual) tmpPop.get(i), tmpPop)) {
((AbstractEAIndividual)tmpPop.get(i)).SetData("ParetoLevel", new Integer(level));
((AbstractEAIndividual)tmpPop.get(i)).putData("ParetoLevel", new Integer(level));
tmpDom.add(tmpPop.get(i));
} else {
@ -130,7 +130,7 @@ public class ArchivingNSGAII extends ArchivingNSGA implements java.io.Serializab
System.out.println("Problem NSGA II at level " + level + ".");
tmpDom.addPopulation(tmpNonDom);
for (int i = 0; i < tmpDom.size(); i++)
((AbstractEAIndividual)tmpDom.get(i)).SetData("ParetoLevel", new Integer(level));
((AbstractEAIndividual)tmpDom.get(i)).putData("ParetoLevel", new Integer(level));
tmpPop.clear();
// System.out.println(""+tmpPop.getStringRepresentation());
// tmpPop.removeDoubleInstancesUsingFitness();
@ -158,7 +158,7 @@ public class ArchivingNSGAII extends ArchivingNSGA implements java.io.Serializab
}
hyperCube = heidi.calculateHyperCubeVolumes(fitness);
for (int j = 0; j < fronts[i].size(); j++) {
((AbstractEAIndividual)fronts[i].get(j)).SetData("HyperCube", new Double(hyperCube[j]));
((AbstractEAIndividual)fronts[i].get(j)).putData("HyperCube", new Double(hyperCube[j]));
}
}
}

View File

@ -249,8 +249,8 @@ public class ArchivingPESAII extends AbstractArchiving implements java.io.Serial
for (int j = 0; j < coll.size(); j++) {
result[((Integer)coll.get(j)).intValue()] = coll.size();
tmpIndy = (AbstractEAIndividual)pop.get(((Integer)coll.get(j)).intValue());
tmpIndy.SetData("SqueezeFactor", new Integer(coll.size()));
tmpIndy.SetData("GridBox", curGrid);
tmpIndy.putData("SqueezeFactor", new Integer(coll.size()));
tmpIndy.putData("GridBox", curGrid);
}
}
}

View File

@ -512,8 +512,8 @@ public class ArchivingSPEAII extends AbstractArchiving implements java.io.Serial
for (int i = 0; i < SPEAResult.length; i++) {
if (1/(2+D[i]) >= 1) System.out.println("d " +1/(2+D[i]));
SPEAResult[i] = SPEAFitness[i] + (1/(2+D[i]));
((AbstractEAIndividual)pop.get(i)).SetData("RawFit", new Double(SPEAFitness[i]));
((AbstractEAIndividual)pop.get(i)).SetData("SPEAFit", new Double(SPEAResult[i]));
((AbstractEAIndividual)pop.get(i)).putData("RawFit", new Double(SPEAFitness[i]));
((AbstractEAIndividual)pop.get(i)).putData("SPEAFit", new Double(SPEAResult[i]));
}
if (this.m_Debug && this.m_Plot != null) {

View File

@ -44,7 +44,7 @@ public class RemoveSurplusIndividualsStaticHyperCube extends RemoveSurplusIndivi
}
space = this.calculateHyperCubeVolumes(fitness);
for (int i = 0; i < archive.size(); i++) {
((AbstractEAIndividual)archive.get(i)).SetData("HyperCube", new Double(space[i]));
((AbstractEAIndividual)archive.get(i)).putData("HyperCube", new Double(space[i]));
}
while(archive.size() > archive.getPopulationSize()) {

View File

@ -51,7 +51,7 @@ public class MOSODynamicallyWeightedFitness implements InterfaceMOSOConverter, j
double[] weights;
tmpFit = indy.getFitness();
indy.SetData("MOFitness", tmpFit);
indy.putData("MOFitness", tmpFit);
weights = new double[tmpFit.length];
// calculate the dynamic weights

View File

@ -53,7 +53,7 @@ public class MOSOEpsilonConstraint implements InterfaceMOSOConverter, java.io.Se
double[] tmpFit;
tmpFit = indy.getFitness();
indy.SetData("MOFitness", tmpFit);
indy.putData("MOFitness", tmpFit);
resultFit[0] = tmpFit[this.m_EpsilonConstraint.m_OptimizeObjective];
for (int i = 0; i < this.m_EpsilonConstraint.m_TargetValue.length; i++) {
if (i != this.m_EpsilonConstraint.m_OptimizeObjective) {

View File

@ -56,7 +56,7 @@ public class MOSOEpsilonThreshold implements InterfaceMOSOConverter, java.io.Ser
double[] tmpFit;
tmpFit = indy.getFitness();
indy.SetData("MOFitness", tmpFit);
indy.putData("MOFitness", tmpFit);
for (int i = 0; i < tmpFit.length; i++) {
if (new Double(tmpFit[i]).isNaN()) System.out.println("Fitness is NaN");
if (new Double(tmpFit[i]).isInfinite()) System.out.println("Fitness is Infinite");

View File

@ -50,7 +50,7 @@ public class MOSOGoalProgramming implements InterfaceMOSOConverter, java.io.Seri
double[] tmpFit;
tmpFit = indy.getFitness();
indy.SetData("MOFitness", tmpFit);
indy.putData("MOFitness", tmpFit);
resultFit[0] = 0;
for (int i = 0; (i < this.m_Goals.m_DoubleArray.length) && (i < tmpFit.length) ; i++)
resultFit[0] += tmpFit[i]-this.m_Goals.m_DoubleArray[i];

View File

@ -52,7 +52,7 @@ public class MOSOLpMetric implements InterfaceMOSOConverter, java.io.Serializabl
double[] tmpFit;
tmpFit = indy.getFitness();
indy.SetData("MOFitness", tmpFit);
indy.putData("MOFitness", tmpFit);
if (m_P >= 1) {
// standard Lp Metric
resultFit[0] = 0;

View File

@ -41,7 +41,7 @@ public class MOSOMOGARankBased implements InterfaceMOSOConverter, java.io.Serial
}
}
for (int i = 0; i < pop.size(); i++) {
((AbstractEAIndividual)pop.get(i)).SetData("MOGARank", new Integer(MOGARank[i]));
((AbstractEAIndividual)pop.get(i)).putData("MOGARank", new Integer(MOGARank[i]));
}
for (int i = 0; i < pop.size(); i++) {
this.convertSingleIndividual((AbstractEAIndividual)pop.get(i));
@ -56,7 +56,7 @@ public class MOSOMOGARankBased implements InterfaceMOSOConverter, java.io.Serial
double[] tmpFit;
tmpFit = indy.getFitness();
indy.SetData("MOFitness", tmpFit);
indy.putData("MOFitness", tmpFit);
resultFit[0] = ((Integer)indy.getData("MOGARank")).doubleValue();
indy.SetFitness(resultFit);
}

View File

@ -66,7 +66,7 @@ public class MOSOMaxiMin implements InterfaceMOSOConverter, java.io.Serializable
// write the result to the individuals
tmpIndy = (AbstractEAIndividual) pop.get(i);
tmpFit = tmpIndy.getFitness();
tmpIndy.SetData("MOFitness", tmpFit);
tmpIndy.putData("MOFitness", tmpFit);
resultFit = new double[1];
resultFit[0] = result[i];
tmpIndy.SetFitness(resultFit);
@ -107,7 +107,7 @@ public class MOSOMaxiMin implements InterfaceMOSOConverter, java.io.Serializable
double[] tmpFit;
tmpFit = indy.getFitness();
indy.SetData("MOFitness", tmpFit);
indy.putData("MOFitness", tmpFit);
System.out.println("The MaxiMin MOSO can not be applied to single individuals! I default to random criterion.");
resultFit[0] = tmpFit[RNG.randomInt(0, tmpFit.length)];
indy.SetFitness(resultFit);

View File

@ -41,7 +41,7 @@ public class MOSONoConvert implements InterfaceMOSOConverter, java.io.Serializab
double[] tmpFit;
tmpFit = indy.getFitness();
indy.SetData("MOFitness", tmpFit);
indy.putData("MOFitness", tmpFit);
// resultFit[0] = tmpFit[RNG.randomInt(0, tmpFit.length)];
// indy.SetFitness(resultFit);
}

View File

@ -45,7 +45,7 @@ public class MOSORandomChoice implements InterfaceMOSOConverter, java.io.Serial
double[] tmpFit;
tmpFit = indy.getFitness();
indy.SetData("MOFitness", tmpFit);
indy.putData("MOFitness", tmpFit);
resultFit[0] = tmpFit[RNG.randomInt(0, tmpFit.length-1)];
indy.SetFitness(resultFit);
}

View File

@ -44,7 +44,7 @@ public class MOSORandomWeight implements InterfaceMOSOConverter, java.io.Seriali
double sum = 0;
tmpFit = indy.getFitness();
indy.SetData("MOFitness", tmpFit);
indy.putData("MOFitness", tmpFit);
tmpWeight = new double[tmpFit.length];
for (int i = 0; i < tmpWeight.length; i++) {
tmpWeight[i] = RNG.randomDouble(0,1);

View File

@ -45,7 +45,7 @@ public class MOSORankbased implements InterfaceMOSOConverter, java.io.Serializab
double[] tmpFit;
tmpFit = indy.getFitness();
indy.SetData("MOFitness", tmpFit);
indy.putData("MOFitness", tmpFit);
resultFit[0] = ((Integer)indy.getData("ParetoLevel")).doubleValue();
indy.SetFitness(resultFit);
}

View File

@ -46,7 +46,7 @@ public class MOSOUtilityFunction implements InterfaceMOSOConverter, java.io.Seri
double[] tmpFit;
tmpFit = indy.getFitness();
indy.SetData("MOFitness", tmpFit);
indy.putData("MOFitness", tmpFit);
resultFit[0] = 0;
/**********************************************************************************************

View File

@ -51,7 +51,7 @@ public class MOSOWeightedFitness implements InterfaceMOSOConverter, java.io.Seri
double[] tmpFit;
tmpFit = indy.getFitness();
indy.SetData("MOFitness", tmpFit);
indy.putData("MOFitness", tmpFit);
for (int i = 0; (i < this.m_Weights.m_DoubleArray.length) && (i < tmpFit.length) ; i++)
resultFit[0] += tmpFit[i]*this.m_Weights.m_DoubleArray[i];
indy.SetFitness(resultFit);

View File

@ -55,7 +55,7 @@ public class MOSOWeightedLPTchebycheff implements InterfaceMOSOConverter, java.i
double[] tmpFit;
tmpFit = indy.getFitness();
indy.SetData("MOFitness", tmpFit);
indy.putData("MOFitness", tmpFit);
resultFit[0] = 0;
for (int i = 0; i < tmpFit.length; i++) {
if (this.m_WLPT.m_P == 0) {

View File

@ -8,68 +8,230 @@ import wsi.ra.math.Jama.EigenvalueDecomposition;
import wsi.ra.math.Jama.Matrix;
import eva2.gui.BeanInspector;
import eva2.gui.GenericObjectEditor;
import eva2.server.go.InterfacePopulationChangedEventListener;
import eva2.server.go.enums.ESMutationInitialSigma;
import eva2.server.go.individuals.AbstractEAIndividual;
import eva2.server.go.individuals.InterfaceDataTypeDouble;
import eva2.server.go.populations.Population;
import eva2.server.go.problems.InterfaceOptimizationProblem;
import eva2.server.go.strategies.EvolutionStrategies;
import eva2.tools.EVAERROR;
import eva2.tools.Mathematics;
import eva2.tools.Pair;
/**
* The collection of all population specific data required for a rank-mu-CMA optimization.
* Besides methods for initialization, this class implements the InterfacePopulationChangedEventListener
* and is added as listener to the population it is initialized on. The reason for this is that the
* CMA parameters must be reinitialized whenever the population itself is initialized, so the reinit
* event is caught and handled. As there are numerous mutator instances but only one CMA parameter
* set per population, this way is the good one.
*
* @author mkron
*
*/
class CMAParamSet implements InterfacePopulationChangedEventListener, Serializable {
private static final long serialVersionUID = -1940875082544233819L;
protected double firstSigma = -1.;
protected double sigma;
protected double d_sig, c_sig;
protected double[] meanX, pathC, pathS, eigenvalues;
protected double[] weights = null;
protected double[][] range = null;
protected Matrix mC;
protected Matrix mB;
protected boolean firstAdaptionDone = false;
public String toString() {
return "d_sig " + d_sig + ", c_sig" + ", sigma " + sigma + ", firstSigma " + firstSigma+ ", firstAdaptionDone " + firstAdaptionDone
+ ",\n meanX " + Arrays.toString(meanX) + ", pathC " + Arrays.toString(pathC)+ ", pathS " + Arrays.toString(pathS)+ ", eigenvalues " + Arrays.toString(eigenvalues)
+ ", weights " + Arrays.toString(weights)+ ",\n mC " + mC.toString() + ",\n mB " + mB.toString();
}
/**
* Initializes a new CMAParamSet from scratch.
*
* @see #initCMAParams(CMAParamSet, int, int, Population, double)
* @param mu
* @param lambda
* @param oldGen
* @param initialSigma
* @return
*/
public static CMAParamSet initCMAParams(int mu, int lambda, Population oldGen, double initialSigma) {
return initCMAParams(new CMAParamSet(), mu, lambda, oldGen, initialSigma);
}
/**
* Initializes the CMA parameter set for given mu, lambda and a population.
* The initialSigma parameter is used as initial sigma directly unless it is <0, in
* that case the average range is used as initial sigma.
* The parameter instance is also added as listener to the population.
*
* @param params the CMA parameter set to be used - its data are overwritten
* @param mu ES mu parameter
* @param lambda ES lambda parameter
* @param pop associated Population
* @param initialSigma initial sigma or -1 to indicate the usage of average range
* @return
*/
public static CMAParamSet initCMAParams(CMAParamSet params, int mu, int lambda, Population pop, double initialSigma) {
// those are from init:
params.firstAdaptionDone = false;
params.range = ((InterfaceDataTypeDouble)pop.getEAIndividual(0)).getDoubleRange();
int dim = params.range.length;
// if (TRACE_1) System.out.println("WCMA init " + dim);
// if (TRACE_1) System.out.println("WCMA static init " + dim);
params.eigenvalues = new double[dim];
Arrays.fill(params.eigenvalues, 1.);
params.meanX = new double[dim];
params.pathC = new double[dim];
params.pathS = new double[dim];
params.mC = Matrix.identity(dim, dim);
params.mB = Matrix.identity(dim, dim);
// from adaptAfterSel
params.weights = initWeights(mu, lambda);
double muEff = getMuEff(params.weights, mu);
params.c_sig = (muEff+2)/(muEff+dim+3);
// c_u_sig = Math.sqrt(c_sig * (2.-c_sig));
params.d_sig = params.c_sig+1+2*Math.max(0, Math.sqrt((muEff-1)/(dim+1)) - 1);
if (initialSigma<0) initialSigma = getAvgRange(params.range);
params.sigma = initialSigma;
// System.out.println("INitial sigma: "+sigma);
params.firstSigma = params.sigma;
params.meanX = pop.getCenter(); // this might be ok?
pop.addPopulationChangedEventListener(params);
return params;
}
/**
* Initialize the default weights for the mu update using a log scale.
*
* @param mu
* @param lambda
* @return
*/
public static double[] initWeights(int mu, int lambda) {
double[] theWeights = new double[mu];
double sum = 0;
int type = 0; // zero is default log scale
for (int i=0; i<mu; i++) {
if (type == 0) {
theWeights[i] = (Math.log((lambda+1)/2.)-Math.log(i+1));
} else theWeights[i] = 1.;
sum+=theWeights[i];
}
for (int i=0; i<mu; i++) theWeights[i] /= sum;
return theWeights;
}
/**
* So-called effective mu value.
*
* @param weights
* @param mu
* @return
*/
public static double getMuEff(double[] weights, int mu) {
double res = 0, u;
for (int i=0; i<mu;i++) {
u = weights[i];
res += u*u;
}
return 1./res;
}
/**
* The default mu_cov is equal to the mu_eff value.
*
* @param weights
* @param mu
* @return
*/
public static double getMuCov(double[] weights, int mu) {
// default parameter value ( HK03, sec. 2)
return getMuEff(weights, mu);
}
/**
* Calculate the average length of the range intervals over all dimensions.
*
* @param range
* @return
*/
public static double getAvgRange(double[][] range) {
double sum = 0.;
for (int i=0; i<range.length; i++) sum+=(range[i][1]-range[i][0]);
return sum/range.length;
}
/**
* Make sure that the parameter sets of each population are updated (reinitialized)
* if a population is reinitialized.
*
* @see InterfacePopulationChangedEventListener
*/
public void registerPopulationStateChanged(Object source, String name) {
if (name.equals(Population.populationInitialized)) {
Population pop = (Population)source;
if (MutateESRankMuCMA.TRACE_1) System.out.println("Event " + name + " arrived in CMAParamSet!!!");
CMAParamSet params = (CMAParamSet)(pop.getData(MutateESRankMuCMA.cmaParamsKey));
int mu;
if (pop.hasData(EvolutionStrategies.esMuParam)) {
mu = (Integer)pop.getData(EvolutionStrategies.esMuParam);
} else {
System.err.println("Unknown mu in reinit! using lambda/2...");
mu = pop.size()/2;
}
pop.putData(MutateESRankMuCMA.cmaParamsKey, CMAParamSet.initCMAParams(params, mu, pop.size(), pop, params.firstSigma));
}
}
}
/**
* Implementing CMA ES with rank-mu-update and weighted recombination. More information can be found here:
* - http://www.bionik.tu-berlin.de/user/niko/cmaesintro.html
* - N.Hansen & S.Kern 2004: Evaluating the CMA Evolution Strategy on Multimodal Test Functions.
* Parallel Problem Solving from Nature 2004.
* - For the stopping criteria: Auger&Hansen, CEC '05, A Restart CMA ES with increasing population size.
*
* The implementation uses a structure for keeping all adaptive parameters, CMAParamSet, which is stored
* in the populations, so that in principle, multi-modal optimization with several populations becomes possible.
* This of course requires proper handling of the generational cycle, i.e., new generations should be cloned from
* the former ones (without individuals is ok) so that the parameters are taken over.
*
* @author mkron
*
*/
public class MutateESRankMuCMA implements InterfaceMutationGenerational, Serializable {
int dim;
// int dim;
private double c_c, expRandStepLen;
private double[] z, zCor;
// The static member lastParams is used to store the parameter set last seen in an adaption step, which
// is then later used for the individual mutations. Necessary because each individual has its own mutator
// instance. It would be cleaner to keep all parameters within the individual and have just one mutation
// instance, however this would create quite a big baustelle.
private static transient CMAParamSet lastParams=null;
private ESMutationInitialSigma initializeSig = ESMutationInitialSigma.avgInitialDistance;
private double userDefInitSig = 0.2;
private static double firstSigma = -1.;
private static double sigma;
private static double d_sig, c_sig;
private static double[] meanX, pathC, pathS, eigenvalues;
private static double[] weights = null;
private static double[][] range = null;
private static Matrix mC;
private static Matrix mB;
// private static double[] mBD;
private static boolean firstAdaptionDone = false;
private static boolean TRACE_1 = false;
private static boolean TRACE_2 = false;
private static boolean TRACE_TEST = false;
// private Matrix BD;
public static final String cmaParamsKey = "RankMuCMAParameters";
public static boolean TRACE_1 = false;
public static boolean TRACE_2 = false;
public static boolean TRACE_TEST = false;
public MutateESRankMuCMA() {
firstAdaptionDone = false;
}
public MutateESRankMuCMA(MutateESRankMuCMA mutator) {
this.c_c = mutator.c_c;
// this.c_sig = mutator.c_sig;
// this.c_u_sig = mutator.c_u_sig;
// this.d_sig = mutator.d_sig;
this.expRandStepLen = mutator.expRandStepLen;
this.dim = mutator.dim;
this.initializeSig = mutator.initializeSig;
// if (mutator.meanX != null) this.meanX = (double[]) mutator.meanX.clone();
// if (mutator.pathC != null) this.pathC = (double[]) mutator.pathC.clone();
// if (mutator.pathS != null) this.pathS = (double[]) mutator.pathS.clone();
if (mutator.z != null) this.z = (double[]) mutator.z.clone();
if (mutator.zCor != null) this.zCor = (double[]) mutator.zCor.clone();
// if (mutator.eigenvalues != null) this.eigenvalues = (double[]) mutator.eigenvalues.clone();
// if (mutator.mC != null) this.mC = (Matrix) mutator.mC.clone();
// if (mutator.mB != null) this.mB = (Matrix) mutator.mB.clone();
}
public Object clone() {
@ -79,6 +241,7 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
/**
* Retrieve the initial sigma for the given population and the user defined method.
* For the halfRange case, -1 is returned, as the range is not available here.
* @param initGen
* @return
*/
@ -89,12 +252,20 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
//return initGen.getPopulationMeasures(null)[0]*getAvgRange();
// use euclidian measures without normation and scaling
return initGen.getPopulationMeasures(null)[0];
case halfRange: return getAvgRange()/2.;
//case halfRange: return getAvgRange(range)/2.;
case userDefined: return userDefInitSig ;
default: return 0.2;
default: return -1.;
}
}
/**
* Perform the main adaption of sigma and C using evolution paths.
* The evolution path is deduced from the center of the selected population compared to the old
* mean value.
* See Hansen&Kern 04 for further information.
* @param oldGen
* @param selectedP
*/
public void adaptAfterSelection(Population oldGen, Population selectedP) {
Population selectedSorted = selectedP.getSortedBestFirst();
@ -105,58 +276,57 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
EVAERROR.errorMsgOnce("Warning: invalid mu/lambda ratio (" + mu + "/" + lambda + ") ! Setting mu to lambda/2.");
mu = lambda/2;
}
if (!firstAdaptionDone) {
initWeights(mu, lambda);
double muEff = getMuEff(mu);
c_sig = (muEff+2)/(muEff+dim+3);
// c_u_sig = Math.sqrt(c_sig * (2.-c_sig));
d_sig = c_sig+1+2*Math.max(0, Math.sqrt((muEff-1)/(dim+1)) - 1);
sigma = getInitSigma(oldGen);
// System.out.println("INitial sigma: "+sigma);
firstSigma = sigma;
meanX = oldGen.getCenter(); // this might be ok?
CMAParamSet params;
if (oldGen.getGeneration() <= 1) { // init new param set. At gen < 1 we shouldnt be called, but better do it once too often
if (oldGen.hasData(cmaParamsKey)) params = CMAParamSet.initCMAParams((CMAParamSet)oldGen.getData(cmaParamsKey), mu, lambda, oldGen, getInitSigma(oldGen));
else params = CMAParamSet.initCMAParams(mu, lambda, oldGen, getInitSigma(oldGen));
} else {
if (!oldGen.hasData(cmaParamsKey)) {
if (oldGen.getGeneration() > 1) System.err.println("pop had no params at gen " + oldGen.getGeneration());
params = CMAParamSet.initCMAParams(mu, lambda, oldGen, getInitSigma(oldGen));
} else params = (CMAParamSet)oldGen.getData(cmaParamsKey);
}
int generation = oldGen.getGeneration();
if (TRACE_1) {
System.out.println("WCMA adaptGenerational");
System.out.println("WCMA adaptGenerational **********");
// System.out.println("newPop measures: " + BeanInspector.toString(newPop.getPopulationMeasures()));
System.out.println("mu_eff: " + getMuEff(mu));
System.out.println("meanX: " + BeanInspector.toString(meanX));
System.out.println("pathC: " + BeanInspector.toString(pathC));
System.out.println("pathS: " + BeanInspector.toString(pathS));
System.out.println("mu_eff: " + CMAParamSet.getMuEff(params.weights, mu));
System.out.println(params.toString());
System.out.println("*********************************");
}
double[] newMeanX = calcMeanX(selectedSorted);
double[] newMeanX = calcMeanX(params.weights, selectedSorted);
if (TRACE_1) System.out.println("newMeanX: " + BeanInspector.toString(newMeanX));
int dim=params.meanX.length;
double[] BDz = new double[dim];
for (int i=0; i<dim; i++) { /* calculate xmean and BDz~N(0,C) */
// Eq. 4 from HK04, most right term
BDz[i] = Math.sqrt(getMuEff(mu)) * (newMeanX[i] - meanX[i]) / getSigma(i);
BDz[i] = Math.sqrt(CMAParamSet.getMuEff(params.weights, mu)) * (newMeanX[i] - params.meanX[i]) / getSigma(params, i);
}
// if (TRACE_2) System.out.println("BDz is " + BeanInspector.toString(BDz));
double[] newPathS = pathS.clone();
double[] newPathC = pathC.clone();
double[] newPathS = params.pathS.clone();
double[] newPathC = params.pathC.clone();
double[] zVect = new double[dim];
/* calculate z := D^(-1) * B^(-1) * BDz into artmp, we could have stored z instead */
for (int i = 0; i < dim; ++i) {
double sum=0.;
for (int j = 0; j < dim; ++j) {
sum += mB.get(j,i) * BDz[j]; // times B transposed, (Eq 4) in HK04
sum += params.mB.get(j,i) * BDz[j]; // times B transposed, (Eq 4) in HK04
}
zVect[i] = sum / Math.sqrt(eigenvalues[i]);
zVect[i] = sum / Math.sqrt(params.eigenvalues[i]);
}
/* cumulation for sigma (ps) using B*z */
for (int i = 0; i < dim; ++i) {
double sum = 0.;
for (int j = 0; j < dim; ++j) sum += mB.get(i,j) * zVect[j];
newPathS[i] = (1. - getCs()) * pathS[i]
+ Math.sqrt(getCs() * (2. - getCs())) * sum;
for (int j = 0; j < dim; ++j) sum += params.mB.get(i,j) * zVect[j];
newPathS[i] = (1. - params.c_sig) * params.pathS[i]
+ Math.sqrt(params.c_sig * (2. - params.c_sig)) * sum;
}
// System.out.println("pathS diff: " + BeanInspector.toString(Mathematics.vvSub(newPathS, pathS)));
// System.out.println("newPathS is " + BeanInspector.toString(newPathS));
@ -164,12 +334,12 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
double psNorm = Mathematics.norm(newPathS);
double hsig = 0;
if (psNorm / Math.sqrt(1. - Math.pow(1. - getCs(), 2. * generation))
if (psNorm / Math.sqrt(1. - Math.pow(1. - params.c_sig, 2. * generation))
/ expRandStepLen < 1.4 + 2. / (dim + 1.)) {
hsig = 1;
}
for (int i = 0; i < dim; ++i) {
newPathC[i] = (1. - getCc()) * pathC[i] + hsig
newPathC[i] = (1. - getCc()) * params.pathC[i] + hsig
* Math.sqrt(getCc() * (2. - getCc())) * BDz[i];
}
@ -180,36 +350,39 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
System.out.println("newPathS: " + BeanInspector.toString(newPathS));
}
if (TRACE_1) System.out.println("Bef: C is \n" + mC.toString());
if (meanX == null) meanX = newMeanX;
if (TRACE_1) System.out.println("Bef: C is \n" + params.mC.toString());
if (params.meanX == null) params.meanX = newMeanX;
updateCov(newPathC, newMeanX, hsig, mu, selectedSorted);
updateBD();
updateCov(params, newPathC, newMeanX, hsig, mu, selectedSorted);
updateBD(params);
if (TRACE_2) System.out.println("Aft: C is \n" + mC.toString());
if (TRACE_2) System.out.println("Aft: C is \n" + params.mC.toString());
/* update of sigma */
double sigFact = Math.exp(((psNorm / expRandStepLen) - 1) * getCs()
/ getDamps());
if (Double.isInfinite(sigFact)) sigma *= 10.; // in larger search spaces sigma tends to explode after init.
else sigma *= sigFact;
double sigFact = Math.exp(((psNorm / expRandStepLen) - 1) * params.c_sig
/ params.d_sig);
if (Double.isInfinite(sigFact)) params.sigma *= 10.; // in larger search spaces sigma tends to explode after init.
else params.sigma *= sigFact;
if (Double.isInfinite(sigma) || Double.isNaN(sigma)) {
if (Double.isInfinite(params.sigma) || Double.isNaN(params.sigma)) {
System.err.println("Error, unstable sigma!");
}
testAndCorrectNumerics(generation, selectedSorted);
testAndCorrectNumerics(params, generation, selectedSorted);
// System.out.println("sigma=" + sigma + " psLen=" + (psNorm) + " chiN="+expRandStepLen + " cs="+getCs()+ " damps="+getDamps() + " diag " + BeanInspector.toString(eigenvalues));
if (TRACE_1) {
System.out.print("psLen=" + (psNorm) + " ");
outputParams(mu);
outputParams(params, mu);
}
// take over data
meanX = newMeanX;
pathC = newPathC;
pathS = newPathS;
firstAdaptionDone = true;
params.meanX = newMeanX;
params.pathC = newPathC;
params.pathS = newPathS;
params.firstAdaptionDone = true;
lastParams = params;
oldGen.putData(cmaParamsKey, params);
selectedP.putData(cmaParamsKey, params);
// if (TRACE_2) System.out.println("sampling around " + BeanInspector.toString(meanX));
}
@ -218,7 +391,13 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
*/
public void adaptGenerational(Population oldPop, Population selectedPop,
Population newPop, boolean updateSelected) {
// nothing to do?
// nothing to do? Oh yes, we can easily transfer the cma-params from the old to the new population.
if (!newPop.hasData(cmaParamsKey)) {
if (!oldPop.hasData(cmaParamsKey)) System.err.println("warning: no cma param set found (MutateESRankMuCMA!");
else newPop.putData(cmaParamsKey, oldPop.getData(cmaParamsKey));
}
//newPop.addData(cmaParamsKey, oldPop.getData(cmaParamsKey));
//newPop.addPopulationChangedEventListener(this); // listen to every population to be informed about reinit events
}
/**
@ -227,13 +406,13 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
* @param iterations
* @param selected
*/
void testAndCorrectNumerics(int iterations, Population selected) { // not much left here
void testAndCorrectNumerics(CMAParamSet params, int iterations, Population selected) { // not much left here
/* Flat Fitness, Test if function values are identical */
if (iterations > 1) {
// selected pop is sorted
if (nearlySame(selected.getEAIndividual(0).getFitness(),selected.getEAIndividual(selected.size()-1).getFitness())) {
if (TRACE_1) System.err.println("flat fitness landscape, consider reformulation of fitness, step-size increased");
sigma *= Math.exp(0.2+getCs()/getDamps());
params.sigma *= Math.exp(0.2+params.c_sig/params.d_sig);
// sigma=0.1;
}
}
@ -243,20 +422,20 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
double fac = 1.;
double minEig = 1e-12;
double maxEig = 1e8;
if (Mathematics.max(eigenvalues) < minEig)
fac = 1./Math.sqrt(Mathematics.max(eigenvalues));
else if (Mathematics.min(eigenvalues) > maxEig)
fac = 1./Math.sqrt(Mathematics.min(eigenvalues));
if (Mathematics.max(params.eigenvalues) < minEig)
fac = 1./Math.sqrt(Mathematics.max(params.eigenvalues));
else if (Mathematics.min(params.eigenvalues) > maxEig)
fac = 1./Math.sqrt(Mathematics.min(params.eigenvalues));
if (fac != 1.) {
System.err.println("Scaling by " + fac);
sigma /= fac;
for(int i = 0; i < dim; ++i) {
pathC[i] *= fac;
eigenvalues[i] *= fac*fac;
params.sigma /= fac;
for(int i = 0; i < params.meanX.length; ++i) {
params.pathC[i] *= fac;
params.eigenvalues[i] *= fac*fac;
for (int j = 0; j <= i; ++j) {
mC.set(i, j, mC.get(i,j)*fac*fac);
if (i!=j) mC.set(j, i, mC.get(i,j));
params.mC.set(i, j, params.mC.get(i,j)*fac*fac);
if (i!=j) params.mC.set(j, i, params.mC.get(i,j));
}
}
}
@ -274,70 +453,67 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
* @param i
* @return
*/
private double getSigma(int i) {
return sigma;
}
private double getDamps() {
return d_sig;
private double getSigma(CMAParamSet params, int i) {
return params.sigma;
}
//
// private double getDamps() {
// return d_sig;
// }
private double getCc() {
return c_c;
}
private double getCs() {
return c_sig;
}
// private double getCs() {
// return c_sig;
// }
private double calcExpRandStepLen() {
private double calcExpRandStepLen(int dim) {
// scale by avg range?
return Math.sqrt(dim)*(1.-(1./(4*dim))+(1./(21*dim*dim)));
}
private double getAvgRange() {
double sum = 0.;
for (int i=0; i<dim; i++) sum+=(range[i][1]-range[i][0]);
return sum/dim;
}
/* update C */
private void updateCov(double[] newPathC, double[] newMeanX, double hsig, int mu, Population selected) {
private void updateCov(CMAParamSet params, double[] newPathC, double[] newMeanX, double hsig, int mu, Population selected) {
double newVal = 0;
if (getCCov(mu) > 0) {
int dim = newMeanX.length;
double ccv = getCCov(params.weights, mu, dim);
if (ccv > 0) {
double mcv = CMAParamSet.getMuCov(params.weights, mu);
/* (only upper triangle!) */
/* update covariance matrix */
//System.out.println("CCov " + getCCov(selected) + " Cc " + getCc() + " muCov " + getMuCov(selected));
for (int i = 0; i < dim; ++i)
for (int j = 0; j <= i; ++j) {
// oldVal = mC.get(i,j);
newVal = (1 - getCCov(mu)) * mC.get(i,j)
+ getCCov(mu)
* (1. / getMuCov(mu))
newVal = (1 - ccv) * params.mC.get(i,j)
+ ccv
* (1. / mcv)
* (newPathC[i] * newPathC[j] + (1 - hsig) * getCc()
* (2. - getCc()) * mC.get(i,j));
mC.set(i,j,newVal);
* (2. - getCc()) * params.mC.get(i,j));
params.mC.set(i,j,newVal);
for (int k = 0; k < mu; ++k) { /*
* additional rank mu
* update
*/
double[] x_k = ((InterfaceDataTypeDouble)selected.getEAIndividual(k)).getDoubleData();
newVal = mC.get(i,j)+ getCCov(mu) * (1 - 1. / getMuCov(mu))
* getWeight(k) * (x_k[i] - meanX[i])
* (x_k[j] - meanX[j]) / (getSigma(i) * getSigma(j)); // TODO right sigmas?
mC.set(i,j, newVal);
newVal = params.mC.get(i,j)+ ccv * (1 - 1. / mcv)
* params.weights[k] * (x_k[i] - params.meanX[i])
* (x_k[j] - params.meanX[j]) / (getSigma(params, i) * getSigma(params, j)); // TODO right sigmas?
params.mC.set(i,j, newVal);
}
}
// fill rest of C
for (int i = 0; i < dim; ++i) {
for (int j = i+1; j < dim; ++j) {
mC.set(i, j, mC.get(j,i));
params.mC.set(i, j, params.mC.get(j,i));
}
}
if (mC.get(0,1) != mC.get(1,0)) {
System.err.println("WARNING");
if (params.mC.get(0,1) != params.mC.get(1,0)) {
System.err.println("WARNING, C is not symmetric!");
}
// maxsqrtdiagC = Math.sqrt(math.max(math.diag(C)));
// minsqrtdiagC = Math.sqrt(math.min(math.diag(C)));
@ -345,32 +521,22 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
}
private double getMuCov(int mu) {
// default parameter value ( HK03, sec. 2)
return getMuEff(mu);
}
private double getCCov(int mu) {
private double getCCov(double[] weights, int mu, int dim) {
// ( HK03, sec. 2)
//return Math.min(1., 2*getMuEff(selected)/(dim*dim));
double ccov = (2./(getMuCov(mu)*Math.pow(dim+Math.sqrt(2.), 2)))+(1.-(1./getMuCov(mu)))*Math.min(1., (2*getMuEff(mu)-1.)/(dim*dim+2*dim+4+getMuEff(mu)));
double muC=CMAParamSet.getMuCov(weights, mu);
double muE=CMAParamSet.getMuEff(weights,mu);
double ccov = (2./(muC*Math.pow(dim+Math.sqrt(2.), 2)))+(1.-(1./muC))*Math.min(1., (2*muE-1.)/(dim*dim+2*dim+4+muE));
return ccov;
}
private double getMuEff(int mu) {
double res = 0, u;
for (int i=0; i<mu;i++) {
u = getWeight(i);
res += u*u;
}
return 1./res;
}
private void outputParams(int mu) {
System.out.println("sigma=" + sigma + " chiN="+expRandStepLen + " cs="+getCs()+ " damps="+getDamps() + " Cc=" + getCc() + " Ccov=" + getCCov(mu) + " mueff=" + getMuEff(mu) + " mucov="+getMuCov(mu));
private void outputParams(CMAParamSet params, int mu) {
System.out.println("sigma=" + params.sigma + " chiN="+expRandStepLen + " cs="+params.c_sig
+ " damps="+params.d_sig + " Cc=" + getCc() + " Ccov=" + getCCov(params.weights, mu, params.meanX.length)
+ " mueff=" + CMAParamSet.getMuEff(params.weights, mu) + " mucov="+CMAParamSet.getMuCov(params.weights, mu));
}
private void updateBD() {
private void updateBD(CMAParamSet params) {
// C=triu(C)+transpose(triu(C,1)); % enforce symmetry
// [B,D] = eig(C);
// % limit condition of C to 1e14 + 1
@ -382,13 +548,13 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
// D = diag(sqrt(diag(D))); % D contains standard deviations now
// BD = B*D; % for speed up only
////////////////////////////////////////////7
mC = (mC.plus(mC.transpose()).times(0.5)); // MAKE C SYMMETRIC
params.mC = (params.mC.plus(params.mC.transpose()).times(0.5)); // MAKE C SYMMETRIC
EigenvalueDecomposition helper;
// this.m_Counter = 0;
helper = new EigenvalueDecomposition(mC);
mB = helper.getV(); // Return the eigenvector matrix
eigenvalues = helper.getRealEigenvalues();
helper = new EigenvalueDecomposition(params.mC);
params.mB = helper.getV(); // Return the eigenvector matrix
params.eigenvalues = helper.getRealEigenvalues();
// double[] sqrtEig = eigenvalues.clone();
// for (int i = 0; i < sqrtEig.length; i++) {
@ -417,26 +583,9 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
* @param selectedPop
* @return
*/
private double[] calcMeanX(Population selectedPop) {
private double[] calcMeanX(double[] weights, Population selectedPop) {
return selectedPop.getCenterWeighted(weights);
}
private double getWeight(int i) {
return weights[i];
}
private void initWeights(int mu, int lambda) {
weights = new double[mu];
double sum = 0;
int type = 0; // zero is default log scale
for (int i=0; i<mu; i++) {
if (type == 0) {
weights[i] = (Math.log((lambda+1)/2.)-Math.log(i+1));
} else weights[i] = 1.;
sum+=weights[i];
}
for (int i=0; i<mu; i++) weights[i] /= sum;
}
public void crossoverOnStrategyParameters(AbstractEAIndividual indy1,
Population partners) {
@ -458,29 +607,30 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
public void init(AbstractEAIndividual individual,
InterfaceOptimizationProblem opt) {
// TODO recheck all this; some is handled in adaptGeneration on the first call
firstAdaptionDone = false;
range = ((InterfaceDataTypeDouble)individual).getDoubleRange();
dim = range.length;
if (TRACE_1) System.out.println("WCMA init " + dim);
// firstAdaptionDone = false;
// range = ((InterfaceDataTypeDouble)individual).getDoubleRange();
// dim = range.length;
// if (TRACE_1) System.out.println("WCMA init " + dim);
// c_c = (4./(dim+4));
// c_sig = Double.NaN; // mark as not yet initialized
//// c_u_sig = Double.NaN;
// d_sig = Double.NaN; // init in first adaption step!
// if (TRACE_1) System.out.println("WCMA static init " + dim);
// eigenvalues = new double[dim];
// Arrays.fill(eigenvalues, 1.);
//
// meanX = new double[dim];
// pathC = new double[dim];
// pathS = new double[dim];
//// mBD = new double[dim];
// mC = Matrix.identity(dim, dim);
// mB = Matrix.identity(dim, dim);
// sigma = 0.2;
// ^^^ moved to CMAParamSet initialization
double[][] range = ((InterfaceDataTypeDouble)individual).getDoubleRange();
int dim = range.length;
c_c = (4./(dim+4));
c_sig = Double.NaN; // mark as not yet initialized
// c_u_sig = Double.NaN;
d_sig = Double.NaN; // init in first adaption step!
if (TRACE_1) System.out.println("WCMA static init " + dim);
eigenvalues = new double[dim];
Arrays.fill(eigenvalues, 1.);
meanX = new double[dim];
pathC = new double[dim];
pathS = new double[dim];
// mBD = new double[dim];
mC = Matrix.identity(dim, dim);
mB = Matrix.identity(dim, dim);
sigma = 0.2;
z = new double[dim];
zCor = new double[dim];
expRandStepLen = calcExpRandStepLen();
expRandStepLen = calcExpRandStepLen(dim);
}
@ -494,36 +644,42 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
// if (TRACE) System.out.println("WCMA mutate, bef: " + BeanInspector.toString(x));
double[][] range = ((InterfaceDataTypeDouble)individual).getDoubleRange();
((InterfaceDataTypeDouble)individual).SetDoubleGenotype(mutate(x, range, 0));
// this is a critical point: where do the CMA parameters for this individual's mutation come from?
// for GA and ES we can expect that selection occured directly before the mutation cycle,
// so we take the parameter set from the last adpation step.
((InterfaceDataTypeDouble)individual).SetDoubleGenotype(mutate(lastParams, x, range, 0));
// if (TRACE) System.out.println("WCMA mutate, aft: " + BeanInspector.toString(x));
} else System.err.println("Error, expecting InterfaceDataTypeDouble");
}
private double[] mutate(double[] x, double[][] range, int count) {
if (firstAdaptionDone) {
double[] sampl = new double[x.length]; // generate scaled random vector (D * z)
private double[] mutate(CMAParamSet params, double[] x, double[][] range, int count) {
int dim = range.length;
if (params!=null && (params.firstAdaptionDone)) {
double[] sampl = new double[dim]; // generate scaled random vector (D * z)
for (int i = 0; i < dim; ++i) {
sampl[i] = Math.sqrt(eigenvalues[i]) * RNG.gaussianDouble(1.);
sampl[i] = Math.sqrt(params.eigenvalues[i]) * RNG.gaussianDouble(1.);
}
// System.out.println("Sampling around " + BeanInspector.toString(meanX));
/* add mutation (sigma * B * (D*z)) */
for (int i = 0; i < dim; ++i) {
double sum = 0.;
for (int j = 0; j < dim; ++j)
sum += mB.get(i,j) * sampl[j];
x[i] = meanX[i]+getSigma(i)*sum;
sum += params.mB.get(i,j) * sampl[j];
x[i] = params.meanX[i]+getSigma(params, i)*sum;
}
} else {
// no valid meanX yet, so just do a gaussian jump with sigma
if (params==null) {
System.err.println("Error in MutateESRankMuCMA: parameter set was null! Skipping mutation...");
} // no valid meanX yet, so just do a gaussian jump with sigma
for (int i = 0; i < dim; ++i) {
x[i] += RNG.gaussianDouble(getSigma(i));
x[i] += RNG.gaussianDouble(getSigma(params, i));
}
}
if (isInRange(x, range)) return x;
else {
if (count > 5) return repairMutation(x, range); // allow some nice tries before using brute force
else return mutate(x, range, count+1); // for really bad initial deviations this might be a quasi infinite loop
else return mutate(params, x, range, count+1); // for really bad initial deviations this might be a quasi infinite loop
}
}
@ -553,8 +709,8 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
*
* @return the initial sigma value actually employed
*/
public double getFirstSigma() {
return firstSigma;
public double getFirstSigma(Population pop) {
return ((CMAParamSet)pop.getData(cmaParamsKey)).firstSigma;
}
public void hideHideable() {
@ -586,12 +742,13 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
* @param tolX
* @return
*/
public boolean testAllDistBelow(double tolX) {
public boolean testAllDistBelow(Population pop, double tolX) {
// if all(sigma*(max(abs(pc), sqrt(diag(C)))) < stopTolX)
boolean res = true;
CMAParamSet params = (CMAParamSet)pop.getData(cmaParamsKey);
int i=0;
while (res && i<dim) {
res = res && (getSigma(i)*Math.max(Math.abs(pathC[i]), Math.sqrt(mC.get(i,i))) < tolX);
while (res && i<params.meanX.length) {
res = res && (getSigma(params, i)*Math.max(Math.abs(params.pathC[i]), Math.sqrt(params.mC.get(i,i))) < tolX);
i++;
}
if (TRACE_TEST) if (res) System.out.println("testAllDistBelow hit");
@ -604,19 +761,20 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
* @param gen
* @return
*/
public boolean testNoChangeAddingDevAxis(double d, int gen) {
public boolean testNoChangeAddingDevAxis(Population pop, double d, int gen) {
// if all(xmean == xmean + 0.1*sigma*BD(:,1+floor(mod(countiter,N))))
// i = 1+floor(mod(countiter,N));
// stopflag(end+1) = {'warnnoeffectaxis'};
CMAParamSet params = (CMAParamSet)pop.getData(cmaParamsKey);
int dim=params.meanX.length;
int k = gen%dim;
double[] ev_k = mB.getColumn(k);
Mathematics.svMult(Math.sqrt(eigenvalues[k]), ev_k, ev_k); // this is now e_k*v_k = BD(:,...)
double[] ev_k = params.mB.getColumn(k);
Mathematics.svMult(Math.sqrt(params.eigenvalues[k]), ev_k, ev_k); // this is now e_k*v_k = BD(:,...)
int i=0;
boolean res = true;
while (res && (i<dim)) {
res = res && (meanX[i] == (meanX[i] + d*getSigma(i)*ev_k[i]));
res = res && (params.meanX[i] == (params.meanX[i] + d*getSigma(params, i)*ev_k[i]));
i++;
}
if (TRACE_TEST) if (res) System.out.println("testNoChangeAddingDevAxis hit");
@ -628,13 +786,14 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
* @param d
* @return
*/
public boolean testNoEffectCoord(double d) {
public boolean testNoEffectCoord(Population pop, double d) {
// if any(xmean == xmean + 0.2*sigma*sqrt(diag(C)))
// stopflag(end+1) = {'warnnoeffectcoord'};
boolean ret = false;
CMAParamSet params = (CMAParamSet)pop.getData(cmaParamsKey);
int i=0;
while ((i<dim) && !ret) {
ret = ret || (meanX[i]==(meanX[i] + d*getSigma(i)*Math.sqrt(mC.get(i, i))));
while ((i<params.meanX.length) && !ret) {
ret = ret || (params.meanX[i]==(params.meanX[i] + d*getSigma(params, i)*Math.sqrt(params.mC.get(i, i))));
i++;
}
if (TRACE_TEST) if (ret) System.out.println("testNoEffectCoord hit");
@ -648,10 +807,11 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
* @param d
* @return true, if a diagonal entry is <= 0 or >= d, else false
*/
public boolean testCCondition(double d) {
public boolean testCCondition(Population pop, double d) {
// if (min(diag(D)) <= 0) || (max(diag(D)) > 1e14*min(diag(D)))
// stopflag(end+1) = {'warnconditioncov'};
Pair<Double,Double> minMax = mC.getMinMaxDiag();
CMAParamSet params = (CMAParamSet)pop.getData(cmaParamsKey);
Pair<Double,Double> minMax = params.mC.getMinMaxDiag();
if ((minMax.head <= 0) || (minMax.tail >= d)) {
if (TRACE_TEST) System.out.println("testCCondition hit");
return true;

View File

@ -2,7 +2,9 @@ package eva2.server.go.populations;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Set;
@ -39,13 +41,16 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
protected Population m_Archive = null;
transient private ArrayList<AbstractEAIndividual> sortedArr = null;
transient protected InterfacePopulationChangedEventListener m_Listener = null;
transient private ArrayList<InterfacePopulationChangedEventListener> listeners = null;
// transient protected InterfacePopulationChangedEventListener m_Listener = null;
// the evaluation interval at which listeners are notified
protected int notifyEvalInterval = 0;
protected HashMap<String, Object> additionalPopData = null;
public static String funCallIntervalReached = "FunCallIntervalReached";
public static final String funCallIntervalReached = "FunCallIntervalReached";
public static final String populationInitialized = "PopulationReinitOccured";
public static final String nextGenerationPerformed = "NextGenerationPerformed";
boolean useHistory = false;
public ArrayList<AbstractEAIndividual> m_History = new ArrayList<AbstractEAIndividual>();
@ -95,7 +100,9 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
this.m_Size = population.m_Size;
this.useHistory = population.useHistory;
this.notifyEvalInterval = population.notifyEvalInterval;
this.m_Listener = population.m_Listener;
// this.m_Listener = population.m_Listener;
if (population.listeners != null) this.listeners = (ArrayList<InterfacePopulationChangedEventListener>)population.listeners.clone();
else listeners = null;
if (population.additionalPopData != null) {
additionalPopData = new HashMap<String, Object>();
Set<String> keys = additionalPopData.keySet();
@ -105,7 +112,7 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
}
}
public void addData(String key, Object value) {
public void putData(String key, Object value) {
if (additionalPopData == null) additionalPopData = new HashMap<String, Object>();
additionalPopData.put(key, value);
}
@ -115,6 +122,11 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
else return additionalPopData.get(key);
}
public boolean hasData(String key) {
if (additionalPopData != null) return (additionalPopData.get(key)!=null);
else return false;
}
public Object clone() {
return (Object) new Population(this);
}
@ -130,6 +142,7 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
Population res = new Population();
res.setSameParams(this);
res.copyHistAndArchive(this);
if (additionalPopData!=null) res.additionalPopData = (HashMap<String, Object>)(additionalPopData.clone());
return res;
}
@ -147,6 +160,7 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
this.m_Archive.clear();
this.m_Archive.init();
}
firePropertyChangedEvent(Population.populationInitialized);
}
/** This method inits the population. Function and generation counters
@ -215,11 +229,16 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
/** Something has changed
*/
protected void firePropertyChangedEvent(String name) {
if (this.m_Listener != null) this.m_Listener.registerPopulationStateChanged(this, name);
if (listeners != null) {
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
InterfacePopulationChangedEventListener listener = (InterfacePopulationChangedEventListener) iterator.next();
listener.registerPopulationStateChanged(this, name);
}
}
}
private boolean doEvalNotify() {
return ((this.m_Listener != null) && (notifyEvalInterval > 0));
return ((listeners != null) && (listeners.size() > 0) && (notifyEvalInterval > 0));
}
/** This method return the current number of function calls performed.
@ -260,7 +279,7 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
if (useHistory && (this.size() >= 1)) this.m_History.add(this.getBestEAIndividual());
for (int i=0; i<size(); i++) ((AbstractEAIndividual)get(i)).incrAge();
this.m_Generation++;
firePropertyChangedEvent("NextGenerationPerformed");
firePropertyChangedEvent(nextGenerationPerformed);
}
/** This method returns the current generation.
@ -281,7 +300,16 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
* @param ea
*/
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea;
if (listeners == null) listeners = new ArrayList<InterfacePopulationChangedEventListener>(3);
if (!listeners.contains(ea)) {
listeners.add(ea);
}
}
public void removePopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
if (listeners != null) {
listeners.remove(ea);
}
}
/** This method allows you to add a complete population to the current population.
@ -350,12 +378,13 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
/**
* This method will return the index of the current best individual from the
* population.
* population. If the population is empty, -1 is returned.
*
* @see getIndexOfBestOrWorstIndividual()
* @return The index of the best individual.
*/
public int getIndexOfBestIndividual() {
if (size()<1) return -1;
return getIndexOfBestOrWorstIndividual(true, true);
}
@ -422,15 +451,23 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
return result;
}
/** This method returns the current best individual from the population
/**
* This method returns the current best individual from the population.
* If the population is empty, null is returned.
*
* @return The best individual
*/
public AbstractEAIndividual getBestEAIndividual() {
if (size()<1) return null;
int best = this.getIndexOfBestIndividual();
if (best == -1) System.err.println("This shouldnt happen!");;
AbstractEAIndividual result = (AbstractEAIndividual)this.get(best);
if (result == null) System.err.println("Serious Problem! Population Size: " + this.size());
return result;
if (best == -1) {
System.err.println("This shouldnt happen!");
return null;
} else {
AbstractEAIndividual result = (AbstractEAIndividual)this.get(best);
if (result == null) System.err.println("Serious Problem! Population Size: " + this.size());
return result;
}
}
/**
@ -796,7 +833,7 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
public boolean add(IndividualInterface o) {
return addIndividual((IndividualInterface)o);
}
/**
* ArrayList does not increase the modCount in set. Why???
*/

View File

@ -51,22 +51,14 @@ public abstract class AbstractOptimizationProblem implements InterfaceOptimizati
*/
public void evaluate(Population population) {
AbstractEAIndividual tmpIndy;
// if (population.isEvaluated()) {
// System.err.println("Population evaluation seems not required!");
// } else {
// @todo This is the position to implement a granular
// @todo paralleliziation scheme
evaluatePopulationStart(population);
for (int i = 0; i < population.size(); i++) {
tmpIndy = (AbstractEAIndividual) population.get(i);
tmpIndy.resetConstraintViolation();
this.evaluate(tmpIndy);
population.incrFunctionCalls();
}
evaluatePopulationEnd(population);
// population.setEvaluated();
// }
evaluatePopulationStart(population);
for (int i = 0; i < population.size(); i++) {
tmpIndy = (AbstractEAIndividual) population.get(i);
tmpIndy.resetConstraintViolation();
this.evaluate(tmpIndy);
population.incrFunctionCalls();
}
evaluatePopulationEnd(population);
}
/**
@ -103,20 +95,6 @@ public abstract class AbstractOptimizationProblem implements InterfaceOptimizati
return AbstractEAIndividual.getDefaultStringRepresentation(individual);
}
/** This method returns a single line representation of the solution
* @param individual The individual
* @return The string
*/
// public String getSolutionDataFor(IndividualInterface individual) {
// }
// /** This method returns a string describing the optimization problem.
// * @return The description.
// */
// public String getStringRepresentationF() {
// return "AbstractOptimizationProblem: programmer failed to give further details";
// }
/** This method returns a double value that will be displayed in a fitness
* plot. A fitness that is to be minimized with a global min of zero
* would be best, since log y can be used. But the value can depend on the problem.
@ -152,7 +130,9 @@ public abstract class AbstractOptimizationProblem implements InterfaceOptimizati
result.setLayout(new BorderLayout());
JTextArea area = new JTextArea();
JScrollPane scroll = new JScrollPane(area);
area.setText("Best Solution:\n"+this.getSolutionRepresentationFor(indy));
String text = "Best Solution:\n"+this.getSolutionRepresentationFor(indy);
area.setLineWrap(true);
area.setText(text);
area.setEditable(false);
result.add(scroll, BorderLayout.CENTER);
return result;

View File

@ -1,13 +1,10 @@
package eva2.server.go.problems;
import javax.swing.*;
import eva2.server.go.individuals.AbstractEAIndividual;
import eva2.server.go.populations.Population;
import eva2.server.go.strategies.InterfaceOptimizer;
import eva2.server.stat.InterfaceStatistics;
/**
* Created by IntelliJ IDEA.
@ -51,15 +48,6 @@ public interface InterfaceOptimizationProblem extends InterfaceAdditionalPopulat
*/
public void evaluate(AbstractEAIndividual individual);
// DEPRECATED, use PhenotypeMetric
//** This method should be used to calculate the distance between two
// * individuals
// * @param indy1 The first individual.
// * @param indy2 The second individual.
// * @return The distance.
// */
// public double distanceBetween(AbstractEAIndividual indy1, AbstractEAIndividual indy2);
/******************** Some output methods *******************************************/
/** This method allows the CommonJavaObjectEditorPanel to read the

View File

@ -73,7 +73,7 @@ public class CHCAdaptiveSearchAlgorithm implements InterfaceOptimizer, java.io.S
}
this.evaluatePopulation(this.m_Population);
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/** This method will init the optimizer with a given population
@ -92,7 +92,7 @@ public class CHCAdaptiveSearchAlgorithm implements InterfaceOptimizer, java.io.S
if (reset) {
this.evaluatePopulation(this.m_Population);
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
}
@ -212,7 +212,7 @@ public class CHCAdaptiveSearchAlgorithm implements InterfaceOptimizer, java.io.S
nextGeneration.addPopulation(tmp);
this.m_Population = nextGeneration;
}
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/** This method allows you to add the LectureGUI as listener to the Optimizer

View File

@ -614,7 +614,7 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
// System.out.println("species distract best towards " + BeanInspector.toString(distVect));
// }
// }
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/**

View File

@ -113,7 +113,7 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
this.m_Problem.initPopulation(this.m_Population);
m_Population.addPopulationChangedEventListener(null); // noone will be notified directly on pop changes
this.m_Problem.evaluate(this.m_Population);
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/** This method will init the optimizer with a given population
@ -127,7 +127,7 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
if (reset) {
this.m_Population.init();
this.m_Problem.evaluate(this.m_Population);
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
}
@ -176,7 +176,7 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
}
}
// System.out.println("funcalls: " + evalCnt);
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
@ -189,7 +189,7 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
// set funcalls to real value
m_Population.SetFunctionCalls(((Population)source).getFunctionCalls());
// System.out.println("FunCallIntervalReached at " + (((Population)source).getFunctionCalls()));
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
// do not react to NextGenerationPerformed
//else System.err.println("ERROR, event was " + name);

View File

@ -78,7 +78,7 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
this.m_Problem.initPopulation(this.m_Population);
// children = new Population(m_Population.size());
this.evaluatePopulation(this.m_Population);
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
public void hideHideable() {
@ -94,7 +94,7 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
if (reset) {
this.m_Population.init();
this.evaluatePopulation(this.m_Population);
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
// if (reset) this.m_Population.init();
// else children = new Population(m_Population.size());
@ -413,7 +413,7 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
// }
m_Problem.evaluatePopulationEnd(m_Population);
this.m_Population.incrGeneration();
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/**

View File

@ -375,7 +375,7 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
for (int i = 0; i < this.m_Population.size(); i++) {
AbstractEAIndividual indy = (AbstractEAIndividual)m_Population.get(i);
if (i>=quantumCount) {
indy.SetData(partTypeKey, quantumType);
indy.putData(partTypeKey, quantumType);
quantumCount += 1./quantumRatio;
}
}
@ -437,8 +437,8 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
// log the best individual of the population
if (envHasChanged || (this.m_Population.getBestEAIndividual().isDominatingDebConstraints(this.m_BestIndividual))) {
this.m_BestIndividual = (AbstractEAIndividual)this.m_Population.getBestEAIndividual().clone();
this.m_BestIndividual.SetData(partBestFitKey, this.m_BestIndividual.getFitness());
this.m_BestIndividual.SetData(partBestPosKey, ((InterfaceDataTypeDouble)this.m_BestIndividual).getDoubleData());
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]);
}
}

View File

@ -49,6 +49,7 @@ public class EvolutionStrategies implements InterfaceOptimizer, java.io.Serializ
transient private String m_Identifier = "";
transient private InterfacePopulationChangedEventListener m_Listener;
public static final String esMuParam = "EvolutionStrategyMuParameter";
public EvolutionStrategies() {
this.m_Population.setPopulationSize(this.m_Lambda);
@ -97,10 +98,11 @@ public class EvolutionStrategies implements InterfaceOptimizer, java.io.Serializ
// }
//System.out.println("init");
checkPopulationConstraints();
m_Population.putData(esMuParam, getMu());
this.m_Problem.initPopulation(this.m_Population);
this.evaluatePopulation(this.m_Population);
// this.m_Population.setPopulationSize(orgPopSize);
// this.firePropertyChangedEvent("NextGenerationPerformed");// not necessary if incrGeneration is called
// this.firePropertyChangedEvent(Population.nextGenerationPerformed);// not necessary if incrGeneration is called
}
@ -115,7 +117,7 @@ public class EvolutionStrategies implements InterfaceOptimizer, java.io.Serializ
if (reset) {
this.m_Population.init();
this.evaluatePopulation(this.m_Population);
// this.firePropertyChangedEvent("NextGenerationPerformed"); // not necessary if incrGeneration is called
// this.firePropertyChangedEvent(Population.nextGenerationPerformed); // not necessary if incrGeneration is called
}
}
@ -203,7 +205,7 @@ public class EvolutionStrategies implements InterfaceOptimizer, java.io.Serializ
// System.out.println("Population size: " + this.m_Population.size());
// System.out.println("-- Best Fitness " + this.m_Population.getBestFitness()[0]);
this.firePropertyChangedEvent("NextGenerationPerformed"); // necessary here because evalPop was not called on m_Population
this.firePropertyChangedEvent(Population.nextGenerationPerformed); // necessary here because evalPop was not called on m_Population
}
/**

View File

@ -91,7 +91,7 @@ public class EvolutionStrategyIPOP extends EvolutionStrategies implements Interf
//
// setPop(getReplacePop(nextGeneration));
//
// this.firePropertyChangedEvent("NextGenerationPerformed");
// this.firePropertyChangedEvent(Population.nextGenerationPerformed);
//////////////////////////
super.optimize();
@ -126,7 +126,7 @@ public class EvolutionStrategyIPOP extends EvolutionStrategies implements Interf
bestList.add(best);
best = null;
Population newPop = getPopulation().cloneWithoutInds();
getProblem().initPopulation(newPop);
getProblem().initPopulation(newPop); // this is where the reinit event of Pop is called, meaning that the rank-mu-cma matrix is reinitialized as well
double[] badFit = getPopulation().getBestFitness().clone();
Arrays.fill(badFit, Double.MAX_VALUE);
newPop.setAllFitnessValues(badFit);
@ -137,7 +137,7 @@ public class EvolutionStrategyIPOP extends EvolutionStrategies implements Interf
protected void firePropertyChangedEvent(String name) {
if (name.equals(Population.funCallIntervalReached)) {
super.firePropertyChangedEvent("NextGenerationPerformed");
super.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
else {} // nothing, evt is produced in #registerPopulationStateChanged, dont forward original due to changing pop size
}
@ -196,16 +196,16 @@ public class EvolutionStrategyIPOP extends EvolutionStrategies implements Interf
// stop if the std dev of the normal distribution is smaller than TolX in all coords
// and sigma p_c is smaller than TolX in all components; TolX = 10^-12 sigma_0
if (rcmaMute.testAllDistBelow(10e-12*rcmaMute.getFirstSigma())) return true;
if (rcmaMute.testAllDistBelow(pop, 10e-12*rcmaMute.getFirstSigma(pop))) return true;
// stop if adding a 0.1 std dev vector in a principal axis dir. of C does not change <x>_w^g
if (rcmaMute.testNoChangeAddingDevAxis(0.1, curGen)) return true;
if (rcmaMute.testNoChangeAddingDevAxis(pop, 0.1, curGen)) return true;
// stop if adding a 0.2 std dev in each coordinate does (not???) change <x>_w^g
if (rcmaMute.testNoEffectCoord(0.2)) return true;
if (rcmaMute.testNoEffectCoord(pop, 0.2)) return true;
// stop if the condition number of C exceeds 10^14
if (rcmaMute.testCCondition(10e14)) return true;
if (rcmaMute.testCCondition(pop, 10e14)) return true;
}
return false;
@ -231,7 +231,7 @@ public class EvolutionStrategyIPOP extends EvolutionStrategies implements Interf
public void registerPopulationStateChanged(Object source, String name) {
if (name.equals(Population.funCallIntervalReached)) {
getPopulation().SetFunctionCalls(((Population)source).getFunctionCalls()); // TODO this is ugly
super.firePropertyChangedEvent(name);
super.firePropertyChangedEvent(Population.nextGenerationPerformed);
} else {
// System.err.println("Not forwarding event " + name);
}

View File

@ -50,7 +50,7 @@ public class EvolutionaryProgramming implements InterfaceOptimizer, java.io.Seri
this.m_Problem.initPopulation(this.m_Population);
this.evaluatePopulation(this.m_Population);
this.m_PopulationSize = this.m_Population.size();
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/** This method will init the optimizer with a given population
@ -61,7 +61,7 @@ public class EvolutionaryProgramming implements InterfaceOptimizer, java.io.Seri
if (reset) {
this.m_Population.init();
this.evaluatePopulation(this.m_Population);
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
}
@ -119,7 +119,7 @@ public class EvolutionaryProgramming implements InterfaceOptimizer, java.io.Seri
nextGeneration.addPopulation(this.m_Population);
this.m_Population = nextGeneration;
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/** This method allows you to add the LectureGUI as listener to the Optimizer

View File

@ -59,7 +59,7 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
this.m_Problem.initPopulation(this.m_Population);
this.m_Problem.evaluate(this.m_Population);
this.m_CurrentFloodPeak = this.m_InitialFloodPeak;
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/** This method will init the optimizer with a given population
@ -70,7 +70,7 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
if (reset) {
this.m_Population.init();
this.m_Problem.evaluate(this.m_Population);
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
this.m_CurrentFloodPeak = this.m_InitialFloodPeak;
}
@ -99,7 +99,7 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
}
this.m_CurrentFloodPeak = this.m_CurrentFloodPeak - this.m_DrainRate;
this.m_Population.incrGeneration();
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/** This method calculates the difference between the fitness values

View File

@ -59,7 +59,7 @@ public class GeneticAlgorithm implements InterfaceOptimizer, java.io.Serializabl
public void init() {
this.m_Problem.initPopulation(this.m_Population);
this.evaluatePopulation(this.m_Population);
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/** This method will init the optimizer with a given population
@ -70,7 +70,7 @@ public class GeneticAlgorithm implements InterfaceOptimizer, java.io.Serializabl
if (reset) {
this.m_Population.init();
this.evaluatePopulation(this.m_Population);
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
}
@ -162,7 +162,7 @@ public class GeneticAlgorithm implements InterfaceOptimizer, java.io.Serializabl
// }
// }
// this.m_Population.incrGeneration();
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/** This method allows you to add the LectureGUI as listener to the Optimizer

View File

@ -56,7 +56,7 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
if (reset) {
this.getPopulation().init();
this.m_Problem.evaluate(this.getPopulation());
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
//System.out.println("initByPopulation() called");
indyhash = new Hashtable();
@ -247,7 +247,7 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
}
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
private double momentumweigth = 0.1;

View File

@ -55,7 +55,7 @@ public class HillClimbing implements InterfaceOptimizer, java.io.Serializable {
public void init() {
this.m_Problem.initPopulation(this.m_Population);
this.m_Problem.evaluate(this.m_Population);
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
public void initByPopulation(Population pop, boolean reset) {
@ -63,7 +63,7 @@ public class HillClimbing implements InterfaceOptimizer, java.io.Serializable {
if (reset) {
this.m_Population.init();
this.m_Problem.evaluate(this.m_Population);
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
}
@ -107,7 +107,7 @@ public class HillClimbing implements InterfaceOptimizer, java.io.Serializable {
// }
// }
// this.m_Population.incrGeneration();
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
public InterfaceMutation getMutationOperator() {

View File

@ -135,7 +135,7 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
this.m_Population.addPopulation(pop);
this.m_Population.incrFunctionCallsBy(pop.getFunctionCalls());
}
this.firePropertyChangedEvent("NextGenerationPerformed", this.m_Optimizer.getPopulation());
this.firePropertyChangedEvent(Population.nextGenerationPerformed, this.m_Optimizer.getPopulation());
}
/** This method will init the optimizer with a given population
@ -197,7 +197,7 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
this.m_Population.addPopulation(pop);
this.m_Population.incrFunctionCallsBy(pop.getFunctionCalls());
}
this.firePropertyChangedEvent("NextGenerationPerformed", this.m_Optimizer.getPopulation());
this.firePropertyChangedEvent(Population.nextGenerationPerformed, this.m_Optimizer.getPopulation());
}
/** The optimize method will compute an 'improved' and evaluated population
@ -252,7 +252,7 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
this.m_Population.incrFunctionCallsBy(pop.getFunctionCalls());
}
// System.out.println("Fitnesscalls :" + this.m_Population.getFunctionCalls());
this.firePropertyChangedEvent("NextGenerationPerformed", this.m_Optimizer.getPopulation());
this.firePropertyChangedEvent(Population.nextGenerationPerformed, 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);
// now they are synchronized

View File

@ -92,7 +92,7 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
if (reset) {
this.getPopulation().init();
this.m_Problem.evaluate(this.getPopulation());
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
}
@ -101,7 +101,7 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
this.m_GlobalOptimizer.SetProblem(this.m_Problem);
this.m_GlobalOptimizer.init();
this.evaluatePopulation(this.m_GlobalOptimizer.getPopulation());
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/**
@ -192,7 +192,7 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
if (TRACE)
System.out.println("function calls"
+ this.m_GlobalOptimizer.getPopulation().getFunctionCalls());
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/**

View File

@ -55,7 +55,7 @@ public class MonteCarloSearch implements InterfaceOptimizer, java.io.Serializabl
public void init() {
this.m_Problem.initPopulation(this.m_Population);
this.m_Problem.evaluate(this.m_Population);
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/** This method will init the optimizer with a given population
@ -67,7 +67,7 @@ public class MonteCarloSearch implements InterfaceOptimizer, java.io.Serializabl
if (reset) {
this.m_Population.init();
this.m_Problem.evaluate(this.m_Population);
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
}
@ -86,7 +86,7 @@ public class MonteCarloSearch implements InterfaceOptimizer, java.io.Serializabl
}
}
this.m_Population.incrGeneration();
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}

View File

@ -76,7 +76,7 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
public void init() {
this.m_Optimizer.init();
this.m_Archiver.addElementsToArchive(this.m_Optimizer.getPopulation());
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
@ -87,7 +87,7 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
public void initByPopulation(Population pop, boolean reset) {
this.m_Optimizer.initByPopulation(pop, reset);
this.m_Archiver.addElementsToArchive(this.m_Optimizer.getPopulation());
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/** The optimize method will compute a 'improved' and evaluated population
@ -127,7 +127,7 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
System.gc();
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
private double[][] showMay(Population pop) {

View File

@ -183,8 +183,8 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
for (int j = 0; j < writeData.length; j++) {
writeData[j] = (writeData[j]/relSpeed)*this.m_InitialVelocity;
}
indy.SetData(partTypeKey, defaultType);
indy.SetData(partVelKey, writeData);
indy.putData(partTypeKey, defaultType);
indy.putData(partVelKey, writeData);
}
/**
@ -197,12 +197,12 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
double[] tmpD = indy.getFitness();
double[] writeData = new double[tmpD.length];
System.arraycopy(tmpD, 0, writeData, 0, tmpD.length);
indy.SetData(partBestFitKey, writeData);
indy.putData(partBestFitKey, writeData);
// init best position
tmpD = ((InterfaceDataTypeDouble)indy).getDoubleData();
writeData = new double[tmpD.length];
System.arraycopy(tmpD, 0, writeData, 0, tmpD.length);
indy.SetData(partBestPosKey, writeData);
indy.putData(partBestPosKey, writeData);
}
/**
@ -380,7 +380,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
this.m_BestIndividual = (AbstractEAIndividual)this.m_Population.getBestEAIndividual().clone();
if (reset) this.firePropertyChangedEvent("NextGenerationPerformed");
if (reset) this.firePropertyChangedEvent(Population.nextGenerationPerformed);
treeLevels = 0;
// the HPSO tree will contain layers 0...HPSOLevels, the last one is "incomplete" with only HPSOOrphans number of nodes
@ -405,7 +405,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
if (indy instanceof InterfaceDataTypeDouble) {
initIndividualDefaults(indy);
}
indy.SetData(indexKey, i);
indy.putData(indexKey, i);
indy.setIndividualIndex(i);
}
}
@ -473,7 +473,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
if (indy instanceof InterfaceDataTypeDouble) {
indy.setParents(null);
indy.defaultInit();
indy.SetData(partTypeKey, defaultType); // turn into default type
indy.putData(partTypeKey, defaultType); // turn into default type
initIndividualDefaults(indy);
initIndividualMemory(indy);
plotIndy(((InterfaceDataTypeDouble)indy).getDoubleData(), null, (Integer)indy.getData(indexKey));
@ -506,7 +506,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
protected void defaultIndividualUpdate(int index, AbstractEAIndividual indy, Population pop) {
InterfaceDataTypeDouble endy = (InterfaceDataTypeDouble) indy;
indy.SetData(partTypeKey, defaultType);
indy.putData(partTypeKey, defaultType);
// default update
double[] personalBestPos = (double[]) indy.getData(partBestPosKey);
double[] velocity = (double[]) indy.getData(partVelKey);
@ -598,8 +598,8 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
* @param indy the individual to update
*/
protected void updateIndProps(AbstractEAIndividual indy) {
indy.SetData(partBestFitKey, indy.getFitness());
indy.SetData(partBestPosKey, ((InterfaceDataTypeDouble)indy).getDoubleData());
indy.putData(partBestFitKey, indy.getFitness());
indy.putData(partBestPosKey, ((InterfaceDataTypeDouble)indy).getDoubleData());
}
/**
@ -1025,7 +1025,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
if (!m_CheckConstraints) System.err.println("warning, checkbounds will be forced by InterfaceESIndividual!");
}
indy.SetData(partVelKey, curVelocity);
indy.putData(partVelKey, curVelocity);
// ((InterfaceESIndividual) indy).SetDGenotype(newPosition);
}
@ -1135,7 +1135,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
// System.out.println(">>> " + m_Population.getBestEAIndividual().getStringRepresentation());
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
if (sleepTime > 0 ) try { Thread.sleep(sleepTime); } catch(Exception e) {}
@ -1176,8 +1176,8 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
protected void logBestIndividual() {
if (this.m_Population.getBestEAIndividual().isDominatingDebConstraints(this.m_BestIndividual)) {
this.m_BestIndividual = (AbstractEAIndividual)this.m_Population.getBestEAIndividual().clone();
this.m_BestIndividual.SetData(partBestFitKey, this.m_BestIndividual.getFitness());
this.m_BestIndividual.SetData(partBestPosKey, ((InterfaceDataTypeDouble)this.m_BestIndividual).getDoubleData());
this.m_BestIndividual.putData(partBestFitKey, this.m_BestIndividual.getFitness());
this.m_BestIndividual.putData(partBestPosKey, ((InterfaceDataTypeDouble)this.m_BestIndividual).getDoubleData());
// System.out.println("new best: "+m_BestIndividual.toString());
}
}
@ -1224,7 +1224,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
for (int i=0; i<pop.size(); i++) {
// cross-link the sorted list for faster access
origIndex = (Integer)((AbstractEAIndividual)sortedPopulation[i]).getData(indexKey);
((AbstractEAIndividual)pop.get(origIndex)).SetData(sortedIndexKey, new Integer(i));
((AbstractEAIndividual)pop.get(origIndex)).putData(sortedIndexKey, new Integer(i));
}
}
@ -1260,22 +1260,22 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
} else {
found = true;
// assign to leader, update swarm size
((AbstractEAIndividual)sortedPop[cur]).SetData(multiSwTypeKey, leaders.get(i));
((AbstractEAIndividual)sortedPop[cur]).SetData(multiSwSizeKey, new Integer(-1));
leaders.get(i).SetData(multiSwSizeKey, 1+sSize);
((AbstractEAIndividual)sortedPop[cur]).putData(multiSwTypeKey, leaders.get(i));
((AbstractEAIndividual)sortedPop[cur]).putData(multiSwSizeKey, new Integer(-1));
leaders.get(i).putData(multiSwSizeKey, 1+sSize);
break;
}
}
}
if (!found) { // new leader is found
leaders.add(((AbstractEAIndividual)sortedPop[cur]));
((AbstractEAIndividual)sortedPop[cur]).SetData(multiSwTypeKey, sortedPop[cur]);
((AbstractEAIndividual)sortedPop[cur]).SetData(multiSwSizeKey, new Integer(1));
((AbstractEAIndividual)sortedPop[cur]).putData(multiSwTypeKey, sortedPop[cur]);
((AbstractEAIndividual)sortedPop[cur]).putData(multiSwSizeKey, new Integer(1));
} else if (superfluous) {
//System.out.println("reinitializing " + cur);
((AbstractEAIndividual)sortedPop[cur]).SetData(partTypeKey, resetType);
((AbstractEAIndividual)sortedPop[cur]).SetData(multiSwTypeKey, sortedPop[cur]);
((AbstractEAIndividual)sortedPop[cur]).SetData(multiSwSizeKey, new Integer(1));
((AbstractEAIndividual)sortedPop[cur]).putData(partTypeKey, resetType);
((AbstractEAIndividual)sortedPop[cur]).putData(multiSwTypeKey, sortedPop[cur]);
((AbstractEAIndividual)sortedPop[cur]).putData(multiSwSizeKey, new Integer(1));
}
cur++;
}
@ -1432,7 +1432,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
if (indy.hasData(partTypeKey)) {
initIndividualDefaults(indy);
initIndividualMemory(indy);
indy.SetData(indexKey, i);
indy.putData(indexKey, i);
indy.setIndividualIndex(i);
if (TRACE) System.err.println("init indy " + i + " " + AbstractEAIndividual.getDefaultDataString(indy));
}

View File

@ -60,7 +60,7 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
public void init() {
this.m_Problem.initPopulation(this.m_Population);
this.evaluatePopulation(this.m_Population);
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/** This method will init the optimizer with a given population
@ -78,7 +78,7 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
this.evaluatePopulation(this.m_Population);
}
((PBILPopulation)this.m_Population).buildProbabilityVector();
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/** This method will evaluate the current population using the
@ -121,7 +121,7 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
} else {
this.m_Population = nextGeneration;
}
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/** This method will set the problem that is to be optimized

View File

@ -58,7 +58,7 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
this.m_Problem.initPopulation(this.m_Population);
this.m_Problem.evaluate(this.m_Population);
this.m_CurrentTemperature = this.m_InitialTemperature;
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/** This method will init the optimizer with a given population
@ -71,7 +71,7 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
if (reset) {
this.m_Population.init();
this.m_Problem.evaluate(this.m_Population);
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
}
@ -105,7 +105,7 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
}
this.m_CurrentTemperature = this.m_Alpha * this.m_CurrentTemperature;
this.m_Population.incrGeneration();
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/** This method calculates the difference between the fitness values

View File

@ -54,7 +54,7 @@ public class SteadyStateGA implements InterfaceOptimizer, java.io.Serializable {
public void init() {
this.m_Problem.initPopulation(this.m_Population);
this.evaluatePopulation(this.m_Population);
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/** This method will init the optimizer with a given population
@ -65,7 +65,7 @@ public class SteadyStateGA implements InterfaceOptimizer, java.io.Serializable {
if (reset) {
this.m_Population.init();
this.evaluatePopulation(this.m_Population);
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
}
@ -111,7 +111,7 @@ public class SteadyStateGA implements InterfaceOptimizer, java.io.Serializable {
for (int i = 0; i < this.m_Population.size(); i++) this.generateChildren();
this.m_Population.incrFunctionCallsBy(this.m_Population.size());
this.m_Population.incrGeneration();
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/** This method allows you to add the LectureGUI as listener to the Optimizer

View File

@ -56,7 +56,7 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
this.m_Problem.initPopulation(this.m_Population);
this.m_Problem.evaluate(this.m_Population);
this.m_CurrentT = this.m_InitialT;
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/** This method will init the optimizer with a given population
@ -69,7 +69,7 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
if (reset) {
this.m_Population.init();
this.m_Problem.evaluate(this.m_Population);
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
}
@ -97,7 +97,7 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
}
this.m_CurrentT = this.m_Alpha * this.m_CurrentT;
this.m_Population.incrGeneration();
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/** This method calculates the difference between the fitness values

View File

@ -736,7 +736,7 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
population.incrFunctionCalls();
if (notifyAfter(population.getFunctionCalls())) {
// System.out.println("Notifying after " + population.getFunctionCalls());
firePropertyChangedEvent("NextGenerationPerformed");
firePropertyChangedEvent(Population.nextGenerationPerformed);
}
}

View File

@ -92,7 +92,7 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
this.m_SOOptimizer.init();
}
this.communicate();
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
@ -130,7 +130,7 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
this.m_SOOptimizer.initByPopulation(pop, reset);
}
this.communicate();
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/** The optimize method will compute a 'improved' and evaluated population
@ -148,7 +148,7 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
System.gc();
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/** This method will manage comunication between the
@ -171,7 +171,7 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
oldFunctionCalls = this.m_Population.getFunctionCalls();
this.m_Problem.evaluate(this.m_Population);
this.m_Population.SetFunctionCalls(oldFunctionCalls);
this.firePropertyChangedEvent("NextGenerationPerformed");
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
double plotValue = (this.m_Problem.getDoublePlotValue(this.m_Population)).doubleValue();
// now they are synchronized lets migrate
this.migrate();

View File

@ -16,12 +16,12 @@ import java.io.Serializable;
import java.net.InetAddress;
import java.util.Vector;
import eva2.gui.JTabbedModuleFrame;
import eva2.gui.LogPanel;
import eva2.server.go.InterfaceProcessor;
import wsi.ra.jproxy.MainAdapterClient;
import wsi.ra.jproxy.RemoteStateListener;
import eva2.gui.JTabbedModuleFrame;
import eva2.gui.LogPanel;
import eva2.server.go.InterfaceGOParameters;
import eva2.server.go.InterfaceProcessor;
/*==========================================================================*
* ABSTRACT CLASS DECLARATION
*==========================================================================*/
@ -120,6 +120,12 @@ abstract public class AbstractModuleAdapter implements ModuleAdapter, Serializab
} else return false;
}
public InterfaceGOParameters getGOParameters() {
if ((m_Processor != null) && (m_Processor instanceof Processor)) {
return ((Processor)m_Processor).getGOParams();
} else return null;
}
/**
*
*/

View File

@ -29,6 +29,6 @@ public class GOModuleAdapter extends GenericModuleAdapter implements ModuleAdapt
* @param Client the client instance
*/
public GOModuleAdapter(String adapterName, MainAdapterClient client) {
super (adapterName, "GO.html", client, GOParameters.getInstance(), false);
super (adapterName, "", client, GOParameters.getInstance(), false);
}
}

View File

@ -251,19 +251,21 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
* @param name Could be used to indicate the nature of the event.
*/
public void registerPopulationStateChanged(Object source, String name) {
m_Statistics.createNextGenerationPerformed(
(PopulationInterface)this.goParams.getOptimizer().getPopulation(),
this.goParams.getProblem());
if (m_ListenerModule != null) {
m_ListenerModule.updateProgress(
getStatusPercent(
goParams.getOptimizer().getPopulation(),
runCounter,
m_Statistics.getStatisticsParameter().getMultiRuns()),
null);
}
if (name.equals(Population.nextGenerationPerformed)) {
m_Statistics.createNextGenerationPerformed(
(PopulationInterface)this.goParams.getOptimizer().getPopulation(),
this.goParams.getProblem());
if (m_ListenerModule != null) {
m_ListenerModule.updateProgress(
getStatusPercent(
goParams.getOptimizer().getPopulation(),
runCounter,
m_Statistics.getStatisticsParameter().getMultiRuns()),
null);
}
}
}
/** This method writes Data to file.
* @param line The line that is to be added to the file
*/