00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef EOVARIABLEINERTIAWEIGHTEDVELOCITY_H
00012 #define EOVARIABLEINERTIAWEIGHTEDVELOCITY_H
00013
00014
00015 #include <eoVelocity.h>
00016 #include <eoTopology.h>
00017 #include <eoWeightUpdater.h>
00018 #include <utils/eoRealVectorBounds.h>
00019 #include <eoRealBoundModifier.h>
00020
00021
00022
00023
00029 template < class POT > class eoVariableInertiaWeightedVelocity:public eoVelocity < POT >
00030 {
00031
00032 public:
00033
00034
00035
00036
00037 typedef typename POT::ParticleVelocityType VelocityType;
00038
00049 eoVariableInertiaWeightedVelocity (eoTopology < POT > & _topology,
00050 eoWeightUpdater<VelocityType> & _weightUpdater,
00051 const VelocityType & _c1,
00052 const VelocityType & _c2 ,
00053 eoRealVectorBounds & _bounds,
00054 eoRealBoundModifier & _bndsModifier,
00055 eoRng & _gen = rng):
00056 topology(_topology),
00057 weightUpdater(_weightUpdater),
00058 c1 (_c1),
00059 c2 (_c2),
00060 bounds(_bounds),
00061 bndsModifier(_bndsModifier),
00062 gen(_gen){}
00063
00064
00074 eoVariableInertiaWeightedVelocity (eoTopology < POT > & _topology,
00075 eoWeightUpdater<VelocityType> & _weightUpdater,
00076 const VelocityType & _c1,
00077 const VelocityType & _c2,
00078 eoRealVectorBounds & _bounds,
00079 eoRng & _gen = rng):
00080 topology(_topology),
00081 weightUpdater(_weightUpdater),
00082 c1 (_c1),
00083 c2 (_c2),
00084 bounds(_bounds),
00085 bndsModifier(dummyModifier),
00086 gen(_gen){}
00087
00088
00096 eoVariableInertiaWeightedVelocity (eoTopology < POT > & _topology,
00097 eoWeightUpdater<VelocityType> & _weightUpdater,
00098 const VelocityType & _c1,
00099 const VelocityType & _c2,
00100 eoRng & _gen = rng):
00101 topology(_topology),
00102 weightUpdater(_weightUpdater),
00103 c1 (_c1),
00104 c2 (_c2),
00105 bounds(*(new eoRealVectorNoBounds(0))),
00106 bndsModifier(dummyModifier),
00107 gen(_gen)
00108 {}
00109
00120 void operator () (POT & _po,unsigned _indice)
00121 {
00122 VelocityType r1;
00123 VelocityType r2;
00124
00125 VelocityType newVelocity;
00126
00127
00128 r1 = (VelocityType) rng.uniform (1) * c1;
00129 r2 = (VelocityType) rng.uniform (1) * c2;
00130
00131
00132 bounds.adjust_size(_po.size());
00133
00134
00135 weightUpdater(weight);
00136
00137
00138 for (unsigned j = 0; j < _po.size (); j++)
00139 {
00140 newVelocity= weight * _po.velocities[j] + r1 * (_po.bestPositions[j] - _po[j]) + r2 * (topology.best (_indice)[j] - _po[j]);
00141
00142
00143 bndsModifier(bounds,j);
00144
00145
00146 if (bounds.isMinBounded(j))
00147 newVelocity=(VelocityType)std::max(newVelocity,bounds.minimum(j));
00148 if (bounds.isMaxBounded(j))
00149 newVelocity=(VelocityType)std::min(newVelocity,bounds.maximum(j));
00150
00151 _po.velocities[j]=newVelocity;
00152 }
00153 }
00154
00158 void updateNeighborhood(POT & _po,unsigned _indice)
00159 {
00160 topology.updateNeighborhood(_po,_indice);
00161 }
00162
00163
00164
00165 protected:
00166 eoTopology < POT > & topology;
00167 eoWeightUpdater<VelocityType> & weightUpdater;
00168 const VelocityType & c1;
00169 const VelocityType & c2;
00170
00171 eoRealVectorBounds & bounds;
00172 eoRealBoundModifier & bndsModifier;
00173
00174 VelocityType weight;
00175 eoRng & gen;
00176
00177
00178 eoDummyRealBoundModifier dummyModifier;
00179 };
00180
00181 #endif
00182