32 #ifndef GRT_PARTICLE_SWARM_OPTIMIZATION_HEADER 33 #define GRT_PARTICLE_SWARM_OPTIMIZATION_HEADER 35 #include "../../Util/GRTCommon.h" 36 #include "PSOParticle.h" 40 template<
class PARTICLE_TYPE,
class OBSERVATION_TYPE>
49 minImprovement = 1.0e-10;
51 maxNumIterNoChange = 10;
92 if( K != xMin.size() || K != xMax.size() )
return false;
115 pIter->init(K,xMin,xMax);
151 virtual bool search(OBSERVATION_TYPE &observation){
159 errorLog << __GRT_LOG__ <<
" Particle propagation failed!" << std::endl;
164 unsigned int iterCounter = 0;
165 unsigned int numIterNoChangeCounter = 0;
166 Float currentMaxima = 0;
167 Float lastMaxima = 0;
169 bool keepSearching =
true;
174 while( keepSearching ){
180 delta = fabs( currentMaxima - lastMaxima );
181 lastMaxima = currentMaxima;
183 if( delta < minImprovement ){
184 if( ++numIterNoChangeCounter >= maxNumIterNoChange ){
185 keepSearching =
false;
186 infoLog << __GRT_LOG__ <<
" Reached no change limit, stopping search at iteration: " << iterCounter <<
" with a change of: " << fabs( currentMaxima - lastMaxima ) << std::endl;
188 }
else numIterNoChangeCounter = 0;
190 if( ++iterCounter == maxIter ){
191 keepSearching =
false;
192 infoLog << __GRT_LOG__ <<
" Max iteration reached, stopping search at iteration: " << iterCounter << std::endl;
213 unsigned int index = 0;
214 unsigned int bestIndex = 0;
215 Float currentBestMaxima = 0;
223 epsilon = pIter->evaluate(observation);
226 if( epsilon > currentBestMaxima ){
227 currentBestMaxima = epsilon;
245 return currentBestMaxima;
265 Float minImprovement;
266 unsigned int maxIter;
267 unsigned int maxNumIterNoChange;
284 #endif //GRT_PARTICLE_SWARM_OPTIMIZATION_HEADER virtual ~ParticleSwarmOptimization()
bool initialized
A flag to indicate if the PSO algorithm has been initialized.
This file contains the Random class, a useful wrapper for generating cross platform random functions...
virtual bool resize(const unsigned int size)
ParticleSwarmOptimization()
VectorFloat globalBestX
The state Vector of the particle with the best cost.
VectorFloat xMin
The minimum range of the state space.
Float globalBestCost
The current global best cost over all the particles.
bool setPropagationModel(const VectorFloat &propagationModel)
Vector< PARTICLE_TYPE > particles
A Vector containing all the particles used for the search.
Vector< Vector< PARTICLE_TYPE > > iterHistory
A buffer to keep track of the search history.
unsigned int K
The size of the particles state Vector.
PARTICLE_TYPE & operator[](const unsigned int &index)
int getRandomNumberInt(int minRange, int maxRange)
Vector< VectorFloat > globalBestXHistory
A buffer to keep track of the search history.
virtual Float searchIteration(OBSERVATION_TYPE &observation)
VectorFloat propagationModel
The propagation model used to update each particle.
VectorFloat xMax
The maximum range of the state space.
virtual bool init(const unsigned int numParticles, const unsigned int K, const VectorFloat &xMin, const VectorFloat &xMax, const VectorFloat &propagationModel)
VectorFloat finalX
The final estimate.
virtual bool search(OBSERVATION_TYPE &observation)