This commit is contained in:
Fabian Becker 2014-11-04 16:33:55 +01:00
parent b77cda3046
commit efe1a1188b
6 changed files with 81 additions and 20 deletions

View File

@ -1,6 +1,9 @@
package eva2.cli; package eva2.cli;
import eva2.OptimizerFactory;
import eva2.optimization.go.InterfaceOptimizationParameters; import eva2.optimization.go.InterfaceOptimizationParameters;
import eva2.optimization.modules.OptimizationParameters;
import eva2.optimization.statistics.InterfaceStatisticsParameters;
/** /**
* Created by becker on 01.11.2014. * Created by becker on 01.11.2014.
@ -8,7 +11,12 @@ import eva2.optimization.go.InterfaceOptimizationParameters;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
InterfaceOptimizationParameters parameters = OptimizationBuilder.parseArguments(args); InterfaceOptimizationParameters parameters = OptimizationBuilder.parseOptimizerArguments(args);
InterfaceStatisticsParameters statisticsParameters = OptimizationBuilder.parseStatisticsArguments(args);
double[] result = OptimizerFactory.optimizeToDouble((OptimizationParameters)parameters);
} }

View File

@ -3,6 +3,8 @@ package eva2.cli;
import eva2.gui.BeanInspector; import eva2.gui.BeanInspector;
import eva2.optimization.go.InterfaceOptimizationParameters; import eva2.optimization.go.InterfaceOptimizationParameters;
import eva2.optimization.modules.OptimizationParameters; import eva2.optimization.modules.OptimizationParameters;
import eva2.optimization.statistics.InterfaceStatisticsParameters;
import eva2.optimization.statistics.StatisticsParameters;
import eva2.tools.ReflectPackage; import eva2.tools.ReflectPackage;
import eva2.util.annotation.Hidden; import eva2.util.annotation.Hidden;
import eva2.util.annotation.Parameter; import eva2.util.annotation.Parameter;
@ -50,18 +52,26 @@ class ArgumentTree extends LinkedHashMap<String, Object> {
public final class OptimizationBuilder { public final class OptimizationBuilder {
private OptimizationBuilder() {} private OptimizationBuilder() {}
public static InterfaceOptimizationParameters parseArguments(String[] args) { public static InterfaceOptimizationParameters parseOptimizerArguments(String[] args) {
ArgumentTree argumentTree = parseArguments(args);
return constructFromArgumentTree(OptimizationParameters.class, argumentTree);
}
public static InterfaceStatisticsParameters parseStatisticsArguments(String[] args) {
ArgumentTree argumentTree = parseArguments(args);
return constructFromArgumentTree(StatisticsParameters.class, argumentTree);
}
private static ArgumentTree parseArguments(String[] args) {
HashMap<String, String> argumentMap = new HashMap<>(args.length/2); HashMap<String, String> argumentMap = new HashMap<>(args.length/2);
int i = 0; int i = 0;
while (i < args.length) { while (i < args.length) {
// Is it a parameter? // Is it a parameter?
if (args[i].startsWith("--")) { if (args[i].startsWith("--")) {
String key = args[i].substring(2); String key = args[i].substring(2);
String value = null;
// Is the next a value? // Is the next a value?
if (i < args.length - 1 && !args[i+1].startsWith("--")) { if (i < args.length - 1 && !args[i+1].startsWith("--")) {
value = args[i + 1]; argumentMap.put(key, args[i + 1]);
argumentMap.put(key, value);
i = i + 2; i = i + 2;
} else { } else {
argumentMap.put(key, null); argumentMap.put(key, null);
@ -76,7 +86,7 @@ public final class OptimizationBuilder {
} }
System.out.println(argumentTree.toString()); System.out.println(argumentTree.toString());
return constructFromArgumentTree(OptimizationParameters.class, argumentTree); return argumentTree;
} }
private static void insertIntoArgumentTree(ArgumentTree tree, String key, String value) { private static void insertIntoArgumentTree(ArgumentTree tree, String key, String value) {

View File

@ -0,0 +1,45 @@
package eva2.cli;
import eva2.optimization.OptimizationStateListener;
import eva2.optimization.go.InterfaceOptimizationParameters;
import eva2.optimization.population.InterfacePopulationChangedEventListener;
import java.io.OutputStream;
/**
*
*/
public class OptimizationLogger implements InterfacePopulationChangedEventListener, OptimizationStateListener {
private final OutputStream outputStream;
private final InterfaceOptimizationParameters optimizationParameters;
public OptimizationLogger(InterfaceOptimizationParameters optimizationParameters, OutputStream outputStream) {
this.optimizationParameters = optimizationParameters;
this.outputStream = outputStream;
}
@Override
public void registerPopulationStateChanged(Object source, String name) {
}
@Override
public void performedStop() {
}
@Override
public void performedStart(String infoString) {
}
@Override
public void performedRestart(String infoString) {
}
@Override
public void updateProgress(int percent, String msg) {
}
}

View File

@ -956,7 +956,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
currentMeanFit = null; currentMeanFit = null;
if (firstPlot) { if (firstPlot) {
initPlots(null, null); initializePlots(null, null);
firstPlot = false; firstPlot = false;
} }
if ((iterationCounter == 0) && printHeaderByVerbosity()) { if ((iterationCounter == 0) && printHeaderByVerbosity()) {
@ -1013,7 +1013,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
/** /**
* Called at the very first (multirun mode) plot of a fitness curve. * Called at the very first (multirun mode) plot of a fitness curve.
*/ */
protected abstract void initPlots(PopulationInterface pop, List<InterfaceAdditionalPopulationInformer> informerList); protected abstract void initializePlots(PopulationInterface pop, List<InterfaceAdditionalPopulationInformer> informerList);
/** /**
* To set a list of informers (even before the actual run is started). * To set a list of informers (even before the actual run is started).
@ -1120,7 +1120,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
resultOut.flush(); resultOut.flush();
} }
if (firstPlot) { if (firstPlot) {
initPlots(pop, informerList); initializePlots(pop, informerList);
firstPlot = false; firstPlot = false;
currentBestFeasibleFit = null; currentBestFeasibleFit = null;
} }

View File

@ -8,7 +8,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* This eva2.problems.simple statistics implementation can collect all Object data available during runs. * This simple statistics implementation can collect all Object data available during runs.
* Be aware that the memory requirements can be excessive depending on the data produced by * Be aware that the memory requirements can be excessive depending on the data produced by
* the additional informers, and depending on the selected fields to be collected. * the additional informers, and depending on the selected fields to be collected.
* Therefore, the default is not to log the data but just print it using the super class. * Therefore, the default is not to log the data but just print it using the super class.
@ -51,7 +51,7 @@ public class StatisticsStandalone extends AbstractStatistics implements Interfac
} }
@Override @Override
protected void initPlots(PopulationInterface pop, List<InterfaceAdditionalPopulationInformer> informerList) { protected void initializePlots(PopulationInterface pop, List<InterfaceAdditionalPopulationInformer> informerList) {
if (collectData) { if (collectData) {
resultData = new ArrayList<>(statisticsParameter.getMultiRuns()); resultData = new ArrayList<>(statisticsParameter.getMultiRuns());
List<String> description = getOutputHeaderFieldNames(informerList); List<String> description = getOutputHeaderFieldNames(informerList);
@ -80,7 +80,7 @@ public class StatisticsStandalone extends AbstractStatistics implements Interfac
double[] specificData = pop.getSpecificData(); double[] specificData = pop.getSpecificData();
if (specificData != null) { if (specificData != null) {
for (int i = 0; i < specificData.length; i++) { for (int i = 0; i < specificData.length; i++) {
resultData.get(optRunsPerformed).add(new Object[]{new Double(functionCalls), specificData}); resultData.get(optRunsPerformed).add(new Object[]{(double) functionCalls, specificData});
} }
} }
} }

View File

@ -9,7 +9,6 @@ import eva2.gui.plot.Plot;
import eva2.gui.plot.PlotInterface; import eva2.gui.plot.PlotInterface;
import eva2.optimization.population.PopulationInterface; import eva2.optimization.population.PopulationInterface;
import eva2.problems.InterfaceAdditionalPopulationInformer; import eva2.problems.InterfaceAdditionalPopulationInformer;
import eva2.tools.EVAERROR;
import eva2.tools.Pair; import eva2.tools.Pair;
import java.io.Serializable; import java.io.Serializable;
@ -20,7 +19,7 @@ import java.util.logging.Logger;
/** /**
* A statistics class to plot fitness curves in client-server mode. Mainly, * A statistics class to plot fitness curves in client-server mode. Mainly,
* arrays of GraphWindows and Graphs are managed and the selected data fields * arrays of GraphWindows and Graphs are managed and the selected data fields
* are plotted. TODO: this could finally be cleanly reduced to an * are plotted. TODO: this could eventually be cleanly reduced to an
* InterfaceStatisticsListener - without inheriting from AbstractStatistics. * InterfaceStatisticsListener - without inheriting from AbstractStatistics.
*/ */
public class StatisticsWithGUI extends AbstractStatistics implements Serializable, InterfaceStatistics { public class StatisticsWithGUI extends AbstractStatistics implements Serializable, InterfaceStatistics {
@ -39,7 +38,6 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl
* some time. * some time.
*/ */
private transient List<Pair<String, Integer>> graphDesc = null; private transient List<Pair<String, Integer>> graphDesc = null;
protected static String hostName = null;
/** /**
* *
@ -112,12 +110,12 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl
} }
@Override @Override
protected void initPlots(PopulationInterface pop, List<InterfaceAdditionalPopulationInformer> informerList) { protected void initializePlots(PopulationInterface pop, List<InterfaceAdditionalPopulationInformer> informerList) {
if (statisticsParameter instanceof StatisticsParameters) { if (statisticsParameter instanceof StatisticsParameters) {
graphDesc = lastFieldSelection.getSelectedWithIndex(); graphDesc = lastFieldSelection.getSelectedWithIndex();
} else { } else {
graphDesc = null; graphDesc = null;
System.err.println("Error in StatisticsWithGUI.initPlots()!"); System.err.println("Error in StatisticsWithGUI.initializePlots()!");
} }
maybeShowProxyPrinter(); maybeShowProxyPrinter();
@ -130,7 +128,7 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl
fitnessGraph = new Graph[windowCount][]; fitnessGraph = new Graph[windowCount][];
// contains one graph for every value to be plotted (best / worst / best+worst) // contains one graph for every value to be plotted (best / worst / best+worst)
// TODO Im really not sure why this is a 2-dimensional array. shouldnt one be enough? // TODO Im really not sure why this is a 2-dimensional array. shouldn't one be enough?
for (int i = 0; i < fitnessGraph.length; i++) { for (int i = 0; i < fitnessGraph.length; i++) {
fitnessGraph[i] = new Graph[graphCount]; fitnessGraph[i] = new Graph[graphCount];
for (int j = 0; j < fitnessGraph[i].length; j++) { for (int j = 0; j < fitnessGraph[i].length; j++) {
@ -156,11 +154,11 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl
private void plotFitnessPoint(int graph, int subGraph, int x, double y) { private void plotFitnessPoint(int graph, int subGraph, int x, double y) {
if (fitnessGraph == null) { if (fitnessGraph == null) {
EVAERROR.WARNING("fitness graph is null! (StatisticsWithGUI)"); LOGGER.warning("fitness graph is null! (StatisticsWithGUI)");
return; return;
} }
if (graph >= fitnessGraph.length || subGraph >= fitnessGraph[graph].length) { if (graph >= fitnessGraph.length || subGraph >= fitnessGraph[graph].length) {
EVAERROR.WARNING("tried to plot to invalid graph! (StatisticsWithGUI)"); LOGGER.warning("tried to plot to invalid graph! (StatisticsWithGUI)");
return; return;
} }
boolean isValidGraph = fitnessFrame[graph].isValid(); boolean isValidGraph = fitnessFrame[graph].isValid();