diff --git a/eo/doc/Makefile.am b/eo/doc/Makefile.am index 0f22bbdf5..922a7810d 100644 --- a/eo/doc/Makefile.am +++ b/eo/doc/Makefile.am @@ -6,4 +6,12 @@ ############################################################################### -EXTRA_DIST = eo.cfg foot.html \ No newline at end of file +EXTRA_DIST = eo.cfg foot.html html/* latex/* + +all : + +doc : eo.cfg + doxygen eo.cfg + +clean : + rm -rf html latex man diff --git a/eo/src/eoPop.h b/eo/src/eoPop.h index 7d254cb48..bd8c54fa2 100644 --- a/eo/src/eoPop.h +++ b/eo/src/eoPop.h @@ -27,6 +27,7 @@ #include #include +#include // EO includes #include // for eoInit @@ -90,6 +91,15 @@ class eoPop: public vector, public eoObject, public eoPersistent /// ~eoPop() {}; + + /// helper struct for getting a pointer + struct Ref { const EOT* operator()(const EOT& eot) { return &eot;}}; + /// helper struct for comparing on pointers + struct Cmp { + bool operator()(const EO* a, const EO* b) const + { return b->operator<(*a); } + }; + /** sort the population. Use this member to sort in order of descending Fitness, so the first individual is the best! @@ -99,6 +109,15 @@ class eoPop: public vector, public eoObject, public eoPersistent std::sort(begin(), end(), greater >()); } + void sort(vector& result) const + { + result.resize(size()); + + std::transform(begin(), end(), result.begin(), Ref()); + + std::sort(result.begin(), result.end(), Cmp()); + } + /** slightly faster algorithm than sort to find all individuals that are better than the nth individual @@ -123,11 +142,6 @@ class eoPop: public vector, public eoObject, public eoPersistent return *it; } - struct Ref { const EOT* operator()(const EOT& eot) { return &eot;}}; - struct Cmp { - bool operator()(const EO* a, const EO* b) const - { return b->operator<(*a); } - }; /// const nth_element function, returns pointers to sorted individuals void nth_element(int which, vector& result) const { diff --git a/eo/src/utils/eoCheckPoint.h b/eo/src/utils/eoCheckPoint.h index c7abcef7b..831a19419 100644 --- a/eo/src/utils/eoCheckPoint.h +++ b/eo/src/utils/eoCheckPoint.h @@ -30,6 +30,7 @@ #include template class eoStatBase; +template class eoSortedStatBase; class eoMonitor; class eoUpdater; @@ -42,6 +43,7 @@ public : bool operator()(const eoPop& _pop); + void add(eoSortedStatBase& _stat) { sorted.push_back(&_stat); } void add(eoStatBase& _stat) { stats.push_back(&_stat); } void add(eoMonitor& _mon) { monitors.push_back(&_mon); } void add(eoUpdater& _upd) { updaters.push_back(&_upd); } @@ -51,6 +53,7 @@ public : private : eoContinue& cont; + std::vector*> sorted; std::vector*> stats; std::vector monitors; std::vector updaters; @@ -60,6 +63,18 @@ template bool eoCheckPoint::operator()(const eoPop& _pop) { unsigned i; + + if (!sorted.empty()) + { + vector sorted_pop; + _pop.sort(sorted_pop); + + for (i = 0; i < sorted.size(); ++i) + { + (*sorted[i])(sorted_pop); + } + } + for (i = 0; i < stats.size(); ++i) (*stats[i])(_pop); diff --git a/eo/src/utils/eoStat.h b/eo/src/utils/eoStat.h index a78a5eea0..0ae15e761 100644 --- a/eo/src/utils/eoStat.h +++ b/eo/src/utils/eoStat.h @@ -31,17 +31,13 @@ #include #include +/** + Base class for all statistics that need to be calculated + over the (unsorted) population +*/ template class eoStatBase : public eoUnaryFunctor&> -{ -public : - virtual ~eoStatBase(){} - - /** - calculate some statistic on the population - */ - virtual void operator()(const eoPop& _pop) = 0; -}; +{}; template class eoStat : public eoValueParam, public eoStatBase @@ -50,6 +46,21 @@ public : eoStat(T _value, std::string _description) : eoValueParam(_value, _description) {} }; +/** + Base class for statistics calculated over a sorted snapshot of the population +*/ +template +class eoSortedStatBase : public eoUnaryFunctor&> +{ +}; + +template +class eoSortedStat : public eoSortedStatBase, public eoValueParam +{ +public : + eoSortedStat(ParamType _value, std::string _desc) : eoValueParam(_value, _desc) {} +}; + #include /** @@ -104,19 +115,19 @@ public : }; template -class eoNthElementFitnessStat : public eoStat +class eoNthElementFitnessStat : public eoSortedStat { public : typedef typename EOT::Fitness Fitness; - eoNthElementFitnessStat(int _which, std::string _description = "nth element fitness") : eoStat(Fitness(), _description), which(_which) {} + eoNthElementFitnessStat(int _which, std::string _description = "nth element fitness") : eoSortedStat(Fitness(), _description), which(_which) {} - virtual void operator()(const eoPop& _pop) + virtual void operator()(const vector& _pop) { if (which > _pop.size()) throw logic_error("fitness requested of element outside of pop"); - value() = _pop.nth_element_fitness(which); + value() = _pop[which]->fitness(); } private :