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 EOSTANDARDVELOCITY_H
00027 #define EOSTANDARDVELOCITY_H
00028
00029
00030 #include <eoFunctor.h>
00031 #include <utils/eoRNG.h>
00032 #include <eoPop.h>
00033 #include <utils/eoRealVectorBounds.h>
00034 #include <eoRealBoundModifier.h>
00035 #include <eoTopology.h>
00036
00037
00038
00044 template < class POT > class eoStandardVelocity:public eoVelocity < POT >
00045 {
00046
00047 public:
00048
00049
00050
00051
00052 typedef typename POT::ParticleVelocityType VelocityType;
00053
00064 eoStandardVelocity (eoTopology < POT > & _topology,
00065 const VelocityType & _w,
00066 const VelocityType & _c1,
00067 const VelocityType & _c2,
00068 eoRealVectorBounds & _bounds,
00069 eoRealBoundModifier & _bndsModifier,
00070 eoRng & _gen = rng):
00071 topology(_topology),
00072 omega (_w),
00073 c1 (_c1),
00074 c2 (_c2),
00075 bounds(_bounds),
00076 bndsModifier(_bndsModifier),
00077 gen(_gen){}
00078
00079
00089 eoStandardVelocity (eoTopology < POT > & _topology,
00090 const VelocityType & _w,
00091 const VelocityType & _c1,
00092 const VelocityType & _c2,
00093 eoRealVectorBounds & _bounds,
00094 eoRng & _gen = rng):
00095 topology(_topology),
00096 omega (_w),
00097 c1 (_c1),
00098 c2 (_c2),
00099 bounds(_bounds),
00100 bndsModifier(dummyModifier),
00101 gen(_gen){}
00102
00103
00111 eoStandardVelocity (eoTopology < POT > & _topology,
00112 const VelocityType & _w,
00113 const VelocityType & _c1,
00114 const VelocityType & _c2,
00115 eoRng & _gen = rng):
00116 topology(_topology),
00117 omega (_w),
00118 c1 (_c1),
00119 c2 (_c2),
00120 bounds(*(new eoRealVectorNoBounds(0))),
00121 bndsModifier(dummyModifier),
00122 gen(_gen)
00123 {}
00124
00125
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= omega * _po.velocities[j] + r1 * (_po.bestPositions[j] - _po[j]) + r2 * (topology.best (_indice)[j] - _po[j]);
00150
00151
00152 if (bounds.isMinBounded(j))
00153 newVelocity=std::max(newVelocity,bounds.minimum(j));
00154 if (bounds.isMaxBounded(j))
00155 newVelocity=std::min(newVelocity,bounds.maximum(j));
00156
00157 _po.velocities[j]=newVelocity;
00158 }
00159 }
00160
00164 void updateNeighborhood(POT & _po,unsigned _indice)
00165 {
00166 topology.updateNeighborhood(_po,_indice);
00167 }
00168
00171
00172 eoTopology<POT> & getTopology ()
00173 {
00174 return topology;
00175 }
00176
00177 protected:
00178 eoTopology < POT > & topology;
00179 const VelocityType & omega;
00180 const VelocityType & c1;
00181 const VelocityType & c2;
00182
00183 eoRealVectorBounds bounds;
00184 eoRealBoundModifier & bndsModifier;
00185
00186 eoRng & gen;
00187
00188
00189 eoDummyRealBoundModifier dummyModifier;
00190 };
00191
00192
00193 #endif
00194