eoEsStandardXover.h

00001 
00023 //-----------------------------------------------------------------------------
00024 
00025 
00026 #ifndef _eoEsLocalXover_H
00027 #define _eoEsLocalXover_H
00028 
00029 #include <utils/eoRNG.h>
00030 
00031 #include <es/eoEsSimple.h>
00032 #include <es/eoEsStdev.h>
00033 #include <es/eoEsFull.h>
00034 
00035 #include <eoGenOp.h>
00036 // needs a selector - here random
00037 #include <eoRandomSelect.h>
00038 
00045 template<class EOT> 
00046 class eoEsStandardXover: public eoBinOp<EOT>
00047 {
00048 public:
00049   typedef typename EOT::Fitness FitT;
00050 
00054   eoEsStandardXover(eoBinOp<double> & _crossObj, eoBinOp<double> & _crossMut) :
00055     crossObj(_crossObj), crossMut(_crossMut) {}
00056 
00058   virtual std::string className() const { return "eoEsStandardXover"; }
00059 
00064   bool operator()(EOT& _eo1, const EOT& _eo2)
00065     {
00066       bool bLoc=false;
00067     // first, the object variables
00068     for (unsigned i=0; i<_eo1.size(); i++)
00069       {
00070         bLoc |= crossObj(_eo1[i], _eo2[i]); // apply eoBinOp
00071       }
00072     // then the self-adaptation parameters
00073     bLoc |= cross_self_adapt(_eo1, _eo2);
00074     return bLoc;
00075   }
00076   
00077 private:
00078 
00079   // the method to cross slef-adaptation parameters: need to specialize
00080 
00081   bool cross_self_adapt(eoEsSimple<FitT> & _parent1, const eoEsSimple<FitT> & _parent2)
00082   {
00083     return crossMut(_parent1.stdev, _parent2.stdev); // apply eoBinOp
00084   }
00085 
00086   bool cross_self_adapt(eoEsStdev<FitT> & _parent1, const eoEsStdev<FitT> & _parent2)
00087   {
00088     bool bLoc=false;
00089     for (unsigned i=0; i<_parent1.size(); i++)
00090       {
00091         bLoc |= crossMut(_parent1.stdevs[i], _parent2.stdevs[i]); // apply eoBinOp
00092       }
00093     return bLoc;
00094   }
00095 
00096   bool cross_self_adapt(eoEsFull<FitT> & _parent1, const eoEsFull<FitT> & _parent2)
00097   {
00098     bool bLoc=false;
00099     unsigned i;
00100     // the StDev
00101     for (i=0; i<_parent1.size(); i++)
00102       {
00103         bLoc |= crossMut(_parent1.stdevs[i], _parent2.stdevs[i]); // apply eoBinOp
00104       }
00105     // the roataion angles
00106     for (i=0; i<_parent1.correlations.size(); i++)
00107       {
00108         bLoc |= crossMut(_parent1.correlations[i], _parent2.correlations[i]); // apply eoBinOp
00109       }
00110     return bLoc;
00111 
00112   }
00113 
00114   // the data
00115   eoRandomSelect<EOT> sel;
00116   eoBinOp<double> & crossObj;
00117   eoBinOp<double> & crossMut;
00118 };
00119 
00120 #endif

Generated on Thu Apr 19 11:02:27 2007 for EO by  doxygen 1.4.7