EvolvingObjects
eoCombinedInit.h
00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 //-----------------------------------------------------------------------------
00004 // eoCombinedInit.h
00005 // (c) Maarten Keijzer, GeNeura Team, Marc Schoenauer 2004
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: Marc.Schoenauer@inria.fr
00022  */
00023 //-----------------------------------------------------------------------------
00024 
00025 #ifndef _eoCombinedInit_h
00026 #define _eoCombinedInit_h
00027 
00028 #include <eoInit.h>
00029 
00035 template< class EOT>
00036 class eoCombinedInit: public eoInit<EOT> {
00037 public:
00038 
00040   eoCombinedInit( eoInit<EOT>& _init, double _rate)
00041     : eoInit<EOT> ()
00042   {
00043     initializers.push_back(&_init);
00044     rates.push_back(_rate);
00045   }
00046 
00047   /* FIXME remove in next release
00048   void add(eoInit<EOT> & _init, double _rate, bool _verbose)
00049   {
00050       eo::log << eo::warnings << "WARNING: the use of the verbose parameter in eoCombinedInit::add is deprecated and will be removed in the next release." << std::endl;
00051       add( _init, _rate );
00052   }
00053   */
00054 
00057   void add(eoInit<EOT> & _init, double _rate)
00058   {
00059     initializers.push_back(&_init);
00060     rates.push_back(_rate);
00061     // compute the relative rates in percent - to warn the user!
00062       printOn( eo::log << eo::logging );
00063   }
00064 
00066   virtual void printOn(std::ostream & _os)
00067   {
00068     double total = 0;
00069     unsigned i;
00070     for (i=0; i<initializers.size(); i++)
00071       total += rates[i];
00072     _os << "In " << className() << "\n" ;
00073     for (i=0; i<initializers.size(); i++)
00074       _os << initializers[i]->className() << " with rate " << 100*rates[i]/total << " %\n";
00075   }
00076 
00080   virtual void operator() ( EOT & _eo )
00081   {
00082     unsigned what = rng.roulette_wheel(rates); // choose one op
00083     (*initializers[what])(_eo);            // apply it
00084     return;
00085   }
00086 
00087   virtual std::string className(void) const { return "eoCombinedInit"; }
00088 
00089 private:
00090 std::vector<eoInit<EOT>*> initializers;
00091 std::vector<double> rates;
00092 };
00093 
00094 #endif
 All Classes Namespaces Files Functions Variables Typedefs Friends