Cleaner code.
This commit is contained in:
parent
049304e9c1
commit
b77cda3046
@ -192,7 +192,7 @@ public abstract class AbstractOptimizationParameters implements InterfaceOptimiz
|
||||
|
||||
private List<InterfaceAdditionalPopulationInformer> getInformerList() {
|
||||
LinkedList<InterfaceAdditionalPopulationInformer> ret = new LinkedList<>();
|
||||
if (problem instanceof InterfaceAdditionalPopulationInformer) {
|
||||
if (problem != null) {
|
||||
ret.add(problem);
|
||||
}
|
||||
if (optimizer instanceof InterfaceAdditionalPopulationInformer) {
|
||||
|
@ -28,9 +28,8 @@ public class OptimizationParameters extends AbstractOptimizationParameters imple
|
||||
|
||||
/**
|
||||
* Should be removed and replaced by a more solid
|
||||
* serialization. (EvAScript?)
|
||||
* serialization.
|
||||
*
|
||||
* @deprecated
|
||||
* @return
|
||||
*/
|
||||
public static OptimizationParameters getInstance() {
|
||||
|
@ -187,7 +187,7 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
||||
LOGGER.log(Level.SEVERE, errMsg, e);
|
||||
try {
|
||||
JOptionPane.showMessageDialog(null, StringTools.wrapLine(errMsg, 60, 0.2), "Error in Optimization", JOptionPane.ERROR_MESSAGE);
|
||||
} catch (Exception | Error ex) {
|
||||
} catch (Exception | Error ignored) {
|
||||
}
|
||||
//statistics.stopOptimizationPerformed(false);
|
||||
setOptimizationRunning(false); // normal finish
|
||||
@ -221,10 +221,13 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
||||
}
|
||||
}
|
||||
|
||||
optimizationParameters.getOptimizer().addPopulationChangedEventListener(this);
|
||||
|
||||
runCounter = 0;
|
||||
|
||||
InterfaceTerminator terminator = this.optimizationParameters.getTerminator();
|
||||
InterfaceOptimizer optimizer = this.optimizationParameters.getOptimizer();
|
||||
InterfaceOptimizationProblem problem = this.optimizationParameters.getProblem();
|
||||
|
||||
optimizer.addPopulationChangedEventListener(this);
|
||||
/**
|
||||
* We keep the optimization running until it is aborted by the user or
|
||||
* the number of multiple runs has been reached.
|
||||
@ -233,16 +236,17 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
||||
LOGGER.info(String.format("Starting Optimization %d/%d", runCounter + 1, statistics.getStatisticsParameter().getMultiRuns()));
|
||||
statistics.startOptimizationPerformed(getInfoString(), runCounter, optimizationParameters, getInformerList());
|
||||
|
||||
this.optimizationParameters.getProblem().initializeProblem();
|
||||
this.optimizationParameters.getOptimizer().setProblem(this.optimizationParameters.getProblem());
|
||||
this.optimizationParameters.getTerminator().initialize(this.optimizationParameters.getProblem());
|
||||
problem.initializeProblem();
|
||||
optimizer.setProblem(problem);
|
||||
terminator.initialize(problem);
|
||||
|
||||
maybeInitParamCtrl(optimizationParameters);
|
||||
if (this.createInitialPopulations) {
|
||||
this.optimizationParameters.getOptimizer().initialize();
|
||||
optimizer.initialize();
|
||||
}
|
||||
|
||||
if (optimizationStateListener != null) {
|
||||
optimizationStateListener.updateProgress(getStatusPercent(optimizationParameters.getOptimizer().getPopulation(), runCounter, statistics.getStatisticsParameter().getMultiRuns()), null);
|
||||
optimizationStateListener.updateProgress(getStatusPercent(optimizer.getPopulation(), runCounter, statistics.getStatisticsParameter().getMultiRuns()), null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -253,23 +257,23 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
||||
do {
|
||||
maybeUpdateParamCtrl(optimizationParameters);
|
||||
|
||||
this.optimizationParameters.getOptimizer().optimize();
|
||||
} while (isOptimizationRunning() && !this.optimizationParameters.getTerminator().isTerminated(this.optimizationParameters.getOptimizer().getAllSolutions()));
|
||||
optimizer.optimize();
|
||||
} while (isOptimizationRunning() && !terminator.isTerminated(optimizer.getAllSolutions()));
|
||||
|
||||
runCounter++;
|
||||
maybeFinishParamCtrl(optimizationParameters);
|
||||
userAborted = !isOptimizationRunning(); // stop is "normal" if opt wasnt set false by the user (and thus still true)
|
||||
//////////////// Default stats
|
||||
statistics.stopOptimizationPerformed(!userAborted, optimizationParameters.getTerminator().lastTerminationMessage()); // stop is "normal" if opt wasnt set false by the user (and thus still true)
|
||||
statistics.stopOptimizationPerformed(!userAborted, terminator.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 = optimizationParameters.getOptimizer().getAllSolutions().getSolutions();
|
||||
resultPop = optimizer.getAllSolutions().getSolutions();
|
||||
}
|
||||
} else {
|
||||
resultPop = optimizationParameters.getOptimizer().getAllSolutions().getSolutions();
|
||||
resultPop = optimizer.getAllSolutions().getSolutions();
|
||||
}
|
||||
statistics.postProcessingPerformed(resultPop);
|
||||
|
||||
@ -281,7 +285,7 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
||||
if (optimizationStateListener != null) {
|
||||
optimizationStateListener.updateProgress(0, null);
|
||||
}
|
||||
optimizationParameters.getOptimizer().removePopulationChangedEventListener(this);
|
||||
optimizer.removePopulationChangedEventListener(this);
|
||||
return resultPop;
|
||||
}
|
||||
|
||||
@ -334,11 +338,10 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
||||
args = new Object[]{optimizer};
|
||||
}
|
||||
|
||||
if (args != null) { // only if iteration counting is available
|
||||
iterateParamCtrl(optimizer, "updateParameters", args);
|
||||
args[0] = goParams.getProblem();
|
||||
iterateParamCtrl(goParams.getProblem(), "updateParameters", args);
|
||||
}
|
||||
// only if iteration counting is available
|
||||
iterateParamCtrl(optimizer, "updateParameters", args);
|
||||
args[0] = goParams.getProblem();
|
||||
iterateParamCtrl(goParams.getProblem(), "updateParameters", args);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -17,9 +17,6 @@ public interface InterfaceStatisticsParameters {
|
||||
|
||||
int getMultiRuns();
|
||||
|
||||
String multiRunsTipText();
|
||||
|
||||
|
||||
/**
|
||||
* Use averaged graph for multi-run plots or not.
|
||||
*
|
||||
|
@ -57,7 +57,7 @@ public class StatisticsParameters implements InterfaceStatisticsParameters, Inte
|
||||
*/
|
||||
public static StatisticsParameters getInstance(boolean loadDefaultSerFile) {
|
||||
if (loadDefaultSerFile) {
|
||||
return getInstance("Statistics.ser");
|
||||
return getInstance("Statistics.yml");
|
||||
} else {
|
||||
return new StatisticsParameters();
|
||||
}
|
||||
@ -149,6 +149,7 @@ public class StatisticsParameters implements InterfaceStatisticsParameters, Inte
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
@Parameter(name = "runs", description = "Number of independent optimization runs to evaluate.")
|
||||
public void setMultiRuns(int x) {
|
||||
multiRuns = x;
|
||||
}
|
||||
@ -161,14 +162,6 @@ public class StatisticsParameters implements InterfaceStatisticsParameters, Inte
|
||||
return multiRuns;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public String multiRunsTipText() {
|
||||
return "Number of independent optimization runs to evaluate.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Use averaged graph for multi-run plots or not
|
||||
*/
|
||||
@ -181,14 +174,11 @@ public class StatisticsParameters implements InterfaceStatisticsParameters, Inte
|
||||
* Activate or deactivate averaged graph for multi-run plots
|
||||
*/
|
||||
@Override
|
||||
@Parameter(description = "Plotting each fitness graph separately if multiruns > 1.")
|
||||
public void setUseStatPlot(boolean x) {
|
||||
useStatPlot = x;
|
||||
}
|
||||
|
||||
public String useStatPlotTipText() {
|
||||
return "Plotting each fitness graph separately if multiruns > 1.";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user