Helping Agents in Epidemics

No preview image

2 collaborators

Default-person Dorothy Catey (Author)
Default-person Bert Baumgaertner (Advisor)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.3 • Viewed 271 times • Downloaded 33 times • Run 0 times
Download the 'Helping Agents in Epidemics' modelDownload this modelEmbed this model

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


Comments and Questions

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

Click to Run Model

globals [
  seed

 max-infected              ;; Maximum number of agents infected at a single time point
 max-infected-time         ;; time step at which the above occurs
end -time                  ;; time step at which the number of infected = 0 (DC: redundant due to step counter already output with csv file?)
 last-susceptible          ;; number of agents who were never infected. Subtracting from population size would give number of recovered at end.
 final-epi-size            ;; number of total people who got infected throughout the epidemic (N - last-susceptible)

 total-helper-infected     ;; total number of helpers that got infected throughout epidemic
 total-normal-infected     ;; total number of non-helpers infected throughout epidemic

 total-contacts             ;; interactions for every agent
 total-contact-list         ;; list of total contacts for each time step

 r0                        ;; r0 calculated by averaging number of people one indiv infects throughout time as infected
 length-infection          ;; average length of infection for initially infected agents

]

turtles-own [
initial-infected?          ;; turtle owned marker indicating if one of the initial infected agents
help                       ;; each helper's contribution depending on surroundings and maxhelp set by user, calc at each time step for each helper, normal setting = 0
totalInfected              ;; total number agents that a turtle infected thus far
helper-surrounding         ;; keeps track of how many helpers are around each sick individual at each time step
infected-surrounding       ;; keeps track of how many infected are around each helper at each time step
finish-infected            ;; (initial infected agents) how long initial agents were sick
]

to setup
  clear-all
  set seed new-seed
  random-seed seed
  resize-world 0 world-size 0 world-size

  set final-epi-size 0
  set total-helper-infected 0
  set total-normal-infected 0
  set total-contacts 0
  set total-contact-list []
  set max-infected 0
  set max-infected-time 0
  set end-time 0
  set last-susceptible 0
  turtle-creation

  ask patches [
    set pcolor 8
    if pxcor mod 2 = 1 and pycor mod 2 = 0 [set pcolor 9.9] if pxcor mod 2 = 0 and pycor mod 2 = 1 [set pcolor 9.9]]
  ask turtles [ set pen-mode "up"]

  reset-ticks
end 

to turtle-creation
  create-turtles N-H  [                               ;; create helpers
    set shape "person"
    set color black
    setxy random-xcor random-ycor
    set initial-infected? false
    ]
  if count turtles < N [                              ;; if helpers do not make up entire population, fill rest with default
    create-turtles (N - count turtles)[               ;; could theoretically put in more helpers than N, population size would be # helpers rather than N
      set color black
      setxy random-xcor random-ycor
      set initial-infected? false
    ]
  ]
  ask n-of N-I turtles [
    set initial-infected? true                        ;; initial infected
    set color red
  ]
end 

to go
  if count turtles with [color = red] = 0 [                         ;; check to see if epidemic over, do ending measurements
end -stats
    calculate-r0
    stop]

  tracking
  contacts
  targets-calc
  move
  infection-transmission
  help-calc
  recover
  update-plots
  tick-advance 1
end 

to tracking
  if count turtles with [color = red] > max-infected [              ;; keep writing over largest number of infected
    set max-infected count turtles with [color = red]               ;; record and write over time at which maximum number of infected achieved
    set max-infected-time ticks
  ]
end 

to targets-calc
  ask turtles with [color = red] [
    set helper-surrounding count turtles with [shape = "person" and color != red] in-radius hrad      ;;if sick, count number of helpers in help radius
  ]
  ask turtles with [color != red] [                                                                   ;; don't care about number of helpers surrounding the healthy or recovered
    set helper-surrounding 0
  ]
  ask turtles with [shape = "person" and color != red] [
    set infected-surrounding count turtles with [color = red] in-radius hrad
  ]
  ask turtles with [shape != "person"] [
    set infected-surrounding 0
  ]
  ask turtles with [shape = "person" and color = red] [
    set infected-surrounding 0
  ]
end 

to contacts
  ask turtles [
    set total-contacts total-contacts + count turtles in-radius infrad
  ]
set total-contact-list lput total-contacts total-contact-list
end 

to move


 if interaction-type = "random-move" [                                                      ;; all turtles move randomly
   ask turtles [
     right (random-float 2 * 90 ) - 90
    fd 1
   ]
 ]

 if interaction-type = "helper-seek" [
   ask turtles with [shape = "person" and color = red] [                                    ;; sick helpers move randomly
     right (random-float 2 * 90 ) - 90
     fd 1
   ]

   ask turtles with [shape = "default"][                                                    ;; non-helpers move randomly
     right (random-float 2 * 90 ) - 90
     fd 1
   ]
   ask turtles with [shape = "person" and color != red][                                    ;; non-sick helpers seek the sick
    ifelse any? turtles with [color = red][
      let target min-one-of turtles with [color = red] [distance myself]                    ;; move toward nearest sick person
      face target
      fd 1
    ]
    [
      right (random-float 2 * 90 ) - 90                                                     ;; if no one is sick, move normally
      fd 1
    ]
   ]
 ]

 if interaction-type = "helper-smart-seek" [                                                ;; non-helpers move randomly
   ask turtles with [shape = "default"][
     right (random-float 2 * 90 ) - 90
     fd 1
   ]
   ask turtles with [shape = "person" and color = red] [                                    ;; sick helpers move randomly
     right (random-float 2 * 90 ) - 90
     fd 1
   ]
   ask turtles with [shape = "person" and color != red][                                    ;; non-sick helpers seek...
     ifelse any? turtles with [color = red and (helper-surrounding = 0)][
       let possible-targets turtles with [color = red]
       let targets possible-targets with [helper-surrounding = 0]
       let target min-one-of targets [distance myself]                                      ;; nearest sick agent without a helper (helper-surrounding = 0)
       face target
       fd 1
     ]
     [
       right (random-float 2 * 90 ) - 90                                                    ;; if all helpers busy or all are non-sick, move randomly
       fd 1
     ]
   ]
 ]

 if interaction-type = "infected-seek"[
   ask turtles with [shape = "default" and color != red] [                                 ;; ask normal agents to move randomly
     right (random-float 2 * 90 ) - 90
     fd 1
   ]
   ask turtles with [shape = "person" and color != red] [                                  ;; ask non-sick helpers to move randomly
     right (random-float 2 * 90 ) - 90
     fd 1
   ]
   ask turtles with [color = red] [
     ifelse any? turtles with [shape = "person" and color != red] [                        ;; ask infected to seek nearest non-sick helper
       let target min-one-of turtles with [shape = "person" and color != red] [distance myself]
       face target
       fd 1
     ]
     [
       right (random-float 2 * 90 ) - 90                                                   ;; if no non-sick helpers, move randomly
       fd 1
     ]
   ]
 ]

 if interaction-type = "infected-smart-seek" [
   ask turtles with [shape = "default" and color != red] [                                ;; ask normal non-sick agents to move randomly
     right (random-float 2 * 90 ) - 90
     fd 1
   ]
   ask turtles with [shape = "person" and color != red] [                                 ;; ask helper non-sick agents to move randomly
     right (random-float 2 * 90 ) - 90
     fd 1
   ]
   ask turtles with [color = red] [                                                       ;; ask infected to seek nearest helper who isn't already helping someone else
     ifelse any? turtles with [shape = "person" and color != red and (infected-surrounding = 0)] [
       let possible-targets turtles with [shape = "person" and color != red]
       let targets possible-targets with [infected-surrounding = 0]
       let target min-one-of targets [distance myself]
       face target
       fd 1
     ]
     [
       right (random-float 2 * 90 ) - 90                                                 ;; if no non-sick helpers free, move randomly
       fd 1
     ]
   ]
 ]

if interaction-type = "dual-smart-seek" [
  ask turtles with [shape = "default" and color != red] [                                ;; ask normal non-sick agents to move randomly
    right (random-float 2 * 90 ) - 90
    fd 1
  ]
  ask turtles with [shape = "person" and color != red][                                    ;; non-sick helpers seek...
    ifelse any? turtles with [color = red and (helper-surrounding = 0)][
      let possible-targets turtles with [color = red]
      let targets possible-targets with [helper-surrounding = 0]
      let target min-one-of targets [distance myself]                                      ;; nearest sick agent without a helper (helper-surrounding = 0)
      face target
      fd 1
    ]
    [
      right (random-float 2 * 90 ) - 90                                                    ;; if all helpers busy or all are non-sick, move randomly
      fd 1
    ]
  ]
  ask turtles with [color = red] [                                                       ;; ask infected to seek nearest helper who isn't already helping someone else
    ifelse any? turtles with [shape = "person" and color != red and (infected-surrounding = 0)] [
      let possible-targets turtles with [shape = "person" and color != red]
      let targets possible-targets with [infected-surrounding = 0]
      let target min-one-of targets [distance myself]
      face target
      fd 1
    ]
    [
      right (random-float 2 * 90 ) - 90                                                 ;; if no non-sick helpers free, move randomly
      fd 1
    ]
  ]
]
end 

to infection-transmission
  ask turtles with [color = black and shape != "person"] [                                ;; normal suceptible agents calculate prob infection based on frac infected neighbors and infect-prob
    if (random-float 1) < infect-prob * count turtles with [color = red] in-radius infrad / count turtles in-radius infrad [
        set color red
        ask turtles with [color = red] in-radius infrad [
          set totalInfected totalInfected + 1                                             ;; infected how many agents across entire infective period
        ]
    ]
  ]
  ask turtles with [color = black and shape = "person"] [                                 ;; helpers get decreased chance of infection.
    if (random-float 1) < (1 - helper-immunity) * infect-prob * count turtles with [color = red] in-radius infrad / count turtles in-radius infrad [
        set color red
        ask turtles with [color = red] in-radius infrad [
          set totalInfected totalInfected + 1                                             ;; infected how many agents across entire infective period
        ]
    ]
  ]
end 

to help-calc
  ask turtles with [shape = "person" and color != red]
  [
    ifelse any? turtles with [color = red] in-radius hrad [
       set help maxhelp / count turtles with [color = red] in-radius hrad                 ;; ideal "maxhelp" from slider, helper splits effort between sick in radius
    ]
    [
       set help 0                                                                         ;; no one to help, set help 0
    ]
  ]
end 

to recover
  ask turtles with [color = red][
    ifelse any? turtles with [shape = "person" and color != red] in-radius hrad [        ;; ask helpers for help
      let totalhelp 0
      ask turtles with [shape = "person" and color != red] in-radius hrad [
        set totalhelp totalhelp + help
        if totalhelp > maxhelp [set totalhelp maxhelp]                                   ;; if aggregate help exceeds maxhelp, set total help back to max
      ]
      if (random-float 1) < recover-prob + totalhelp [                                   ;; increased probability of recovery with help
        set color blue
        if initial-infected? [set finish-infected ticks]
      ]
    ]
    [ if (random-float 1) < recover-prob [                                               ;; probability of recovery without help
        set color blue
        if initial-infected? [set finish-infected ticks]
      ]
      ]
  ]
end 

to calculate-r0
  set r0 mean [totalInfected] of turtles with [initial-infected?]                       ;; mean number infected by individual during entire infective state
  set length-infection mean [finish-infected] of turtles with [initial-infected?]       ;; average length of infection for initially infected agents
end 

to end-stats
  set end-time ticks
  set last-susceptible count turtles with [color = black]
  set final-epi-size (N - last-susceptible)
  set total-helper-infected count turtles with [color = blue and shape = "person"]
  set total-normal-infected count turtles with [color = blue and shape = "default"]
end 

There is only one version of this model, created almost 8 years ago by Dorothy Catey.

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.