00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef EOFIXEDINERTIAWEIGHTEDVELOCITY_H
00026 #define EOFIXEDINERTIAWEIGHTEDVELOCITY_H
00027
00028
00029 #include <eoFunctor.h>
00030 #include <utils/eoRNG.h>
00031 #include <eoPop.h>
00032 #include <utils/eoRealVectorBounds.h>
00033 #include <eoTopology.h>
00034
00035
00036
00042 template < class POT > class eoFixedInertiaWeightedVelocity:public eoVelocity < POT >
00043 {
00044
00045 public:
00046
00047
00048
00049
00050 typedef typename POT::ParticleVelocityType VelocityType;
00051
00062 eoFixedInertiaWeightedVelocity (eoTopology < POT > & _topology,
00063 const VelocityType & _weight,
00064 const VelocityType & _c1,
00065 const VelocityType & _c2 ,
00066 eoRealVectorBounds & _bounds,
00067 eoRealBoundModifier & _bndsModifier,
00068 eoRng & _gen = rng):
00069 topology(_topology),
00070 weight(_weight),
00071 c1 (_c1),
00072 c2 (_c2),
00073 bounds(_bounds),
00074 bndsModifier(_bndsModifier),
00075 gen(_gen){}
00076
00077
00087 eoFixedInertiaWeightedVelocity (eoTopology < POT > & _topology,
00088 const VelocityType & _weight,
00089 const VelocityType & _c1,
00090 const VelocityType & _c2,
00091 eoRealVectorBounds & _bounds,
00092 eoRng & _gen = rng):
00093 topology(_topology),
00094 weight(_weight),
00095 c1 (_c1),
00096 c2 (_c2),
00097 bounds(_bounds),
00098 bndsModifier(dummyModifier),
00099 gen(_gen){}
00100
00101
00109 eoFixedInertiaWeightedVelocity (eoTopology < POT > & _topology,
00110 const VelocityType & _weight,
00111 const VelocityType & _c1,
00112 const VelocityType & _c2,
00113 eoRng & _gen = rng):
00114 topology(_topology),
00115 weight(_weight),
00116 c1 (_c1),
00117 c2 (_c2),
00118 bounds(*(new eoRealVectorNoBounds(0))),
00119 bndsModifier(dummyModifier),
00120 gen(_gen)
00121 {}
00122
00132 void operator () (POT & _po,unsigned _indice)
00133 {
00134 VelocityType r1;
00135 VelocityType r2;
00136
00137 VelocityType newVelocity;
00138
00139
00140 r1 = (VelocityType) rng.uniform (1) * c1;
00141 r2 = (VelocityType) rng.uniform (1) * c2;
00142
00143
00144 bounds.adjust_size(_po.size());
00145
00146
00147 for (unsigned j = 0; j < _po.size (); j++)
00148 {
00149 newVelocity= weight * _po.velocities[j] + r1 * (_po.bestPositions[j] - _po[j]) + r2 * (topology.best (_indice)[j] - _po[j]);
00150
00151
00152 bndsModifier(bounds,j);
00153
00154
00155 if (bounds.isMinBounded(j))
00156 newVelocity=(VelocityType)std::max(newVelocity,bounds.minimum(j));
00157 if (bounds.isMaxBounded(j))
00158 newVelocity=(VelocityType)std::min(newVelocity,bounds.maximum(j));
00159
00160 _po.velocities[j]=newVelocity;
00161 }
00162 }
00163
00167 void updateNeighborhood(POT & _po,unsigned _indice)
00168 {
00169 topology.updateNeighborhood(_po,_indice);
00170 }
00171
00172
00173
00174 protected:
00175 eoTopology < POT > & topology;
00176 const VelocityType & c1;
00177 const VelocityType & c2;
00178 const VelocityType & weight;
00179 eoRng & gen;
00180
00181 eoRealVectorBounds & bounds;
00182 eoRealBoundModifier & bndsModifier;
00183
00184
00185 eoDummyRealBoundModifier dummyModifier;
00186 };
00187
00188
00189 #endif
00190