Introduction to Complex Systems


Practical Problem 9: Chemotaxis

In this problem you will implement a model that captures several aspects of chemotaxis. The model involves patches as well as turtles. The problem follows several steps that add complexity to the model until end up with a full implementation of the model. Please follow the steps outlines below.

First set up a world of size 64x64.

Part 0: Diffusing Bugs

As a start generate 10 turtles that move around in the world randomly using sliders for

  • speed
  • and wiggle

like we did in previous examples.

Set the shape of the turtles to "bug" and color them black. In order to see the turtles you need to turn the background white:

 ask patches [set pcolor white]

Run the system to see if everything is working. The turtles should be very small on your screen.

Part 1: Bugs move around and stink

Now we are going model a situation in which the turtles emit a chemical. We are going to call the chemical smell and define it as a patch variable. When the turtle emits a smell it sets the patch variable of the patch on which the turtle currently sits to 1. So first we need to define a patch variable

patches-own [smell]

then we construct a function emit that loops over all turtles and emits a smell like to

ask turtles [
	if random-float 1 < emissionrate [
		ask patch-here [set smell 1]
	]
]

Now we need to visualize the smell by coloring the patches according to the value of the patch variable smell:

ask patches [set pcolor rgb  (255 - 255 * smell) (255 - 255 * smell) 255  ]

we make use of the netlogo function rgb here which takes three arguments for the color components red, green, blue each in the range of [0, 255].

When you run this, all the turtles should leave a trace of the smell chemical behind them.

Part 2: Smell diffuses and decays

Now you can diffuse the chemical, so the concentration of smell in each patch diffuses to the neighbors at each step. It’s super easy to do this Just add the command

diffuse smell 0.1

into the go function. The value 0.1 means that when the command diffuse is excecuted 10% of the smell is distributed among a patches neighbors.

Instead of a fixed number add a slider for diffusionrate to be able to control how fast diffusion happens. The value should be in the range [0,1].

Chemicals also decay, so write a function that at each tick decays the smell at each patch, like so:

ask patches [set smell smell * (1 - decayrate)]

The parameter decayrate should be small, like 0.01 or so. Use a slider to set it.

Part 3: Followers

Now add 100 new turtles that are supposed to respond to the smell. These should be a different type than the turtles that emit the smell. You can use breed to distinguish them, e.g.

breed [stinkers stinker]
breed [sniffers sniffer]

or something similar. Give the followers a different color, like red. One way to make these turtles respond the smell is by turning them towards a surrounding patches with the highest concentration like so:

let p max-one-of neighbors [smell]  
      face p
]      

Now add a threshold parameter that makes the followers only respond according to the above code if the smell is above a critical threshold.

Part 4: Avoiders

Now code a version in which the follower do now turn towards the neighboring patch with the highest smell, but the lowest.