00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef _EOLSPSO_H
00012 #define _EOLSPSO_H
00013
00014
00015 #include <eoPSO.h>
00016 #include <eoContinue.h>
00017 #include <eoStandardFlight.h>
00018 #include <eoLinearTopology.h>
00019 #include <eoStandardVelocity.h>
00020 #include <utils/eoRealVectorBounds.h>
00021 #include <eoRealBoundModifier.h>
00022
00023
00030 template < class POT > class eoLSPSO:public eoPSO < POT >
00031 {
00032 public:
00033
00034
00035 typedef typename POT::ParticleVelocityType VelocityType;
00036
00047 eoLSPSO (
00048 eoContinue < POT > &_continuator,
00049 eoEvalFunc < POT > &_eval,
00050 const VelocityType & _c1,
00051 const VelocityType & _c2 ,
00052 const unsigned _neighborhoodSize,
00053 eoRealVectorBounds & _bounds,
00054 eoRealBoundModifier & _bndsModifier):
00055 continuator (_continuator),
00056 eval (_eval),
00057 topology(eoLinearTopology<POT>(_neighborhoodSize)),
00058 velocity(eoStandardVelocity<POT>(topology,_c1,_c2,_bounds,_bndsModifier)),
00059 neighborhoodSize(_neighborhoodSize),
00060 bounds(_bounds),
00061 boundsModifier(_bndsModifier)
00062 {}
00063
00073 eoLSPSO (
00074 eoContinue < POT > &_continuator,
00075 eoEvalFunc < POT > &_eval,
00076 const VelocityType & _c1,
00077 const VelocityType & _c2 ,
00078 const unsigned _neighborhoodSize,
00079 eoRealVectorBounds & _bounds):
00080 continuator (_continuator),
00081 eval (_eval),
00082 topology(eoLinearTopology<POT>(_neighborhoodSize)),
00083 velocity(eoStandardVelocity<POT>(topology,_c1,_c2,_bounds)),
00084 neighborhoodSize(_neighborhoodSize),
00085 bounds(_bounds),
00086 boundsModifier(dummyModifier)
00087 {}
00088
00089
00098 eoLSPSO (
00099 eoContinue < POT > &_continuator,
00100 eoEvalFunc < POT > &_eval,
00101 const VelocityType & _c1,
00102 const VelocityType & _c2,
00103 const unsigned _neighborhoodSize):
00104 continuator (_continuator),
00105 eval (_eval),
00106 topology(eoLinearTopology<POT>(_neighborhoodSize)),
00107 velocity(eoStandardVelocity<POT>(topology,_c1,_c2)),
00108 neighborhoodSize(_neighborhoodSize),
00109 bounds(*(new eoRealVectorNoBounds(0))),
00110 boundsModifier(dummyModifier)
00111 {}
00112
00113
00115 virtual void operator () (eoPop < POT > &_pop)
00116 {
00117 try
00118 {
00119
00120 topology.setup(_pop);
00121
00122 do
00123 {
00124
00125 for (unsigned idx = 0; idx < _pop.size (); idx++)
00126 {
00127
00128 velocity (_pop[idx],idx);
00129
00130
00131 flight (_pop[idx]);
00132
00133
00134 eval (_pop[idx]);
00135
00136
00137 velocity.updateNeighborhood(_pop[idx],idx);
00138 }
00139
00140 } while (continuator (_pop));
00141
00142 }catch (std::exception & e)
00143 {
00144 std::string s = e.what ();
00145 s.append (" in eoLSPSO");
00146 throw std::runtime_error (s);
00147 }
00148
00149 }
00150
00151 protected:
00152 eoContinue < POT > &continuator;
00153 eoEvalFunc < POT > &eval;
00154
00155 eoStandardVelocity < POT > velocity;
00156 eoStandardFlight < POT > flight;
00157
00158 const unsigned neighborhoodSize;
00159 eoLinearTopology<POT> topology;
00160
00161 eoRealVectorBounds bounds;
00162 eoRealBoundModifier & boundsModifier;
00163
00164
00165 eoDummyRealBoundModifier dummyModifier;
00166
00167 };
00168
00169
00170 #endif