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