-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBali31.nlogo
1291 lines (1166 loc) · 38.6 KB
/
Bali31.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
breed [subaks subak]
breed [dams dam]
breed [damdams damdam]
breed [damsubaks damsubak]
breed [subakdams subakdam]
breed [subaksubaks subaksubak]
subaks-own [old? mip stillgrowing dpests pestneighbors damneighbors totharvestarea area
SCC ;Subak's crop plan
sd ; start date (month)
SCCc; help variable during imitation process
sdc ;help variable during imitation process
pests
nMS ; counter for number of subaks in masceti
MS ; masceti
dmd masceti ulunswi pyharvest pyharvestha WSS harvest crop ricestage Ymax pest-damage pestloss totLoss source return]
dams-own [flow0 flow elevation
WSarea ; WSarea is area (ha) of dams' watershed
damht rain
EWS ; Effective Watershed Area
areadam Runoff d1 d3 XS
WSD ; Water Stress Dam
totWSD]
damdams-own [a b distanceab]
damsubaks-own [a b distanceab]
subakdams-own [a b distanceab]
subaksubaks-own [a b distanceab]
globals [ subak-data dam-data subaksubak-data subakdam-data new-subaks subaks_array dams_array subakdams_array damsubaks_array Rel Rem Reh month ET RRT LRS Xf devtime yldmax pestsens growthrate cropuse totpestloss totpestlossarea totWS totWSarea avgharvestha]
to setup
ca
set-default-shape subaks "circle"
set-default-shape dams "square"
set-default-shape damdams "line"
set-default-shape damsubaks "line"
set-default-shape subakdams "line"
set-default-shape subaksubaks "line"
set subaks_array [ ]
set dams_array []
set subakdams_array []
set damsubaks_array []
set devtime [0 6 4 3] ; development time for crops
set yldmax [0 5 5 10] ; maximum yld of rice crops
set pestsens [0 0.5 0.75 1.0] ; sensitivity of crops to pests
set growthrate [0.1 2.2 2.2 2.2 0.33] ; monthly growth rate parameter
set cropuse [0 0.015 0.015 0.015 0.003] ; use of water per crop parameter
set growthrate replace-item 1 growthrate pestgrowth-rate
set growthrate replace-item 2 growthrate pestgrowth-rate
set growthrate replace-item 3 growthrate pestgrowth-rate
set month 0
set totpestloss 0
set totpestlossarea 0
set totWS 0
set totWSarea 0
set avgharvestha 0
set ET 50 / 30000 ;between 40 and 60 Evapotranspiration rate, mm/mon => m/d
set RRT ET + 50 / 30000 ;between 0 and 100 Rain-Runoff threshold for 1:1, mm/mon => m/d
set LRS 1 - ET / RRT ;LowRainSlope, below threshold for RR relation
set Xf 1.0 ;between 0.8 and 1.2 X factor for changing minimum groundwater flow
load-data
ask subaks [set old? false]
set dams_array sort-by [ [?1 ?2] -> [who] of ?1 < [who] of ?2 ] dams
set subaks_array sort-by [ [?1 ?2] -> [who] of ?1 < [who] of ?2 ] subaks
ask dams [set areadam 0]
ask subaks [
let returndam self
let sourcedam self
let tempsubak self
set stillgrowing false
set returndam [b] of one-of subakdams with [a = tempsubak]
set sourcedam [a] of one-of damsubaks with [b = tempsubak]
let areasubak area
ifelse (returndam = sourcedam) [
ask returndam [set areadam areadam + areasubak]
][
ask sourcedam [set areadam areadam + areasubak]
]
set pyharvest 0
set pyharvestha 0
; initial cropping plans are randomly allocated
set SCC random nrcropplans
set sd random 12
cropplan SCC sd
set totharvestarea 0
if Color_subaks = "cropping plans" [set color SCC * 10 + 5]; + sd]
]
ask dams [set flow0 flow0 * Xf * 86400]
ask dams [set EWS WSarea - areadam]
; Effective Watershed Area EWS of each dam is reduced by cultiv'n area areadam because rain onto sawa enters the irrig'n system meeting immediate demand directly or passing on to the downstream irrigation point
ask subaks [
let sdhelp 0
set SCC random nrcropplans
set sd random 12
set pests 0.01
set old? false
cropplan SCC sd
ricestageplan SCC sd
let subak1 self
ask subaks [
if [source] of self = [source] of subak1 [ask subak1 [set damneighbors lput myself damneighbors]]
]
]
reset-ticks
end
to go
ask subaks [set mip sd + month if mip > 11 [set mip mip - 12]]
ask subaks [
cropplan SCC mip
if stillgrowing [if ((crop = 0) or (crop = 4)) [set stillgrowing false]]
]
demandwater
determineflow
growrice
growpest
determineharvest
if month = 11 [set totpestloss totpestloss / totpestlossarea set totWS totWS / totWSarea]
if month = 11 [plot-figs]
if month = 11 [imitatebestneighbors]
ifelse month = 11
[set month 0 set totWSarea 0 set totWS 0 ask subaks [set pyharvest 0 set pyharvestha 0 set totpestloss 0 set totpestlossarea 0 set totharvestarea 0 set pests 0.01]]
[set month month + 1]
tick
end
to demandwater
; determine the water demand for different subaks
ask dams [
if rainfall-scenario = "low" [rainfall damht 0]
if rainfall-scenario = "middle" [rainfall damht 1]
if rainfall-scenario = "high" [rainfall damht 2]
set rain rain / 30000
ifelse rain < RRT [
set Runoff rain * LRS * EWS * 10000 ; 'm/d * ha* m2/ha => m3/d for basin
][
set Runoff (rain - ET) * EWS * 10000
if (Runoff < 0) [set Runoff 0]
]]
; Demand for each Subak based on cropping pattern, less any rainfall.
; dmd may be + or - because local rain can exceed demand ==> an excess.
ask subaks [
; cropuse is m/d demand for the 4 crops:
if Color_subaks = "crops" [
if crop = 0 [ set color green]
if crop = 1 [ set color cyan]
if crop = 2 [ set color yellow]
if crop = 3 [ set color white]
if crop = 4 [ set color red]
]
set dmd item crop cropuse - [rain] of return
set dmd dmd * area * 10000
]
; Sum the partial demands for areas 1, 2, & 3 of each dam
ask dams [set d1 0 set d3 0 set XS 0 ]
; In each case, put dmd<0 into excess (XS)
; Total dmd for all Subaks inside basin taking flow before the dam
ask subaks [
let returndam self
let sourcedam self
let tempsubak self
set returndam [b] of one-of subakdams with [a = tempsubak]
set sourcedam [a] of one-of damsubaks with [b = tempsubak]
ifelse (returndam = sourcedam)
[
let dmdsubak dmd
ifelse dmd > 0 [
ask returndam [set d1 d1 + dmdsubak]
][
ask returndam [set XS XS - dmdsubak]]]
; Any excess of rain>dmd for Subaks in basin but source outside
; Excess always returned to this dam, i.e. location = the downstream dam
[
let dmdsubak dmd
if dmd < 0 [ask returndam [set XS XS - dmdsubak]]
; Downstream irrig'n dmd drawn from this dam; >0 only, no excess allowed
if dmd > 0 [ask sourcedam [set d3 d3 + dmdsubak]]]]
end
to determineflow
let bool 0
ask dams [
if bool = 0 [
set bool 1 ; dirty trick to make sure upstream subaks are updated first
foreach dams_array [
let dam1 self
set flow flow0 + Runoff - d1 + XS - d3
foreach dams_array [
let flowadd flow
if (count damdams with [a = self and b = dam1] + count damdams with [a = dam1 and b = self]) > 0
[
ask dam1 [set flow flow + flowadd]
]
]
ifelse flow < 0 [
ifelse ((d1 + d3) = 0) [][
set WSD 1 + flow / (d1 + d3)
set d1 d1 * WSD
set d3 d3 * WSD
set flow 0 ; waterstress
]] [set WSD 1]
set totWSD totWSD + WSD
]]]
ask subaks [
let subak1 self
set WSS [WSD] of [a] of one-of damsubaks with [b = subak1]
set dmd dmd * WSS]
end
to growrice
ask subaks [
let subak1 self
let WSDhelp self
if crop = 0 [set ricestage 0 set WSS 1] ;Fallow period
if crop = 4 [set ricestage 0 set WSS 1] ; Growing paliwiga
if ((crop = 1) or (crop = 2) or (crop = 3)) [
set WSS [WSD] of source
set ricestage ricestage + (WSS / (item crop devtime))
]]
end
to growpest
let dxx 100
let dt 30 ;days
let dc 0
let cs 0
let cN 0
let minimumpests 0.01
ask subaks [
let subak1 self
set cs 4 * pests
ask subaks [
let subak2 self
ifelse member? subak1 pestneighbors [set cN pests - [pests] of subak1][set cN 0]
set cs cs + cN]
set dc (pestdispersal-rate / dxx) * ( cs - (4 * pests)) * dt ; this is the net change in pest dispersed to or from the subak
set dpests ((item crop growthrate) * (pests + 0.5 * dc)) + (0.5 * dc)
if dpests < minimumpests [set dpests minimumpests]]
ask subaks [set pests dpests if Color_subaks = "pests" [set color 62 + pests ]]
end
to determineharvest
let hy 0
let croph 0
let cropf 0
ask subaks [
set harvest 0
if ((crop = 1) or (crop = 2) or (crop = 3)) [set stillgrowing true]
set croph crop
cropplan SCC (mip + 1)
set cropf crop
set crop croph
if (cropf = 0) or (cropf = 4)
[
set Ymax ricestage * (item crop yldmax)
set pest-damage 1 - pests * (item crop pestsens)
if pest-damage < 0 [set pest-damage 0]
set harvest Ymax * pest-damage
set pestloss pestloss + Ymax * (1 - pest-damage) * area
set totLoss totLoss + pestloss
set hy hy + harvest * area
set pyharvest pyharvest + harvest * area
set pyharvestha pyharvestha + harvest
set totpestloss totpestloss + area * (1 - pest-damage) * Ymax
set totpestlossarea totpestlossarea + area
set totWS totWS + (1 - ricestage) * area
set totWSarea totWSarea + area
set totharvestarea totharvestarea + area
]]
end
to imitatebestneighbors
let minharvest 0
let maxharvest 0
ask subaks [
let bestneighbor self
set minharvest pyharvestha
set maxharvest minharvest
set SCCc SCC
set sdc sd
foreach pestneighbors [ [?1] ->
ask ?1 [
if pyharvestha > maxharvest
[
set maxharvest pyharvestha
set bestneighbor self
]]
if maxharvest > minharvest [set SCCc [SCC] of bestneighbor set sdc [sd] of bestneighbor] ]
]
ask subaks [
set SCC SCCc
set sd sdc
if Color_subaks = "cropping plans" [
set color SCC * 10 + 5]]
end
to setup-plot
set-current-plot "Harvest"
set-plot-y-range 0 30
set-current-plot "Pestloss"
set-plot-y-range 0 1
set-current-plot "Waterstress"
set-plot-y-range 0 1
end
to plot-figs
let totarea 0
let totharvest 0
set-current-plot "Harvest"
ask subaks [
set totarea totarea + totharvestarea
set totharvest totharvest + pyharvest
]
set-current-plot-pen "harvest"
set avgharvestha totharvest / totarea
plot avgharvestha
set-current-plot "Pestloss"
plot totpestloss
set-current-plot "Waterstress"
plot totWS
end
;========================= data ========================================
to load-data
ifelse ( file-exists? "subakdata.txt" )
[
;; We are saving the data into a list, so it only needs to be loaded once.
set subak-data []
file-open "subakdata.txt"
while [ not file-at-end? ]
[
;; file-read gives you variables.
;; We store them in a double list (ex [[1 2 3 4 5 6] [1 2 3 4 5 6] ...
set subak-data sentence subak-data (list (list file-read file-read file-read file-read file-read file-read))
]
file-close
]
[ user-message "There is no subakdata.txt file in current directory!" ]
ifelse ( file-exists? "damdata.txt" )
[
set dam-data []
file-open "damdata.txt"
while [ not file-at-end? ]
[set dam-data sentence dam-data (list (list file-read file-read file-read file-read file-read file-read file-read))]
file-close
]
[ user-message "There is no damdata.txt file in current directory!" ]
ifelse ( file-exists? "subaksubakdata.txt" )
[
set subaksubak-data []
file-open "subaksubakdata.txt"
while [ not file-at-end? ]
[set subaksubak-data sentence subaksubak-data (list (list file-read file-read))]
file-close
]
[ user-message "There is no subaksubakdata.txt file in current directory!" ]
ifelse ( file-exists? "subakdamdata.txt" )
[
set subakdam-data []
file-open "subakdamdata.txt"
while [ not file-at-end? ]
[ set subakdam-data sentence subakdam-data (list (list file-read file-read file-read))]
file-close
]
[ user-message "There is no subakdamdata.txt file in current directory!" ]
foreach subak-data [ [?1] ->
create-subaks 1 [set color white setxy (item 1 ?1) (item 2 ?1) set area item 3 ?1 set masceti item 4 ?1 set ulunswi item 5 ?1
set pestneighbors [] set damneighbors []
set subaks_array lput self subaks_array
if Color_subaks = "Temple groups" [
if masceti = 1 [set color white]
if masceti = 2 [set color yellow]
if masceti = 3 [set color red]
if masceti = 4 [set color blue]
if masceti = 5 [set color cyan]
if masceti = 6 [set color pink]
if masceti = 7 [set color orange]
if masceti = 8 [set color lime]
if masceti = 9 [set color sky]
if masceti = 10 [set color violet]
if masceti = 11 [set color magenta]
if masceti = 12 [set color green]
if masceti = 13 [set color turquoise]
if masceti = 14 [set color brown]
]] ]
foreach dam-data [ [?1] ->
create-dams 1 [ set color yellow setxy (item 1 ?1) (item 2 ?1) set flow0 item 3 ?1 set elevation item 4 ?1 set WSarea item 5 ?1 set damht item 6 ?1
set dams_array lput self dams_array] ]
linkdams
foreach subaksubak-data [ [?1] -> make-subaksubak (item first ?1 subaks_array) (item last ?1 subaks_array) ]
foreach subakdam-data [ [?1] -> make-subakdams (item first ?1 subaks_array) (item (item 1 ?1) dams_array) (item last ?1 dams_array) ]
end
to cropplan [nr m]
if m > 11 [set m m - 12]
; for each month a crop is defined
let cropplan0 [3 3 3 0 3 3 3 0 3 3 3 0]
let cropplan1 [3 3 3 0 0 0 3 3 3 0 0 0]
let cropplan2 [3 3 3 0 3 3 3 0 0 0 0 0]
let cropplan3 [3 3 3 0 0 3 3 3 0 0 0 0]
let cropplan4 [3 3 3 0 0 0 0 3 3 3 0 0]
let cropplan5 [3 3 3 0 0 0 0 0 3 3 3 0]
let cropplan6 [1 1 1 1 1 1 0 2 2 2 2 0]
let cropplan7 [1 1 1 1 1 1 0 3 3 3 0 0]
let cropplan8 [1 1 1 1 1 1 0 0 3 3 3 0]
let cropplan9 [1 1 1 1 1 1 0 0 0 0 0 0]
let cropplan10 [2 2 2 2 0 0 2 2 2 2 0 0]
let cropplan11 [2 2 2 2 0 2 2 2 2 0 0 0]
let cropplan12 [2 2 2 2 0 0 0 2 2 2 2 0]
let cropplan13 [2 2 2 2 0 0 3 3 3 0 0 0]
let cropplan14 [2 2 2 2 0 3 3 3 0 0 0 0]
let cropplan15 [2 2 2 2 0 0 0 3 3 3 0 0]
let cropplan16 [2 2 2 2 0 0 0 0 3 3 3 0]
let cropplan17 [3 3 3 0 0 2 2 2 2 0 0 0]
let cropplan18 [3 3 3 0 0 0 2 2 2 2 0 0]
let cropplan19 [3 3 3 0 2 2 2 2 0 0 0 0]
let cropplan20 [3 3 3 0 0 0 0 2 2 2 2 0]
if nr = 0 [set crop item m cropplan0]
if nr = 1 [set crop item m cropplan1]
if nr = 2 [set crop item m cropplan2]
if nr = 3 [set crop item m cropplan3]
if nr = 4 [set crop item m cropplan4]
if nr = 5 [set crop item m cropplan5]
if nr = 6 [set crop item m cropplan6]
if nr = 7 [set crop item m cropplan7]
if nr = 8 [set crop item m cropplan8]
if nr = 9 [set crop item m cropplan9]
if nr = 10 [set crop item m cropplan10]
if nr = 11 [set crop item m cropplan11]
if nr = 12 [set crop item m cropplan12]
if nr = 13 [set crop item m cropplan13]
if nr = 14 [set crop item m cropplan14]
if nr = 15 [set crop item m cropplan15]
if nr = 16 [set crop item m cropplan16]
if nr = 17 [set crop item m cropplan17]
if nr = 18 [set crop item m cropplan18]
if nr = 19 [set crop item m cropplan19]
if nr = 20 [set crop item m cropplan20]
end
to ricestageplan [nr m]
let ricestageplan0 [0 0.33 0.67 0 0 0.33 0.67 0 0 0.33 0.67 0]
let ricestageplan1 [0 0.33 0.67 0 0 0 0 0.33 0.67 0 0 0]
let ricestageplan2 [0 0.33 0.67 0 0 0.33 0.67 0 0 0 0 0]
let ricestageplan3 [0 0.33 0.67 0 0 0 0.33 0.67 0 0 0 0]
let ricestageplan4 [0 0.33 0.67 0 0 0 0 0 0.33 0.67 0 0]
let ricestageplan5 [0 0.33 0.67 0 0 0 0 0 0 0.33 0.67 0]
let ricestageplan6 [0 0.16 0.33 0.5 0.67 0.84 0 0 0.25 0.5 0.75 0]
let ricestageplan7 [0 0.16 0.33 0.5 0.67 0.84 0 0 0.33 0.67 0 0]
let ricestageplan8 [0 0.16 0.33 0.5 0.67 0.84 0 0 0 0.33 0.67 0]
let ricestageplan9 [0 0.16 0.33 0.5 0.67 0.84 0 0 0 0 0 0]
let ricestageplan10 [0 0.25 0.5 0.75 0 0 0 0.25 0.5 0.75 0 0]
let ricestageplan11 [0 0.25 0.5 0.75 0 0 0.25 0.5 0.75 0 0 0]
let ricestageplan12 [0 0.25 0.5 0.75 0 0 0 0 0.25 0.5 0.75 0]
let ricestageplan13 [0 0.25 0.5 0.75 0 0 0 0.33 0.67 0 0 0]
let ricestageplan14 [0 0.25 0.5 0.75 0 0 0.33 0.67 0 0 0 0]
let ricestageplan15 [0 0.25 0.5 0.75 0 0 0 0 0.33 0.67 0 0]
let ricestageplan16 [0 0.25 0.5 0.75 0 0 0 0 0 0.33 0.67 0]
let ricestageplan17 [0 0.33 0.67 0 0 0 0.25 0.5 0.75 0 0 0]
let ricestageplan18 [0 0.33 0.67 0 0 0 0 0.25 0.5 0.75 0 0]
let ricestageplan19 [0 0.33 0.67 0 0 0.25 0.5 0.75 0 0 0 0]
let ricestageplan20 [0 0.33 0.67 0 0 0 0 0 0.25 0.5 0.75 0]
if nr = 0 [set ricestage item m ricestageplan0]
if nr = 1 [set ricestage item m ricestageplan1]
if nr = 2 [set ricestage item m ricestageplan2]
if nr = 3 [set ricestage item m ricestageplan3]
if nr = 4 [set ricestage item m ricestageplan4]
if nr = 5 [set ricestage item m ricestageplan5]
if nr = 6 [set ricestage item m ricestageplan6]
if nr = 7 [set ricestage item m ricestageplan7]
if nr = 8 [set ricestage item m ricestageplan8]
if nr = 9 [set ricestage item m ricestageplan9]
if nr = 10 [set ricestage item m ricestageplan10]
if nr = 11 [set ricestage item m ricestageplan11]
if nr = 12 [set ricestage item m ricestageplan12]
if nr = 13 [set ricestage item m ricestageplan13]
if nr = 14 [set ricestage item m ricestageplan14]
if nr = 15 [set ricestage item m ricestageplan15]
if nr = 16 [set ricestage item m ricestageplan16]
if nr = 17 [set ricestage item m ricestageplan17]
if nr = 18 [set ricestage item m ricestageplan18]
if nr = 19 [set ricestage item m ricestageplan19]
if nr = 20 [set ricestage item m ricestageplan20]
end
to linkdams
make-damdam (item 0 dams_array) (item 5 dams_array)
make-damdam (item 5 dams_array) (item 6 dams_array)
make-damdam (item 6 dams_array) (item 8 dams_array)
make-damdam (item 1 dams_array) (item 7 dams_array)
make-damdam (item 7 dams_array) (item 8 dams_array)
make-damdam (item 2 dams_array) (item 9 dams_array)
make-damdam (item 3 dams_array) (item 9 dams_array)
make-damdam (item 4 dams_array) (item 9 dams_array)
make-damdam (item 9 dams_array) (item 10 dams_array)
make-damdam (item 10 dams_array) (item 11 dams_array)
end
to rainfall [hight level]
; rainfall scenarios for different latitudes
if (hight = 0) [
set Rel [114 118 100 8 21 0 0 2 1 0 28 114]
set Rem [252 269 167 67 96 96 110 48 64 101 150 271]
set Reh [390 420 234 126 171 192 220 94 127 202 272 428]
levelrainfall level]
if hight = 1 [
set Rel [200 167 131 63 42 62 0 0 0 26 92 156]
set Rem [364 278 230 135 131 153 160 84 109 194 220 298]
set Reh [528 389 329 207 220 244 320 168 218 362 348 440]
levelrainfall level]
if hight = 2 [
set Rel [215 227 205 100 121 51 6 4 67 45 138 243]
set Rem [282 274 319 181 206 141 95 138 249 265 267 327]
set Reh [349 321 433 262 291 231 184 272 431 485 396 411]
levelrainfall level]
if hight = 3 [
set Rel [148 210 120 53 53 54 8 13 0 45 112 192]
set Rem [348 291 221 138 124 160 183 106 136 179 241 312]
set Reh [548 372 322 223 195 266 358 199 272 313 370 432]
levelrainfall level]
if hight = 4 [
set Rel [289 234 249 125 78 13 0 6 10 57 141 281]
set Rem [418 384 372 246 208 128 114 68 77 162 268 405]
set Reh [547 534 495 367 338 243 228 130 144 267 395 529]
levelrainfall level]
end
to levelrainfall [level]
if level = 0 [set rain item month Rel]
if level = 1 [set rain item month Rem]
if level = 2 [set rain item month Reh]
end
to make-damdam [dam1 dam2]
create-damdams 1
[
set color blue
set a dam1
set b dam2
reposition-edges
]
end
to make-subaksubak [s1 s2]
create-subaksubaks 1
[
set color green
set a s1
set b s2
reposition-edges
]
ask s1 [set pestneighbors lput s2 pestneighbors]
end
to make-subakdams [s1 s2 s3]
create-subakdams 1
[
set color blue
set a s1
set b s2
reposition-edges
if not viewdamsubaks [set size 0]
]
create-damsubaks 1
[
set color blue
set a s3
set b s1
reposition-edges
if not viewdamsubaks [set size 0]
]
ask s1 [set source s3 set return s2]
end
to reposition-edges ;; edges procedure
setxy ([xcor] of a) ([ycor] of a)
set size distance b
set distanceab distance b
;; watch out for special case where a and b are
;; at the same place
if size != 0
[
;; position edges at midpoint between a and b
set heading towards b
jump size / 2
]
end
@#$#@#$#@
GRAPHICS-WINDOW
178
11
796
630
-1
-1
10.0
1
10
1
1
1
0
0
0
1
-30
30
-30
30
0
0
1
ticks
30.0
BUTTON
14
29
77
62
NIL
setup
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
BUTTON
102
32
165
65
NIL
go
T
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
SLIDER
4
96
176
129
pestgrowth-rate
pestgrowth-rate
2
2.4
2.2
0.01
1
NIL
HORIZONTAL
SLIDER
1
135
178
168
pestdispersal-rate
pestdispersal-rate
0.6
1.5
1.0
0.01
1
NIL
HORIZONTAL
PLOT
803
15
1128
247
Harvest
NIL
NIL
0.0
10.0
0.0
10.0
true
false
"" ""
PENS
"harvest" 1.0 0 -10899396 true "" ""
CHOOSER
1
268
176
313
rainfall-scenario
rainfall-scenario
"low" "middle" "high"
0
PLOT
802
473
1127
696
Pestloss
NIL
NIL
0.0
1.0
0.0
0.1
true
false
"" ""
PENS
"totpestloss" 1.0 0 -2674135 true "" ""
PLOT
801
248
1127
472
Waterstress
NIL
NIL
0.0
1.0
0.0
0.1
true
false
"" ""
PENS
"totWS" 1.0 0 -13345367 true "" ""
SWITCH
2
318
146
351
viewdamsubaks
viewdamsubaks
1
1
-1000
CHOOSER
1
174
176
219
nrcropplans
nrcropplans
6 21
0
CHOOSER
0
358
148
403
Color_subaks
Color_subaks
"Temple groups" "cropping plans" "crops" "pests"
0
@#$#@#$#@
## LICENSE
This is a replication of the model reported in Lansing, J.S., J.N. Kremer (1993) Emergent properties of Balinese water temples. American Anthropologist 95 (1), 97�114, based on code provided by the authors
The replication is performed by Marco A. Janssen, Arizona State University, November 2006.
Replication of Lansing and Kremer model Copyright (C) 1993 Lansing and Kremer ((original) Copyright (C) 2006 M.A. Janssen (replication)
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
## ODD DESCRIPTION
The purpose of this model is to understand how local interactions between subaks, local irrigation communities, lead to high performance of rice production is a complex irrigation network.
Reference: Lansing, J. Stephen, and James N. Kremer (1993) Emergent properties of Balinese water temples. American Anthropologist 95:97�114.
State variables and scales
The model consists of 172 subaks, who act as independent agents. These subaks are within a complex irrigation network that describes 2 rivers. A total of 11 dams act as points where subaks get their water or return their water left over.
Subaks are indirectly connected via waterways, they share water from the same dams, and directly via spatial proximity which makes it possible for pests to spread between neighboring subaks. Each subak has a specific area of land available which affect the demand for water.
Process overview and scheduling
One time step is equivalent to one month. Subaks decide each year which of the 21 cropping patterns to follow. A cropping pattern determines which crop to plant in which month. There are 3 rice variety, fallow and vegetables.
Subaks imitate the cropping pattern of a neighbor, if there is a neighboring subak who had a higher harvest per ha during the previous year. Since Lansing and Kremer are not clear in their definition of neighbors, we implemented two type of neighbors, those who are directly connected in the spread of pests, and secondly, those subaks with whom a subak share the same dam as the source of water.
Practically, a subak can not directly implement a new cropping pattern in the new year, since it may still have crops on the fields. It is not clear how Lansing and Kremer implemented this. To reproduce their results, we assumed that each year the pest start at initial values (0.01) and a new cropping pattern.
The monthly schedule of activities is to determine for all subaks the following processes:
- Demand for water
- Water flows
- Rice
- Pest
- Harvest
Design concepts
Emergence: the evolving pattern of cropping plans mimic the temple groups at the masceti temple level. Thus local adjustments of synchronization of cropping plans lead to high performance of harvest with similar organization structures as observed in the field.
Adaptation: Each year the subak can adapt their cropping plan.
Fitness: harvest of rice per ha is used to evaluate the performance of a cropping plan for a subak.
Stochasticity: the only stochasticity is the initialization of the cropping plans.
Initialization
Each subaks get randomly allocated one of the 21 cropping plans, and start this plan in a randomly determined month.
Inputs
The following data are input in the model, and are provided in the code of the model:
- Water network of dams and subaks
- Network of subaks who can disperse pest to eachother
- rainfall per month for different elevations (three different scenarios are provided)
- cropping plans.
- area of subaks
- masceti temple subaks belong to
- for each crop: maximum yield, duration of crop on land before harvest, sensitivity to pests, growth rate of pests when specific crop in on the land.
Submodels
Demand for irrigation water
Demand for irrigation water for a subak depends on the difference between the water the crop needs per ha and the rain that fell per ha. This difference is multiplied by the area of land available in the subak.
Demand = (cropuse � rain)*area
Water flows
Starting with dams upstream, the waterflows in dams and subaks are calculated taking into account rainfall and water streaming into canals from upstream.
Rice
If not enough water is derived for rice, there is waterstress. If rice takes X months to grow, each month the rice is assumed to grow 1/X part. If only a fraction Y<1 of the demanded water is provided, the rice grows that month for a smaller part: Y/X
Pest
For all neighboring subaks between which pests can disperse calculate the sum (sumpestdif) of pests level of the own subak minus the pest level of a neighboring subak.
Then calculate dc
dc = (pestdispersal-rate / dx) * sumpestdif * dt
and finally determine the pest level:
Pests = growthrate * (Pests + 0.5 * dc)) + (0.5 * dc)
Harvest
If it is time to harvest, the harvest of a subak is calculated as follows:
harvest = ricestage * yldmax * (1 � pests * pestsens) * area,
where ricestage is a value between 0 and 1 representing which fraction of the water demand is provided over the course of the time rice was on the land, yldmax is the maximum yield in optimal conditions, and pestsens is the amount of rice lost for a unit of pest on the land.
@#$#@#$#@
default
true
0
Polygon -7500403 true true 150 5 40 250 150 205 260 250
airplane
true
0
Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15
arrow
true
0
Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150
box
false
0
Polygon -7500403 true true 150 285 285 225 285 75 150 135
Polygon -7500403 true true 150 135 15 75 150 15 285 75
Polygon -7500403 true true 15 75 15 225 150 285 150 135
Line -16777216 false 150 285 150 135
Line -16777216 false 150 135 15 75
Line -16777216 false 150 135 285 75
bug
true
0
Circle -7500403 true true 96 182 108
Circle -7500403 true true 110 127 80
Circle -7500403 true true 110 75 80
Line -7500403 true 150 100 80 30
Line -7500403 true 150 100 220 30
butterfly
true
0
Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240
Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240
Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163
Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165
Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225
Circle -16777216 true false 135 90 30
Line -16777216 false 150 105 195 60
Line -16777216 false 150 105 105 60
car
false
0
Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180
Circle -16777216 true false 180 180 90
Circle -16777216 true false 30 180 90
Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89
Circle -7500403 true true 47 195 58
Circle -7500403 true true 195 195 58
circle
false
0
Circle -7500403 true true 0 0 300
circle 2
false
0
Circle -7500403 true true 0 0 300
Circle -16777216 true false 30 30 240
cow
false
0
Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167
Polygon -7500403 true true 73 210 86 251 62 249 48 208
Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123
cylinder
false
0
Circle -7500403 true true 0 0 300
dot
false
0
Circle -7500403 true true 90 90 120
face happy
false
0
Circle -7500403 true true 8 8 285
Circle -16777216 true false 60 75 60
Circle -16777216 true false 180 75 60
Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240
face neutral
false
0
Circle -7500403 true true 8 7 285
Circle -16777216 true false 60 75 60
Circle -16777216 true false 180 75 60
Rectangle -16777216 true false 60 195 240 225
face sad
false
0
Circle -7500403 true true 8 8 285
Circle -16777216 true false 60 75 60
Circle -16777216 true false 180 75 60
Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183
fish
false
0
Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166
Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165