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