EvolvingObjects
eoG3Replacement.h
00001 
00024 //-----------------------------------------------------------------------------
00025 
00026 #ifndef _eoG3Replacement_h
00027 #define _eoG3Replacement_h
00028 
00029 
00030 //-----------------------------------------------------------------------------
00031 #include <eoPop.h>
00032 #include <eoFunctor.h>
00033 #include <eoMerge.h>
00034 #include <eoReduce.h>
00035 #include <utils/eoHowMany.h>
00036 #include <eoReduceSplit.h>
00037 //-----------------------------------------------------------------------------
00038 
00049 template <class EOT>
00050 class eoG3Replacement : public eoReplacement<EOT>
00051 {
00052 public:
00053   eoG3Replacement(eoHowMany _howManyEliminatedParents = eoHowMany(2, false)) :
00054     // split truncates the parents and returns eliminated parents
00055     split(_howManyEliminatedParents, true),
00056     // reduce truncates the offpsring and does not return eliminated guys
00057     reduce(-_howManyEliminatedParents, false)
00058   {}
00059 
00060     void operator()(eoPop<EOT> & _parents, eoPop<EOT> & _offspring)
00061     {
00062       eoPop<EOT> temp;
00063       split(_parents, temp);
00064       unsigned toKeep = temp.size(); // how many to keep from merged populations
00065       // merge temp into offspring
00066       plus(temp, _offspring);      // add temp to _offspring (a little inconsistent!)
00067 
00068       // reduce merged
00069       reduce(_offspring, temp);    // temp dummy arg. will not be modified
00070       // minimla check:
00071       if (_offspring.size() != toKeep)
00072         {
00073           std::cerr << "Les tailles " << _offspring.size() << " " << toKeep << std::endl;
00074         throw std::runtime_error("eoG3Replacement: wrong number of remaining offspring");
00075         }
00076       // and put back into _parents
00077       plus(_offspring, _parents);
00078     }
00079 
00080 private:
00081   eoLinearTruncateSplit<EOT> split; // few parents to truncate -> linear
00082   eoTruncateSplit<EOT> reduce;     // supposedly many offspring to truncate
00083   eoPlus<EOT> plus;
00084 };
00085 
00086 #endif
 All Classes Namespaces Files Functions Variables Typedefs Friends