From bcdc7d254e8654c734a620b28c6a9e274d25f16f Mon Sep 17 00:00:00 2001 From: Marcel Kronfeld Date: Fri, 12 Sep 2008 09:57:36 +0000 Subject: [PATCH] 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. --- src/eva2/gui/JModuleGeneralPanel.java | 76 ++- src/eva2/server/go/GOStandaloneVersion.java | 68 ++- src/eva2/server/go/MOCCOStandalone.java | 30 +- .../go/individuals/AbstractEAIndividual.java | 2 +- .../operators/archiving/ArchivingNSGAII.java | 6 +- .../operators/archiving/ArchivingPESAII.java | 4 +- .../operators/archiving/ArchivingSPEAII.java | 4 +- ...moveSurplusIndividualsStaticHyperCube.java | 2 +- .../moso/MOSODynamicallyWeightedFitness.java | 2 +- .../operators/moso/MOSOEpsilonConstraint.java | 2 +- .../operators/moso/MOSOEpsilonThreshold.java | 2 +- .../operators/moso/MOSOGoalProgramming.java | 2 +- .../go/operators/moso/MOSOLpMetric.java | 2 +- .../go/operators/moso/MOSOMOGARankBased.java | 4 +- .../server/go/operators/moso/MOSOMaxiMin.java | 4 +- .../go/operators/moso/MOSONoConvert.java | 2 +- .../go/operators/moso/MOSORandomChoice.java | 2 +- .../go/operators/moso/MOSORandomWeight.java | 2 +- .../go/operators/moso/MOSORankbased.java | 2 +- .../operators/moso/MOSOUtilityFunction.java | 2 +- .../operators/moso/MOSOWeightedFitness.java | 2 +- .../moso/MOSOWeightedLPTchebycheff.java | 2 +- .../operators/mutation/MutateESRankMuCMA.java | 572 +++++++++++------- .../server/go/populations/Population.java | 67 +- .../problems/AbstractOptimizationProblem.java | 42 +- .../InterfaceOptimizationProblem.java | 12 - .../CHCAdaptiveSearchAlgorithm.java | 6 +- .../go/strategies/ClusterBasedNichingEA.java | 2 +- .../go/strategies/ClusteringHillClimbing.java | 8 +- .../go/strategies/DifferentialEvolution.java | 6 +- .../DynamicParticleSwarmOptimization.java | 6 +- .../go/strategies/EvolutionStrategies.java | 8 +- .../go/strategies/EvolutionStrategyIPOP.java | 16 +- .../strategies/EvolutionaryProgramming.java | 6 +- .../server/go/strategies/FloodAlgorithm.java | 6 +- .../go/strategies/GeneticAlgorithm.java | 6 +- .../strategies/GradientDescentAlgorithm.java | 4 +- .../server/go/strategies/HillClimbing.java | 6 +- .../server/go/strategies/IslandModelEA.java | 6 +- .../go/strategies/MemeticAlgorithm.java | 6 +- .../go/strategies/MonteCarloSearch.java | 6 +- .../go/strategies/MultiObjectiveEA.java | 6 +- .../strategies/ParticleSwarmOptimization.java | 48 +- .../PopulationBasedIncrementalLearning.java | 6 +- .../go/strategies/SimulatedAnnealing.java | 6 +- .../server/go/strategies/SteadyStateGA.java | 6 +- .../go/strategies/ThresholdAlgorithm.java | 6 +- src/eva2/server/go/strategies/Tribes.java | 2 +- .../go/strategies/WingedMultiObjectiveEA.java | 8 +- .../server/modules/AbstractModuleAdapter.java | 14 +- src/eva2/server/modules/GOModuleAdapter.java | 2 +- src/eva2/server/modules/Processor.java | 26 +- 52 files changed, 690 insertions(+), 455 deletions(-) diff --git a/src/eva2/gui/JModuleGeneralPanel.java b/src/eva2/gui/JModuleGeneralPanel.java index ee77c971..37964b17 100644 --- a/src/eva2/gui/JModuleGeneralPanel.java +++ b/src/eva2/gui/JModuleGeneralPanel.java @@ -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; + } } } diff --git a/src/eva2/server/go/GOStandaloneVersion.java b/src/eva2/server/go/GOStandaloneVersion.java index a5431296..210e2807 100644 --- a/src/eva2/server/go/GOStandaloneVersion.java +++ b/src/eva2/server/go/GOStandaloneVersion.java @@ -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. diff --git a/src/eva2/server/go/MOCCOStandalone.java b/src/eva2/server/go/MOCCOStandalone.java index b49900f2..ca9613d3 100644 --- a/src/eva2/server/go/MOCCOStandalone.java +++ b/src/eva2/server/go/MOCCOStandalone.java @@ -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!? + } + } } } diff --git a/src/eva2/server/go/individuals/AbstractEAIndividual.java b/src/eva2/server/go/individuals/AbstractEAIndividual.java index c1c45885..58de0d29 100644 --- a/src/eva2/server/go/individuals/AbstractEAIndividual.java +++ b/src/eva2/server/go/individuals/AbstractEAIndividual.java @@ -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); } diff --git a/src/eva2/server/go/operators/archiving/ArchivingNSGAII.java b/src/eva2/server/go/operators/archiving/ArchivingNSGAII.java index b585c172..0a012e88 100644 --- a/src/eva2/server/go/operators/archiving/ArchivingNSGAII.java +++ b/src/eva2/server/go/operators/archiving/ArchivingNSGAII.java @@ -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])); } } } diff --git a/src/eva2/server/go/operators/archiving/ArchivingPESAII.java b/src/eva2/server/go/operators/archiving/ArchivingPESAII.java index 31c935df..ec69cf6d 100644 --- a/src/eva2/server/go/operators/archiving/ArchivingPESAII.java +++ b/src/eva2/server/go/operators/archiving/ArchivingPESAII.java @@ -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); } } } diff --git a/src/eva2/server/go/operators/archiving/ArchivingSPEAII.java b/src/eva2/server/go/operators/archiving/ArchivingSPEAII.java index 585df186..8db85a87 100644 --- a/src/eva2/server/go/operators/archiving/ArchivingSPEAII.java +++ b/src/eva2/server/go/operators/archiving/ArchivingSPEAII.java @@ -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) { diff --git a/src/eva2/server/go/operators/archiving/RemoveSurplusIndividualsStaticHyperCube.java b/src/eva2/server/go/operators/archiving/RemoveSurplusIndividualsStaticHyperCube.java index 85f817c2..b93cd9b3 100644 --- a/src/eva2/server/go/operators/archiving/RemoveSurplusIndividualsStaticHyperCube.java +++ b/src/eva2/server/go/operators/archiving/RemoveSurplusIndividualsStaticHyperCube.java @@ -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()) { diff --git a/src/eva2/server/go/operators/moso/MOSODynamicallyWeightedFitness.java b/src/eva2/server/go/operators/moso/MOSODynamicallyWeightedFitness.java index 579be6ce..1e64302b 100644 --- a/src/eva2/server/go/operators/moso/MOSODynamicallyWeightedFitness.java +++ b/src/eva2/server/go/operators/moso/MOSODynamicallyWeightedFitness.java @@ -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 diff --git a/src/eva2/server/go/operators/moso/MOSOEpsilonConstraint.java b/src/eva2/server/go/operators/moso/MOSOEpsilonConstraint.java index 09276d1a..3c609c59 100644 --- a/src/eva2/server/go/operators/moso/MOSOEpsilonConstraint.java +++ b/src/eva2/server/go/operators/moso/MOSOEpsilonConstraint.java @@ -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) { diff --git a/src/eva2/server/go/operators/moso/MOSOEpsilonThreshold.java b/src/eva2/server/go/operators/moso/MOSOEpsilonThreshold.java index 41582483..1b60e2ea 100644 --- a/src/eva2/server/go/operators/moso/MOSOEpsilonThreshold.java +++ b/src/eva2/server/go/operators/moso/MOSOEpsilonThreshold.java @@ -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"); diff --git a/src/eva2/server/go/operators/moso/MOSOGoalProgramming.java b/src/eva2/server/go/operators/moso/MOSOGoalProgramming.java index fd39419c..42a870d7 100644 --- a/src/eva2/server/go/operators/moso/MOSOGoalProgramming.java +++ b/src/eva2/server/go/operators/moso/MOSOGoalProgramming.java @@ -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]; diff --git a/src/eva2/server/go/operators/moso/MOSOLpMetric.java b/src/eva2/server/go/operators/moso/MOSOLpMetric.java index 3d3b5043..78fc5b4b 100644 --- a/src/eva2/server/go/operators/moso/MOSOLpMetric.java +++ b/src/eva2/server/go/operators/moso/MOSOLpMetric.java @@ -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; diff --git a/src/eva2/server/go/operators/moso/MOSOMOGARankBased.java b/src/eva2/server/go/operators/moso/MOSOMOGARankBased.java index ac5db9e0..00a6beee 100644 --- a/src/eva2/server/go/operators/moso/MOSOMOGARankBased.java +++ b/src/eva2/server/go/operators/moso/MOSOMOGARankBased.java @@ -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); } diff --git a/src/eva2/server/go/operators/moso/MOSOMaxiMin.java b/src/eva2/server/go/operators/moso/MOSOMaxiMin.java index 480b91ed..6f677f6d 100644 --- a/src/eva2/server/go/operators/moso/MOSOMaxiMin.java +++ b/src/eva2/server/go/operators/moso/MOSOMaxiMin.java @@ -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); diff --git a/src/eva2/server/go/operators/moso/MOSONoConvert.java b/src/eva2/server/go/operators/moso/MOSONoConvert.java index 9c84924f..bb035c9e 100644 --- a/src/eva2/server/go/operators/moso/MOSONoConvert.java +++ b/src/eva2/server/go/operators/moso/MOSONoConvert.java @@ -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); } diff --git a/src/eva2/server/go/operators/moso/MOSORandomChoice.java b/src/eva2/server/go/operators/moso/MOSORandomChoice.java index f0ae1a44..900e1895 100644 --- a/src/eva2/server/go/operators/moso/MOSORandomChoice.java +++ b/src/eva2/server/go/operators/moso/MOSORandomChoice.java @@ -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); } diff --git a/src/eva2/server/go/operators/moso/MOSORandomWeight.java b/src/eva2/server/go/operators/moso/MOSORandomWeight.java index 9dfe0e83..6b6179a2 100644 --- a/src/eva2/server/go/operators/moso/MOSORandomWeight.java +++ b/src/eva2/server/go/operators/moso/MOSORandomWeight.java @@ -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); diff --git a/src/eva2/server/go/operators/moso/MOSORankbased.java b/src/eva2/server/go/operators/moso/MOSORankbased.java index 4f071e1b..029bf40d 100644 --- a/src/eva2/server/go/operators/moso/MOSORankbased.java +++ b/src/eva2/server/go/operators/moso/MOSORankbased.java @@ -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); } diff --git a/src/eva2/server/go/operators/moso/MOSOUtilityFunction.java b/src/eva2/server/go/operators/moso/MOSOUtilityFunction.java index 8df6a020..1f8df02e 100644 --- a/src/eva2/server/go/operators/moso/MOSOUtilityFunction.java +++ b/src/eva2/server/go/operators/moso/MOSOUtilityFunction.java @@ -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; /********************************************************************************************** diff --git a/src/eva2/server/go/operators/moso/MOSOWeightedFitness.java b/src/eva2/server/go/operators/moso/MOSOWeightedFitness.java index c50cef05..8e49a27e 100644 --- a/src/eva2/server/go/operators/moso/MOSOWeightedFitness.java +++ b/src/eva2/server/go/operators/moso/MOSOWeightedFitness.java @@ -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); diff --git a/src/eva2/server/go/operators/moso/MOSOWeightedLPTchebycheff.java b/src/eva2/server/go/operators/moso/MOSOWeightedLPTchebycheff.java index c4258020..526c9b36 100644 --- a/src/eva2/server/go/operators/moso/MOSOWeightedLPTchebycheff.java +++ b/src/eva2/server/go/operators/moso/MOSOWeightedLPTchebycheff.java @@ -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) { diff --git a/src/eva2/server/go/operators/mutation/MutateESRankMuCMA.java b/src/eva2/server/go/operators/mutation/MutateESRankMuCMA.java index 3cb02005..8a4dae55 100644 --- a/src/eva2/server/go/operators/mutation/MutateESRankMuCMA.java +++ b/src/eva2/server/go/operators/mutation/MutateESRankMuCMA.java @@ -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 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 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 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 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= 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 minMax = mC.getMinMaxDiag(); + CMAParamSet params = (CMAParamSet)pop.getData(cmaParamsKey); + Pair minMax = params.mC.getMinMaxDiag(); if ((minMax.head <= 0) || (minMax.tail >= d)) { if (TRACE_TEST) System.out.println("testCCondition hit"); return true; diff --git a/src/eva2/server/go/populations/Population.java b/src/eva2/server/go/populations/Population.java index 24cfa124..1fd848c0 100644 --- a/src/eva2/server/go/populations/Population.java +++ b/src/eva2/server/go/populations/Population.java @@ -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 sortedArr = null; - transient protected InterfacePopulationChangedEventListener m_Listener = null; + transient private ArrayList listeners = null; +// transient protected InterfacePopulationChangedEventListener m_Listener = null; // the evaluation interval at which listeners are notified protected int notifyEvalInterval = 0; protected HashMap 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 m_History = new ArrayList(); @@ -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)population.listeners.clone(); + else listeners = null; if (population.additionalPopData != null) { additionalPopData = new HashMap(); Set 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(); 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)(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(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??? */ diff --git a/src/eva2/server/go/problems/AbstractOptimizationProblem.java b/src/eva2/server/go/problems/AbstractOptimizationProblem.java index 5b025183..f171bc81 100644 --- a/src/eva2/server/go/problems/AbstractOptimizationProblem.java +++ b/src/eva2/server/go/problems/AbstractOptimizationProblem.java @@ -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; diff --git a/src/eva2/server/go/problems/InterfaceOptimizationProblem.java b/src/eva2/server/go/problems/InterfaceOptimizationProblem.java index 2f275b0c..d01da3e9 100644 --- a/src/eva2/server/go/problems/InterfaceOptimizationProblem.java +++ b/src/eva2/server/go/problems/InterfaceOptimizationProblem.java @@ -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 diff --git a/src/eva2/server/go/strategies/CHCAdaptiveSearchAlgorithm.java b/src/eva2/server/go/strategies/CHCAdaptiveSearchAlgorithm.java index e477ed66..478f8897 100644 --- a/src/eva2/server/go/strategies/CHCAdaptiveSearchAlgorithm.java +++ b/src/eva2/server/go/strategies/CHCAdaptiveSearchAlgorithm.java @@ -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 diff --git a/src/eva2/server/go/strategies/ClusterBasedNichingEA.java b/src/eva2/server/go/strategies/ClusterBasedNichingEA.java index 3ff4d518..c41cb8e6 100644 --- a/src/eva2/server/go/strategies/ClusterBasedNichingEA.java +++ b/src/eva2/server/go/strategies/ClusterBasedNichingEA.java @@ -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); } /** diff --git a/src/eva2/server/go/strategies/ClusteringHillClimbing.java b/src/eva2/server/go/strategies/ClusteringHillClimbing.java index f424865e..c19b808f 100644 --- a/src/eva2/server/go/strategies/ClusteringHillClimbing.java +++ b/src/eva2/server/go/strategies/ClusteringHillClimbing.java @@ -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); diff --git a/src/eva2/server/go/strategies/DifferentialEvolution.java b/src/eva2/server/go/strategies/DifferentialEvolution.java index 54e38c8f..2008a24b 100644 --- a/src/eva2/server/go/strategies/DifferentialEvolution.java +++ b/src/eva2/server/go/strategies/DifferentialEvolution.java @@ -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); } /** diff --git a/src/eva2/server/go/strategies/DynamicParticleSwarmOptimization.java b/src/eva2/server/go/strategies/DynamicParticleSwarmOptimization.java index 10c97aba..f9acae49 100644 --- a/src/eva2/server/go/strategies/DynamicParticleSwarmOptimization.java +++ b/src/eva2/server/go/strategies/DynamicParticleSwarmOptimization.java @@ -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]); } } diff --git a/src/eva2/server/go/strategies/EvolutionStrategies.java b/src/eva2/server/go/strategies/EvolutionStrategies.java index cc888b95..99d259c4 100644 --- a/src/eva2/server/go/strategies/EvolutionStrategies.java +++ b/src/eva2/server/go/strategies/EvolutionStrategies.java @@ -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 } /** diff --git a/src/eva2/server/go/strategies/EvolutionStrategyIPOP.java b/src/eva2/server/go/strategies/EvolutionStrategyIPOP.java index f0cf6858..d4072f9b 100644 --- a/src/eva2/server/go/strategies/EvolutionStrategyIPOP.java +++ b/src/eva2/server/go/strategies/EvolutionStrategyIPOP.java @@ -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 _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 _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); } diff --git a/src/eva2/server/go/strategies/EvolutionaryProgramming.java b/src/eva2/server/go/strategies/EvolutionaryProgramming.java index f9cfe261..5359849d 100644 --- a/src/eva2/server/go/strategies/EvolutionaryProgramming.java +++ b/src/eva2/server/go/strategies/EvolutionaryProgramming.java @@ -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 diff --git a/src/eva2/server/go/strategies/FloodAlgorithm.java b/src/eva2/server/go/strategies/FloodAlgorithm.java index 1df5152f..aff76d6b 100644 --- a/src/eva2/server/go/strategies/FloodAlgorithm.java +++ b/src/eva2/server/go/strategies/FloodAlgorithm.java @@ -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 diff --git a/src/eva2/server/go/strategies/GeneticAlgorithm.java b/src/eva2/server/go/strategies/GeneticAlgorithm.java index 20bd3286..257bbbef 100644 --- a/src/eva2/server/go/strategies/GeneticAlgorithm.java +++ b/src/eva2/server/go/strategies/GeneticAlgorithm.java @@ -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 diff --git a/src/eva2/server/go/strategies/GradientDescentAlgorithm.java b/src/eva2/server/go/strategies/GradientDescentAlgorithm.java index d8f2cd89..80ae00f4 100644 --- a/src/eva2/server/go/strategies/GradientDescentAlgorithm.java +++ b/src/eva2/server/go/strategies/GradientDescentAlgorithm.java @@ -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; diff --git a/src/eva2/server/go/strategies/HillClimbing.java b/src/eva2/server/go/strategies/HillClimbing.java index 8598ad2c..4a9cd790 100644 --- a/src/eva2/server/go/strategies/HillClimbing.java +++ b/src/eva2/server/go/strategies/HillClimbing.java @@ -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() { diff --git a/src/eva2/server/go/strategies/IslandModelEA.java b/src/eva2/server/go/strategies/IslandModelEA.java index 177f5263..a0a55345 100644 --- a/src/eva2/server/go/strategies/IslandModelEA.java +++ b/src/eva2/server/go/strategies/IslandModelEA.java @@ -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 diff --git a/src/eva2/server/go/strategies/MemeticAlgorithm.java b/src/eva2/server/go/strategies/MemeticAlgorithm.java index d264d4b9..1b62e4f0 100644 --- a/src/eva2/server/go/strategies/MemeticAlgorithm.java +++ b/src/eva2/server/go/strategies/MemeticAlgorithm.java @@ -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); } /** diff --git a/src/eva2/server/go/strategies/MonteCarloSearch.java b/src/eva2/server/go/strategies/MonteCarloSearch.java index 5bd13dc6..4ab5e966 100644 --- a/src/eva2/server/go/strategies/MonteCarloSearch.java +++ b/src/eva2/server/go/strategies/MonteCarloSearch.java @@ -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); } diff --git a/src/eva2/server/go/strategies/MultiObjectiveEA.java b/src/eva2/server/go/strategies/MultiObjectiveEA.java index 174a5132..497d27c9 100644 --- a/src/eva2/server/go/strategies/MultiObjectiveEA.java +++ b/src/eva2/server/go/strategies/MultiObjectiveEA.java @@ -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) { diff --git a/src/eva2/server/go/strategies/ParticleSwarmOptimization.java b/src/eva2/server/go/strategies/ParticleSwarmOptimization.java index 32e7a28a..c0cee616 100644 --- a/src/eva2/server/go/strategies/ParticleSwarmOptimization.java +++ b/src/eva2/server/go/strategies/ParticleSwarmOptimization.java @@ -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