eoSSPSO.h

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 //-----------------------------------------------------------------------------
00004 // eoSSPSO.h
00005 // (c) OPAC 2007
00006 /*
00007     Contact: paradiseo-help@lists.gforge.inria.fr
00008  */
00009 //-----------------------------------------------------------------------------
00010 
00011 #ifndef _EOSSPSO_H
00012 #define _EOSSPSO_H
00013 
00014 //-----------------------------------------------------------------------------
00015 #include <eoPSO.h>
00016 #include <eoContinue.h>
00017 #include <eoStandardFlight.h>
00018 #include <eoStarTopology.h>
00019 #include <eoStandardVelocity.h>
00020 #include <utils/eoRealVectorBounds.h>
00021 #include <eoRealBoundModifier.h>
00022 //-----------------------------------------------------------------------------
00023 
00030 template < class POT > class eoSSPSO:public eoPSO < POT >
00031 {
00032 public:
00033 
00034 
00035     typedef typename POT::ParticleVelocityType VelocityType;
00036 
00046     eoSSPSO (
00047         eoContinue < POT > &_continuator,
00048         eoEvalFunc < POT > &_eval,
00049         const VelocityType & _c1,
00050         const VelocityType & _c2 ,
00051         eoRealVectorBounds & _bounds,
00052         eoRealBoundModifier & _bndsModifier):
00053             continuator (_continuator),
00054             eval (_eval),
00055             velocity(eoStandardVelocity<POT>(topology,_c1,_c2,_bounds,_bndsModifier)),
00056             bounds(_bounds),
00057             boundsModifier(_bndsModifier)
00058     {}
00059 
00068     eoSSPSO (
00069         eoContinue < POT > &_continuator,
00070         eoEvalFunc < POT > &_eval,
00071         const VelocityType & _c1,
00072         const VelocityType & _c2 ,
00073         eoRealVectorBounds & _bounds):
00074             continuator (_continuator),
00075             eval (_eval),
00076             velocity(eoStandardVelocity<POT>(topology,_c1,_c2,_bounds)),
00077             bounds(_bounds),
00078             boundsModifier(dummyModifier)
00079     {}
00080 
00081 
00089     eoSSPSO (
00090         eoContinue < POT > &_continuator,
00091         eoEvalFunc < POT > &_eval,
00092         const VelocityType & _c1,
00093         const VelocityType & _c2):
00094             continuator (_continuator),
00095             eval (_eval),
00096             velocity(eoStandardVelocity<POT>(topology,_c1,_c2)),
00097             bounds(*(new eoRealVectorNoBounds(0))),
00098             boundsModifier(dummyModifier)
00099     {}
00100 
00101 
00103     virtual void operator  () (eoPop < POT > &_pop)
00104     {
00105         try
00106         {
00107             // setup the topology (done once)
00108             topology.setup(_pop);
00109 
00110             do
00111             {
00112                 // loop over all the particles for the current iteration
00113                 for (unsigned idx = 0; idx < _pop.size (); idx++)
00114                 {
00115                     // perform velocity evaluation
00116                     velocity (_pop[idx],idx);
00117 
00118                     // apply the flight
00119                     flight (_pop[idx]);
00120 
00121                     // evaluate the position
00122                     eval (_pop[idx]);
00123 
00124                     // update the topology (particle and the global bests)
00125                     velocity.updateNeighborhood(_pop[idx],idx);
00126                 }
00127             } while (continuator (_pop));
00128 
00129         }catch (std::exception & e)
00130         {
00131             std::string s = e.what ();
00132             s.append (" in eoSSPSO");
00133             throw std::runtime_error (s);
00134         }
00135     }
00136 
00137 protected:
00138     eoContinue < POT > &continuator;
00139     eoEvalFunc < POT > &eval;
00140 
00141     eoStandardVelocity < POT > velocity;
00142     eoStandardFlight < POT > flight;
00143     eoStarTopology<POT> topology;
00144 
00145     eoRealVectorBounds bounds; // REAL bounds even if the velocity could be of another type.
00146     eoRealBoundModifier & boundsModifier;
00147 
00148     // If the bound modifier doesn't need to be used, use the dummy instance
00149     eoDummyRealBoundModifier dummyModifier;
00150 
00151 };
00152 
00153 
00154 #endif /*_EOSSPSO_H*/

Generated on Fri Jun 22 10:17:02 2007 for EO-PSO by  doxygen 1.4.7