EvolvingObjects
eoMergeReduce.h
00001 
00023 //-----------------------------------------------------------------------------
00024 
00025 #ifndef _eoMergeReduce_h
00026 #define _eoMergeReduce_h
00027 
00028 
00029 //-----------------------------------------------------------------------------
00030 #include <eoPop.h>
00031 #include <eoFunctor.h>
00032 #include <eoMerge.h>
00033 #include <eoReduce.h>
00034 #include <eoReplacement.h>
00035 #include <utils/eoHowMany.h>
00036 //-----------------------------------------------------------------------------
00050 template <class EOT>
00051 class eoMergeReduce : public eoReplacement<EOT>
00052 {
00053     public:
00054         eoMergeReduce(eoMerge<EOT>& _merge, eoReduce<EOT>& _reduce) :
00055         merge(_merge), reduce(_reduce)
00056         {}
00057 
00058         virtual void operator()(eoPop<EOT>& _parents, eoPop<EOT>& _offspring)
00059         {
00060             merge(_parents, _offspring); // parents untouched, result in offspring
00061             reduce(_offspring, _parents.size());
00062             _parents.swap(_offspring);
00063         }
00064 
00065     private :
00066         eoMerge<EOT>& merge;
00067         eoReduce<EOT>& reduce;
00068 };
00069 
00074 template <class EOT>
00075 class eoPlusReplacement : public eoMergeReduce<EOT>
00076 {
00077     public :
00078         eoPlusReplacement() : eoMergeReduce<EOT>(plus, truncate) {}
00079 
00080     private :
00081         eoPlus<EOT> plus;
00082         eoTruncate<EOT> truncate;
00083 };
00084 
00089 template <class EOT>
00090 class eoCommaReplacement : public eoMergeReduce<EOT>
00091 {
00092     public :
00093         eoCommaReplacement() : eoMergeReduce<EOT>(no_elite, truncate) {}
00094 
00095         virtual void operator()(eoPop<EOT>& _parents, eoPop<EOT>& _offspring)
00096         {
00097             // There must be more offsprings than parents, or else an exception will be raised
00098             assert( _offspring.size() >= _parents.size() );
00099 
00100             eoMergeReduce<EOT>::operator()( _parents, _offspring );
00101         }
00102 
00103     private :
00104         eoNoElitism<EOT> no_elite;
00105         eoTruncate<EOT> truncate;
00106 };
00107 
00113 template <class EOT>
00114 class eoEPReplacement : public eoMergeReduce<EOT>
00115 {
00116 public :
00117   eoEPReplacement(int _tSize) : eoMergeReduce<EOT>(plus, truncate), truncate(_tSize)
00118     //  {truncate.setSize(_tSize);}
00119   {}
00120 private :
00121   eoPlus<EOT> plus;
00122   eoEPReduce<EOT> truncate;
00123 };
00124 
00125 
00126 
00127 #endif
 All Classes Namespaces Files Functions Variables Typedefs Friends