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
00026 #ifndef EOCONSTRICTEDVELOCITY_H
00027 #define EOCONSTRICTEDVELOCITY_H
00028
00029
00030 #include <eoFunctor.h>
00031 #include <utils/eoRNG.h>
00032 #include <eoPop.h>
00033 #include <utils/eoRealVectorBounds.h>
00034 #include <eoTopology.h>
00035
00036
00037
00044 template < class POT > class eoConstrictedVelocity:public eoVelocity < POT >
00045 {
00046
00047 public:
00048
00049
00050
00051
00052 typedef typename POT::ParticleVelocityType VelocityType;
00053
00064 eoConstrictedVelocity (eoTopology < POT > & _topology,
00065 const VelocityType & _coeff,
00066 const VelocityType & _c1,
00067 const VelocityType & _c2 ,
00068 eoRealVectorBounds & _bounds,
00069 eoRealBoundModifier & _bndsModifier,
00070 eoRng & _gen = rng):
00071 topology(_topology),
00072 coeff(_coeff),
00073 c1 (_c1),
00074 c2 (_c2),
00075 bounds(_bounds),
00076 bndsModifier(_bndsModifier),
00077 gen(_gen){}
00078
00079
00089 eoConstrictedVelocity (eoTopology < POT > & _topology,
00090 const VelocityType & _coeff,
00091 const VelocityType & _c1,
00092 const VelocityType & _c2,
00093 eoRealVectorBounds & _bounds,
00094 eoRng & _gen = rng):
00095 topology(_topology),
00096 coeff(_coeff),
00097 c1 (_c1),
00098 c2 (_c2),
00099 bounds(_bounds),
00100 bndsModifier(dummyModifier),
00101 gen(_gen){}
00102
00103
00111 eoConstrictedVelocity (eoTopology < POT > & _topology,
00112 const VelocityType & _coeff,
00113 const VelocityType & _c1,
00114 const VelocityType & _c2,
00115 eoRng & _gen = rng):
00116 topology(_topology),
00117 coeff(_coeff),
00118 c1 (_c1),
00119 c2 (_c2),
00120 bounds(*(new eoRealVectorNoBounds(0))),
00121 bndsModifier(dummyModifier),
00122 gen(_gen){}
00123
00124
00134 void operator () (POT & _po,unsigned _indice)
00135 {
00136 VelocityType r1;
00137 VelocityType r2;
00138
00139 VelocityType newVelocity;
00140
00141
00142 r1 = (VelocityType) rng.uniform (1) * c1;
00143 r2 = (VelocityType) rng.uniform (1) * c2;
00144
00145
00146 bounds.adjust_size(_po.size());
00147
00148
00149 for (unsigned j = 0; j < _po.size (); j++)
00150 {
00151 newVelocity= coeff * (_po.velocities[j] + r1 * (_po.bestPositions[j] - _po[j]) + r2 * (topology.best (_indice)[j] - _po[j]));
00152
00153
00154 bndsModifier(bounds,j);
00155
00156
00157 if (bounds.isMinBounded(j))
00158 newVelocity=(VelocityType)std::max(newVelocity,bounds.minimum(j));
00159 if (bounds.isMaxBounded(j))
00160 newVelocity=(VelocityType)std::min(newVelocity,bounds.maximum(j));
00161
00162 _po.velocities[j]=newVelocity;
00163 }
00164 }
00165
00169 void updateNeighborhood(POT & _po,unsigned _indice)
00170 {
00171 topology.updateNeighborhood(_po,_indice);
00172 }
00173
00176
00177 eoTopology<POT> & getTopology ()
00178 {
00179 return topology;
00180 }
00181
00182 protected:
00183 eoTopology < POT > & topology;
00184 const VelocityType & c1;
00185 const VelocityType & c2;
00186 const VelocityType & coeff;
00187 eoRng & gen;
00188
00189 eoRealVectorBounds & bounds;
00190 eoRealBoundModifier & bndsModifier;
00191
00192
00193 eoDummyRealBoundModifier dummyModifier;
00194 };
00195
00196
00197 #endif
00198