-
Notifications
You must be signed in to change notification settings - Fork 4
/
Covid19VO.nlogo
2316 lines (2093 loc) · 60.1 KB
/
Covid19VO.nlogo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
__includes ["DiseaseConfig.nls" "output.nls" "SocialNetwork.nls" "layout.nls" "scotland.nls" "work_distribution.nls" ]
extensions [csv table]
undirected-link-breed [households household]
undirected-link-breed [relations relation] ;; Relatives who don't live in the same household
undirected-link-breed [friendships friendship]
undirected-link-breed [tracings tracing] ;; The contact tracing app
undirected-link-breed [wps wp] ;; workplaces
globals
[
rnd ;; Random seed
b
c
fq
use-existing-nw?
show-layout
testing-today
testing-tomorrow
;; Behaviour
compliance-adjustment
high-prob-isolating
low-prob-isolating
;; Counters
N-people
tests-remaining
tests-per-day
tests-performed
tests-today
hospital-beds ;; Number of places in the hospital (currently unused)
counters ;; Table containing information on source of infection e.g household, friends...
populations ;;
cumulatives ;; table of cumulative disease states
infections ;; table containing the average number of infections of people recovered or dead in the past week
all-infections
placecnt ;;table of size of neigh and prop of young
cum-infected
workplaces ;;table of agents by work-id
;; Reproduction rate
beta-n ;; The average number of new secondary infections per infected this tick
gamma ;; The average number of new recoveries per infected this tick
s0 ;; Initial number of susceptibles
r0 ;; The number of secondary infections that arise due to a single infective introduced in a wholly susceptible population
k0 ;; K value: clustering of spreading events (variance to mean)
rtime
nb-infected ;; Number of secondary infections caused by an infected person at the end of the tick
nb-infected-previous
nb-recovered ;; Number of recovered people at the end of the tick
;; Interventions
lockdown? ;; If true we are in a state of lockdown
contact-tracing ;; If true a contact tracing app exists
app-initalize? ;; If the app was distributed to agents
howmanyrnd ;; Number of random people we meet
howmanyelder ;; Number of random people (> 67 y.o.) we meet
;; agent-sets
seniors
schoolkids
adults
working-age-agents
workers ;;people working in "offices"
crowd-workers ;; people working with crowd
school ;; Table of classes and pupils
place ;; Table of neighbourhoods and their residents ;;
work-place ;list of work place size
double-t
flu-symp ;;number of agents with flu-symptomas that will try to get tested for covid19
ratio-flu-covid ;; ration between covid and flu
tested-positive ;;number of agents tested as positive
wardmap ;; pcode - ward lookup table
]
turtles-own
[
sex
age
age-discount
gender-discount
status ;; Marital status 0 = single 1 = married 2 = divorced 3 = widowed
infected? ;; If true, the person is infected.
symptomatic? ;; If true, the person is showing symptoms of infection
severe-symptoms? ;; If true, the person is showing severe symptoms
cured? ;; If true, the person has lived through an infection. They cannot be re-infected.
isolated? ;; If true, the person is isolated at home, unable to infect friends and passer-bys.
days-isolated ;; Number of days the agent has spent in self-isolation
hospitalized? ;; If true, the person is hospitalized.
infected-by ;; Agent who infected me
spreading-to ;; Number of agents infected by me
chance-of-infecting ;; Probability that the person (when infective) will infect someone he comes close with
my-state ;;describe the disease state of the agent: "incubation" "asymptomatic" "symptomatic" "severe" "in-hospital" "recovered" "dead"
state-counter ;;how long in this disease state
t-incubation ;;length of incubatiom
t-asymptomatic ;;length of asymtomatic
t-symptomatic ;;length of symptomatic
t-severe ;;duration untill severe is addmited to hospital
t-hospital ;;duration in hospital untill death or recovery
t-infectious ;; time in which agent become infectiuos
t-stopinfecting ;;time when agent stop infecting
prob-symptoms ;; Probability that the person is symptomatic
isolation-tendency ;; Chance the person will self-quarantine when symptomatic.
testing-urgency ;; When the person will seek to get tested after the onset of symptoms
probability-of-dying
probability-of-worsening
susceptible? ;; Tracks whether the person was initially susceptible
;; Agentsets
friends
relatives
hh ;; household
wide-colleagues
close-colleagues
myclass ;; name of the pupil's class
my-work ;;identifier of work site, where 0- is not working
my-work-sub ;;identifier of sub work group
out-grp ;; instrumental variable to produce workgroups quickly
office-worker?
crowd-worker? ;; if the worker works with crowd
has-app? ;; If true the agent carries the contact-tracing app
tested-today?
aware?
neigh
ward
hhtype
days_cont ;;days of contacts since being infected
nm_contacts ;;number of contacts the agents had
]
friendships-own [mean-age]
households-own [ltype] ; ltype 0 is a spouse; ltype 1 is offspring/sibling
wps-own [wp-id wtype]
tracings-own [day]
;; ===========================================================================
;;;
;;; SETUP
;;;
;; ==========================================================================
to setup
set rnd ifelse-value use-seed? [-1114321144][new-seed]
random-seed rnd
;show rnd ;if behaviorspace-run-number = 0 [output-print (word "Random seed: " rnd)]
clear-all
set show-layout false
set use-existing-nw? true
; if impossible-run [
; reset-ticks
; stop
; ]
set-default-shape turtles "circle"
ifelse social-distancing? [
set b 0.7 ;; reduction factor in probability of infection
set fq 2 ;; discount in frequency of work/school
set c 0.7 ;; reduction factor in contacts around at work/school/street
][
set b 1
set fq 0
set c 1
]
set app-initalize? false
read-wards
ifelse use-existing-nw? [read-agents-sco][create-agents-sco]
set N-people count turtles
set-initial-variables
ifelse use-existing-nw?
[import-network]
[
create-hh-sco
ask seniors [create-relations]
create-friendships2
remove-excess
]
if schools-open? ;[foreach table:keys place [ngh -> create-schools-sco ngh]]
[foreach remove-duplicates table:values wardmap [ngh -> create-schools-sco ngh]]
ask turtles [
reset-variables
assign-disease-par
]
if show-layout [
resize-nodes
repeat 50 [layout]
]
reset-ticks
infect-initial-agents
ifelse use-existing-nw?
[read-workplaces]
[create-workplaces]
set s0 table:get populations "susceptible"
if behaviorspace-run-number = 0 [
output-print (word count turtles with [infected?] " individuals are currently infected " "(" precision (100 * count turtles with [infected?] / N-people) 2 "%)")
let school-state "open"
let sd-state "people practice social distancing"
if schools-open? = false [set school-state "closed"]
if social-distancing? = false [set sd-state "people do not practice social distancing"]
output-print (word "The schools are " school-state ", " sd-state)
plot-friends
plot-age
;plot-worksites
set infections table:make
]
end
to read-wards
set wardmap table:make
foreach csv:from-file "Glasgow_wards_lookup.csv" [w ->
table:put wardmap item 0 w item 1 w
]
end
to set-initial-variables
set compliance-adjustment ifelse-value app-compliance = "High" [0.9][0.5]
;;initially we start the expirement with no app-----------------------
;;ifelse pct-with-tracing-app > 0 [set contact-tracing true][]
set contact-tracing false
set high-prob-isolating ["symptomatic-individual" "household-of-symptomatic" "household-of-positive" "relation-of-symptomatic" "relation-of-positive" ]
set low-prob-isolating ["app-contact-of-symptomatic" "app-contact-of-positive"]
set counters table:from-list (list ["household" 0]["relations" 0]["friends" 0]["school" 0]["random" 0]["work" 0])
set populations table:from-list (list ["susceptible" 0]["infected" 0]["recovered" 0]["isolated" 0]["dead" 0]["in-hospital" 0]["incubation" 0]["symptomatic" 0]["asymptomatic" 0]["severe" 0])
set cumulatives table:from-list (list ["incubation" 0] ["asymptomatic" 0] ["symptomatic" 0] ["severe" 0 ] ["in-hospital" 0]["recovered" 0 ]["dead" 0])
table:put populations "susceptible" N-people
;; initally there will be no tests------------------------------
;;set tests-per-day round ((tests-per-100-people / 100) * N-People / 7)
set tests-per-day 0
set tests-remaining tests-per-day
set tests-performed 0
set flu-symp (0.035 / 7) * N-people * 0.3 ;;3.5% of pop have flu on any given week, for daily we divide by 7, 30% will have cough or fever or sore throat and get tested
set tested-positive 0
;; initially we don't distribute an app
;;let adults turtles with [age > 14]
;;ask n-of (round count adults * (pct-with-tracing-app / 100)) adults [set has-app? true]
set all-infections []
set lockdown? false
set testing-today []
set testing-tomorrow []
end
;; In this variant we test the situation of several countries with 5% cured and 0.5% infected
to infect-initial-agents
ask n-of (round (N-people / 100) * initially-infected) turtles [
change-state "incubation"
table:put populations "infected" (table:get populations "infected" + 1)
set infected? true
set susceptible? false
]
ask n-of (round (N-people / 100) * initially-cured) turtles with [infected? = false] [
change-state "recovered"
set cured? true
set susceptible? false
]
end
to initial-app
set contact-tracing ifelse-value pct-with-tracing-app > 0 [true][false]
set tests-per-day round ((tests-per-100-people / 100) * N-People / 7)
ask n-of (round count adults * (pct-with-tracing-app / 100)) adults [set has-app? true]
end
to reset-variables
set state-counter 0
set my-state "susceptible"
set has-app? false
set cured? false
set isolated? false
set hospitalized? false
set infected? false
set susceptible? true
set symptomatic? false
set severe-symptoms? false
; set dead? false
set aware? false
set spreading-to 0
set infected-by nobody
set office-worker? false
set crowd-worker? false
ifelse age <= 15 [set age-discount 0.5][set age-discount 1]
ifelse sex = "F" [set gender-discount 0.8] [set gender-discount 1]
set days_cont 0
set nm_contacts 0
end
;=====================================================================================
to go
; if ticks = 0 and impossible-run [stop]
if table:get populations "infected" = 0 [
print-final-summary
stop
]
clear-count
;;to initial the app onece 5% of the population are cured
if app-initalize? = false [
if table:get populations "recovered" / N-people > 0.05 [
initial-app
set app-initalize? true
]
]
; New tests are available every day
set tests-remaining tests-remaining + tests-per-day
ask turtles [set tested-today? false]
; The contact tracing app removes contacts older than 10 days
if contact-tracing [ask tracings with [day < (ticks - 10)][die]]
ask turtles with [isolated?] [
set days-isolated days-isolated + 1
if ((symptomatic? = false) and (days-isolated = 10)) [unisolate]
]
let symp-covid turtles with [infected? and (not hospitalized?) and
(member? my-state ["symptomatic" "severe"]) and
(should-test?) and
(state-counter = testing-urgency)
]
let nm-sym-covid count symp-covid ;; number of covid infected ppl who want to get-tested today
if nm-sym-covid > 0 [set ratio-flu-covid round (flu-symp / nm-sym-covid)]
ask turtles with [infected? and (not hospitalized?)] [ ;; we could exclude those still in the incubation phase here. We don't, so that we produce a few false positives in the app
; Infected agents (except those in hospital) infect others
set days_cont days_cont + 1
infect
if member? self symp-covid [
ifelse tests-remaining > 0
[get-tested "symptomatic-individual"]
[if not isolated? [maybe-isolate "symptomatic-individual"]]
]
]
;;crowd workers work 5 days and may infect the customers or be infected by them
ask crowd-workers with [not isolated?] [if 5 / 7 > random-float 1 [meet-people]]
;;non-symptomatic are can get tested in tests are still available- in case of priorty to testing symptomatic
if tests-remaining > 0 and (length testing-today) > 0 [test-people]
;;after the infection between contactas took place during the day, at the "end of the day" agents change states
ask turtles with [infected?][progression-disease]
ifelse behaviorspace-run-number != 0
[ save-individual ]
[
table:remove infections (ticks - 8)
if ticks = 7
[set double-t 7
set cum-infected table:get cumulatives "asymptomatic" + table:get cumulatives "symptomatic" + table:get cumulatives "severe"
]
if (ticks > 7) and (inc-rate >= 2) [
print-double-time
set double-t ticks
set cum-infected table:get cumulatives "asymptomatic" + table:get cumulatives "symptomatic" + table:get cumulatives "severe"
]
if show-layout [ask turtles [assign-color]]
plot-contacts
calculate-r0
current-rt
]
tick
end
to clear-count
set nb-infected 0
set nb-recovered 0
set tests-today 0
set tested-positive 0
set testing-today testing-tomorrow
set testing-tomorrow []
end
to change-state [new-state]
table:put populations my-state (table:get populations my-state - 1)
set my-state new-state
table:put populations my-state (table:get populations my-state + 1)
table:put cumulatives my-state (table:get cumulatives my-state + 1)
end
;; =========================================================================
;; PROGRESSION OF THE INFECTION
;; =========================================================================
;; After the incubation period the person may become asymptomatic or mild symptomatic or severe symptomatic. Severe are hospitlized within few days
to progression-disease
set state-counter state-counter + 1
ifelse (my-state = "incubation") [
if (state-counter = t-infectious) [set chance-of-infecting infection-chance ]
if (state-counter = t-incubation) [determine-progress]
][
ifelse (my-state = "asymptomatic") [
if (state-counter = t-asymptomatic) [recover]
if (t-incubation - t-infectious + state-counter > 3) [set chance-of-infecting chance-of-infecting * 0.9] ;; we assume asymptomatic infectiousness declines at 3rd day
][ifelse (my-state = "symptomatic") and (state-counter = t-symptomatic) [recover][
ifelse (my-state = "severe") and (state-counter = t-severe) [hospitalize][ ;;severe cases are hospitlized within several days
if (my-state = "in-hospital") and (state-counter = t-hospital) [ifelse probability-of-dying * gender-discount > random-float 1 [kill-agent] [recover]] ;patient either dies in hospital or recover
]
]
]
]
if (member? my-state ["symptomatic" "asymptomatic"]) and (state-counter = t-stopinfecting) [set chance-of-infecting 0] ;;stop being infectious after 7-11 days
;; agents states: "incubation" "asymptomatic" "symptomatic" "severe" "in-hospital" "recovered" "dead"
end
to determine-progress
ifelse prob-symptoms > random-float 1 [
;show "DEBUG: I have the symptoms!"
ifelse probability-of-worsening > random-float 1 [
change-state "severe"
set severe-symptoms? true
set symptomatic? true
set state-counter 0
]
[change-state "symptomatic"
set symptomatic? true
set state-counter 0
]
]
[ change-state "asymptomatic"
set state-counter 0
]
end
to recover
set state-counter 0
change-state "recovered"
table:put populations "infected" (table:get populations "infected" - 1)
set infected? false
set symptomatic? false
set cured? true
set all-infections lput spreading-to all-infections
if behaviorspace-run-number = 0 [
ifelse table:has-key? infections ticks
[table:put infections ticks (lput spreading-to table:get infections ticks)]
[table:put infections ticks (list spreading-to)]
]
if hospitalized? [
set hospitalized? false
set isolated? false
]
if isolated? [unisolate]
set nb-recovered (nb-recovered + 1)
end
to kill-agent
table:put populations my-state (table:get populations my-state - 1)
table:put populations "infected" (table:get populations "infected" - 1)
table:put populations "dead" (table:get populations "dead" + 1)
table:put cumulatives "dead" (table:get cumulatives "dead" + 1)
if hospitalized? [set isolated? false]
if isolated? [table:put populations "isolated" (table:get populations "isolated" - 1)]
set all-infections lput spreading-to all-infections
if behaviorspace-run-number = 0 [
ifelse table:has-key? infections ticks
[table:put infections ticks lput spreading-to table:get infections ticks ]
[table:put infections ticks (list spreading-to)]
]
die
if table:get populations "dead" = 1 [
if lockdown-at-first-death [lockdown]
if behaviorspace-run-number = 0 [
output-print (word "Epidemic day " ticks ": death number 1. Age: " age "; gender: " sex)
output-print (word "Duration of agent's infection: " t-incubation " days incubation + " (t-severe + t-hospital) " days of illness")
print-current-summary
]
]
end
to test-people
set testing-today remove-duplicates testing-today
let to-test length testing-today
if to-test >= tests-remaining [set to-test tests-remaining]
repeat to-test [
ask item 0 testing-today [get-tested "other"]
set testing-today remove-item 0 testing-today
]
end
;; ===============================================================================
to enter-list
set testing-tomorrow fput self testing-tomorrow
end
to-report should-test?
if not tested-today? and not aware? and not member? self testing-tomorrow [report true]
report false
end
to-report should-isolate?
if not isolated? and not aware? and not tested-today? [report true]
report false
end
to-report can-be-infected?
if (not infected?) and (not aware?) [report true]
report false
end
to maybe-isolate [origin]
let tendency isolation-tendency
if member? origin low-prob-isolating and not symptomatic? [set tendency tendency * compliance-adjustment]
if random-float 1 < tendency [
isolate
;;symptomatic ask hh members and relatives to isolate
if origin = "symptomatic-individual" [
ask hh with [should-isolate?][maybe-isolate "household-of-symptomatic"]
if any? relatives [ask relatives with [should-isolate?] [maybe-isolate "relation-of-symptomatic"]]
;if has-app? [ask tracing-neighbors with [should-isolate?] [maybe-isolate "app-contact-of-symptomatic"]]
]
]
end
;; When the agent is isolating all friendhips and relations are frozen. The agent stops going to school or work.
;; household members links stay in place, as it is assumed that one isolates at home
to isolate
set isolated? true
table:put populations "isolated" (table:get populations "isolated" + 1)
end
to unisolate ;; turtle procedure
set isolated? false
table:put populations "isolated" (table:get populations "isolated" - 1)
set days-isolated 0
end
to hospitalize ;; turtle procedure
set state-counter 0
change-state "in-hospital"
set hospitalized? true
set aware? true
;; We assume that hospitals always have tests. If the aget ends up in hospital, the app updates the contacts.
ask tracing-neighbors with [should-test?] [
if not isolated? [maybe-isolate "app-contact-of-positive"]
ifelse prioritize-symptomatics?
[enter-list]
[if tests-remaining > 0 [get-tested "other"]]
]
ifelse not isolated? [set isolated? true] ;; The agent is isolated, so people won't encounter him around, but we don't count him
[table:put populations "isolated" table:get populations "isolated" - 1]
set pcolor black
if show-layout [
move-to patch (max-pxcor / 2) 0
set pcolor white
]
end
;=====================================================================================
;; Encounters between 'crowd workers' and the crowd.
;; There's a chance that the worker will get infected and that he will infect someone.
to meet-people
let here table:get placecnt neigh
let nmMeet ((lambda * 3) * item 0 here) ;;contacts with customera are:lambda % of the people in the neigh
let propelderly 0.5 * (1 - item 1 here) ;;gives 50% of the proportion of the elderly in the neigh
set howmanyelder round (nmMeet * propelderly)
set howmanyrnd nmMeet - howmanyelder
let spreader self
let chance chance-of-infecting
let victim self
let locals other table:get place neigh
let crowd (turtle-set
up-to-n-of random-poisson (howmanyrnd ) locals with [ age < 67]
up-to-n-of random-poisson (howmanyelder) locals with [age > 67])
ifelse infected? [
;; Here the worker is infecting others
ask crowd [
let in_contact false
if random-float 1 < c [
set in_contact true
ask myself[set nm_contacts nm_contacts + 1] ]
if (can-be-infected?) and (not isolated?) and in_contact [
if has-app? and [has-app?] of spreader [add-contact spreader]
if (not cured?) and random-float 1 < (chance * age-discount * prob-rnd-infection * b) [newinfection spreader "random"] ; If the worker infects someone, it counts as random
]
]
]
[
ask crowd with [(infected?) and (not isolated?) and (random-float 1 < c)] [
;; here the worker is being infected by others
ask myself[set nm_contacts nm_contacts + 1]
set spreader self
set chance chance-of-infecting
ask victim [
if can-be-infected? [
if has-app? and [has-app?] of spreader [add-contact spreader]
if (not cured?) and random-float 1 < (chance * prob-rnd-infection * b) [newinfection spreader "work"] ; If the worker is infected by someone, it's work.
]
]
]
]
end
;; Infected individuals who are not isolated or hospitalized have a chance of transmitting
;; their disease to their susceptible friends and family.
;; We allow people to meet others even before they are infective so that the app will record these
;; interactions and produce a few false positives
to infect ;; turtle procedure
;; Number of people we meet at random every day: 1 per 1000 people. Elderly goes out 1/2 less than other
let here table:get placecnt neigh
let nmMeet (lambda * item 0 here) ;;random contacts with lambda % of the people in the neigh
let propelderly 0.5 * (1 - item 1 here) ;;gives 50% of the proportion of the elderly in the neigh
set howmanyelder round(nmMeet * propelderly)
set howmanyrnd nmMeet - howmanyelder
let spreader self
let chance chance-of-infecting
;; Every day an infected person risks infecting all other household members.
;; Even if the agent is isolating or there's a lockdown.
if count hh > 0 [
let hh-infection-chance chance
;; if the person is isolating the people in the household have a reduced risk to get infected
if isolated? [set hh-infection-chance hh-infection-chance * 0.7]
ask hh with [(not cured?) and can-be-infected?] [
if random-float 1 < (hh-infection-chance * age-discount) [newinfection spreader "household"]
]
]
;; When there's no lockdown, and we are not isolated, we go out and infect other people.
if (not isolated?) and (not lockdown?) [
;; Infected agents will infect someone at random. The probability is a fraction of the normal infection-chance
;; If both parties have the app a link is created to keep track of the meeting
let random-passersby nobody
if (age <= 67 or 0.5 > random-float 1) [
let locals table:get place neigh
set random-passersby (turtle-set
up-to-n-of random-poisson howmanyrnd other locals with [age < 65 ]
up-to-n-of random-poisson howmanyelder other locals with [age > 65 ]
)
;show random-passersby
]
let nm-passby 0
if random-passersby != nobody [set nm-passby count random-passersby ]
set nm_contacts nm_contacts + count hh
let proportion max-prop-friends-met ;; Change this and the infection probability if we want more superpreading
if age > 40 [set proportion proportion / 2] ;; older meets less
;; The following are schoolkids
ifelse age > 5 and age < 18 [
if schools-open? and ((5 / 7) > random-float 1) [ ;; If schools are open children go to school 5 days a week
;; Schoolchildren meet their schoolmates every SCHOOLDAY, and can infect them.
set proportion proportion / 2 ;;school children meet less than younger adults
let classmates table:get school myclass
set classmates classmates with [isolated? = false]
ask n-of ((count classmates * 0.5) ) other classmates [
let in_contact false
if random-float 1 < c [
set in_contact true
ask myself[set nm_contacts nm_contacts + 1 ]
]
if can-be-infected? and in_contact [
; We don't rely on the app in school. The classrom is quarantined if a pupil is positive
;if has-app? and [has-app?] of spreader [add-contact spreader]
if (not cured?) and random-float 1 < (chance * age-discount) [newinfection spreader "school"]
]
]
]
]
;; People who work in offices
[
if office-worker? and (((5 - fq) / 7) > random-float 1) [ ;; People who work in offices go to work 5 days a week
let todaysvictims (turtle-set n-of (count close-colleagues) close-colleagues one-of wide-colleagues)
ask todaysvictims [
let in_contact false
if random-float 1 < c [
set in_contact true
ask myself[set nm_contacts nm_contacts + 1 ] ]
if can-be-infected? and (not isolated?) and (in_contact) [
if has-app? and [has-app?] of spreader [add-contact spreader]
if (not cured?) and random-float 1 < (chance * b) [newinfection spreader "work"]
]
]
]
]
;; The following applies to everyone who has friends
if (age <= 67 or 0.5 > random-float 1) [ ;;; Old people only meet friends half of the times younger people do.
;;; Every day the agent meets a certain fraction of her friends.
;;; If the agent has the contact tracing app, a link is created between she and the friends who also have the app.
;;; If the agent is infective, with probability infection-chance, he infects the susceptible friends who he's is meeting.
if count friends > 0 [
let howmany 1 + random round (count friends * proportion)
;;----------------------------------------------------------------------------------------------------
;;This is for sensitivity analysis of friends meeting
if per-dif-friends != 0[
;;here we want to increase friends meeting
if per-dif-friends > 0 [
repeat howmany [if random-float 1 <= per-dif-friends [set howmany howmany + 1] ]
set howmany min (list howmany round (count friends))
]
;;here we decrease meeting
if per-dif-friends < 0 [ repeat howmany [if random-float 1 <= -1 * per-dif-friends [set howmany howmany - 1] ]
]
]
;;-------------------------------------------------------------------------------------------------------------
if howmany > 0[
ask n-of howmany friends [
let in_contact false
if random-float 1 < c [
set in_contact true
ask myself[set nm_contacts nm_contacts + 1] ]
if (not isolated?) and (can-be-infected?) and (in_contact) [
if has-app? and [has-app?] of spreader [add-contact spreader]
if (not cured?) and random-float 1 < ((chance * age-discount * b)) [newinfection spreader "friends"]]
]
]
]
]
;; Every week we visit granpa twice and risk infecting him
if count relatives > 0 and (2 / 7) > random-float 1 [
set nm_contacts nm_contacts + 1
ask one-of relatives [
if can-be-infected? and (not isolated?) [
if (not cured?) and random-float 1 < (chance * age-discount * b) [newinfection spreader "relations"]
]
]
]
;; Here we determine who are the unknown people we encounter. This is the 'random' group.
;; If we are isolated or there is a lockdown, this is assumed to be zero.
;; Elderly people are assumed to go out half as much as everyone else.
;; Currently an individual meets a draw from a poisson distribution with average howmanyrnd or howmanyelder
if random-passersby != nobody [
ask random-passersby [
let in_contact false
if random-float 1 < c [
set in_contact true
ask myself[set nm_contacts nm_contacts + 1] ]
if (can-be-infected?) and (not isolated?) and in_contact [
if has-app? and [has-app?] of spreader [add-contact spreader]
if (not cured?) and random-float 1 < (chance * age-discount * prob-rnd-infection * b) [newinfection spreader "random"]
]
]
]
]
end
to add-contact [infected-agent]
create-tracing-with infected-agent [set day ticks]
end
to newinfection [spreader origin]
set infected? true
set state-counter 0
change-state "incubation"
table:put populations "infected" (table:get populations "infected" + 1)
set symptomatic? false
set severe-symptoms? false
set aware? false
set nb-infected (nb-infected + 1)
set chance-of-infecting 0
set infected-by spreader
ask spreader [set spreading-to spreading-to + 1]
table:put counters origin (table:get counters origin + 1)
end
;; ========= Interventions =============================
to lockdown
if behaviorspace-run-number = 0 [
output-print " ================================ "
output-print (word "Day " ticks ": Locking down!")
]
set lockdown? true
close-schools
end
to remove-lockdown
if behaviorspace-run-number = 0 [
output-print " ================================ "
output-print (word "Day " ticks ": Removing lockdown!")
]
set lockdown? false
reopen-schools
end
to close-schools
set schools-open? false
end
to reopen-schools
set schools-open? true
end
to get-tested [origin]
;show (word " day " ticks ": tested-today?: " tested-today? " - aware?: " aware? " - now getting tested")
let depletion 1
if origin = "symptomatic-individual" [set depletion depletion + ratio-flu-covid]
set tests-remaining tests-remaining - depletion
set tests-performed tests-performed + depletion
set tests-today tests-today + depletion ; this all tests today including flu symptomatic
; if tests-remaining = 0 and behaviorspace-run-number = 0 [output-print (word "Day " ticks ": tests finished")]
;; If someone is found to be positive they:
;; 1. Isolate, 2. Their household decides whether to isolate, 3. The notify relatives
;; 4. If they use the app, the contacts are notified and have the option of getting tested or isolate.
ifelse infected? [
set tested-positive tested-positive + 1
if should-isolate? [isolate]
set tested-today? true
set aware? true
ask hh with [should-test?] ;;notify the hh memebers
[if not isolated? [maybe-isolate "household-of-positive"]] ;;hh member decides wether to self-isolte
if any? relatives [
ask relatives [
if should-isolate?
[
maybe-isolate "relation-of-positive"
ifelse prioritize-symptomatics?
[enter-list]
[if tests-remaining > 0 [get-tested "other"]]
]
]
]
if age > 5 and age < 18 [ask other table:get school myclass [SCHOOL-ALERT]]
;; Following a positive test the app notifies the contacts
if has-app? [ask tracing-neighbors with [should-test?] [APP-ALERT]]
]
[if isolated? [unisolate]] ;;agent who was isolating and tested negative will unisolate
end
to SCHOOL-ALERT
if not isolated? [isolate]
if should-test? [
ifelse prioritize-symptomatics?
[enter-list]
[if tests-remaining > 0 [get-tested "other"]]
]
end
to APP-ALERT
if not isolated? [maybe-isolate "app-contact-of-positive"]
ifelse prioritize-symptomatics?
[enter-list]
[if tests-remaining > 0 [get-tested "other"]]
end
;; =======================================================
to-report impossible-run
if (pct-with-tracing-app = 0 and app-compliance = "High") OR
(tests-per-100-people = 0 and prioritize-symptomatics?)
[report true]
report false
end
;;===================== work distribution ==================================
@#$#@#$#@
GRAPHICS-WINDOW
410
765
833
1189
-1
-1
2.065
1
10
1
1
1
0
0
0
1
-100
100
-100
100
1
1
1
day
30.0
BUTTON
7
146
87
179
setup
setup
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
BUTTON
87
146
152
179
go
go
T
1
T
OBSERVER
NIL
NIL
NIL
NIL
0
PLOT
0
525
406
717
Populations
days
# people
0.0
10.0
0.0
100.0
true
true
"" ""
PENS
"Infected" 1.0 0 -2674135 true "" "plot table:get populations \"infected\""
"Dead" 1.0 0 -16777216 true "" "plot table:get populations \"dead\""
"Hospitalized" 1.0 0 -955883 true "" "plot table:get populations \"in-hospital\""
"Self-Isolating" 1.0 0 -13791810 true "" "plot table:get populations \"isolated\""