Flocking simulations model the coordinated movements that animals exhibit when moving in a group. Flocking simulations are typically used to simulate flocks of birds or schools of fish. There have also been applications of flocking simulations to conduct research on human crowds, especially in panic situations. Flocking simulations belong to the category of multi-agent systems.

A Natural Flock of Birds. Depicted here is a flock that consists of thousands of starlings. These birds are particularly famous for their spectacular murmurations.

Multi-Agent Systems

Multi-Agent systems play an important role in the synthetic natural sciences such as Artificial Live and Artificial Intelligence. As the name implies, multi-agent systems model the behaviours of multiple agents at the same time. Such systems can be useful research tools to study social phenomena. In particular, such systems allow to systematically explore how the properties and behaviours of individual agents affect the emergence of properties and behaviours at the level of a group (or multiple groups). Following the principle of Occam’s razor, these systems try to obtain sophisticated group behaviours from minimalistic agent designs.

Core Components of a Multi-Agent System. © Herrera et. al. 2020

The core principles of a multi-agent system are as follows. A multi-agent system consists of agents and an environment. Agents are decidedly kept simple in their properties and capabilities (especially in terms of their cognitive capabilities). Agents are situated which implies that they can only perceive their environment and other agents within their local surroundings (and possibly through their own sensory organs). Agents’ possess behaviours that allow them to act based on what they locally perceive. The immediate consequences of these actions have only a local effect. Everything that happens on a global level such as the behaviours of an entire group or large scale changes in the environment results from the self-organised dynamics of local activities.

Flocking Simulation

A flocking simulation is a particularly simple instance of a multi-agent system. In its most basic form, a flocking simulation is barely different from a physics simulation, with the only exception that the bodies in the simulation possess behaviours to generate forces to propel themselves forward and that some of these behaviours take the proximity of other bodies into account.

Boids

The archetype of flocking simulations is a system named Boids that has been devised by Craig Reynolds in 1987. At that time, Boids helped him create a computer animation of a flock of birds that would have been too tedious to do manually. In Boids, agents possess three properties and three behaviours. An agent has a mass, a position, and a velocity. The three behaviours are:

• Cohesion: agents move towards the perceived centre of their neighbours.
• Separation: agents move away from very close neighbours.
• Alignment: agents adapt the magnitude and direction of their velocity to the average velocity of their neighbours.

The Three Agent Behaviours in Boids. Agents are depicted as triangles. The green triangle is the agent exhibiting a behaviour and the blue agents are its neighbours. The grey circle depicts the zone within which the agent perceives its neighbours.

Extensions to Boids

The Boids system serves as basis for many scientific and artistic works that involve flocking simulations. One of the reasons for this is that the Boids system can be easily modified and extended. These extensions can serve the purpose of increasing the biological plausibility of the simulation or to increase the richness of group formations that can be obtained. Some possible extensions include: directional instead of omnidirectional perception of agents, heterogenous agent properties that mimic for instance differences between adult and child animals, adaptive behaviours that change through learning or evolution, agents with body shapes other than just points, and the simulation of the physical properties of the medium through which agents travel.

As part of the E2-Create project, a C++ flocking simulation library that has originally developed for applications in computer music has been ported to the OpenFrameworks creative coding platform. This library makes it easy to implement simulations that extend the Boids system or are even entirely different from it.

Addendum: Simulation Boundary

The environment in a flocking simulation is decidedly simple. It serves mostly as empty space within which agents are assigned their positions. Occasionally, the environment might also contain static obstacles. Other than that, the most important aspect of the environment in a flocking simulation concerns its boundaries. Spatial boundaries play an important role in any type of simulation. But in the case of flocking simulations, the boundaries influence the overall group movements. For this reason, it is worthwhile to briefly mention the three different canonical approaches for dealing with simulation boundaries. A computer is obviously unable to simulate an environment that is infinitely large. Sometimes, the fact that an environment is limited in size conforms with the intended properties of the simulation. But at other times, it is not.

In a simulated environment that is treated as finite, agents that are about to cross the boundary can be dealt with in three ways. One approach causes the agents to elastically bounce of the boundary by mirroring the direction of their velocity at the anticipated point of contact with the boundary. A second approach brings the agents to a full stop at the point of contact with the boundary by setting its velocity to zero. A third approach employs repulsion forces that push agents away from the boundary. These forces increase the closer an agent approaches a boundary. All these three approaches substantially change the coordinated group movements of the agents.

A simulation environment can also be treated as if it was infinite by wrapping the positions of the agents that cross a boundary around. This causes the agents to reappear at the other end of the simulation environment without changing their velocities or accelerations. By employing this approach, the coordinated group movements of agents are not affected by the presence of a boundary.

Dance Performance

In the context of the E2-Create project, a dance piece entitled “Embodied Machine” has been created. This dance piece has been choreographed by Muriel Romero. The music for the piece has been composed by Pablo Palacio. The piece employs live motion capture of a single dancer in combination with moving lights, lasers, and synthetic music. In two scenes, a flocking simulation is used to control the movement of lights.

In one scene, the dancer interacts with moving lights that follow more or less closely one or several of the dancer’s body joints. For this scene, a flocking simulation with two groups of agents is used. In the first group, each agent corresponds to a single moving light which is points towards the agent’s position. In the second group, each agent corresponds to one of the dancer’s joints that is tracked by the motion capture system. These agents mirror the position and velocities of the dancer’s joints. The agents in the first group possess several behaviours with which they can respond to the proximity of other agents from the first or second group. These behaviours are identical to those of a Boids system but exist in duplicated versions. One version causes an agent to respond only to neighbouring agents in the first group. The other version causes the agent to respond only to neighbouring agents in the second group. The agents in the second group don’t possess any behaviours (they are fully remote controlled through motion capture) but they can change their visibility for the agents in the first group. By varying the contribution of these behaviours to the overall movement of the agents, different group formations can be created that are either clustered around joints of the dancer or move independently of them.

Flocks and Motion Capture. Agents from two simulated flocks are interacting with each other. The agents in red are assigned to joints of a dancer in a live motion capture recording and simply mirror the joints’ positions and velocities. The agents in black are autonomous and respond to each other or to the agents in red through Boids type of behaviours.
Scene from the Dance Piece “Embodied Machine”. The moving lights are pointing towards the agents of a flock that move autonomously and are occasionally attracted to joints of the dancer.

In another scene, the agents in a flocking simulation are displayed as simple lines by a laser light show projector. These lines are projected on the dancer and on the floor. This simulation consists of only one group of agents. These agents possess various behaviours in addition to those of a Boids system. These additional behaviours are:

  • Target Position Behaviour: generates forces that push agents towards a target position.
  • Target Velocity Behaviour: generates forces that cause agents to align in velocity and direction with a target velocity.
  • Damping Behaviour: generates forces that cause agents to accelerate or de-accelerate to achieve a preferred speed.
  • Circular Behaviour: generates forces that cause agents to move within an inner and outer circumference of a circle.
  • Angular Acceleration Behaviour: limits the amount by which the direction of an agent’s acceleration can change from one simulation step to the other.

The parameters of the behaviours offer ample room to improvise with different flocking formations. In this scene, both the dancer and the performer controlling the swarm improvise together.

Improvising with Behaviour Parameters of a Single Flock. Shown on the left is the regular visualisation of the flocking simulation. Shown on the right is a visualisation used for laser light shown projection in which agents are displayed as directed lines whose length if proportional to the agents’ velocity.
Scene from the Dance Piece “Embodied Machine”. The lines projected with a light show laser projector correspond to flocking agents. Both the dancer and person controlling the flocking simulation improvise in this scene.