Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages | Search for

# VirusOp.h

    00001 /*
    00002    ViruOp.h
    00003    (c) GeNeura Team 2001, Marc Schoenauer 2000
    00004
    00005     This library is free software; you can redistribute it and/or
    00006     modify it under the terms of the GNU Lesser General Public
    00007     License as published by the Free Software Foundation; either
    00008     version 2 of the License, or (at your option) any later version.
    00009
    00010     This library is distributed in the hope that it will be useful,
    00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013     Lesser General Public License for more details.
    00014
    00015     You should have received a copy of the GNU Lesser General Public
    00016     License along with this library; if not, write to the Free Software
    00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00018
    00019     Contact: todos@geneura.ugr.es, http://geneura.ugr.es
    00020              Marc.Schoenauer@polytechnique.fr
    00021 CVS Info: $Date: 2003/02/27 19:26:43 $ $Header: /cvsroot/eodev/eo/contrib/MGE/VirusOp.h,v 1.3 2003/02/27 19:26:43 okoenig Exp $ $Author: okoenig $
    00022 */
    00023
    00024 #ifndef VirusOp_h
    00025 #define VirusOp_h
    00026
    00027 //-----------------------------------------------------------------------------
    00028
    00029 #include <iostream>    // ostream, istream
    00030 #include <functional>  // bind2nd
    00031 #include <string>      // std::string
    00032
    00033 #include <utils/eoRNG.h>
    00034 #include "../contrib/MGE/eoVirus.h"
    00035
    00039 template<class FitT>
    00040 class VirusBitFlip: public eoMonOp<eoVirus<FitT> > {
    00041  public:
    00043   virtual std::string className() const { return "VirusBitFlip"; };
    00044
    00049   bool operator()(eoVirus<FitT>& _chrom) {
    00050       unsigned i = eo::rng.random(_chrom.size());
    00051       _chrom.virusBitSet(i, _chrom.virusBit(i) ? false : true );
    00052       return true;
    00053   }
    00054 };
    00055
    00056 template<class FitT>
    00057 class VirusMutation: public eoMonOp<eoVirus<FitT> > {
    00058  public:
    00060   virtual std::string className() const { return "VirusMutation"; };
    00061
    00066   bool operator()(eoVirus<FitT>& _chrom) {
    00067         // Search for virus bits
    00068         std::vector<unsigned> bitsSet;
    00069         for ( unsigned i = 0; i < _chrom.size(); i ++ ) {
    00070           if ( _chrom.virusBit(i) ) {
    00071                 bitsSet.push_back( i );
    00072           }
    00073         }
    00074         if ( !bitsSet.size() ) {
    00075           return false;
    00076         }
    00077     unsigned flipSite = eo::rng.random(bitsSet.size());
    00078         unsigned flipValue = bitsSet[ flipSite ];
    00079         _chrom[flipValue] = _chrom[flipValue] ? false : true;
    00080         return true;
    00081   }
    00082 };
    00083
    00085 template<class FitT>
    00086 class VirusShiftMutation: public eoMonOp<eoVirus<FitT> > {
    00087  public:
    00088
    00090   VirusShiftMutation( ) {};
    00091
    00093   virtual std::string className() const { return "VirusShiftMutation"; };
    00094
    00099   bool operator()(eoVirus<FitT>& _chrom) {
    00100         // Search for virus bits
    00101         eoBooleanGenerator gen;
    00102         for ( unsigned i = 0; i < _chrom.size(); i ++ ) {
    00103           if ( _chrom.virusBit(i) ) {
    00104                 if ( gen() ) {
    00105                   if ( i + 1 < _chrom.size() ) {
    00106                         _chrom.virusBitSet(i+1,true);
    00107                         _chrom.virusBitSet(i, false);
    00108                   }
    00109                 } else {
    00110                   if ( i - 1 > 0 ) {
    00111                         _chrom.virusBitSet(i-1,true);
    00112                         _chrom.virusBitSet(i, false);
    00113                   }
    00114                 }
    00115           }
    00116         }
    00117         return true;
    00118   }
    00119
    00120  private:
    00121 };
    00122
    00123
    00124 template<class FitT>
    00125 class VirusTransmission: public eoBinOp<eoVirus<FitT> > {
    00126  public:
    00128   virtual std::string className() const { return "VirusTransmission"; };
    00129
    00135   bool operator()(eoVirus<FitT>& _chrom,const eoVirus<FitT>& _chrom2) {
    00136         // Search for virus bits
    00137         for ( unsigned i = 0; i < _chrom.size(); i ++ ) {
    00138           _chrom.virusBitSet(i, _chrom2.virusBit(i) );
    00139         }
    00140         return true;
    00141   }
    00142 };
    00143
    00144 #endif //VirusOp_h