* make_checkpoint.h: added --monitor_with_CtrlC option in order to monitor only when Ctrl-C is pressed

This commit is contained in:
Caner Candan 2012-06-22 17:41:46 +02:00
commit 46b3f77d9c
3 changed files with 52 additions and 3 deletions

View file

@ -59,6 +59,24 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoValu
_state.storeFunctor(checkpoint); _state.storeFunctor(checkpoint);
////////////////////
// Signal monitoring
////////////////////
#ifndef _MSC_VER
// the CtrlC monitoring interception
eoSignal<EOT> *mon_ctrlCCont;
eoValueParam<bool>& mon_ctrlCParam = _parser.createParam(false, "monitor-with-CtrlC", "Monitor current generation upon Ctrl C",0, "Stopping criterion");
if (mon_ctrlCParam.value())
{
mon_ctrlCCont = new eoSignal<EOT>;
// store
_state.storeFunctor(mon_ctrlCCont);
// add to checkpoint
checkpoint->add(*mon_ctrlCCont);
}
#endif
/////////////////// ///////////////////
// Counters // Counters
////////////////// //////////////////
@ -117,18 +135,24 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoValu
_state.storeFunctor(bestStat); _state.storeFunctor(bestStat);
// add it to the checkpoint // add it to the checkpoint
checkpoint->add(*bestStat); checkpoint->add(*bestStat);
// check if monitoring with signal
if ( mon_ctrlCParam.value() )
mon_ctrlCCont->add(*bestStat);
} }
// Average fitness alone // Average fitness alone
//---------------------- //----------------------
eoAverageStat<EOT> *averageStat = NULL; // do we need averageStat? eoAverageStat<EOT> *averageStat = NULL; // do we need averageStat?
if ( plotBestParam.value() ) // we need it for gnuplot output if ( printBestParam.value() || plotBestParam.value() || fileBestParam.value() ) // we need it for gnuplot output
{ {
averageStat = new eoAverageStat<EOT>; averageStat = new eoAverageStat<EOT>;
// store it // store it
_state.storeFunctor(averageStat); _state.storeFunctor(averageStat);
// add it to the checkpoint // add it to the checkpoint
checkpoint->add(*averageStat); checkpoint->add(*averageStat);
// check if monitoring with signal
if ( mon_ctrlCParam.value() )
mon_ctrlCCont->add(*averageStat);
} }
// Second moment stats: average and stdev // Second moment stats: average and stdev
@ -141,6 +165,9 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoValu
_state.storeFunctor(secondStat); _state.storeFunctor(secondStat);
// add it to the checkpoint // add it to the checkpoint
checkpoint->add(*secondStat); checkpoint->add(*secondStat);
// check if monitoring with signal
if ( mon_ctrlCParam.value() )
mon_ctrlCCont->add(*secondStat);
} }
// Dump of the whole population // Dump of the whole population
@ -155,6 +182,9 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoValu
_state.storeFunctor(popStat); _state.storeFunctor(popStat);
// add it to the checkpoint // add it to the checkpoint
checkpoint->add(*popStat); checkpoint->add(*popStat);
// check if monitoring with signal
if ( mon_ctrlCParam.value() )
mon_ctrlCCont->add(*popStat);
} }
// do we wnat some histogram of fitnesses snpashots? // do we wnat some histogram of fitnesses snpashots?
@ -175,7 +205,11 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoValu
_state.storeFunctor(monitor); _state.storeFunctor(monitor);
// when called by the checkpoint (i.e. at every generation) // when called by the checkpoint (i.e. at every generation)
checkpoint->add(*monitor); // check if monitoring with signal
if ( ! mon_ctrlCParam.value() )
checkpoint->add(*monitor);
else
mon_ctrlCCont->add(*monitor);
// the monitor will output a series of parameters: add them // the monitor will output a series of parameters: add them
monitor->add(*generationCounter); monitor->add(*generationCounter);
@ -186,7 +220,11 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoValu
{ {
tCounter = new eoTimeCounter; tCounter = new eoTimeCounter;
_state.storeFunctor(tCounter); _state.storeFunctor(tCounter);
checkpoint->add(*tCounter); // check if monitoring with signal
if ( ! mon_ctrlCParam.value() )
checkpoint->add(*tCounter);
else
mon_ctrlCCont->add(*tCounter);
monitor->add(*tCounter); monitor->add(*tCounter);
} }

View file

@ -36,6 +36,7 @@
#include <utils/eoGnuplot1DSnapshot.h> #include <utils/eoGnuplot1DSnapshot.h>
#endif #endif
#include <utils/eoCheckPoint.h> #include <utils/eoCheckPoint.h>
#include <utils/eoSignal.h>
#include <utils/eoStat.h> #include <utils/eoStat.h>
#include <utils/eoScalarFitnessStat.h> #include <utils/eoScalarFitnessStat.h>
#include <utils/eoAssembledFitnessStat.h> #include <utils/eoAssembledFitnessStat.h>

View file

@ -52,13 +52,23 @@ public :
eoSignal( int sig = SIGINT ) : eoCheckPoint<EOT>( _dummyContinue ), _sig( sig ) eoSignal( int sig = SIGINT ) : eoCheckPoint<EOT>( _dummyContinue ), _sig( sig )
{ {
::signals_called[_sig] = false; ::signals_called[_sig] = false;
#ifndef _WINDOWS
#ifdef SIGQUIT
::signal( _sig, handler ); ::signal( _sig, handler );
#endif // !SIGQUIT
#endif // !_WINDOWS
} }
eoSignal( eoContinue<EOT>& _cont, int sig = SIGINT ) : eoCheckPoint<EOT>( _cont ), _sig( sig ) eoSignal( eoContinue<EOT>& _cont, int sig = SIGINT ) : eoCheckPoint<EOT>( _cont ), _sig( sig )
{ {
::signals_called[_sig] = false; ::signals_called[_sig] = false;
#ifndef _WINDOWS
#ifdef SIGQUIT
::signal( _sig, handler ); ::signal( _sig, handler );
#endif // !SIGQUIT
#endif // !_WINDOWS
} }
bool operator()( const eoPop<EOT>& _pop ) bool operator()( const eoPop<EOT>& _pop )