00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef EOCONSTRICTEDVARIABLEWEIGHTVELOCITY_H
00012 #define EOCONSTRICTEDVARIABLEWEIGHTVELOCITY_H
00013
00014
00015 #include <eoVelocity.h>
00016 #include <eoTopology.h>
00017 #include <eoWeightUpdater.h>
00018 #include <utils/eoRealVectorBounds.h>
00019 #include <eoRealBoundModifier.h>
00020
00021
00022
00023
00029 template < class POT > class eoConstrictedVariableWeightVelocity:public eoVelocity < POT >
00030 {
00031
00032 public:
00033
00034
00035
00036
00037 typedef typename POT::ParticleVelocityType VelocityType;
00038
00050 eoConstrictedVariableWeightVelocity (eoTopology < POT > & _topology,
00051 const VelocityType & _coeff,
00052 eoWeightUpdater<VelocityType> & _weightUpdater,
00053 const VelocityType & _c1,
00054 const VelocityType & _c2 ,
00055 eoRealVectorBounds & _bounds,
00056 eoRealBoundModifier & _bndsModifier,
00057 eoRng & _gen = rng):
00058 topology(_topology),
00059 coeff(_coeff),
00060 weightUpdater(_weightUpdater),
00061 c1 (_c1),
00062 c2 (_c2),
00063 bounds(_bounds),
00064 bndsModifier(_bndsModifier),
00065 gen(_gen){}
00066
00067
00078 eoConstrictedVariableWeightVelocity (eoTopology < POT > & _topology,
00079 const VelocityType & _coeff,
00080 eoWeightUpdater<VelocityType> & _weightUpdater,
00081 const VelocityType & _c1,
00082 const VelocityType & _c2,
00083 eoRealVectorBounds & _bounds,
00084 eoRng & _gen = rng):
00085 topology(_topology),
00086 coeff(_coeff),
00087 weightUpdater(_weightUpdater),
00088 c1 (_c1),
00089 c2 (_c2),
00090 bounds(_bounds),
00091 bndsModifier(dummyModifier),
00092 gen(_gen){}
00093
00094
00103 eoConstrictedVariableWeightVelocity (eoTopology < POT > & _topology,
00104 const VelocityType & _coeff,
00105 eoWeightUpdater<VelocityType> & _weightUpdater,
00106 const VelocityType & _c1,
00107 const VelocityType & _c2,
00108 eoRng & _gen = rng):
00109 topology(_topology),
00110 coeff(_coeff),
00111 weightUpdater(_weightUpdater),
00112 c1 (_c1),
00113 c2 (_c2),
00114 bounds(*(new eoRealVectorNoBounds(0))),
00115 bndsModifier(dummyModifier),
00116 gen(_gen)
00117 {}
00118
00129 void operator () (POT & _po,unsigned _indice)
00130 {
00131 VelocityType r1;
00132 VelocityType r2;
00133
00134 VelocityType newVelocity;
00135
00136
00137 r1 = (VelocityType) rng.uniform (1) * c1;
00138 r2 = (VelocityType) rng.uniform (1) * c2;
00139
00140
00141 bounds.adjust_size(_po.size());
00142
00143
00144 weightUpdater(weight);
00145
00146
00147 for (unsigned j = 0; j < _po.size (); j++)
00148 {
00149 newVelocity= coeff * (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
00177 const VelocityType & coeff;
00178 eoWeightUpdater<VelocityType> & weightUpdater;
00179
00180 const VelocityType & c1;
00181 const VelocityType & c2;
00182
00183 eoRealVectorBounds & bounds;
00184 eoRealBoundModifier & bndsModifier;
00185
00186 VelocityType weight;
00187 eoRng & gen;
00188
00189
00190 eoDummyRealBoundModifier dummyModifier;
00191 };
00192
00193 #endif
00194