00001
00024
00025
00026 #ifndef _eoMGGReplacement_h
00027 #define _eoMGGReplacement_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 eoMGGReplacement : public eoReplacement<EOT>
00051 {
00052 public:
00053 eoMGGReplacement(eoHowMany _howManyEliminatedParents = eoHowMany(2, false),
00054 unsigned _tSize=2) :
00055
00056 split(_howManyEliminatedParents, true),
00057 tSize(_tSize)
00058 {
00059 if (tSize < 2)
00060 {
00061 std::cout << "Warning, Size for eoDetTournamentTruncateSplit adjusted to 2\n";
00062 tSize = 2;
00063 }
00064 }
00065
00066 void operator()(eoPop<EOT> & _parents, eoPop<EOT> & _offspring)
00067 {
00068 eoPop<EOT> temp;
00069 split(_parents, temp);
00070 unsigned toKeep = temp.size();
00071
00072 if (toKeep < 2)
00073 throw std::runtime_error("Not enough parents killed in eoMGGReplacement");
00074
00075
00076 typename eoPop<EOT>::iterator it = _offspring.it_best_element();
00077
00078 _parents.push_back(*it);
00079
00080 _offspring.erase(it);
00081
00082
00083 plus(temp, _offspring);
00084
00085
00086 for (unsigned i=0; i<toKeep-1; i++)
00087 {
00088
00089 it = deterministic_tournament(_offspring.begin(), _offspring.end(), tSize);
00090
00091 _parents.push_back(*it);
00092
00093 _offspring.erase(it);
00094 }
00095 }
00096
00097 private:
00098 eoLinearTruncateSplit<EOT> split;
00099 eoPlus<EOT> plus;
00100 unsigned int tSize;
00101 };
00102
00103 #endif