diff --git a/src/eva2/OptimizerFactory.java b/src/eva2/OptimizerFactory.java index 8827e71d..ba11c8cb 100644 --- a/src/eva2/OptimizerFactory.java +++ b/src/eva2/OptimizerFactory.java @@ -782,7 +782,7 @@ public class OptimizerFactory { if (runnable == null) { return null; } - runnable.run(); + new Thread(runnable).start(); lastRunnable = runnable; return runnable; } diff --git a/src/eva2/OptimizerRunnable.java b/src/eva2/OptimizerRunnable.java index 5710da26..4e37165d 100644 --- a/src/eva2/OptimizerRunnable.java +++ b/src/eva2/OptimizerRunnable.java @@ -155,7 +155,7 @@ public class OptimizerRunnable implements Runnable { } else { proc.startOptimization(); } - proc.runOptOnce(); + proc.runOptimizationOnce(); } } catch (Exception e) { proc.getStatistics().printToTextListener("Exception in OptimizeThread::run: " + e.getMessage() + "\n"); diff --git a/src/eva2/gui/Main.java b/src/eva2/gui/Main.java index f166586a..aa909eab 100644 --- a/src/eva2/gui/Main.java +++ b/src/eva2/gui/Main.java @@ -762,15 +762,6 @@ public class Main extends JFrame implements OptimizationStateListener { return ((GenericModuleAdapter) currentModuleAdapter).getStatistics().getStatisticsParameter(); } - /** - * Check if there is an optimization currently running. - * - * @return - */ - public boolean isOptimizationRunning() { - return (currentModuleAdapter != null) && (currentModuleAdapter instanceof AbstractModuleAdapter) && ((AbstractModuleAdapter) currentModuleAdapter).isOptRunning(); - } - private void loadSpecificModule(String selectedModule, InterfaceOptimizationParameters optimizationParameters) { ModuleAdapter newModuleAdapter = null; // diff --git a/src/eva2/gui/PropertySelectableList.java b/src/eva2/gui/PropertySelectableList.java index d24606d4..4539cf7f 100644 --- a/src/eva2/gui/PropertySelectableList.java +++ b/src/eva2/gui/PropertySelectableList.java @@ -116,27 +116,6 @@ public class PropertySelectableList implements java.io.Serializable { propertyChangeSupport.firePropertyChange("PropertySelectableList", null, this); } -// /** -// * Append an object at the end of the list and immediately select it. -// * @param o -// */ -// public void addObject(T o) { -// if (objects==null) { -// objects=(T[]) new Object[]{o}; -// selections = new boolean[1]; -// } else { -// T[] newOs = (T[])new Object[objects.length+1]; -// boolean[] newSs = new boolean[selections.length+1]; -// System.arraycopy(objects, 0, newOs, 0, this.objects.length); -// System.arraycopy(selections, 0, newSs, 0, this.selections.length); -// newOs[objects.length]=o; -// newSs[objects.length]=true; -// objects=newOs; -// selections=newSs; -// } -// propertyChangeSupport.firePropertyChange("PropertySelectableList", null, this); -// } - public void addPropertyChangeListener(PropertyChangeListener l) { if (propertyChangeSupport == null) { propertyChangeSupport = new PropertyChangeSupport(this); diff --git a/src/eva2/optimization/modules/AbstractModuleAdapter.java b/src/eva2/optimization/modules/AbstractModuleAdapter.java index 38a00318..e4f40d4b 100644 --- a/src/eva2/optimization/modules/AbstractModuleAdapter.java +++ b/src/eva2/optimization/modules/AbstractModuleAdapter.java @@ -92,10 +92,6 @@ abstract public class AbstractModuleAdapter implements ModuleAdapter, Serializab } } - public boolean isOptRunning() { - return (processor != null) && (processor instanceof Processor) && ((Processor) processor).isOptimizationRunning(); - } - /** * Adds a remote state listener. */ diff --git a/src/eva2/optimization/modules/Processor.java b/src/eva2/optimization/modules/Processor.java index ac222ee7..f6d8b46b 100644 --- a/src/eva2/optimization/modules/Processor.java +++ b/src/eva2/optimization/modules/Processor.java @@ -158,11 +158,11 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo } catch (Exception e) { System.err.println("There was an error in sleep Processor.run()" + e); } - runOptOnce(); + runOptimizationOnce(); } } - public Population runOptOnce() { + public Population runOptimizationOnce() { try { EVAERROR.clearMsgCache(); while (isOptimizationRunning()) { @@ -179,7 +179,7 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo } } catch (Exception e) { String errMsg = e.toString(); - if ((errMsg == null) || (errMsg.length() == 0)) { + if (errMsg.length() == 0) { errMsg = "check console output for error messages."; } errMsg = "Exception in Processor: " + errMsg; diff --git a/src/eva2/optimization/statistics/AbstractStatistics.java b/src/eva2/optimization/statistics/AbstractStatistics.java index 52eebe3c..2b58eb13 100644 --- a/src/eva2/optimization/statistics/AbstractStatistics.java +++ b/src/eva2/optimization/statistics/AbstractStatistics.java @@ -20,6 +20,7 @@ import java.io.FileOutputStream; import java.io.PrintWriter; import java.text.SimpleDateFormat; import java.util.*; +import java.util.concurrent.CopyOnWriteArraySet; /** * An abstract class handling statistics. Most important stuff happens in startOptimizationPerformed, stopOptimizationPerformed @@ -29,7 +30,7 @@ import java.util.*; * The method plotCurrentResults should be implemented to plot further results per iteration. *

* All displayable data is now routed through a single pipeline, which consists in a - * list of Objects assembled in the getOutputValues method. This allows all eva2.problems.simple data types which are + * list of Objects assembled in the getOutputValues method. This allows all simple data types which are * provided by the external informer instances to be handled uniformly to the internally collected data, and * thus they can be plotted and text-dumped in the same manner. * Basic fields are identified by the enum GraphSelectionEnum and are available independently of additional @@ -90,8 +91,8 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter private ArrayList runBestFeasibleList; private ArrayList runBestFitList; - private transient ArrayList textListeners; - private transient List dataListeners = null; + private transient Set textListeners; + private transient Set dataListeners = null; private List lastInformerList = null; private PopulationInterface lastSols = null; @@ -108,26 +109,18 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter convergenceCnt = 0; optRunsPerformed = 0; iterationCounter = 0; - textListeners = new ArrayList<>(); + textListeners = new CopyOnWriteArraySet<>(); + dataListeners = new CopyOnWriteArraySet<>(); } @Override public void addDataListener(InterfaceStatisticsListener l) { - if (dataListeners == null) { - dataListeners = new LinkedList<>(); - } - if (l != null && !dataListeners.contains(l)) { - dataListeners.add(l); - } + dataListeners.add(l); } @Override public boolean removeDataListener(InterfaceStatisticsListener l) { - if (dataListeners == null) { - return false; - } else { - return dataListeners.remove(l); - } + return dataListeners.remove(l); } private void fireDataListeners() { @@ -496,7 +489,6 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter if (optRunsPerformed > 1) { if (runBestFitList.size() > 0) { -// Mathematics.svDiv((double)optRunsPerformed, meanBestOfRunFitness, meanBestOfRunFitness); if (printFinalVerbosity()) { double[] meanBestFit = getMeanBestFit(false); printToTextListener(" MultiRun stats: Mean best fitness: " + BeanInspector.toString(meanBestFit) + "\n"); @@ -509,7 +501,6 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter if (printFinalVerbosity() && (bestFeasibleAllRuns != null)) { printIndy("Overall best feasible", bestFeasibleAllRuns); } -// if ((runBestFeasibleList.size()>0) && (!equalLists(runBestFeasibleList, runBestFitList))) { // is there a difference between best feasibles and best fit? if (runBestFeasibleList.size() > 0) { // always output feasible stats even if theyre equal if (printFinalVerbosity()) { double[] meanBestFeasibleFit = getMeanBestFit(true); @@ -550,22 +541,18 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter private String getFinalAdditionalInfo() { PopulationInterface bestPop = makeStatsPop(); -// List additionalFields = getAdditionalInfoHeader(lastInformerList, bestPop); String additionalFields = getOutputHeaderFieldNamesAsString(lastInformerList); -// String header = getOutputHeader(lastInformerList, bestPop); List vals = getOutputValues(lastInformerList, bestPop); StringBuilder sbuf = new StringBuilder("Overall best statistical data: \n"); sbuf.append(additionalFields); sbuf.append('\n'); sbuf.append(StringTools.concatValues(vals, textFieldDelimiter)); -// appendAdditionalInfo(lastInformerList, bestPop, sbuf); -// getOutputLine(lastInformerList, makeStatsPop()); return sbuf.toString(); } private double[] calcStdDevVar(ArrayList list, double meanFit) { - double tmp = 0, sum = 0; + double tmp, sum = 0; for (Iterator iter = list.iterator(); iter.hasNext(); ) { IndividualInterface indy = iter.next(); tmp = indy.getFitness()[0] - meanFit; @@ -1050,7 +1037,6 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter currentBestFeasibleFit = curBestFeasible.getFitness().clone(); if ((bestOfRunFeasibleIndy == null) || (secondIsBetter(bestOfRunFeasibleIndy, curBestFeasible))) { bestOfRunFeasibleIndy = (AbstractEAIndividual) curBestFeasible.clone(); -// System.out.println("New best feasible: " + AbstractEAIndividual.getDefaultStringRepresentation((AbstractEAIndividual)bestRunFeasibleIndy)); } if ((bestFeasibleAllRuns == null) || (secondIsBetter(bestFeasibleAllRuns, bestOfRunFeasibleIndy))) { bestFeasibleAllRuns = bestOfRunFeasibleIndy; @@ -1102,8 +1088,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter * Do some data collection on the population. */ @Override - public synchronized void createNextGenerationPerformed(PopulationInterface - pop, InterfaceOptimizer opt, List informerList) { + public synchronized void createNextGenerationPerformed(PopulationInterface pop, InterfaceOptimizer opt, List informerList) { lastInformerList = informerList; if (resultOut != null) { @@ -1150,7 +1135,6 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter if ((optRunsPerformed == 0) && (sumDataCollection.size() <= iterationCounter)) { // in the first run, newly allocate the arrays // assume that all later data sets will have the same format -// means = new double[4][currentBestFit.length]; // this only fits fitness vectors! of course this is sensible for multi-crit fitnesses... sumDataEntry = currentStatDoubleData.clone(); sumDataCollection.add(sumDataEntry); } else { @@ -1168,17 +1152,6 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter } } -// if (doTextOutput()) { -// Pair addInfo = getOutputLine(informerList, lastSols); -// -// if (printLineByVerbosity(runIterCnt)) { -// printToTextListener(addInfo.head()+'\n'); -// } -// currentAdditionalInfo = addInfo.tail(); -// if (addInfo.tail()!=null) { -// additionalInfoSums = updateAdditionalInfo(additionalInfoSums, addInfo.tail()); -// } -// } plotCurrentResults(); fireDataListeners(); if (resultOut != null) { diff --git a/src/eva2/optimization/statistics/OptimizationJob.java b/src/eva2/optimization/statistics/OptimizationJob.java index a755ed08..fa4b53cf 100644 --- a/src/eva2/optimization/statistics/OptimizationJob.java +++ b/src/eva2/optimization/statistics/OptimizationJob.java @@ -99,8 +99,6 @@ public class OptimizationJob implements Serializable, InterfaceStatisticsListene tag = "!"; break; } - - tag = tag + numRuns + " "; return tag; }