-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbirdflu.nlogo
5090 lines (4728 loc) · 174 KB
/
birdflu.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
;; A NetLogo model of an SEIR+network model of birdflu transmission in Thailand.
;; Version: 1.1.0
;;
;; author: Amanda Beaudoin and Alan G. Isaac
;; (authors are in alphabetical order)
;; email: <amanda.beaudoin AT state.mn.us> and <aisaac AT american.edu>
;;
;; NOTE: run model from a folder that has an `out` subfolder, which
;; in turn must have two subfolders: `locations`, and `log`.
;; REQUIRES: Netlogo 6.1+
;;
;; See accompanying paper for model details.
;;
;; Note: for ease of reading:
;;
;; - local variables defined with `let` begin with `_`
;; - local variables defined as procedure formal arguments begin with `#`
;; - variables beginning with `pct` should be an integer percentage
;;
;; ALERT:
;; refactoring should attend to code marked with alert
;;
;; TODO:
;; - document colors and shapes
;; - add sampling regime for detection/destruction
;; - add non-poultry-related households
;; - move some plot code inside plots
;; - some items marked in code
__includes ["utilities.nls"]
extensions [table nw]
;type declarations
; NOTE: z-order in the GUI is determined by declaration order
;;declare road-related types
undirected-link-breed [road-links road-link] ;; link intersections with roads
breed [intersections intersection] ;; road intersections
;;; other inanimate-types chkchkchk
undirected-link-breed [egg-links egg-link] ;; stable eggtrader links
undirected-link-breed [livebird-links livebird-link] ;; volatile livetrader links
undirected-link-breed [fgd-links fgd-link] ;; tie fgds to owners
;;; poultry-types
breed [fcs fc] ;fighting cocks
breed [chickens chicken] ;based on a large farm, or free ranging in a backyard
breed [ducks duck] ;based on a large farm, or free grazing, or penned in a backyard
;; human-types (may move w/out poultry to households, market, arena, etc)
breed [flock-owners flock-owner]
breed [eggtraders eggtrader]
breed [livetraders livetrader] ;live poultry traders
;;attributes common to all human types
turtles-own [
contam-until ;;Integer, day contamination ends
contam-period ;;Integer, length of contamination potential
;; (can contaminate if contam-period>0)
;; (set to human-contam-period for humans)
homebase ;;Patch, the home base:
;; barn for FGD flock; house/yard for backyard poultry
;; house/yard for fighting cocks;
;; house/slaughterhouse for local traders
]
fcs-own [
;fighting-cock-specific attributes
practice-fight-week ;;Integer; 0|1 (even or odd weeks)
target-match-arena ;;Patch, this fc's match arena
target-practice-arena ;;Patch, this fc's practice arena
;shared poultry attributes
owner ;;Turtle, the owner of the fgd flock
shedding-period ;;Integer, number of days
flu-state ;;String {"s" | "e" | "i" | "d"}
]
ducks-own [
;duck-flock-specific attributes
target-field ;;Patch; a harvested rice field (i.e., a dayfield)
target-road-access
field-only? ;;Boolean, whether to overnight on field
;shared flock attributes (chickens and ducks, but not fcs)
biotype ;;String, "fg" | "pen" | "farm" (remember, byducks are penned)
n-birds ;;Integer, number of birds in flock (to determine grazing consumption)
has-eggs? ;;Boolean, eggs are available for pickup
n-egg-pickup-days ;;Integer, number of egg pickup days (from eggtraders)
n-onsite-eggtraders ;;Integer, number of eggtraders that come to flock to pick up eggs
target-egg-market ;;patch
n-egg-delivery-days ;;Integer, number of days per week that flock delivers eggs
meat-delivery-days ;;Integer, number of days per week that flock delivers meat (not currently used)
;shared poultry attributes
owner ;;Turtle, the (human) owner of the flock
shedding-period
flu-state ;;String {"s" | "e" | "i" | "r" | "d"}
]
chickens-own [
;type-specific attributes:
; none, although note that bychickens are not penned
;shared flock attributes (chickens and ducks, but not fcs)
biotype ;;String, "fg" | "by" | "farm" (remember, bychickens are *not* penned)
n-birds ;;Integer, number of birds in the flock (not currently used)
has-eggs? ;;Boolean, eggs are available for pickup
n-egg-pickup-days
n-onsite-eggtraders ;; number of eggtraders that come to flock to pick up eggs
target-egg-market
n-egg-delivery-days ;; number of days per week that flock delivers eggs
meat-delivery-days ;; number of days per week that flock delivers meat (not currently used)
;shared poultry attributes
owner ;;Turtle, the (human) owner of the flock
shedding-period
flu-state ;;String {"s" | "e" | "i" | "r" | "d"}
]
flock-owners-own [
;type-specific attributes:
n-visit-days-per-week
flock
fighting-cock
livebird-selldate
;shared worker attributes
n-visits ;; number of visits per day
visit-list ;; agentset of neighbors that receive visits from this owner
]
eggtraders-own [
;type-specific attributes:
n-eggtrader-links
egg-type ;;alert: currently unused
target-egg-market ;; one of the three markets
;shared worker attributes
n-visits
visit-list
]
livetraders-own [
;type-specific attributes:
livetrader-links
n-bird-pickup-days
n-flocks-per-pickup
;shared worker attributes
n-visits
visit-list
]
road-links-own [
roadtype ;;String, one of: "highway" "major_road" "loose_road" "small_road" "field_road"
road-patches ;;Patch[1..*], patch set of patches along road-link
]
patches-own [
;; rai used as rough measure of productive capacity for rice fields:
rai ;;Number, area in rai (1 rai =1,600 m^2)
field-patches ;;Patch[*], an agentset of patches, empty for all but access fields
field-num ;;Integer {nonnegative}, unique field identifier
field-state ;; "" | "harvested" | "growing" | "fallow"
;; - harvested: the fields that duck flocks move to
;; - growing: ducks do not graze in these fields
;; - fallow: After ducks exhaust a field, it is left until the next harvest
occupant ;; field is the target of occupant (who may not always be physically present)
;; patches will be contaminated if next to a road with infectious ducks passing by; rice field can be contaminated
pcontam-until ;;Integer, day patch contamination ends
pcontam-period ;;Integer, set to field-contam-period or road-contam-period
; (chk nicer to use patch type?)
patch-type ;;ricefield, barn, market, practice-arena, match-arena, etc
road-access ;;closest `intersection`
]
;;;;;;;;;;;;;;;;;;;;;;;;
;; Globals ;;
;;;;;;;;;;;;;;;;;;;;;;;;
;;;PARAMETERS:
;;; globals declared in choosers: ;;;
;baseline ;;;String {"mode" | "pert"}, (mode is default)
;infection-source ;;String {"fgduck" | "farm" | "byduck" | "bychicken"}
;scenario ;;;String, the scenario name
;n-cooperatives ;;Integer, number of central egg cooperatives (affects egg delivery behavior)
;;; globals declared in sliders: ;;;
;prop-fgd-barntofield
;shedding-period-duck ;; this is the length of the shedding period in days for ducks
;shedding-period-chicken;; this is the length of the shedding period in days for chickens
;;;OTHER declared globals: ;;;
globals [
;;; CONSTANTS (calibrated to data) ;;;
;humans
N-LIVETRADERS ;;Integer, fixed number of live-bird traders (vs. endog # eggtraders!)
n-flocks-per-pickup-ltrdr ;;Integer, number of flocks the livetrader buys from each day s/he trades
;poultry:
N-FGDS ;;Integer, small number of large free grazing duck flocks
N-BYCHICKENS ;;Integer, large number of small backyard chicken flocks
N-FCS ;;Integer, large number of fighting cocks
N-BYDUCKS ;;Integer, large number of small backyard duck flocks
N-DUCK-FARMS ;;Integer, small number of large duck farms
N-CHICKEN-FARMS ;;Integer, small number of large layer-chicken farms
RAI-PER-DUCK ;;Float, per duck daily consumption rate (as "area" consumed)
LIVEBIRD-REPLENISH ;;Integer, days to replenish livebird supply after sale
meat-eggs-both-byd ;;List, the number of byduck flocks producing only meat, only eggs, or both
;land use:
N-BARNS ;;Integer, large number of patches that are barns (i.e., poultry-owning households or farms)
N-PRACTICE-ARENAS ;;Integer, number of patches that are practice arenas
N-MATCH-ARENAS ;;Integer, number of patches that are practice arenas
N-MARKETS ;;Integer, number of patches that are practice arenas
;;; land-use patch sets: assignment to these must be finalized in setup
rice-fields ;; field patches can be in 3 states; components of larger rice fields
access-fields ;; rice-field patches that provide field access
barns ;; the patches that are barns
match-arenas ;; arenas for fighting cock matches
practice-arenas ;; arenas for fighting cock practice
markets
cooperatives
out-of-subdistrict-patches ;; patches representing areas outside of our modeled subdistrict
;;; turtle agentsets: assignment to these must be finalized during setup
;; owner subtypes ;;; convenient to avoid repeated recreation
;; may move w/out poultry to other households, market, arena, etc;
fgd-owners ;; FGD owners (can move w/out ducks to households, egg cooperative, market, etc)
byd-owners ;; backyard duck owners
fmd-owners ;; duck farm owners
fmc-owners ;; chicken farm owners
byc-owners ;; backyard chicken owners (move w/out poultry to other households, market, arena, etc)l
fc-owners ;; fighting cock owners (some byc-owners are also fc owners)
farm-owners ;; owners of *large* poultry farms
;; flock subtypes
fgducks ;; free grazing ducks (ducks with [biotype = "fg"])
byducks ;; penned backyard ducks (ducks with [biotype = "pen"])
fmducks ;; farm ducks (ducks with [biotype = "fm"])
bychickens ;; backyard chickens (chickens with [biotype = "by"])
fmchickens ;; farm chickens (chickens with [biotype = "fm"])
farms ;; fmducks + fmchickens (farms used in plots and reporters)
;;; breed lists ;;;
human-types
trader-types
flock-types
poultry-types ;; flock-types + fighting cocks
;;; key duration parameters, in days
latent-period ;;Integer, duration of the viral latent period (common to all flocks)
road-contam-period ;;Integer, duration after contamination that the road will pose risks
human-contam-period ;;Integer, duration after contamination (by infected birds) that traders pose risks
field-contam-period ;;Integer, duration after contamination (by infected fgd) that fields pose risks
;;contamination/infection probabilities (as pct) following a risky event
pct-flock-field-contam ;; flock contaminates field
pct-flock-road-contam ;; flock contaminates road
pct-flock-eggtrader-contam ;; eggtrader contaminated when getting eggs from contaminated premises
pct-eggtrader-flock-infect ;; contaminated eggtrader infects a susceptible flock when visiting
pct-flock-livetrader-contam ;; live trader is contaminated while acquiring birds from an infected premises
pct-livetrader-flock-infect ;; contaminated live trader causes infection of a susceptible flock while visiting
pct-flock-visitor-contam ;; visitor is contaminated while visiting an infected premises
pct-from-visit-infect ;; visitor that goes to an infected flock will infect own susceptible flock
pct-to-visit-infect ;; an infectious flock owner visits and infects a neighbor's flock
pct-arena-fc-infect ;; FC becomes infected while at the arena
pct-fc-byc-infect ;; infected FC (infected at arena) infects his homebase flock
;;roads can become contaminated when infected FGDs travel on them:
pct-road-byc-infect ;; road infects bychickens
pct-road-pen-infect ;; road infects penned duck or farmed layer flock
;visiting parameters
n-nbrs ;;Integer, positive number of other humans a human can visit (size of the social circle)
visit-radius ;;Float, positive radius from which we select neighbors to visit
; (alert: be careful about the units) todo: set physical units
n-visits-task ;;Task, sets number of visits per day by humans to other humans' homebase patches (scenario-based task!)
etlinks-task ;;Task, sets the number of links (suppliers) an eggtrader can service
;odds and ends
pct-fgd-deliver ;; number, the percentage of FGD flocks that deliver to market (if no cooperative)
n-onsite-eggtraders-fgd-task
n-onsite-eggtraders-byd-task
n-onsite-eggtraders-fm-task
n-egg-delivery-days-fgd-task
n-egg-delivery-days-byd-task
n-egg-delivery-days-fm-task
n-egg-pickup-days-fgd-task
n-egg-pickup-days-byd-task
n-egg-pickup-days-fm-task
n-bird-pickup-days-ltrdr-task
;;; calendar constants ;;;
VISIT-SCHEDULE ;;List, [[int]] specifies for each day of the week who will do live-bird pickup
LIVETRADER-PICKUP-SCHEDULE ;;List, [[int]] specifies for each day of the week who will do live-bird pickup
EGGTRADER-PICKUP-SCHEDULE ;;List, [[int]] specifies for each day of the week which flocks want egg pickup
DAY-NAMES ;;List, [str] (days of the week)
;;; filenames ;;;
base-filename ;;String, base filename for current replicate
locations-file ;;String, name of file to write location data
log-file ;;String, filename for logging info about this run
setupComplete?
runsim? ;;Boolean, for simulation control
stop-sim-reason ;;String, diagnostic msg
DEBUG ;;Integer, global DEBUG level
;;; convenience tables ;;;
days-on-field ;;Table, map FGD who numbers to lists of days on field count for each field
transmissions ;;Table, transmission type -> daily count of transmissions
contaminations ;;Table, map contamination types to lists of daily numbers
transition-dates ;;Table, map date (ticks) to list (agents due for state transition)
;;TODO: delete expired transitions chkchk
infecteds ;list of infected flocks (for debugging only)
]
;;;;;;;;;;;;;;;;;;;;;;;;
;; SETUP PROCEDURES ;;
;;;;;;;;;;;;;;;;;;;;;;;;
to startup
;;`startup` runs when the model first loads in GUI (not BS)
;;This can only set breed shapes (not other turtle sets).
set-default-shape eggtraders "car"
set-default-shape livetraders "truck"
set-default-shape flock-owners "person"
set-default-shape ducks "duck"
set-default-shape chickens "backyard" ;;chkchk
set scenario "none"
set forbid-fcs false
set baseline "pert"
set n-cooperatives 0
set prop-fgd-barntofield 0.6
set shedding-period-chicken 4
set shedding-period-duck 7
end
to setup ;; setup the display with globals, patches, agents
set setupComplete? false
;; do not use clear-all! (it's a problem for our BS;
;; it resets **all** non-interface globals, including those set by BS,
;; where we are setting some of them!)
clear-ticks ;; version 5+
clear-turtles
clear-patches
clear-drawing
clear-all-plots
clear-output
setupGlobals
setup-roads ;;must set up road **before** patches!
setup-patches ;;calls place-along-roads!
setup-agents
initialize-locations-file ;;must come before initialize-infection
;;reset ticks at *end* of setup (version 5+)
;; http://ccl.northwestern.edu/netlogo/docs/dictionary.html#reset-ticks
reset-ticks
initialize-infection ;; calls `infect-poultry` which executes ``ticks``, so comes *after* ``reset-ticks``
updatePlots ;chkchk: plot initial state
setup-visuals
set setupComplete? true
log2file 0 (word "Setup complete with ticks = " ticks " and n-fcs " (count fcs))
if (DEBUG > 0) [ test-setup ]
end
;; Setup the enumerations
to setupGlobals
;;sliders and switches set the following:
;; baseline
;; scenario
;; infection-source
;; prop-fgd-barntofield
;; shedding-period-duck
;; shedding-period-chicken
;; n-cooperatives
;;preliminaries
;; set `DEBUG` to 0 during BahaviorSpace experiments (to speed runs)
set DEBUG ifelse-value (behaviorspace-run-number > 0) [0] [3]
;;set the random seed for experiments (but allow it to vary in GUI)
if (behaviorspace-run-number > 0) [
random-seed (314159 + behaviorspace-run-number)
]
set base-filename (make-filename ;the only call to `make-filename`
behaviorspace-experiment-name scenario behaviorspace-run-number)
;;
set runsim? true ;; `runsim?` reset to false to stop simulation
set stop-sim-reason ""
;;; FILES
;; file for event logging
set log-file (word "out/log/" base-filename ".log")
carefully [file-delete log-file] []
log2file 0 (word date-and-time "\n")
;; file for location data; but don't initialize yet
set locations-file (word "out/locations/" base-filename ".txt")
;;define agent-type lists (i.e., lists of breeds)
;; (must NOT be agentsets; here, those may be empty)
;; (comment: fc-owners are NOT a separate breed ...)
;;MUST *list* all human breeds:
set human-types (list eggtraders livetraders flock-owners)
set trader-types (list eggtraders livetraders)
;;MUST *list* all poultry breeds:
set poultry-types (list fcs ducks chickens)
set flock-types (list ducks chickens)
set access-fields nobody ;; initialization is just a place-holder
intializeDataTables
;; calendar variables
set DAY-NAMES ["Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday"]
setup-baseline
setupScenario scenario
record-params ;; record the final parameter values for this run
set infecteds []
log2file 0 "finished setting up globals"
end ;;setupGlobals
to intializeDataTables
set days-on-field table:make ;;empty table; initialized by init-fgduck
set transmissions table:make ;;empty table
foreach ["road-flock" "after-visit" "visitor-flock" "eggtrader-flock"
"livetrader-flock" "arena-fc" "fc-flock"] [? ->
table:put transmissions ? [0]
]
set contaminations table:make
foreach ["flock-livetrader" "flock-eggtrader" "flock-visitor"
"flock-road" "flock-field"] [? ->
table:put contaminations ? [0]
]
;setup a flu-state transition table, to map date (ticks) to list (transitioning agents)
;(must create this before initial infection)
set transition-dates table:make
end
to setup-baseline
;; chkchk EGGTRADER-LINKS- Not here because need to set manually during runs chkchkchk
;;NOTE: this will be executed *after* BehaviorSpace sets values!
;;NOTE: this will be executed *before* a scenario sets values!
;; (so do not set slider or switch variables here)
if not (member? baseline ["pert" "mode"]) [error "unrecognized baseline"]
;; set values of constants
let _ini read-params "baseline.ini"
let _constantParams [ ;;constant throughout experiment
"N-BYCHICKENS" "N-FCS" "N-CHICKEN-FARMS" ;;; chicken types
"N-FGDS" "N-BYDUCKS" "N-DUCK-FARMS" ;;; duck types
"meat-eggs-both-byd"
"N-BARNS" "N-LIVETRADERS"
"N-MATCH-ARENAS" "N-PRACTICE-ARENAS"
"N-MARKETS" "RAI-PER-DUCK"
"pct-flock-road-contam" "pct-flock-field-contam" "pct-flock-visitor-contam"
"latent-period" "road-contam-period" "field-contam-period" "human-contam-period"
"n-nbrs" "visit-radius"
"pct-fgd-deliver"
"LIVETRADER-PICKUP-SCHEDULE" "EGGTRADER-PICKUP-SCHEDULE" "VISIT-SCHEDULE"
"LIVEBIRD-REPLENISH"
"n-flocks-per-pickup-ltrdr"
]
;;only change zeros since BS may have set some values ...
foreach _constantParams [? -> zerosToNumericDefaults ? _ini]
let _replicateParams [ ;;constant throughout one replicate
"pct-road-pen-infect" "pct-road-byc-infect"
"pct-from-visit-infect" "pct-to-visit-infect"
"pct-flock-eggtrader-contam" "pct-eggtrader-flock-infect"
"pct-flock-livetrader-contam" "pct-livetrader-flock-infect"
"pct-fc-byc-infect" "pct-arena-fc-infect"
]
;;for the _replicateParams, use a different _ini table if baseline=mode
;;(otherwise we'll keep the previous assignment to _ini)
if (not member? baseline ["pert" "mode"]) [error "unrecognized baseline"]
let _ini2 _ini
if (baseline = "mode") [
set _ini2 table:from-list (list
["pct-road-pen-infect" 25]
["pct-road-byc-infect" 55]
["pct-from-visit-infect" 15 ]
["pct-to-visit-infect" 20 ]
["pct-flock-eggtrader-contam" 70]
["pct-eggtrader-flock-infect" 70]
["pct-flock-livetrader-contam" 83]
["pct-livetrader-flock-infect" 82]
["pct-fc-byc-infect" 83]
["pct-arena-fc-infect" 48]
(list "n-visits-task" [[] -> 1])
(list "etlinks-task" [[] -> 1])
)
]
;; change any zeros to the (pert or mode) param values
foreach _replicateParams [? -> zerosToNumericDefaults ? _ini2]
;;finally set the tasks
foreach [
"n-visits-task" "etlinks-task"
"n-onsite-eggtraders-fgd-task" "n-onsite-eggtraders-byd-task" "n-onsite-eggtraders-fm-task"
"n-egg-delivery-days-fgd-task" "n-egg-delivery-days-byd-task" "n-egg-delivery-days-fm-task"
"n-egg-pickup-days-fgd-task" "n-egg-pickup-days-byd-task" "n-egg-pickup-days-fm-task"
"n-bird-pickup-days-ltrdr-task"
] [? ->
let _taskname ?
if (runresult _taskname = 0) [ ;;again, only change zeros
zerosToTaskDefaults _taskname _ini
]
]
end
to setupScenario [#scenario] ;;observer proc
;;Called by `setup` *after* `setup-baseline`.
;;Side effects: set specified global parameters.
;;
;;First we choose a baseline (`pert` or `mode`);
;;then we choose a scenario to deviate from the baseline
;;(As it comes last in setup, this may **re**set some values!)
;;Note: use the `scenario` choser to choose a scenario;
;;this proc will then set the implied parameters.
;;CAUTION: a scenario comes last in setup and thus
;; OVERWRITES current values.
;; (For example, those values set by an experiment!)
;;CAUTON: scenario names are incorporated in file names
;; without testing; make sure they will be valid.
;; (Alphanumeric is safe.)
let scenarios table:make
table:put scenarios "none" []
;;;;;; ROAD-FLOCK SCENARIOS ;;;;;;
table:put scenarios "etlinks(low)" (list (list "etlinks-task" [-> 1]))
table:put scenarios "etlinks(high)" (list (list "etlinks-task" [-> 10]))
table:put scenarios "road-flock(high)" (list
["pct-road-pen-infect" 40]
["pct-road-byc-infect" 71]
)
table:put scenarios "road-flock(low)" (list
["pct-road-pen-infect" 0]
["pct-road-byc-infect" 29]
)
table:put scenarios "road-flock(zero)" (list
["pct-road-pen-infect" 0]
["pct-road-byc-infect" 0]
)
;;;;;; VISIT SCENARIOS ;;;;;;
table:put scenarios "visit(veryhigh)" (list
["pct-from-visit-infect" 98]
["pct-to-visit-infect" 100]
)
table:put scenarios "visit(high)" (list
["pct-from-visit-infect" 30]
["pct-to-visit-infect" 40]
)
table:put scenarios "visit(low)" (list
["pct-from-visit-infect" 5]
["pct-to-visit-infect" 10]
)
table:put scenarios "visit(verylow)" (list
["pct-from-visit-infect" 5]
["pct-to-visit-infect" 5]
)
table:put scenarios "visit(zero)" (list
["pct-from-visit-infect" 0]
["pct-to-visit-infect" 0]
)
;;;;;; FIELD SCENARIOS ;;;;;;
table:put scenarios "fgdsStay" (list
["prop-fgd-barntofield" 0]
)
;;;;;; TRADER SCENARIOS ;;;;;;
;; (used by eggtrade experiment)
table:put scenarios "eggtrade(high)" (list
["pct-flock-eggtrader-contam" 88]
["pct-eggtrader-flock-infect" 88]
)
table:put scenarios "eggtrade(low)" (list
["pct-flock-eggtrader-contam" 53]
["pct-eggtrader-flock-infect" 55]
)
;; (used by livetrade experiment)
table:put scenarios "livetrade(high)" (list
["pct-flock-livetrader-contam" 95]
["pct-livetrader-flock-infect" 92]
)
table:put scenarios "livetrade(low)" (list
["pct-flock-livetrader-contam" 68]
["pct-livetrader-flock-infect" 68]
)
;pick out the scenario
; and set the parameter values for the chosen scenario
foreach table:get scenarios #scenario [kv ->
run (word "set " first kv " " last kv)
]
end
;; to old-setupScenario ;;observer proc
;; ;;Called by `setup` *after* `setup-baseline`.
;; ;;Side effects: set specified global parameters.
;; ;;
;; ;;First we choose a baseline (`pert` or `mode`);
;; ;;then we choose a scenario to deviate from the baseline
;; ;;(As it comes last in setup, this may **re**set some values!)
;; ;;Note: use the `scenario` choser to choose a scenario;
;; ;;this proc will then set the implied parameters.
;; ;;CAUTION: a scenario comes last in setup and thus
;; ;; OVERWRITES current values.
;; ;; (For example, those values set by an experiment!)
;; ;;CAUTON: scenario names are incorporated in file names
;; ;; without testing; make sure they will be valid.
;; ;; (Alphanumeric is safe.)
;; let _set-params []
;; if (scenario = "none") [] ;; change no values
;; ;;;;;; ROAD-FLOCK SCENARIOS ;;;;;;
;; if (scenario = "etlinks(low)") [
;; set _set-params
;; (list
;; (list "etlinks-task" [[] -> [1]])
;; )
;; ]
;; if (scenario = "etlinks(high)") [
;; set _set-params
;; (list
;; (list "etlinks-task" [[] -> [10]])
;; )
;; ]
;; if (scenario = "road-flock(high)") [
;; set _set-params
;; [
;; ["pct-road-pen-infect" 40]
;; ["pct-road-byc-infect" 71]
;; ]
;; ]
;; if (scenario = "road-flock(low)") [
;; set _set-params
;; [
;; ["pct-road-pen-infect" 0]
;; ["pct-road-byc-infect" 29]
;; ]
;; ]
;; if (scenario = "road-flock(zero)") [
;; set _set-params
;; [
;; ["pct-road-pen-infect" 0]
;; ["pct-road-byc-infect" 0]
;; ]
;; ]
;; ;;;;;; VISIT SCENARIOS ;;;;;;
;; if (scenario = "visit(veryhigh)") [
;; set _set-params
;; [
;; ["pct-from-visit-infect" 98]
;; ["pct-to-visit-infect" 100]
;; ]
;; ]
;; if (scenario = "visit(high)") [
;; set _set-params
;; [
;; ["pct-from-visit-infect" 30]
;; ["pct-to-visit-infect" 40]
;; ]
;; ]
;; if (scenario = "visit(low)") [
;; set _set-params
;; [
;; ["pct-from-visit-infect" 5]
;; ["pct-to-visit-infect" 10]
;; ]
;; ]
;; if (scenario = "visit(zero)") [
;; set _set-params
;; [
;; ["pct-from-visit-infect" 0]
;; ["pct-to-visit-infect" 0]
;; ]
;; ]
;; ;;;;;; EGGTRADER SCENARIOS ;;;;;;
;; ;; (used by eggtrade experiment)
;; if (scenario = "eggtrade(high)") [
;; set _set-params
;; [
;; ["pct-flock-eggtrader-contam" 88]
;; ["pct-eggtrader-flock-infect" 88]
;; ]
;; ]
;; if (scenario = "eggtrade(low)") [
;; set _set-params
;; [
;; ["pct-flock-eggtrader-contam" 53]
;; ["pct-eggtrader-flock-infect" 55]
;; ]
;; ]
;; ;;set the parameter values for the chosen scenario
;; foreach _set-params [? -> run (word "set " first ? " " last ?)]
;; end
to record-params
;;record the parameter values used for the run
;; (must call this *after* `set-scenario`)
let _filename (word "out/params/" base-filename ".txt")
carefully [file-delete _filename] []
file-open _filename
let _params [
"scenario"
"pct-road-byc-infect"
"pct-road-pen-infect"
"pct-from-visit-infect"
"pct-to-visit-infect"
"pct-flock-eggtrader-contam"
"pct-eggtrader-flock-infect"
]
foreach _params [? -> file-print (word ? " : " run-result ?)]
file-close
end
to initialize-locations-file
;;;initialize the file of the transmission locations with initial location
;; delete possible old file for writing the transmission locations
carefully [file-delete locations-file][]
;; write the initial locations
file-open locations-file
file-print "positions after setup:"
ask turtle-set poultry-types [
file-show patch-here
if (member? flu-state "ei") [error "nobody should be infected yet"]
]
file-close
log2file 5 locations-file ;; log the filename of the locations file
end
;;;;;;;;;
;Patches;
;;;;;;;;;
;; Even though our nodes (intersections) are turtles rather than patches,
;; we must call setup-roads *before* `setup-patches` (which has an error check),
;; because the latter calls `setup-road-patches` (which needs our roads).
to setup-roads
;;first we create the road intersections (later we link them)
let nodes table:make ;;we will map ids to turtles (our nodes/intersections)
file-open "intersections.txt" ;;SSV file; separator is a *single* space
while [not file-at-end?] [
let data file-read-line
if not (first data = "#") [ ;;ignore comment lines
set data split data " " ;;split on *single* (!!) space
;; cast the co-ordinates from strings to numbers
let x read-from-string item 0 data
let y read-from-string item 1 data
;; get the intersection id and intersection type
let _id item 2 data
;let _itype last data ;;chk: intersection type not currently used
ask patch x y [
sprout-intersections 1 [
set homebase patch-here
setxy x y ;;in case x and y are not integers
table:put nodes _id self ;;map id to intersection (node)
;;set label (word "(" _id ")")
]
]
]
]
file-close
log2file 5 (word "nodes: " nodes)
;;next we represent roads by linking intersections
file-open "roads.txt" ;;SSV file; separator is a *single* space
while [not file-at-end?] [
let data file-read-line
if not (first data = "#") [ ;; prevent reading of the comment line
set data split data " " ;; split location indicated by one (!) space
let node1 table:get nodes item 0 data
let node2 table:get nodes item 1 data
ask node1 [
create-road-link-with node2 [
set roadtype last data
]
]
]
]
file-close
log2file 5 (word "roads & types:\n" [list self roadtype] of road-links)
end ;;END:setup-roads
to setup-patches ;;observer proc
if not (count road-links > 0) [error "must setup-roads *before* setup-patches"]
;; First, initialize all patches as growing rice fields (afterwards, we'll repurpose some of them)
ask patches [
set patch-type "ricefield" ;;this inital value changes whenever we change the patch type
set field-state "growing" ;;we change this for non-field patch types
set field-patches (patch-set ) ;empty
set occupant nobody
set road-access min-one-of intersections [distance myself]
;; set pcontam-until 0 ; default
]
setup-road-patches
place-objects-along-roads ;;(arenas, markets, coops, barns, & two "out of DKY" patches)
setup-ricefields
end ;;END:setup-patches
to setup-road-patches
;;let every road keep a set of neaby patches
ask road-links [
set road-patches patches with [patch-near-link? self myself]
ask road-patches [
set pcontam-period road-contam-period
set field-state ""
;;some road patches may later become barns, etc., but initially:
set patch-type "road"
]
]
end
to place-objects-along-roads
;;;; PLACE OBJECTS ALONG ROADS (arenas, markets, coops, barns, two "out of DKY" patches ;chk )
;; patches along roads are currently road patches (but that will now change)
if (count patches with [patch-type = "road"] = 0) [error "must first setup road patches"]
let _major-roads road-links with [roadtype = "major_road"]
let _loose-roads road-links with [roadtype = "loose_road"]
let _small-roads road-links with [roadtype = "small_road"]
;; place out-of-subdistrict-patches (location for flocks that "leave" the district)
;; (do this first so it won't overwrite an object "placement")
;; WARNING: using hard-coded patch coordinates (to match roads) chkchkchk
;; (can probably put these on the edge chkchk)
set out-of-subdistrict-patches (patch-set patch min-pxcor 30 patch max-pxcor 30)
ask out-of-subdistrict-patches [set patch-type "out" set field-state ""]
;; place match arenas
place-along-roads N-MATCH-ARENAS "match-arena" _loose-roads
set match-arenas patches with [ patch-type = "match-arena" ]
;; place practice arenas
let _n3 int (N-PRACTICE-ARENAS / 3)
place-along-roads-north _n3 "practice-arena" _loose-roads ;;chkchk
place-along-roads-south _n3 "practice-arena" _loose-roads
place-along-roads (N-PRACTICE-ARENAS - (2 * _n3)) "practice-arena" _loose-roads
set practice-arenas patches with [ patch-type = "practice-arena" ]
;; place markets
place-along-roads N-MARKETS "market" _major-roads
set markets patches with [ patch-type = "market" ]
;; place cooperatives (no cooperatives in baseline!)
if (n-cooperatives < 0 or n-cooperatives != round n-cooperatives) [
error "n-cooperatives must be nonnegative integer"
]
place-along-roads-north n-cooperatives "cooperative" _major-roads
set cooperatives patches with [ patch-type = "cooperative" ]
;; place barns (60%, 30% and 10% around major, loose and small roads)
place-along-roads round (0.6 * N-BARNS) "barn" _major-roads
place-along-roads round (0.3 * N-BARNS) "barn" _loose-roads
place-along-roads round (0.1 * N-BARNS) "barn" _small-roads
set barns patches with [ patch-type = "barn" ]
end ;;END:place-objects-along-roads
to place-along-roads [#num #type #roads] ;;observer proc
let _patches ((patch-set [road-patches] of #roads) with [(not any? turtles-here) and (patch-type = "road")])
ask n-of #num _patches [
set patch-type #type
set field-state ""
]
end
to place-along-roads-north [#num #type #roads] ;;observer proc
let _patches ((patch-set [road-patches] of #roads) with [(not any? turtles-here) and (patch-type = "road") and ( pycor > 0)])
ask n-of #num _patches [
set patch-type #type
set field-state ""
]
end
to place-along-roads-south [#num #type #roads] ;;observer proc
let _patches ((patch-set [road-patches] of #roads) with [(not any? turtles-here) and (patch-type = "road") and ( pycor < 0)])
ask n-of #num _patches [
set patch-type #type
set field-state ""
]
end
to setup-ricefields ;;observer proc
set rice-fields (patches with [ field-state = "growing" ]) ;;finalize global variable
ask rice-fields [set pcontam-period field-contam-period] ;; are these the only agents for this?
create-fields
ask access-fields [
harvest-field ;;changes field-state (and color), makes rai available
]
log2file 5 (word "total rai available at sim start is " sum [rai] of access-fields)
log2file 5 (word "this shd match " sum [rai] of patches)
end
to create-fields ;; observer proc
if (DEBUG > 5) [log2file 5 "enter proc: create-fields"]
let total-ricefield-rai 6552 ;;shd be a global chkchkchk
let num-field-patches count rice-fields
if (num-field-patches = 0) [error "first establish rice fields"]
let av-rai-per-patch (total-ricefield-rai / num-field-patches)
let most-likely (150 / av-rai-per-patch) ;; PERT most likely value (shd be global chkchk)
let spacing ceiling sqrt most-likely
let xvals n-values floor (world-width / spacing) [? -> spacing / 2 + ? * spacing]
let yvals n-values floor (world-height / spacing) [? -> spacing / 2 + ? * spacing]
let _targetradius 9
;; create the field-access patches
let _y min-pycor + (_targetradius / 2)
while [_y < max-pycor] [
let _x min-pxcor + (_targetradius / 2)
while [_x < max-pxcor] [
let _new-access-field patch _x _y
if ([field-state] of _new-access-field = "growing") [
set access-fields (patch-set access-fields _new-access-field)
]
set _x (_x + _targetradius)
]
set _y (_y + _targetradius)
]
log2file 5 (word (count access-fields) " access fields created")
;; number the access fields and set their size
let _n-access-fields 0
ask access-fields [
set _n-access-fields (_n-access-fields + 1)
set field-num _n-access-fields
set rai random-pert 20 150 610 ;;chk is this the best way to set field size??
log2file 5 (word "provides access to " rai " rai")
]
;; make minimal fields around the access patch
ask access-fields [
let _field patch-set [neighbors] of neighbors
ask _field with [field-state = "growing" and field-num = 0] [ ;; does *not* include the access-field patch
set field-num [field-num] of myself
]
]
;; fill in the fields
ask access-fields [
let _n-patches (rai / 2)
let _radius ceiling sqrt (_n-patches / 3)
let _field patches in-radius _radius with [field-state = "growing" and field-num = 0] ;; does *not* include the access-field patch
ask _field [
set field-num [field-num] of myself
]
]
;; attach remaining rice-field patches to fields
ask patches with [field-state = "growing" and field-num = 0] [
let _field-patches patches with [field-state = "growing" and field-num != 0]
set field-num [field-num] of min-one-of _field-patches [distance myself]
]
ask access-fields [
set field-patches (patches with [field-num = [field-num] of myself]) ;; *include* the access patch
]
if (DEBUG > 5) [log2file 5 "exit proc: create-fields"]
end
to harvest-field ;;patch (access field) proc
if (DEBUG > 5) [log2file 5 "enter proc: harvest-field"]
if (field-state != "growing") [ error (word "field-state '" field-state "' should be 'growing'")]
if (not any? field-patches) [ error "apply harvest-field proc only to access fields"]
;;set rai random-pert 20 150 610 ;;chkchkchk do we still want this?? already used when create access fields!
ask field-patches [set field-state "harvested"]
if (DEBUG > 5) [log2file 5 "exit proc: harvest-field"]
end
to fallow [#field] ;;access-field (patch) proc
if (DEBUG > 5) [log2file 5 "enter proc: fallow"]
let _field-patches [field-patches] of #field
let _field-state [field-state] of #field
;first, do some error checks
if (_field-patches = nobody) [ error "apply `fallow` only to access fields"]
if (_field-state != "harvested") [
let _msg
(word
"patch " #field
"has field-num " [field-num] of #field
" and field-patches " _field-patches
)
log2file 5 _msg
error (word _msg "field-state '" field-state "' should be 'harvested'")
]
;finally, do the actual fallowing
ask #field [set rai 0] ;; "wasted rai" chkchk! shd separate area from food-days
ask _field-patches [set field-state "fallow"]
if (DEBUG > 5) [log2file 5 "exit proc: fallow"]
end
;;;;;;;;;;;;
;; Agents ;;
;;;;;;;;;;;;
to setup-agents ;;observer proc; sets up flocks and owners, and traders
if (DEBUG > 5) [log2file 5 "enter proc: setup-agents"]
setup-fgds-and-owners