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
|
|
@ -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>& 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");
|
eoValueParam<bool>& useTimeParam = _parser.createParam(true, "useTime", "Display time (s) every generation", '\0', "Output");
|
||||||
|
|
||||||
// Create anyway a generation-counter parameter
|
// if we want the time, we need an eoTimeCounter
|
||||||
eoValueParam<unsigned> *generationCounter = new eoValueParam<unsigned>(0, "Gen.");
|
eoTimeCounter * tCounter = NULL;
|
||||||
// Create an incrementor (sub-class of eoUpdater).
|
|
||||||
eoIncrementor<unsigned>* increment = new eoIncrementor<unsigned>(generationCounter->value());
|
// Create anyway a generation-counter
|
||||||
// Add it to the checkpoint,
|
// Recent change (03/2002): it is now an eoIncrementorParam, both
|
||||||
checkpoint->add(*increment);
|
// a parameter AND updater so you can store it into the eoState
|
||||||
// and store it in the state
|
eoIncrementorParam<unsigned> *generationCounter = new eoIncrementorParam<unsigned>("Gen.");
|
||||||
_state.storeFunctor(increment);
|
// store it in the state
|
||||||
|
_state.storeFunctor(generationCounter);
|
||||||
|
// And add it to the checkpoint,
|
||||||
|
checkpoint->add(*generationCounter);
|
||||||
|
|
||||||
// dir for DISK output
|
// dir for DISK output
|
||||||
eoValueParam<string>& dirNameParam = _parser.createParam(string("Res"), "resDir", "Directory to store DISK outputs", '\0', "Output - Disk");
|
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);
|
monitor->add(_eval);
|
||||||
if (useTimeParam.value()) // we want time
|
if (useTimeParam.value()) // we want time
|
||||||
{
|
{
|
||||||
eoTimeCounter * tCounter = new eoTimeCounter;
|
tCounter = new eoTimeCounter;
|
||||||
_state.storeFunctor(tCounter);
|
_state.storeFunctor(tCounter);
|
||||||
checkpoint->add(*tCounter);
|
checkpoint->add(*tCounter);
|
||||||
monitor->add(*tCounter);
|
monitor->add(*tCounter);
|
||||||
|
|
@ -196,6 +199,11 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval
|
||||||
// and feed with some statistics
|
// and feed with some statistics
|
||||||
fileMonitor->add(*generationCounter);
|
fileMonitor->add(*generationCounter);
|
||||||
fileMonitor->add(_eval);
|
fileMonitor->add(_eval);
|
||||||
|
if (tCounter) // we want the time as well
|
||||||
|
{
|
||||||
|
cout << "On met timecounter\n";
|
||||||
|
fileMonitor->add(*tCounter);
|
||||||
|
}
|
||||||
fileMonitor->add(*bestStat);
|
fileMonitor->add(*bestStat);
|
||||||
fileMonitor->add(*secondStat);
|
fileMonitor->add(*secondStat);
|
||||||
}
|
}
|
||||||
|
|
@ -209,9 +217,11 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval
|
||||||
_state.storeFunctor(gnuMonitor);
|
_state.storeFunctor(gnuMonitor);
|
||||||
checkpoint->add(*gnuMonitor);
|
checkpoint->add(*gnuMonitor);
|
||||||
// and feed with some statistics
|
// and feed with some statistics
|
||||||
if (useEvalParam.value())
|
if (useEvalParam.value()) // do we want eval as X coordinate
|
||||||
gnuMonitor->add(_eval);
|
gnuMonitor->add(_eval);
|
||||||
else
|
else if (tCounter) // or time?
|
||||||
|
gnuMonitor->add(*tCounter);
|
||||||
|
else // default: generation
|
||||||
gnuMonitor->add(*generationCounter);
|
gnuMonitor->add(*generationCounter);
|
||||||
gnuMonitor->add(*bestStat);
|
gnuMonitor->add(*bestStat);
|
||||||
gnuMonitor->add(*averageStat);
|
gnuMonitor->add(*averageStat);
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
#include <eoFunctor.h>
|
#include <eoFunctor.h>
|
||||||
#include <utils/eoState.h>
|
#include <utils/eoState.h>
|
||||||
|
#include <utils/eoParam.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
eoUpdater is a generic procudere for updating whatever you want.
|
eoUpdater is a generic procudere for updating whatever you want.
|
||||||
|
|
@ -46,8 +47,10 @@ public:
|
||||||
template <class T>
|
template <class T>
|
||||||
class eoIncrementor : public eoUpdater
|
class eoIncrementor : public eoUpdater
|
||||||
{public :
|
{public :
|
||||||
|
/** Default Ctor - requires a reference to the thing to increment */
|
||||||
eoIncrementor(T& _counter, T _stepsize = 1) : counter(_counter), stepsize(_stepsize) {}
|
eoIncrementor(T& _counter, T _stepsize = 1) : counter(_counter), stepsize(_stepsize) {}
|
||||||
|
|
||||||
|
/** Simply increments */
|
||||||
virtual void operator()()
|
virtual void operator()()
|
||||||
{
|
{
|
||||||
counter += stepsize;
|
counter += stepsize;
|
||||||
|
|
@ -58,6 +61,33 @@ private:
|
||||||
T stepsize;
|
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>
|
#include <time.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Reference in a new issue