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

# eoInitVirus.h

    00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003 //-----------------------------------------------------------------------------
    00004 // eoInit.h
    00005 // (c) Maarten Keijzer 2000, GeNeura Team, 2000
    00006 /*
    00007     This library is free software; you can redistribute it and/or
    00008     modify it under the terms of the GNU Lesser General Public
    00009     License as published by the Free Software Foundation; either
    00010     version 2 of the License, or (at your option) any later version.
    00011
    00012     This library is distributed in the hope that it will be useful,
    00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00015     Lesser General Public License for more details.
    00016
    00017     You should have received a copy of the GNU Lesser General Public
    00018     License along with this library; if not, write to the Free Software
    00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00020
    00021     Contact: todos@geneura.ugr.es, http://geneura.ugr.es
    00022              Marc.Schoenauer@polytechnique.fr
    00023              mak@dhi.dk
    00024  */
    00025 //-----------------------------------------------------------------------------
    00026
    00027 #ifndef _eoInitVirus_H
    00028 #define _eoInitVirus_H
    00029
    00030 #include <algorithm>
    00031
    00032 #include <eoOp.h>
    00033 #include <eoSTLFunctor.h>
    00034 #include <utils/eoRndGenerators.h>
    00035 #include <eoInit.h>
    00036
    00040 template <class FitT>
    00041 class eoInitVirus: public eoInit< eoVirus<FitT> > {
    00042 public:
    00043
    00044   eoInitVirus(unsigned _combien, eoRndGenerator<bool>& _generator )
    00045         : combien(_combien), generator(_generator) {}
    00046
    00047   virtual void operator()( eoVirus<FitT>& chrom)
    00048   {
    00049         chrom.resize(combien);
    00050         chrom.virResize(combien);
    00051         std::generate(chrom.begin(), chrom.end(), generator);
    00052         for ( unsigned i = 0; i < combien; i ++ ) {
    00053           chrom.virusBitSet(i, generator() );
    00054         }
    00055         chrom.invalidate();
    00056   }
    00057
    00058 private :
    00059   unsigned combien;
    00061   eoSTLF<bool> generator;
    00062 };
    00063
    00065 template <class FitT>
    00066 class eoInitVirus1bit: public eoInit< eoVirus<FitT> > {
    00067 public:
    00068
    00069   eoInitVirus1bit(unsigned _combien, eoRndGenerator<bool>& _generator )
    00070         : combien(_combien), generator(_generator) {}
    00071
    00072   virtual void operator()( eoVirus<FitT>& chrom)
    00073   {
    00074         chrom.resize(combien);
    00075         chrom.virResize(combien);
    00076         std::generate(chrom.begin(), chrom.end(), generator);
    00077         chrom.virusBitSet(0, true );
    00078         chrom.invalidate();
    00079   }
    00080
    00081 private :
    00082   unsigned combien;
    00084   eoSTLF<bool> generator;
    00085 };
    00086 #endif