00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef _eoAssembledFitnessStat_h
00034 #define _eoAssembledFitnessStat_h
00035
00036 #include <utils/eoStat.h>
00037 #include <eoScalarFitnessAssembled.h>
00038
00045 template <class EOT>
00046 class eoAssembledFitnessAverageStat : public eoStat<EOT, double>
00047 {
00048 public :
00049
00050 using eoStat<EOT, double>::value;
00051
00052 typedef typename EOT::Fitness Fitness;
00053
00054
00055 eoAssembledFitnessAverageStat(unsigned _whichTerm=0, std::string _description = "Average Fitness")
00056 : eoStat<EOT, double>(Fitness(), _description), whichFitnessTerm(_whichTerm)
00057 {}
00058
00059
00060 virtual void operator()(const eoPop<EOT>& _pop) {
00061 if( whichFitnessTerm >= _pop[0].fitness().size() )
00062 throw std::logic_error("Fitness term requested out of range");
00063
00064 double result =0.0;
00065 unsigned count = 0;
00066 for (typename eoPop<EOT>::const_iterator it = _pop.begin(); it != _pop.end(); ++it){
00067 if ( it->fitness().failed == false ){
00068 result+= it->fitness()[whichFitnessTerm];
00069 ++count;
00070 }
00071 }
00072
00073 value() = result / (double) count;
00074 }
00075
00076 private:
00077
00078 unsigned whichFitnessTerm;
00079 };
00080
00086 template <class EOT>
00087 class eoAssembledFitnessBestStat : public eoStat<EOT, double>
00088 {
00089 public:
00090
00091 using eoStat<EOT, double>::value;
00092
00093 typedef typename EOT::Fitness Fitness;
00094
00095 eoAssembledFitnessBestStat(unsigned _whichTerm=0, std::string _description = "Best Fitness")
00096 : eoStat<EOT, double>(Fitness(), _description), whichFitnessTerm(_whichTerm)
00097 {}
00098
00099 virtual void operator()(const eoPop<EOT>& _pop) {
00100 if( whichFitnessTerm >= _pop[0].fitness().size() )
00101 throw std::logic_error("Fitness term requested out of range");
00102
00103 value() = _pop.best_element().fitness()[whichFitnessTerm];
00104 }
00105
00106 private:
00107
00108
00109 unsigned whichFitnessTerm;
00110 };
00111
00112 #endif