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
00055 split(_howManyEliminatedParents, true),
00056
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();
00065
00066 plus(temp, _offspring);
00067
00068
00069 reduce(_offspring, temp);
00070
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
00077 plus(_offspring, _parents);
00078 }
00079
00080 private:
00081 eoLinearTruncateSplit<EOT> split;
00082 eoTruncateSplit<EOT> reduce;
00083 eoPlus<EOT> plus;
00084 };
00085
00086 #endif