00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- 00002 00003 //----------------------------------------------------------------------------- 00004 // eoShiftMutation.h 00005 // (c) GeNeura Team, 2000 - EEAAX 2000 - Maarten Keijzer 2000 00006 // (c) INRIA Futurs - Dolphin Team - Thomas Legrand 2007 00007 /* 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Lesser General Public 00010 License as published by the Free Software Foundation; either 00011 version 2 of the License, or (at your option) any later version. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Lesser General Public License for more details. 00017 00018 You should have received a copy of the GNU Lesser General Public 00019 License along with this library; if not, write to the Free Software 00020 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 00022 Contact: todos@geneura.ugr.es, http://geneura.ugr.es 00023 thomas.legrand@lifl.fr 00024 Marc.Schoenauer@polytechnique.fr 00025 mak@dhi.dk 00026 */ 00027 //----------------------------------------------------------------------------- 00028 00029 #ifndef eoShiftMutation_h 00030 #define eoShiftMutation_h 00031 00032 //----------------------------------------------------------------------------- 00033 00034 00038 template<class EOT> class eoShiftMutation: public eoMonOp<EOT> 00039 { 00040 public: 00041 00042 typedef typename EOT::AtomType GeneType; 00043 00045 eoShiftMutation(){} 00046 00047 00049 virtual std::string className() const { return "eoShiftMutation"; } 00050 00051 00056 bool operator()(EOT& _eo) 00057 { 00058 00059 unsigned i, j, from, to; 00060 GeneType tmp; 00061 00062 // generate two different indices 00063 i=eo::rng.random(_eo.size()); 00064 do j = eo::rng.random(_eo.size()); while (i == j); 00065 00066 // indexes 00067 from=std::min(i,j); 00068 to=std::max(i,j); 00069 00070 // keep the first component to change 00071 tmp=_eo[to]; 00072 00073 // shift 00074 for(unsigned int k=to ; k > from ; k--) 00075 _eo[k]=_eo[k-1]; 00076 00077 // shift the first component 00078 _eo[from]=tmp; 00079 00080 return true; 00081 } 00082 00083 }; 00084 00085 00086 //----------------------------------------------------------------------------- 00087 #endif 00088