Introduction to Complex Systems


Practical Problem 6: Swarming - The Viszek Model

In this problem, we will implemement a simple model for collective motion of bird flocks or animal swarms.

This is going to be a turtles-only simulation.

The model works like this: At each iteration turtles move forward at a predefined speed and they should randomly change their heading within a predefined wiggle angle much like in some of the other models you have implemented to far.

By default turtles have a heading, a variable that tells you what direction the turtle is heading.

At each step a turtle interacts with other turtles in an interaction radius $R$:

The turtle tries to align its heading to the average heading of the other turtles in the radius.

Preparation

We need 100-200 turtles with a shape of your choice. The setup function should place them randomly in the world. Add sliders for

  1. the initial number of turtles
  2. the speed
  3. the wiggle
  4. the interaction radius $R$

Simulation 1

First code the system without interactions, so the turtles move around randomly.

Then implement the interaction.

The difficulty here is computing the average of the headings of the neighbors. It is tempting to write:

ask turtles [
	set heading mean [heading] of turtles in-radius R
]

But this doesn’t work. Why does this not work?

We discussed this briefly in the discussion on the Kuramoto model and averaging angle variables. Because heading is an angle variable we have to apply the rules on how to average angles. If you can’t remember check the script The Kuramoto Model

So, in order to compute an average heading using a transformation to cartesian coordinates you can define a reporter function. This is how it works in netlogo:

to-report mean-heading [ headings ]
  let mean-x mean map sin headings
  let mean-y mean map cos headings
  report atan mean-x mean-y
end

You can call this function like this for example:

let x mean-heading [heading] of turtles;

This defines a new variable x that stores the average of the heading of the turtles as computed by the reporter-function mean-heading.

Optional:

Now we add a few predators. These are also turtles and we need a way to distinguish the swarming prey fish from the predators. We do this using netlogo breeds. Go to the netlogo manual and read about breeds. In a nutshell breeds are types of turtles that you can define in the beginning and the refer to them later.

The predators should first just move around in the world and the prey should avoid them. If a predator is within range of a prey the head should change its direction away from it. In order to make this more realistic the prey should only be able to see a predator in a visual cone ahead of it. You can implement this using the in-cone function.