# eoReplacement.h

    00001
    00025 //-----------------------------------------------------------------------------
    00026
    00027 #ifndef _eoReplacement_h
    00028 #define _eoReplacement_h
    00029
    00030
    00031 //-----------------------------------------------------------------------------
    00032 #include <eoPop.h>
    00033 #include <eoFunctor.h>
    00034 #include <eoMerge.h>
    00035 #include <eoReduce.h>
    00036 #include <utils/eoHowMany.h>
    00037 //-----------------------------------------------------------------------------
    00038
    00074
    00076 template<class EOT>
    00077 class eoReplacement : public eoBF<eoPop<EOT>&, eoPop<EOT>&, void>
    00078 {};
    00079
    00083 template <class EOT>
    00084 class eoGenerationalReplacement : public eoReplacement<EOT>
    00085 {
    00086     public :
    00088   void operator()(eoPop<EOT>& _parents, eoPop<EOT>& _offspring)
    00089   {
    00090     _parents.swap(_offspring);
    00091   }
    00092 };
    00093
    00101 template <class EOT>
    00102 class eoWeakElitistReplacement : public eoReplacement<EOT>
    00103 {
    00104 public :
    00105   typedef typename EOT::Fitness Fitness;
    00106
    00107   // Ctor, takes an eoReplacement
    00108   eoWeakElitistReplacement(eoReplacement<EOT> & _replace) :
    00109     replace(_replace) {}
    00110
    00112   void operator()(eoPop<EOT>& _pop, eoPop<EOT>& _offspring)
    00113   {
    00114     const EOT & oldChamp = _pop.best_element();
    00115     replace(_pop, _offspring);     // "normal" replacement, parents are the new
    00116     if (_pop.best_element() < oldChamp) // need to do something
    00117       {
    00118         typename eoPop<EOT>::iterator itPoorGuy = _pop.it_worse_element();
    00119         (*itPoorGuy) = oldChamp;
    00120       }
    00121   }
    00122 private:
    00123   eoReplacement<EOT> & replace;
    00124 };
    00125
    00127
    00128 #endif