Swarm

Swarming and flocking behaviour is shown by many species but it can be simulated using just three simple rules, first show by boids, a Java demonstration. To learn more about the demonstration read on below the applet.

swarm demo
Java applet cannot run. Replacing with screenshot.

Behaviour

The basic flocking model consists of three simple steering behaviours:

  1. Separation: steer to avoid crowding local flockmates.
  2. Alignment: steer towards the average heading of local flockmates.
  3. Cohesion: steer to move toward the average position of local flockmates.

Each bot knows about static objects within the world and other bots nearby. More elaborate behaviour can be created using predictive obstacle avoidance and goal seeking.

One of the purposes of a flock is to protect against predators, they find it difficult to pick individuals out of the swirling mass. Bots try to avoid the predator using two more rules of my own invention:

  1. Evasion: steer away from the predators heading.
  2. Avoidance: steer to move away from the position of the predator.

In this demonstration each behaviour has its own relative importance. Behaviours strengths can be dynamically modified and the effect seen immediately. Click on the applet brings up the control panel. There are five graphs, top to bottom, left to right, they are - separation, alignment, cohesion, evasion, avoidance. Dots on the left of each graph control behaviour close to the bot, each step to the right adds five body radii to the distance and the final dot represents all long distance behaviour. The two vertical extremes are 0% compliance at the bottom and 100% compliance at the top. To change a behaviour just grab on of the dots and slide it up and down. If the simulation appears slow or fast on your computer try a different number of bots and press set number bots.

Some behaviours are already preprogrammed in. To see one choose from the behaviour menu and press set behaviour, the graphs are moved automatically. Flocking is meant to be most the most bird like behaviour settings, to full appreciate it the predator should be switched on. Swarming is more bee like with individuals swerving about. Following that are some a selection of pure behaviours using just one graph each. Try these out and experiment with a few of your own. I have yet to see the evasion behaviour performing well but it may happen.

For those who want to see how its done here is the source code:

Credits

Thanks to Craig Reynolds who originated the bird flocking rules.