This commit is contained in:
Fabian Becker 2014-11-13 17:23:35 +01:00
parent 153b6e3974
commit 3627d33df5
8 changed files with 15 additions and 78 deletions

View File

@ -782,7 +782,7 @@ public class OptimizerFactory {
if (runnable == null) { if (runnable == null) {
return null; return null;
} }
runnable.run(); new Thread(runnable).start();
lastRunnable = runnable; lastRunnable = runnable;
return runnable; return runnable;
} }

View File

@ -155,7 +155,7 @@ public class OptimizerRunnable implements Runnable {
} else { } else {
proc.startOptimization(); proc.startOptimization();
} }
proc.runOptOnce(); proc.runOptimizationOnce();
} }
} catch (Exception e) { } catch (Exception e) {
proc.getStatistics().printToTextListener("Exception in OptimizeThread::run: " + e.getMessage() + "\n"); proc.getStatistics().printToTextListener("Exception in OptimizeThread::run: " + e.getMessage() + "\n");

View File

@ -762,15 +762,6 @@ public class Main extends JFrame implements OptimizationStateListener {
return ((GenericModuleAdapter) currentModuleAdapter).getStatistics().getStatisticsParameter(); 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) { private void loadSpecificModule(String selectedModule, InterfaceOptimizationParameters optimizationParameters) {
ModuleAdapter newModuleAdapter = null; ModuleAdapter newModuleAdapter = null;
// //

View File

@ -116,27 +116,6 @@ public class PropertySelectableList<T> implements java.io.Serializable {
propertyChangeSupport.firePropertyChange("PropertySelectableList", null, this); 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) { public void addPropertyChangeListener(PropertyChangeListener l) {
if (propertyChangeSupport == null) { if (propertyChangeSupport == null) {
propertyChangeSupport = new PropertyChangeSupport(this); propertyChangeSupport = new PropertyChangeSupport(this);

View File

@ -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. * Adds a remote state listener.
*/ */

View File

@ -158,11 +158,11 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
} catch (Exception e) { } catch (Exception e) {
System.err.println("There was an error in sleep Processor.run()" + e); System.err.println("There was an error in sleep Processor.run()" + e);
} }
runOptOnce(); runOptimizationOnce();
} }
} }
public Population runOptOnce() { public Population runOptimizationOnce() {
try { try {
EVAERROR.clearMsgCache(); EVAERROR.clearMsgCache();
while (isOptimizationRunning()) { while (isOptimizationRunning()) {
@ -179,7 +179,7 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
} }
} catch (Exception e) { } catch (Exception e) {
String errMsg = e.toString(); String errMsg = e.toString();
if ((errMsg == null) || (errMsg.length() == 0)) { if (errMsg.length() == 0) {
errMsg = "check console output for error messages."; errMsg = "check console output for error messages.";
} }
errMsg = "Exception in Processor: " + errMsg; errMsg = "Exception in Processor: " + errMsg;

View File

@ -20,6 +20,7 @@ import java.io.FileOutputStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.concurrent.CopyOnWriteArraySet;
/** /**
* An abstract class handling statistics. Most important stuff happens in startOptimizationPerformed, stopOptimizationPerformed * 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. * The method plotCurrentResults should be implemented to plot further results per iteration.
* <p> * <p>
* All displayable data is now routed through a single pipeline, which consists in a * 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 * 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. * 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 * 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<IndividualInterface> runBestFeasibleList; private ArrayList<IndividualInterface> runBestFeasibleList;
private ArrayList<IndividualInterface> runBestFitList; private ArrayList<IndividualInterface> runBestFitList;
private transient ArrayList<InterfaceTextListener> textListeners; private transient Set<InterfaceTextListener> textListeners;
private transient List<InterfaceStatisticsListener> dataListeners = null; private transient Set<InterfaceStatisticsListener> dataListeners = null;
private List<InterfaceAdditionalPopulationInformer> lastInformerList = null; private List<InterfaceAdditionalPopulationInformer> lastInformerList = null;
private PopulationInterface lastSols = null; private PopulationInterface lastSols = null;
@ -108,26 +109,18 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
convergenceCnt = 0; convergenceCnt = 0;
optRunsPerformed = 0; optRunsPerformed = 0;
iterationCounter = 0; iterationCounter = 0;
textListeners = new ArrayList<>(); textListeners = new CopyOnWriteArraySet<>();
dataListeners = new CopyOnWriteArraySet<>();
} }
@Override @Override
public void addDataListener(InterfaceStatisticsListener l) { public void addDataListener(InterfaceStatisticsListener l) {
if (dataListeners == null) { dataListeners.add(l);
dataListeners = new LinkedList<>();
}
if (l != null && !dataListeners.contains(l)) {
dataListeners.add(l);
}
} }
@Override @Override
public boolean removeDataListener(InterfaceStatisticsListener l) { public boolean removeDataListener(InterfaceStatisticsListener l) {
if (dataListeners == null) { return dataListeners.remove(l);
return false;
} else {
return dataListeners.remove(l);
}
} }
private void fireDataListeners() { private void fireDataListeners() {
@ -496,7 +489,6 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
if (optRunsPerformed > 1) { if (optRunsPerformed > 1) {
if (runBestFitList.size() > 0) { if (runBestFitList.size() > 0) {
// Mathematics.svDiv((double)optRunsPerformed, meanBestOfRunFitness, meanBestOfRunFitness);
if (printFinalVerbosity()) { if (printFinalVerbosity()) {
double[] meanBestFit = getMeanBestFit(false); double[] meanBestFit = getMeanBestFit(false);
printToTextListener(" MultiRun stats: Mean best fitness: " + BeanInspector.toString(meanBestFit) + "\n"); 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)) { if (printFinalVerbosity() && (bestFeasibleAllRuns != null)) {
printIndy("Overall best feasible", bestFeasibleAllRuns); 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 (runBestFeasibleList.size() > 0) { // always output feasible stats even if theyre equal
if (printFinalVerbosity()) { if (printFinalVerbosity()) {
double[] meanBestFeasibleFit = getMeanBestFit(true); double[] meanBestFeasibleFit = getMeanBestFit(true);
@ -550,22 +541,18 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
private String getFinalAdditionalInfo() { private String getFinalAdditionalInfo() {
PopulationInterface bestPop = makeStatsPop(); PopulationInterface bestPop = makeStatsPop();
// List<String> additionalFields = getAdditionalInfoHeader(lastInformerList, bestPop);
String additionalFields = getOutputHeaderFieldNamesAsString(lastInformerList); String additionalFields = getOutputHeaderFieldNamesAsString(lastInformerList);
// String header = getOutputHeader(lastInformerList, bestPop);
List<Object> vals = getOutputValues(lastInformerList, bestPop); List<Object> vals = getOutputValues(lastInformerList, bestPop);
StringBuilder sbuf = new StringBuilder("Overall best statistical data: \n"); StringBuilder sbuf = new StringBuilder("Overall best statistical data: \n");
sbuf.append(additionalFields); sbuf.append(additionalFields);
sbuf.append('\n'); sbuf.append('\n');
sbuf.append(StringTools.concatValues(vals, textFieldDelimiter)); sbuf.append(StringTools.concatValues(vals, textFieldDelimiter));
// appendAdditionalInfo(lastInformerList, bestPop, sbuf);
// getOutputLine(lastInformerList, makeStatsPop());
return sbuf.toString(); return sbuf.toString();
} }
private double[] calcStdDevVar(ArrayList<IndividualInterface> list, double meanFit) { private double[] calcStdDevVar(ArrayList<IndividualInterface> list, double meanFit) {
double tmp = 0, sum = 0; double tmp, sum = 0;
for (Iterator<IndividualInterface> iter = list.iterator(); iter.hasNext(); ) { for (Iterator<IndividualInterface> iter = list.iterator(); iter.hasNext(); ) {
IndividualInterface indy = iter.next(); IndividualInterface indy = iter.next();
tmp = indy.getFitness()[0] - meanFit; tmp = indy.getFitness()[0] - meanFit;
@ -1050,7 +1037,6 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
currentBestFeasibleFit = curBestFeasible.getFitness().clone(); currentBestFeasibleFit = curBestFeasible.getFitness().clone();
if ((bestOfRunFeasibleIndy == null) || (secondIsBetter(bestOfRunFeasibleIndy, curBestFeasible))) { if ((bestOfRunFeasibleIndy == null) || (secondIsBetter(bestOfRunFeasibleIndy, curBestFeasible))) {
bestOfRunFeasibleIndy = (AbstractEAIndividual) curBestFeasible.clone(); bestOfRunFeasibleIndy = (AbstractEAIndividual) curBestFeasible.clone();
// System.out.println("New best feasible: " + AbstractEAIndividual.getDefaultStringRepresentation((AbstractEAIndividual)bestRunFeasibleIndy));
} }
if ((bestFeasibleAllRuns == null) || (secondIsBetter(bestFeasibleAllRuns, bestOfRunFeasibleIndy))) { if ((bestFeasibleAllRuns == null) || (secondIsBetter(bestFeasibleAllRuns, bestOfRunFeasibleIndy))) {
bestFeasibleAllRuns = bestOfRunFeasibleIndy; bestFeasibleAllRuns = bestOfRunFeasibleIndy;
@ -1102,8 +1088,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
* Do some data collection on the population. * Do some data collection on the population.
*/ */
@Override @Override
public synchronized void createNextGenerationPerformed(PopulationInterface public synchronized void createNextGenerationPerformed(PopulationInterface pop, InterfaceOptimizer opt, List<InterfaceAdditionalPopulationInformer> informerList) {
pop, InterfaceOptimizer opt, List<InterfaceAdditionalPopulationInformer> informerList) {
lastInformerList = informerList; lastInformerList = informerList;
if (resultOut != null) { if (resultOut != null) {
@ -1150,7 +1135,6 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
if ((optRunsPerformed == 0) && (sumDataCollection.size() <= iterationCounter)) { if ((optRunsPerformed == 0) && (sumDataCollection.size() <= iterationCounter)) {
// in the first run, newly allocate the arrays // in the first run, newly allocate the arrays
// assume that all later data sets will have the same format // 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(); sumDataEntry = currentStatDoubleData.clone();
sumDataCollection.add(sumDataEntry); sumDataCollection.add(sumDataEntry);
} else { } else {
@ -1168,17 +1152,6 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
} }
} }
// if (doTextOutput()) {
// Pair<String,Double[]> addInfo = getOutputLine(informerList, lastSols);
//
// if (printLineByVerbosity(runIterCnt)) {
// printToTextListener(addInfo.head()+'\n');
// }
// currentAdditionalInfo = addInfo.tail();
// if (addInfo.tail()!=null) {
// additionalInfoSums = updateAdditionalInfo(additionalInfoSums, addInfo.tail());
// }
// }
plotCurrentResults(); plotCurrentResults();
fireDataListeners(); fireDataListeners();
if (resultOut != null) { if (resultOut != null) {

View File

@ -99,8 +99,6 @@ public class OptimizationJob implements Serializable, InterfaceStatisticsListene
tag = "!"; tag = "!";
break; break;
} }
tag = tag + numRuns + " ";
return tag; return tag;
} }