Life Example NetLogo Model

Produced for the book series "Artificial Intelligence";

Author: W. J. Teahan; Publisher: Ventus Publishing Aps, Denmark.

powered by NetLogo

view/download model file: Life-Example.nlogo

WHAT IS IT?

This model shows how to use some simple commands in NetLogo to simulate the life cycle of people.


THE INTERFACE

The setup button will reset the simulation to the start state when nobody is alive.

The go button will run the simulation.

The births-per-tick slider controls the number of births per tick of the simulation.

The deaths-per-tick slider controls the number of deaths per tick of the simulation.

The maximum-age slider specifies the maximum age before people die of old age.

The "count people" monitor reports the number of people currently alive.

The Population plot graphs the number of people versus tick.


HOW IT WORKS

It uses one turtle agent breed, people, that has a single variable - age. Births and deaths occur every time tick as according to the births and deaths procedures. The people turtle agents live until they are chosen randomly to die early, or until they grow too old, as according to the life procedure.


HOW TO USE IT

Select how many births and deaths you want per tick, and the maximum age, using the three sliders. Press the setup button to reset the simulation. Then press the go button to start it.


WHAT IS ITS PURPOSE?

Its purpose is to show how to define and create breeds of agents.


THINGS TO NOTICE

Notice what happens when you set the number of deaths greater than or equal to the number of births. If you do this at the start, nothing will happen. Why?

If you set the number of births to one more than the deaths at the beginning temporarily, with the maximum age set at 100, then not long afterwards while the simulation is still running try increasing the number of deaths so that it equals the number of births. Notice that the population gradually reduces until eventually it will reach an equilibrium point. Notice that it takes a long time for this to happen. Why is this?

Notice that when the number of births is set to low, it seems that the people are moving around the environment. However, this is just an illusion. There is no code in the model that makes the people turtle agents move around.


THINGS TO TRY

Try changing the values of the sliders to see what happens in the simulation.

Try changing these values as the simulation is running and observe what happens in the plot.


EXTENDING THE MODEL

Try adding further parameters to the model to make the simulation more and more like real-life.


CREDITS AND REFERENCES

To refer to this model in publications, please use:

Teahan, W. J. (2010). Life Example NetLogo model.
Artificial Intelligence. Ventus Publishing Aps.


PROCEDURES

; Life Example model.
;
; People are born, they live, then they die.
;
; Copyright 2010 William John Teahan. All Rights Reserved.
;
breed
[ people person ] ; the person breed

people-own
[
  age ; current age of the turtle
]

to setup
  clear-all
end

to go
  births
  life
  deaths

  tick
  plot count people
end

to births
; some people are born

  create-people births-per-tick
  [
    set shape "person"
    set age 0
    set size 1.5
    setxy random-xcor random-ycor
  ]
end

to life
; people live until they get too old

  ask people
  [
    set age age + 1
    if (age > maximum-age)
    [ die ]
  ]
end

to deaths
; some people die    

  repeat deaths-per-tick
  [ if (count people > 0)
      [
        ask one-of people
        [ die ]
      ]
  ]
end
;
; Copyright 2010 by William John Teahan.  All rights reserved.
;
; Permission to use, modify or redistribute this model is hereby granted,
; provided that both of the following requirements are followed:
; a) this copyright notice is included.
; b) this model will not be redistributed for profit without permission
;    from William John Teahan.
; Contact William John Teahan for appropriate licenses for redistribution for
; profit.
;
; To refer to this model in publications, please use:
;
; Teahan, W. J. (2010).  Life Example NetLogo model.
;   Artificial Intelligence. Ventus Publishing Aps
;