diff --git a/eo/src/do/make_checkpoint.h b/eo/src/do/make_checkpoint.h index f48a2d66..c9477bd3 100644 --- a/eo/src/do/make_checkpoint.h +++ b/eo/src/do/make_checkpoint.h @@ -45,7 +45,7 @@ eoCheckPoint& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval // first, create a checkpoint from the eoContinue eoCheckPoint *checkpoint = new eoCheckPoint(_continue); _state.storeFunctor(checkpoint); - + /////////////////// // Counters ////////////////// @@ -53,14 +53,17 @@ eoCheckPoint& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval eoValueParam& useEvalParam = _parser.createParam(true, "useEval", "Use nb of eval. as counter (vs nb of gen.)", '\0', "Output"); eoValueParam& useTimeParam = _parser.createParam(true, "useTime", "Display time (s) every generation", '\0', "Output"); - // Create anyway a generation-counter parameter - eoValueParam *generationCounter = new eoValueParam(0, "Gen."); - // Create an incrementor (sub-class of eoUpdater). - eoIncrementor* increment = new eoIncrementor(generationCounter->value()); - // Add it to the checkpoint, - checkpoint->add(*increment); - // and store it in the state - _state.storeFunctor(increment); + // if we want the time, we need an eoTimeCounter + eoTimeCounter * tCounter = NULL; + + // Create anyway a generation-counter + // Recent change (03/2002): it is now an eoIncrementorParam, both + // a parameter AND updater so you can store it into the eoState + eoIncrementorParam *generationCounter = new eoIncrementorParam("Gen."); + // store it in the state + _state.storeFunctor(generationCounter); + // And add it to the checkpoint, + checkpoint->add(*generationCounter); // dir for DISK output eoValueParam& dirNameParam = _parser.createParam(string("Res"), "resDir", "Directory to store DISK outputs", '\0', "Output - Disk"); @@ -162,7 +165,7 @@ eoCheckPoint& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval monitor->add(_eval); if (useTimeParam.value()) // we want time { - eoTimeCounter * tCounter = new eoTimeCounter; + tCounter = new eoTimeCounter; _state.storeFunctor(tCounter); checkpoint->add(*tCounter); monitor->add(*tCounter); @@ -196,6 +199,11 @@ eoCheckPoint& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval // and feed with some statistics fileMonitor->add(*generationCounter); fileMonitor->add(_eval); + if (tCounter) // we want the time as well + { + cout << "On met timecounter\n"; + fileMonitor->add(*tCounter); + } fileMonitor->add(*bestStat); fileMonitor->add(*secondStat); } @@ -209,9 +217,11 @@ eoCheckPoint& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval _state.storeFunctor(gnuMonitor); checkpoint->add(*gnuMonitor); // and feed with some statistics - if (useEvalParam.value()) + if (useEvalParam.value()) // do we want eval as X coordinate gnuMonitor->add(_eval); - else + else if (tCounter) // or time? + gnuMonitor->add(*tCounter); + else // default: generation gnuMonitor->add(*generationCounter); gnuMonitor->add(*bestStat); gnuMonitor->add(*averageStat); diff --git a/eo/src/utils/eoUpdater.h b/eo/src/utils/eoUpdater.h index 593c6aa4..a7413ec0 100644 --- a/eo/src/utils/eoUpdater.h +++ b/eo/src/utils/eoUpdater.h @@ -29,6 +29,7 @@ #include #include +#include /** eoUpdater is a generic procudere for updating whatever you want. @@ -46,8 +47,10 @@ public: template class eoIncrementor : public eoUpdater {public : + /** Default Ctor - requires a reference to the thing to increment */ eoIncrementor(T& _counter, T _stepsize = 1) : counter(_counter), stepsize(_stepsize) {} + /** Simply increments */ virtual void operator()() { counter += stepsize; @@ -58,6 +61,33 @@ private: T stepsize; }; +/** an eoUpdater that is an eoValueParam (and thus OWNS its counter) + * Mandatory for generation counter in make_checkpoint +*/ +template +class eoIncrementorParam : public eoUpdater, public eoValueParam +{ +public : + /** Default Ctor : a name and optionally an increment*/ + eoIncrementorParam(string _name, T _stepsize = 1) : + eoValueParam(T(0), _name), stepsize(_stepsize) {} + + /** Ctor with a name and non-zero initial value + * and mandatory stepSize to remove ambiguity + */ + eoIncrementorParam(string _name, T _countValue, T _stepsize) : + eoValueParam(_countValue, _name), stepsize(_stepsize) {} + + /** Simply increments */ + virtual void operator()() + { + value() += stepsize; + } + +private: + T stepsize; +}; + #include /**