The University of Melbourne SWEN90004: Modelling Complex Software Systems Some solutions to Workshop Cx.03: Cellular Automata
1. Getting started: (no solution) 2. The SIR disease model:
(a) Version 1 – NetLogo:
Add the following code to the check-infect procedure:
if random 100 <= infect-chance
[
set infected? true
]
Add the following code to the check-recover procedure:
if random 100 <= recover-chance
[
set infected? false
set recovered? true
]
(b) Version 2 – NetLogo:
Replace the code in the go procedure that calls check-infect and check-recover with the following:
ask patches with [ infected? ]
[
check-infect
set infected-days (infected-days - 1)
if infected-days < 0
[ check-recover ]
]
ask patches with [ recovered? ]
[
set recovered-days (recovered-days - 1)
if recovered-days < 0
[ set recovered? false ]
]
1
Add the following code to the check-infect procedure: set infected? true
set infected-days random infection-duration
Add the following code to the check-recover procedure:
set infected? false
set recovered? true
set recovered-days random recovered-duration
2