peoPSO.h

00001 /* <peoPSO.h>
00002 *
00003 *  (c) OPAC Team, October 2008
00004 *
00005 * Clive Canape
00006 *
00007 * This software is governed by the CeCILL license under French law and
00008 * abiding by the rules of distribution of free software.  You can  use,
00009 * modify and/ or redistribute the software under the terms of the CeCILL
00010 * license as circulated by CEA, CNRS and INRIA at the following URL
00011 * "http://www.cecill.info".
00012 *
00013 * As a counterpart to the access to the source code and  rights to copy,
00014 * modify and redistribute granted by the license, users are provided only
00015 * with a limited warranty  and the software's author,  the holder of the
00016 * economic rights,  and the successive licensors  have only  limited liability.
00017 *
00018 * In this respect, the user's attention is drawn to the risks associated
00019 * with loading,  using,  modifying and/or developing or reproducing the
00020 * software by the user in light of its specific status of free software,
00021 * that may mean  that it is complicated to manipulate,  and  that  also
00022 * therefore means  that it is reserved for developers  and  experienced
00023 * professionals having in-depth computer knowledge. Users are therefore
00024 * encouraged to load and test the software's suitability as regards their
00025 * requirements in conditions enabling the security of their systems and/or
00026 * data to be ensured and,  more generally, to use and operate it in the
00027 * same conditions as regards security.
00028 * The fact that you are presently reading this means that you have had
00029 * knowledge of the CeCILL license and that you accept its terms.
00030 *
00031 * ParadisEO WebSite : http://paradiseo.gforge.inria.fr
00032 * Contact: paradiseo-help@lists.gforge.inria.fr
00033 *   Contact: clive.canape@inria.fr
00034 */
00035 
00036 #ifndef peoPSO_h
00037 #define peoPSO_h
00038 
00039 #include <eoPop.h>
00040 #include <utils/eoRNG.h>
00041 #include <eoFunctor.h>
00042 #include <eoMerge.h>
00043 #include <eoReduce.h>
00044 #include <eoReplacement.h>
00045 #include <utils/eoHowMany.h>
00046 #include <eoSelectOne.h>
00047 
00048 
00054 template <class POT> class peoPSOSelect: public eoSelectOne<POT>
00055   {
00056   public:
00057 
00060     peoPSOSelect(eoTopology < POT > & _topology):topology(_topology)
00061     {}
00062 
00064     typedef typename PO < POT >::Fitness Fitness;
00065 
00069     virtual const POT& operator()(const eoPop<POT>& _pop)
00070     {
00071       return topology.globalBest(_pop);
00072     }
00073 
00074   private:
00076     eoTopology < POT > & topology;
00077   };
00078 
00084 template <class POT>
00085 class peoGlobalBestVelocity : public eoReplacement<POT>
00086   {
00087   public:
00088 
00090     typedef typename POT::ParticleVelocityType VelocityType;
00091 
00095     peoGlobalBestVelocity(      const double & _c3, eoVelocity < POT > &_velocity): c3 (_c3),velocity (_velocity)
00096     {}
00097 
00101     void operator()(eoPop<POT>& _dest, eoPop<POT>& _source)
00102     {
00103 
00104       VelocityType newVelocity,r3;
00105       r3 =  (VelocityType) rng.uniform (1) * c3;
00106       for (unsigned i=0;i<_dest.size();i++)
00107         for (unsigned j=0;j<_dest[i].size();j++)
00108           {
00109             newVelocity=  _dest[i].velocities[j] + r3 * (_source[0].bestPositions[j] - _dest[i][j]);
00110             _dest[i].velocities[j]=newVelocity;
00111           }
00112 
00113     }
00114 
00115   protected:
00118     const double & c3;
00119     eoVelocity < POT > & velocity;
00120   };
00121 
00127 template <class POT> class peoWorstPositionReplacement : public eoReplacement<POT>
00128   {
00129   public:
00131     peoWorstPositionReplacement()
00132     {}
00133 
00137     void operator()(eoPop<POT>& _dest, eoPop<POT>& _source)
00138     {
00139       unsigned ind=0;
00140       double best=_dest[0].best();
00141       for (unsigned j=1;j<_dest.size();j++)
00142         if (_dest[j].best() < best)
00143           {
00144             ind=j;
00145             best=_dest[j].best();
00146           }
00147       if (_dest[ind].best() < _source[0].best())
00148         {
00149           _dest[ind].best(_source[0].best());
00150           for (unsigned j=0;j<_dest[ind].size();j++)
00151             _dest[ind].bestPositions[j]=_source[0].bestPositions[j];
00152         }
00153     }
00154   };
00155 
00156 #endif

Generated on Thu Mar 13 15:55:03 2008 for ParadisEO-PEO-ParallelanddistributedEvolvingObjects by  doxygen 1.4.7