Virus Spread with Hospital Capacities of Hospital Beds, Medics and Medicines

Virus Spread with Hospital Capacities of Hospital Beds, Medics and Medicines preview image

1 collaborator

Air_avatar Alfredo Ramirez (Author)

Tags

virus-spread, hospital-capacity 

Tagged by Alfredo Ramirez about 1 month ago

Visible to everyone | Changeable by the author
Model was written in NetLogo 6.4.0 • Viewed 78 times • Downloaded 9 times • Run 0 times
Download the 'Virus Spread with Hospital Capacities of Hospital Beds, Medics and Medicines' modelDownload this modelEmbed this model

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


Info tab cannot be displayed because of an encoding error

Comments and Questions

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

Click to Run Model

;; 100 ticks = 1 day
globals[
  pop-susceptible       ; counts susceptible population
  pop-infected          ; counts infected population
  pop-recovered         ; counts recovered population
  pop-deceased          ; counts deceased population
  pop-density           ; population density
  time-infection        ; number of ticks that persons remains infected
  kapa                  ; percentage of deceased
  seconds               ; used for execution time
  normal-speed          ; normal agents' speed
  high-speed            ; when an agent is infected it's urgent to arrive to hospital
  time-revision         ; ticks needed to check agents at hospital
  days-hospitalized     ; ticks convesrion to days to calculate medicines per day at hospital
  dead-possibility      ; random posibility to compare with kapa
  ; values for increasing-decreasing chance-of-dead
  lgm   ; low getting medicine
  hh    ; high hospitalized
  hdm   ; high daily medicine
  hgm   ; high getting medicine
  daily-increase ; if not getting treatment will increase chance-of-dead daily
  p-deceased    ; percentage of deceased
  p-recovered   ; percentage of recovered
  p-susceptible ; percentage of not infected
  acc-infected          ; infected population accumulator
]

breed [persons person]  ; principal agents that represent persons
breed [units unit]      ; agents that represents hospital units
breed [banners banner]  ; simple label to identify hospital units

; specification for persons
persons-own[
  status                ; susceptible, infected, recovered or deceased
  ticks-infected        ; time in ticks that agent is infected
  severity              ; 0 (low) - not require hospitalization; 1 (mid) - requires revision at hospital; 2 (high) - requires hospitalization
  chance-of-dead        ; increase when not getting attention or hospitalization or medicines
  p-mobility            ; speed of agent's mobility
  h-target              ; hospital where agent will be attended
  attended              ; status of attention
  time-at-unit          ; time spent at hospital
  days-at-unit          ; days at hospital
  received-medicine     ; status of received medicines
]

; specification for hospital units
units-own [
  u-beds        ; number of beds available
  u-medics      ; number of medics available
  u-medicines   ; number of medicines available
]

to setup
  ca
  reset-ticks
  reset-timer

  ; initialize values
  set pop-susceptible population - 1
  set pop-infected 0
  set pop-recovered 0
  set pop-deceased 0
  set pop-density (population / (world-height * world-width) )
  set acc-infected 0

  set time-infection 210      ; 21 days of infection
  set kapa 0.15               ; 15% of total infected people will die
  set normal-speed 0.5
  set high-speed 1

  set time-revision 10        ; ticks needed to check a person at hospital
  set days-hospitalized 20    ; max of days that a person can be hospitalized

  set	lgm	 0.3
  set	hh	 0.5
  set	hdm	 0.8
  set	hgm	 0.5
  set daily-increase 0.05

  ask patches[
    set pcolor white
  ]

  ; person initialize
  create-persons population[
    move-to one-of (patches with [not any? turtles-here])   ; initial position, ensure that two persons don't use same patch

    set status "susceptible"          ; all agents are suceptible
    set ticks-infected 0              ; counts how many ticks person is infected
    set severity 0                    ; not used until agents gets infected
    set chance-of-dead 0              ; not used until agents gets infected
    set p-mobility normal-speed       ; agent moves at normal speed
    set h-target nobody               ; while not infected, agent is not looking hospital
    set attended 0                    ; when receives attention at hospital it could take values: 1, 2, 3 or 4 used for statistical info
    set time-at-unit 0                ; count how many ticks agent is at hospital unit receiving attention
    set days-at-unit 0                ; count how many days agent is hospitalized
    set received-medicine 0           ; not need medicine so far
    update-status                     ; updates color and shape
  ]

  ; calculus for position hospital units in a polygon vertex, so they don't render closer to another
  let radius ( world-width / 2.5 )
  let angle ( 360 / hospitals )
  let rotation random 360

  ; initialize hospital units
  create-units hospitals [
    set shape "hospital2"
    set size 2
    set color cyan
    set u-beds beds                   ; beds defined by slider
    set u-medics medics               ; medics defined by slider calculated as follows medics for shift: 10 at morning, 10 at evening 5 at night
    set u-medicines medicines         ; number of treatments a hospital can provide, 1 per consultation and 1 per day at hospital
    ; calculations to move the hospital to a polygon vertex
    let x ( radius * sin ((who - hospitals) * angle) )
    let y ( radius * cos ((who - hospitals) * angle) )
    let xn ( x * cos(rotation) - y * sin(rotation) )
    let yn ( y * cos(rotation) + x * sin(rotation) )
    setxy xn yn
    ; set the label under the icon
    set label-color [ 0 0 0 128 ]               ; label in black color with 50% transparency
    attach-banner who ( xn + 1 ) ( yn - 1.7 )   ; label sets the id of agent
  ]

  ; initialize the first infected person
  ask one-of persons [
    set status "infected"
    set ticks-infected 1                ; tick 1 of infection
    set pop-infected (pop-infected + 1) ; update count of infected population
    set severity 0                      ; always initialize with the lower severity
    set chance-of-dead 1                ; normal chance, depends of posibility determined by kapa
    update-status
  ]
end 

to go
  if all? persons [ status != "infected" ] [       ; stops simulation when infected people is 0
    ifelse pop-recovered = 1 [
      output-print "Not enough infections. Run again!"
    ][
      set p-susceptible ( pop-susceptible / population ) * 100
      set p-deceased ( pop-deceased / acc-infected ) * 100
      set p-recovered ( pop-recovered / population ) * 100
      output-print word "Percentage of Not infected   = " word ( precision p-susceptible 2 ) "%"
      output-print word "Percentage of Decease        = " word ( precision p-deceased 2 ) "%"
      output-print word "Percentage of Recovered      = " word ( precision p-recovered 2 ) "%"
    ]
    stop
  ]

  ; main process, checks mobility of agents, infection and hospitals consuming
  ask persons with [ status != "deceased"] [
    ; if not infected agent is not looking for hospital and moves normally
    ifelse h-target = nobody [
      rt random 20
      lt random 20
    ][
      ; in case that agent is assigned to an hospital
      ; check if agent has arrived to hospital and stops moving
      if any? units-on patch-ahead 1 [
        set p-mobility 0

        ; actions for agents with severity = 1 (med)
        if severity = 1 [
          if attended = 0 [                                     ; check if agent has no received attention
            ask h-target [
              ifelse u-medics > 0 [                             ; check if there are medics available
                set u-medics ( u-medics - 1)                    ; assigns medic
                ask myself [
                  set attended 1                                ; agent is attended (for medical consultation)
                ]
              ][
                ask myself [
                  set h-target nobody                           ; if not medics available, agent leaves hospital
                  set p-mobility normal-speed                   ; and change to normal speed moving
                  set attended 2                                ; agent didn't receive attention (for medical consultation)
                  set received-medicine 3                       ; not getting medicines by insufficient medics
                ]
              ]
            ]
          ]
          if attended = 1 [                                     ; if agents is attended
            set time-at-unit ( time-at-unit + 1 )               ; counts how many ticks is at consultation
            if time-at-unit > time-revision [                   ; when consultation ends medics is reasigned to hospital
              ask h-target [
                set u-medics ( u-medics + 1 )
                ifelse u-medicines > 0 [                        ; if there are medicines available agents gets one
                  set u-medicines ( u-medicines - 1 )
                  ask myself [
                    set received-medicine 1                     ; getting medicines
                    set chance-of-dead ( chance-of-dead * lgm ) ; chance of dead decreased, lgm
                  ]
                ][
                  ask myself [
                    set received-medicine 2                     ; not getting medicines by insufficient stock
                  ]
                ]
              ]
              set h-target nobody                               ; when agent gets attended, no more looking for unit
              set p-mobility normal-speed
            ]
          ]
          update-status
        ]

        ; actions for agents with severity = 2 (high)
        if severity = 2 [
          if attended = 0 [
            ask h-target [
              ifelse u-medics > 0 [
                set u-medics ( u-medics - 1)
                ask myself [
                  set attended 1                                ; agent is attended (for medical consultation)
                ]
              ][
                ask myself [
                  set h-target nobody
                  set p-mobility normal-speed
                  set attended 2                                ; agent didn't receive attention (for medical consultation)
                  set received-medicine 3                       ; not getting medicines by insufficient medics
                ]
              ]
            ]
          ]
          if attended = 1 [
            set time-at-unit ( time-at-unit + 1 )
            if time-at-unit > time-revision [                       ; if medical consultation is finished, free medics and check if it can be hospitalized
              ask h-target [
                set u-medics ( u-medics + 1 )
                ifelse u-beds > 0 [                                 ; if bed is available then is assigned to agent and decreased from count
                  set u-beds ( u-beds - 1)
                  ask myself [
                    set attended 3                                  ; agent is hospitalized
                    set chance-of-dead ( chance-of-dead * hh )     ; chance of dead decreased, hh
                  ]
                ][
                  ask myself [
                    set attended 4                                  ; agents isn't hospitalized
                    ;set chance-of-dead ( chance-of-dead * hnh )     ; chance of dead increased, hnh
                    ask h-target [
                      ifelse u-medicines > 0 [                        ; if there are medicines available agents gets one
                        set u-medicines ( u-medicines - 1 )
                        ask myself [
                          set received-medicine 1                     ; getting medicines
                          set chance-of-dead ( chance-of-dead * hgm ) ; chance of dead decreased, hgm
                        ]
                      ][
                        ask myself [
                          set received-medicine 4                     ; not getting medicines by insufficient beds
                        ]
                      ]
                    ]
                    set h-target nobody                             ; if there is not beds, agent leaves hospital
                    set p-mobility normal-speed
                  ]
                ]
              ]
            ]
          ]
          if attended = 3 [                                     ; if agent is hospitalized, count days
            set time-at-unit ( time-at-unit + 1 )
            if time-at-unit > 10 [                              ; if times count 10, a day has passed and medicine is given to agent, if available
              set days-at-unit ( days-at-unit + 1 )
              set time-at-unit 0
              ask h-target [
                ifelse u-medicines > 0 [
                  set u-medicines ( u-medicines - 1 )
                  ask myself [
                    set received-medicine 1                     ; getting medicines
                    set chance-of-dead ( chance-of-dead * hdm ) ; chance of dead decreased every day getting medicines, hdm
                  ]
                ][
                  ask myself [
                    set received-medicine 2                     ; not getting medicines by insufficiente stock
                  ]
                ]
              ]
            ]
          ]
          update-status
        ]
      ]
    ]

    fd p-mobility                                           ; move agent based on speed calculated in above actions
  ]



  ; infect other agents
  ask persons with [ status = "infected" ][
    let nb (other persons) in-radius 0.1 with [ status = "susceptible" ]      ; check for agents nearby with susceptible status and infect them
    if nb != nobody[
      ask nb [
        set status "infected"
        set pop-infected (pop-infected + 1)                                   ; update count for infected population
        set acc-infected (acc-infected + 1)                                   ; accumulates infected population
        set pop-susceptible (pop-susceptible - 1)                             ; update count for susceptible population
        set severity random 3                                                 ; assign a random severity
        if severity = 0 [
          set chance-of-dead 1                                                ; basic dead rate, death depends totally by kapa
        ]
        if severity != 0 [
          set h-target one-of units                                           ; if severity is med or high then look for an hospital
          face h-target                                                       ; set direction toward hospital
        ]
        if severity = 1 [
          set chance-of-dead 1.25                                             ; chance of dead increased by severity in 25%, based on basic death rate = 1
        ]
        if severity = 2 [
          set p-mobility high-speed                                           ; if severity is high, speed up agent movility
          set chance-of-dead 1.5                                              ; chance of dead increased by severity in 50%, based on basic death rate = 1
        ]
        update-status
      ]
    ]
    if ( attended = 2 ) or ( attended = 4 ) or ( received-medicine != 1 )[
      set chance-of-dead ( chance-of-dead + chance-of-dead * daily-increase ) ; increase daily if not hospitalized or getting treatment
    ]
    set ticks-infected (ticks-infected + 1)                                   ; increase count of ticks infected
  ]

  ; check for recovered or decesased agents
  ask persons with [ status = "infected" ][
    if ticks-infected > time-infection [                                      ; check if time of infection has reached to end
      set dead-possibility random-float 1                                      ; calculate if agent will die or not, based on kapa value
      ifelse severity = 0 [                                                   ; if severity is low, agent gets recovered
        set status "recovered"
        set pop-recovered (pop-recovered + 1)
        set p-mobility normal-speed
        set h-target nobody
      ][
        if attended = 3 [                                                     ; if agent was hospitilized, free the bed
          ask h-target [
            set u-beds ( u-beds + 1 )
          ]
        ]
        ifelse dead-possibility <= ( kapa * chance-of-dead ) [                 ; agent dies if dead-posibility is between 0 an kapa, chance-of-dead increments posibility
          set status "deceased"
          set pop-deceased (pop-deceased + 1)
        ][
          set status "recovered"
          set pop-recovered (pop-recovered + 1)
          set p-mobility normal-speed
          set h-target nobody
        ]
      ]
      set pop-infected (pop-infected - 1)
      update-status
    ]
  ]

  tick
  set seconds timer
end 

; update shape and color by condition of agent
; normal agent                                = gray circle not filled
; infected low severity                       = yellow circle filled
; infected mid severity looking hospital      = red arrow filled
; infected mid severity attended              = red circle filled
; infected mid severity not attended          = red circle not filled
; infected hihg severity looking hospital     = maroon arrow filled
; infected hihg severity attended             = maroon circle filled
; infected hihg severity not attended         = maroon circle not filled
; infected hihg severity hospitalized         = maroon star
; infected hihg severity not hospitalized     = maroon x
; recovered agent                             = green +
; deceased agent                              = blue x

to update-status
  (ifelse
    status = "susceptible"
    [
      set color gray + 2
      set size 0.6
      set shape "circle 3"
    ]
    status = "infected"
    [
      (ifelse
        severity = 0 [
          set size 0.6
          set shape "circle 4"
          set color [255 145 0]
        ]
        severity = 1 [
          set color [255 0 0]
          (ifelse
            attended = 0 [
              set size 0.8
              set shape "navigation"
            ]
            attended = 1 [
              set size 0.6
              set shape "circle 4"
            ]
            attended = 2 [
              set size 0.6
              set shape "circle 3"
            ]
          )
        ]
        severity = 2 [
          set color [155 15 15]
          (ifelse
            attended = 0 [
              set size 0.8
              set shape "navigation"
            ]
            attended = 1 [
              set size 0.6
              set shape "circle 4"
            ]
            attended = 2 [
              set size 0.6
              set shape "circle 3"
            ]
            attended = 3 [
              set size 0.9
              set shape "star"
            ]
            attended = 4 [
              set size 0.8
              set shape "x"
            ]
          )
        ]
      )
    ]
    status = "recovered"
    [
      set color [21 176 26]
      set size 0.6
      set shape "cross"
    ]
    status = "deceased"
    [
      set color [0 0 255]
      set size 0.7
      set shape "x"
    ]
  )
end 

; function to place label

to attach-banner [lbl lx ly]
  hatch-banners 1 [
    set size 0
    set label lbl
    setxy lx ly
    create-link-from myself [
      tie
      hide-link
    ]
  ]
end 

There are 3 versions of this model.

Uploaded by When Description Download
Alfredo Ramirez 23 days ago Updated Info Tab Download this version
Alfredo Ramirez 27 days ago Percentage of deceased people recalculated, based only in infected people. Download this version
Alfredo Ramirez about 1 month ago Initial upload Download this version

Attached files

File Type Description Last updated
Virus Spread with Hospital Capacities of Hospital Beds, Medics and Medicines.png preview Preview for 'Virus Spread with Hospital Capacities of Hospital Beds, Medics and Medicines' about 1 month ago, by Alfredo Ramirez Download

This model does not have any ancestors.

This model does not have any descendants.