Refactoring foo
This commit is contained in:
parent
117284ace5
commit
945889dcaf
@ -627,9 +627,9 @@ public class OptimizerFactory {
|
|||||||
if (params != null) {
|
if (params != null) {
|
||||||
opt = new OptimizerRunnable(params, outputFilePrefix);
|
opt = new OptimizerRunnable(params, outputFilePrefix);
|
||||||
if (terminator != null) {
|
if (terminator != null) {
|
||||||
opt.getGOParams().setTerminator(terminator);
|
opt.getOptimizationParameters().setTerminator(terminator);
|
||||||
} else {
|
} else {
|
||||||
opt.getGOParams().setTerminator(getTerminator());
|
opt.getOptimizationParameters().setTerminator(getTerminator());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return opt;
|
return opt;
|
||||||
|
@ -42,7 +42,7 @@ public class OptimizerRunnable implements Runnable {
|
|||||||
* @param params
|
* @param params
|
||||||
* @param outputFilePrefix
|
* @param outputFilePrefix
|
||||||
*/
|
*/
|
||||||
public OptimizerRunnable(OptimizationParameters params, String outputFilePrefix) {
|
public OptimizerRunnable(InterfaceOptimizationParameters params, String outputFilePrefix) {
|
||||||
this(params, outputFilePrefix, false);
|
this(params, outputFilePrefix, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ public class OptimizerRunnable implements Runnable {
|
|||||||
* @param params
|
* @param params
|
||||||
* @param restart
|
* @param restart
|
||||||
*/
|
*/
|
||||||
public OptimizerRunnable(OptimizationParameters params, boolean restart) {
|
public OptimizerRunnable(InterfaceOptimizationParameters params, boolean restart) {
|
||||||
this(params, new StatisticsDummy(), restart);
|
this(params, new StatisticsDummy(), restart);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ public class OptimizerRunnable implements Runnable {
|
|||||||
* @param outputFilePrefix
|
* @param outputFilePrefix
|
||||||
* @param restart
|
* @param restart
|
||||||
*/
|
*/
|
||||||
public OptimizerRunnable(OptimizationParameters params, String outputFilePrefix, boolean restart) {
|
public OptimizerRunnable(InterfaceOptimizationParameters params, String outputFilePrefix, boolean restart) {
|
||||||
this(params, new StatisticsStandalone(outputFilePrefix), restart);
|
this(params, new StatisticsStandalone(outputFilePrefix), restart);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,10 +75,10 @@ public class OptimizerRunnable implements Runnable {
|
|||||||
* If restart is true, the processor will not reinitialize the population allowing search on predefined populations.
|
* If restart is true, the processor will not reinitialize the population allowing search on predefined populations.
|
||||||
*
|
*
|
||||||
* @param params
|
* @param params
|
||||||
* @param outputFilePrefix
|
* @param stats
|
||||||
* @param restart
|
* @param restart
|
||||||
*/
|
*/
|
||||||
public OptimizerRunnable(OptimizationParameters params, InterfaceStatistics stats, boolean restart) {
|
public OptimizerRunnable(InterfaceOptimizationParameters params, InterfaceStatistics stats, boolean restart) {
|
||||||
rnblID = cntID;
|
rnblID = cntID;
|
||||||
cntID++;
|
cntID++;
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ public class OptimizerRunnable implements Runnable {
|
|||||||
return rnblID;
|
return rnblID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InterfaceOptimizationParameters getGOParams() {
|
public InterfaceOptimizationParameters getOptimizationParameters() {
|
||||||
return proc.getOptimizationParameters();
|
return proc.getOptimizationParameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ public class OptimizerRunnable implements Runnable {
|
|||||||
return proc.getStatistics();
|
return proc.getStatistics();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStats(InterfaceStatistics stats) {
|
public void setStatistics(InterfaceStatistics stats) {
|
||||||
if (proc.isOptimizationRunning()) {
|
if (proc.isOptimizationRunning()) {
|
||||||
throw new RuntimeException("Error - cannot change statistics instance during optimization.");
|
throw new RuntimeException("Error - cannot change statistics instance during optimization.");
|
||||||
}
|
}
|
||||||
|
@ -813,11 +813,11 @@ public class PostProcess {
|
|||||||
* Just execute the runnable.
|
* Just execute the runnable.
|
||||||
*/
|
*/
|
||||||
private static void runPP(OptimizerRunnable rnbl) {
|
private static void runPP(OptimizerRunnable rnbl) {
|
||||||
rnbl.getGOParams().setDoPostProcessing(false);
|
rnbl.getOptimizationParameters().setDoPostProcessing(false);
|
||||||
rnbl.setVerbosityLevel(StatisticsParameter.VERBOSITY_NONE);
|
rnbl.setVerbosityLevel(StatisticsParameter.VERBOSITY_NONE);
|
||||||
ppRunnables.add(rnbl);
|
ppRunnables.add(rnbl);
|
||||||
rnbl.run();
|
rnbl.run();
|
||||||
rnbl.getGOParams().setDoPostProcessing(true);
|
rnbl.getOptimizationParameters().setDoPostProcessing(true);
|
||||||
ppRunnables.remove(rnbl);
|
ppRunnables.remove(rnbl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -901,7 +901,7 @@ public class PostProcess {
|
|||||||
InterfaceMultimodalProblemKnown mmp = (InterfaceMultimodalProblemKnown) problem;
|
InterfaceMultimodalProblemKnown mmp = (InterfaceMultimodalProblemKnown) problem;
|
||||||
OptimizerRunnable runnable = OptimizerFactory.getOptRunnable(OptimizerFactory.STD_GA, problem, 100, null);
|
OptimizerRunnable runnable = OptimizerFactory.getOptRunnable(OptimizerFactory.STD_GA, problem, 100, null);
|
||||||
runnable.run();
|
runnable.run();
|
||||||
Population pop = runnable.getGOParams().getOptimizer().getPopulation();
|
Population pop = runnable.getOptimizationParameters().getOptimizer().getPopulation();
|
||||||
Population found = getFoundOptima(pop, mmp.getRealOptima(), 0.05, true);
|
Population found = getFoundOptima(pop, mmp.getRealOptima(), 0.05, true);
|
||||||
System.out.println("all found (" + found.size() + "): " + BeanInspector.toString(found));
|
System.out.println("all found (" + found.size() + "): " + BeanInspector.toString(found));
|
||||||
|
|
||||||
|
@ -253,7 +253,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
|
|||||||
public void startOptimizationPerformed(String infoString, int runNumber, Object params, List<InterfaceAdditionalPopulationInformer> informerList) {
|
public void startOptimizationPerformed(String infoString, int runNumber, Object params, List<InterfaceAdditionalPopulationInformer> informerList) {
|
||||||
|
|
||||||
if (runNumber == 0) {
|
if (runNumber == 0) {
|
||||||
// store the intial graph selection state, so that modifications during runtime cannot cause inconsistencies
|
// store the initial graph selection state, so that modifications during runtime cannot cause inconsistencies
|
||||||
lastFieldSelection = (StringSelection) statisticsParameter.getFieldSelection().clone();
|
lastFieldSelection = (StringSelection) statisticsParameter.getFieldSelection().clone();
|
||||||
lastIsShowFull = statisticsParameter.isOutputAllFieldsAsText();
|
lastIsShowFull = statisticsParameter.isOutputAllFieldsAsText();
|
||||||
|
|
||||||
@ -305,20 +305,19 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
|
|||||||
if (printRunIntroVerbosity()) {
|
if (printRunIntroVerbosity()) {
|
||||||
printToTextListener("\n****** Multirun " + runNumber);
|
printToTextListener("\n****** Multirun " + runNumber);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
ToDo: Figure out if we need this. Right now it is just spamming the text output
|
||||||
if (params != null) {
|
if (params != null) {
|
||||||
if (printRunIntroVerbosity()) {
|
if (printRunIntroVerbosity()) {
|
||||||
printToTextListener("\nModule parameters: ");
|
printToTextListener("\nOptimization parameters: ");
|
||||||
}
|
|
||||||
if (printRunIntroVerbosity()) {
|
|
||||||
printToTextListener(BeanInspector.niceToString(params));
|
printToTextListener(BeanInspector.niceToString(params));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (printRunIntroVerbosity()) {
|
if (printRunIntroVerbosity()) {
|
||||||
printToTextListener("\nStatistics parameters: ");
|
printToTextListener("\nStatistics parameters: ");
|
||||||
}
|
|
||||||
if (printRunIntroVerbosity()) {
|
|
||||||
printToTextListener(BeanInspector.niceToString(getStatisticsParameter()) + '\n');
|
printToTextListener(BeanInspector.niceToString(getStatisticsParameter()) + '\n');
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
functionCalls = 0;
|
functionCalls = 0;
|
||||||
fireDataListenersStartStop(runNumber, true, true);
|
fireDataListenersStartStop(runNumber, true, true);
|
||||||
}
|
}
|
||||||
@ -326,7 +325,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
|
|||||||
@Override
|
@Override
|
||||||
public void stopOptimizationPerformed(boolean normal, String stopMessage) {
|
public void stopOptimizationPerformed(boolean normal, String stopMessage) {
|
||||||
if (lastSols == null) {
|
if (lastSols == null) {
|
||||||
System.err.println("WARNING, possibly there was no call to createNextGenerationPerformed before calling stopOptimizationPerformed (AnstractStatistics).");
|
System.err.println("WARNING, possibly there was no call to createNextGenerationPerformed before calling stopOptimizationPerformed (AbstractStatistics).");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iterationCounter < sumDataCollection.size()) {
|
if (iterationCounter < sumDataCollection.size()) {
|
||||||
|
@ -366,7 +366,7 @@ public class MatlabProblem extends AbstractOptimizationProblem implements Interf
|
|||||||
runnable.setOutputFullStatsToText(outputAllStatsField);
|
runnable.setOutputFullStatsToText(outputAllStatsField);
|
||||||
|
|
||||||
if (seedPopulation != null) {
|
if (seedPopulation != null) {
|
||||||
runnable.getGOParams().getOptimizer().setPopulation(seedPopulation);
|
runnable.getOptimizationParameters().getOptimizer().setPopulation(seedPopulation);
|
||||||
runnable.setDoRestart(true);
|
runnable.setDoRestart(true);
|
||||||
log("Setting seed population of size " + seedPopulation.size() + ", target size " + seedPopulation.getTargetSize() + "\n");
|
log("Setting seed population of size " + seedPopulation.size() + ", target size " + seedPopulation.getTargetSize() + "\n");
|
||||||
log(BeanInspector.toString(seedPopulation.getStringRepresentation()) + "\n");
|
log(BeanInspector.toString(seedPopulation.getStringRepresentation()) + "\n");
|
||||||
@ -378,7 +378,7 @@ public class MatlabProblem extends AbstractOptimizationProblem implements Interf
|
|||||||
System.err.println("mismatching value list for parameter arguments: " + specValues);
|
System.err.println("mismatching value list for parameter arguments: " + specValues);
|
||||||
} else {
|
} else {
|
||||||
log("setting specific parameters...\n");
|
log("setting specific parameters...\n");
|
||||||
InterfaceOptimizer opt = runnable.getGOParams().getOptimizer();
|
InterfaceOptimizer opt = runnable.getOptimizationParameters().getOptimizer();
|
||||||
for (int i = 0; i < specParams.length; i++) { // loop over settings
|
for (int i = 0; i < specParams.length; i++) { // loop over settings
|
||||||
log("try setting " + specParams[i] + " to " + specValues[i]);
|
log("try setting " + specParams[i] + " to " + specValues[i]);
|
||||||
String paramName = null;
|
String paramName = null;
|
||||||
@ -481,7 +481,7 @@ public class MatlabProblem extends AbstractOptimizationProblem implements Interf
|
|||||||
if (runnable == null) {
|
if (runnable == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return runnable.getGOParams().getOptimizer().getPopulation().getFunctionCalls();
|
return runnable.getOptimizationParameters().getOptimizer().getPopulation().getFunctionCalls();
|
||||||
}
|
}
|
||||||
|
|
||||||
void exportResultPopulationToMatlab(Population pop) {
|
void exportResultPopulationToMatlab(Population pop) {
|
||||||
|
@ -37,7 +37,7 @@ class WaitForEvARunnable implements Runnable {
|
|||||||
try {
|
try {
|
||||||
mp.log("runnable.getDoubleSolution: " + BeanInspector.toString(runnable.getDoubleSolution()) + "\n");
|
mp.log("runnable.getDoubleSolution: " + BeanInspector.toString(runnable.getDoubleSolution()) + "\n");
|
||||||
mp.log("runnable.getIntegerSolution: " + BeanInspector.toString(runnable.getIntegerSolution()) + "\n");
|
mp.log("runnable.getIntegerSolution: " + BeanInspector.toString(runnable.getIntegerSolution()) + "\n");
|
||||||
mp.log("getAllSols best: " + AbstractEAIndividual.getDefaultDataString(runnable.getGOParams().getOptimizer().getAllSolutions().getSolutions().getBestEAIndividual()) + "\n");
|
mp.log("getAllSols best: " + AbstractEAIndividual.getDefaultDataString(runnable.getOptimizationParameters().getOptimizer().getAllSolutions().getSolutions().getBestEAIndividual()) + "\n");
|
||||||
mp.log("\n");
|
mp.log("\n");
|
||||||
// write results back to matlab
|
// write results back to matlab
|
||||||
mp.exportResultToMatlab(runnable);
|
mp.exportResultToMatlab(runnable);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user