00001
00025
00026
00027 #ifndef eoRanking_h
00028 #define eoRanking_h
00029
00030 #include <eoPerf2Worth.h>
00031
00037 template <class EOT>
00038 class eoRanking : public eoPerf2Worth<EOT>
00039 {
00040 public:
00041
00042 using eoPerf2Worth<EOT>::value;
00043
00044
00045
00046
00047
00048 eoRanking(double _p=2.0, double _e=1.0):
00049 pressure(_p), exponent(_e) {}
00050
00051
00052 int lookfor(const EOT *_eo, const eoPop<EOT>& _pop)
00053 {
00054 typename eoPop<EOT>::const_iterator it;
00055 for (it=_pop.begin(); it<_pop.end(); it++)
00056 {
00057 if (_eo == &(*it))
00058 return it-_pop.begin();
00059 }
00060 throw std::runtime_error("Not found in eoLinearRanking");
00061 }
00062
00063
00064
00065
00066
00067 virtual void operator()(const eoPop<EOT>& _pop)
00068 {
00069 std::vector<const EOT *> rank;
00070 _pop.sort(rank);
00071 unsigned pSize =_pop.size();
00072 unsigned int pSizeMinusOne = pSize-1;
00073
00074 if (pSize <= 1)
00075 throw std::runtime_error("Cannot do ranking with population of size <= 1");
00076
00077
00078 value().resize(pSize);
00079
00080 double beta = (2-pressure)/pSize;
00081 if (exponent == 1.0)
00082 {
00083 double alpha = (2*pressure-2)/(pSize*pSizeMinusOne);
00084 for (unsigned i=0; i<pSize; i++)
00085 {
00086 int which = lookfor(rank[i], _pop);
00087 value()[which] = alpha*(pSize-i)+beta;
00088 }
00089 }
00090 else
00091 {
00092 double gamma = (2*pressure-2)/pSize;
00093 for (unsigned i=0; i<pSize; i++)
00094 {
00095 int which = lookfor(rank[i], _pop);
00096
00097 double tmp = ((double)(pSize-i))/pSize;
00098
00099 value()[which] = gamma*pow(tmp, exponent)+beta;
00100 }
00101 }
00102 }
00103 private:
00104 double pressure;
00105 double exponent;
00106 };
00107
00108
00109
00110 #endif