Infection Dynamics - Practice
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
This simulation helps explore how an infection spreads, recovers, reinfects, and how doctors and hospitals can influence the outcome. It is designed as a self-learning tool for understanding real-world infection dynamics and system behavior.
HOW IT WORKS
In this simulation, a small population of turtles moves around a virtual world, where the spread of infection plays out dynamically. At the start, most turtles are healthy (blue), but a few begin infected (red). As they move, infected turtles can transmit the illness to nearby healthy ones. Some infected turtles are programmed to seek care in a designated hospital area, marked with a large pink “H.” However, hospital capacity is limited, so only a few can be treated at a time. Once inside, turtles stay locked in until they recover, which happens faster than in the outside environment.
Doctors, colored orange and labeled “Doctor,” roam the world searching for infected turtles. When they find one within range, they administer care that helps the turtle recover and turn green. Recovered turtles are not immune forever — after some time, they may lose immunity, flash cyan with a “Lost Immunity” label, and become susceptible to infection again.
HOW TO USE IT
(how to use the model, including a description of each of the items in the Interface tab)
THINGS TO NOTICE
(suggested things for the user to notice while running the model)
THINGS TO TRY
(suggested things for the user to try to do (move sliders, switches, etc.) with the model)
EXTENDING THE MODEL
(suggested things to add or change in the Code tab to make the model more complicated, detailed, accurate, etc.)
NETLOGO FEATURES
(interesting or unusual features of NetLogo that the model uses, particularly in the Code tab; or where workarounds were needed for missing features)
RELATED MODELS
(models in the NetLogo Models Library and elsewhere which are of related interest)
CREDITS AND REFERENCES
(a reference to the model's URL on the web if it has one, as well as any other necessary credits, citations, and links)
Comments and Questions
globals [ trail_count total_infected max_infected total_healed_by_doctors hospital_capacity ] turtles-own [ infected_time recovered_time reinfected? reinfected_for in_hospital_lock? will_go_to_hospital? ] breed [doctors doctor] to-report in_hospital? report [pcolor] of patch-here = pink end to setup clear-all set trail_count 0 set total_infected 1 set max_infected 1 set total_healed_by_doctors 0 set hospital_capacity 5 ask patches [ set pcolor blue + 4.9] ; set hospital zone ask patches with [ pxcor > max-pxcor - 5 and pycor > max-pycor - 5] [set pcolor pink ] ; Mark hospital area with a big H ask patches with [ pxcor > max-pxcor - 3 and pxcor < max-pxcor - 1 and pycor > max-pycor - 3 and pycor < max-pycor - 1 ] [ set plabel "H" set plabel-color black ] create-turtles 30 [ setxy random-xcor random-ycor set color blue set infected_time 0 set recovered_time 0 set reinfected? false set reinfected_for 0 set in_hospital_lock? false set will_go_to_hospital? false ] ask n-of 5 turtles [ set color red set infected_time 1 ] create-doctors 2 [ setxy random-xcor random-ycor set color orange + 1 set size 1.3 set label "Doctor" set label-color black ] reset-ticks end to go ;main turtle logic ask turtles with [not member? self doctors ] [ ;infection logic if color = red [ let nearby-turtles turtles in-radius 1 with [color = blue] ask nearby-turtles [ set color red set infected_time 0 set total_infected total_infected + 1 set will_go_to_hospital? (random-float 1.0 < 0.2) ] ] ;Recovery logic set infected_time infected_time + 1 if in_hospital? [ set infected_time infected_time + 2 ] ; faster recovery in hospital if infected_time > recovery_time and color = red [ set color green set recovered_time 0 set in_hospital_lock? false ] ;Reinfection logic if color = green [ set recovered_time recovered_time + 1 if recovered_time > reinfection_delay and not reinfected? [ set color cyan ; flash color to highlight reinfection set label "Lost Immunity" ; showing label set label-color black set reinfected? true set reinfected_for 25 ; flash will last for 25 ticks set size 2 ; make the turtle stand out ] ] ; maintain flash for a few ticks if reinfected? and reinfected_for > 0 [ set reinfected_for reinfected_for - 1 ] ; end flash, reset to blue if reinfected? and reinfected_for = 0 [ set color blue set infected_time 0 set label "" set reinfected? false set size 1 ; reset to previous size ] ; hospital entry logic if color = red and will_go_to_hospital? and not in_hospital? and not in_hospital_lock? [ if xcor = max-pxcor - 5 and ycor >= max-pycor - 5 [ if count turtles with [ color = red and in_hospital_lock? ] < hospital_capacity [ facexy max-pxcor - 3 max-pycor - 3 forward 1 ] ] ] ; lock turtle when it get inside hospital if color = red and in_hospital? and will_go_to_hospital? and not in_hospital_lock? [ if count turtles with [color = red and in_hospital_lock?] < hospital_capacity [ set in_hospital_lock? true ] ] ; lock movement if inside hospital and infected if in_hospital_lock? [ if not in_hospital? [ facexy max-pxcor - 3 max-pycor - 3 forward 1 ] ] ; block healthy turtles from entering hospital if (color != red and in_hospital?) [ rt 180 forward 1 ] ;movement logic forward movement_speed rt random 50 lt random 50 if color = green and in_hospital? [ rt 180 forward 1 ] ] ;update max infected count let current_infected count turtles with [color = red ] if current_infected > max_infected [ set max_infected current_infected ] ; Doctors logic ask doctors [ let nearby_infected turtles in-radius 1 with [color = red] ask nearby_infected [ set color green set total_healed_by_doctors total_healed_by_doctors + 1 ] ; doctor movement forward 1 rt random 30 lt random 30 ] tick end
There is only one version of this model, created 2 months ago by Mohammad Mustafa.
Attached files
No files
This model does not have any ancestors.
This model does not have any descendants.