Sunday 2 February 2014

Programming swarm intelligence

Incidentally, exploring swarm intelligence isn't terribly difficult if you know a bit of programming... when I was experimenting with it, I just used VBA and Excel.  The trick is knowing object oriented programming and using it to create multiple entities that can interact in a virtual environment - e.g., by position on a 2 dimensional matrix.  Excel's main advantage is that its easy to dump the results out into a worksheet to examine and graph, though I wouldn't use it for any computationally heavy project.  Because the behavior of your entities is based on simple rules, the programming can be as basic as checking if the block in an array at the position ahead or behind is occupied, and then altering behavior accordingly... or assessing the values of the other members of the swarm and modifying its status in response. 

It would be nice if I could point to a bespoke programming environment for programming and experimenting with these concepts... I suspect with some looking I could find one, but it would probably be locked away in some university comp sci lab. I did find reference to this book which has a chapter on swarm intelligence and some pseudocode to start people out with however.

Swarm Intelligence and Data Mining


Some years ago, I experimented with swarm intelligence as a way to search out optimal solutions for non-linear problems.  The idea behind this is that rather than taking a straight computational approach, you use a swam of entities that 'search' the computational space for the optimal solution, each entity following a set of search rules and communicating with the other entities in order to quickly find the best result.  Its used for problems where there may be multiple 'sorta right' answers and where its easy to get an answer that is better than the others, but not the best possible answer. Think of problems such as the travelling salesman problem, where the is one best solution, but it could take a long time to find it, and there are lots of suboptimal solutions that look right (better than most) but aren't the best.

The inspiration for this approach is taken directly from nature... ants are an obvious type of animal that uses swarm intelligence, as are flocking birds and schooling fishes.  Using simple rules of proximity, they maintain a structure and move as a unit (or in the case of ants, move towards a goal) without an overarching intelligence.  On this video below, look at the way these grunts change their movement and shift direction together as I swim through the school...  they do it almost automatically, with no pauses to reassess their location and speed.  Imagine trying to do this if you were driving in a 'swarm' of cars... without the instinct to automatically judge neighbors distance and adjust speed and direction, it would be a disaster.