StarLogo Project:

Flies



WHAT IS IT?

This project simulates the behavior of up to 100 artificial flies, interacting visually with each other. Each fly uses a simple tracking system (Poggio and Reichardt, 1973, Land and Collett, 1974) which summarizes behavioral experiments in which individual flies fixate a target. The interaction of these simple modules gives rise to a variety of relatively complex behaviors, including swarm-like behaviors for a group of many flies.

This project is a StarLogo adaptation of the Visual Basic program on which A.I. Memo No. 1512, "Cooperative physics of fly swarms: an emergent behavior" by M. Poggio and T. Poggio, was based (this publication can be retrieved by anonymous ftp to publications.ai.mit.edu). If anything in the following description is unclear please refer to the above paper which explains the project in greater detail.

Male and female flies fixate - that is fly towards - small contrasted patterns and track moving objects. A simple mathematical model developed by Reichardt and Poggio describes this behavior. Each fly in this simulation uses this simple mathematical function to fixate, or chase, the other flies it sees. The angle between the chasing fly's direction of flight and the direction of the chased fly is calculated. This angle represents the position of the chased fly in the 360 degree visual field of the chasing fly. Each fly then uses this error angle to generate a torque value in order to correct its direction of flight. In each step each fly calculates an error angle and then a torque for all the flies it sees. Once all the torques corresponding to all the seen flies are calculated then they are added up and translated into an angular velocity value. However, the absolute value of the torque produced by the fly cannot exceed an upper limit. Therefore before calculating the angular velocity a saturation function is applied to the total torque. For one fly to see another fly, the latter fly has to be within the sight range of the former. This range can be altered on the slider marked "dist". The flies are all assumed to travel at a constant velocity. It is also important to note that the flies in our simulation are simply points on a screen and can pass through each other, unlike real flies.

Although the model is clearly an oversimplification, these simulations suggest that the interaction of very simple control systems may account for some of the complex behaviors observed in real swarms of flies or mosquitoes.

HOW TO USE IT

Before starting the simulation, set the various sliders to the desired positions. The following are descriptions of each slider's function:

-- The "flynum" slider --
This slider has a range of 2 to 100. It controls the total number of flies in the simulation.

-- The "dist" slider --
This slider has a range of 1 to 100. It sets the maximum distance at which one fly is visible to another fly. The units of distance are patches.

-- The "step" slider --
This slider sets the size of the time step of the simulation. In other words it sets what fraction of a patch the flies travel in one iteration. Its range is from 1 to 100. When the slider is set to 1, each fly moves 1/100 of a patch in one time step. When set to 100, each fly moves 1 patch per time step. It is usually preferable to increase the size of the time step when working with large numbers of flies so that the simulation does not run too slowly.

-- The "lin-non" slider --
There are two inputs to this slider: either 0 or 1. When set to 0, a linear function is used to calculate torque from error angle values. This means that the value of the torque increases in direct proportion with the value of the error angle. When the slider is set to 1, a non-linear function is used to generate torque. For error angles up to + or - 20 degrees this function generates a torque directly proportional to the error angle like the linear function. However, when the error angle exceeds + or - 20 degrees the slope of the function changes from positive to negative. This means that as the error angle gets larger and larger beyond + or - 20 degrees the torque generated decreases proportionally. This function is somewhat more realistic than the linear function because it gives less importance to flies which are behind the chasing fly and more importance to those directly infront of it.

-- The "blind" slider --
This slider has a range form 0 to 100. It sets the number of "blind" flies in the simulation. A "blind" fly is a fly which does not see any other flies and thus does not chase any other flies. It simply randomly changes its direction by up to + or - 20 degrees per step. "Blind" flies are useful for adding noise to a simulation since "non-blind" flies see and attempt to chase "blind" flies when they are within their sight range.

-- The "trails" slider --
There are two inputs to this slider: either 0 or 1. When set to 0, the flies do not leave any trails of their path. When set to 1 the flies do leave trails. This slider can be changed while the simulation is running and is useful for observing the precise flight paths of flies and keeping the screen from getting cluttered.

After setting the sliders to the desired positions click the "setup" button and the "go" button to start the simulation. All sliders can be changed while the simulation is running except the "flynum" slider. Changing this slider while the simulation is running yields faulty results.

THINGS TO NOTICE

There are so many interesting behaviors to take note of that it is impossible to list them all here. Many of them are described in detail in the A.I. memo mentioned above. However it is important to notice the difference between behaviors of flies controlled by the linear function and the non-linear function. It is also interesting to play around with the "dist" slider and to observe how changing the maximum sight distance affects the flies.

Although swarms of many flies may seem to be the most interesting behavior to observe, do not overlook the behavior of 2 or 3 flies chasing each other.

EXPLORATIONS

* Swarm behaviors are best observed with the "lin-non" slider set to 1, the "step" slider set to around 60, the "trails" slider set to 0, the "dist" slider set to 100, the "flynum" slider set to around 20 or 25, and the "blind" slider is set to 5 or 10. "Blind" flies add noise to the simulation which increases the likelihood of swarms breaking up and regrouping. This is by no means the only setup for swarming behavior. Experiment with other setups.

* Play around with the settings when there are only 2 or 3 flies in the simulation (the "step" slider will have to be set very low for such a small number of flies). Set the "trails" slider to 1 and look for "weaving" behaviors and "flower-like" attractors.

* Play around with all the settings. Use your imagination. There are countless combinations to explore.

STARLOGO FEATURES

The code of this program is relatively long and complicated compared to most StarLogo programs. But if you can make sense out of it, changing the torque function can yield some interesting results. Can you write a more efficient chasing function?

Project by M. Poggio

Special thanks to Prof. Heinrich Blthoff and The Max Planck Institut fr Biologische Kybernetik for supporting this project.

For more information see:

A.I. Memo No. 1512, "Cooperative physics of fly swarms: an emergent behavior" by M. Poggio and T. Poggio

(ftp://publications.ai.mit.edu/ai-publications/1500-1999/ AIM-1512ps.Z)