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 _eoVariableLengthMutation_h
00027 #define _eoVariableLengthMutation_h
00028
00029 #include <eoFunctor.h>
00030 #include <eoOp.h>
00031 #include <eoInit.h>
00032
00047 template <class EOT>
00048 class eoVlAddMutation : public eoMonOp<EOT>
00049 {
00050 public :
00051
00052 typedef typename EOT::AtomType AtomType;
00053
00059 eoVlAddMutation(unsigned _nMax, eoInit<AtomType> & _atomInit) :
00060 nMax(_nMax), atomInit(_atomInit) {}
00061
00063 bool operator()(EOT & _eo)
00064 {
00065 if (_eo.size() >= nMax)
00066 return false;
00067 AtomType atom;
00068 atomInit(atom);
00069 unsigned pos = rng.random(_eo.size()+1);
00070 _eo.insert(_eo.begin()+pos, atom);
00071 return true;
00072 }
00073
00075 virtual std::string className() const { return "eoVlAddMutation"; }
00076
00077 private:
00078 unsigned nMax;
00079 eoInit<AtomType> & atomInit;
00080 };
00081
00082
00084 template <class EOT>
00085 class eoGeneDelChooser : public eoUF<EOT &, unsigned int>
00086 {
00087 public:
00088 virtual std::string className() const =0;
00089
00090 };
00091
00093 template <class EOT>
00094 class eoUniformGeneChooser: public eoGeneDelChooser<EOT>
00095 {
00096 public:
00097 eoUniformGeneChooser(){}
00098 unsigned operator()(EOT & _eo)
00099 {
00100 return eo::rng.random(_eo.size());
00101 }
00102 virtual std::string className() const { return "eoUniformGeneChooser"; }
00103 };
00104
00109 template <class EOT>
00110 class eoVlDelMutation : public eoMonOp<EOT>
00111 {
00112 public :
00113
00114 typedef typename EOT::AtomType AtomType;
00115
00121 eoVlDelMutation(unsigned _nMin, eoGeneDelChooser<EOT> & _chooser) :
00122 nMin(_nMin), uChooser(), chooser(_chooser) {}
00123
00128 eoVlDelMutation(unsigned _nMin) :
00129 nMin(_nMin), uChooser(), chooser(uChooser) {}
00130
00134 bool operator()(EOT & _eo)
00135 {
00136 if (_eo.size() <= nMin)
00137 return false;
00138 unsigned pos = chooser(_eo);
00139 _eo.erase(_eo.begin()+pos);
00140 return true;
00141 }
00142
00143 virtual std::string className() const
00144 {
00145 std::ostringstream os;
00146 os << "eoVlDelMutation("<<chooser.className() << ")";
00147 return os.str();
00148 }
00149
00150 private:
00151 unsigned nMin;
00152 eoUniformGeneChooser<EOT> uChooser;
00153 eoGeneDelChooser<EOT> & chooser;
00154 };
00155
00156
00157
00158 #endif