00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _eoFlOrMonOp_h
00027 #define _eoFlOrMonOp_h
00028
00029 #include <eoFunctor.h>
00030 #include <eoOp.h>
00031 #include <eoInit.h>
00032
00044 template <class EOT>
00045 class eoFlOrAllMutation : public eoMonOp<EOT>
00046 {
00047 public :
00048
00049 typedef typename EOT::AtomType AtomType;
00050
00052 eoFlOrAllMutation(eoMonOp<AtomType> & _atomMutation, double _rate=1.0) :
00053 atomMutation(_atomMutation), rate(_rate) {}
00054
00056 bool operator()(EOT & _eo)
00057 {
00058 bool modified=false;
00059 for (unsigned i=0; i<_eo.size(); i++)
00060 if (eo::rng.flip(rate))
00061 if (atomMutation(_eo[i]))
00062 modified = true;
00063
00064 return modified;
00065 }
00066
00068 virtual std::string className() const
00069 {
00070 return "eoFlOrAllMutation(" + atomMutation.className() + ")";
00071 }
00072
00073 private:
00074 eoMonOp<AtomType> & atomMutation;
00075 double rate;
00076 };
00077
00081 template <class EOT>
00082 class eoFlOrKMutation : public eoMonOp<EOT>
00083 {
00084 public :
00085
00086 typedef typename EOT::AtomType AtomType;
00087
00089 eoFlOrKMutation(eoMonOp<AtomType> & _atomMutation, unsigned _nb=1) :
00090 nb(_nb), atomMutation(_atomMutation) {}
00091
00092
00094 bool operator()(EOT & _eo)
00095 {
00096 bool modified=false;
00097 for (unsigned k=0; k<nb; k++)
00098 {
00099 unsigned i = rng.random(_eo.size());
00100 if (atomMutation(_eo[i]))
00101 modified = true;
00102 }
00103 return modified;
00104 }
00105
00107 virtual std::string className() const
00108 {
00109 return "eoFlOrKMutation(" + atomMutation.className() + ")";
00110 }
00111
00112 private:
00113 unsigned nb;
00114 eoMonOp<AtomType> & atomMutation;
00115 };
00116
00117
00118 #endif