Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages | Search for

# eoEsGlobalXover.h

    00001
    00023 //-----------------------------------------------------------------------------
    00024
    00025
    00026 #ifndef _eoEsGlobalXover_H
    00027 #define _eoEsGlobalXover_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
    00043 template<class EOT>
    00044 class eoEsGlobalXover: public eoGenOp<EOT>
    00045 {
    00046 public:
    00047   typedef typename EOT::Fitness FitT;
    00048
    00052   eoEsGlobalXover(eoBinOp<double> & _crossObj, eoBinOp<double> & _crossMut) :
    00053     crossObj(_crossObj), crossMut(_crossMut) {}
    00054
    00056   virtual std::string className() const { return "eoEsGlobalXover"; }
    00057
    00059   unsigned max_production(void) { return 1; }
    00060
    00067   void apply(eoPopulator<EOT>& _plop)
    00068   {
    00069     // First, select as many parents as you will have offspring
    00070     EOT& parent = *_plop; // select the first parent
    00071
    00072     // first, the object variables
    00073     for (unsigned i=0; i<parent.size(); i++)
    00074       {
    00075         // get extra parents - use private selector
    00076         // _plop.source() is the eoPop<EOT> used by _plop to get parents
    00077         const EOT& realParent1 = sel(_plop.source());
    00078         const EOT& realParent2 = sel(_plop.source());
    00079         parent[i] = realParent1[i];
    00080         crossObj(parent[i], realParent2[i]); // apply eoBinOp
    00081       }
    00082     // then the self-adaptation parameters
    00083     cross_self_adapt(parent, _plop.source());
    00084     // dont' forget to invalidate
    00085     parent.invalidate();
    00086   }
    00087
    00088 private:
    00089
    00094   void cross_self_adapt(eoEsSimple<FitT> & _parent, const eoPop<eoEsSimple<FitT> >& _pop)
    00095   {
    00096     const EOT& realParent1 = sel(_pop);
    00097     const EOT& realParent2 = sel(_pop);
    00098     _parent.stdev = realParent1.stdev;
    00099     crossMut(_parent.stdev, realParent2.stdev); // apply eoBinOp
    00100   }
    00101
    00106   void cross_self_adapt(eoEsStdev<FitT> & _parent, const eoPop<eoEsStdev<FitT> >& _pop)
    00107   {
    00108     for (unsigned i=0; i<_parent.size(); i++)
    00109       {
    00110         const EOT& realParent1 = sel(_pop);
    00111         const EOT& realParent2 = sel(_pop);
    00112         _parent.stdevs[i] = realParent1.stdevs[i];
    00113         crossMut(_parent.stdevs[i], realParent2.stdevs[i]); // apply eoBinOp
    00114       }
    00115   }
    00116
    00121   void cross_self_adapt(eoEsFull<FitT> & _parent, const eoPop<eoEsFull<FitT> >& _pop)
    00122   {
    00123     unsigned i;
    00124     // the StDev
    00125     for (i=0; i<_parent.size(); i++)
    00126       {
    00127         const EOT& realParent1 = sel(_pop);
    00128         const EOT& realParent2 = sel(_pop);
    00129         _parent.stdevs[i] = realParent1.stdevs[i];
    00130         crossMut(_parent.stdevs[i], realParent2.stdevs[i]); // apply eoBinOp
    00131       }
    00132     // the roataion angles
    00133     for (i=0; i<_parent.correlations.size(); i++)
    00134       {
    00135         const EOT& realParent1 = sel(_pop);
    00136         const EOT& realParent2 = sel(_pop);
    00137         _parent.correlations[i] = realParent1.correlations[i];
    00138         crossMut(_parent.correlations[i], realParent2.correlations[i]); // apply eoBinOp
    00139       }
    00140
    00141   }
    00142
    00143   // the data
    00144   eoRandomSelect<EOT> sel;
    00145   eoBinOp<double> & crossObj;
    00146   eoBinOp<double> & crossMut;
    00147 };
    00148
    00149 #endif