libflocks is an open source, ISO C programming library implementing boids, specifically using Conrad Parker's algorithm, to illustrate game theory with swarm behaviour. It is used in the flocks and gtkflocks applications.

Callers invoke a session of boids and their flocks (pure strategies), then repeatedly update the session to move? boids. From time to time, a single bird is chosen to play a game with its nearest neighbour?. This game produces probabilities for creating offspring. If offspring are born, each replaces a randomly-selected bird.

For questions, comments, and so on, please contact , k-Consulting, who originally wrote the flocks application for , Stockholm School of Economics with financial support from the Knut and Alice Wallenberg Research Foundation. If you'd like to use our work, please use the included citation!

How do the birds move?

The swarm algorithm describes complicated flock behaviour by having each boid (participant) follow simple rules. These rules are applied sequentially to all individuals in each session update. The parameters implementing these concepts are described in the flocks(3) manual.

1. Alignment

Each bird will displace itself (by a given multiplier) toward the centre of all birds excluding itself. In the following, the chosen bird (right) will align itself toward the centre of mass (circled–in reality, the centre is to the right of this location).

Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird

2. Cohesion

Each bird will adjust its velocity (in all three dimensions) to match the average velocity (again, all dimensions) of all birds excluding itself. In the following, the chosen bird (right) will adjust its velocity toward the average velocity of birds on the right (a bird circled as approximating the mean).

Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird

3. Separation

Each bird will displace itself from nearby birds. In the following, the chosen bird (centre) will adjust its position away from two closest birds (circled).

Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird

In addition to these basic rules, I implement several extensions that work along the same principles. First, each bird's speed (velocity magnitude) is bounded above and below. This prevents birds from being too pokey or too fast. Second, each bird's position is soft bounded within a flight space (i.e., encouraged to turn back at the boundary by softly displacing) or hard bounded within the visible space (i.e., forced to reverse direction). Lastly, I extend alignment to be a linear combination toward a boid's own flock (assortative matching) or all birds (random matching) depending on an assortativity fraction.

Alignment gives rise to the ability to study assortativity, or the effect of matching within one's own flock instead of uniform randomly. To wit, flocks(3) has shot-clock parameters designating for how long the assortativity is cranked up, then inverted. The shot clocks are represented as the mean to a Poisson random number, which is drawn whenever the shot clock expires. Thus, one may stipulate fractional time spent matching assortitatively versus uniform randomly.

How do the birds reproduce?

Game-play occurs periodically, at which point the system randomly choose a boid i to play a game with the nearest boid j of any flock as measured by Euclidean distance.

Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird

They play a simple bimatrix game, where the material payoff πij is linearly transformed into a reproduction probability. If either boid reproduces (both might), one boid per offspring (possibly the offspring's parent) is randomly selected for removal. If the new and old bird are from differnet flocks, the removed boids will fly off the space, and the offspring will fly in from random locations.

For example, consider a simple prisoner's dilemma. Let i be a cooperator and j be a defector. When these birds play together, i will draw a payoff less than j. These payoffs are then linearly transformed into reproduction probabilities, for example, πij = 0.3 and πji = 0.8, respectively. Both birds independently draw a random number to see if they'll reproduce. If the number is less than the payoff probability, they do.

Dowload

libflocks is distributed as source code which you can use for designing your own applications. If you'd rather see the result, visit gtkflocks or flocks. Otherwise, download the libflocks.tgz archive (optionally verifying its fingerprint). (An archive of all releases is in the snapshots directory.) If you're running on a UNIX system, you can compile and install the software in the usual way with make to compile and make install to install, which will install the library, header file, and manpage. If you're using Microsoft Windows, you'll need to find another way. (If you have a solution to this, let me know!)

For the time being, libflocks depends upon the GSL library solely for generating pseudo-random numbers. This is expected to change or be abstracted to the caller in future versions. Meanwhile, consider it a compile-time dependency.

The following describes recent releases of the system.