added eoFuncPtrStat, and appended various addTo member functions for more elegant definition of monitors, stats, checkpoints, etc

This commit is contained in:
maartenkeijzer 2007-09-05 11:36:44 +00:00
commit cb85c19259
6 changed files with 58 additions and 3 deletions

View file

@ -32,6 +32,7 @@
#include <utils/eoMonitor.h> #include <utils/eoMonitor.h>
#include <utils/eoStat.h> #include <utils/eoStat.h>
/** eoCheckPoint is a container class. /** eoCheckPoint is a container class.
It contains std::vectors of (pointers to) It contains std::vectors of (pointers to)
eoContinue (modif. MS July 16. 2002) eoContinue (modif. MS July 16. 2002)

View file

@ -62,6 +62,7 @@ eoMonitor& eoFileMonitor::operator()(void)
eoMonitor& eoFileMonitor::operator()(std::ostream& os) eoMonitor& eoFileMonitor::operator()(std::ostream& os)
{ {
iterator it = vec.begin(); iterator it = vec.begin();
os << (*it)->getValue(); os << (*it)->getValue();

View file

@ -0,0 +1,36 @@
#ifndef eoFuncPtrStat_h
#define eoFuncPtrStat_h
#include <eoFunctorStore.h>
#include <utils/eoStat.h>
template <class EOT, class T>
class eoFuncPtrStat : public eoStat<EOT, T>
{
public :
typedef T (*func_t)(const eoPop<EOT>&);
eoFuncPtrStat(func_t f, std::string _description = "func_ptr")
: eoStat<EOT, T>(T(), _description), func(f)
{}
using eoStat<EOT, T>::value;
void operator()(const eoPop<EOT>& pop) {
value() = func(pop);
}
private:
func_t func;
};
template <class EOT, class T>
eoFuncPtrStat<EOT, T>& makeFuncPtrStat( T (*func)(const eoPop<EOT>&), eoFunctorStore& store, std::string description = "func") {
return store.storeFunctor(
new eoFuncPtrStat<EOT, T>( func, description)
);
}
#endif

View file

@ -10,8 +10,8 @@ eoMonitor& eoGnuplot1DSnapshot::operator()()
{ {
// update file using the eoFileMonitor method // update file using the eoFileMonitor method
eoFileSnapshot::operator()(); eoFileSnapshot::operator()();
#ifdef HAVE_GNUPLOT #ifdef HAVE_GNUPLOT
// sends plot order to gnuplot // sends plot order to gnuplot
std::ostringstream os; std::ostringstream os;
os << "set title 'Gen. " << getCounter() << "'; plot '" os << "set title 'Gen. " << getCounter() << "'; plot '"

View file

@ -21,7 +21,7 @@
Contact: todos@geneura.ugr.es, http://geneura.ugr.es Contact: todos@geneura.ugr.es, http://geneura.ugr.es
Marc.Schoenauer@polytechnique.fr Marc.Schoenauer@polytechnique.fr
mak@dhi.dk mak@dhi.dk
CVS Info: $Date: 2004-06-15 07:09:57 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/src/utils/eoMonitor.h,v 1.11 2004-06-15 07:09:57 evomarc Exp $ $Author: evomarc $ CVS Info: $Date: 2007-09-05 11:36:44 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/src/utils/eoMonitor.h,v 1.12 2007-09-05 11:36:44 maartenkeijzer Exp $ $Author: maartenkeijzer $
*/ */
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -35,6 +35,7 @@ CVS Info: $Date: 2004-06-15 07:09:57 $ $Header: /home/nojhan/dev/eodev/eodev_cvs
#include <eoFunctor.h> #include <eoFunctor.h>
class eoParam; class eoParam;
template <class EOT> class eoCheckPoint;
/** /**
The abstract monitor class is a std::vector of parameter pointers. Use The abstract monitor class is a std::vector of parameter pointers. Use
@ -57,6 +58,9 @@ public :
virtual std::string className(void) const { return "eoMonitor"; } virtual std::string className(void) const { return "eoMonitor"; }
template <class EOT>
eoMonitor& addTo(eoCheckPoint<EOT>& cp) { cp.add(*this); return *this; }
protected : protected :
typedef std::vector<const eoParam*>::iterator iterator; typedef std::vector<const eoParam*>::iterator iterator;
std::vector<const eoParam*> vec; std::vector<const eoParam*> vec;

View file

@ -33,6 +33,8 @@
#include <utils/eoParam.h> #include <utils/eoParam.h>
#include <eoPop.h> #include <eoPop.h>
#include <eoParetoFitness.h> #include <eoParetoFitness.h>
#include <utils/eoMonitor.h>
#include <utils/eoCheckPoint.h>
/** /**
Base class for all statistics that need to be calculated Base class for all statistics that need to be calculated
@ -49,6 +51,9 @@ public:
virtual std::string className(void) const { return "eoStatBase"; } virtual std::string className(void) const { return "eoStatBase"; }
}; };
template <class EOT> class eoCheckPoint;
/** /**
The actual class that will be used as base for all statistics The actual class that will be used as base for all statistics
that need to be calculated over the (unsorted) population that need to be calculated over the (unsorted) population
@ -65,6 +70,10 @@ public:
virtual std::string className(void) const virtual std::string className(void) const
{ return "eoStat"; } { return "eoStat"; }
eoStat<EOT, T>& addTo(eoCheckPoint<EOT>& cp) { cp.add(*this); return *this; }
eoStat<EOT, T>& addTo(eoMonitor& mon) { mon.add(*this); return *this; }
}; };
@ -78,6 +87,7 @@ class eoSortedStatBase : public eoUF<const std::vector<const EOT*>&, void>
public: public:
virtual void lastCall(const std::vector<const EOT*>&) {} virtual void lastCall(const std::vector<const EOT*>&) {}
virtual std::string className(void) const { return "eoSortedStatBase"; } virtual std::string className(void) const { return "eoSortedStatBase"; }
}; };
/** /**
@ -91,6 +101,9 @@ class eoSortedStat : public eoSortedStatBase<EOT>, public eoValueParam<ParamType
public : public :
eoSortedStat(ParamType _value, std::string _desc) : eoValueParam<ParamType>(_value, _desc) {} eoSortedStat(ParamType _value, std::string _desc) : eoValueParam<ParamType>(_value, _desc) {}
virtual std::string className(void) const { return "eoSortedStat"; } virtual std::string className(void) const { return "eoSortedStat"; }
eoSortedStat<EOT, ParamType>& addTo(eoCheckPoint<EOT>& cp) { cp.add(*this); return *this; }
eoSortedStat<EOT, ParamType>& addTo(eoMonitor& mon) { mon.add(*this); return *this; }
}; };
/** /**