Added the eoIncrementorParam - now ALL pointers allocated in make_checkpoint
are stored somewhere (the generation counter was not)
This commit is contained in:
parent
bd688656bb
commit
6848622539
2 changed files with 52 additions and 12 deletions
|
|
@ -45,7 +45,7 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval
|
|||
// first, create a checkpoint from the eoContinue
|
||||
eoCheckPoint<EOT> *checkpoint = new eoCheckPoint<EOT>(_continue);
|
||||
_state.storeFunctor(checkpoint);
|
||||
|
||||
|
||||
///////////////////
|
||||
// Counters
|
||||
//////////////////
|
||||
|
|
@ -53,14 +53,17 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval
|
|||
eoValueParam<bool>& useEvalParam = _parser.createParam(true, "useEval", "Use nb of eval. as counter (vs nb of gen.)", '\0', "Output");
|
||||
eoValueParam<bool>& useTimeParam = _parser.createParam(true, "useTime", "Display time (s) every generation", '\0', "Output");
|
||||
|
||||
// Create anyway a generation-counter parameter
|
||||
eoValueParam<unsigned> *generationCounter = new eoValueParam<unsigned>(0, "Gen.");
|
||||
// Create an incrementor (sub-class of eoUpdater).
|
||||
eoIncrementor<unsigned>* increment = new eoIncrementor<unsigned>(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<unsigned> *generationCounter = new eoIncrementorParam<unsigned>("Gen.");
|
||||
// store it in the state
|
||||
_state.storeFunctor(generationCounter);
|
||||
// And add it to the checkpoint,
|
||||
checkpoint->add(*generationCounter);
|
||||
|
||||
// dir for DISK output
|
||||
eoValueParam<string>& dirNameParam = _parser.createParam(string("Res"), "resDir", "Directory to store DISK outputs", '\0', "Output - Disk");
|
||||
|
|
@ -162,7 +165,7 @@ eoCheckPoint<EOT>& 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<EOT>& 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<EOT>& 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);
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include <eoFunctor.h>
|
||||
#include <utils/eoState.h>
|
||||
#include <utils/eoParam.h>
|
||||
|
||||
/**
|
||||
eoUpdater is a generic procudere for updating whatever you want.
|
||||
|
|
@ -46,8 +47,10 @@ public:
|
|||
template <class T>
|
||||
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 T>
|
||||
class eoIncrementorParam : public eoUpdater, public eoValueParam<T>
|
||||
{
|
||||
public :
|
||||
/** Default Ctor : a name and optionally an increment*/
|
||||
eoIncrementorParam(string _name, T _stepsize = 1) :
|
||||
eoValueParam<T>(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<T>(_countValue, _name), stepsize(_stepsize) {}
|
||||
|
||||
/** Simply increments */
|
||||
virtual void operator()()
|
||||
{
|
||||
value() += stepsize;
|
||||
}
|
||||
|
||||
private:
|
||||
T stepsize;
|
||||
};
|
||||
|
||||
#include <time.h>
|
||||
|
||||
/**
|
||||
|
|
|
|||
Reference in a new issue