Chapter 7: Half-Life & Stink-Bomb

Many simulations involve one or both of these situations; it is very important to do these and other things in your simulations in ways that are biologically reasonable. These exercises will show you biologically-reasonable ways to include these processes in your simulations.

  1. I need to make something go away. It could be a hormone, an activated enzyme, an injected drug, or a pheromone left behind by an ant leaving a trail to find her way home. In all of these cases, it's easy to figure out how to make the agents but it's not as obvious how to get rid of them. You'd like them to go away eventually but things like hormones and activated molecules don't have self-destruct timers built in.
    So, how do they go away in real life? Something happens to them randomly: a hormone molecule gets excreted by the kidney; a drug runs into a liver enzyme that inactivates it; a pheromone evaoprates; an enzyme is hit by a deactivating protein; etc. The thing that all of these have in common is that they're random - nobody can control when they happen but we can say something about how likely it is to happen. This is where 'half-life' comes in.
  2. I need one agent to tell if it's close to another. It could be a bacterium looking for a mate, an amoeba looking for prey, or a protozoan wanting to avoid something toxic. In all of these cases, the thing you're simulating doesn't have eyes so it can't see how far away the other agent is.
    How does this work in real life? One agent secretes molecules that diffuse out and eventually are degraded. The closer another agent is to the secreter, the more often it will be hit by one of these stinky molecules. So, you can set a threshold for how many hits counts as 'close enough'. This is where 'stink-bomb' comes in.

The next two exercises will show you how to code these two very useful tricks.

1) Exponential decay (a.k.a. "half-life")

In many simulations, you'll need a biologically-reasonable way to get rid of unwanted agents.
Exponential decay is a very realistic and easily-implemented way to do this.

1) Put some agents in the world that randomly 'self-destruct'.

Steps:
  1. Start a new project and give it a fun name.
  2. Set it to create 100 scattered agents with some fun color and shape when you press 'setup'.
  3. Give each agent a 1% chance of deleting itself every time tick once "forever" is toggled.
  4. Build a databox and graph that shows the number of surviving agents over time.

You can download a template project here.

to setup
  clear-all
  create-turtles 100 [
    set color red
    set shape "triangle"
    set xcor (random 32) - 16
    set ycor (random 32) - 16
  ]
  reset-ticks
end



to forever
  ask turtles [
    if (random 100) < 1 [ die ]
  ]
  tick
end
		
2) The result: exponential decay.

You should see the number of turtles drop. But, more specifically:
  • At first, it drops rapidly and then the rate of decline slows.
  • To be exponential decay, it must decay with a constant half-life. That is, the time it takes to go from 100 to 50 should be the same as to go from 80 to 40 or 20 to 10 etc. Check this at a few points. It should be about the same number of time steps for each 1/2 ratio.
3) Play with the numbers.
  1. Try starting with 1000 agents and measure the half-life. It should be the same as when you started with 100.
  2. Try changing the chance of deletion and estimating the half-life. Does a higher chance lead to a longer or shorter half-life?
4) Add a source of agents.

Modify the code to:

  1. Add a new button called "add agents" (a pushbutton, not a toggle button).
  2. Put code in the "world" tab so that, when this button is pressed, 10 turtles with the same features as the others are created and scattered in the world.
  3. Make sure that the databox and graph are updated when you click this button.
to setup
  clear-all
  create-turtles 100 [
    set color red
    set shape "triangle"
    set xcor (random 32) - 16
    set ycor (random 32) - 16
  ]
  reset-ticks
end

to forever
  ask turtles [
    if (random 100) < 1 [ die ]
  ]
  tick
end

to addAgents 
  create-turtles 10 [
    set color red
    set shape "triangle"
    set xcor (random 32) - 16
    set ycor (random 32) - 16
  ]
end  

5) Play around and see how it behaves.

Try to answer some of these questions:

  • What happens when tyou click the button rarely? frequently?
  • What would you need to do to keep a relatively constant level of agents?

You can download a complete version of this project here.

2) Diffusible signals (a.k.a. "stink-bomb")

This is a realistic way for agents without eyes to learn about their neighborhood.

1) Start a project with a 'stinky' agent in the center and have it spray out 'stinky' molecules.

Steps:
  1. Start a new project and give it a clever name.
  2. Create a new breed called 'stinker'.
  3. When setup is pushed, create one stinker, make it large enough to see, and put it in the center of SpaceLand. Stinkers never move.
  4. Create a new breed called 'stink'.
  5. When forever is toggled, have it constantly produce five stinks per 'tick', each facing in a random direction. Have these 'meander' and have a 5% chance of deleting.

You can download a template project here.
Note that, since the world is smaller in NetLogo, you need to give the stinks a shorter half-life or they'll end up all over the world.

breed [stinkers stinker]
breed [stinks stink]

to setup
  clear-all
  create-stinkers 1 [
    set color blue
    set shape "square"
    set size 2
  ]

end

to forever
  create-stinks 5 [
    set color red
    set shape "circle"
    set size 1
    set heading random 360
  ]
  
  ask stinks [
    forward 1
    left random 11
    right random 11
    ;; need a higher chance of self-destructing
    ;;  since world is smaller than in SLN
    if (random 100) < 25 [ die ]
  ]
end
2) Test your code.

You should see a stinker in the center spewing out stinks in all directions. The stinks should go a little distance before disappearing. Some will go farther than others since they have a random chance of self-destructing.

On average, there should be a higher density (concentration) closer to the stinker than far away. This is called a "concentration gradient".

3) Build a very slow-moving detector agent to detect the stink.

Create a new "detector" breed that is big enough to see clearly. Have it be born far from the center. Have it also 'meander' but have it move very slowly - give it a 75% chance of taking one step each 'tick' (this is because "forward 0.75" doesn't work).
breed [stinkers stinker]
breed [stinks stink]
breed [detectors detector]

to setup
  clear-all
  create-stinkers 1 [
    set color blue
    set shape "square"
    set size 2
  ]
  create-detectors 1 [
    set color white
    set shape "square"
    set size 2
    set xcor 12
    set ycor 12
  ]
end

to forever
  create-stinks 5 [
    set color red
    set shape "circle"
    set size 1
    set heading random 360
  ]
  
  ask stinks [
    forward 1
    left random 11
    right random 11
    ;; need a higher chance of sel-destructing
    ;;  since world is smaller than in SLN
    if (random 100) < 25 [ die ]
  ]
  
  ask detectors [
    if (random 100) <= 74 [
      forward 1
      left random 11
      right random 11
    ]
  ]
end
4) Test your code.

Your detector should meander slowly and haltingly.
5) Have the detector agent change color depending on how close it is to the 'stinker'.

The closer the detector is to the stinker, the more frequently it will be hit by stinks.

Steps:
  1. Add a new trait to the detector called "hit count".
  2. Set this hit count to 0 (zero) when the detector is born.
  3. When a detector is hit by stink, delete the stink and increase the hit count by one.
  4. Color the detector by the hit count. When hit count is less than 10, make it white; when it's 10 or higher, make it purple.
  5. Be sure that, if the detector is purple and then moves away from the stinker, it turns back white eventually.
breed [stinkers stinker]
breed [stinks stink]
breed [detectors detector]
detectors-own [hitCount]

to setup
  clear-all
  create-stinkers 1 [
    set color blue
    set shape "square"
    set size 2
  ]
  create-detectors 1 [
    set color white
    set shape "square"
    set size 2
    set xcor 12
    set ycor 12
    set hitCount 0
  ]
end

to forever
  create-stinks 5 [
    set color red
    set shape "circle"
    set size 1
    set heading random 360
  ]
  
  ask stinks [
    forward 1
    left random 11
    right random 11
    ;; need a higher chance of sel-destructing
    ;;  since world is smaller than in SLN
    if (random 100) < 25 [ die ]
  ]
  
  ask detectors [
    if (random 100) < 75 [
      forward 1
      left random 11
      right random 11
    ]
    
    ifelse hitCount > 9
    [ set color pink ]
    [ set color white ]
    
    if any? stinks in-radius 1 [
      set hitCount (hitCount + 1)
      ask one-of stinks in-radius 1 [ die ]
    ]
  ]
end

You can download a complete version of this project here.

6) Find and fix the problem with your code.

Run your code and the detector should turn purple.

But something isn't right. What is it and how can you fix it?