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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access