Disease Alternate

No preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

biology 

Tagged by Reuven M. Lerner about 7 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 4.1pre1 • Viewed 272 times • Downloaded 27 times • Run 0 times
Download the 'Disease Alternate' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


VERSION

$Id: Disease Alternate.nlogo 39921 2008-05-13 11:37:16Z tisue $

WHAT IS IT?

This model simulates the spread of a disease through a population. This population can consist of either students, which are turtles controlled by individual students via the HubNet Client, or turtles that are generated and controlled by NetLogo, called androids, or both androids and students.

Turtles move around, possibly catching an infection. Healthy turtles on the same patch as sick turtles have a INFECTION-CHANCE chance of becoming ill. A plot shows the number of sick turtles at each time tick, and if SHOW-ILL? is on, sick turtles have a red circle attached to their shape.

Initially, all turtles are healthy. A number of turtles equal to INITIAL-NUMBER-SICK become ill when the INFECT button is depressed.

For further documentation, see the Participatory Simulations Guide found at http://ccl.northwestern.edu/ps/

HOW TO USE IT

Quickstart Instructions:

------------------------

Teacher: Follow these directions to run the HubNet activity.

Optional: Zoom In (see Tools in the Menu Bar)

Optional: Change any of the settings. If you want to add androids press the CREATE ANDROIDS button. Press the GO button.

Everyone: Open up a HubNet client on your machine and type your user name, select this activity and press ENTER.

Teacher: Have the students move their turtles around to acquaint themselves with the interface. Press the INFECT button to start the simulation.

Everyone: Watch the plot of the number infected.

Teacher: To run the activity again with the same group, stop the model by pressing the NetLogo GO button, if it is on. Change any of the settings that you would like. Press the CURE-ALL button to keep the androids, or SETUP to clear them

Teacher: Restart the simulation by pressing the NetLogo GO button again. Infect some turtles and continue.

Teacher: To start the simulation over with a new group, stop the model by pressing the GO button, if it is on, have all the students log out or press the RESET button in the Control Center, and start these instructions from the beginning

Buttons:

--------

SETUP - returns the model to the starting state, all student turtles are cured and androids are killed. The plot is advanced to start a new run but it is not cleared.

CURE-ALL - cures all turtles, androids are kept. The plot is advanced to start a new run but it is not cleared.

GO - runs the simulation

CREATE ANDROIDS - adds randomly moving turtles to the simulation

INFECT - infects INITIAL-NUMBER-SICK turtles in the simulation

NEXT >>> - shows the next quick start instruction

<<< PREVIOUS - shows the previous quick start instruction

RESET INSTRUCTIONS - shows the first quick start instruction

Sliders:

--------

NUMBER - determines how many androids are created by the CREATE ANDROIDS button

ANDROID-DELAY - the delay time, in seconds, for android movement - the higher the number, the slower the androids move

INITIAL-NUMBER-SICK - the number of turtles that become infected spontaneously when the INFECT button is pressed

INFECTION-CHANCE - sets the percentage chance that every tenth of a second a healthy turtle will become sick if it is on the same patch as an infected turtle

Switches:

---------

WANDER? - when on, the androids wander randomly. When off, they sit still

SHOW-SICK? - when on, sick turtles add to their original shape a red circle. When off, they can move through the populace unnoticed

SHOW-SICK-ON-CLIENTS? - when on, the clients will be told if their turtle is sick or not.

Monitors:

---------

TURTLES - the number of turtles in the simulation

NUMBER SICK - the number of turtles that are infected

Plots:

------

NUMBER SICK - shows the number of sick turtles versus time

Client Information

------------------

After logging in, the client interface will appear for the students, and if GO is pressed in NetLogo they will be assigned a turtle which will be described in the YOU ARE A: monitor. And their current location will be shown in the LOCATED AT: monitor. If the student doesn't like their assigned shape and/or color they can hit the CHANGE APPEARANCE button at any time to change to another random appearance.

The SICK? monitor will show one of three values: "true" "false" or "N/A". "N/A" will be shown if the NetLogo SHOW-ILL-ON-CLIENTS? switch is off, otherwise "true" will be shown if your turtle is infected, or "false" will be shown if your turtle is not infected.

The student controls the movement of their turtle with the UP, DOWN, LEFT, and RIGHT buttons and the STEP-SIZE slider. Clicking any of the directional buttons will cause their turtle to move in the respective direction a distance of STEP-SIZE.

THINGS TO NOTICE

No matter how you change the various parameters, the same basic plot shape emerges. After using the model once with the students, ask them how they think the plot will change if you alter a parameter. Altering the initial percentage sick and the infection chance will have different effects on the plot.

THINGS TO TRY

Use the model with the entire class to serve as an introduction to the topic. Then have students use the NetLogo model individually, in a computer lab, to explore the effects of the various parameters. Discuss what they find, observe, and can conclude from this model.

EXTENDING THE MODEL

Currently, the turtles remain sick once they're infected. How would the shape of the plot change if turtles eventually healed? If, after healing, they were immune to the disease, or could still spread the disease, how would the dynamics be altered?

CREDITS AND REFERENCES

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Variable and Breed declarations ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

globals
[
  ;; variables related to the health of the turtles
  old-num-infected          ;; number of turtles that had infected? = true during the last pass through the go procedure
  clock        ;; keeps track of the number of times through the go procedure (if there is at least one turtle infected)
  run-number

  ;; variables used to assign unique color and shape to clients
  shape-names        ;; list that holds the names of the non-sick shapes a student's turtle can have
  colors             ;; list that holds the colors used for students' turtles
  color-names        ;; list that holds the names of the colors used for students' turtles
  used-shape-colors  ;; list that holds the shape-color pairs that are already being used
  max-possible-codes ;; total number of possible unique shape/color combinations
  old-vision-radius
  old-sick-status-visibility
]

turtles-own
[
  infected?    ;; if a turtle is sick, infected? is true, otherwise, it is false
  base-shape   ;; original shape of a turtle
  step-size    ;; the amount that a turtle will go forward in the current direction
]

breed [ androids android ]  ;; created by the CREATE ANDROIDS button; not controlled by anyone, but can become sick and spread sickness
breed [ students student ]  ;; created and controlled by the clients

students-own
[
  user-id  ;; unique id, input by the client when they log in, to identify each student turtle
]


;;;;;;;;;;;;;;;;;;;;;;
;; Setup Procedures ;;
;;;;;;;;;;;;;;;;;;;;;;

to startup
  hubnet-set-client-interface "COMPUTER" []
  hubnet-reset
  setup-vars
  setup-plot
  set old-sick-status-visibility sick-status-visibility
end 

to setup
  reset-ticks
  ask androids [ die ]
  cure-all
  set old-vision-radius vision-radius
end 

;; heals all sick turtles,  clears and sets up the plot,
;; and clears the lists sent to the calculators

to cure-all
  set clock 0
  ask turtles
  [
    set infected? false
    set shape base-shape
  ]

  set old-num-infected 0
  set run-number run-number + 1
  setup-plot
end 

;; initialize global variables

to setup-vars
  set clock 0
  set old-num-infected 0

  set shape-names ["box" "star" "wheel" "target" "cat" "dog"
                   "butterfly" "leaf" "car" "airplane"
                   "monster" "key" "cow skull" "ghost"
                   "cactus" "moon" "heart"]
  ;; these colors were chosen with the goal of having colors
  ;; that are readily distinguishable from each other, and that
  ;; have names that everyone knows (e.g. no "cyan"!), and that
  ;; contrast sufficiently with the red infection dots and the
  ;; gray androids
  set colors      (list white brown green yellow
                        (violet + 1) (sky + 1))
  set color-names ["white" "brown" "green" "yellow"
                   "purple" "blue"]
  set max-possible-codes (length colors * length shape-names)
  set used-shape-colors []
  set run-number 1
end 

;; create a temporary plot pen for the current run
;; cycle through a few colors so it is easy to
;; differentiate the runs.

to setup-plot
  create-temporary-plot-pen word "run " run-number
  set-plot-pen-color item (run-number mod 5)
                          [blue red green orange violet]
end 

;; creates turtles that wander at random

to make-androids
  create-androids number
  [
    move-to one-of patches
    face one-of neighbors4
    set color gray
    set infected? false
    set base-shape "android"
    set shape base-shape
    set step-size 1
    if sick-status-visibility = "clients see their own sickness"
    [
      ask students [ hubnet-send-override user-id myself "shape" [base-shape] ]
    ]
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;
;; Runtime Procedures ;;
;;;;;;;;;;;;;;;;;;;;;;;;

to go
  every 0.1
  [
    ;; get commands and data from the clients
    listen-clients

    ;;allow the androids to wander around the view
    if wander?
    [ androids-wander ]

    ask turtles with [ infected? ]
    [ spread-disease ]

    ;; increment the clock if there are infected turtles and plot the data
    let current-infected count turtles with [infected?]
    if current-infected > 0 and current-infected > old-num-infected
    [
      ;; plot the new data
      plotxy clock current-infected
      set old-num-infected current-infected
    ]
    if current-infected > 0
    [ set clock clock + 1 ]
    tick
  ]
  if old-vision-radius != vision-radius
  [ 
    ask turtles [ hubnet-send-follow user-id self vision-radius ]
    set old-vision-radius vision-radius
  ]
  if not (old-sick-status-visibility = sick-status-visibility)
  [
    ifelse sick-status-visibility = "no one sees sickness"
    [
      ask turtles [ set shape base-shape ]
    ]
    [
      ask turtles with [infected?] [ set-sick-shape ]
      ifelse sick-status-visibility = "clients see their own sickness"
      [ 
        ask students
          [ hubnet-send-override user-id other turtles "shape" [base-shape] ]
      ]
      [
        ask students
          [ hubnet-clear-overrides user-id ]
      ]
    ]
    set old-sick-status-visibility sick-status-visibility
  ]
end 

;; controls the motion of the androids

to androids-wander
  every android-delay
  [
    ask androids
    [
      face one-of neighbors4
      fd 1
    ]
  ]
end 

;; additional check infect called when student moves to new patch
;; added to avoid rewarding movement

to student-move-check-infect
  if infected?
  [ spread-disease ]

  ask other turtles-here with [ infected? ]
  [ ask myself [ maybe-get-sick ] ]
end 

;; spread disease to other turtles here

to spread-disease
  ask other turtles-here [ maybe-get-sick ]
end 


;; turtle procedure -- roll the dice and maybe get sick

to maybe-get-sick
  if not infected? [
    if ((random 100) + 1) <= infection-chance
    [ get-sick ] ]
end 

;; turtle procedure -- set the appropriate variables to make this turtle sick

to get-sick
  set infected? true
  set-sick-shape
end 

;; turtle procedure -- change the shape of turtles to its sick shape
;; if show-sick? is true and change the shape to the base-shape if
;; show-sick? is false

to set-sick-shape
  ifelse not (sick-status-visibility = "no one sees sickness")
  [   
    ;; we want to check if the turtles shape is already a sick shape
    ;; to prevent flickering in the turtles
    if shape != word base-shape " sick"
    [ set shape word base-shape " sick" ]
  ]
  [
    ;; we want to check if the turtles shape is already a base-shape
    ;; to prevent flickering in the turtles
    if shape != base-shape
    [ set shape base-shape ]
  ]
end 

;; causes the initial infection in the turtle population --
;; infects a random healthy turtle until the desired number of
;; turtles are infected

to infect-turtles
  let healthy-turtles turtles with [ not infected? ]

  ifelse count healthy-turtles < initial-number-sick
  [
    ask healthy-turtles
    [
      get-sick
      set-sick-shape
    ]
    user-message "There are no more healthy turtles to infect.  Infection stopped."
    stop
  ]
  [
    ask n-of initial-number-sick healthy-turtles
    [
      get-sick
      set-sick-shape
    ]
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;
;; HubNet Procedures ;;
;;;;;;;;;;;;;;;;;;;;;;;

;; determines which client sent a command, and what the command was

to listen-clients
  while [ hubnet-message-waiting? ]
  [
    hubnet-fetch-message
    ifelse hubnet-enter-message?
    [ create-new-student ]
    [
      ifelse hubnet-exit-message?
      [ remove-student ]
      [
        ask students with [ user-id = hubnet-message-source ]
          [ execute-command hubnet-message-tag ]
      ]
    ]
  ]
end 

;; NetLogo knows what each student turtle is supposed to be
;; doing based on the tag sent by the node:
;; step-size - set the turtle's step-size
;; Up    - make the turtle move up by step-size
;; Down  - make the turtle move down by step-size
;; Right - make the turtle move right by step-size
;; Left  - make the turtle move left by step-size
;; Get a Different Turtle - change the turtle's shape and color

to execute-command [command]
  if command = "step-size"
  [
    set step-size hubnet-message
    stop
  ]
  if command = "Up"
  [ execute-move 0 stop ]
  if command = "Down"
  [ execute-move 180 stop ]
  if command = "Right"
  [ execute-move 90 stop ]
  if command = "Left"
  [ execute-move 270 stop ]
  if command = "Change Appearance"
  [ execute-change-turtle stop ]
end 

;; Create a turtle, set its shape, color, and position
;; and tell the node what its turtle looks like and where it is

to create-new-student
  create-students 1
  [
    setup-student-vars
    send-info-to-clients
    ;; we want to make sure that the clients all have the same plot ranges,
    ;; so when somebody logs in, set the plot ranges to themselves so that
    ;; everybody will have the same size plots.
    set-plot-y-range plot-y-min plot-y-max
    set-plot-x-range plot-x-min plot-x-max
    hubnet-send-follow user-id self vision-radius
    if sick-status-visibility = "clients see their own sickness"
    [
      hubnet-send-override user-id other turtles "shape" [base-shape]
      ask other students [ hubnet-send-override user-id myself "shape" [base-shape] ]
    ]
  ]
end 

;; sets the turtle variables to appropriate initial values

to setup-student-vars  ;; turtle procedure
  set user-id hubnet-message-source
  set-unique-shape-and-color
  move-to one-of patches
  face one-of neighbors4
  set infected? false
  set step-size 1
end 

;; pick a base-shape and color for the turtle

to set-unique-shape-and-color
  let code random max-possible-codes
  while [member? code used-shape-colors and count students < max-possible-codes]
  [
    set code random max-possible-codes
  ]
  set used-shape-colors (lput code used-shape-colors)
  set base-shape item (code mod length shape-names) shape-names
  set shape base-shape
  set color item (code / length shape-names) colors
end 

;; report the string version of the turtle's color

to-report color-string [color-value]
  report item (position color-value colors) color-names
end 

;; sends the appropriate monitor information back to the client

to send-info-to-clients
  hubnet-send user-id "You are a:" (word (color-string color) " " base-shape)
  hubnet-send user-id "Located at:" (word "(" pxcor "," pycor ")")  
end 

;; Kill the turtle, set its shape, color, and position
;; and tell the node what its turtle looks like and where it is

to remove-student
  ask students with [user-id = hubnet-message-source]
  [
    set used-shape-colors remove my-code used-shape-colors
    die
  ]
end 

;; translates a student turtle's shape and color into a code

to-report my-code
  report (position base-shape shape-names) + (length shape-names) * (position color colors)
end 

;; Cause the students to move forward step-size in new-heading's heading

to execute-move [new-heading]
  set heading new-heading
  fd step-size
  hubnet-send user-id "Located at:" (word "(" pxcor "," pycor ")")

  ;; maybe infect or get infected by turtles on the patch student moved to
  student-move-check-infect
end 

to execute-change-turtle
  ask students with [user-id = hubnet-message-source]
  [
    set used-shape-colors remove my-code used-shape-colors
    show-turtle
    set-unique-shape-and-color
    hubnet-send user-id "You are a:" (word (color-string color) " " base-shape)
    if infected?
    [ set-sick-shape ]
  ]
end 

;;; this procedure is handy for testing out additional shapes and colors;
;;; you can call it from the Command Center

to show-gamut
  ca
  setup-vars
  create-ordered-turtles max-possible-codes [
    fd max-pxcor * 0.7
    if who mod 3 = 0
      [ fd max-pxcor * 0.3 ]
    if who mod 3 = 1
      [ fd max-pxcor * 0.15 ]
    set heading 0
    set-unique-shape-and-color
  ]
  ask patch 0 0 [
    ask patches in-radius 2 [
      sprout-androids 1 [
        set shape "android"
        set color gray
      ]
    ]
  ]
  user-message (word length shape-names
              " shapes * "
              length colors
              " colors = "
              max-possible-codes
              " combinations")
end 

There are 2 versions of this model.

Uploaded by When Description Download
Uri Wilensky about 10 years ago Disease Alternate Download this version
Uri Wilensky about 10 years ago Disease Alternate Download this version

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.