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:
parent
137ef279ac
commit
bcdc7d254e
@ -21,9 +21,16 @@ import java.awt.event.ActionEvent;
|
|||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPanel;
|
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 eva2.server.modules.ModuleAdapter;
|
||||||
|
|
||||||
import wsi.ra.jproxy.RMIProxyLocal;
|
import wsi.ra.jproxy.RMIProxyLocal;
|
||||||
@ -44,6 +51,7 @@ public class JModuleGeneralPanel implements RemoteStateListener, Serializable {
|
|||||||
private JButton m_actStop;
|
private JButton m_actStop;
|
||||||
// private JButton m_actExitMod;
|
// private JButton m_actExitMod;
|
||||||
private JButton m_JHelpButton;
|
private JButton m_JHelpButton;
|
||||||
|
private JButton m_ShowSolButton;
|
||||||
private JPanel m_Panel;
|
private JPanel m_Panel;
|
||||||
private String m_HelperFileName;
|
private String m_HelperFileName;
|
||||||
|
|
||||||
@ -90,10 +98,10 @@ public class JModuleGeneralPanel implements RemoteStateListener, Serializable {
|
|||||||
m_RunButton.setEnabled(false);
|
m_RunButton.setEnabled(false);
|
||||||
m_PPButton.setEnabled(false);
|
m_PPButton.setEnabled(false);
|
||||||
// m_RestartButton.setEnabled(false);
|
// m_RestartButton.setEnabled(false);
|
||||||
m_JHelpButton.setEnabled(true);
|
// m_JHelpButton.setEnabled(true);
|
||||||
} catch (Exception ee) {
|
} catch (Exception ee) {
|
||||||
ee.printStackTrace();
|
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){
|
public void actionPerformed(ActionEvent e){
|
||||||
try {
|
try {
|
||||||
m_Adapter.stopOpt(); // this means user break
|
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);
|
// m_RunButton.setEnabled(false);
|
||||||
} catch (Exception ee) {
|
} catch (Exception ee) {
|
||||||
ee.printStackTrace();
|
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_PPButton.setEnabled(m_StateRunning && m_Adapter.hasPostProcessing());
|
||||||
m_Panel.add(m_PPButton);
|
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= new JButton("Description");
|
||||||
m_JHelpButton.setToolTipText("Description of the current optimization algorithm.");
|
m_JHelpButton.setToolTipText("Description of the current optimization algorithm.");
|
||||||
m_JHelpButton.addActionListener(new ActionListener() {
|
m_JHelpButton.addActionListener(new ActionListener() {
|
||||||
@ -162,9 +205,6 @@ public class JModuleGeneralPanel implements RemoteStateListener, Serializable {
|
|||||||
);
|
);
|
||||||
m_Panel.add(m_JHelpButton);
|
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) {
|
public void performedStart(String infoString) {
|
||||||
|
m_ShowSolButton.setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -199,7 +240,22 @@ public class JModuleGeneralPanel implements RemoteStateListener, Serializable {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void setHelperFilename (String s) {
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -555,41 +555,43 @@ public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopu
|
|||||||
* @param name Could be used to indicate the nature of the event.
|
* @param name Could be used to indicate the nature of the event.
|
||||||
*/
|
*/
|
||||||
public void registerPopulationStateChanged(Object source, String name) {
|
public void registerPopulationStateChanged(Object source, String name) {
|
||||||
Population population = ((InterfaceOptimizer)source).getPopulation();
|
if (name.equals(Population.nextGenerationPerformed)) {
|
||||||
double x = 100/this.m_MultiRuns;
|
Population population = ((InterfaceOptimizer)source).getPopulation();
|
||||||
if (this.m_GO.getTerminator() instanceof EvaluationTerminator) {
|
double x = 100/this.m_MultiRuns;
|
||||||
double y = x/(double)((EvaluationTerminator)this.m_GO.getTerminator()).getFitnessCalls();
|
if (this.m_GO.getTerminator() instanceof EvaluationTerminator) {
|
||||||
currentProgress = (int)(this.currentRun * x + population.getFunctionCalls()*y);
|
double y = x/(double)((EvaluationTerminator)this.m_GO.getTerminator()).getFitnessCalls();
|
||||||
} else {
|
currentProgress = (int)(this.currentRun * x + population.getFunctionCalls()*y);
|
||||||
currentProgress = (int)(this.currentRun * x);
|
} else {
|
||||||
}
|
currentProgress = (int)(this.currentRun * x);
|
||||||
updateStatus(currentProgress);
|
}
|
||||||
|
updateStatus(currentProgress);
|
||||||
|
|
||||||
// data to be stored in file
|
// data to be stored in file
|
||||||
double tmpd = 0;
|
double tmpd = 0;
|
||||||
StringBuffer tmpLine = new StringBuffer("");
|
StringBuffer tmpLine = new StringBuffer("");
|
||||||
tmpLine.append(population.getFunctionCalls());
|
tmpLine.append(population.getFunctionCalls());
|
||||||
tmpLine.append("\t");
|
tmpLine.append("\t");
|
||||||
tmpLine.append(population.getBestEAIndividual().getFitness(0));
|
tmpLine.append(population.getBestEAIndividual().getFitness(0));
|
||||||
tmpLine.append("\t");
|
tmpLine.append("\t");
|
||||||
for (int i = 0; i < population.size(); i++) tmpd += ((AbstractEAIndividual)population.get(i)).getFitness(0)/(double)population.size();
|
for (int i = 0; i < population.size(); i++) tmpd += ((AbstractEAIndividual)population.get(i)).getFitness(0)/(double)population.size();
|
||||||
tmpLine.append("\t");
|
tmpLine.append("\t");
|
||||||
tmpLine.append(tmpd);
|
tmpLine.append(tmpd);
|
||||||
tmpLine.append("\t");
|
tmpLine.append("\t");
|
||||||
tmpLine.append(population.getWorstEAIndividual().getFitness(0));
|
tmpLine.append(population.getWorstEAIndividual().getFitness(0));
|
||||||
//tmpLine.append("\t");
|
//tmpLine.append("\t");
|
||||||
//tmpLine.append(this.m_GO.getProblem().getAdditionalFileStringValue(population));
|
//tmpLine.append(this.m_GO.getProblem().getAdditionalFileStringValue(population));
|
||||||
this.writeToFile(tmpLine.toString());
|
this.writeToFile(tmpLine.toString());
|
||||||
|
|
||||||
Double[] tmpData = new Double[2];
|
Double[] tmpData = new Double[2];
|
||||||
tmpData[0] = new Double(population.getFunctionCalls());
|
tmpData[0] = new Double(population.getFunctionCalls());
|
||||||
// instead of adding simply the best fitness value i'll ask the problem what to show
|
// instead of adding simply the best fitness value i'll ask the problem what to show
|
||||||
tmpData[1] = this.m_GO.getProblem().getDoublePlotValue(population);
|
tmpData[1] = this.m_GO.getProblem().getDoublePlotValue(population);
|
||||||
if (this.m_Plot != null) {
|
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);
|
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);
|
else this.m_Plot.setConnectedPoint(tmpData[0].doubleValue(), tmpData[1].doubleValue(), 1000+this.currentRun);
|
||||||
}
|
}
|
||||||
this.m_TmpData.add(tmpData);
|
this.m_TmpData.add(tmpData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method writes Data to file.
|
/** This method writes Data to file.
|
||||||
|
@ -498,19 +498,21 @@ public class MOCCOStandalone implements InterfaceGOStandalone, InterfacePopulati
|
|||||||
* @param name Could be used to indicate the nature of the event.
|
* @param name Could be used to indicate the nature of the event.
|
||||||
*/
|
*/
|
||||||
public void registerPopulationStateChanged(Object source, String name) {
|
public void registerPopulationStateChanged(Object source, String name) {
|
||||||
int currentProgress;
|
int currentProgress;
|
||||||
if (this.m_State.isVisible) {
|
if (name.equals(Population.nextGenerationPerformed)) {
|
||||||
Population population = ((InterfaceOptimizer)source).getPopulation();
|
if (this.m_State.isVisible) {
|
||||||
double x = 100;
|
Population population = ((InterfaceOptimizer)source).getPopulation();
|
||||||
if (this.m_State.m_Terminator instanceof EvaluationTerminator) {
|
double x = 100;
|
||||||
double y = x/(double)((EvaluationTerminator)this.m_State.m_Terminator).getFitnessCalls();
|
if (this.m_State.m_Terminator instanceof EvaluationTerminator) {
|
||||||
currentProgress = (int)(population.getFunctionCalls()*y);
|
double y = x/(double)((EvaluationTerminator)this.m_State.m_Terminator).getFitnessCalls();
|
||||||
} else {
|
currentProgress = (int)(population.getFunctionCalls()*y);
|
||||||
currentProgress = (int)(0);
|
} else {
|
||||||
}
|
currentProgress = (int)(0);
|
||||||
updateStatus("Optimizing...",currentProgress);
|
}
|
||||||
} else {
|
updateStatus("Optimizing...",currentProgress);
|
||||||
// perhaps i could write it to file!?
|
} else {
|
||||||
}
|
// perhaps i could write it to file!?
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -749,7 +749,7 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
|
|||||||
* @param name The identifying name.
|
* @param name The identifying name.
|
||||||
* @param obj The object that is to be stored.
|
* @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);
|
m_dataHash.put(name, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ public class ArchivingNSGAII extends ArchivingNSGA implements java.io.Serializab
|
|||||||
tmpNonDom = new Population();
|
tmpNonDom = new Population();
|
||||||
for (int i = 0; i < tmpPop.size(); i++) {
|
for (int i = 0; i < tmpPop.size(); i++) {
|
||||||
if (this.isDominant((AbstractEAIndividual) tmpPop.get(i), tmpPop)) {
|
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));
|
tmpDom.add(tmpPop.get(i));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -130,7 +130,7 @@ public class ArchivingNSGAII extends ArchivingNSGA implements java.io.Serializab
|
|||||||
System.out.println("Problem NSGA II at level " + level + ".");
|
System.out.println("Problem NSGA II at level " + level + ".");
|
||||||
tmpDom.addPopulation(tmpNonDom);
|
tmpDom.addPopulation(tmpNonDom);
|
||||||
for (int i = 0; i < tmpDom.size(); i++)
|
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();
|
tmpPop.clear();
|
||||||
// System.out.println(""+tmpPop.getStringRepresentation());
|
// System.out.println(""+tmpPop.getStringRepresentation());
|
||||||
// tmpPop.removeDoubleInstancesUsingFitness();
|
// tmpPop.removeDoubleInstancesUsingFitness();
|
||||||
@ -158,7 +158,7 @@ public class ArchivingNSGAII extends ArchivingNSGA implements java.io.Serializab
|
|||||||
}
|
}
|
||||||
hyperCube = heidi.calculateHyperCubeVolumes(fitness);
|
hyperCube = heidi.calculateHyperCubeVolumes(fitness);
|
||||||
for (int j = 0; j < fronts[i].size(); j++) {
|
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]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -249,8 +249,8 @@ public class ArchivingPESAII extends AbstractArchiving implements java.io.Serial
|
|||||||
for (int j = 0; j < coll.size(); j++) {
|
for (int j = 0; j < coll.size(); j++) {
|
||||||
result[((Integer)coll.get(j)).intValue()] = coll.size();
|
result[((Integer)coll.get(j)).intValue()] = coll.size();
|
||||||
tmpIndy = (AbstractEAIndividual)pop.get(((Integer)coll.get(j)).intValue());
|
tmpIndy = (AbstractEAIndividual)pop.get(((Integer)coll.get(j)).intValue());
|
||||||
tmpIndy.SetData("SqueezeFactor", new Integer(coll.size()));
|
tmpIndy.putData("SqueezeFactor", new Integer(coll.size()));
|
||||||
tmpIndy.SetData("GridBox", curGrid);
|
tmpIndy.putData("GridBox", curGrid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -512,8 +512,8 @@ public class ArchivingSPEAII extends AbstractArchiving implements java.io.Serial
|
|||||||
for (int i = 0; i < SPEAResult.length; i++) {
|
for (int i = 0; i < SPEAResult.length; i++) {
|
||||||
if (1/(2+D[i]) >= 1) System.out.println("d " +1/(2+D[i]));
|
if (1/(2+D[i]) >= 1) System.out.println("d " +1/(2+D[i]));
|
||||||
SPEAResult[i] = SPEAFitness[i] + (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)).putData("RawFit", new Double(SPEAFitness[i]));
|
||||||
((AbstractEAIndividual)pop.get(i)).SetData("SPEAFit", new Double(SPEAResult[i]));
|
((AbstractEAIndividual)pop.get(i)).putData("SPEAFit", new Double(SPEAResult[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.m_Debug && this.m_Plot != null) {
|
if (this.m_Debug && this.m_Plot != null) {
|
||||||
|
@ -44,7 +44,7 @@ public class RemoveSurplusIndividualsStaticHyperCube extends RemoveSurplusIndivi
|
|||||||
}
|
}
|
||||||
space = this.calculateHyperCubeVolumes(fitness);
|
space = this.calculateHyperCubeVolumes(fitness);
|
||||||
for (int i = 0; i < archive.size(); i++) {
|
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()) {
|
while(archive.size() > archive.getPopulationSize()) {
|
||||||
|
@ -51,7 +51,7 @@ public class MOSODynamicallyWeightedFitness implements InterfaceMOSOConverter, j
|
|||||||
double[] weights;
|
double[] weights;
|
||||||
|
|
||||||
tmpFit = indy.getFitness();
|
tmpFit = indy.getFitness();
|
||||||
indy.SetData("MOFitness", tmpFit);
|
indy.putData("MOFitness", tmpFit);
|
||||||
weights = new double[tmpFit.length];
|
weights = new double[tmpFit.length];
|
||||||
|
|
||||||
// calculate the dynamic weights
|
// calculate the dynamic weights
|
||||||
|
@ -53,7 +53,7 @@ public class MOSOEpsilonConstraint implements InterfaceMOSOConverter, java.io.Se
|
|||||||
double[] tmpFit;
|
double[] tmpFit;
|
||||||
|
|
||||||
tmpFit = indy.getFitness();
|
tmpFit = indy.getFitness();
|
||||||
indy.SetData("MOFitness", tmpFit);
|
indy.putData("MOFitness", tmpFit);
|
||||||
resultFit[0] = tmpFit[this.m_EpsilonConstraint.m_OptimizeObjective];
|
resultFit[0] = tmpFit[this.m_EpsilonConstraint.m_OptimizeObjective];
|
||||||
for (int i = 0; i < this.m_EpsilonConstraint.m_TargetValue.length; i++) {
|
for (int i = 0; i < this.m_EpsilonConstraint.m_TargetValue.length; i++) {
|
||||||
if (i != this.m_EpsilonConstraint.m_OptimizeObjective) {
|
if (i != this.m_EpsilonConstraint.m_OptimizeObjective) {
|
||||||
|
@ -56,7 +56,7 @@ public class MOSOEpsilonThreshold implements InterfaceMOSOConverter, java.io.Ser
|
|||||||
double[] tmpFit;
|
double[] tmpFit;
|
||||||
|
|
||||||
tmpFit = indy.getFitness();
|
tmpFit = indy.getFitness();
|
||||||
indy.SetData("MOFitness", tmpFit);
|
indy.putData("MOFitness", tmpFit);
|
||||||
for (int i = 0; i < tmpFit.length; i++) {
|
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]).isNaN()) System.out.println("Fitness is NaN");
|
||||||
if (new Double(tmpFit[i]).isInfinite()) System.out.println("Fitness is Infinite");
|
if (new Double(tmpFit[i]).isInfinite()) System.out.println("Fitness is Infinite");
|
||||||
|
@ -50,7 +50,7 @@ public class MOSOGoalProgramming implements InterfaceMOSOConverter, java.io.Seri
|
|||||||
double[] tmpFit;
|
double[] tmpFit;
|
||||||
|
|
||||||
tmpFit = indy.getFitness();
|
tmpFit = indy.getFitness();
|
||||||
indy.SetData("MOFitness", tmpFit);
|
indy.putData("MOFitness", tmpFit);
|
||||||
resultFit[0] = 0;
|
resultFit[0] = 0;
|
||||||
for (int i = 0; (i < this.m_Goals.m_DoubleArray.length) && (i < tmpFit.length) ; i++)
|
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];
|
resultFit[0] += tmpFit[i]-this.m_Goals.m_DoubleArray[i];
|
||||||
|
@ -52,7 +52,7 @@ public class MOSOLpMetric implements InterfaceMOSOConverter, java.io.Serializabl
|
|||||||
double[] tmpFit;
|
double[] tmpFit;
|
||||||
|
|
||||||
tmpFit = indy.getFitness();
|
tmpFit = indy.getFitness();
|
||||||
indy.SetData("MOFitness", tmpFit);
|
indy.putData("MOFitness", tmpFit);
|
||||||
if (m_P >= 1) {
|
if (m_P >= 1) {
|
||||||
// standard Lp Metric
|
// standard Lp Metric
|
||||||
resultFit[0] = 0;
|
resultFit[0] = 0;
|
||||||
|
@ -41,7 +41,7 @@ public class MOSOMOGARankBased implements InterfaceMOSOConverter, java.io.Serial
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < pop.size(); i++) {
|
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++) {
|
for (int i = 0; i < pop.size(); i++) {
|
||||||
this.convertSingleIndividual((AbstractEAIndividual)pop.get(i));
|
this.convertSingleIndividual((AbstractEAIndividual)pop.get(i));
|
||||||
@ -56,7 +56,7 @@ public class MOSOMOGARankBased implements InterfaceMOSOConverter, java.io.Serial
|
|||||||
double[] tmpFit;
|
double[] tmpFit;
|
||||||
|
|
||||||
tmpFit = indy.getFitness();
|
tmpFit = indy.getFitness();
|
||||||
indy.SetData("MOFitness", tmpFit);
|
indy.putData("MOFitness", tmpFit);
|
||||||
resultFit[0] = ((Integer)indy.getData("MOGARank")).doubleValue();
|
resultFit[0] = ((Integer)indy.getData("MOGARank")).doubleValue();
|
||||||
indy.SetFitness(resultFit);
|
indy.SetFitness(resultFit);
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ public class MOSOMaxiMin implements InterfaceMOSOConverter, java.io.Serializable
|
|||||||
// write the result to the individuals
|
// write the result to the individuals
|
||||||
tmpIndy = (AbstractEAIndividual) pop.get(i);
|
tmpIndy = (AbstractEAIndividual) pop.get(i);
|
||||||
tmpFit = tmpIndy.getFitness();
|
tmpFit = tmpIndy.getFitness();
|
||||||
tmpIndy.SetData("MOFitness", tmpFit);
|
tmpIndy.putData("MOFitness", tmpFit);
|
||||||
resultFit = new double[1];
|
resultFit = new double[1];
|
||||||
resultFit[0] = result[i];
|
resultFit[0] = result[i];
|
||||||
tmpIndy.SetFitness(resultFit);
|
tmpIndy.SetFitness(resultFit);
|
||||||
@ -107,7 +107,7 @@ public class MOSOMaxiMin implements InterfaceMOSOConverter, java.io.Serializable
|
|||||||
double[] tmpFit;
|
double[] tmpFit;
|
||||||
|
|
||||||
tmpFit = indy.getFitness();
|
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.");
|
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)];
|
resultFit[0] = tmpFit[RNG.randomInt(0, tmpFit.length)];
|
||||||
indy.SetFitness(resultFit);
|
indy.SetFitness(resultFit);
|
||||||
|
@ -41,7 +41,7 @@ public class MOSONoConvert implements InterfaceMOSOConverter, java.io.Serializab
|
|||||||
double[] tmpFit;
|
double[] tmpFit;
|
||||||
|
|
||||||
tmpFit = indy.getFitness();
|
tmpFit = indy.getFitness();
|
||||||
indy.SetData("MOFitness", tmpFit);
|
indy.putData("MOFitness", tmpFit);
|
||||||
// resultFit[0] = tmpFit[RNG.randomInt(0, tmpFit.length)];
|
// resultFit[0] = tmpFit[RNG.randomInt(0, tmpFit.length)];
|
||||||
// indy.SetFitness(resultFit);
|
// indy.SetFitness(resultFit);
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ public class MOSORandomChoice implements InterfaceMOSOConverter, java.io.Serial
|
|||||||
double[] tmpFit;
|
double[] tmpFit;
|
||||||
|
|
||||||
tmpFit = indy.getFitness();
|
tmpFit = indy.getFitness();
|
||||||
indy.SetData("MOFitness", tmpFit);
|
indy.putData("MOFitness", tmpFit);
|
||||||
resultFit[0] = tmpFit[RNG.randomInt(0, tmpFit.length-1)];
|
resultFit[0] = tmpFit[RNG.randomInt(0, tmpFit.length-1)];
|
||||||
indy.SetFitness(resultFit);
|
indy.SetFitness(resultFit);
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ public class MOSORandomWeight implements InterfaceMOSOConverter, java.io.Seriali
|
|||||||
double sum = 0;
|
double sum = 0;
|
||||||
|
|
||||||
tmpFit = indy.getFitness();
|
tmpFit = indy.getFitness();
|
||||||
indy.SetData("MOFitness", tmpFit);
|
indy.putData("MOFitness", tmpFit);
|
||||||
tmpWeight = new double[tmpFit.length];
|
tmpWeight = new double[tmpFit.length];
|
||||||
for (int i = 0; i < tmpWeight.length; i++) {
|
for (int i = 0; i < tmpWeight.length; i++) {
|
||||||
tmpWeight[i] = RNG.randomDouble(0,1);
|
tmpWeight[i] = RNG.randomDouble(0,1);
|
||||||
|
@ -45,7 +45,7 @@ public class MOSORankbased implements InterfaceMOSOConverter, java.io.Serializab
|
|||||||
double[] tmpFit;
|
double[] tmpFit;
|
||||||
|
|
||||||
tmpFit = indy.getFitness();
|
tmpFit = indy.getFitness();
|
||||||
indy.SetData("MOFitness", tmpFit);
|
indy.putData("MOFitness", tmpFit);
|
||||||
resultFit[0] = ((Integer)indy.getData("ParetoLevel")).doubleValue();
|
resultFit[0] = ((Integer)indy.getData("ParetoLevel")).doubleValue();
|
||||||
indy.SetFitness(resultFit);
|
indy.SetFitness(resultFit);
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ public class MOSOUtilityFunction implements InterfaceMOSOConverter, java.io.Seri
|
|||||||
double[] tmpFit;
|
double[] tmpFit;
|
||||||
|
|
||||||
tmpFit = indy.getFitness();
|
tmpFit = indy.getFitness();
|
||||||
indy.SetData("MOFitness", tmpFit);
|
indy.putData("MOFitness", tmpFit);
|
||||||
resultFit[0] = 0;
|
resultFit[0] = 0;
|
||||||
|
|
||||||
/**********************************************************************************************
|
/**********************************************************************************************
|
||||||
|
@ -51,7 +51,7 @@ public class MOSOWeightedFitness implements InterfaceMOSOConverter, java.io.Seri
|
|||||||
double[] tmpFit;
|
double[] tmpFit;
|
||||||
|
|
||||||
tmpFit = indy.getFitness();
|
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++)
|
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];
|
resultFit[0] += tmpFit[i]*this.m_Weights.m_DoubleArray[i];
|
||||||
indy.SetFitness(resultFit);
|
indy.SetFitness(resultFit);
|
||||||
|
@ -55,7 +55,7 @@ public class MOSOWeightedLPTchebycheff implements InterfaceMOSOConverter, java.i
|
|||||||
double[] tmpFit;
|
double[] tmpFit;
|
||||||
|
|
||||||
tmpFit = indy.getFitness();
|
tmpFit = indy.getFitness();
|
||||||
indy.SetData("MOFitness", tmpFit);
|
indy.putData("MOFitness", tmpFit);
|
||||||
resultFit[0] = 0;
|
resultFit[0] = 0;
|
||||||
for (int i = 0; i < tmpFit.length; i++) {
|
for (int i = 0; i < tmpFit.length; i++) {
|
||||||
if (this.m_WLPT.m_P == 0) {
|
if (this.m_WLPT.m_P == 0) {
|
||||||
|
@ -8,68 +8,230 @@ import wsi.ra.math.Jama.EigenvalueDecomposition;
|
|||||||
import wsi.ra.math.Jama.Matrix;
|
import wsi.ra.math.Jama.Matrix;
|
||||||
import eva2.gui.BeanInspector;
|
import eva2.gui.BeanInspector;
|
||||||
import eva2.gui.GenericObjectEditor;
|
import eva2.gui.GenericObjectEditor;
|
||||||
|
import eva2.server.go.InterfacePopulationChangedEventListener;
|
||||||
import eva2.server.go.enums.ESMutationInitialSigma;
|
import eva2.server.go.enums.ESMutationInitialSigma;
|
||||||
import eva2.server.go.individuals.AbstractEAIndividual;
|
import eva2.server.go.individuals.AbstractEAIndividual;
|
||||||
import eva2.server.go.individuals.InterfaceDataTypeDouble;
|
import eva2.server.go.individuals.InterfaceDataTypeDouble;
|
||||||
import eva2.server.go.populations.Population;
|
import eva2.server.go.populations.Population;
|
||||||
import eva2.server.go.problems.InterfaceOptimizationProblem;
|
import eva2.server.go.problems.InterfaceOptimizationProblem;
|
||||||
|
import eva2.server.go.strategies.EvolutionStrategies;
|
||||||
import eva2.tools.EVAERROR;
|
import eva2.tools.EVAERROR;
|
||||||
import eva2.tools.Mathematics;
|
import eva2.tools.Mathematics;
|
||||||
import eva2.tools.Pair;
|
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:
|
* 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
|
* - http://www.bionik.tu-berlin.de/user/niko/cmaesintro.html
|
||||||
* - N.Hansen & S.Kern 2004: Evaluating the CMA Evolution Strategy on Multimodal Test Functions.
|
* - N.Hansen & S.Kern 2004: Evaluating the CMA Evolution Strategy on Multimodal Test Functions.
|
||||||
* Parallel Problem Solving from Nature 2004.
|
* 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
|
* @author mkron
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class MutateESRankMuCMA implements InterfaceMutationGenerational, Serializable {
|
public class MutateESRankMuCMA implements InterfaceMutationGenerational, Serializable {
|
||||||
int dim;
|
// int dim;
|
||||||
private double c_c, expRandStepLen;
|
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 ESMutationInitialSigma initializeSig = ESMutationInitialSigma.avgInitialDistance;
|
||||||
private double userDefInitSig = 0.2;
|
private double userDefInitSig = 0.2;
|
||||||
private static double firstSigma = -1.;
|
public static final String cmaParamsKey = "RankMuCMAParameters";
|
||||||
private static double sigma;
|
|
||||||
private static double d_sig, c_sig;
|
public static boolean TRACE_1 = false;
|
||||||
private static double[] meanX, pathC, pathS, eigenvalues;
|
public static boolean TRACE_2 = false;
|
||||||
private static double[] weights = null;
|
public static boolean TRACE_TEST = false;
|
||||||
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 MutateESRankMuCMA() {
|
public MutateESRankMuCMA() {
|
||||||
firstAdaptionDone = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MutateESRankMuCMA(MutateESRankMuCMA mutator) {
|
public MutateESRankMuCMA(MutateESRankMuCMA mutator) {
|
||||||
this.c_c = mutator.c_c;
|
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.expRandStepLen = mutator.expRandStepLen;
|
||||||
this.dim = mutator.dim;
|
|
||||||
this.initializeSig = mutator.initializeSig;
|
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() {
|
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.
|
* 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
|
* @param initGen
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -89,12 +252,20 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
|
|||||||
//return initGen.getPopulationMeasures(null)[0]*getAvgRange();
|
//return initGen.getPopulationMeasures(null)[0]*getAvgRange();
|
||||||
// use euclidian measures without normation and scaling
|
// use euclidian measures without normation and scaling
|
||||||
return initGen.getPopulationMeasures(null)[0];
|
return initGen.getPopulationMeasures(null)[0];
|
||||||
case halfRange: return getAvgRange()/2.;
|
//case halfRange: return getAvgRange(range)/2.;
|
||||||
case userDefined: return userDefInitSig ;
|
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) {
|
public void adaptAfterSelection(Population oldGen, Population selectedP) {
|
||||||
Population selectedSorted = selectedP.getSortedBestFirst();
|
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.");
|
EVAERROR.errorMsgOnce("Warning: invalid mu/lambda ratio (" + mu + "/" + lambda + ") ! Setting mu to lambda/2.");
|
||||||
mu = lambda/2;
|
mu = lambda/2;
|
||||||
}
|
}
|
||||||
if (!firstAdaptionDone) {
|
CMAParamSet params;
|
||||||
initWeights(mu, lambda);
|
if (oldGen.getGeneration() <= 1) { // init new param set. At gen < 1 we shouldnt be called, but better do it once too often
|
||||||
double muEff = getMuEff(mu);
|
if (oldGen.hasData(cmaParamsKey)) params = CMAParamSet.initCMAParams((CMAParamSet)oldGen.getData(cmaParamsKey), mu, lambda, oldGen, getInitSigma(oldGen));
|
||||||
c_sig = (muEff+2)/(muEff+dim+3);
|
else params = CMAParamSet.initCMAParams(mu, lambda, oldGen, getInitSigma(oldGen));
|
||||||
// c_u_sig = Math.sqrt(c_sig * (2.-c_sig));
|
} else {
|
||||||
d_sig = c_sig+1+2*Math.max(0, Math.sqrt((muEff-1)/(dim+1)) - 1);
|
if (!oldGen.hasData(cmaParamsKey)) {
|
||||||
sigma = getInitSigma(oldGen);
|
if (oldGen.getGeneration() > 1) System.err.println("pop had no params at gen " + oldGen.getGeneration());
|
||||||
// System.out.println("INitial sigma: "+sigma);
|
params = CMAParamSet.initCMAParams(mu, lambda, oldGen, getInitSigma(oldGen));
|
||||||
firstSigma = sigma;
|
} else params = (CMAParamSet)oldGen.getData(cmaParamsKey);
|
||||||
meanX = oldGen.getCenter(); // this might be ok?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int generation = oldGen.getGeneration();
|
int generation = oldGen.getGeneration();
|
||||||
|
|
||||||
if (TRACE_1) {
|
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("newPop measures: " + BeanInspector.toString(newPop.getPopulationMeasures()));
|
||||||
System.out.println("mu_eff: " + getMuEff(mu));
|
System.out.println("mu_eff: " + CMAParamSet.getMuEff(params.weights, mu));
|
||||||
System.out.println("meanX: " + BeanInspector.toString(meanX));
|
System.out.println(params.toString());
|
||||||
System.out.println("pathC: " + BeanInspector.toString(pathC));
|
System.out.println("*********************************");
|
||||||
System.out.println("pathS: " + BeanInspector.toString(pathS));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double[] newMeanX = calcMeanX(selectedSorted);
|
double[] newMeanX = calcMeanX(params.weights, selectedSorted);
|
||||||
if (TRACE_1) System.out.println("newMeanX: " + BeanInspector.toString(newMeanX));
|
if (TRACE_1) System.out.println("newMeanX: " + BeanInspector.toString(newMeanX));
|
||||||
|
|
||||||
|
int dim=params.meanX.length;
|
||||||
double[] BDz = new double[dim];
|
double[] BDz = new double[dim];
|
||||||
for (int i=0; i<dim; i++) { /* calculate xmean and BDz~N(0,C) */
|
for (int i=0; i<dim; i++) { /* calculate xmean and BDz~N(0,C) */
|
||||||
// Eq. 4 from HK04, most right term
|
// 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));
|
// if (TRACE_2) System.out.println("BDz is " + BeanInspector.toString(BDz));
|
||||||
|
|
||||||
double[] newPathS = pathS.clone();
|
double[] newPathS = params.pathS.clone();
|
||||||
double[] newPathC = pathC.clone();
|
double[] newPathC = params.pathC.clone();
|
||||||
|
|
||||||
double[] zVect = new double[dim];
|
double[] zVect = new double[dim];
|
||||||
/* calculate z := D^(-1) * B^(-1) * BDz into artmp, we could have stored z instead */
|
/* calculate z := D^(-1) * B^(-1) * BDz into artmp, we could have stored z instead */
|
||||||
for (int i = 0; i < dim; ++i) {
|
for (int i = 0; i < dim; ++i) {
|
||||||
double sum=0.;
|
double sum=0.;
|
||||||
for (int j = 0; j < dim; ++j) {
|
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 */
|
/* cumulation for sigma (ps) using B*z */
|
||||||
for (int i = 0; i < dim; ++i) {
|
for (int i = 0; i < dim; ++i) {
|
||||||
double sum = 0.;
|
double sum = 0.;
|
||||||
for (int j = 0; j < dim; ++j) sum += mB.get(i,j) * zVect[j];
|
for (int j = 0; j < dim; ++j) sum += params.mB.get(i,j) * zVect[j];
|
||||||
newPathS[i] = (1. - getCs()) * pathS[i]
|
newPathS[i] = (1. - params.c_sig) * params.pathS[i]
|
||||||
+ Math.sqrt(getCs() * (2. - getCs())) * sum;
|
+ Math.sqrt(params.c_sig * (2. - params.c_sig)) * sum;
|
||||||
}
|
}
|
||||||
// System.out.println("pathS diff: " + BeanInspector.toString(Mathematics.vvSub(newPathS, pathS)));
|
// System.out.println("pathS diff: " + BeanInspector.toString(Mathematics.vvSub(newPathS, pathS)));
|
||||||
// System.out.println("newPathS is " + BeanInspector.toString(newPathS));
|
// System.out.println("newPathS is " + BeanInspector.toString(newPathS));
|
||||||
@ -164,12 +334,12 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
|
|||||||
double psNorm = Mathematics.norm(newPathS);
|
double psNorm = Mathematics.norm(newPathS);
|
||||||
|
|
||||||
double hsig = 0;
|
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.)) {
|
/ expRandStepLen < 1.4 + 2. / (dim + 1.)) {
|
||||||
hsig = 1;
|
hsig = 1;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < dim; ++i) {
|
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];
|
* Math.sqrt(getCc() * (2. - getCc())) * BDz[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,36 +350,39 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
|
|||||||
System.out.println("newPathS: " + BeanInspector.toString(newPathS));
|
System.out.println("newPathS: " + BeanInspector.toString(newPathS));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TRACE_1) System.out.println("Bef: C is \n" + mC.toString());
|
if (TRACE_1) System.out.println("Bef: C is \n" + params.mC.toString());
|
||||||
if (meanX == null) meanX = newMeanX;
|
if (params.meanX == null) params.meanX = newMeanX;
|
||||||
|
|
||||||
updateCov(newPathC, newMeanX, hsig, mu, selectedSorted);
|
updateCov(params, newPathC, newMeanX, hsig, mu, selectedSorted);
|
||||||
updateBD();
|
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 */
|
/* update of sigma */
|
||||||
double sigFact = Math.exp(((psNorm / expRandStepLen) - 1) * getCs()
|
double sigFact = Math.exp(((psNorm / expRandStepLen) - 1) * params.c_sig
|
||||||
/ getDamps());
|
/ params.d_sig);
|
||||||
if (Double.isInfinite(sigFact)) sigma *= 10.; // in larger search spaces sigma tends to explode after init.
|
if (Double.isInfinite(sigFact)) params.sigma *= 10.; // in larger search spaces sigma tends to explode after init.
|
||||||
else sigma *= sigFact;
|
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!");
|
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) {
|
if (TRACE_1) {
|
||||||
System.out.print("psLen=" + (psNorm) + " ");
|
System.out.print("psLen=" + (psNorm) + " ");
|
||||||
outputParams(mu);
|
outputParams(params, mu);
|
||||||
}
|
}
|
||||||
|
|
||||||
// take over data
|
// take over data
|
||||||
meanX = newMeanX;
|
params.meanX = newMeanX;
|
||||||
pathC = newPathC;
|
params.pathC = newPathC;
|
||||||
pathS = newPathS;
|
params.pathS = newPathS;
|
||||||
firstAdaptionDone = true;
|
params.firstAdaptionDone = true;
|
||||||
|
|
||||||
|
lastParams = params;
|
||||||
|
oldGen.putData(cmaParamsKey, params);
|
||||||
|
selectedP.putData(cmaParamsKey, params);
|
||||||
// if (TRACE_2) System.out.println("sampling around " + BeanInspector.toString(meanX));
|
// 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,
|
public void adaptGenerational(Population oldPop, Population selectedPop,
|
||||||
Population newPop, boolean updateSelected) {
|
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 iterations
|
||||||
* @param selected
|
* @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 */
|
/* Flat Fitness, Test if function values are identical */
|
||||||
if (iterations > 1) {
|
if (iterations > 1) {
|
||||||
// selected pop is sorted
|
// selected pop is sorted
|
||||||
if (nearlySame(selected.getEAIndividual(0).getFitness(),selected.getEAIndividual(selected.size()-1).getFitness())) {
|
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");
|
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;
|
// sigma=0.1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -243,20 +422,20 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
|
|||||||
double fac = 1.;
|
double fac = 1.;
|
||||||
double minEig = 1e-12;
|
double minEig = 1e-12;
|
||||||
double maxEig = 1e8;
|
double maxEig = 1e8;
|
||||||
if (Mathematics.max(eigenvalues) < minEig)
|
if (Mathematics.max(params.eigenvalues) < minEig)
|
||||||
fac = 1./Math.sqrt(Mathematics.max(eigenvalues));
|
fac = 1./Math.sqrt(Mathematics.max(params.eigenvalues));
|
||||||
else if (Mathematics.min(eigenvalues) > maxEig)
|
else if (Mathematics.min(params.eigenvalues) > maxEig)
|
||||||
fac = 1./Math.sqrt(Mathematics.min(eigenvalues));
|
fac = 1./Math.sqrt(Mathematics.min(params.eigenvalues));
|
||||||
|
|
||||||
if (fac != 1.) {
|
if (fac != 1.) {
|
||||||
System.err.println("Scaling by " + fac);
|
System.err.println("Scaling by " + fac);
|
||||||
sigma /= fac;
|
params.sigma /= fac;
|
||||||
for(int i = 0; i < dim; ++i) {
|
for(int i = 0; i < params.meanX.length; ++i) {
|
||||||
pathC[i] *= fac;
|
params.pathC[i] *= fac;
|
||||||
eigenvalues[i] *= fac*fac;
|
params.eigenvalues[i] *= fac*fac;
|
||||||
for (int j = 0; j <= i; ++j) {
|
for (int j = 0; j <= i; ++j) {
|
||||||
mC.set(i, j, mC.get(i,j)*fac*fac);
|
params.mC.set(i, j, params.mC.get(i,j)*fac*fac);
|
||||||
if (i!=j) mC.set(j, i, mC.get(i,j));
|
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
|
* @param i
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private double getSigma(int i) {
|
private double getSigma(CMAParamSet params, int i) {
|
||||||
return sigma;
|
return params.sigma;
|
||||||
}
|
|
||||||
|
|
||||||
private double getDamps() {
|
|
||||||
return d_sig;
|
|
||||||
}
|
}
|
||||||
|
//
|
||||||
|
// private double getDamps() {
|
||||||
|
// return d_sig;
|
||||||
|
// }
|
||||||
|
|
||||||
private double getCc() {
|
private double getCc() {
|
||||||
return c_c;
|
return c_c;
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getCs() {
|
// private double getCs() {
|
||||||
return c_sig;
|
// return c_sig;
|
||||||
}
|
// }
|
||||||
|
|
||||||
private double calcExpRandStepLen() {
|
private double calcExpRandStepLen(int dim) {
|
||||||
// scale by avg range?
|
// scale by avg range?
|
||||||
return Math.sqrt(dim)*(1.-(1./(4*dim))+(1./(21*dim*dim)));
|
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 */
|
/* 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;
|
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!) */
|
/* (only upper triangle!) */
|
||||||
/* update covariance matrix */
|
/* update covariance matrix */
|
||||||
//System.out.println("CCov " + getCCov(selected) + " Cc " + getCc() + " muCov " + getMuCov(selected));
|
//System.out.println("CCov " + getCCov(selected) + " Cc " + getCc() + " muCov " + getMuCov(selected));
|
||||||
for (int i = 0; i < dim; ++i)
|
for (int i = 0; i < dim; ++i)
|
||||||
for (int j = 0; j <= i; ++j) {
|
for (int j = 0; j <= i; ++j) {
|
||||||
// oldVal = mC.get(i,j);
|
// oldVal = mC.get(i,j);
|
||||||
newVal = (1 - getCCov(mu)) * mC.get(i,j)
|
newVal = (1 - ccv) * params.mC.get(i,j)
|
||||||
+ getCCov(mu)
|
+ ccv
|
||||||
* (1. / getMuCov(mu))
|
* (1. / mcv)
|
||||||
* (newPathC[i] * newPathC[j] + (1 - hsig) * getCc()
|
* (newPathC[i] * newPathC[j] + (1 - hsig) * getCc()
|
||||||
* (2. - getCc()) * mC.get(i,j));
|
* (2. - getCc()) * params.mC.get(i,j));
|
||||||
mC.set(i,j,newVal);
|
params.mC.set(i,j,newVal);
|
||||||
for (int k = 0; k < mu; ++k) { /*
|
for (int k = 0; k < mu; ++k) { /*
|
||||||
* additional rank mu
|
* additional rank mu
|
||||||
* update
|
* update
|
||||||
*/
|
*/
|
||||||
double[] x_k = ((InterfaceDataTypeDouble)selected.getEAIndividual(k)).getDoubleData();
|
double[] x_k = ((InterfaceDataTypeDouble)selected.getEAIndividual(k)).getDoubleData();
|
||||||
newVal = mC.get(i,j)+ getCCov(mu) * (1 - 1. / getMuCov(mu))
|
newVal = params.mC.get(i,j)+ ccv * (1 - 1. / mcv)
|
||||||
* getWeight(k) * (x_k[i] - meanX[i])
|
* params.weights[k] * (x_k[i] - params.meanX[i])
|
||||||
* (x_k[j] - meanX[j]) / (getSigma(i) * getSigma(j)); // TODO right sigmas?
|
* (x_k[j] - params.meanX[j]) / (getSigma(params, i) * getSigma(params, j)); // TODO right sigmas?
|
||||||
mC.set(i,j, newVal);
|
params.mC.set(i,j, newVal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// fill rest of C
|
// fill rest of C
|
||||||
for (int i = 0; i < dim; ++i) {
|
for (int i = 0; i < dim; ++i) {
|
||||||
for (int j = i+1; j < dim; ++j) {
|
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)) {
|
if (params.mC.get(0,1) != params.mC.get(1,0)) {
|
||||||
System.err.println("WARNING");
|
System.err.println("WARNING, C is not symmetric!");
|
||||||
}
|
}
|
||||||
// maxsqrtdiagC = Math.sqrt(math.max(math.diag(C)));
|
// maxsqrtdiagC = Math.sqrt(math.max(math.diag(C)));
|
||||||
// minsqrtdiagC = Math.sqrt(math.min(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) {
|
private double getCCov(double[] weights, int mu, int dim) {
|
||||||
// default parameter value ( HK03, sec. 2)
|
|
||||||
return getMuEff(mu);
|
|
||||||
}
|
|
||||||
|
|
||||||
private double getCCov(int mu) {
|
|
||||||
// ( HK03, sec. 2)
|
// ( HK03, sec. 2)
|
||||||
//return Math.min(1., 2*getMuEff(selected)/(dim*dim));
|
//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;
|
return ccov;
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getMuEff(int mu) {
|
private void outputParams(CMAParamSet params, int mu) {
|
||||||
double res = 0, u;
|
System.out.println("sigma=" + params.sigma + " chiN="+expRandStepLen + " cs="+params.c_sig
|
||||||
for (int i=0; i<mu;i++) {
|
+ " damps="+params.d_sig + " Cc=" + getCc() + " Ccov=" + getCCov(params.weights, mu, params.meanX.length)
|
||||||
u = getWeight(i);
|
+ " mueff=" + CMAParamSet.getMuEff(params.weights, mu) + " mucov="+CMAParamSet.getMuCov(params.weights, mu));
|
||||||
res += u*u;
|
|
||||||
}
|
|
||||||
return 1./res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void outputParams(int mu) {
|
private void updateBD(CMAParamSet params) {
|
||||||
System.out.println("sigma=" + sigma + " chiN="+expRandStepLen + " cs="+getCs()+ " damps="+getDamps() + " Cc=" + getCc() + " Ccov=" + getCCov(mu) + " mueff=" + getMuEff(mu) + " mucov="+getMuCov(mu));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateBD() {
|
|
||||||
// C=triu(C)+transpose(triu(C,1)); % enforce symmetry
|
// C=triu(C)+transpose(triu(C,1)); % enforce symmetry
|
||||||
// [B,D] = eig(C);
|
// [B,D] = eig(C);
|
||||||
// % limit condition of C to 1e14 + 1
|
// % 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
|
// D = diag(sqrt(diag(D))); % D contains standard deviations now
|
||||||
// BD = B*D; % for speed up only
|
// BD = B*D; % for speed up only
|
||||||
////////////////////////////////////////////7
|
////////////////////////////////////////////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;
|
EigenvalueDecomposition helper;
|
||||||
// this.m_Counter = 0;
|
// this.m_Counter = 0;
|
||||||
helper = new EigenvalueDecomposition(mC);
|
helper = new EigenvalueDecomposition(params.mC);
|
||||||
mB = helper.getV(); // Return the eigenvector matrix
|
params.mB = helper.getV(); // Return the eigenvector matrix
|
||||||
eigenvalues = helper.getRealEigenvalues();
|
params.eigenvalues = helper.getRealEigenvalues();
|
||||||
|
|
||||||
// double[] sqrtEig = eigenvalues.clone();
|
// double[] sqrtEig = eigenvalues.clone();
|
||||||
// for (int i = 0; i < sqrtEig.length; i++) {
|
// for (int i = 0; i < sqrtEig.length; i++) {
|
||||||
@ -417,27 +583,10 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
|
|||||||
* @param selectedPop
|
* @param selectedPop
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private double[] calcMeanX(Population selectedPop) {
|
private double[] calcMeanX(double[] weights, Population selectedPop) {
|
||||||
return selectedPop.getCenterWeighted(weights);
|
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,
|
public void crossoverOnStrategyParameters(AbstractEAIndividual indy1,
|
||||||
Population partners) {
|
Population partners) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
@ -458,29 +607,30 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
|
|||||||
|
|
||||||
public void init(AbstractEAIndividual individual,
|
public void init(AbstractEAIndividual individual,
|
||||||
InterfaceOptimizationProblem opt) {
|
InterfaceOptimizationProblem opt) {
|
||||||
// TODO recheck all this; some is handled in adaptGeneration on the first call
|
// firstAdaptionDone = false;
|
||||||
firstAdaptionDone = false;
|
// range = ((InterfaceDataTypeDouble)individual).getDoubleRange();
|
||||||
range = ((InterfaceDataTypeDouble)individual).getDoubleRange();
|
// dim = range.length;
|
||||||
dim = range.length;
|
// if (TRACE_1) System.out.println("WCMA init " + dim);
|
||||||
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_c = (4./(dim+4));
|
||||||
c_sig = Double.NaN; // mark as not yet initialized
|
expRandStepLen = calcExpRandStepLen(dim);
|
||||||
// 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();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -494,36 +644,42 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
|
|||||||
// if (TRACE) System.out.println("WCMA mutate, bef: " + BeanInspector.toString(x));
|
// if (TRACE) System.out.println("WCMA mutate, bef: " + BeanInspector.toString(x));
|
||||||
double[][] range = ((InterfaceDataTypeDouble)individual).getDoubleRange();
|
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));
|
// if (TRACE) System.out.println("WCMA mutate, aft: " + BeanInspector.toString(x));
|
||||||
} else System.err.println("Error, expecting InterfaceDataTypeDouble");
|
} else System.err.println("Error, expecting InterfaceDataTypeDouble");
|
||||||
}
|
}
|
||||||
|
|
||||||
private double[] mutate(double[] x, double[][] range, int count) {
|
private double[] mutate(CMAParamSet params, double[] x, double[][] range, int count) {
|
||||||
if (firstAdaptionDone) {
|
int dim = range.length;
|
||||||
double[] sampl = new double[x.length]; // generate scaled random vector (D * z)
|
if (params!=null && (params.firstAdaptionDone)) {
|
||||||
|
double[] sampl = new double[dim]; // generate scaled random vector (D * z)
|
||||||
for (int i = 0; i < dim; ++i) {
|
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));
|
// System.out.println("Sampling around " + BeanInspector.toString(meanX));
|
||||||
/* add mutation (sigma * B * (D*z)) */
|
/* add mutation (sigma * B * (D*z)) */
|
||||||
for (int i = 0; i < dim; ++i) {
|
for (int i = 0; i < dim; ++i) {
|
||||||
double sum = 0.;
|
double sum = 0.;
|
||||||
for (int j = 0; j < dim; ++j)
|
for (int j = 0; j < dim; ++j)
|
||||||
sum += mB.get(i,j) * sampl[j];
|
sum += params.mB.get(i,j) * sampl[j];
|
||||||
x[i] = meanX[i]+getSigma(i)*sum;
|
x[i] = params.meanX[i]+getSigma(params, i)*sum;
|
||||||
}
|
}
|
||||||
} else {
|
} 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) {
|
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;
|
if (isInRange(x, range)) return x;
|
||||||
else {
|
else {
|
||||||
if (count > 5) return repairMutation(x, range); // allow some nice tries before using brute force
|
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
|
* @return the initial sigma value actually employed
|
||||||
*/
|
*/
|
||||||
public double getFirstSigma() {
|
public double getFirstSigma(Population pop) {
|
||||||
return firstSigma;
|
return ((CMAParamSet)pop.getData(cmaParamsKey)).firstSigma;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hideHideable() {
|
public void hideHideable() {
|
||||||
@ -586,12 +742,13 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
|
|||||||
* @param tolX
|
* @param tolX
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public boolean testAllDistBelow(double tolX) {
|
public boolean testAllDistBelow(Population pop, double tolX) {
|
||||||
// if all(sigma*(max(abs(pc), sqrt(diag(C)))) < stopTolX)
|
// if all(sigma*(max(abs(pc), sqrt(diag(C)))) < stopTolX)
|
||||||
boolean res = true;
|
boolean res = true;
|
||||||
|
CMAParamSet params = (CMAParamSet)pop.getData(cmaParamsKey);
|
||||||
int i=0;
|
int i=0;
|
||||||
while (res && i<dim) {
|
while (res && i<params.meanX.length) {
|
||||||
res = res && (getSigma(i)*Math.max(Math.abs(pathC[i]), Math.sqrt(mC.get(i,i))) < tolX);
|
res = res && (getSigma(params, i)*Math.max(Math.abs(params.pathC[i]), Math.sqrt(params.mC.get(i,i))) < tolX);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (TRACE_TEST) if (res) System.out.println("testAllDistBelow hit");
|
if (TRACE_TEST) if (res) System.out.println("testAllDistBelow hit");
|
||||||
@ -604,19 +761,20 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
|
|||||||
* @param gen
|
* @param gen
|
||||||
* @return
|
* @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))))
|
// if all(xmean == xmean + 0.1*sigma*BD(:,1+floor(mod(countiter,N))))
|
||||||
// i = 1+floor(mod(countiter,N));
|
// i = 1+floor(mod(countiter,N));
|
||||||
// stopflag(end+1) = {'warnnoeffectaxis'};
|
// stopflag(end+1) = {'warnnoeffectaxis'};
|
||||||
|
CMAParamSet params = (CMAParamSet)pop.getData(cmaParamsKey);
|
||||||
|
int dim=params.meanX.length;
|
||||||
int k = gen%dim;
|
int k = gen%dim;
|
||||||
double[] ev_k = mB.getColumn(k);
|
double[] ev_k = params.mB.getColumn(k);
|
||||||
Mathematics.svMult(Math.sqrt(eigenvalues[k]), ev_k, ev_k); // this is now e_k*v_k = BD(:,...)
|
Mathematics.svMult(Math.sqrt(params.eigenvalues[k]), ev_k, ev_k); // this is now e_k*v_k = BD(:,...)
|
||||||
|
|
||||||
int i=0;
|
int i=0;
|
||||||
boolean res = true;
|
boolean res = true;
|
||||||
while (res && (i<dim)) {
|
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++;
|
i++;
|
||||||
}
|
}
|
||||||
if (TRACE_TEST) if (res) System.out.println("testNoChangeAddingDevAxis hit");
|
if (TRACE_TEST) if (res) System.out.println("testNoChangeAddingDevAxis hit");
|
||||||
@ -628,13 +786,14 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
|
|||||||
* @param d
|
* @param d
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public boolean testNoEffectCoord(double d) {
|
public boolean testNoEffectCoord(Population pop, double d) {
|
||||||
// if any(xmean == xmean + 0.2*sigma*sqrt(diag(C)))
|
// if any(xmean == xmean + 0.2*sigma*sqrt(diag(C)))
|
||||||
// stopflag(end+1) = {'warnnoeffectcoord'};
|
// stopflag(end+1) = {'warnnoeffectcoord'};
|
||||||
boolean ret = false;
|
boolean ret = false;
|
||||||
|
CMAParamSet params = (CMAParamSet)pop.getData(cmaParamsKey);
|
||||||
int i=0;
|
int i=0;
|
||||||
while ((i<dim) && !ret) {
|
while ((i<params.meanX.length) && !ret) {
|
||||||
ret = ret || (meanX[i]==(meanX[i] + d*getSigma(i)*Math.sqrt(mC.get(i, i))));
|
ret = ret || (params.meanX[i]==(params.meanX[i] + d*getSigma(params, i)*Math.sqrt(params.mC.get(i, i))));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (TRACE_TEST) if (ret) System.out.println("testNoEffectCoord hit");
|
if (TRACE_TEST) if (ret) System.out.println("testNoEffectCoord hit");
|
||||||
@ -648,10 +807,11 @@ public class MutateESRankMuCMA implements InterfaceMutationGenerational, Seriali
|
|||||||
* @param d
|
* @param d
|
||||||
* @return true, if a diagonal entry is <= 0 or >= d, else false
|
* @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)))
|
// if (min(diag(D)) <= 0) || (max(diag(D)) > 1e14*min(diag(D)))
|
||||||
// stopflag(end+1) = {'warnconditioncov'};
|
// 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 ((minMax.head <= 0) || (minMax.tail >= d)) {
|
||||||
if (TRACE_TEST) System.out.println("testCCondition hit");
|
if (TRACE_TEST) System.out.println("testCCondition hit");
|
||||||
return true;
|
return true;
|
||||||
|
@ -2,7 +2,9 @@ package eva2.server.go.populations;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.PriorityQueue;
|
import java.util.PriorityQueue;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -39,13 +41,16 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
|
|||||||
protected Population m_Archive = null;
|
protected Population m_Archive = null;
|
||||||
|
|
||||||
transient private ArrayList<AbstractEAIndividual> sortedArr = 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
|
// the evaluation interval at which listeners are notified
|
||||||
protected int notifyEvalInterval = 0;
|
protected int notifyEvalInterval = 0;
|
||||||
protected HashMap<String, Object> additionalPopData = null;
|
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;
|
boolean useHistory = false;
|
||||||
public ArrayList<AbstractEAIndividual> m_History = new ArrayList<AbstractEAIndividual>();
|
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.m_Size = population.m_Size;
|
||||||
this.useHistory = population.useHistory;
|
this.useHistory = population.useHistory;
|
||||||
this.notifyEvalInterval = population.notifyEvalInterval;
|
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) {
|
if (population.additionalPopData != null) {
|
||||||
additionalPopData = new HashMap<String, Object>();
|
additionalPopData = new HashMap<String, Object>();
|
||||||
Set<String> keys = additionalPopData.keySet();
|
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>();
|
if (additionalPopData == null) additionalPopData = new HashMap<String, Object>();
|
||||||
additionalPopData.put(key, value);
|
additionalPopData.put(key, value);
|
||||||
}
|
}
|
||||||
@ -115,6 +122,11 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
|
|||||||
else return additionalPopData.get(key);
|
else return additionalPopData.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasData(String key) {
|
||||||
|
if (additionalPopData != null) return (additionalPopData.get(key)!=null);
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
return (Object) new Population(this);
|
return (Object) new Population(this);
|
||||||
}
|
}
|
||||||
@ -130,6 +142,7 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
|
|||||||
Population res = new Population();
|
Population res = new Population();
|
||||||
res.setSameParams(this);
|
res.setSameParams(this);
|
||||||
res.copyHistAndArchive(this);
|
res.copyHistAndArchive(this);
|
||||||
|
if (additionalPopData!=null) res.additionalPopData = (HashMap<String, Object>)(additionalPopData.clone());
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,6 +160,7 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
|
|||||||
this.m_Archive.clear();
|
this.m_Archive.clear();
|
||||||
this.m_Archive.init();
|
this.m_Archive.init();
|
||||||
}
|
}
|
||||||
|
firePropertyChangedEvent(Population.populationInitialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method inits the population. Function and generation counters
|
/** This method inits the population. Function and generation counters
|
||||||
@ -215,11 +229,16 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
|
|||||||
/** Something has changed
|
/** Something has changed
|
||||||
*/
|
*/
|
||||||
protected void firePropertyChangedEvent(String name) {
|
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() {
|
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.
|
/** 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());
|
if (useHistory && (this.size() >= 1)) this.m_History.add(this.getBestEAIndividual());
|
||||||
for (int i=0; i<size(); i++) ((AbstractEAIndividual)get(i)).incrAge();
|
for (int i=0; i<size(); i++) ((AbstractEAIndividual)get(i)).incrAge();
|
||||||
this.m_Generation++;
|
this.m_Generation++;
|
||||||
firePropertyChangedEvent("NextGenerationPerformed");
|
firePropertyChangedEvent(nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method returns the current generation.
|
/** This method returns the current generation.
|
||||||
@ -281,7 +300,16 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
|
|||||||
* @param ea
|
* @param ea
|
||||||
*/
|
*/
|
||||||
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener 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.
|
/** 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
|
* 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()
|
* @see getIndexOfBestOrWorstIndividual()
|
||||||
* @return The index of the best individual.
|
* @return The index of the best individual.
|
||||||
*/
|
*/
|
||||||
public int getIndexOfBestIndividual() {
|
public int getIndexOfBestIndividual() {
|
||||||
|
if (size()<1) return -1;
|
||||||
return getIndexOfBestOrWorstIndividual(true, true);
|
return getIndexOfBestOrWorstIndividual(true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -422,15 +451,23 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
|
|||||||
return result;
|
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
|
* @return The best individual
|
||||||
*/
|
*/
|
||||||
public AbstractEAIndividual getBestEAIndividual() {
|
public AbstractEAIndividual getBestEAIndividual() {
|
||||||
|
if (size()<1) return null;
|
||||||
int best = this.getIndexOfBestIndividual();
|
int best = this.getIndexOfBestIndividual();
|
||||||
if (best == -1) System.err.println("This shouldnt happen!");;
|
if (best == -1) {
|
||||||
AbstractEAIndividual result = (AbstractEAIndividual)this.get(best);
|
System.err.println("This shouldnt happen!");
|
||||||
if (result == null) System.err.println("Serious Problem! Population Size: " + this.size());
|
return null;
|
||||||
return result;
|
} else {
|
||||||
|
AbstractEAIndividual result = (AbstractEAIndividual)this.get(best);
|
||||||
|
if (result == null) System.err.println("Serious Problem! Population Size: " + this.size());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,22 +51,14 @@ public abstract class AbstractOptimizationProblem implements InterfaceOptimizati
|
|||||||
*/
|
*/
|
||||||
public void evaluate(Population population) {
|
public void evaluate(Population population) {
|
||||||
AbstractEAIndividual tmpIndy;
|
AbstractEAIndividual tmpIndy;
|
||||||
|
evaluatePopulationStart(population);
|
||||||
// if (population.isEvaluated()) {
|
for (int i = 0; i < population.size(); i++) {
|
||||||
// System.err.println("Population evaluation seems not required!");
|
tmpIndy = (AbstractEAIndividual) population.get(i);
|
||||||
// } else {
|
tmpIndy.resetConstraintViolation();
|
||||||
// @todo This is the position to implement a granular
|
this.evaluate(tmpIndy);
|
||||||
// @todo paralleliziation scheme
|
population.incrFunctionCalls();
|
||||||
evaluatePopulationStart(population);
|
}
|
||||||
for (int i = 0; i < population.size(); i++) {
|
evaluatePopulationEnd(population);
|
||||||
tmpIndy = (AbstractEAIndividual) population.get(i);
|
|
||||||
tmpIndy.resetConstraintViolation();
|
|
||||||
this.evaluate(tmpIndy);
|
|
||||||
population.incrFunctionCalls();
|
|
||||||
}
|
|
||||||
evaluatePopulationEnd(population);
|
|
||||||
// population.setEvaluated();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -103,20 +95,6 @@ public abstract class AbstractOptimizationProblem implements InterfaceOptimizati
|
|||||||
return AbstractEAIndividual.getDefaultStringRepresentation(individual);
|
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
|
/** 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
|
* 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.
|
* 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());
|
result.setLayout(new BorderLayout());
|
||||||
JTextArea area = new JTextArea();
|
JTextArea area = new JTextArea();
|
||||||
JScrollPane scroll = new JScrollPane(area);
|
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);
|
area.setEditable(false);
|
||||||
result.add(scroll, BorderLayout.CENTER);
|
result.add(scroll, BorderLayout.CENTER);
|
||||||
return result;
|
return result;
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
package eva2.server.go.problems;
|
package eva2.server.go.problems;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
import eva2.server.go.individuals.AbstractEAIndividual;
|
import eva2.server.go.individuals.AbstractEAIndividual;
|
||||||
import eva2.server.go.populations.Population;
|
import eva2.server.go.populations.Population;
|
||||||
import eva2.server.go.strategies.InterfaceOptimizer;
|
import eva2.server.go.strategies.InterfaceOptimizer;
|
||||||
import eva2.server.stat.InterfaceStatistics;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by IntelliJ IDEA.
|
* Created by IntelliJ IDEA.
|
||||||
@ -51,15 +48,6 @@ public interface InterfaceOptimizationProblem extends InterfaceAdditionalPopulat
|
|||||||
*/
|
*/
|
||||||
public void evaluate(AbstractEAIndividual individual);
|
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 *******************************************/
|
/******************** Some output methods *******************************************/
|
||||||
|
|
||||||
/** This method allows the CommonJavaObjectEditorPanel to read the
|
/** This method allows the CommonJavaObjectEditorPanel to read the
|
||||||
|
@ -73,7 +73,7 @@ public class CHCAdaptiveSearchAlgorithm implements InterfaceOptimizer, java.io.S
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.evaluatePopulation(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
|
/** This method will init the optimizer with a given population
|
||||||
@ -92,7 +92,7 @@ public class CHCAdaptiveSearchAlgorithm implements InterfaceOptimizer, java.io.S
|
|||||||
|
|
||||||
if (reset) {
|
if (reset) {
|
||||||
this.evaluatePopulation(this.m_Population);
|
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);
|
nextGeneration.addPopulation(tmp);
|
||||||
this.m_Population = nextGeneration;
|
this.m_Population = nextGeneration;
|
||||||
}
|
}
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method allows you to add the LectureGUI as listener to the Optimizer
|
/** This method allows you to add the LectureGUI as listener to the Optimizer
|
||||||
|
@ -614,7 +614,7 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
|
|||||||
// System.out.println("species distract best towards " + BeanInspector.toString(distVect));
|
// System.out.println("species distract best towards " + BeanInspector.toString(distVect));
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -113,7 +113,7 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
|
|||||||
this.m_Problem.initPopulation(this.m_Population);
|
this.m_Problem.initPopulation(this.m_Population);
|
||||||
m_Population.addPopulationChangedEventListener(null); // noone will be notified directly on pop changes
|
m_Population.addPopulationChangedEventListener(null); // noone will be notified directly on pop changes
|
||||||
this.m_Problem.evaluate(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
|
/** This method will init the optimizer with a given population
|
||||||
@ -127,7 +127,7 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
|
|||||||
if (reset) {
|
if (reset) {
|
||||||
this.m_Population.init();
|
this.m_Population.init();
|
||||||
this.m_Problem.evaluate(this.m_Population);
|
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);
|
// 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
|
// set funcalls to real value
|
||||||
m_Population.SetFunctionCalls(((Population)source).getFunctionCalls());
|
m_Population.SetFunctionCalls(((Population)source).getFunctionCalls());
|
||||||
// System.out.println("FunCallIntervalReached at " + (((Population)source).getFunctionCalls()));
|
// System.out.println("FunCallIntervalReached at " + (((Population)source).getFunctionCalls()));
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
// do not react to NextGenerationPerformed
|
// do not react to NextGenerationPerformed
|
||||||
//else System.err.println("ERROR, event was " + name);
|
//else System.err.println("ERROR, event was " + name);
|
||||||
|
@ -78,7 +78,7 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
|
|||||||
this.m_Problem.initPopulation(this.m_Population);
|
this.m_Problem.initPopulation(this.m_Population);
|
||||||
// children = new Population(m_Population.size());
|
// children = new Population(m_Population.size());
|
||||||
this.evaluatePopulation(this.m_Population);
|
this.evaluatePopulation(this.m_Population);
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hideHideable() {
|
public void hideHideable() {
|
||||||
@ -94,7 +94,7 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
|
|||||||
if (reset) {
|
if (reset) {
|
||||||
this.m_Population.init();
|
this.m_Population.init();
|
||||||
this.evaluatePopulation(this.m_Population);
|
this.evaluatePopulation(this.m_Population);
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
// if (reset) this.m_Population.init();
|
// if (reset) this.m_Population.init();
|
||||||
// else children = new Population(m_Population.size());
|
// else children = new Population(m_Population.size());
|
||||||
@ -413,7 +413,7 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
|
|||||||
// }
|
// }
|
||||||
m_Problem.evaluatePopulationEnd(m_Population);
|
m_Problem.evaluatePopulationEnd(m_Population);
|
||||||
this.m_Population.incrGeneration();
|
this.m_Population.incrGeneration();
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -375,7 +375,7 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
|
|||||||
for (int i = 0; i < this.m_Population.size(); i++) {
|
for (int i = 0; i < this.m_Population.size(); i++) {
|
||||||
AbstractEAIndividual indy = (AbstractEAIndividual)m_Population.get(i);
|
AbstractEAIndividual indy = (AbstractEAIndividual)m_Population.get(i);
|
||||||
if (i>=quantumCount) {
|
if (i>=quantumCount) {
|
||||||
indy.SetData(partTypeKey, quantumType);
|
indy.putData(partTypeKey, quantumType);
|
||||||
quantumCount += 1./quantumRatio;
|
quantumCount += 1./quantumRatio;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -437,8 +437,8 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
|
|||||||
// log the best individual of the population
|
// log the best individual of the population
|
||||||
if (envHasChanged || (this.m_Population.getBestEAIndividual().isDominatingDebConstraints(this.m_BestIndividual))) {
|
if (envHasChanged || (this.m_Population.getBestEAIndividual().isDominatingDebConstraints(this.m_BestIndividual))) {
|
||||||
this.m_BestIndividual = (AbstractEAIndividual)this.m_Population.getBestEAIndividual().clone();
|
this.m_BestIndividual = (AbstractEAIndividual)this.m_Population.getBestEAIndividual().clone();
|
||||||
this.m_BestIndividual.SetData(partBestFitKey, this.m_BestIndividual.getFitness());
|
this.m_BestIndividual.putData(partBestFitKey, this.m_BestIndividual.getFitness());
|
||||||
this.m_BestIndividual.SetData(partBestPosKey, ((InterfaceDataTypeDouble)this.m_BestIndividual).getDoubleData());
|
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]);
|
//System.out.println("-- best ind set to " + ((InterfaceDataTypeDouble)this.m_BestIndividual).getDoubleData()[0] + "/" + ((InterfaceDataTypeDouble)this.m_BestIndividual).getDoubleData()[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,7 @@ public class EvolutionStrategies implements InterfaceOptimizer, java.io.Serializ
|
|||||||
|
|
||||||
transient private String m_Identifier = "";
|
transient private String m_Identifier = "";
|
||||||
transient private InterfacePopulationChangedEventListener m_Listener;
|
transient private InterfacePopulationChangedEventListener m_Listener;
|
||||||
|
public static final String esMuParam = "EvolutionStrategyMuParameter";
|
||||||
|
|
||||||
public EvolutionStrategies() {
|
public EvolutionStrategies() {
|
||||||
this.m_Population.setPopulationSize(this.m_Lambda);
|
this.m_Population.setPopulationSize(this.m_Lambda);
|
||||||
@ -97,10 +98,11 @@ public class EvolutionStrategies implements InterfaceOptimizer, java.io.Serializ
|
|||||||
// }
|
// }
|
||||||
//System.out.println("init");
|
//System.out.println("init");
|
||||||
checkPopulationConstraints();
|
checkPopulationConstraints();
|
||||||
|
m_Population.putData(esMuParam, getMu());
|
||||||
this.m_Problem.initPopulation(this.m_Population);
|
this.m_Problem.initPopulation(this.m_Population);
|
||||||
this.evaluatePopulation(this.m_Population);
|
this.evaluatePopulation(this.m_Population);
|
||||||
// this.m_Population.setPopulationSize(orgPopSize);
|
// 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) {
|
if (reset) {
|
||||||
this.m_Population.init();
|
this.m_Population.init();
|
||||||
this.evaluatePopulation(this.m_Population);
|
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("Population size: " + this.m_Population.size());
|
||||||
// System.out.println("-- Best Fitness " + this.m_Population.getBestFitness()[0]);
|
// 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
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -91,7 +91,7 @@ public class EvolutionStrategyIPOP extends EvolutionStrategies implements Interf
|
|||||||
//
|
//
|
||||||
// setPop(getReplacePop(nextGeneration));
|
// setPop(getReplacePop(nextGeneration));
|
||||||
//
|
//
|
||||||
// this.firePropertyChangedEvent("NextGenerationPerformed");
|
// this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
//////////////////////////
|
//////////////////////////
|
||||||
super.optimize();
|
super.optimize();
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ public class EvolutionStrategyIPOP extends EvolutionStrategies implements Interf
|
|||||||
bestList.add(best);
|
bestList.add(best);
|
||||||
best = null;
|
best = null;
|
||||||
Population newPop = getPopulation().cloneWithoutInds();
|
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();
|
double[] badFit = getPopulation().getBestFitness().clone();
|
||||||
Arrays.fill(badFit, Double.MAX_VALUE);
|
Arrays.fill(badFit, Double.MAX_VALUE);
|
||||||
newPop.setAllFitnessValues(badFit);
|
newPop.setAllFitnessValues(badFit);
|
||||||
@ -137,7 +137,7 @@ public class EvolutionStrategyIPOP extends EvolutionStrategies implements Interf
|
|||||||
|
|
||||||
protected void firePropertyChangedEvent(String name) {
|
protected void firePropertyChangedEvent(String name) {
|
||||||
if (name.equals(Population.funCallIntervalReached)) {
|
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
|
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
|
// 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
|
// 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
|
// 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
|
// 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
|
// 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;
|
return false;
|
||||||
@ -231,7 +231,7 @@ public class EvolutionStrategyIPOP extends EvolutionStrategies implements Interf
|
|||||||
public void registerPopulationStateChanged(Object source, String name) {
|
public void registerPopulationStateChanged(Object source, String name) {
|
||||||
if (name.equals(Population.funCallIntervalReached)) {
|
if (name.equals(Population.funCallIntervalReached)) {
|
||||||
getPopulation().SetFunctionCalls(((Population)source).getFunctionCalls()); // TODO this is ugly
|
getPopulation().SetFunctionCalls(((Population)source).getFunctionCalls()); // TODO this is ugly
|
||||||
super.firePropertyChangedEvent(name);
|
super.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
} else {
|
} else {
|
||||||
// System.err.println("Not forwarding event " + name);
|
// System.err.println("Not forwarding event " + name);
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ public class EvolutionaryProgramming implements InterfaceOptimizer, java.io.Seri
|
|||||||
this.m_Problem.initPopulation(this.m_Population);
|
this.m_Problem.initPopulation(this.m_Population);
|
||||||
this.evaluatePopulation(this.m_Population);
|
this.evaluatePopulation(this.m_Population);
|
||||||
this.m_PopulationSize = this.m_Population.size();
|
this.m_PopulationSize = this.m_Population.size();
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will init the optimizer with a given population
|
/** This method will init the optimizer with a given population
|
||||||
@ -61,7 +61,7 @@ public class EvolutionaryProgramming implements InterfaceOptimizer, java.io.Seri
|
|||||||
if (reset) {
|
if (reset) {
|
||||||
this.m_Population.init();
|
this.m_Population.init();
|
||||||
this.evaluatePopulation(this.m_Population);
|
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);
|
nextGeneration.addPopulation(this.m_Population);
|
||||||
this.m_Population = nextGeneration;
|
this.m_Population = nextGeneration;
|
||||||
|
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method allows you to add the LectureGUI as listener to the Optimizer
|
/** This method allows you to add the LectureGUI as listener to the Optimizer
|
||||||
|
@ -59,7 +59,7 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
|
|||||||
this.m_Problem.initPopulation(this.m_Population);
|
this.m_Problem.initPopulation(this.m_Population);
|
||||||
this.m_Problem.evaluate(this.m_Population);
|
this.m_Problem.evaluate(this.m_Population);
|
||||||
this.m_CurrentFloodPeak = this.m_InitialFloodPeak;
|
this.m_CurrentFloodPeak = this.m_InitialFloodPeak;
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will init the optimizer with a given population
|
/** This method will init the optimizer with a given population
|
||||||
@ -70,7 +70,7 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
|
|||||||
if (reset) {
|
if (reset) {
|
||||||
this.m_Population.init();
|
this.m_Population.init();
|
||||||
this.m_Problem.evaluate(this.m_Population);
|
this.m_Problem.evaluate(this.m_Population);
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
this.m_CurrentFloodPeak = this.m_InitialFloodPeak;
|
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_CurrentFloodPeak = this.m_CurrentFloodPeak - this.m_DrainRate;
|
||||||
this.m_Population.incrGeneration();
|
this.m_Population.incrGeneration();
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method calculates the difference between the fitness values
|
/** This method calculates the difference between the fitness values
|
||||||
|
@ -59,7 +59,7 @@ public class GeneticAlgorithm implements InterfaceOptimizer, java.io.Serializabl
|
|||||||
public void init() {
|
public void init() {
|
||||||
this.m_Problem.initPopulation(this.m_Population);
|
this.m_Problem.initPopulation(this.m_Population);
|
||||||
this.evaluatePopulation(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
|
/** This method will init the optimizer with a given population
|
||||||
@ -70,7 +70,7 @@ public class GeneticAlgorithm implements InterfaceOptimizer, java.io.Serializabl
|
|||||||
if (reset) {
|
if (reset) {
|
||||||
this.m_Population.init();
|
this.m_Population.init();
|
||||||
this.evaluatePopulation(this.m_Population);
|
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.m_Population.incrGeneration();
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method allows you to add the LectureGUI as listener to the Optimizer
|
/** This method allows you to add the LectureGUI as listener to the Optimizer
|
||||||
|
@ -56,7 +56,7 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
|
|||||||
if (reset) {
|
if (reset) {
|
||||||
this.getPopulation().init();
|
this.getPopulation().init();
|
||||||
this.m_Problem.evaluate(this.getPopulation());
|
this.m_Problem.evaluate(this.getPopulation());
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
//System.out.println("initByPopulation() called");
|
//System.out.println("initByPopulation() called");
|
||||||
indyhash = new Hashtable();
|
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;
|
private double momentumweigth = 0.1;
|
||||||
|
@ -55,7 +55,7 @@ public class HillClimbing implements InterfaceOptimizer, java.io.Serializable {
|
|||||||
public void init() {
|
public void init() {
|
||||||
this.m_Problem.initPopulation(this.m_Population);
|
this.m_Problem.initPopulation(this.m_Population);
|
||||||
this.m_Problem.evaluate(this.m_Population);
|
this.m_Problem.evaluate(this.m_Population);
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initByPopulation(Population pop, boolean reset) {
|
public void initByPopulation(Population pop, boolean reset) {
|
||||||
@ -63,7 +63,7 @@ public class HillClimbing implements InterfaceOptimizer, java.io.Serializable {
|
|||||||
if (reset) {
|
if (reset) {
|
||||||
this.m_Population.init();
|
this.m_Population.init();
|
||||||
this.m_Problem.evaluate(this.m_Population);
|
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.m_Population.incrGeneration();
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InterfaceMutation getMutationOperator() {
|
public InterfaceMutation getMutationOperator() {
|
||||||
|
@ -135,7 +135,7 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
|
|||||||
this.m_Population.addPopulation(pop);
|
this.m_Population.addPopulation(pop);
|
||||||
this.m_Population.incrFunctionCallsBy(pop.getFunctionCalls());
|
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
|
/** 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.addPopulation(pop);
|
||||||
this.m_Population.incrFunctionCallsBy(pop.getFunctionCalls());
|
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
|
/** 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());
|
this.m_Population.incrFunctionCallsBy(pop.getFunctionCalls());
|
||||||
}
|
}
|
||||||
// System.out.println("Fitnesscalls :" + this.m_Population.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();
|
double plotValue = (this.m_Problem.getDoublePlotValue(this.m_Population)).doubleValue();
|
||||||
if (this.m_Show) this.m_Plot.setConnectedPoint(this.m_Population.getFunctionCalls(), plotValue, 0);
|
if (this.m_Show) this.m_Plot.setConnectedPoint(this.m_Population.getFunctionCalls(), plotValue, 0);
|
||||||
// now they are synchronized
|
// now they are synchronized
|
||||||
|
@ -92,7 +92,7 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
|
|||||||
if (reset) {
|
if (reset) {
|
||||||
this.getPopulation().init();
|
this.getPopulation().init();
|
||||||
this.m_Problem.evaluate(this.getPopulation());
|
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.SetProblem(this.m_Problem);
|
||||||
this.m_GlobalOptimizer.init();
|
this.m_GlobalOptimizer.init();
|
||||||
this.evaluatePopulation(this.m_GlobalOptimizer.getPopulation());
|
this.evaluatePopulation(this.m_GlobalOptimizer.getPopulation());
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -192,7 +192,7 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
|
|||||||
if (TRACE)
|
if (TRACE)
|
||||||
System.out.println("function calls"
|
System.out.println("function calls"
|
||||||
+ this.m_GlobalOptimizer.getPopulation().getFunctionCalls());
|
+ this.m_GlobalOptimizer.getPopulation().getFunctionCalls());
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,7 +55,7 @@ public class MonteCarloSearch implements InterfaceOptimizer, java.io.Serializabl
|
|||||||
public void init() {
|
public void init() {
|
||||||
this.m_Problem.initPopulation(this.m_Population);
|
this.m_Problem.initPopulation(this.m_Population);
|
||||||
this.m_Problem.evaluate(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
|
/** This method will init the optimizer with a given population
|
||||||
@ -67,7 +67,7 @@ public class MonteCarloSearch implements InterfaceOptimizer, java.io.Serializabl
|
|||||||
if (reset) {
|
if (reset) {
|
||||||
this.m_Population.init();
|
this.m_Population.init();
|
||||||
this.m_Problem.evaluate(this.m_Population);
|
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.m_Population.incrGeneration();
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
|
|||||||
public void init() {
|
public void init() {
|
||||||
this.m_Optimizer.init();
|
this.m_Optimizer.init();
|
||||||
this.m_Archiver.addElementsToArchive(this.m_Optimizer.getPopulation());
|
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) {
|
public void initByPopulation(Population pop, boolean reset) {
|
||||||
this.m_Optimizer.initByPopulation(pop, reset);
|
this.m_Optimizer.initByPopulation(pop, reset);
|
||||||
this.m_Archiver.addElementsToArchive(this.m_Optimizer.getPopulation());
|
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
|
/** The optimize method will compute a 'improved' and evaluated population
|
||||||
@ -127,7 +127,7 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
|
|||||||
|
|
||||||
System.gc();
|
System.gc();
|
||||||
|
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
private double[][] showMay(Population pop) {
|
private double[][] showMay(Population pop) {
|
||||||
|
@ -183,8 +183,8 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
|||||||
for (int j = 0; j < writeData.length; j++) {
|
for (int j = 0; j < writeData.length; j++) {
|
||||||
writeData[j] = (writeData[j]/relSpeed)*this.m_InitialVelocity;
|
writeData[j] = (writeData[j]/relSpeed)*this.m_InitialVelocity;
|
||||||
}
|
}
|
||||||
indy.SetData(partTypeKey, defaultType);
|
indy.putData(partTypeKey, defaultType);
|
||||||
indy.SetData(partVelKey, writeData);
|
indy.putData(partVelKey, writeData);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -197,12 +197,12 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
|||||||
double[] tmpD = indy.getFitness();
|
double[] tmpD = indy.getFitness();
|
||||||
double[] writeData = new double[tmpD.length];
|
double[] writeData = new double[tmpD.length];
|
||||||
System.arraycopy(tmpD, 0, writeData, 0, tmpD.length);
|
System.arraycopy(tmpD, 0, writeData, 0, tmpD.length);
|
||||||
indy.SetData(partBestFitKey, writeData);
|
indy.putData(partBestFitKey, writeData);
|
||||||
// init best position
|
// init best position
|
||||||
tmpD = ((InterfaceDataTypeDouble)indy).getDoubleData();
|
tmpD = ((InterfaceDataTypeDouble)indy).getDoubleData();
|
||||||
writeData = new double[tmpD.length];
|
writeData = new double[tmpD.length];
|
||||||
System.arraycopy(tmpD, 0, writeData, 0, 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();
|
this.m_BestIndividual = (AbstractEAIndividual)this.m_Population.getBestEAIndividual().clone();
|
||||||
|
|
||||||
if (reset) this.firePropertyChangedEvent("NextGenerationPerformed");
|
if (reset) this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
|
|
||||||
treeLevels = 0;
|
treeLevels = 0;
|
||||||
// the HPSO tree will contain layers 0...HPSOLevels, the last one is "incomplete" with only HPSOOrphans number of nodes
|
// 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) {
|
if (indy instanceof InterfaceDataTypeDouble) {
|
||||||
initIndividualDefaults(indy);
|
initIndividualDefaults(indy);
|
||||||
}
|
}
|
||||||
indy.SetData(indexKey, i);
|
indy.putData(indexKey, i);
|
||||||
indy.setIndividualIndex(i);
|
indy.setIndividualIndex(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -473,7 +473,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
|||||||
if (indy instanceof InterfaceDataTypeDouble) {
|
if (indy instanceof InterfaceDataTypeDouble) {
|
||||||
indy.setParents(null);
|
indy.setParents(null);
|
||||||
indy.defaultInit();
|
indy.defaultInit();
|
||||||
indy.SetData(partTypeKey, defaultType); // turn into default type
|
indy.putData(partTypeKey, defaultType); // turn into default type
|
||||||
initIndividualDefaults(indy);
|
initIndividualDefaults(indy);
|
||||||
initIndividualMemory(indy);
|
initIndividualMemory(indy);
|
||||||
plotIndy(((InterfaceDataTypeDouble)indy).getDoubleData(), null, (Integer)indy.getData(indexKey));
|
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) {
|
protected void defaultIndividualUpdate(int index, AbstractEAIndividual indy, Population pop) {
|
||||||
InterfaceDataTypeDouble endy = (InterfaceDataTypeDouble) indy;
|
InterfaceDataTypeDouble endy = (InterfaceDataTypeDouble) indy;
|
||||||
|
|
||||||
indy.SetData(partTypeKey, defaultType);
|
indy.putData(partTypeKey, defaultType);
|
||||||
// default update
|
// default update
|
||||||
double[] personalBestPos = (double[]) indy.getData(partBestPosKey);
|
double[] personalBestPos = (double[]) indy.getData(partBestPosKey);
|
||||||
double[] velocity = (double[]) indy.getData(partVelKey);
|
double[] velocity = (double[]) indy.getData(partVelKey);
|
||||||
@ -598,8 +598,8 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
|||||||
* @param indy the individual to update
|
* @param indy the individual to update
|
||||||
*/
|
*/
|
||||||
protected void updateIndProps(AbstractEAIndividual indy) {
|
protected void updateIndProps(AbstractEAIndividual indy) {
|
||||||
indy.SetData(partBestFitKey, indy.getFitness());
|
indy.putData(partBestFitKey, indy.getFitness());
|
||||||
indy.SetData(partBestPosKey, ((InterfaceDataTypeDouble)indy).getDoubleData());
|
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!");
|
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);
|
// ((InterfaceESIndividual) indy).SetDGenotype(newPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1135,7 +1135,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
|||||||
|
|
||||||
// System.out.println(">>> " + m_Population.getBestEAIndividual().getStringRepresentation());
|
// System.out.println(">>> " + m_Population.getBestEAIndividual().getStringRepresentation());
|
||||||
|
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
|
|
||||||
if (sleepTime > 0 ) try { Thread.sleep(sleepTime); } catch(Exception e) {}
|
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() {
|
protected void logBestIndividual() {
|
||||||
if (this.m_Population.getBestEAIndividual().isDominatingDebConstraints(this.m_BestIndividual)) {
|
if (this.m_Population.getBestEAIndividual().isDominatingDebConstraints(this.m_BestIndividual)) {
|
||||||
this.m_BestIndividual = (AbstractEAIndividual)this.m_Population.getBestEAIndividual().clone();
|
this.m_BestIndividual = (AbstractEAIndividual)this.m_Population.getBestEAIndividual().clone();
|
||||||
this.m_BestIndividual.SetData(partBestFitKey, this.m_BestIndividual.getFitness());
|
this.m_BestIndividual.putData(partBestFitKey, this.m_BestIndividual.getFitness());
|
||||||
this.m_BestIndividual.SetData(partBestPosKey, ((InterfaceDataTypeDouble)this.m_BestIndividual).getDoubleData());
|
this.m_BestIndividual.putData(partBestPosKey, ((InterfaceDataTypeDouble)this.m_BestIndividual).getDoubleData());
|
||||||
// System.out.println("new best: "+m_BestIndividual.toString());
|
// 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++) {
|
for (int i=0; i<pop.size(); i++) {
|
||||||
// cross-link the sorted list for faster access
|
// cross-link the sorted list for faster access
|
||||||
origIndex = (Integer)((AbstractEAIndividual)sortedPopulation[i]).getData(indexKey);
|
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 {
|
} else {
|
||||||
found = true;
|
found = true;
|
||||||
// assign to leader, update swarm size
|
// assign to leader, update swarm size
|
||||||
((AbstractEAIndividual)sortedPop[cur]).SetData(multiSwTypeKey, leaders.get(i));
|
((AbstractEAIndividual)sortedPop[cur]).putData(multiSwTypeKey, leaders.get(i));
|
||||||
((AbstractEAIndividual)sortedPop[cur]).SetData(multiSwSizeKey, new Integer(-1));
|
((AbstractEAIndividual)sortedPop[cur]).putData(multiSwSizeKey, new Integer(-1));
|
||||||
leaders.get(i).SetData(multiSwSizeKey, 1+sSize);
|
leaders.get(i).putData(multiSwSizeKey, 1+sSize);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) { // new leader is found
|
if (!found) { // new leader is found
|
||||||
leaders.add(((AbstractEAIndividual)sortedPop[cur]));
|
leaders.add(((AbstractEAIndividual)sortedPop[cur]));
|
||||||
((AbstractEAIndividual)sortedPop[cur]).SetData(multiSwTypeKey, sortedPop[cur]);
|
((AbstractEAIndividual)sortedPop[cur]).putData(multiSwTypeKey, sortedPop[cur]);
|
||||||
((AbstractEAIndividual)sortedPop[cur]).SetData(multiSwSizeKey, new Integer(1));
|
((AbstractEAIndividual)sortedPop[cur]).putData(multiSwSizeKey, new Integer(1));
|
||||||
} else if (superfluous) {
|
} else if (superfluous) {
|
||||||
//System.out.println("reinitializing " + cur);
|
//System.out.println("reinitializing " + cur);
|
||||||
((AbstractEAIndividual)sortedPop[cur]).SetData(partTypeKey, resetType);
|
((AbstractEAIndividual)sortedPop[cur]).putData(partTypeKey, resetType);
|
||||||
((AbstractEAIndividual)sortedPop[cur]).SetData(multiSwTypeKey, sortedPop[cur]);
|
((AbstractEAIndividual)sortedPop[cur]).putData(multiSwTypeKey, sortedPop[cur]);
|
||||||
((AbstractEAIndividual)sortedPop[cur]).SetData(multiSwSizeKey, new Integer(1));
|
((AbstractEAIndividual)sortedPop[cur]).putData(multiSwSizeKey, new Integer(1));
|
||||||
}
|
}
|
||||||
cur++;
|
cur++;
|
||||||
}
|
}
|
||||||
@ -1432,7 +1432,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
|||||||
if (indy.hasData(partTypeKey)) {
|
if (indy.hasData(partTypeKey)) {
|
||||||
initIndividualDefaults(indy);
|
initIndividualDefaults(indy);
|
||||||
initIndividualMemory(indy);
|
initIndividualMemory(indy);
|
||||||
indy.SetData(indexKey, i);
|
indy.putData(indexKey, i);
|
||||||
indy.setIndividualIndex(i);
|
indy.setIndividualIndex(i);
|
||||||
if (TRACE) System.err.println("init indy " + i + " " + AbstractEAIndividual.getDefaultDataString(indy));
|
if (TRACE) System.err.println("init indy " + i + " " + AbstractEAIndividual.getDefaultDataString(indy));
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
|
|||||||
public void init() {
|
public void init() {
|
||||||
this.m_Problem.initPopulation(this.m_Population);
|
this.m_Problem.initPopulation(this.m_Population);
|
||||||
this.evaluatePopulation(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
|
/** 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);
|
this.evaluatePopulation(this.m_Population);
|
||||||
}
|
}
|
||||||
((PBILPopulation)this.m_Population).buildProbabilityVector();
|
((PBILPopulation)this.m_Population).buildProbabilityVector();
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will evaluate the current population using the
|
/** This method will evaluate the current population using the
|
||||||
@ -121,7 +121,7 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
|
|||||||
} else {
|
} else {
|
||||||
this.m_Population = nextGeneration;
|
this.m_Population = nextGeneration;
|
||||||
}
|
}
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will set the problem that is to be optimized
|
/** This method will set the problem that is to be optimized
|
||||||
|
@ -58,7 +58,7 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
|
|||||||
this.m_Problem.initPopulation(this.m_Population);
|
this.m_Problem.initPopulation(this.m_Population);
|
||||||
this.m_Problem.evaluate(this.m_Population);
|
this.m_Problem.evaluate(this.m_Population);
|
||||||
this.m_CurrentTemperature = this.m_InitialTemperature;
|
this.m_CurrentTemperature = this.m_InitialTemperature;
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will init the optimizer with a given population
|
/** This method will init the optimizer with a given population
|
||||||
@ -71,7 +71,7 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
|
|||||||
if (reset) {
|
if (reset) {
|
||||||
this.m_Population.init();
|
this.m_Population.init();
|
||||||
this.m_Problem.evaluate(this.m_Population);
|
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_CurrentTemperature = this.m_Alpha * this.m_CurrentTemperature;
|
||||||
this.m_Population.incrGeneration();
|
this.m_Population.incrGeneration();
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method calculates the difference between the fitness values
|
/** This method calculates the difference between the fitness values
|
||||||
|
@ -54,7 +54,7 @@ public class SteadyStateGA implements InterfaceOptimizer, java.io.Serializable {
|
|||||||
public void init() {
|
public void init() {
|
||||||
this.m_Problem.initPopulation(this.m_Population);
|
this.m_Problem.initPopulation(this.m_Population);
|
||||||
this.evaluatePopulation(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
|
/** This method will init the optimizer with a given population
|
||||||
@ -65,7 +65,7 @@ public class SteadyStateGA implements InterfaceOptimizer, java.io.Serializable {
|
|||||||
if (reset) {
|
if (reset) {
|
||||||
this.m_Population.init();
|
this.m_Population.init();
|
||||||
this.evaluatePopulation(this.m_Population);
|
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();
|
for (int i = 0; i < this.m_Population.size(); i++) this.generateChildren();
|
||||||
this.m_Population.incrFunctionCallsBy(this.m_Population.size());
|
this.m_Population.incrFunctionCallsBy(this.m_Population.size());
|
||||||
this.m_Population.incrGeneration();
|
this.m_Population.incrGeneration();
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method allows you to add the LectureGUI as listener to the Optimizer
|
/** This method allows you to add the LectureGUI as listener to the Optimizer
|
||||||
|
@ -56,7 +56,7 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
|
|||||||
this.m_Problem.initPopulation(this.m_Population);
|
this.m_Problem.initPopulation(this.m_Population);
|
||||||
this.m_Problem.evaluate(this.m_Population);
|
this.m_Problem.evaluate(this.m_Population);
|
||||||
this.m_CurrentT = this.m_InitialT;
|
this.m_CurrentT = this.m_InitialT;
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will init the optimizer with a given population
|
/** This method will init the optimizer with a given population
|
||||||
@ -69,7 +69,7 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
|
|||||||
if (reset) {
|
if (reset) {
|
||||||
this.m_Population.init();
|
this.m_Population.init();
|
||||||
this.m_Problem.evaluate(this.m_Population);
|
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_CurrentT = this.m_Alpha * this.m_CurrentT;
|
||||||
this.m_Population.incrGeneration();
|
this.m_Population.incrGeneration();
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method calculates the difference between the fitness values
|
/** This method calculates the difference between the fitness values
|
||||||
|
@ -736,7 +736,7 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
|
|||||||
population.incrFunctionCalls();
|
population.incrFunctionCalls();
|
||||||
if (notifyAfter(population.getFunctionCalls())) {
|
if (notifyAfter(population.getFunctionCalls())) {
|
||||||
// System.out.println("Notifying after " + population.getFunctionCalls());
|
// System.out.println("Notifying after " + population.getFunctionCalls());
|
||||||
firePropertyChangedEvent("NextGenerationPerformed");
|
firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
|
|||||||
this.m_SOOptimizer.init();
|
this.m_SOOptimizer.init();
|
||||||
}
|
}
|
||||||
this.communicate();
|
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.m_SOOptimizer.initByPopulation(pop, reset);
|
||||||
}
|
}
|
||||||
this.communicate();
|
this.communicate();
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The optimize method will compute a 'improved' and evaluated population
|
/** The optimize method will compute a 'improved' and evaluated population
|
||||||
@ -148,7 +148,7 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
|
|||||||
|
|
||||||
System.gc();
|
System.gc();
|
||||||
|
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will manage comunication between the
|
/** This method will manage comunication between the
|
||||||
@ -171,7 +171,7 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
|
|||||||
oldFunctionCalls = this.m_Population.getFunctionCalls();
|
oldFunctionCalls = this.m_Population.getFunctionCalls();
|
||||||
this.m_Problem.evaluate(this.m_Population);
|
this.m_Problem.evaluate(this.m_Population);
|
||||||
this.m_Population.SetFunctionCalls(oldFunctionCalls);
|
this.m_Population.SetFunctionCalls(oldFunctionCalls);
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
|
||||||
double plotValue = (this.m_Problem.getDoublePlotValue(this.m_Population)).doubleValue();
|
double plotValue = (this.m_Problem.getDoublePlotValue(this.m_Population)).doubleValue();
|
||||||
// now they are synchronized lets migrate
|
// now they are synchronized lets migrate
|
||||||
this.migrate();
|
this.migrate();
|
||||||
|
@ -16,12 +16,12 @@ import java.io.Serializable;
|
|||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.Vector;
|
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.MainAdapterClient;
|
||||||
import wsi.ra.jproxy.RemoteStateListener;
|
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
|
* ABSTRACT CLASS DECLARATION
|
||||||
*==========================================================================*/
|
*==========================================================================*/
|
||||||
@ -120,6 +120,12 @@ abstract public class AbstractModuleAdapter implements ModuleAdapter, Serializab
|
|||||||
} else return false;
|
} else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public InterfaceGOParameters getGOParameters() {
|
||||||
|
if ((m_Processor != null) && (m_Processor instanceof Processor)) {
|
||||||
|
return ((Processor)m_Processor).getGOParams();
|
||||||
|
} else return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -29,6 +29,6 @@ public class GOModuleAdapter extends GenericModuleAdapter implements ModuleAdapt
|
|||||||
* @param Client the client instance
|
* @param Client the client instance
|
||||||
*/
|
*/
|
||||||
public GOModuleAdapter(String adapterName, MainAdapterClient client) {
|
public GOModuleAdapter(String adapterName, MainAdapterClient client) {
|
||||||
super (adapterName, "GO.html", client, GOParameters.getInstance(), false);
|
super (adapterName, "", client, GOParameters.getInstance(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -251,17 +251,19 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
|||||||
* @param name Could be used to indicate the nature of the event.
|
* @param name Could be used to indicate the nature of the event.
|
||||||
*/
|
*/
|
||||||
public void registerPopulationStateChanged(Object source, String name) {
|
public void registerPopulationStateChanged(Object source, String name) {
|
||||||
m_Statistics.createNextGenerationPerformed(
|
if (name.equals(Population.nextGenerationPerformed)) {
|
||||||
(PopulationInterface)this.goParams.getOptimizer().getPopulation(),
|
m_Statistics.createNextGenerationPerformed(
|
||||||
this.goParams.getProblem());
|
(PopulationInterface)this.goParams.getOptimizer().getPopulation(),
|
||||||
if (m_ListenerModule != null) {
|
this.goParams.getProblem());
|
||||||
m_ListenerModule.updateProgress(
|
if (m_ListenerModule != null) {
|
||||||
getStatusPercent(
|
m_ListenerModule.updateProgress(
|
||||||
goParams.getOptimizer().getPopulation(),
|
getStatusPercent(
|
||||||
runCounter,
|
goParams.getOptimizer().getPopulation(),
|
||||||
m_Statistics.getStatisticsParameter().getMultiRuns()),
|
runCounter,
|
||||||
null);
|
m_Statistics.getStatisticsParameter().getMultiRuns()),
|
||||||
}
|
null);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method writes Data to file.
|
/** This method writes Data to file.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user