SimuVeda

Computer Science · Simulator 056

Flocking

Each bird (“boid”) follows three simple rules about its nearby neighbours only. There is no leader and no plan, yet the group swirls and flows like a real flock. Turn each rule up or down, release a predator, and see which behaviour each rule controls.

How the model works

Craig Reynolds' boids (1987) steer by three local rules, each a small force computed from neighbours within a vision radius:

  • Separation: steer away from neighbours that are too close (avoid crowding).
  • Alignment: steer towards the average heading of neighbours.
  • Cohesion: steer towards the average position of neighbours.

Speeds are kept between a minimum and maximum, and the world wraps around. The order parameter (length of the average heading vector, from 0 = random to 1 = all aligned) measures how coordinated the flock is.

A predator adds a strong flee force for boids within its range, producing the splitting and re-forming seen in starling murmurations and fish schools. Lookups use a spatial grid so hundreds of boids stay fast.

An agent-based illustration, not a calibrated model of any species. Starting positions use a fixed seed.

Guided experiments

  1. All three rules. Default settings. Prediction: within seconds, scattered boids form moving flocks, and the order parameter rises towards 1.
  2. No alignment. Set alignment to 0. Prediction: boids clump but mill around in a swarm with no common direction. Order stays low.
  3. Predator. Turn on the predator. Prediction: the flock parts around the predator and re-forms behind it.

Challenge

Which single rule would you remove to make boids crash into each other, and which to make them never gather into groups?

Reveal the explanation

Without separation, cohesion and alignment pull boids on top of each other, so they collide. Without cohesion (and with little alignment), nothing draws them together, so they stay spread out. Try each with the sliders.

References

  • Reynolds, C. W. (1987), “Flocks, herds and schools: a distributed behavioral model”, SIGGRAPH '87, 25–34.
  • Ballerini et al. (2008), “Interaction ruling animal collective behavior…”, PNAS 105: 1232–1237.