/* Copyright 2006 by Sean Luke Licensed under the Academic Free License version 3.0 See the file "LICENSE" for more information */ package ec.simple; import ec.*; import ec.steadystate.*; import java.io.IOException; import ec.util.*; import java.io.File; /* * SimpleStatistics.java * * Created: Tue Aug 10 21:10:48 1999 * By: Sean Luke */ /** * A basic Statistics class suitable for simple problem applications. * * SimpleStatistics prints out the best individual, per subpopulation, * each generation. At the end of a run, it also prints out the best * individual of the run. SimpleStatistics outputs this data to a log * which may either be a provided file or stdout. Compressed files will * be overridden on restart from checkpoint; uncompressed files will be * appended on restart. * *

SimpleStatistics implements a simple version of steady-state statistics: * if it quits before a generation boundary, * it will include the best individual discovered, even if the individual was discovered * after the last boundary. This is done by using individualsEvaluatedStatistics(...) * to update best-individual-of-generation in addition to doing it in * postEvaluationStatistics(...).

Parameters
base.gzip
boolean
(whether or not to compress the file (.gz suffix added)
base.file
String (a filename), or nonexistant (signifies stdout)
(the log for statistics)
* * @author Sean Luke * @version 1.0 */ public class SimpleStatistics extends Statistics implements SteadyStateStatisticsForm //, ec.eval.ProvidesBestSoFar { public Individual[] getBestSoFar() { return best_of_run; } /** log file parameter */ public static final String P_STATISTICS_FILE = "file"; /** compress? */ public static final String P_COMPRESS = "gzip"; /** The Statistics' log */ public int statisticslog; /** The best individual we've found so far */ public Individual[] best_of_run; /** Should we compress the file? */ public boolean compress; public SimpleStatistics() { best_of_run = null; statisticslog = 0; /* stdout */ } public void setup(final EvolutionState state, final Parameter base) { super.setup(state,base); compress = state.parameters.getBoolean(base.push(P_COMPRESS),null,false); File statisticsFile = state.parameters.getFile( base.push(P_STATISTICS_FILE),null); if (statisticsFile!=null) try { statisticslog = state.output.addLog(statisticsFile, !compress, compress); } catch (IOException i) { state.output.fatal("An IOException occurred while trying to create the log " + statisticsFile + ":\n" + i); } } public void postInitializationStatistics(final EvolutionState state) { super.postInitializationStatistics(state); // set up our best_of_run array -- can't do this in setup, because // we don't know if the number of subpopulations has been determined yet best_of_run = new Individual[state.population.subpops.length]; } /** Logs the best individual of the generation. */ public void postEvaluationStatistics(final EvolutionState state) { super.postEvaluationStatistics(state); // for now we just print the best fitness per subpopulation. Individual[] best_i = new Individual[state.population.subpops.length]; // quiets compiler complaints for(int x=0;x