diff --git a/eo/src/eoEvalCounterThrowException.h b/eo/src/eoEvalCounterThrowException.h index 8b38908e4..b83699916 100644 --- a/eo/src/eoEvalCounterThrowException.h +++ b/eo/src/eoEvalCounterThrowException.h @@ -37,6 +37,10 @@ algorithm have reached a maximum number of evaluations. This may be useful if you want to check this kind of stopping criterion at each _evaluation_, instead of using continuators at each _iteration_. +This eval counter permits to stop a search during a generation, without waiting for a continue to be +checked at the end of the loop. Useful if you have 10 individuals and 10 generations, +but want to stop after 95 evaluations. + The class first call the evaluation function, then check the number of times it has been called. If the maximum number of evaluation has been reached, it throw an eoMaxEvalException. You can catch this exception @@ -72,7 +76,7 @@ public : } // evaluate - func(eo); + this->eoEvalFuncCounter::operator()(eo); } // if invalid } diff --git a/eo/src/eoEvalFuncCounterBounder.h b/eo/src/eoEvalFuncCounterBounder.h deleted file mode 100644 index 30ac03473..000000000 --- a/eo/src/eoEvalFuncCounterBounder.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef eoEvalFuncCounterBounder_H -#define eoEvalFuncCounterBounder_H - -#include "eoEvalFunc.h" -#include "utils/eoParam.h" - -/** @addtogroup Evaluation - * @{ - */ - -/** The exception raised by eoEvalFuncCounterBounder - * when the maximum number of allowed evaluations is reached. - */ -class eoEvalFuncCounterBounderException : public std::exception -{ -public: - eoEvalFuncCounterBounderException(unsigned long threshold) : _threshold(threshold){} - - const char* what() const throw() - { - std::ostringstream ss; - ss << "STOP in eoEvalFuncCounterBounderException: the maximum number of evaluation has been reached (" << _threshold << ")."; - return ss.str().c_str(); - } - -private: - unsigned long _threshold; -}; - -/** Counts the number of evaluations actually performed and throw an eoEvalFuncCounterBounderException - * when the maximum number of allowed evaluations is reached. - * - * This eval counter permits to stop a search during a generation, without waiting for a continue to be - * checked at the end of the loop. Useful if you have 10 individuals and 10 generations, - * but want to stop after 95 evaluations. -*/ -template < typename EOT > -class eoEvalFuncCounterBounder : public eoEvalFuncCounter< EOT > -{ -public : - eoEvalFuncCounterBounder(eoEvalFunc& func, unsigned long threshold, std::string name = "Eval. ") - : eoEvalFuncCounter< EOT >( func, name ), _threshold( threshold ) - {} - - using eoEvalFuncCounter< EOT >::value; - - virtual void operator()(EOT& eo) - { - if (eo.invalid()) - { - value()++; - - if (_threshold > 0 && value() >= _threshold) - { - throw eoEvalFuncCounterBounderException(_threshold); - } - - this->func(eo); - } - } - -private : - unsigned long _threshold; -}; - -/** @} */ -#endif