EvolvingObjects
|
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 00038 template<class EOT> class eoTwoOptMutation: public eoMonOp<EOT> 00039 { 00040 public: 00041 00042 typedef typename EOT::AtomType GeneType; 00043 00045 eoTwoOptMutation(){} 00046 00048 virtual std::string className() const { return "eoTwoOptMutation"; } 00049 00054 bool operator()(EOT& _eo) { 00055 // generate two different indices 00056 unsigned i(eo::rng.random(_eo.size())); 00057 unsigned j; 00058 do { 00059 j = eo::rng.random(_eo.size()); 00060 } while(i == j); 00061 unsigned from(std::min(i,j)); 00062 unsigned to(std::max(i,j)); 00063 unsigned idx((to - from)/2); 00064 00065 // inverse between from and to 00066 for(unsigned k = 0; k <= idx; ++k) 00067 std::swap(_eo[from+k],_eo[to-k]); 00068 return true; 00069 } 00070 00071 }; 00076 //----------------------------------------------------------------------------- 00077 #endif 00078 00079 00080 // Local Variables: 00081 // coding: iso-8859-1 00082 // mode: C++ 00083 // c-file-offsets: ((c . 0)) 00084 // c-file-style: "Stroustrup" 00085 // fill-column: 80 00086 // End: