EvolvingObjects
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 
00045  template<class EOT>
00046 class eoSGAGenOp : public eoGenOp<EOT>
00047 {
00048  public:
00049 
00054   eoSGAGenOp(eoQuadOp<EOT>& _cross, double _pCross,
00055                  eoMonOp<EOT>& _mut, double _pMut)
00056     : cross(_cross),
00057       pCross(_pCross),
00058       mut(_mut),
00059       pMut(_pMut)
00060   {
00061     // the crossover - with probability pCross
00062     propOp.add(cross, pCross); // crossover, with proba pcross
00063     propOp.add(quadClone, 1-pCross); // nothing, with proba 1-pcross
00064 
00065     // now the sequential
00066     op.add(propOp, 1.0);         // always do combined crossover
00067     op.add(mut, pMut);     // then mutation, with proba pmut
00068   }
00069 
00071   virtual void apply(eoPopulator<EOT>& _pop)
00072   {
00073     op.apply(_pop);
00074   }
00075 
00077   virtual unsigned max_production(void) {return 2;}
00078 
00079   virtual std::string className() const {return "eoSGAGenOp";}
00080 
00081 
00082  private:
00083   eoQuadOp<EOT> &cross;   // eoInvalidateXXX take the boolean output
00084   double pCross;
00085   eoMonOp<EOT> & mut;      // of the XXX op and invalidate the EOT
00086   double pMut;
00087   eoProportionalOp<EOT> propOp;
00088   eoQuadCloneOp<EOT> quadClone;
00089   eoSequentialOp<EOT> op;
00090 };
00091 
00092 
00093 #endif
 All Classes Namespaces Files Functions Variables Typedefs Friends