-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVilasData.nlogo
2054 lines (1889 loc) · 46.9 KB
/
VilasData.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
;Each row seems to be 1351 units wide. Starting at 105,500 (y,x), 142462
extensions [matrix]
breed [birds bird]
birds-own [energy lifetime]
;added code
;birds-own [bugsEaten bird-energy SMR]
patches-own
[
;added code
;bugs-amt
landcover
canopy2k1
house1996
house2k5
frontage
lakesize
road soil
ownership
zoning
mean_diam
bin_list ;list of trees based on diameter
dist_type ;0 if normal, 1 if neg exp
herb_veg
bug_pop
b_area
tree_height ;list of heights based on diameter
volume ;list of volume based on diameter
total_volume ;list of total volume per diameter
cut-off
cord ;pole timber
mbf ;saw timber
money_pole
money_saw
bird-range
bird-nests
]
globals [
currentyear_saw
total_saw
currentyear_pole
total_pole
counter_patch
current_profit
total_profit
decid_matrix
evergreen_matrix
mixed_matrix
wet_matrix
decid_ingrow
evergreen_ingrow
mixed_ingrow
wet_ingrow
water-color
ice-color
dev-op-color
dev-low-color
dev-med-color
dev-hi-color
barren-color
forest-dec-color
forest-ever-color
forest-mix-color
shrub-color
shrub-dwarf-color
herb-grass-color
herb-sed-color
herb-lic-color
herb-moss-color
plant-past-color
plant-crop-color
wet-woody-color
wet-emerg-color
water
ice
dev-op
dev-low
dev-med
dev-hi
barren
forest-dec
forest-ever
forest-mix
shrub
shrub-dwarf
herb-grass
herb-sed
herb-lic
herb-moss
plant-past
plant-crop
wet-woody
wet-emerg
s-constant
max_ba_41
min_ba_41
max_ba_42
min_ba_42
max_ba_43
min_ba_43
max_ba_90
min_ba_90
]
to setup
clear-patches
;; (for this model to work with NetLogo's new plotting features,
;; __clear-all-and-reset-ticks should be replaced with clear-all at
;; the beginning of your setup procedure and reset-ticks at the end
;; of the procedure.)
__clear-all-and-reset-ticks
reset-ticks
set water-color 105
set ice-color 9.9
set dev-op-color 137
set dev-low-color 134
set dev-med-color 15
set dev-hi-color 13
set barren-color 38
set forest-dec-color 57
set forest-ever-color 53
set forest-mix-color 58
set shrub-color 27
set shrub-dwarf-color 25
set herb-grass-color 47
set herb-sed-color 44
set herb-lic-color 43
set herb-moss-color 85
set plant-past-color 45
set plant-crop-color 22
set wet-woody-color 87
set wet-emerg-color 94
set water 11
set ice 12
set dev-op 21
set dev-low 22
set dev-med 23
set dev-hi 24
set barren 31
set forest-dec 41
set forest-ever 42
set forest-mix 43
set shrub-dwarf 51
set shrub 52
set herb-grass 71
set herb-sed 72
set herb-lic 73
set herb-moss 74
set plant-past 81
set plant-crop 82
set wet-woody 90
set wet-emerg 95
set s-constant 80
set total_profit 0
set current_profit 0
set current_profit 0
set total_pole 0
set total_saw 0
set currentyear_saw 0
set currentyear_pole 0
file-open user-file
; skipping line to get user data
repeat 142462
[
let lineone file-read-line
]
repeat 100
[
repeat 100
[
; get the input, skip the comma
let id file-read
;print id
let skip1 file-read-characters 1
;print skip1
let row file-read - 155
let skip2 file-read-characters 1
let col file-read - 551
;ask patch col row [ set pcolor red ]
let skip3 file-read-characters 1
let templandcover file-read
;print "Location"
;print col
;print row
ask patch col row [ set landcover templandcover set bin_list [0 0 0 0 0 0 0 0 0 0 0 0 ] ]
;print templandcover
ifelse templandcover = 42
[ ask patch col row [ set cut-off 8 ] ]
[ ask patch col row [ set cut-off 10 ] ]
; color assignment
ask patch col row [select-case templandcover [
[11 105] ;water
[12 9.9] ;ice
[21 137] ;dev-op
[22 134] ;dev-low
[23 15] ;dev-med
[24 13] ;dev-hi
[31 38] ;barren
[41 57] ;forest-dec
[42 53] ;forest-ever
[43 58] ;forest-mix
[51 25] ;shrub-dwarf
[52 27] ;shrub
[71 47] ;herb
[72 44] ;herb-seg
[73 43] ;herb-lic
[74 85] ;herb-moss
[81 45] ;plant-past
[82 22] ;plant-crop
[90 87] ;wet-wood
[95 94] ;wet-herb
[255 125]
]]
let skip4 file-read-characters 1
ask patch col row [ set canopy2k1 file-read ]
let skip5 file-read-characters 1
ask patch col row [ set house1996 file-read ]
let skip6 file-read-characters 1
ask patch col row [ set house2k5 file-read ]
let skip7 file-read-characters 1
ask patch col row [ set frontage file-read ]
let skip8 file-read-characters 1
ask patch col row [ set lakesize file-read ]
let skip9 file-read-characters 1
ask patch col row [ set road file-read ]
let skip10 file-read-characters 1
ask patch col row [ set soil file-read ]
let skip11 file-read-characters 1
ask patch col row [ set ownership file-read ]
let skip12 file-read-characters 1
ask patch col row [ set zoning file-read ]
ask patch col row [initialize-trees]
let ratio .5
if templandcover = 42
[
;11, 90, 95
ask patch col row
[ifelse any? neighbors with [landcover = 11] or any? neighbors with [landcover = 90] or any? neighbors with [landcover = 95]
[
set ratio 1
]
[
if any? neighbors in-radius 2 with [landcover = 11] or any? neighbors in-radius 2 with [landcover = 90] or any? neighbors in-radius 2 with [landcover = 95]
[
set ratio .75
]
]]
create-birds (num-birds * ratio)
[
set shape "bird side"
set size .5
set color red
setxy col row
set energy random 50
set lifetime random 1826
]
]
]
repeat 1252 [let skipline file-read-line]
]
file-close
initialize-matrix 41
initialize-matrix 42
initialize-matrix 43
initialize-matrix 90
;set min_ba_41 [b_area] of min-one-of (patches with [landcover = 41]) [b_area]
;set max_ba_41 [b_area] of max-one-of (patches with [landcover = 41]) [b_area]
set min_ba_41 [b_area] of min-one-of patches [b_area]
set max_ba_41 [b_area] of max-one-of patches [b_area]
;set min_ba_42 [b_area] of min-one-of (patches with [landcover = 42]) [b_area]
;set max_ba_42 [b_area] of max-one-of (patches with [landcover = 42]) [b_area]
;set min_ba_43 [b_area] of min-one-of (patches with [landcover = 43]) [b_area]
;set max_ba_43 [b_area] of max-one-of (patches with [landcover = 43]) [b_area]
;set min_ba_90 [b_area] of min-one-of (patches with [landcover = 90]) [b_area]
;set max_ba_90 [b_area] of max-one-of (patches with [landcover = 90]) [b_area]
;initialize stuff
ask patches with [landcover != 11]
[
set herb_veg 1
set bug_pop 1
]
end
to select-case [value cases]
foreach cases
[
;print ?1
if (item 0 ?1 = value) [ set pcolor (item 1 ?1) stop ]
]
end
to initialize-trees
let weights_conif [0.556035896 0.258728096 0.185236008]
let weights_deci [0.43 0.37 0.2]
let weights_wet [0.424745355 0.350450241 0.224804403]
let weights_mix [0.424745355 0.350450241 0.224804403]
; use the function calc_mean_diam
if landcover = 42 ;Coniferous
[
calc_mean_diam weights_conif
generate_dist
]
if landcover = 41 ;Deciduous
[
calc_mean_diam weights_deci
generate_dist
]
if landcover = 90 ;Forested Wetlands
[
calc_mean_diam weights_wet
generate_dist
]
if landcover = 43 ;Mixed
[
calc_mean_diam weights_mix
generate_dist
]
set tree_height [ 0 0 0 0 0 0 0 0 0 0 0 0 ]
set volume [ 0 0 0 0 0 0 0 0 0 0 0 0 ]
set total_volume [ 0 0 0 0 0 0 0 0 0 0 0 0 ]
end
to calc_mean_diam [weights]
let treesize [10 8 5]
let rand random-float 1
if rand < item 0 weights
[
;call subroutine
calc_mean_diam_sub
]
if rand > item 0 weights and rand < (item 0 weights + item 1 weights)
[
set mean_diam item 1 treesize
]
if rand > (item 0 weights + item 1 weights)
[
set mean_diam item 2 treesize
]
end
to calc_mean_diam_sub
let rand random-float 1
let treesize [0 2 4 6 8 10 15 20]
let distr [0.125 0.25 0.375 0.5 0.625 0.75 0.875]
;uniform distribution i.e Pr[mean_diam = treesize(i)] = 1/8 or 0.125
if rand < item 0 distr
[
set mean_diam item 0 treesize
]
if rand > item 0 distr and rand < item 1 distr
[
set mean_diam item 1 treesize
]
if rand > item 1 distr and rand < item 2 distr
[
set mean_diam item 2 treesize
]
if rand > item 2 distr and rand < item 3 distr
[
set mean_diam item 3 treesize
]
if rand > item 3 distr and rand < item 4 distr
[
set mean_diam item 4 treesize
]
if rand > item 4 distr and rand < item 5 distr
[
set mean_diam item 5 treesize
]
if rand > item 5 distr and rand < item 6 distr
[
set mean_diam item 6 treesize
]
if rand > item 6 distr
[
set mean_diam item 7 treesize
]
end
; get the basal area
; choose either the normal diam distri / negative exp distri
; half half chance
to generate_dist
if mean_diam = 0 [stop]
let target_basal_area (random 50) + 60
let running_basal_area 0
let rand random-float 1
ifelse rand < 0.5
[
;normal diameter distribution
set dist_type 0
;calculate coefficient of variation of a beta distribution
let alpha 2
let beta 5
;generate a random number from a beta distribution given a gamma distribution
let x random-gamma alpha 1
let y random-gamma beta 1
let rand_beta x / (x + y)
let cv rand_beta
let sd cv * mean_diam
while[running_basal_area < target_basal_area]
[
let tree_size random-normal mean_diam sd
if tree_size >= 0 and tree_size <= 29
[
increment_tree_bin tree_size
let basal_area 0.005454 * (tree_size ^ 2)
set running_basal_area (running_basal_area + basal_area)
]
]
]
[
;negative exponential diameter distribution
set dist_type 1
;calculate negative exp for each tree size
let lamda 1 / mean_diam
let fds [0 0 0 0 0 0 0 0 0 0 0 0]
set fds replace-item 0 fds calc_fd lamda 1.5
set fds replace-item 1 fds calc_fd lamda 4
set fds replace-item 2 fds calc_fd lamda 6
set fds replace-item 3 fds calc_fd lamda 8
set fds replace-item 4 fds calc_fd lamda 10
set fds replace-item 5 fds calc_fd lamda 12
set fds replace-item 6 fds calc_fd lamda 14
set fds replace-item 7 fds calc_fd lamda 16
set fds replace-item 8 fds calc_fd lamda 18
set fds replace-item 9 fds calc_fd lamda 20
set fds replace-item 10 fds calc_fd lamda 22
set fds replace-item 11 fds calc_fd lamda 26
let fd_sum sum fds
; divide by fd sum according to the description
let distr [0 0 0 0 0 0 0 0 0 0 0 0]
set distr replace-item 0 distr (item 0 fds / fd_sum)
set distr replace-item 1 distr (item 1 fds / fd_sum)
set distr replace-item 2 distr (item 2 fds / fd_sum)
set distr replace-item 3 distr (item 3 fds / fd_sum)
set distr replace-item 4 distr (item 4 fds / fd_sum)
set distr replace-item 5 distr (item 5 fds / fd_sum)
set distr replace-item 6 distr (item 6 fds / fd_sum)
set distr replace-item 7 distr (item 7 fds / fd_sum)
set distr replace-item 8 distr (item 8 fds / fd_sum)
set distr replace-item 9 distr (item 9 fds / fd_sum)
set distr replace-item 10 distr (item 10 fds / fd_sum)
set distr replace-item 11 distr (item 11 fds / fd_sum)
; get the prob for each tree diameter
let prob [0 0 0 0 0 0 0 0 0 0 0]
set prob replace-item 0 prob item 0 distr
set prob replace-item 1 prob (item 0 distr + item 1 distr)
set prob replace-item 2 prob (item 0 distr + item 1 distr + item 2 distr)
set prob replace-item 3 prob (item 0 distr + item 1 distr + item 2 distr + item 3 distr)
set prob replace-item 4 prob (item 0 distr + item 1 distr + item 2 distr + item 3 distr + item 4 distr)
set prob replace-item 5 prob (item 0 distr + item 1 distr + item 2 distr + item 3 distr + item 4 distr + item 5 distr)
set prob replace-item 6 prob (item 0 distr + item 1 distr + item 2 distr + item 3 distr + item 4 distr + item 5 distr
+ item 6 distr)
set prob replace-item 7 prob (item 0 distr + item 1 distr + item 2 distr + item 3 distr + item 4 distr + item 5 distr
+ item 6 distr + item 7 distr)
set prob replace-item 8 prob (item 0 distr + item 1 distr + item 2 distr + item 3 distr + item 4 distr + item 5 distr
+ item 6 distr + item 7 distr + item 8 distr)
set prob replace-item 9 prob (item 0 distr + item 1 distr + item 2 distr + item 3 distr + item 4 distr + item 5 distr
+ item 6 distr + item 7 distr + item 8 distr + item 9 distr)
set prob replace-item 10 prob (item 0 distr + item 1 distr + item 2 distr + item 3 distr + item 4 distr + item 5 distr
+ item 6 distr + item 7 distr + item 8 distr + item 9 distr + item 10 distr)
;loop
while[running_basal_area < target_basal_area]
[
;generate new tree, update bin and running_basal_area
let tree_size 0
let rand2 random-float 1
if rand2 < item 0 prob
[
set bin_list replace-item 0 bin_list ((item 0 bin_list) + 1)
set tree_size 2
]
if rand2 > item 0 prob and rand2 < item 1 prob
[
set bin_list replace-item 1 bin_list ((item 1 bin_list) + 1)
set tree_size 4
]
if rand2 > item 1 prob and rand2 < item 2 prob
[
set bin_list replace-item 2 bin_list ((item 2 bin_list) + 1)
set tree_size 6
]
if rand2 > item 2 prob and rand2 < item 3 prob
[
set bin_list replace-item 3 bin_list ((item 3 bin_list) + 1)
set tree_size 8
]
if rand2 > item 3 prob and rand2 < item 4 prob
[
set bin_list replace-item 4 bin_list ((item 4 bin_list) + 1)
set tree_size 10
]
if rand2 > item 4 prob and rand2 < item 5 prob
[
set bin_list replace-item 5 bin_list ((item 5 bin_list) + 1)
set tree_size 12
]
if rand2 > item 5 prob and rand2 < item 6 prob
[
set bin_list replace-item 6 bin_list ((item 6 bin_list) + 1)
set tree_size 14
]
if rand2 > item 6 prob and rand2 < item 7 prob
[
set bin_list replace-item 7 bin_list ((item 7 bin_list) + 1)
set tree_size 16
]
if rand2 > item 7 prob and rand2 < item 8 prob
[
set bin_list replace-item 8 bin_list ((item 8 bin_list) + 1)
set tree_size 18
]
if rand2 > item 8 prob and rand2 < item 9 prob
[
set bin_list replace-item 9 bin_list ((item 9 bin_list) + 1)
set tree_size 20
]
if rand2 > item 9 prob and rand2 < item 10 prob
[
set bin_list replace-item 10 bin_list ((item 10 bin_list) + 1)
set tree_size 22
]
if rand2 > item 10 prob
[
set bin_list replace-item 11 bin_list ((item 11 bin_list) + 1)
set tree_size 24
]
let basal_area 0.005454 * (tree_size ^ 2)
set running_basal_area (running_basal_area + basal_area)
]
]
set b_area running_basal_area
end
; get the number of tree in the tree bin
to increment_tree_bin [tree_size]
let bins [3 5 7 9 11 13 15 17 19 21 23]
if tree_size < item 0 bins
[
set bin_list replace-item 0 bin_list ((item 0 bin_list) + 1)
]
if tree_size >= item 0 bins and tree_size < item 1 bins
[
set bin_list replace-item 1 bin_list ((item 1 bin_list) + 1)
]
if tree_size >= item 1 bins and tree_size < item 2 bins
[
set bin_list replace-item 2 bin_list ((item 2 bin_list) + 1)
]
if tree_size >= item 2 bins and tree_size < item 3 bins
[
set bin_list replace-item 3 bin_list ((item 3 bin_list) + 1)
]
if tree_size >= item 3 bins and tree_size < item 4 bins
[
set bin_list replace-item 4 bin_list ((item 4 bin_list) + 1)
]
if tree_size >= item 4 bins and tree_size < item 5 bins
[
set bin_list replace-item 5 bin_list ((item 5 bin_list) + 1)
]
if tree_size >= item 5 bins and tree_size < item 6 bins
[
set bin_list replace-item 6 bin_list ((item 6 bin_list) + 1)
]
if tree_size >= item 6 bins and tree_size < item 7 bins
[
set bin_list replace-item 7 bin_list ((item 7 bin_list) + 1)
]
if tree_size >= item 7 bins and tree_size < item 8 bins
[
set bin_list replace-item 8 bin_list ((item 8 bin_list) + 1)
]
if tree_size >= item 8 bins and tree_size < item 9 bins
[
set bin_list replace-item 9 bin_list ((item 9 bin_list) + 1)
]
if tree_size >= item 9 bins and tree_size < item 10 bins
[
set bin_list replace-item 10 bin_list ((item 10 bin_list) + 1)
]
if tree_size >= item 10 bins
[
set bin_list replace-item 11 bin_list ((item 11 bin_list) + 1)
]
end
to-report calc_fd [lamda medi]
report lamda * e ^ (lamda * medi)
end
to grow-forest
;show templast
let is_forest 0
set cord 0
set mbf 0
set money_pole 0
set money_saw 0
; getting the matrix T
let treematrix matrix:make-constant 12 1 0
matrix:set-column treematrix 0 bin_list
let inter2 matrix:make-constant 12 1 0
if landcover = 41
[
let inter1 matrix:times decid_matrix treematrix
set inter2 matrix:plus decid_ingrow inter1
set is_forest 1
]
if landcover = 42
[
let inter1 matrix:times evergreen_matrix treematrix
set inter2 matrix:plus evergreen_ingrow inter1
set is_forest 1
]
if landcover = 43
[
let inter1 matrix:times mixed_matrix treematrix
set inter2 matrix:plus mixed_ingrow inter1
set is_forest 1
]
if landcover = 90
[
let inter1 matrix:times wet_matrix treematrix
set inter2 matrix:plus wet_ingrow inter1
set is_forest 1
]
if is_forest = 0
[
stop
]
; update the tree growth
set bin_list matrix:get-column inter2 0
let counter 0
set b_area 0
repeat 12
[
let dia (counter + 1) * 2
set b_area (b_area + (0.005454 * dia ^ 2) * (item counter bin_list))
set counter counter + 1
]
end
; get the matrix upgrowth, mortality, and ingrowth set up
to initialize-matrix [cover_id]
let upgrowth [0 0 0 0 0 0 0 0 0 0 0 0]
let mortality [0 0 0 0 0 0 0 0 0 0 0 0]
let ingrowth [0 0 0 0 0 0 0 0 0 0 0 0]
;set b_area 0
if cover_id = 41 ;deciduous
[
let counter 0
repeat 12
[
let dia (counter + 1) * 2
set upgrowth replace-item counter upgrowth (0.0164 - 0.0001 * 0.005454 * dia ^ 2 + 0.0055 * dia - 0.0002 * dia ^ 2)
set mortality replace-item counter mortality (0.0336 - 0.0018 * dia + 0.0001 * dia ^ 2 - 0.00002 * s-constant * dia)
set ingrowth replace-item counter ingrowth (18.187 - 0.097 * 0.005454 * dia ^ 2)
set counter counter + 1
]
]
if cover_id = 42 ;evergreen
[
let counter 0
repeat 12
[
let dia (counter + 1) * 2
set upgrowth replace-item counter upgrowth (0.0069 - 0.0001 * 0.005454 * dia ^ 2 + 0.0059 * dia - 0.0002 * dia ^ 2)
set mortality replace-item counter mortality (0.0418 - 0.0009 * dia)
set ingrowth replace-item counter ingrowth (7.622 - 0.059 * 0.005454 * dia ^ 2)
set counter counter + 1
]
]
if cover_id = 43 ;mixed
[
let counter 0
repeat 12
[
let dia (counter + 1) * 2
set upgrowth replace-item counter upgrowth (0.0134 - 0.0002 * 0.005454 * dia ^ 2 + 0.0051 * dia - 0.0002 * dia ^ 2 + 0.00002 * s-constant * dia)
set mortality replace-item counter mortality (0.0417 - 0.0033 * dia + 0.0001 * dia ^ 2)
set ingrowth replace-item counter ingrowth (4.603 - 0.035 * 0.005454 * dia ^ 2)
set counter counter + 1
]
]
if cover_id = 90 ;wetland with threes
[
let counter 0
repeat 12
[
let dia (counter + 1) * 2
set upgrowth replace-item counter upgrowth (0.0134 - 0.0002 * 0.005454 * dia ^ 2 + 0.0051 * dia - 0.0002 * dia ^ 2 + 0.00002 * s-constant * dia)
set mortality replace-item counter mortality (0.0417 - 0.0033 * dia + 0.0001 * dia ^ 2)
set ingrowth replace-item counter ingrowth (4.603 - 0.035 * 0.005454 * dia ^ 2)
;set b_area b_area + (0.005454 * dia ^ 2)
set counter counter + 1
]
]
let columns [
[0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0]
]
let column_counter 0
repeat 11
[
let temp (item column_counter columns)
set temp replace-item column_counter temp ((1 - (item column_counter mortality)) * (1 - (item column_counter upgrowth)))
set temp replace-item (column_counter + 1) temp ((1 - (item column_counter mortality)) * (item column_counter upgrowth))
set columns replace-item column_counter columns temp
set column_counter column_counter + 1
]
let templast (item 11 columns)
set templast replace-item 11 templast (1 - (item 11 mortality))
set columns replace-item 11 columns templast
let ingrowthcolumn [ 0 0 0 0 0 0 0 0 0 0 0 0 ]
set ingrowthcolumn replace-item 0 ingrowthcolumn (item 0 ingrowth)
if cover_id = 41
[
set decid_matrix matrix:from-column-list columns
set decid_ingrow matrix:make-constant 12 1 0
matrix:set-column decid_ingrow 0 ingrowthcolumn
]
if cover_id = 42
[
set evergreen_matrix matrix:from-column-list columns
set evergreen_ingrow matrix:make-constant 12 1 0
matrix:set-column evergreen_ingrow 0 ingrowthcolumn
]
if cover_id = 43
[
set mixed_matrix matrix:from-column-list columns
set mixed_ingrow matrix:make-constant 12 1 0
matrix:set-column mixed_ingrow 0 ingrowthcolumn
]
if cover_id = 90
[
set wet_matrix matrix:from-column-list columns
set wet_ingrow matrix:make-constant 12 1 0
matrix:set-column wet_ingrow 0 ingrowthcolumn
]
end
to go
let current_time ticks
let current_mod current_time mod 365
ask patches with [landcover != 11] [ init_herbs init_bugs ]
if current_mod = 0
[
set total_profit total_profit + current_profit
set current_profit 0
set total_saw total_saw + currentyear_saw
set total_pole total_pole + currentyear_pole
set currentyear_saw 0
set currentyear_pole 0
; scale the color of the forest according to the basal area size
ask patches with [landcover = 41]
[
grow-forest
if b_area > max_ba_41
[ set max_ba_41 b_area ]
]
ask patches with [landcover = 42]
[
grow-forest
if b_area > max_ba_41
[ set max_ba_41 b_area ]
]
ask patches with [landcover = 43]
[
grow-forest
if b_area > max_ba_41
[ set max_ba_41 b_area ]
]
ask patches with [landcover = 90]
[
grow-forest
if b_area > max_ba_41
[ set max_ba_41 b_area ]
]
if show-growth = true and show-growth-herbs = false
[
ask patches with [landcover = 41] [ draw-forest min_ba_41 max_ba_41 ]
ask patches with [landcover = 42] [ draw-forest min_ba_41 max_ba_41 ]
ask patches with [landcover = 43] [ draw-forest min_ba_41 max_ba_41 ]
ask patches with [landcover = 90] [ draw-forest min_ba_41 max_ba_41 ]
]
]
; change the nest amount by adjusting a range for current mod
; get the amount of tree suitable for bird nesting
if current_mod >= 182 and current_mod <= 186
[
ask patches with [landcover = 42]
[
let counter 4
repeat 8
[
set bird-nests bird-nests + item counter bin_list
set counter counter + 1
]
; bird nest changed
set bird-nests (bird-nests / 30)
set bird-nests round bird-nests
;print (bird-nests)
]
]
ask birds
[
bird-eat
set lifetime lifetime - 1
bird-die
if current_mod < 152 or current_mod > 244
[
stop
]
if current_mod = 152
[
show-turtle
]
if current_mod >= 152 and current_mod < 182 or current_mod > 187 and current_mod < 243
[
if [count birds] of patch-here > 3 [
bird-fight
]
]
; bird-reproducing at certain range, changed
if current_mod >= 182 and current_mod <= 187
[
bird-repro
]
; if energy < 100 and lifetime, lifetime is the additional condition for bird to die
; migrate to the south
if current_mod = 243
[
hide-turtle
if energy < 100 and lifetime < 730
[ die ]
]
]
tick
end
to init_herbs
let doy ticks mod 365
;let r_p 0.5
;let r_die 0.1
;let K 5
;initialization / budding
;if landcover = 41 or landcover = 42 or landcover = 43 or landcover = 90
;[
;set K 3
;]
;if doy = 1 [set herb_veg herb_veg + 1]
let delta_pt 0
;calculate delta_pt
;ifelse doy < 175
;[
;set delta_pt r_p * herb_veg * (1 - (herb_veg / K))
;]
;[
;set delta_pt (-1) * r_p * herb_veg
;]
;New population model
set delta_pt (herb_veg * r_p) - (herb_veg * bug_pop * plant_eating)
set herb_veg herb_veg + delta_pt
if show-growth-herbs = true and show-growth = false
[
set pcolor scale-color green herb_veg 6 0
]
end
to init_bugs
let doy ticks mod 365
;let r_h 0.1
let delta_ht 0
;if doy = 1 [set bug_pop bug_pop + 1]
;calcualte delta_ht
set delta_ht (bug_pop * herb_veg * r_h) - (bug_pop * bug_die)
set bug_pop bug_pop + delta_ht
end
to draw-forest [min_ba max_ba ]
let self-land landcover
set pcolor scale-color pcolor b_area min_ba max_ba
end
to draw-cut
if mouse-down? and mouse-inside? [
ask patch mouse-xcor mouse-ycor [
if landcover = 41 or landcover = 42 or landcover = 43 or landcover = 90
[
calc_profit
; cut all trees
; get the money profit from tree cut and update the bin list
if strategy = "clear-cut"
[
set bin_list [ 0 0 0 0 0 0 0 0 0 0 0 0 ]
show money_pole
show money_saw
set current_profit (current_profit + money_pole + money_saw)
show bin_list
]
; get the index of diameter, repeat and cut all trees above the designated diameter
if strategy = "diameter"
[
let index (dia-cut / 2) - 1
let index-end 12 - index
repeat index-end
[
set bin_list replace-item index bin_list 0
set index index + 1
]
let old_pole money_pole
let old_saw money_saw
calc_profit
set current_profit (current_profit + (old_pole - money_pole) + (old_saw - money_saw))
set currentyear_pole currentyear_pole + cord
set currentyear_saw currentyear_saw + mbf
show bin_list
]
; select which class category of tree diameter
; then select the q value according to the tree diameter class
; get the total basal area of current tree across diameters
; loop to get the total basal area for a category of tree diameters
; set the new bin list according to the ratio
if strategy = "bdq"
[
ifelse b_area > B
[
let counter 0
repeat 4
[
let new_b_area 0
let new_bin 0
let inner_count 0
let endpoint 3
let startpoint 0
; set the # of times to run the bdq for the diameter onwards
if counter = 0 [ set endpoint 2 set startpoint 0 ]
if counter = 1 [ set endpoint 3 set startpoint 2 ]
if counter = 2 [ set endpoint 2 set startpoint 5 ]
if counter = 3 [ set endpoint 5 set startpoint 7 ]
repeat endpoint
[