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 #ifndef _eoPBILAdditive_H
00027 #define _eoPBILAdditive_H
00028
00029 #include <eoDistribUpdater.h>
00030 #include <ga/eoPBILDistrib.h>
00031
00045 template <class EOT>
00046 class eoPBILAdditive : public eoDistribUpdater<EOT>
00047 {
00048 public:
00052 eoPBILAdditive(double _LRBest, unsigned _nbBest = 1,
00053 double _tolerance=0.0,
00054 double _LRWorst = 0.0, unsigned _nbWorst = 0 ) :
00055 maxBound(1.0-_tolerance), minBound(_tolerance),
00056 LR(0.0), nbBest(_nbBest), nbWorst(_nbWorst)
00057 {
00058 if (nbBest+nbWorst == 0)
00059 throw std::runtime_error("Must update either from best or from worst in eoPBILAdditive");
00060
00061 if (_nbBest)
00062 {
00063 lrb = _LRBest/_nbBest;
00064 LR += _LRBest;
00065 }
00066 else
00067 lrb=0.0;
00068 if (_nbWorst)
00069 {
00070 lrw = _LRWorst/_nbWorst;
00071 LR += _LRWorst;
00072 }
00073 else
00074 lrw=0.0;
00075 }
00076
00078 virtual void operator()(eoDistribution<EOT> & _distrib, eoPop<EOT>& _pop)
00079 {
00080 eoPBILDistrib<EOT>& distrib = dynamic_cast<eoPBILDistrib<EOT>&>(_distrib);
00081
00082 std::vector<double> & p = distrib.value();
00083
00084 unsigned i, popSize=_pop.size();
00085 std::vector<const EOT*> result;
00086 _pop.sort(result);
00087
00088
00089 for (unsigned g=0; g<distrib.size(); g++)
00090 {
00091 p[g] *= (1-LR);
00092 if (nbBest)
00093 for (i=0; i<nbBest; i++)
00094 {
00095 const EOT & best = (*result[i]);
00096 if ( best[g] )
00097 p[g] += lrb;
00098 }
00099 if (nbWorst)
00100 for (i=popSize-1; i>=popSize-nbWorst; i--)
00101 {
00102 const EOT & best = (*result[i]);
00103 if ( !best[g] )
00104 p[g] += lrw;
00105 }
00106
00107 p[g] = std::min(maxBound, p[g]);
00108 p[g] = std::max(minBound, p[g]);
00109 }
00110 }
00111
00112 private:
00113 double maxBound, minBound;
00114 double LR;
00115 unsigned nbBest;
00116 unsigned nbWorst;
00117 double lrb, lrw;
00118 };
00119
00120 #endif