-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Nice Musical Chairs_v9_NetLogo_v604.tmp.nlogo
2795 lines (2457 loc) · 73 KB
/
.Nice Musical Chairs_v9_NetLogo_v604.tmp.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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; GNU GENERAL PUBLIC LICENSE ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; The Nice Musical Chairs model - A model of the interaction between farming and herding, introducing explicit groups and group mechanisms
;; Copyright (C) 2016 Andreas Angourakis (andros.spica@gmail.com)
;;
;; 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 3 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/>.
extensions [ vid ]
;;;;;;;;;;;;;;;;;
;;;;; BREEDS ;;;;
;;;;;;;;;;;;;;;;;
breed [ groups group ]
breed [ pointers pointer ]
breed [ labelpositions labelposition ]
;;;;;;;;;;;;;;;;;
;;; VARIABLES ;;;
;;;;;;;;;;;;;;;;;
globals
[
totalPatches
;;; modified parameters
initH initF
baseIntGrowth maxExtGrowth
initGroups
effectivenessGr
maxGroupChangeRate
opt optimalGrowthIncrease
group_management group_pasture_tenure pairing
;;; variables used in resolve_conflict
defender contender
;;; counters and final measures
countLandUseF countLandUseH
numberGroups
FFcompetitions HHcompetitions HFcompetitions FHcompetitions landUseChangeEvents managementEvents
farmingDemand farmingGrowth farmingDeterrence farmingBalance
herdingDemand herdingGrowth herdingDeterrence herdingBalance
meanGroupSize bigGroupSize
meanGroupEffectiveness bigGroupEffectiveness
bigTargetFarmingRatio meanTargetFarmingRatio
meanFarmingIntegration meanHerdingIntegration meanMixedIntegration
]
groups-own
[
groupSize groupEffectiveness
intGrowthF intGrowthH
farmingRatio targetFarmingRatio
;;; helpers
groupSizeF groupSizeH
groupDemandF groupDemandH
groupDemandRemain
]
patches-own [ landUse myGroup contendersF contendersH withinIntegration betweenIntegration ]
pointers-own [ value ]
labelpositions-own [ name ]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; SETUP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to setup
;;; This procedure initializes the model
clear-all
set totalPatches count patches
parameters-check-1
;;; setup parameters depending on the type of experiment
if (typeOfExperiment = "random")
[
; set random seed
let aSeed new-seed
random-seed aSeed
set seed aSeed
let listOfScenarios (list "Ao - open access, simple group dynamics" "Bo - open access, pairing" "Co - open access, management" "Do - open access, pairing and management" "Ar - restricted access, simple group dynamics" "Br - restricted access, pairing" "Cr - restricted access, management" "Dr - restricted access, pairing and management")
let randomIndex random 8
set scenario item randomIndex listOfScenarios ;;; randomly choose one scenario
set baseIntGrowth 0.01 + random-float base_intrinsic_growth_rate
set maxExtGrowth 0.001 + random-float max_extrinsic_growth_rate
set opt random-float optimum
set optimalGrowthIncrease random-float optimal_growth_increase
set initGroups 1 + random initial_number_of_groups
set maxGroupChangeRate random-float max_group_change_rate
set effectivenessGr random-float totalPatches
set initH random round ((init_herding / 100) * totalPatches)
set initF random round ((init_farming / 100) * totalPatches)
]
if (typeOfExperiment = "defined by GUI")
[
; set random seed
random-seed seed
set baseIntGrowth base_intrinsic_growth_rate
set maxExtGrowth max_extrinsic_growth_rate
set opt optimum
set optimalGrowthIncrease optimal_growth_increase
set initGroups initial_number_of_groups
set maxGroupChangeRate max_group_change_rate
set effectivenessGr effectiveness_gradient
set initH round ((init_herding / 100) * totalPatches)
set initF round ((init_farming / 100) * totalPatches)
]
if (typeOfExperiment = "defined by expNumber")
[
; set random seed
let aSeed new-seed
random-seed aSeed
set seed aSeed
load-experiment
]
parameters-check-2
set pairing true
if (scenario = "Ao - open access, simple group dynamics" OR scenario = "Co - open access, management" OR scenario = "Ar - restricted access, simple group dynamics" OR scenario = "Cr - restricted access, management")
[
set optimalGrowthIncrease 0
set pairing false
]
set group_pasture_tenure false
if (scenario = "Ar - restricted access, simple group dynamics" OR scenario = "Br - restricted access, pairing" OR scenario = "Cr - restricted access, management" OR scenario = "Dr - restricted access, pairing and management")
[
set group_pasture_tenure true
]
set group_management false
if (scenario = "Co - open access, management" OR scenario = "Do - open access, pairing and management" OR scenario = "Cr - restricted access, management" OR scenario = "Dr - restricted access, pairing and management")
[
set group_management true
]
ask patch 0 0
[
sprout-groups initGroups
]
;;; set land use according to the parameter setting (position is arbitrary and has no consequence)
ask patches [ set landUse "N" set myGroup nobody set contendersF (turtle-set) set contendersH (turtle-set) ]
ask n-of initF patches
[
set landUse "F"
]
ask n-of initH patches with [landUse = "N"]
[
set landUse "H"
]
initialize-patches-and-groups
;;; initialize visualization
ask patch (min-pxcor + round ((max-pxcor - min-pxcor) * 0.97) ) (min-pycor + round ((max-pycor - min-pycor) * 0.97) )
[
sprout-labelpositions 1 [ set name "scenario" set label scenario set shape "invisible" ]
]
if (display_details = true)
[
ask patch (min-pxcor + round ((max-pxcor - min-pxcor) * 0.97) ) (min-pycor + round ((max-pycor - min-pycor) * 0.03) )
[
sprout-labelpositions 1 [ set name "time" set label "time: 0" set shape "invisible" ]
]
ask patch (min-pxcor + round ((max-pxcor - min-pxcor) * 0.3) ) (min-pycor + round ((max-pycor - min-pycor) * 0.03) )
[
sprout-labelpositions 1 [ set name "farming" set shape "invisible" ]
]
ask patch (min-pxcor + round ((max-pxcor - min-pxcor) * 0.72) ) (min-pycor + round ((max-pycor - min-pycor) * 0.03) )
[
sprout-labelpositions 1 [ set name "bigGroupSize" set shape "invisible" ]
]
]
update-visualization
reset-ticks
end
to parameters-check-1
;;; check if values were reset to 0
;;; and set default values
if (end-simulation-in-tick = 0) [ set end-simulation-in-tick 1000 ]
if (base_intrinsic_growth_rate = 0) [ set base_intrinsic_growth_rate 0.03 ]
if (initial_number_of_groups = 0) [ set initial_number_of_groups 25 ]
if (initH = 0 and init_farming = 0) [ set init_herding 20
set init_farming 20 ]
;;; initial parameter check (avoiding division per zero error
check-par-is-positive "end-simulation-in-tick" end-simulation-in-tick
check-par-is-positive "initial_number_of_groups" initial_number_of_groups
end
to check-par-is-positive [ parName parValue ]
if (parValue <= 0)
[
print (word "ERROR: " parName " must be greater than zero")
stop
]
end
to parameters-check-2
;;; check number of initial centers and land use units
if (initH + initF >= count patches) [print "ERROR: initial number of land use units (initF + initH) is too high compare to the number of patches" stop ]
if (initGroups >= count patches) [print "ERROR: initial number of groups (initGroups) is too high compare to the number of patches" stop ]
if (initH + initF < 3 * initGroups)
[print "Warning: initial number of groups (initGroups) is too high compare to the initial number of land use units (initF + initH). Some groups will be initialised empty" ]
end
to initialize-patches-and-groups
;;; This procedure initializes patch and group variables
ask patches
[
if (landUse != "N") [ set myGroup (one-of groups) ]
]
ask groups
[
set hidden? true
move-to one-of patches with [any? groups-here = false and (pxcor > 2) and (pycor > 2) and (pxcor < max-pxcor - 2) and (pycor < max-pycor - 2)]
set targetFarmingRatio random-float 1
;set targetFarmingRatio FarmingRatio ;;; alternative initialization of "targetFarmingRatio"
update-group
]
ask patches
[
update-landUnits
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; CYCLE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to go
;;; This procedure is the cycle of the model (what happens during one "tick").
reset-counters
growth
landUse-expansion
check-competitions
change-groups
if (group_management = true) [ group-management ]
update-visualization
tick
if (display_details = true) [ ask labelpositions with [ name = "time" ] [ set label (word "time: " ticks) ] ]
if ticks > end-simulation-in-tick [stop]
end
to reset-counters
;;; This procedure reset all counters which are used either during the cycle or summarized at the "update-visualization" procedure.
set farmingGrowth 0
set farmingDeterrence 0
set herdingGrowth 0
set herdingDeterrence 0
set FFcompetitions 0
set HHcompetitions 0
set HFcompetitions 0
set FHcompetitions 0
set landUseChangeEvents 0
set managementEvents 0
ask groups [ set groupDemandF 0 set groupDemandH 0 ]
end
to growth
;;; This procedure calculates the groups demands for each land use class, based on both the intrinsic and extrinsic growth rates of each of them.
;;; Note that growth rates are dependent on parameters, but also on the context, and may vary from one "tick" to another.
ask groups [ set groupDemandF 0 set groupDemandH 0 ]
;;; FARMING
;;; Intrinsic Demand
ask groups with [groupSize > 0]
[
let myLand count patches with [landUse = "F" and myGroup = myself]
repeat myLand
[
if ( random-float 1 <= intGrowthF )
[
set groupDemandF groupDemandF + 1
]
]
]
;;; Extrinsic Demand
let extF (round (maxExtGrowth * ( totalPatches - countLandUseF ) ) )
repeat extF
[
ask one-of groups
[
set groupDemandF groupDemandF + 1
]
]
;;; HERDING
;;; Intrinsic Growth
ask groups with [groupSize > 0]
[
let myLand count patches with [landUse = "H" and myGroup = myself]
repeat myLand
[
if ( random-float 1 <= intGrowthH )
[
set groupDemandH groupDemandH + 1
]
]
]
;;; Extrinsic Growth
let extH (round (maxExtGrowth * ( totalPatches - countLandUseH ) ) )
repeat extH
[
ask one-of groups
[
set groupDemandH groupDemandH + 1
]
]
end
to landUse-expansion
;;; This procedure calls for the expansion procedures of farming and herding, intentionally in this order.
farming-expansion
herding-expansion
end
to farming-expansion
;;; In this procedure, groups attempt to assign patches to their new farming units.
;;; If there is no patch freely available, groups will randomly choose a patch, and
;;; if this patch belongs to another group (density-dependent growth), the group will generate a competitive situation and be accounted within "contendersF".
;;; In the case that the patch is used for "herding" and "group_pasture_tenure = false", the group will automatically occupy it and change its land use to farming.
let growingGroupsF groups with [ groupDemandF > 0 ]
ask growingGroupsF [ set groupDemandRemain groupDemandF ]
repeat sum [groupDemandRemain] of growingGroupsF
[
ask one-of growingGroupsF with [groupDemandRemain > 0]
[
let me self
ifelse (any? patches with [myGroup = nobody])
[
;;; if the land is not saturated
ask one-of patches with [myGroup = nobody]
[
if (landUse = "N") [ set landUseChangeEvents landUseChangeEvents + 1 ]
set myGroup me set landUse "F"
]
]
[
;;; if the territory is saturated
;;; Choose a random patch
ask one-of patches
[
;;; if the patch is used by another group
if (myGroup != me)
[
ifelse (landUse = "F") [
if ( allow_within-class_competition = true )
[
;;; If the patch is used for farming, F-F competition will be called later
set contendersF (turtle-set contendersF me)
set FFcompetitions (FFcompetitions + 1)
]
]
[
ifelse (group_pasture_tenure = true)
[
;;; F-H competition will be called later
set contendersF (turtle-set contendersF me)
set FHcompetitions (FHcompetitions + 1)
]
[
;;; farming will start using a former pasture
set myGroup myself
set landUSe "F"
set landUseChangeEvents landUseChangeEvents + 1
set farmingGrowth farmingGrowth + 1
set herdingDeterrence herdingDeterrence + 1
]
]
]
]
]
set groupDemandRemain groupDemandRemain - 1
]
]
end
to herding-expansion
;;; In this procedure, groups attempt to assign patches to all their herding units (if "group_pasture_tenure = false") or to their new herding units (group_pasture_tenure = true).
;;; If there is no patch freely available, groups will randomly choose a patch, and
;;; if this patch belongs to another group (density-dependent growth), the group will generate a competitive situation and be accounted within "contendersH"
let groupsH nobody
let herds 0
ifelse (group_pasture_tenure = true)
[
set groupsH groups with [ groupDemandH > 0 ]
ask groupsH [ set groupDemandRemain groupDemandH ]
set herds sum [groupDemandRemain] of groupsH
]
[
set groupsH groups with [ farmingRatio < 1 ]
ask groupsH
[
let me self
set groupDemandRemain groupSizeH + groupDemandH
]
set herds sum [ groupDemandRemain ] of groups
;;; reset herding positions (herds go back not necessarily to the same patch)
ask patches with [ landUse = "H"] [ set myGroup nobody ]
]
repeat herds
[
ask one-of groupsH with [ groupDemandRemain > 0 ]
[
let me self
ifelse (any? patches with [myGroup = nobody])
[
;;; if the land is not saturated
ask one-of patches with [myGroup = nobody]
[
if (landUse != "H")
[
set landUse "H"
set landUseChangeEvents landUseChangeEvents + 1
set herdingGrowth herdingGrowth + 1
]
set myGroup me
]
]
[
;;; if the territory is saturated
;;; Choose a random patch
ask one-of patches
[
;;; Fit-to-maximum exclusion, Density-dependent exclusion
if (myGroup != me)
[
ifelse (landUse = "F")
[
;;; a H-F competition will be called later
set contendersH (turtle-set contendersH me)
set HFcompetitions (HFcompetitions + 1)
]
[
if (allow_within-class_competition = true)
[
;;; a H-H competition will be called later
set contendersH (turtle-set contendersH me)
set HHcompetitions (HHcompetitions + 1)
]
]
]
]
]
set groupDemandRemain groupDemandRemain - 1
]
]
;;; rangelands not claimed will be considered free land (no land use)
if (any? patches with [landUse = "H" and myGroup = nobody] ) [ ask patches with [landUse = "H" and myGroup = nobody] [ set landUse "N" ] ]
end
to check-competitions
;;; This procedure calls, in a particular sequence, for the resolution of all competitive situations generated by farming and herding expansions.
;;; Due to their sedentary condition, farming contenders will act first (F-F and F-H -> H-H and H-F)
;;; Farming stakeholders prefer to acquire other groups' farmlands (F-F),
;;; rather than investing in new infraestructures (F-H)
check-FFcompetitions
check-FHcompetitions
;;; Herding stakeholders prefer to acquire other groups' pastures (H-H),
;;; rather than converting farmlands by violence or negotiation (H-F)
check-HHcompetitions
check-HFcompetitions
ask groups [ update-group ]
end
to check-FFcompetitions
;;; farming-farming competition
ask patches with [ landUse = "F" and any? contendersF ]
[
; print "F-F"
;;; the center assigned is the one that is effectively using the land
set defender myGroup
repeat count contendersF
[
set contender one-of contendersF
;;; remove contender from the respective contenders agent-set
set contendersF contendersF with [self != contender]
;print (word "contendersF after: " contendersF)
resolve-competition "FF"
]
]
end
to check-FHcompetitions
;;; farming-herding competition
ask patches with [ landUse = "H" and any? contendersF ]
[
; print "F-H"
set defender myGroup
repeat count contendersF
[
set contender one-of contendersF
;;; remove contender from the respective contenders agent-set
set contendersF contendersF with [self != contender]
; print (word "contendersH after: " contendersH)
resolve-competition "FH"
]
]
end
to check-HHcompetitions
;;; herding-herding competition
ask patches with [ landUse = "H" and any? contendersH ]
[
; print "H-H"
;;; Since their schedule may vary, a herding center is assigned randomly among the contenders to be the one arriving first (defender)
set defender myGroup
repeat count contendersH
[
set contender one-of contendersH
;;; remove contender from the respective contenders agent-set
set contendersH contendersH with [self != contender]
; print (word "contendersH after: " contendersH)
;;; check if any of contenders still exists. If so, then resolve competition
if ([groupSize] of contender > 0)
[ resolve-competition "HH"]
]
]
end
to check-HFcompetitions
;;; farming-herding competition
ask patches with [ landUse = "F" and any? contendersH ]
[
; print "H-F"
set defender myGroup
repeat count contendersH
[
set contender one-of contendersH
;;; remove contender from the respective contenders agent-set
set contendersH contendersH with [self != contender]
; print (word "contendersH after: " contendersH)
resolve-competition "HF"
]
]
end
to resolve-competition [ typeOfComp ]
;;; This procedure resolves the current competitive situation,
;;; and calculate the consequences of contenders success according to "typeOfComp" ("FF"=farming-farming, "FH"=farming-herding, "HH"=herding-herding, "HF"=herding-farming).
;;; set competition conditions
; define intensities
let supportDef get-group-influence defender
let supportCon get-group-influence contender
; print (word defender " vs " contender ")
; print (word "supportDef: " supportDef " ; supportCon: " supportCon)
;;; the contender is discarted if both defender and contender have zero strength at this patch
if (supportCon + supportDef > 0)
[
;;; a contender is the one attempting to expand, thus it is the one to make a informed decision
let ratio_of_intensities (supportCon /(supportCon + supportDef))
;;; Does the competitive situation evolves into land use change event?
if ( random-float 1 < ratio_of_intensities)
[
;;; extending whichever land use is encouraged
set myGroup contender
;;; update landUse
if (typeOfComp = "HF")
[
; print "herding wins"
set landUse "H"
;;; Hence, there is land use change
set landUseChangeEvents landUseChangeEvents + 1
set herdingGrowth herdingGrowth + 1
set farmingDeterrence farmingDeterrence + 1
]
if (typeOfComp = "FH")
[
; print "farming wins"
set landUse "F"
;;; Hence, there is land use change
set landUseChangeEvents landUseChangeEvents + 1
set farmingGrowth farmingGrowth + 1
set herdingDeterrence herdingDeterrence + 1
]
]
]
end
to change-groups
;;; In this procedure, every patch of every group test their particular probability of changing to another group,
;;; which may be an existing group or a new one collecting all the defecting patches of a group (fission).
;;; The criterium to leave and choose a group is the competitive strength or influence that groups have in the patch at hand (size * effectiveness)
ask groups
[
;;; each patch of a group will assess their will (maxGroupChangeRate)
;;; and their freedom, which is inversely related to the group effectiveness (1 - ([groupEffectiveness] of myGroup) ),
;;; to change groups, possibly forming a new group.
let me self
let myLand patches with [myGroup = me]
let defectingPatches (patch-set nobody)
ask myLand
[
if ( random-float 1 < maxGroupChangeRate * (1 - ([groupEffectiveness] of myGroup) ) )
[
set defectingPatches (patch-set defectingPatches self)
]
]
if (any? defectingPatches)
[
;;; if there are any patches defecting from this group...
;;; the viability of the possible new group is calculated for each patch and compared to the most influent group
let newGroup nobody
let influenceNewGroup (count defectingPatches) * e ^ ( - (count defectingPatches) / (effectivenessGr * totalPatches) )
let mostInfluentGroup max-one-of groups [groupSize * groupEffectiveness]
let influenceOtherGroup get-group-influence mostInfluentGroup
ifelse (influenceOtherGroup > influenceNewGroup)
[
ask defectingPatches [ set myGroup mostInfluentGroup ]
]
[
if (newGroup = nobody)
[
ifelse (any? groups with [groupSize = 0])
[
ask one-of groups with [groupSize = 0]
[
set targetFarmingRatio ([targetFarmingRatio] of me)
set newGroup self
]
]
[
hatch-groups 1
[
;;; new groups inherit the traits of the original group *** or modify them given a mutation parameter
set hidden? true
move-to one-of patches with [any? groups-here = false and (pxcor > 2) and (pycor > 2) and (pxcor < max-pxcor - 2) and (pycor < max-pycor - 2)]
;;; random mutation
;set targetFarmingRatio min(list 1 max(list 0 (([targetFarmingRatio] of me) + (0.1 - random-float 0.2)) ) )
;;; following the optimal
;set targetFarmingRatio ([targetFarmingRatio] of me) + 0.1 * (opt - targetFarmingRatio)
;;; following tradition
set targetFarmingRatio ([targetFarmingRatio] of me)
set newGroup self
; print (word " Group fission: " me " (groupSize=" count myLand ") splits into " me " (groupSize=" (count myLand - count defectingPatches) ") and " newGroup " (groupSize=" count defectingPatches ")")
]
]
]
ask defectingPatches [ set myGroup newGroup ]
]
]
update-group
]
end
to-report get-group-influence [ theGroup ]
report [groupSize * groupEffectiveness] of theGroup
end
to group-management
;;; In this procedure, groups with more than one member calculate the difference between their "farmingRatio" and their "targetFarmingRatio",
;;; and attempt to change the land use of the respective number of patches (note that "floor" is used),
;;; with a success proportional to their "groupEffectiveness".
ask groups
[
if (groupSize > 1)
[
let dif ((farmingRatio - targetFarmingRatio) * groupSize)
let num floor (abs dif * groupEffectiveness)
; print (word self " -> farmingRatio: " precision farmingRatio 4 " ¦¦ targetFarmingRatio: " precision targetFarmingRatio 4 " ¦¦ groupSize: " groupSize " ¦¦ groupEffectiveness: " precision groupEffectiveness 4 " ¦¦ dif: " dif " ¦¦ num: " num)
if (num > 0)
[
;;; if it is greater than target
ifelse ( dif > 0 )
[
ask n-of num patches with [landUse ="F" and myGroup = myself]
[
set landUse "H"
;;; Hence, there is land use change
set landUseChangeEvents landUseChangeEvents + 1
set herdingGrowth herdingGrowth + 1
set farmingDeterrence farmingDeterrence + 1
set managementEvents managementEvents + 1
]
]
[
;;; if it is smaller than target
if ( dif < 0 )
[
ask n-of num patches with [landUse ="H" and myGroup = myself]
[
set landUse "F"
;;; Hence, there is land use change
set landUseChangeEvents landUseChangeEvents + 1
set farmingGrowth farmingGrowth + 1
set herdingDeterrence herdingDeterrence + 1
set managementEvents managementEvents + 1
]
]
]
]
]
update-group
]
end
to update-group
;;; This procedure updates group variables (groupSize, groupEffectiveness, farmingRatio, intGrowthF, intGrowthH).
set farmingRatio 0
set groupSize count patches with [myGroup = myself]
set groupSizeF count patches with [myGroup = myself and landUse = "F"]
set groupSizeH count patches with [myGroup = myself and landUse = "H"]
if (groupSize > 0)
[
set farmingRatio ( count patches with [landUse = "F" and myGroup = myself] / groupSize )
]
set groupEffectiveness e ^ ( - groupSize / (effectivenessGr * totalPatches) )
;;; calculate modified growth out of the group distance from the optimal
let d 0
ifelse (farmingRatio < opt)
[
set d (farmingRatio / opt)
set intGrowthF baseIntGrowth * (1 + (optimalGrowthIncrease / 100))
set intGrowthH baseIntGrowth * (1 + (optimalGrowthIncrease / 100) * d)
]
[
ifelse (opt = 1)
[ set d 1 ]
[ set d 1 - ((farmingRatio - opt) / (1 - opt)) ]
set intGrowthH baseIntGrowth * (1 + (optimalGrowthIncrease / 100))
set intGrowthF baseIntGrowth * (1 + (optimalGrowthIncrease / 100) * d)
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; VISUALIZATION ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to update-landUnits
;;; This procedure updates the patches' "withinIntegration" and "betweenIntegration".
ask patches with [myGroup != nobody]
[
ifelse (landUse = "F")
[
set withinIntegration [farmingRatio] of myGroup
set betweenIntegration 1 - [farmingRatio] of myGroup
]
[
set withinIntegration 1 - [farmingRatio] of myGroup
set betweenIntegration [farmingRatio] of myGroup
]
]
end
to update-visualization
;;; this procedure updates the display and all global output variables.
if (display_mode = "land use proportion") [ update-patches if (display_details = true) [ ask labelpositions [set label-color black] ] ]
if (display_mode = "groups") [ update-network if (display_details = true) [ ask labelpositions [set label-color white] ] ]
set numberGroups count groups with [groupSize > 0]
set countLandUseF count patches with [ landUse = "F" ]
set countLandUseH count patches with [ landUse = "H" ]
set farmingBalance (farmingGrowth - farmingDeterrence)
set herdingBalance (herdingGrowth - herdingDeterrence)
set meanGroupSize mean [[groupSize] of myGroup] of patches with [ landUse != "N" ]
set bigGroupSize [groupSize] of max-one-of groups [groupSize]
set meanGroupEffectiveness mean [[groupEffectiveness] of myGroup] of patches with [ landUse != "N" ]
set bigGroupEffectiveness [groupEffectiveness] of max-one-of groups [groupSize]
set meanTargetFarmingRatio mean [[targetFarmingRatio] of myGroup] of patches with [ landUse != "N" ]
set bigTargetFarmingRatio [targetFarmingRatio] of max-one-of groups [groupSize]
update-landUnits
ifelse (any? patches with [landUse = "F"]) [ set meanFarmingIntegration mean [withinIntegration] of patches with [landUse = "F"] ] [ set meanFarmingIntegration -0.01 ]
ifelse (any? patches with [landUse = "H"]) [ set meanHerdingIntegration mean [withinIntegration] of patches with [landUse = "H"] ] [ set meanHerdingIntegration -0.01 ]
set meanMixedIntegration mean [betweenIntegration] of patches with [ landUse != "N" ]
ifelse (display_details = true)
[
ask labelpositions with [ name = "farming" ] [ set label (word "farming(%): " (precision (100 * countLandUseF / totalPatches) 2) ) ]
ask labelpositions with [ name = "bigGroupSize" ] [ set label (word "biGroupSize(%): " (precision (100 * bigGroupSize / totalPatches) 2) ) ]
]
[
ask labelpositions with [ name = "time" ] [ set label "" ]
ask labelpositions with [ name = "farming" ] [ set label "" ]
ask labelpositions with [ name = "bigGroupSize" ] [ set label "" ]
]
end
to update-patches
;;; this procedure updates the "land use proportion" display mode.
ask pointers [die]
ask groups [set hidden? true]
ask patches
[
set pcolor brown
if (landUse = "F")
[ set pcolor green ]
if (landUse = "H")
[ set pcolor yellow ]
]
end
to update-network
;;; this procedure updates the "groups" display mode.
ask pointers [die]
ask groups
[
ifelse (groupSize > 0) [set hidden? false set color red set shape "circle" set size 0.5] [ set hidden? true ]
create-links-with other groups [ set color black]
]
layout-spring groups links 0.18 9 1.2
ask links [die]
ask patches
[
set pcolor black
let thisPatch self
if (landUse != "N" )
[
sprout-pointers 1 [
set shape "circle" set size 0.2
ifelse ([landUse] of patch-here = "F") [ set color green ] [ set color yellow ]
create-link-with myGroup [ set color grey]
move-to myGroup
]
]
]
ask groups
[
let num groupSize
repeat groupSize [
ask one-of link-neighbors [
rt 360 * who
fd 0.1 * num * e ^ (- num / 60)
]
set num num - 1
]
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;; Parametrization from file ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to load-experiment
;;; this procedure loads the values of each (explored) parameter from a csv file.
;;; Note that the setup will use the value set by the user for any other parameter (e.g. scenario).
let FilePath "SensAnalysis//exp//" ;;; create folders in the model's directory before trying to load experiments
let filename (word FilePath "exp_" expNumber ".csv") ;;; the parameter setting of experiments must be saved as ".csv" files named "exp_<NUMBER>.csv"
file-open filename
while [not file-at-end?]
[
;;; the values of the file must follow this same order
set initH round ((file-read / 100) * totalPatches)
set initF round ((file-read / 100) * totalPatches)
set baseIntGrowth file-read
set maxExtGrowth file-read
set initGroups file-read
set effectivenessGr file-read
set maxGroupChangeRate file-read
set opt file-read
set optimalGrowthIncrease file-read
set end-simulation-in-tick file-read ;- 1500 ;; use this to cut down the time of simulation (e.g. if the file reads 2000)
]
file-close
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;; movie generation ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to generate-animation
;;; this procedure generates a video sequencing the displays of a simulation (using the current parameter configuration).