00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef EOCONSTRICTEDVELOCITY_H
00012 #define EOCONSTRICTEDVELOCITY_H
00013
00014
00015 #include <eoFunctor.h>
00016 #include <utils/eoRNG.h>
00017 #include <eoPop.h>
00018 #include <utils/eoRealVectorBounds.h>
00019 #include <eoTopology.h>
00020
00021
00022
00029 template < class POT > class eoConstrictedVelocity:public eoVelocity < POT >
00030 {
00031
00032 public:
00033
00034
00035
00036
00037 typedef typename POT::ParticleVelocityType VelocityType;
00038
00049 eoConstrictedVelocity (eoTopology < POT > & _topology,
00050 const VelocityType & _coeff,
00051 const VelocityType & _c1,
00052 const VelocityType & _c2 ,
00053 eoRealVectorBounds & _bounds,
00054 eoRealBoundModifier & _bndsModifier,
00055 eoRng & _gen = rng):
00056 topology(_topology),
00057 coeff(_coeff),
00058 c1 (_c1),
00059 c2 (_c2),
00060 bounds(_bounds),
00061 bndsModifier(_bndsModifier),
00062 gen(_gen){}
00063
00064
00074 eoConstrictedVelocity (eoTopology < POT > & _topology,
00075 const VelocityType & _coeff,
00076 const VelocityType & _c1,
00077 const VelocityType & _c2,
00078 eoRealVectorBounds & _bounds,
00079 eoRng & _gen = rng):
00080 topology(_topology),
00081 coeff(_coeff),
00082 c1 (_c1),
00083 c2 (_c2),
00084 bounds(_bounds),
00085 bndsModifier(dummyModifier),
00086 gen(_gen){}
00087
00088
00096 eoConstrictedVelocity (eoTopology < POT > & _topology,
00097 const VelocityType & _coeff,
00098 const VelocityType & _c1,
00099 const VelocityType & _c2,
00100 eoRng & _gen = rng):
00101 topology(_topology),
00102 coeff(_coeff),
00103 c1 (_c1),
00104 c2 (_c2),
00105 bounds(*(new eoRealVectorNoBounds(0))),
00106 bndsModifier(dummyModifier),
00107 gen(_gen){}
00108
00109
00119 void operator () (POT & _po,unsigned _indice)
00120 {
00121 VelocityType r1;
00122 VelocityType r2;
00123
00124 VelocityType newVelocity;
00125
00126
00127 r1 = (VelocityType) rng.uniform (1) * c1;
00128 r2 = (VelocityType) rng.uniform (1) * c2;
00129
00130
00131 bounds.adjust_size(_po.size());
00132
00133
00134 for (unsigned j = 0; j < _po.size (); j++)
00135 {
00136 newVelocity= coeff * (_po.velocities[j] + r1 * (_po.bestPositions[j] - _po[j]) + r2 * (topology.best (_indice)[j] - _po[j]));
00137
00138
00139 bndsModifier(bounds,j);
00140
00141
00142 if (bounds.isMinBounded(j))
00143 newVelocity=(VelocityType)std::max(newVelocity,bounds.minimum(j));
00144 if (bounds.isMaxBounded(j))
00145 newVelocity=(VelocityType)std::min(newVelocity,bounds.maximum(j));
00146
00147 _po.velocities[j]=newVelocity;
00148 }
00149 }
00150
00154 void updateNeighborhood(POT & _po,unsigned _indice)
00155 {
00156 topology.updateNeighborhood(_po,_indice);
00157 }
00158
00159
00160
00161 protected:
00162 eoTopology < POT > & topology;
00163 const VelocityType & c1;
00164 const VelocityType & c2;
00165 const VelocityType & coeff;
00166 eoRng & gen;
00167
00168 eoRealVectorBounds & bounds;
00169 eoRealBoundModifier & bndsModifier;
00170
00171
00172 eoDummyRealBoundModifier dummyModifier;
00173 };
00174
00175
00176 #endif
00177