EvolvingObjects
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 template<class EOT>
00075 class eoReplacement : public eoBF<eoPop<EOT>&, eoPop<EOT>&, void>
00076 {};
00077 
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 
00103 template <class EOT>
00104 class eoWeakElitistReplacement : public eoReplacement<EOT>
00105 {
00106 public :
00107   typedef typename EOT::Fitness Fitness;
00108 
00109   // Ctor, takes an eoReplacement
00110   eoWeakElitistReplacement(eoReplacement<EOT> & _replace) :
00111     replace(_replace) {}
00112 
00114   void operator()(eoPop<EOT>& _pop, eoPop<EOT>& _offspring)
00115   {
00116     const EOT oldChamp = _pop.best_element();
00117     replace(_pop, _offspring);     // "normal" replacement, parents are the new
00118     if (_pop.best_element() < oldChamp) // need to do something
00119       {
00120         typename eoPop<EOT>::iterator itPoorGuy = _pop.it_worse_element();
00121         (*itPoorGuy) = oldChamp;
00122       }
00123   }
00124 private:
00125   eoReplacement<EOT> & replace;
00126 };
00127 
00128 #endif
 All Classes Namespaces Files Functions Variables Typedefs Friends