EvolvingObjects
|
00001 00025 //----------------------------------------------------------------------------- 00026 00027 #ifndef _eoReduceMerge_h 00028 #define _eoReduceMerge_h 00029 00030 00031 //----------------------------------------------------------------------------- 00032 #include <eoPop.h> 00033 #include <eoFunctor.h> 00034 #include <eoMerge.h> 00035 #include <eoReduce.h> 00036 #include <eoReplacement.h> 00037 #include <utils/eoHowMany.h> 00038 //----------------------------------------------------------------------------- 00039 00056 template <class EOT> 00057 class eoReduceMerge : public eoReplacement<EOT> 00058 { 00059 public: 00060 eoReduceMerge(eoReduce<EOT>& _reduce, eoMerge<EOT>& _merge) : 00061 reduce(_reduce), merge(_merge) 00062 {} 00063 00064 void operator()(eoPop<EOT>& _parents, eoPop<EOT>& _offspring) 00065 { 00066 if (_parents.size() < _offspring.size()) 00067 throw std::logic_error("eoReduceMerge: More offspring than parents!\n"); 00068 reduce(_parents, _parents.size() - _offspring.size()); 00069 merge(_offspring, _parents); 00070 } 00071 00072 private : 00073 eoReduce<EOT>& reduce; 00074 eoMerge<EOT>& merge; 00075 }; 00076 00080 template <class EOT> 00081 class eoSSGAWorseReplacement : public eoReduceMerge<EOT> 00082 { 00083 public : 00084 eoSSGAWorseReplacement() : eoReduceMerge<EOT>(truncate, plus) {} 00085 00086 private : 00087 eoLinearTruncate<EOT> truncate; 00088 eoPlus<EOT> plus; 00089 }; 00090 00094 template <class EOT> 00095 class eoSSGADetTournamentReplacement : public eoReduceMerge<EOT> 00096 { 00097 public : 00098 eoSSGADetTournamentReplacement(unsigned _t_size) : 00099 eoReduceMerge<EOT>(truncate, plus), truncate(_t_size) {} 00100 00101 private : 00102 eoDetTournamentTruncate<EOT> truncate; 00103 eoPlus<EOT> plus; 00104 }; 00105 00111 template <class EOT> 00112 class eoSSGAStochTournamentReplacement : public eoReduceMerge<EOT> 00113 { 00114 public : 00115 eoSSGAStochTournamentReplacement(double _t_rate) : 00116 eoReduceMerge<EOT>(truncate, plus), truncate(_t_rate) {} 00117 00118 private : 00119 eoStochTournamentTruncate<EOT> truncate; 00120 eoPlus<EOT> plus; 00121 }; 00122 00124 #endif