Flocking behavior is the behavior exhibited when a group of birds, called a flock, are foraging or in flight. There are parallels with the shoaling behavior of fish, the swarming behavior of insects, and herd behavior of land animals.
Computer simulations and mathematical models which have been developed to emulate the flocking behaviors of birds can generally be applied also to the „flocking“ behavior of other species. As a result, the term „flocking“ is sometimes applied, in computer science, to species other than birds.
This article is about the modelling of flocking behavior. From the perspective of the mathematical modeller, „flocking“ is the collective motion of a large number of self-propelled entities and is a collective animal behavior exhibited by many living beings such as birds, fish, bacteria, and insects. It is considered an emergent behavior arising from simple rules that are followed by individuals and does not involve any central coordination.
Flocking behavior was first simulated on a computer in 1986 by Craig Reynolds with his simulation program, Boids. This program simulates simple agents (boids) that are allowed to move according to a set of basic rules. The result is akin to a flock of birds, a school of fish, or a swarm of insects.
Basic models of flocking behavior are controlled by three simple rules:
- Separation – avoid crowding neighbors (short range repulsion)
- Alignment – steer towards average heading of neighbors
- Cohesion – steer towards average position of neighbors (long range attraction)
With these three simple rules, the flock moves in an extremely realistic way, creating complex motion and interaction that would be extremely hard to create otherwise.
The basic model has been extended in several different ways since Reynolds proposed it. For instance, Delgado-Mata et al.  extended the basic model to incorporate the effects of fear. Olfaction was used to transmit emotion between animals, through pheromones modelled as particles in a free expansion gas. Hartman and Benes  introduced a complementary force to the alignment that they call the change of leadership. This steer deﬁnes the chance of the boid to become a leader and try to escape.