eoSGAGenOp.h

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 //-----------------------------------------------------------------------------
00004 // eoSGAGenOp.h
00005 // (c) Marc.Schoenauer 2002
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@inria.fr
00023              mak@dhi.dk
00024  */
00025 //-----------------------------------------------------------------------------
00026 
00027 #ifndef _eoSGAGenOp_h
00028 #define _eoSGAGenOp_h
00029 
00030 #include "eoGenOp.h"
00031 #include "eoInvalidateOps.h"
00033 // class eoSGAGenOp
00035 
00043 template<class EOT> 
00044 class eoSGAGenOp : public eoGenOp<EOT>
00045 {
00046  public:
00047     
00052   eoSGAGenOp(eoQuadOp<EOT>& _cross, double _pCross, 
00053                  eoMonOp<EOT>& _mut, double _pMut)
00054     : cross(_cross),
00055       pCross(_pCross),
00056       mut(_mut), 
00057       pMut(_pMut) 
00058   {
00059     // the crossover - with probability pCross
00060     propOp.add(cross, pCross); // crossover, with proba pcross
00061     propOp.add(quadClone, 1-pCross); // nothing, with proba 1-pcross
00062     
00063     // now the sequential
00064     op.add(propOp, 1.0);         // always do combined crossover
00065     op.add(mut, pMut);     // then mutation, with proba pmut
00066   }
00067   
00069   virtual void apply(eoPopulator<EOT>& _pop)
00070   {
00071     op.apply(_pop);
00072   }
00073 
00075   virtual unsigned max_production(void) {return 2;}
00076 
00077   virtual std::string className() const {return "eoSGAGenOp";}
00078 
00079 
00080  private:
00081   eoQuadOp<EOT> &cross;   // eoInvalidateXXX take the boolean output
00082   double pCross;
00083   eoMonOp<EOT> & mut;      // of the XXX op and invalidate the EOT
00084   double pMut;
00085   eoProportionalOp<EOT> propOp;
00086   eoQuadCloneOp<EOT> quadClone;
00087   eoSequentialOp<EOT> op;
00088 };
00089 
00090 
00091 #endif

Generated on Thu Apr 19 11:02:28 2007 for EO by  doxygen 1.4.7