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 EOINTEGERVELOCITY_H
00027 #define EOINTEGERVELOCITY_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 eoIntegerVelocity:public eoVelocity < POT >
00045 {
00046
00047 public:
00048
00049
00050
00051
00052 typedef typename POT::ParticleVelocityType VelocityType;
00053
00064 eoIntegerVelocity (eoTopology < POT > & _topology,
00065 const VelocityType & _c1,
00066 const VelocityType & _c2,
00067 const VelocityType & _c3,
00068 eoRealVectorBounds & _bounds,
00069 eoRealBoundModifier & _bndsModifier,
00070 eoRng & _gen = rng):
00071 topology(_topology),
00072 c1 (_c1),
00073 c2 (_c2),
00074 c3 (_c3),
00075 bounds(_bounds),
00076 bndsModifier(_bndsModifier),
00077 gen(_gen){}
00078
00079
00089 eoIntegerVelocity (eoTopology < POT > & _topology,
00090 const VelocityType & _c1,
00091 const VelocityType & _c2,
00092 const VelocityType & _c3,
00093 eoRealVectorBounds & _bounds,
00094 eoRng & _gen = rng):
00095 topology(_topology),
00096 c1 (_c1),
00097 c2 (_c2),
00098 c3 (_c3),
00099 bounds(_bounds),
00100 bndsModifier(dummyModifier),
00101 gen(_gen){}
00102
00103
00110 eoIntegerVelocity (eoTopology < POT > & _topology,
00111 const VelocityType & _c1,
00112 const VelocityType & _c2,
00113 const VelocityType & _c3,
00114 eoRng & _gen = rng):
00115 topology(_topology),
00116 c1 (_c1),
00117 c2 (_c2),
00118 c3 (_c3),
00119 bounds(*(new eoRealVectorNoBounds(0))),
00120 bndsModifier(dummyModifier),
00121 gen(_gen)
00122 {}
00123
00124
00131 void operator () (POT & _po,unsigned _indice)
00132 {
00133 VelocityType r2;
00134 VelocityType r3;
00135
00136 VelocityType newVelocity;
00137
00138
00139 r2 = (VelocityType) rng.uniform (1) * c2;
00140 r3 = (VelocityType) rng.uniform (1) * c3;
00141
00142
00143 bounds.adjust_size(_po.size());
00144
00145
00146 for (unsigned j = 0; j < _po.size (); j++)
00147 {
00148 newVelocity= round (c1 * _po.velocities[j] + r2 * (_po.bestPositions[j] - _po[j]) + r3 * (topology.best (_indice)[j] - _po[j]));
00149
00150
00151 if (bounds.isMinBounded(j))
00152 newVelocity=std::max(newVelocity,bounds.minimum(j));
00153 if (bounds.isMaxBounded(j))
00154 newVelocity=std::min(newVelocity,bounds.maximum(j));
00155
00156 _po.velocities[j]=newVelocity;
00157 }
00158 }
00159
00163 void updateNeighborhood(POT & _po,unsigned _indice)
00164 {
00165 topology.updateNeighborhood(_po,_indice);
00166 }
00167
00170
00171 eoTopology<POT> & getTopology ()
00172 {
00173 return topology;
00174 }
00175
00176 protected:
00177 eoTopology < POT > & topology;
00178 const VelocityType & c1;
00179 const VelocityType & c2;
00180 const VelocityType & c3;
00181
00182 eoRealVectorBounds bounds;
00183 eoRealBoundModifier & bndsModifier;
00184
00185 eoRng & gen;
00186
00187
00188 eoDummyRealBoundModifier dummyModifier;
00189 };
00190
00191
00192 #endif
00193