# 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
    00034 template< class EOT>
    00035 class eoCombinedInit: public eoInit<EOT> {
    00036 public:
    00037
    00039   eoCombinedInit( eoInit<EOT>& _init, double _rate)
    00040     : eoInit<EOT> ()
    00041   {
    00042     initializers.push_back(&_init);
    00043     rates.push_back(_rate);
    00044   }
    00045
    00050   void add(eoInit<EOT> & _init, double _rate, bool _verbose=false)
    00051   {
    00052     initializers.push_back(&_init);
    00053     rates.push_back(_rate);
    00054     // compute the relative rates in percent - to warn the user!
    00055     if (_verbose)
    00056       printOn(std::cout);
    00057   }
    00058
    00060   virtual void printOn(std::ostream & _os)
    00061   {
    00062     double total = 0;
    00063     unsigned i;
    00064     for (i=0; i<initializers.size(); i++)
    00065       total += rates[i];
    00066     _os << "In " << className() << "\n" ;
    00067     for (i=0; i<initializers.size(); i++)
    00068       _os << initializers[i]->className() << " with rate " << 100*rates[i]/total << " %\n";
    00069   }
    00070
    00074   virtual void operator() ( EOT & _eo )
    00075   {
    00076     unsigned what = rng.roulette_wheel(rates); // choose one op
    00077     (*initializers[what])(_eo);            // apply it
    00078     return;
    00079   }
    00080
    00081   virtual std::string className(void) const { return "eoCombinedInit"; }
    00082
    00083 private:
    00084 std::vector<eoInit<EOT>*> initializers;
    00085 std::vector<double> rates;
    00086 };
    00087
    00088 #endif
    00089