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 EOCONSTRICTEDVARIABLEWEIGHTVELOCITY_H
00026 #define EOCONSTRICTEDVARIABLEWEIGHTVELOCITY_H
00027
00028
00029 #include <eoVelocity.h>
00030 #include <eoTopology.h>
00031 #include <eoWeightUpdater.h>
00032 #include <utils/eoRealVectorBounds.h>
00033 #include <eoRealBoundModifier.h>
00034
00035
00036
00037
00043 template < class POT > class eoConstrictedVariableWeightVelocity:public eoVelocity < POT >
00044 {
00045
00046 public:
00047
00048
00049
00050
00051 typedef typename POT::ParticleVelocityType VelocityType;
00052
00064 eoConstrictedVariableWeightVelocity (eoTopology < POT > & _topology,
00065 const VelocityType & _coeff,
00066 eoWeightUpdater<VelocityType> & _weightUpdater,
00067 const VelocityType & _c1,
00068 const VelocityType & _c2 ,
00069 eoRealVectorBounds & _bounds,
00070 eoRealBoundModifier & _bndsModifier,
00071 eoRng & _gen = rng):
00072 topology(_topology),
00073 coeff(_coeff),
00074 weightUpdater(_weightUpdater),
00075 c1 (_c1),
00076 c2 (_c2),
00077 bounds(_bounds),
00078 bndsModifier(_bndsModifier),
00079 gen(_gen){}
00080
00081
00092 eoConstrictedVariableWeightVelocity (eoTopology < POT > & _topology,
00093 const VelocityType & _coeff,
00094 eoWeightUpdater<VelocityType> & _weightUpdater,
00095 const VelocityType & _c1,
00096 const VelocityType & _c2,
00097 eoRealVectorBounds & _bounds,
00098 eoRng & _gen = rng):
00099 topology(_topology),
00100 coeff(_coeff),
00101 weightUpdater(_weightUpdater),
00102 c1 (_c1),
00103 c2 (_c2),
00104 bounds(_bounds),
00105 bndsModifier(dummyModifier),
00106 gen(_gen){}
00107
00108
00117 eoConstrictedVariableWeightVelocity (eoTopology < POT > & _topology,
00118 const VelocityType & _coeff,
00119 eoWeightUpdater<VelocityType> & _weightUpdater,
00120 const VelocityType & _c1,
00121 const VelocityType & _c2,
00122 eoRng & _gen = rng):
00123 topology(_topology),
00124 coeff(_coeff),
00125 weightUpdater(_weightUpdater),
00126 c1 (_c1),
00127 c2 (_c2),
00128 bounds(*(new eoRealVectorNoBounds(0))),
00129 bndsModifier(dummyModifier),
00130 gen(_gen)
00131 {}
00132
00143 void operator () (POT & _po,unsigned _indice)
00144 {
00145 VelocityType r1;
00146 VelocityType r2;
00147
00148 VelocityType newVelocity;
00149
00150
00151 r1 = (VelocityType) rng.uniform (1) * c1;
00152 r2 = (VelocityType) rng.uniform (1) * c2;
00153
00154
00155 bounds.adjust_size(_po.size());
00156
00157
00158 weightUpdater(weight);
00159
00160
00161 for (unsigned j = 0; j < _po.size (); j++)
00162 {
00163 newVelocity= coeff * (weight * _po.velocities[j] + r1 * (_po.bestPositions[j] - _po[j]) + r2 * (topology.best (_indice)[j] - _po[j]));
00164
00165
00166 bndsModifier(bounds,j);
00167
00168
00169 if (bounds.isMinBounded(j))
00170 newVelocity=(VelocityType)std::max(newVelocity,bounds.minimum(j));
00171 if (bounds.isMaxBounded(j))
00172 newVelocity=(VelocityType)std::min(newVelocity,bounds.maximum(j));
00173
00174 _po.velocities[j]=newVelocity;
00175 }
00176 }
00177
00181 void updateNeighborhood(POT & _po,unsigned _indice)
00182 {
00183 topology.updateNeighborhood(_po,_indice);
00184 }
00185
00186
00187
00188 protected:
00189 eoTopology < POT > & topology;
00190
00191 const VelocityType & coeff;
00192 eoWeightUpdater<VelocityType> & weightUpdater;
00193
00194 const VelocityType & c1;
00195 const VelocityType & c2;
00196
00197 eoRealVectorBounds & bounds;
00198 eoRealBoundModifier & bndsModifier;
00199
00200 VelocityType weight;
00201 eoRng & gen;
00202
00203
00204 eoDummyRealBoundModifier dummyModifier;
00205 };
00206
00207 #endif
00208