eoGeneralBreeder.h

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 //-----------------------------------------------------------------------------
00004 // eoGeneralBreeder.h 
00005 // (c) Maarten Keijzer and Marc Schoenauer, 2001
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: mkeijzer@dhi.dk
00022              Marc.Schoenauer@polytechnique.fr
00023  */
00024 //-----------------------------------------------------------------------------
00025 
00026 #ifndef eoGeneralBreeder_h
00027 #define eoGeneralBreeder_h
00028 
00029 //-----------------------------------------------------------------------------
00030 
00031 /*****************************************************************************
00032  * eoGeneralBreeder: transforms a population using the generalOp construct.
00033  *****************************************************************************/
00034 
00035 #include <eoOp.h>
00036 #include <eoGenOp.h>
00037 #include <eoPopulator.h>
00038 #include <eoSelectOne.h>
00039 #include <eoBreed.h>
00040 #include <utils/eoHowMany.h>
00041 
00045 template<class EOT>
00046 class eoGeneralBreeder: public eoBreed<EOT>
00047 {
00048  public:
00056   eoGeneralBreeder(
00057           eoSelectOne<EOT>& _select,
00058           eoGenOp<EOT>& _op,
00059                 double  _rate=1.0,
00060           bool _interpret_as_rate = true) :
00061       select( _select ), op(_op),  howMany(_rate, _interpret_as_rate) {}
00062 
00069   eoGeneralBreeder(
00070           eoSelectOne<EOT>& _select,
00071           eoGenOp<EOT>& _op,
00072           eoHowMany _howMany ) :
00073       select( _select ), op(_op),  howMany(_howMany) {}
00074 
00080   void operator()(const eoPop<EOT>& _parents, eoPop<EOT>& _offspring)
00081     {
00082       unsigned target = howMany(_parents.size());
00083 
00084       _offspring.clear();
00085       eoSelectivePopulator<EOT> it(_parents, _offspring, select);
00086 
00087       while (_offspring.size() < target)
00088             {
00089               op(it);
00090               ++it;
00091             }
00092 
00093       _offspring.resize(target);   // you might have generated a few more
00094     }
00095 
00097   virtual std::string className() const { return "eoGeneralBreeder"; }
00098 
00099  private:
00100   eoSelectOne<EOT>& select;
00101   eoGenOp<EOT>& op;
00102   eoHowMany howMany;
00103 };
00104 
00105 #endif
00106 

Generated on Thu Oct 19 05:06:35 2006 for EO by  doxygen 1.3.9.1