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