|
|
|
@@ -1,5 +1,6 @@
|
|
|
|
|
package eva2.server.modules;
|
|
|
|
|
|
|
|
|
|
import eva2.EvAInfo;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Vector;
|
|
|
|
|
|
|
|
|
@@ -31,6 +32,8 @@ import eva2.tools.EVAHELP;
|
|
|
|
|
import eva2.tools.StringTools;
|
|
|
|
|
import eva2.tools.jproxy.RemoteStateListener;
|
|
|
|
|
import eva2.tools.math.RNG;
|
|
|
|
|
import java.util.logging.Level;
|
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The Processor may run as a thread permanently (GenericModuleAdapter) and is then stopped and started
|
|
|
|
@@ -47,26 +50,25 @@ import eva2.tools.math.RNG;
|
|
|
|
|
*/
|
|
|
|
|
public class Processor extends Thread implements InterfaceProcessor, InterfacePopulationChangedEventListener {
|
|
|
|
|
|
|
|
|
|
private static final boolean TRACE=false;
|
|
|
|
|
private volatile boolean m_optRunning;
|
|
|
|
|
// private volatile boolean m_doRunScript;
|
|
|
|
|
private InterfaceStatistics m_Statistics;
|
|
|
|
|
private InterfaceGOParameters goParams;
|
|
|
|
|
private boolean m_createInitialPopulations = true;
|
|
|
|
|
private boolean saveParams = true;
|
|
|
|
|
private RemoteStateListener m_ListenerModule;
|
|
|
|
|
private boolean wasRestarted = false;
|
|
|
|
|
// private int postProcessSteps = 0;
|
|
|
|
|
private int runCounter = 0;
|
|
|
|
|
private Population resPop = null;
|
|
|
|
|
private boolean userAborted = false;
|
|
|
|
|
|
|
|
|
|
// transient private String m_OutputPath = "";
|
|
|
|
|
// transient private BufferedWriter m_OutputFile = null;
|
|
|
|
|
private static final Logger logger = Logger.getLogger(EvAInfo.defaultLogger);
|
|
|
|
|
private volatile boolean m_optRunning;
|
|
|
|
|
private InterfaceStatistics m_Statistics;
|
|
|
|
|
private InterfaceGOParameters goParams;
|
|
|
|
|
private boolean m_createInitialPopulations = true;
|
|
|
|
|
private boolean saveParams = true;
|
|
|
|
|
private RemoteStateListener m_ListenerModule;
|
|
|
|
|
private boolean wasRestarted = false;
|
|
|
|
|
private int runCounter = 0;
|
|
|
|
|
private Population resPop = null;
|
|
|
|
|
private boolean userAborted = false;
|
|
|
|
|
|
|
|
|
|
public void addListener(RemoteStateListener module) {
|
|
|
|
|
if (TRACE) System.out.println("Processor: setting module as listener: " + ((module==null) ? "null" : module.toString()));
|
|
|
|
|
m_ListenerModule = module;
|
|
|
|
|
logger.log(
|
|
|
|
|
Level.FINEST,
|
|
|
|
|
"Processor: setting module as listener: " + ((module == null)
|
|
|
|
|
? "null" : module.toString()));
|
|
|
|
|
|
|
|
|
|
m_ListenerModule = module;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@@ -76,25 +78,25 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
|
|
|
|
* @see InterfaceNotifyOnInformers
|
|
|
|
|
*/
|
|
|
|
|
public Processor(InterfaceStatistics Stat, ModuleAdapter Adapter, InterfaceGOParameters params) {
|
|
|
|
|
goParams = params;
|
|
|
|
|
m_Statistics = Stat;
|
|
|
|
|
m_ListenerModule = Adapter;
|
|
|
|
|
goParams = params;
|
|
|
|
|
m_Statistics = Stat;
|
|
|
|
|
m_ListenerModule = Adapter;
|
|
|
|
|
|
|
|
|
|
// the statistics want to be informed if the strategy or the optimizer (which provide statistical data as InterfaceAdditionalInformer) change.
|
|
|
|
|
if (Stat!=null && (params != null)) {
|
|
|
|
|
if (Stat.getStatisticsParameter() instanceof InterfaceNotifyOnInformers) {
|
|
|
|
|
// addition for the statistics revision with selectable strings - make sure the go parameters are represented within the statistics
|
|
|
|
|
params.addInformableInstance((InterfaceNotifyOnInformers)(Stat.getStatisticsParameter()));
|
|
|
|
|
}
|
|
|
|
|
if (Stat != null && (params != null)) {
|
|
|
|
|
if (Stat.getStatisticsParameter() instanceof InterfaceNotifyOnInformers) {
|
|
|
|
|
// addition for the statistics revision with selectable strings - make sure the go parameters are represented within the statistics
|
|
|
|
|
params.addInformableInstance((InterfaceNotifyOnInformers) (Stat.getStatisticsParameter()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isOptRunning() {
|
|
|
|
|
return m_optRunning;
|
|
|
|
|
return m_optRunning;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void setOptRunning(boolean bRun) {
|
|
|
|
|
m_optRunning = bRun;
|
|
|
|
|
m_optRunning = bRun;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@@ -103,7 +105,7 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
|
|
|
|
* @param doSave
|
|
|
|
|
*/
|
|
|
|
|
public void setSaveParams(boolean doSave) {
|
|
|
|
|
saveParams = doSave;
|
|
|
|
|
saveParams = doSave;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@@ -111,9 +113,8 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
|
|
|
|
*/
|
|
|
|
|
public void startOpt() {
|
|
|
|
|
m_createInitialPopulations = true;
|
|
|
|
|
if (TRACE) System.out.println("startOpt called:");
|
|
|
|
|
if (isOptRunning()) {
|
|
|
|
|
System.err.println("ERROR: Processor is already running !!");
|
|
|
|
|
logger.log(Level.SEVERE, "Processor is already running.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
resPop = null;
|
|
|
|
@@ -129,7 +130,7 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public boolean wasAborted() {
|
|
|
|
|
return userAborted;
|
|
|
|
|
return userAborted;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@@ -137,9 +138,8 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
|
|
|
|
*/
|
|
|
|
|
public void restartOpt() {
|
|
|
|
|
m_createInitialPopulations = false;
|
|
|
|
|
if (TRACE) System.out.println("restartOpt called:");
|
|
|
|
|
if (isOptRunning()) {
|
|
|
|
|
System.err.println("ERROR: Processor is already running !!");
|
|
|
|
|
logger.log(Level.SEVERE, "Processor is already running.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
userAborted = false;
|
|
|
|
@@ -151,58 +151,60 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public void stopOpt() { // this means user break
|
|
|
|
|
if (TRACE) System.out.println("called StopOpt");
|
|
|
|
|
setOptRunning(false);
|
|
|
|
|
if (TRACE) System.out.println("m_doRunScript = false ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public void run() {
|
|
|
|
|
setPriority(1);
|
|
|
|
|
while (true) {
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(200);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
System.err.println ("There was an error in sleep Processor.run()" + e);
|
|
|
|
|
}
|
|
|
|
|
runOptOnce();
|
|
|
|
|
}
|
|
|
|
|
setPriority(1);
|
|
|
|
|
while (true) {
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(200);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
System.err.println("There was an error in sleep Processor.run()" + e);
|
|
|
|
|
}
|
|
|
|
|
runOptOnce();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Population runOptOnce() {
|
|
|
|
|
try {
|
|
|
|
|
EVAERROR.clearMsgCache();
|
|
|
|
|
while (isOptRunning()) {
|
|
|
|
|
setPriority(3);
|
|
|
|
|
if (saveParams) {
|
|
|
|
|
try {
|
|
|
|
|
goParams.saveInstance();
|
|
|
|
|
} catch(Exception e) {
|
|
|
|
|
System.err.println("Error on saveInstance!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
resPop = optimize("Run");
|
|
|
|
|
setPriority(1);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
String errMsg = e.toString();
|
|
|
|
|
if ((errMsg == null) || (errMsg.length() == 0)) errMsg="check console output for error messages.";
|
|
|
|
|
errMsg = "Exception in Processor: "+errMsg;
|
|
|
|
|
System.err.println(errMsg);
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
try {
|
|
|
|
|
JOptionPane.showMessageDialog(null, StringTools.wrapLine(errMsg, 60, 0.2), "Error in Optimization", JOptionPane.ERROR_MESSAGE);
|
|
|
|
|
} catch (Exception ex) {} catch(Error er) {};
|
|
|
|
|
//m_Statistics.stopOptPerformed(false);
|
|
|
|
|
setOptRunning(false); // normal finish
|
|
|
|
|
if (m_ListenerModule!=null) {
|
|
|
|
|
m_ListenerModule.performedStop(); // is only needed in client server mode
|
|
|
|
|
m_ListenerModule.updateProgress(0, errMsg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return resPop;
|
|
|
|
|
try {
|
|
|
|
|
EVAERROR.clearMsgCache();
|
|
|
|
|
while (isOptRunning()) {
|
|
|
|
|
setPriority(3);
|
|
|
|
|
if (saveParams) {
|
|
|
|
|
try {
|
|
|
|
|
goParams.saveInstance();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
System.err.println("Error on saveInstance!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
resPop = optimize("Run");
|
|
|
|
|
setPriority(1);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
String errMsg = e.toString();
|
|
|
|
|
if ((errMsg == null) || (errMsg.length() == 0)) {
|
|
|
|
|
errMsg = "check console output for error messages.";
|
|
|
|
|
}
|
|
|
|
|
errMsg = "Exception in Processor: " + errMsg;
|
|
|
|
|
System.err.println(errMsg);
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
try {
|
|
|
|
|
JOptionPane.showMessageDialog(null, StringTools.wrapLine(errMsg, 60, 0.2), "Error in Optimization", JOptionPane.ERROR_MESSAGE);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
} catch (Error er) {
|
|
|
|
|
};
|
|
|
|
|
//m_Statistics.stopOptPerformed(false);
|
|
|
|
|
setOptRunning(false); // normal finish
|
|
|
|
|
if (m_ListenerModule != null) {
|
|
|
|
|
m_ListenerModule.performedStop(); // is only needed in client server mode
|
|
|
|
|
m_ListenerModule.updateProgress(0, errMsg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return resPop;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@@ -210,125 +212,146 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
|
|
|
|
* Return a population containing the solutions of the last run if there were multiple.
|
|
|
|
|
*/
|
|
|
|
|
protected Population optimize(String infoString) {
|
|
|
|
|
Population resultPop = null;
|
|
|
|
|
Population resultPop = null;
|
|
|
|
|
|
|
|
|
|
if (!isOptRunning()) {
|
|
|
|
|
System.err.println("warning, this shouldnt happen in processor! Was startOpt called?");
|
|
|
|
|
setOptRunning(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RNG.setRandomSeed(goParams.getSeed());
|
|
|
|
|
|
|
|
|
|
if (m_ListenerModule!=null) {
|
|
|
|
|
if (wasRestarted) m_ListenerModule.performedRestart(getInfoString());
|
|
|
|
|
else m_ListenerModule.performedStart(getInfoString());
|
|
|
|
|
if (!isOptRunning()) {
|
|
|
|
|
System.err.println("warning, this shouldnt happen in processor! Was startOpt called?");
|
|
|
|
|
setOptRunning(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
goParams.getOptimizer().addPopulationChangedEventListener(this);
|
|
|
|
|
RNG.setRandomSeed(goParams.getSeed());
|
|
|
|
|
|
|
|
|
|
if (m_ListenerModule != null) {
|
|
|
|
|
if (wasRestarted) {
|
|
|
|
|
m_ListenerModule.performedRestart(getInfoString());
|
|
|
|
|
} else {
|
|
|
|
|
m_ListenerModule.performedStart(getInfoString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
goParams.getOptimizer().addPopulationChangedEventListener(this);
|
|
|
|
|
|
|
|
|
|
runCounter = 0;
|
|
|
|
|
String popLog = null; //"populationLog.txt";
|
|
|
|
|
|
|
|
|
|
while (isOptRunning() && (runCounter<m_Statistics.getStatisticsParameter().getMultiRuns())) {
|
|
|
|
|
m_Statistics.startOptPerformed(getInfoString(),runCounter, goParams, getInformerList());
|
|
|
|
|
while (isOptRunning() && (runCounter < m_Statistics.getStatisticsParameter().getMultiRuns())) {
|
|
|
|
|
m_Statistics.startOptPerformed(getInfoString(), runCounter, goParams, getInformerList());
|
|
|
|
|
|
|
|
|
|
this.goParams.getProblem().initProblem();
|
|
|
|
|
this.goParams.getOptimizer().SetProblem(this.goParams.getProblem());
|
|
|
|
|
this.goParams.getTerminator().init(this.goParams.getProblem());
|
|
|
|
|
maybeInitParamCtrl(goParams);
|
|
|
|
|
if (this.m_createInitialPopulations) this.goParams.getOptimizer().init();
|
|
|
|
|
this.goParams.getProblem().initProblem();
|
|
|
|
|
this.goParams.getOptimizer().SetProblem(this.goParams.getProblem());
|
|
|
|
|
this.goParams.getTerminator().init(this.goParams.getProblem());
|
|
|
|
|
maybeInitParamCtrl(goParams);
|
|
|
|
|
if (this.m_createInitialPopulations) {
|
|
|
|
|
this.goParams.getOptimizer().init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//m_Statistics.createNextGenerationPerformed((PopulationInterface)this.m_ModulParameter.getOptimizer().getPopulation());
|
|
|
|
|
if (m_ListenerModule!=null) m_ListenerModule.updateProgress(getStatusPercent(goParams.getOptimizer().getPopulation(), runCounter, m_Statistics.getStatisticsParameter().getMultiRuns()), null);
|
|
|
|
|
if (popLog != null) EVAHELP.clearLog(popLog);
|
|
|
|
|
//m_Statistics.createNextGenerationPerformed((PopulationInterface)this.m_ModulParameter.getOptimizer().getPopulation());
|
|
|
|
|
if (m_ListenerModule != null) {
|
|
|
|
|
m_ListenerModule.updateProgress(getStatusPercent(goParams.getOptimizer().getPopulation(), runCounter, m_Statistics.getStatisticsParameter().getMultiRuns()), null);
|
|
|
|
|
}
|
|
|
|
|
if (popLog != null) {
|
|
|
|
|
EVAHELP.clearLog(popLog);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
do { // main loop
|
|
|
|
|
maybeUpdateParamCtrl(goParams);
|
|
|
|
|
do { // main loop
|
|
|
|
|
maybeUpdateParamCtrl(goParams);
|
|
|
|
|
|
|
|
|
|
this.goParams.getOptimizer().optimize();
|
|
|
|
|
// registerPopulationStateChanged *SHOULD* be fired by the optimizer or resp. the population
|
|
|
|
|
// as we are event listener
|
|
|
|
|
if (popLog != null) EVAHELP.logString(this.goParams.getOptimizer().getPopulation().getIndyList(), popLog);
|
|
|
|
|
} while (isOptRunning() && !this.goParams.getTerminator().isTerminated(this.goParams.getOptimizer().getAllSolutions()));
|
|
|
|
|
runCounter++;
|
|
|
|
|
maybeFinishParamCtrl(goParams);
|
|
|
|
|
userAborted = !isOptRunning(); // stop is "normal" if opt wasnt set false by the user (and thus still true)
|
|
|
|
|
//////////////// Default stats
|
|
|
|
|
m_Statistics.stopOptPerformed(!userAborted, goParams.getTerminator().lastTerminationMessage()); // stop is "normal" if opt wasnt set false by the user (and thus still true)
|
|
|
|
|
this.goParams.getOptimizer().optimize();
|
|
|
|
|
// registerPopulationStateChanged *SHOULD* be fired by the optimizer or resp. the population
|
|
|
|
|
// as we are event listener
|
|
|
|
|
if (popLog != null) {
|
|
|
|
|
EVAHELP.logString(this.goParams.getOptimizer().getPopulation().getIndyList(), popLog);
|
|
|
|
|
}
|
|
|
|
|
} while (isOptRunning() && !this.goParams.getTerminator().isTerminated(this.goParams.getOptimizer().getAllSolutions()));
|
|
|
|
|
runCounter++;
|
|
|
|
|
maybeFinishParamCtrl(goParams);
|
|
|
|
|
userAborted = !isOptRunning(); // stop is "normal" if opt wasnt set false by the user (and thus still true)
|
|
|
|
|
//////////////// Default stats
|
|
|
|
|
m_Statistics.stopOptPerformed(!userAborted, goParams.getTerminator().lastTerminationMessage()); // stop is "normal" if opt wasnt set false by the user (and thus still true)
|
|
|
|
|
|
|
|
|
|
//////////////// PP or set results without further PP
|
|
|
|
|
if (!userAborted) {
|
|
|
|
|
resultPop = performPostProcessing();
|
|
|
|
|
if (resultPop==null) { // post processing disabled, so use opt. solutions
|
|
|
|
|
resultPop = goParams.getOptimizer().getAllSolutions().getSolutions();
|
|
|
|
|
}
|
|
|
|
|
} else resultPop = goParams.getOptimizer().getAllSolutions().getSolutions();
|
|
|
|
|
m_Statistics.postProcessingPerformed(resultPop);
|
|
|
|
|
//////////////// PP or set results without further PP
|
|
|
|
|
if (!userAborted) {
|
|
|
|
|
resultPop = performPostProcessing();
|
|
|
|
|
if (resultPop == null) { // post processing disabled, so use opt. solutions
|
|
|
|
|
resultPop = goParams.getOptimizer().getAllSolutions().getSolutions();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
resultPop = goParams.getOptimizer().getAllSolutions().getSolutions();
|
|
|
|
|
}
|
|
|
|
|
m_Statistics.postProcessingPerformed(resultPop);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
setOptRunning(false); // normal finish
|
|
|
|
|
if (m_ListenerModule!=null) m_ListenerModule.performedStop(); // is only needed in client server mode
|
|
|
|
|
if (m_ListenerModule!=null) m_ListenerModule.updateProgress(0, null);
|
|
|
|
|
if (m_ListenerModule != null) {
|
|
|
|
|
m_ListenerModule.performedStop(); // is only needed in client server mode
|
|
|
|
|
}
|
|
|
|
|
if (m_ListenerModule != null) {
|
|
|
|
|
m_ListenerModule.updateProgress(0, null);
|
|
|
|
|
}
|
|
|
|
|
goParams.getOptimizer().removePopulationChangedEventListener(this);
|
|
|
|
|
return resultPop;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void iterateParamCtrl(Object instance, String methodName, Object[] args) {
|
|
|
|
|
Object paramCtrlReturn=null;
|
|
|
|
|
if (null!=(paramCtrlReturn=BeanInspector.callIfAvailable(instance, "getParamControl", null))) {
|
|
|
|
|
if (paramCtrlReturn instanceof Object[]) {
|
|
|
|
|
Object[] controllersOrSubControllables = (Object[])paramCtrlReturn;
|
|
|
|
|
for (Object controllerOrSubControllable : controllersOrSubControllables) {
|
|
|
|
|
// The returned array may contain (i) InterfaceParameterControl associated with the instance
|
|
|
|
|
// itself or (ii) sub-instances which have their own parameter controls. On these, the method
|
|
|
|
|
// is called recursively.
|
|
|
|
|
if (controllerOrSubControllable instanceof InterfaceParameterControl) {
|
|
|
|
|
args[0]=instance;
|
|
|
|
|
if (!((InterfaceParameterControl)controllerOrSubControllable instanceof ConstantParameters))
|
|
|
|
|
BeanInspector.callIfAvailable((InterfaceParameterControl)controllerOrSubControllable, methodName, args);
|
|
|
|
|
} else {
|
|
|
|
|
args[0]=controllerOrSubControllable;
|
|
|
|
|
iterateParamCtrl(controllerOrSubControllable, methodName, args);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (paramCtrlReturn instanceof InterfaceParameterControl) {
|
|
|
|
|
if (!((InterfaceParameterControl)paramCtrlReturn instanceof ConstantParameters))
|
|
|
|
|
BeanInspector.callIfAvailable((InterfaceParameterControl)paramCtrlReturn, methodName, args);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Object paramCtrlReturn = null;
|
|
|
|
|
if (null != (paramCtrlReturn = BeanInspector.callIfAvailable(instance, "getParamControl", null))) {
|
|
|
|
|
if (paramCtrlReturn instanceof Object[]) {
|
|
|
|
|
Object[] controllersOrSubControllables = (Object[]) paramCtrlReturn;
|
|
|
|
|
for (Object controllerOrSubControllable : controllersOrSubControllables) {
|
|
|
|
|
// The returned array may contain (i) InterfaceParameterControl associated with the instance
|
|
|
|
|
// itself or (ii) sub-instances which have their own parameter controls. On these, the method
|
|
|
|
|
// is called recursively.
|
|
|
|
|
if (controllerOrSubControllable instanceof InterfaceParameterControl) {
|
|
|
|
|
args[0] = instance;
|
|
|
|
|
if (!((InterfaceParameterControl) controllerOrSubControllable instanceof ConstantParameters)) {
|
|
|
|
|
BeanInspector.callIfAvailable((InterfaceParameterControl) controllerOrSubControllable, methodName, args);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
args[0] = controllerOrSubControllable;
|
|
|
|
|
iterateParamCtrl(controllerOrSubControllable, methodName, args);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (paramCtrlReturn instanceof InterfaceParameterControl) {
|
|
|
|
|
if (!((InterfaceParameterControl) paramCtrlReturn instanceof ConstantParameters)) {
|
|
|
|
|
BeanInspector.callIfAvailable((InterfaceParameterControl) paramCtrlReturn, methodName, args);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void maybeInitParamCtrl(InterfaceGOParameters goParams) {
|
|
|
|
|
iterateParamCtrl(goParams.getOptimizer(), "init", new Object[]{goParams.getOptimizer(), goParams.getOptimizer().getPopulation()});
|
|
|
|
|
iterateParamCtrl(goParams.getProblem(), "init", new Object[]{goParams.getProblem(), goParams.getOptimizer().getPopulation()});
|
|
|
|
|
}
|
|
|
|
|
iterateParamCtrl(goParams.getOptimizer(), "init", new Object[]{goParams.getOptimizer(), goParams.getOptimizer().getPopulation()});
|
|
|
|
|
iterateParamCtrl(goParams.getProblem(), "init", new Object[]{goParams.getProblem(), goParams.getOptimizer().getPopulation()});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void maybeFinishParamCtrl(InterfaceGOParameters goParams) {
|
|
|
|
|
iterateParamCtrl(goParams.getOptimizer(), "finish", new Object[]{goParams.getOptimizer(), goParams.getOptimizer().getPopulation()});
|
|
|
|
|
iterateParamCtrl(goParams.getProblem(), "finish", new Object[]{goParams.getProblem(), goParams.getOptimizer().getPopulation()});
|
|
|
|
|
}
|
|
|
|
|
iterateParamCtrl(goParams.getOptimizer(), "finish", new Object[]{goParams.getOptimizer(), goParams.getOptimizer().getPopulation()});
|
|
|
|
|
iterateParamCtrl(goParams.getProblem(), "finish", new Object[]{goParams.getProblem(), goParams.getOptimizer().getPopulation()});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void maybeUpdateParamCtrl(InterfaceGOParameters goParams) {
|
|
|
|
|
Object[] args;
|
|
|
|
|
InterfaceTerminator terminator = goParams.getTerminator();
|
|
|
|
|
InterfaceOptimizer optimizer = goParams.getOptimizer();
|
|
|
|
|
if (terminator instanceof GenerationTerminator)
|
|
|
|
|
args = new Object[]{optimizer, optimizer.getPopulation(), optimizer.getPopulation().getGeneration(), ((GenerationTerminator)terminator).getGenerations()};
|
|
|
|
|
// ((InterfaceParameterControl)paramCtrl).updateParameters(optimizer, optimizer.getPopulation().getGeneration(), ((GenerationTerminator)terminator).getGenerations());
|
|
|
|
|
else if (terminator instanceof EvaluationTerminator)
|
|
|
|
|
args = new Object[] {optimizer, optimizer.getPopulation(), optimizer.getPopulation().getFunctionCalls(), ((EvaluationTerminator)terminator).getFitnessCalls()};
|
|
|
|
|
// ((InterfaceParameterControl)paramCtrl).updateParameters(optimizer, optimizer.getPopulation().getFunctionCalls(), ((EvaluationTerminator)terminator).getFitnessCalls());
|
|
|
|
|
else args = new Object[]{optimizer};
|
|
|
|
|
Object[] args;
|
|
|
|
|
InterfaceTerminator terminator = goParams.getTerminator();
|
|
|
|
|
InterfaceOptimizer optimizer = goParams.getOptimizer();
|
|
|
|
|
if (terminator instanceof GenerationTerminator) {
|
|
|
|
|
args = new Object[]{optimizer, optimizer.getPopulation(), optimizer.getPopulation().getGeneration(), ((GenerationTerminator) terminator).getGenerations()};
|
|
|
|
|
} // ((InterfaceParameterControl)paramCtrl).updateParameters(optimizer, optimizer.getPopulation().getGeneration(), ((GenerationTerminator)terminator).getGenerations());
|
|
|
|
|
else if (terminator instanceof EvaluationTerminator) {
|
|
|
|
|
args = new Object[]{optimizer, optimizer.getPopulation(), optimizer.getPopulation().getFunctionCalls(), ((EvaluationTerminator) terminator).getFitnessCalls()};
|
|
|
|
|
} // ((InterfaceParameterControl)paramCtrl).updateParameters(optimizer, optimizer.getPopulation().getFunctionCalls(), ((EvaluationTerminator)terminator).getFitnessCalls());
|
|
|
|
|
else {
|
|
|
|
|
args = new Object[]{optimizer};
|
|
|
|
|
}
|
|
|
|
|
// ((InterfaceParameterControl)paramCtrl).updateParameters(optimizer);
|
|
|
|
|
|
|
|
|
|
if (args != null) { // only if iteration counting is available
|
|
|
|
|
iterateParamCtrl(optimizer, "updateParameters", args);
|
|
|
|
|
args[0]=goParams.getProblem();
|
|
|
|
|
iterateParamCtrl(goParams.getProblem(), "updateParameters", args);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (args != null) { // only if iteration counting is available
|
|
|
|
|
iterateParamCtrl(optimizer, "updateParameters", args);
|
|
|
|
|
args[0] = goParams.getProblem();
|
|
|
|
|
iterateParamCtrl(goParams.getProblem(), "updateParameters", args);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
/**
|
|
|
|
|
* Calculate the percentage of current (multi-)run already performed, based on evaluations/generations
|
|
|
|
|
* for the EvaluationTerminator/GenerationTerminator or multi-runs only.
|
|
|
|
|
*
|
|
|
|
@@ -338,16 +361,18 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
|
|
|
|
* @return the percentage of current (multi-)run already performed
|
|
|
|
|
*/
|
|
|
|
|
private int getStatusPercent(Population pop, int currentRun, int multiRuns) {
|
|
|
|
|
double percentPerRun = 100./multiRuns;
|
|
|
|
|
int curProgress;
|
|
|
|
|
if (this.goParams.getTerminator() instanceof EvaluationTerminator) {
|
|
|
|
|
double curRunPerf = pop.getFunctionCalls()*percentPerRun/(double)((EvaluationTerminator)this.goParams.getTerminator()).getFitnessCalls();
|
|
|
|
|
curProgress = (int)(currentRun * percentPerRun + curRunPerf);
|
|
|
|
|
} else if (this.goParams.getTerminator() instanceof GenerationTerminator) {
|
|
|
|
|
double curRunPerf = pop.getGeneration()*percentPerRun/(double)((GenerationTerminator)this.goParams.getTerminator()).getGenerations();
|
|
|
|
|
curProgress = (int)(currentRun * percentPerRun + curRunPerf);
|
|
|
|
|
} else curProgress = (int)(currentRun * percentPerRun);
|
|
|
|
|
return curProgress;
|
|
|
|
|
double percentPerRun = 100. / multiRuns;
|
|
|
|
|
int curProgress;
|
|
|
|
|
if (this.goParams.getTerminator() instanceof EvaluationTerminator) {
|
|
|
|
|
double curRunPerf = pop.getFunctionCalls() * percentPerRun / (double) ((EvaluationTerminator) this.goParams.getTerminator()).getFitnessCalls();
|
|
|
|
|
curProgress = (int) (currentRun * percentPerRun + curRunPerf);
|
|
|
|
|
} else if (this.goParams.getTerminator() instanceof GenerationTerminator) {
|
|
|
|
|
double curRunPerf = pop.getGeneration() * percentPerRun / (double) ((GenerationTerminator) this.goParams.getTerminator()).getGenerations();
|
|
|
|
|
curProgress = (int) (currentRun * percentPerRun + curRunPerf);
|
|
|
|
|
} else {
|
|
|
|
|
curProgress = (int) (currentRun * percentPerRun);
|
|
|
|
|
}
|
|
|
|
|
return curProgress;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@@ -357,28 +382,30 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
|
|
|
|
* @param name Could be used to indicate the nature of the event.
|
|
|
|
|
*/
|
|
|
|
|
public void registerPopulationStateChanged(Object source, String name) {
|
|
|
|
|
if (name.equals(Population.nextGenerationPerformed)) {
|
|
|
|
|
if (name.equals(Population.nextGenerationPerformed)) {
|
|
|
|
|
// System.out.println(getGOParams().getOptimizer().getPopulation().getFunctionCalls() + " " + getGOParams().getOptimizer().getPopulation().getBestFitness()[0]);
|
|
|
|
|
m_Statistics.createNextGenerationPerformed(
|
|
|
|
|
(PopulationInterface)this.goParams.getOptimizer().getPopulation(),
|
|
|
|
|
this.goParams.getOptimizer(),
|
|
|
|
|
getInformerList());
|
|
|
|
|
if (m_ListenerModule != null) {
|
|
|
|
|
m_ListenerModule.updateProgress(
|
|
|
|
|
getStatusPercent(
|
|
|
|
|
goParams.getOptimizer().getPopulation(),
|
|
|
|
|
runCounter,
|
|
|
|
|
m_Statistics.getStatisticsParameter().getMultiRuns()),
|
|
|
|
|
null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_Statistics.createNextGenerationPerformed(
|
|
|
|
|
(PopulationInterface) this.goParams.getOptimizer().getPopulation(),
|
|
|
|
|
this.goParams.getOptimizer(),
|
|
|
|
|
getInformerList());
|
|
|
|
|
if (m_ListenerModule != null) {
|
|
|
|
|
m_ListenerModule.updateProgress(
|
|
|
|
|
getStatusPercent(
|
|
|
|
|
goParams.getOptimizer().getPopulation(),
|
|
|
|
|
runCounter,
|
|
|
|
|
m_Statistics.getStatisticsParameter().getMultiRuns()),
|
|
|
|
|
null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected List<InterfaceAdditionalPopulationInformer> getInformerList() {
|
|
|
|
|
Vector<InterfaceAdditionalPopulationInformer> informerList = new Vector<InterfaceAdditionalPopulationInformer>(2);
|
|
|
|
|
informerList.add(this.goParams.getProblem());
|
|
|
|
|
if (this.goParams.getOptimizer() instanceof InterfaceAdditionalPopulationInformer) informerList.add((InterfaceAdditionalPopulationInformer)this.goParams.getOptimizer());
|
|
|
|
|
return informerList;
|
|
|
|
|
Vector<InterfaceAdditionalPopulationInformer> informerList = new Vector<InterfaceAdditionalPopulationInformer>(2);
|
|
|
|
|
informerList.add(this.goParams.getProblem());
|
|
|
|
|
if (this.goParams.getOptimizer() instanceof InterfaceAdditionalPopulationInformer) {
|
|
|
|
|
informerList.add((InterfaceAdditionalPopulationInformer) this.goParams.getOptimizer());
|
|
|
|
|
}
|
|
|
|
|
return informerList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** This method writes Data to file.
|
|
|
|
@@ -395,18 +422,17 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
|
|
|
|
// System.err.println("Problems writing to output file!");
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
public String getInfoString() {
|
|
|
|
|
//StringBuffer sb = new StringBuffer("processing ");
|
|
|
|
|
StringBuffer sb = new StringBuffer(this.goParams.getProblem().getName());
|
|
|
|
|
sb.append("+");
|
|
|
|
|
sb.append(this.goParams.getOptimizer().getName());
|
|
|
|
|
// commented out because the number of multi-runs can be changed after start
|
|
|
|
|
// so it might create misinformation (would still be the user's fault, though)
|
|
|
|
|
//StringBuffer sb = new StringBuffer("processing ");
|
|
|
|
|
StringBuilder sb = new StringBuilder(this.goParams.getProblem().getName());
|
|
|
|
|
sb.append("+");
|
|
|
|
|
sb.append(this.goParams.getOptimizer().getName());
|
|
|
|
|
// commented out because the number of multi-runs can be changed after start
|
|
|
|
|
// so it might create misinformation (would still be the user's fault, though)
|
|
|
|
|
// sb.append(" for ");
|
|
|
|
|
// sb.append(m_Statistics.getStatistisParameter().getMultiRuns());
|
|
|
|
|
// sb.append(" runs");
|
|
|
|
|
return sb.toString();
|
|
|
|
|
return sb.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@@ -422,9 +448,13 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
|
|
|
|
public InterfaceGOParameters getGOParams() {
|
|
|
|
|
return goParams;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setGOParams(InterfaceGOParameters params) {
|
|
|
|
|
if (params!=null) goParams= params;
|
|
|
|
|
else System.err.println("Setting parameters failed (parameters were null) (Processor.setGOParams)");
|
|
|
|
|
if (params != null) {
|
|
|
|
|
goParams = params;
|
|
|
|
|
} else {
|
|
|
|
|
System.err.println("Setting parameters failed (parameters were null) (Processor.setGOParams)");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@@ -433,11 +463,11 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
|
|
|
|
* @return the last solution population or null
|
|
|
|
|
*/
|
|
|
|
|
public Population getResultPopulation() {
|
|
|
|
|
return resPop;
|
|
|
|
|
return resPop;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Population performPostProcessing() {
|
|
|
|
|
return performPostProcessing((PostProcessParams)goParams.getPostProcessParams(), (InterfaceTextListener)m_Statistics);
|
|
|
|
|
return performPostProcessing((PostProcessParams) goParams.getPostProcessParams(), (InterfaceTextListener) m_Statistics);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@@ -448,31 +478,35 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
|
|
|
|
* @param listener
|
|
|
|
|
*/
|
|
|
|
|
public Population performPostProcessing(PostProcessParams ppp, InterfaceTextListener listener) {
|
|
|
|
|
if (ppp.isDoPostProcessing()) {
|
|
|
|
|
if (listener != null) {
|
|
|
|
|
listener.println("Post processing params: " + BeanInspector.toString(ppp));
|
|
|
|
|
// if textwindow was closed, check if it should be reopened for pp
|
|
|
|
|
if (m_Statistics instanceof StatisticsWithGUI) ((StatisticsWithGUI)m_Statistics).maybeShowProxyPrinter();
|
|
|
|
|
}
|
|
|
|
|
Population resultPop = (Population)(goParams.getOptimizer().getAllSolutions().getSolutions().clone());
|
|
|
|
|
if (resultPop.getFunctionCalls() != goParams.getOptimizer().getPopulation().getFunctionCalls()) {
|
|
|
|
|
// System.err.println("bad case in Processor::performNewPostProcessing ");
|
|
|
|
|
resultPop.SetFunctionCalls(goParams.getOptimizer().getPopulation().getFunctionCalls());
|
|
|
|
|
}
|
|
|
|
|
if (ppp.isDoPostProcessing()) {
|
|
|
|
|
if (listener != null) {
|
|
|
|
|
listener.println("Post processing params: " + BeanInspector.toString(ppp));
|
|
|
|
|
// if textwindow was closed, check if it should be reopened for pp
|
|
|
|
|
if (m_Statistics instanceof StatisticsWithGUI) {
|
|
|
|
|
((StatisticsWithGUI) m_Statistics).maybeShowProxyPrinter();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Population resultPop = (Population) (goParams.getOptimizer().getAllSolutions().getSolutions().clone());
|
|
|
|
|
if (resultPop.getFunctionCalls() != goParams.getOptimizer().getPopulation().getFunctionCalls()) {
|
|
|
|
|
// System.err.println("bad case in Processor::performNewPostProcessing ");
|
|
|
|
|
resultPop.SetFunctionCalls(goParams.getOptimizer().getPopulation().getFunctionCalls());
|
|
|
|
|
}
|
|
|
|
|
// if (!resultPop.contains(m_Statistics.getBestSolution())) {
|
|
|
|
|
// resultPop.add(m_Statistics.getBestSolution());
|
|
|
|
|
// this is a minor cheat but guarantees that the best solution ever found is contained in the final results
|
|
|
|
|
// This was evil in case multiple runs were performed with PP, because the best of an earlier run is added which is confusing.
|
|
|
|
|
// the minor cheat should not be necessary anymore anyways, since the getAllSolutions() variant replaced the earlier getPopulation() call
|
|
|
|
|
// this is a minor cheat but guarantees that the best solution ever found is contained in the final results
|
|
|
|
|
// This was evil in case multiple runs were performed with PP, because the best of an earlier run is added which is confusing.
|
|
|
|
|
// the minor cheat should not be necessary anymore anyways, since the getAllSolutions() variant replaced the earlier getPopulation() call
|
|
|
|
|
// resultPop.synchSize();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
PostProcess.checkAccuracy((AbstractOptimizationProblem)goParams.getProblem(), resultPop, ppp.getAccuracies(), ppp.getAccAssumeConv(),
|
|
|
|
|
-1, ppp.getAccMaxEval(), (SolutionHistogram[]) null, true, listener);
|
|
|
|
|
PostProcess.checkAccuracy((AbstractOptimizationProblem) goParams.getProblem(), resultPop, ppp.getAccuracies(), ppp.getAccAssumeConv(),
|
|
|
|
|
-1, ppp.getAccMaxEval(), (SolutionHistogram[]) null, true, listener);
|
|
|
|
|
|
|
|
|
|
resultPop = PostProcess.postProcess(ppp, resultPop, (AbstractOptimizationProblem)goParams.getProblem(), listener);
|
|
|
|
|
resPop = resultPop;
|
|
|
|
|
return resultPop;
|
|
|
|
|
} else return null;
|
|
|
|
|
resultPop = PostProcess.postProcess(ppp, resultPop, (AbstractOptimizationProblem) goParams.getProblem(), listener);
|
|
|
|
|
resPop = resultPop;
|
|
|
|
|
return resultPop;
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|