EvolvingObjects
eoShiftMutation.h
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 
00040 template<class EOT> class eoShiftMutation: public eoMonOp<EOT>
00041 {
00042  public:
00043 
00044   typedef typename EOT::AtomType GeneType;
00045 
00047   eoShiftMutation(){}
00048 
00049 
00051   virtual std::string className() const { return "eoShiftMutation"; }
00052 
00053 
00058   bool operator()(EOT& _eo)
00059     {
00060 
00061       unsigned i, j, from, to;
00062       GeneType tmp;
00063 
00064       // generate two different indices
00065       i=eo::rng.random(_eo.size());
00066       do j = eo::rng.random(_eo.size()); while (i == j);
00067 
00068       // indexes
00069       from=std::min(i,j);
00070       to=std::max(i,j);
00071 
00072       // keep the first component to change
00073       tmp=_eo[to];
00074 
00075       // shift
00076       for(unsigned int k=to ; k > from ; k--)
00077                 _eo[k]=_eo[k-1];
00078 
00079       // shift the first component
00080       _eo[from]=tmp;
00081 
00082       return true;
00083     }
00084 
00085 };
00090 //-----------------------------------------------------------------------------
00091 #endif
 All Classes Namespaces Files Functions Variables Typedefs Friends