EvolvingObjects
|
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 00048 template<class EOT> 00049 class eoEsStandardXover: public eoBinOp<EOT> 00050 { 00051 public: 00052 typedef typename EOT::Fitness FitT; 00053 00057 eoEsStandardXover(eoBinOp<double> & _crossObj, eoBinOp<double> & _crossMut) : 00058 crossObj(_crossObj), crossMut(_crossMut) {} 00059 00061 virtual std::string className() const { return "eoEsStandardXover"; } 00062 00067 bool operator()(EOT& _eo1, const EOT& _eo2) 00068 { 00069 bool bLoc=false; 00070 // first, the object variables 00071 for (unsigned i=0; i<_eo1.size(); i++) 00072 { 00073 bLoc |= crossObj(_eo1[i], _eo2[i]); // apply eoBinOp 00074 } 00075 // then the self-adaptation parameters 00076 bLoc |= cross_self_adapt(_eo1, _eo2); 00077 return bLoc; 00078 } 00079 00080 private: 00081 00082 // the method to cross slef-adaptation parameters: need to specialize 00083 00084 bool cross_self_adapt(eoEsSimple<FitT> & _parent1, const eoEsSimple<FitT> & _parent2) 00085 { 00086 return crossMut(_parent1.stdev, _parent2.stdev); // apply eoBinOp 00087 } 00088 00089 bool cross_self_adapt(eoEsStdev<FitT> & _parent1, const eoEsStdev<FitT> & _parent2) 00090 { 00091 bool bLoc=false; 00092 for (unsigned i=0; i<_parent1.size(); i++) 00093 { 00094 bLoc |= crossMut(_parent1.stdevs[i], _parent2.stdevs[i]); // apply eoBinOp 00095 } 00096 return bLoc; 00097 } 00098 00099 bool cross_self_adapt(eoEsFull<FitT> & _parent1, const eoEsFull<FitT> & _parent2) 00100 { 00101 bool bLoc=false; 00102 unsigned i; 00103 // the StDev 00104 for (i=0; i<_parent1.size(); i++) 00105 { 00106 bLoc |= crossMut(_parent1.stdevs[i], _parent2.stdevs[i]); // apply eoBinOp 00107 } 00108 // the roataion angles 00109 for (i=0; i<_parent1.correlations.size(); i++) 00110 { 00111 bLoc |= crossMut(_parent1.correlations[i], _parent2.correlations[i]); // apply eoBinOp 00112 } 00113 return bLoc; 00114 00115 } 00116 00117 // the data 00118 eoRandomSelect<EOT> sel; 00119 eoBinOp<double> & crossObj; 00120 eoBinOp<double> & crossMut; 00121 }; 00122 00123 #endif