Particle Swarm Optmisation

I have always been very interested in the visual aspect of programming. I love to use it as a tool to create and generate things on the screen.


What I liked about both PSO ( Particle Swarm Optimisation ) and DFO ( Dispersive Flies Optimisation ) is that you can display a visual representation of their behaviour.


You can assign problems for them to solve and you can see how they behave based of the assigned problem.


Here is the fundamental behaviour in my PSO application. Inside this function is where the position of each particle is being updated. Inside my ofApp.cpp file I evaluate both the personal best position and the best neighbour position. These vectors are then being passed as arguments into my particle class.


In this application the personal best position or _pBest is set the the x and y position of the mouse. So by moving the mouse across the canvas the best position will update. I


//--------------------------------------------------------------
void Particle::update(ofVec2f _pBest, ofVec2f _neighbourhoodBest){
   
   //----------------------------------------------------------
   // calculate the velocity and adding to the position
   //----------------------------------------------------------
   c1 = c2 = X * 4.1/2.0;
   
   vel.x = X * ( vel.x + c1 * ofRandom(0, 1) * (_pBest.x - pos.x) + c2 * ofRandom(0, 1) * (_neighbourhoodBest.x - pos.x ));
   vel.y = X * ( vel.y + c1 * ofRandom(0, 1) * (_pBest.y - pos.y) + c2 * ofRandom(0, 1) * (_neighbourhoodBest.y - pos.y ));
   
   pos.x = ofClamp(pos.x, 0, ofGetWidth()) + vel.x;
   pos.y = ofClamp(pos.y, 0, ofGetHeight()) + vel.y;
}

Here is a gif of the application working with the mouse’s x & y position as the best position.



Module Evaluation:


There has been many useful topics in this module but the best thing I have learnt during this module has been the ability to convert mathematical equation into fully functional C++ code.
I have learnt to understand the concept about an algorithm and then successfully applying these concept into algorithms within my code.

I would have loved to cover more visual aspects of natural occurring phenomena such as DLA ( Diffusion-limited aggregation ) and perhaps cellular automata.



Comments

Popular posts from this blog

Physical Computing, Final Project

Dispersive Flies Optimisation ( DFO )

No Free Lunch Theorem