added eoFuncPtrStat, and appended various addTo member functions for more elegant definition of monitors, stats, checkpoints, etc
This commit is contained in:
parent
d78387591b
commit
cb85c19259
6 changed files with 58 additions and 3 deletions
|
|
@ -32,6 +32,7 @@
|
|||
#include <utils/eoMonitor.h>
|
||||
#include <utils/eoStat.h>
|
||||
|
||||
|
||||
/** eoCheckPoint is a container class.
|
||||
It contains std::vectors of (pointers to)
|
||||
eoContinue (modif. MS July 16. 2002)
|
||||
|
|
|
|||
|
|
@ -62,8 +62,9 @@ eoMonitor& eoFileMonitor::operator()(void)
|
|||
|
||||
eoMonitor& eoFileMonitor::operator()(std::ostream& os)
|
||||
{
|
||||
|
||||
iterator it = vec.begin();
|
||||
|
||||
|
||||
os << (*it)->getValue();
|
||||
|
||||
for(++it; it != vec.end(); ++it)
|
||||
|
|
|
|||
36
eo/src/utils/eoFuncPtrStat.h
Normal file
36
eo/src/utils/eoFuncPtrStat.h
Normal 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
|
||||
|
||||
|
|
@ -10,8 +10,8 @@ eoMonitor& eoGnuplot1DSnapshot::operator()()
|
|||
{
|
||||
// update file using the eoFileMonitor method
|
||||
eoFileSnapshot::operator()();
|
||||
|
||||
#ifdef HAVE_GNUPLOT
|
||||
|
||||
// sends plot order to gnuplot
|
||||
std::ostringstream os;
|
||||
os << "set title 'Gen. " << getCounter() << "'; plot '"
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
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>
|
||||
|
||||
class eoParam;
|
||||
template <class EOT> class eoCheckPoint;
|
||||
|
||||
/**
|
||||
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"; }
|
||||
|
||||
template <class EOT>
|
||||
eoMonitor& addTo(eoCheckPoint<EOT>& cp) { cp.add(*this); return *this; }
|
||||
|
||||
protected :
|
||||
typedef std::vector<const eoParam*>::iterator iterator;
|
||||
std::vector<const eoParam*> vec;
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@
|
|||
#include <utils/eoParam.h>
|
||||
#include <eoPop.h>
|
||||
#include <eoParetoFitness.h>
|
||||
#include <utils/eoMonitor.h>
|
||||
#include <utils/eoCheckPoint.h>
|
||||
|
||||
/**
|
||||
Base class for all statistics that need to be calculated
|
||||
|
|
@ -49,6 +51,9 @@ public:
|
|||
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
|
||||
that need to be calculated over the (unsorted) population
|
||||
|
|
@ -65,6 +70,10 @@ public:
|
|||
|
||||
virtual std::string className(void) const
|
||||
{ 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:
|
||||
virtual void lastCall(const std::vector<const EOT*>&) {}
|
||||
virtual std::string className(void) const { return "eoSortedStatBase"; }
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -91,6 +101,9 @@ class eoSortedStat : public eoSortedStatBase<EOT>, public eoValueParam<ParamType
|
|||
public :
|
||||
eoSortedStat(ParamType _value, std::string _desc) : eoValueParam<ParamType>(_value, _desc) {}
|
||||
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; }
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue