From 7d7dcb5ce075fb95a176db1ff865ddc41a2cad2d Mon Sep 17 00:00:00 2001 From: Marcel Kronfeld Date: Wed, 29 Sep 2010 07:42:53 +0000 Subject: [PATCH] Addition to statistics interface. --- src/eva2/server/modules/Processor.java | 1 + src/eva2/server/stat/AbstractStatistics.java | 25 ++++++++++++++----- src/eva2/server/stat/InterfaceStatistics.java | 2 ++ src/eva2/server/stat/StatisticsDummy.java | 2 ++ 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/eva2/server/modules/Processor.java b/src/eva2/server/modules/Processor.java index 753330c2..90979efc 100644 --- a/src/eva2/server/modules/Processor.java +++ b/src/eva2/server/modules/Processor.java @@ -262,6 +262,7 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo resultPop = goParams.getOptimizer().getAllSolutions().getSolutions(); } } else resultPop = goParams.getOptimizer().getAllSolutions().getSolutions(); + m_Statistics.postProcessingPerformed(resultPop); } setOptRunning(false); // normal finish diff --git a/src/eva2/server/stat/AbstractStatistics.java b/src/eva2/server/stat/AbstractStatistics.java index f37c0469..f3252654 100644 --- a/src/eva2/server/stat/AbstractStatistics.java +++ b/src/eva2/server/stat/AbstractStatistics.java @@ -127,7 +127,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter if (dataListeners==null) { dataListeners=new LinkedList(); } - if (!dataListeners.contains(l)) dataListeners.add(l); + if (l!=null && !dataListeners.contains(l)) dataListeners.add(l); } public boolean removeDataListener(InterfaceStatisticsListener l) { @@ -349,17 +349,30 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter if (finalObjectData==null) finalObjectData = new ArrayList(); finalObjectData.add(currentStatObjectData); - if (printFinalVerbosity()) printToTextListener("."); + if (!printRunStoppedVerbosity() && printFinalVerbosity()) printToTextListener("."); // if (currentBestFit!= null) { // if (printRunStoppedVerbosity()) printToTextListener(" Best Fitness: " + BeanInspector.toString(currentBestFit) + "\n"); // } - if (optRunsPerformed >= m_StatsParams.getMultiRuns()) { - if (printFinalVerbosity()) printToTextListener("\n"); - finalizeOutput(); - } + fireDataListenersStartStop(optRunsPerformed, normal, false); } + public void postProcessingPerformed(Population resultPop) { // called from processor + if (!printRunStoppedVerbosity() && printFinalVerbosity() && optRunsPerformed >= m_StatsParams.getMultiRuns()) printToTextListener("\n"); + if (printRunStoppedVerbosity()) { + if (resultPop!=null && (resultPop.size()>0)) { + printToTextListener("Resulting population: \n"); + for (int i=0; i= m_StatsParams.getMultiRuns()) { + finalizeOutput(); + } + } + private PopulationInterface makeStatsPop() { Population pop = new Population(4); diff --git a/src/eva2/server/stat/InterfaceStatistics.java b/src/eva2/server/stat/InterfaceStatistics.java index d9769631..b0d9bfbe 100644 --- a/src/eva2/server/stat/InterfaceStatistics.java +++ b/src/eva2/server/stat/InterfaceStatistics.java @@ -16,6 +16,7 @@ import java.util.List; import eva2.server.go.IndividualInterface; import eva2.server.go.PopulationInterface; +import eva2.server.go.populations.Population; import eva2.server.go.problems.InterfaceAdditionalPopulationInformer; import eva2.server.go.strategies.InterfaceOptimizer; /*==========================================================================* @@ -44,4 +45,5 @@ public interface InterfaceStatistics { public IndividualInterface getRunBestSolution(); // return the best fitness of the last run (may not be equal to the last population) public IndividualInterface getBestSolution(); // returns the best overall solution public double[] getBestFitness(); // returns the best overall fitness + public void postProcessingPerformed(Population resultPop); // called from processor } \ No newline at end of file diff --git a/src/eva2/server/stat/StatisticsDummy.java b/src/eva2/server/stat/StatisticsDummy.java index 4d0da9cb..4839a1c9 100644 --- a/src/eva2/server/stat/StatisticsDummy.java +++ b/src/eva2/server/stat/StatisticsDummy.java @@ -5,6 +5,7 @@ import java.util.List; import eva2.server.go.IndividualInterface; import eva2.server.go.PopulationInterface; import eva2.server.go.individuals.AbstractEAIndividual; +import eva2.server.go.populations.Population; import eva2.server.go.problems.InterfaceAdditionalPopulationInformer; import eva2.server.go.strategies.InterfaceOptimizer; @@ -85,6 +86,7 @@ public class StatisticsDummy implements InterfaceStatistics, InterfaceTextListen } public void stopOptPerformed(boolean normal, String stopMessage) {} + public void postProcessingPerformed(Population resultPop) {} public void print(String str) { if (consoleOut) System.out.print(str);