EvolvingObjects
eoParticleFullInitializer.h
00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 //-----------------------------------------------------------------------------
00004 // eoParticleFullInitializer.h
00005 // (c) OPAC Team, INRIA, 2007
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: clive.canape@inria.fr
00022 
00023 
00024  */
00025 //-----------------------------------------------------------------------------
00026 
00027 #ifndef _eoParticleFullInitializer_H
00028 #define _eoParticleFullInitializer_H
00029 
00030 #include <utils/eoRealVectorBounds.h>
00031 #include <eoVelocityInit.h>
00032 #include <eoPop.h>
00033 #include <eoParticleBestInit.h>
00034 #include <eoTopology.h>
00035 
00042 /*
00043  * Abstract class for initialization of algorithm PSO
00044  */
00045 template <class POT> class eoInitializerBase : public eoFunctorBase
00046   {
00047   public :
00048 
00049     virtual ~eoInitializerBase()
00050     {}
00051 
00052     virtual void operator()()
00053     {};
00054   };
00055 
00061 template <class POT> class eoParticleInitializer : public eoInitializerBase <POT>
00062   {
00063   public:
00064 
00071     eoParticleFullInitializer(
00072       eoUF<POT&, void>& _proc,
00073       eoVelocityInit < POT > &_initVelo,
00074       eoParticleBestInit <POT> &_initBest,
00075       eoTopology <POT> &_topology,
00076       eoPop < POT > &_pop
00077     ) : proc(_proc), procPara(dummyEval), initVelo(_initVelo), initBest(_initBest), topology(_topology), pop(_pop) {}
00078 
00079 
00086     eoParticleFullInitializer(
00087       eoPopEvalFunc <POT>& _proc,
00088       eoVelocityInit < POT > &_initVelo,
00089       eoParticleBestInit <POT> &_initBest,
00090       eoTopology <POT> &_topology,
00091       eoPop < POT > &_pop
00092     ) : proc(dummy), procPara(_proc), initVelo(_initVelo), initBest(_initBest), topology(_topology), pop(_pop)
00093     {}
00094 
00095 
00098     virtual std::string className (void) const
00099       {
00100         return "eoInitializer";
00101       }
00102 
00103 
00104 
00105     virtual void operator  () ()
00106     {
00107                 eoPop<POT> empty_pop;
00108 
00109                 // evaluates using either the "sequential" evaluator ...
00110                 apply(proc, pop);
00111 
00112                 // ... or the parallel one
00113         procPara(empty_pop, pop);
00114 
00115         // no matter what is the eval operator, initializes the velocities and the particle's best
00116         apply < POT > (initVelo, pop);
00117         apply < POT > (initBest, pop);
00118 
00119         // finally setup the topology. We have now all we need to do so.
00120         topology.setup(pop);
00121     }
00122 
00123   private :
00124 
00125     /*
00126         @param proc First evaluation
00127         @param initVelo Initialization of the velocity
00128         @param initBest Initialization of the best
00129 
00130     */
00131     eoPop < POT > & pop;
00132     eoUF<POT&, void>& proc;
00133     eoPopEvalFunc <POT>& procPara;
00134     eoVelocityInit < POT > & initVelo;
00135     eoParticleBestInit <POT> & initBest;
00136     eoTopology <POT> & topology;
00137     class eoDummyEval : public eoPopEvalFunc<POT>
00138     {
00139       public:
00140         void operator()(eoPop<POT> &,eoPop<POT> &_pop)
00141         {}
00142     }
00143     dummyEval;
00144     class eoDummy : public eoUF<POT&, void>
00145     {
00146       public:
00147         void operator()(POT &)
00148         {}
00149 
00150     }
00151     dummy;
00152   };
00153 #endif /*_eoParticleFullInitializer_H*/
00154 
 All Classes Namespaces Files Functions Variables Typedefs Friends