00001
00025
00026
00027 #ifndef eoLinearFitScaling_h
00028 #define eoLinearFitScaling_h
00029
00030 #include <eoSelectFromWorth.h>
00031 #include <eoPerf2Worth.h>
00032
00042 template <class EOT>
00043 class eoLinearFitScaling : public eoPerf2Worth<EOT>
00044 {
00045 public:
00046
00047 using eoPerf2Worth<EOT>::value;
00048
00049
00050
00051
00052
00053 eoLinearFitScaling(double _p=2.0)
00054 : pressure(_p) {}
00055
00056
00057
00058
00059
00060 virtual void operator()(const eoPop<EOT>& _pop) {
00061 unsigned pSize =_pop.size();
00062
00063 value().resize(pSize);
00064
00065
00066 double bestFitness = static_cast<double> (_pop.best_element().fitness());
00067
00068
00069
00070 double sum=0.0;
00071 unsigned i;
00072 for (i=0; i<pSize; i++)
00073 sum += static_cast<double>(_pop[i].fitness());
00074 double averageFitness = sum/pSize;
00075
00076
00077 double denom = pSize*(bestFitness - averageFitness);
00078 double alpha = (pressure-1)/denom;
00079 double beta = (bestFitness - pressure*averageFitness)/denom;
00080
00081 for (i=0; i<pSize; i++) {
00082 value()[i] = std::max(alpha*_pop[i].fitness()+beta, 0.0);
00083 }
00084 }
00085
00086 private:
00087 double pressure;
00088 };
00089
00090
00091
00092 #endif