00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef EOVELOCITY_H
00012 #define EOVELOCITY_H
00013
00014
00015 #include <eoFunctor.h>
00016 #include <utils/eoRNG.h>
00017 #include <eoPop.h>
00018 #include <utils/eoRealVectorBounds.h>
00019 #include <eoParticleArchive.h>
00020
00021
00025 template < class POT > class eoVelocity:public eoUF < POT &, void >
00026 {
00027 public:
00028
00032 virtual void apply (eoPop < POT > &_pop)
00033 {
00034 for (unsigned i = 0; i < _pop.size (); i++)
00035 {
00036 operator ()(_pop[i]);
00037 }
00038
00039 }
00040 };
00041
00047 template < class POT > class eoStandardVelocity:public eoVelocity < POT >
00048 {
00049
00050 public:
00051
00060 eoStandardVelocity (eoSingleParticleArchive < POT > &_archive, eoRealVectorBounds & _bounds, const double _c1 = 0.5, const double _c2 = 0.9, eoRng & _gen = rng):c1 (_c1), c2 (_c2),bounds(_bounds), archive (_archive),gen(_gen){}
00061
00069 eoStandardVelocity (eoSingleParticleArchive < POT > &_archive, const double _c1 = 0.5, const double _c2 = 0.9, eoRng & _gen = rng):c1 (_c1), c2 (_c2),bounds(eoDummyVectorNoBounds), archive (_archive),gen(_gen){}
00070
00071 void operator () (POT & _po)
00072 {
00073 double delta1;
00074 double delta2;
00075 double newVelocity;
00076
00077 delta1 = rng.uniform (1) * c1;
00078 delta2 = rng.uniform (1) * c2;
00079
00080
00081 for (unsigned j = 0; j < _po.size (); j++)
00082 {
00083 newVelocity = _po.velocities[j] + delta1 * (_po.bestPositions[j] - _po[j]) + delta2 * (archive.best ()[j] - _po[j]);
00084
00085
00086 if (bounds.isMinBounded(j))
00087 newVelocity=std::max(newVelocity,bounds.minimum(j));
00088 if (bounds.isMaxBounded(j))
00089 newVelocity=std::min(newVelocity,bounds.maximum(j));
00090
00091 _po.velocities[j]=newVelocity;
00092 }
00093 }
00094
00095
00096 protected:
00097 const double c1;
00098 const double c2;
00099 eoRealVectorBounds & bounds;
00100 eoRng & gen;
00101 eoParticleArchive < POT > &archive;
00102 };
00103
00104
00105
00111 template < class POT > class eoInertiaFixedWeightedVelocity:public eoVelocity < POT >
00112 {
00113
00114 public:
00115
00125 eoInertiaFixedWeightedVelocity (eoSingleParticleArchive < POT > &_archive,eoRealVectorBounds & _bounds, const double _weight=1,const double _c1 = 0.5, const double _c2 = 0.9, eoRng & _gen = rng):c1 (_c1), c2 (_c2),bounds(_bounds),weight(_weight), archive (_archive), gen(_gen){}
00126
00127
00136 eoInertiaFixedWeightedVelocity (eoSingleParticleArchive < POT > &_archive, const double _weight=1,const double _c1 = 0.5, const double _c2 = 0.9, eoRng & _gen = rng):c1 (_c1), c2 (_c2),weight(_weight),bounds(eoDummyVectorNoBounds),archive (_archive), gen(_gen){}
00137
00138
00139 void operator () (POT & _po)
00140 {
00141 double delta1;
00142 double delta2;
00143 double newVelocity;
00144
00145 delta1 = rng.uniform (1) * c1;
00146 delta2 = rng.uniform (1) * c2;
00147
00148 for (unsigned j = 0; j < _po.size (); j++)
00149 {
00150 newVelocity = weight*_po.velocities[j] + delta1 * (_po.bestPositions[j] - _po[j]) + delta2 * (archive.best ()[j] - _po[j]);
00151
00152
00153 if (bounds.isMinBounded(j))
00154 newVelocity=std::max(newVelocity,bounds.minimum(j));
00155 if (bounds.isMaxBounded(j))
00156 newVelocity=std::min(newVelocity,bounds.maximum(j));
00157
00158 _po.velocities[j]=newVelocity;
00159 }
00160 }
00161
00162
00163 protected:
00164 const double c1;
00165 const double c2;
00166 const double weight;
00167 eoRealVectorBounds & bounds;
00168 eoParticleArchive < POT > &archive;
00169 eoRng & gen;
00170
00171 };
00172
00173
00174
00180 template < class POT > class eoVariableInertiaWeightedVelocity:public eoVelocity < POT >
00181 {
00182
00183 public:
00184
00195 eoVariableInertiaWeightedVelocity (eoSingleParticleArchive < POT > &_archive,eoRealVectorBounds & _bounds,eoValueParam<unsigned> & _genCounter,const unsigned _maxGen,const double _c1 = 0.5, const double _c2 = 0.9, eoRng & _gen = rng):c1 (_c1), c2 (_c2),bounds(_bounds),genCounter(_genCounter), maxGen(_maxGen),archive (_archive), gen(_gen){}
00196
00197
00207 eoVariableInertiaWeightedVelocity (const double _c1,const double _c2,eoValueParam<unsigned> & _genCounter,const unsigned _maxGen, eoSingleParticleArchive < POT > &_archive, eoRng & _gen = rng):c1 (_c1), c2 (_c2),genCounter(_genCounter), maxGen(_maxGen),archive (_archive), gen(_gen),bounds(eoDummyVectorNoBounds){}
00208
00209 void operator () (POT & _po)
00210 {
00211 double delta1;
00212 double delta2;
00213 double weight;
00214 double newVelocity;
00215
00216 delta1 = rng.uniform (1) * c1;
00217 delta2 = rng.uniform (1) * c2;
00218
00219 weight=(maxGen-genCounter.value())/maxGen;
00220
00221 for (unsigned j = 0; j < _po.size (); j++)
00222 {
00223 newVelocity = weight*_po.velocities[j] + delta1 * (_po.bestPositions[j] - _po[j]) + delta2 * (archive.best ()[j] - _po[j]);
00224
00225
00226 if (bounds.isMinBounded(j))
00227 newVelocity=std::max(newVelocity,bounds.minimum(j));
00228 if (bounds.isMaxBounded(j))
00229 newVelocity=std::min(newVelocity,bounds.maximum(j));
00230
00231 _po.velocities[j]=newVelocity;
00232 }
00233 }
00234
00235
00236 protected:
00237 const double c1;
00238 const double c2;
00239 eoValueParam<unsigned> & genCounter ;
00240 const unsigned maxGen ;
00241 eoParticleArchive < POT > &archive;
00242 eoRng & gen;
00243 eoRealVectorBounds & bounds;
00244 };
00245
00246
00252 template < class POT > class eoConstrictedVelocity:public eoVelocity < POT >
00253 {
00254
00255 public:
00256
00266 eoConstrictedVelocity (eoSingleParticleArchive < POT > &_archive,eoRealVectorBounds & _bounds, const double _K=1,const double _c1 = 0.5, const double _c2 = 0.9, eoRng & _gen = rng):c1 (_c1), c2 (_c2),K(_K), archive (_archive),
00267 gen
00268 (_gen)
00269 {
00270 }
00271
00280 eoConstrictedVelocity (eoSingleParticleArchive < POT > &_archive,eoRealVectorBounds & _bounds, const double _K=1,const double _c1 = 0.5, const double _c2 = 0.9, eoRng & _gen = rng):c1 (_c1), c2 (_c2),K(_K), archive (_archive),bounds(eoDummyVectorNoBounds),gen(_gen)
00281 {
00282 }
00283
00284
00285 void operator () (POT & _po)
00286 {
00287 double delta1;
00288 double delta2;
00289 double newVelocity;
00290
00291 delta1 = rng.uniform (1) * c1;
00292 delta2 = rng.uniform (1) * c2;
00293
00294 for (unsigned j = 0; j < _po.size (); j++)
00295 {
00296 newVelocity = K*(_po.velocities[j] + delta1 * (_po.bestPositions[j] - _po[j]) + delta2 * (archive.best ()[j] - _po[j]));
00297
00298
00299 if (bounds.isMinBounded(j))
00300 newVelocity=std::max(newVelocity,bounds.minimum(j));
00301 if (bounds.isMaxBounded(j))
00302 newVelocity=std::min(newVelocity,bounds.maximum(j));
00303
00304 _po.velocities[j]=newVelocity;
00305 }
00306 }
00307
00308
00309 protected:
00310
00311 const double c1;
00312 const double c2;
00313 const double K;
00314 eoRealVectorBounds & bounds;
00315 eoRng & gen;
00316 eoParticleArchive < POT > &archive;
00317 };
00318
00319 #endif
00320