How to Form a Swarm
You built the single particle code already. Drawing several particles is similar. They can even move randomly but don’t improve over time if that is all they do.
First, get the particles following their neighbors by finding these and making a move function to nudge each particle toward these. Unsurprisingly, these tend to gang together and take a long time to escape the paper bag. By making a different move function, the particles swarm out of your paper bag. The individual movement of the swarm particles will combine momentum, picked at random, to begin with. Over time, the movement needs to include movement toward a personal best and the global best to share information through the swarm. The standard PSO calculates a ...
Get Genetic Algorithms and Machine Learning for Programmers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.