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