Add a stat to keep the best individual found so far, even for non-monotonic algorithms

This commit is contained in:
Johann Dreo 2012-09-06 16:05:00 +02:00
commit b83372b57b

View file

@ -356,6 +356,38 @@ private :
/** @example t-eoSSGA.cpp
*/
/** Keep the best individual found so far
*/
template <class EOT>
class eoBestIndividualStat : public eoStat<EOT, EOT>
{
public:
using eoStat<EOT, EOT>::value;
eoBestIndividualStat(std::string _description = "BestIndiv ")
: eoStat<EOT, EOT>( EOT(), _description )
{}
void operator()(const eoPop<EOT>& pop)
{
EOT best = pop.best_element();
// on the first call, value() is invalid
if( value().invalid() ) {
// thus we cannot compare it to something else
value() = best;
} else {
// keep the best individual found so far
if( best.fitness() > value().fitness() ) {
value() = best;
}
}
}
virtual std::string className(void) const { return "eoBestIndividualStat"; }
};
template <class EOT>
class eoDistanceStat : public eoStat<EOT, double>
{