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