Artificial Life: a fish simulation

For a module called Swarm Intelligence and Artificial Life I was tasked with developing a website that contained a demonstration of either a swarm intelligence or an artificial life. As the more entertaining to watch of the two, I decided to develop an artificial life simulation.

I started by looking into what had been done before. Flocking behaviours are the most common example and very quickly I ended up at Reynolds paper on Boids [1].

As simulations of birds have been done alot, to differentiate my simulation I chose to make a simulation of fish schoaling. The basic algorithm for boids works equally well to describe the behaviour of a school of fish as a flock of birds and so, using the boids algoithm I got some triangles swimming.

Boid triangles

Next I decided that to make it more interesting and so I added the ability to feed the fish. By clicking the mouse, the user drops some food into the fish tank and the fish are attracted to the food.

This is where swarm intelligence ideas came into my mind. In swarm intelligence there is a technique called particle swarm optimisation. This is used to probe a search space to try to find the fittest position. At each time step a number of particles have their velocity updated using a mixture of their current velocity, the previous best position in the search space they've visited and the best position in the search space that any had visited. I wanted to encoporate an aspect of this into my artifical life demonstration.

Unfortuantely, as only one piece of food is dropped when the user clicks, the first fish that reaches it lowers the search space back to an even terrain as they eat the food. Therefore, it would not be useful to have all fish continue to visit this position. On the other hand, in real life a fish that has eaten from a particular spot is more likely to revisit it. So the local best aspect from partical swarm optimisation was adopted; making the fish more likely to swim toward a point where they'd eaten food.

As food has a scent, the food was made to attract the fish. This attraction was modelled with a sence of realism. A scent cannot travel an infinate distance away from its source, and infact decays with the distance it travels. Therefore, the scent of the food was made to decay over distance. This causes an exponential decay of the scent and therefore, an exponential decay in the attraction to the food, based on distance.

Finally, a predator was added to the demonstration. The predator should work in the opposite way to the food. Rather than attracting the fish, the predator repells them from its location. Again this "fear" of the shark was modelled by distance decay, as the further from the shark a fish is, the less it will know the shark is there. The predator can swim faster than the fish as it is larger, thus making the fish have to perform more interesting behaviours to avoid it.

The shark's movement is not modelled and instead it simply heads toward the centre of mass of all the fish. If the mouth of the shark gets within a small distance of the mouth of a fish, the shark eats the fish.

The website for the artificial life simulation can be found here:

[1] Reynolds, C. W. (1987) "Flocks, Herds, and Schools: A Distributed Behavioral Model", in Computer Graphics, 21(4) (SIGGRAPH '87 Conference Proceedings) pages 25-34.