-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sleepy IBM_v.6.1.nlogo
2149 lines (1852 loc) · 62.3 KB
/
Sleepy IBM_v.6.1.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
;**********************************************************************************************************************
;******************************************** ************************************************
;******************************************** Soft foraging submodel ************************************************
;******************************************** ************************************************
;**********************************************************************************************************************
;*********************************************************
;******* Space and time specifics of model *********
;*********************************************************
; Spatial scale: 50 * 50 m
; 1 patch = 2 m
; 1 tick = 2 min
; 1 day = 720 ticks
; i tick = 2 bites possible for small food; 5 bites possible for large food
;*********************************************************
;********************* Interface ********************
;*********************************************************
; Energy cost of individual
; =========================
; Movement-cost: Cost (J) of moving one patch (2 m). Calculated from DEB model.
; Maintenance-cost: Cost (J) of paying maintenance. Calculated from DEB model.
; Energy gain of individual
; =================
; Low-food gain: Energy gain (J) from small food items (Brown 1991).
; High-food gain: Energy gain (J) from large food items (Brown 1991).
; kap_X: Converison efficiency of assimilated energy from food (J) (Kooijman 2010).
; Food patch growth
; =================
; Food-growth: Growth of plant material (J) per tick (Norman et al. 2008).
; Large-food-initial: Initial energy level (J) of large food items at setup. Parameterised from literature.
; Small-food-initial: Initial energy level (J) of small food items at setup. Parameterised from literature.
; Individual attributes
; ===================
; Maximum-reserve: Maximum reserve level (J). Appears in 'to setup' and 'to make decision'.
; Minimum-reserve: Define the critical starvation period. Individuals can survive without food for two hours in this state (reasonable estimate). The threshold of reserve that induces the increasing visual scope of the individual. Vision increases by 2 patches every tick to the maximum vision range (10 patches (20 m)).
;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
; extensions [r] ; Extension for calling R commands from NetLogo
globals
[
in-shade? ; Reports TRUE if turtle is in shade
in-food? ; Reports TRUE if turtle is in a food patch
min-energy ; Minimum food unit level for individual to lose interest and move away from patch. This eliminates the incentive for individuals to return immediately to the previously visited food patch after vacating it.
reserve-level ; Reserve level of individual.
min-vision ; Minimum (normal) vision range of individuals (Auburn et al. 2009).
max-vision ; Maximum vision range of individuals activated by starvation mode. See 'to starving' procedure (Auburn et al. 2009)
ctmincount ; Counter for time spent under min_T_b_
feedcount ; Counter for time spent in feeding state.
restcount ; Counter for the time spent resting in shade
searchcount ; Counter for time spent searching for food.
starvecount ; Counter for time spent in starvation state.
shadecount ; Counter for time spent searching for shade following a feeding bout.
transcount ; Counter for frequency of transitions between any of the three activity states--searching, feeding, resting.
zenith ; Zenith angle of sun (update-sun procedure).
tempX
tempY
tempXY
gutfull ; Reports gut level of DEB model
]
turtles-own
[
activity-state ; Individual is either under a Searching, Feeding, or Resting state for each tick. The transition between the various activity states defines the global behavioural repetoire.
energy-gain ; Converted energy gained from food
; high-energy-gain ; Converted energy gained from large food items
; search-energy ; Minimum reserve that satisficing individual reaches to stop resting and start searching. Defined in Setup as fraction of total reserve. This is the crux of the satisficing strategy--rest only until food is needed.
;T_b_init_ ; Initial body temperature (T_b_init) of individual (Celcius)
T_b_ ; Body temperature (T_b) of individual (Celcius)
T_b_basking_ ; Basking body temperature of individual (Celcius)
T_opt_range ; Foraging body temperature range of individual (Celcius)
T_opt ; Median foraging body temperature of individual (Celcius)
T_opt_lower_ ; Lower foraging body temperature of individual (Celcius)
T_opt_upper_ ; Upper foraging body temperature of individual (Celcius)
min-T_b_ ; Lower critical body temperature (min-T_b) of individual (Celcius)
max-T_b_ ; Upper critical body temperature (max-T_b) of individual (Celcius)
vision-range ; Vision (no. of patches) range of individual.
;strategy ; *> Interface <* Defines the foraging strategy of individual. This is set in the Interface and is thus masked in the code.
has-been-starving? ; Results reporter only variable for reporting stavation time only if individual has starved
has-been-feeding? ; Results reporter only variable for reporting feeding time only if individual has been feeding
X ; List of x coords for homerange
Y ; List of y coords for homerange
gutthresh_ ; Threshold for gutlevel to motivate turtle to move
V_pres_ ; DEB structural volume
wetgonad_ ; DEB wet mass reproductive organ volume
wetstorage_ ; DEB wet mass storage
wetfood_
hungerstate
thermalstate
matestate
fearstate
]
patches-own
[
patch-type ; Defines type of patches in environment as either Food or Shade.
food-level ; *> Interface <* Defines the initial and updated level of energy (J) in food patches. Food level increases (plant growth; see 'Food patch growth' in Interface) and decreases (feeding by individual) with each tick.
shade-level ; *> Interface <* Defines the initial and updated level of shade in shade patches. Shade levels remain constant throughout simulation.
]
breed
[suns sun]
breed
[homeranges homerange]
;********************************************************************************************************************
;*********************************************** SETUP ****************************************************
;********************************************************************************************************************
;;; testing file import of sleepy lidar
;to startup
; ;; read the elevations from an external file
; ;; note that the file is formatted as a list
; ;; so we only have to read once into a local variable.
; file-open "/Users/matthewmalishev/Documents/Postgrad study/Melbourne Uni/Data/Sleepies/waddleometer_shade/"
; let patch-elevations file-read
; file-close
; set color-max max patch-elevations ;; put a little padding on the upper bound so we don't get too much
; ;; white and higher elevations have a little more variation.
; let min-elevation min patch-elevations
; ;; adjust the color-min a little so patches don't end up black
; set color-min min-elevation - ((color-max - min-elevation) / 10)
; ;; transfer the date from the file into the sorted patches
; ( foreach sort patches patch-elevations
; [ ask ?1 [ set elevation ?2 ] ] )
; ;setup
;end
to setup
ca
if Food-patches + Shade-patches > count patches
[ user-message (word "Lower the sum of shade and food patches to < " count patches ".")
stop ]
random-seed 1 ; Outcomment to generate seed for spatial configuration of all patches in the landscape (food and shade). For reproducibility. NB: turtle movement is still stochastic. See below random-seed primitive for complete function.
set min-energy Small-food-initial
set min-vision 5 ; 10m (Auburn et al. 2009)
set max-vision 10 ; 20m (Auburn et al. 2009)
ask patches
[set patch-type "Sun"
set pcolor (random 1 + blue)]
let NumFoodPatches Food-patches / 10 ; divide by 10 because patches are clumped
ask n-of NumFoodPatches patches [
ask n-of 10 patches in-radius 4 [ ; Sets 10 random food patches within a 5-patch radius of Food-patches
let food-amount random 100
ifelse food-amount < 50
[set food-level (Small-food-initial) + random-float 1 * 10 ^ -5] ; Makes only one food patch attractive to turtle
[set food-level (Large-food-initial) + random-float 1 * 10 ^ -5]
set pcolor PatchColor
set patch-type "Food"
]
]
let NumShadePatches Shade-patches
ask n-of NumShadePatches patches [
let shade-amount random 100
ifelse shade-amount < 50
[set shade-level (Low-shade + random-float 1 * 10 ^ -5) ; Makes only one shade patch attractive to turtle
set pcolor black + 2]
[set shade-level (High-shade + random-float 1 * 10 ^ -5)
set pcolor black]
set patch-type "Shade"
]
ask patch 0 0 [set patch-type "Shade"
set pcolor black]
; ask one-of patches with [patch-type = "Shade"]
; [sprout 1]
crt 1
random-seed new-seed ; Outcomment to generate seed for spatial configuration of all patches in the landscape (food and shade).
ask turtle 0
[
setxy 0 0 ;random-xcor random-ycor
set reserve-level Maximum-reserve
set T_b_basking_ 14
set T_opt_range (list 26 27 28 29 30 31 32 33 34 35 ) ; From Pamula thesis
set T_opt_upper last T_opt_range
set T_opt_lower first T_opt_range
set T_opt median T_opt_range
set min-T_b_ min-T_b
set max-T_b_ max-T_b
set V_pres_ V_pres
set wetgonad_ wetgonad
set wetstorage_ wetstorage
set wetfood_ wetfood
set activity-state "S"
; set strategy "Optimising"
set vision-range min-vision
if [patch-type] of patch-here = "Shade"
[set in-shade? TRUE]
if [patch-type] of patch-here = "Food"
[set in-food? TRUE]
set shape "lizard"
set size 2
set color red
pen-down
set X (list xcor)
set Y (list ycor)
]
setup-spatial-plot
;create-sun
reset-ticks
;r:clear ; extensions [r] command. Outcomment if calling R from Netlogo.
end
;********************************************************************************************************************
;*********************************************** GO *****************************************************
;********************************************************************************************************************
to go
tick
if not any? turtles
[
get-homerange
print "All turtles dead. Check output of model results."
repeat 3 [beep wait 0.2]
stop
save-world
]
if (ticks * 2 / 60 / 24) = No.-of-days
[
ask turtle 0
[report-results]
save-plots
stop
save-world
]
ifelse show-plots?
[]
[clear-all-plots]
ask turtle 0
[
report-patch-type
; set reserve-level reserve-level - Maintenance-cost
ask turtles with [reserve-level > Minimum-reserve]
[set vision-range min-vision]
update-T_b
;if (activity-state = "R" and [patch-type] of patch-here != "Shade")
; [shade-search]
make-decision
update-wetmass
; if activity-state = "R" and [patch-type] of patch-here = "Shade"
; [rest]
set X lput xcor X ; populate X list with turtle's X coords to generate home range
set Y lput ycor Y ; populate Y list with turtle's Y coords to generate home range
]
ask turtles with [reserve-level <= 0]
[report-results]
ask patches with [patch-type = "Food"]
[update-food-levels]
;update-sun
end
;*****************************************************************************************************************************
;************************************************* TO UPDATE T_b ******************************************************
;*****************************************************************************************************************************
to update-T_b
ask turtles with [T_b >= max-T_b]
[stop]
if T_b <= min-T_b
[set ctmincount ctmincount + 1]
if (ctmincount * 2 / 60) = ctminthresh
[stop]
end
;*****************************************************************************************************************************
;************************************************* TO MAKE DECISION **************************************************
;*****************************************************************************************************************************
to make-decision
ifelse (T_b > T_opt_upper) or (T_b < T_opt_lower) or (gutfull >= gutthresh); 'gutfull' is DEB.R input
[
ask turtle 0
[;set label "Resting"
set activity-state "R"
ifelse gutfull >= gutthresh and T_b < T_opt_upper and T_b > T_opt_lower
[;set label "Full gut"
stop ]
[if [patch-type] of patch-here != "Shade"
[shade-search]]
if ([patch-type] of patch-here = "Shade") and (T_b < T_b_basking_)
[set in-shade? TRUE]
]
if (activity-state = "R") and (T_b >= T_b_basking_) and (T_b < T_opt_upper) ; Basking behaviour
[set in-shade? FALSE
; set transcount transcount + 1 ; Outcomment to include basking behaviour as activity state
; plotxy xcor ycor
]
set restcount restcount + 1
]
[
if (activity-state = "R")
[
set restcount restcount + 1
; set label "Resting"
if ((T_b <= T_opt_upper) and (T_b >= T_opt_lower)); and reserve-level < search-energy
[set transcount transcount + 1
plotxy xcor ycor
set activity-state "S"]
; [set activity-state "R"]
]
; 28-11-14: Only works with maint. or movement costs, otherwise reserve level = Max. reserve and turtle chooses to rest
if (activity-state = "F"); Use this procedure to eliminate turtle returning to shade patch after every feeding bout and to eliminate min-energy parameter. Using min-energy will cause problems in model with soil moisture profile updating food growth.
[ ; Turning empty food patches into Sun patches elimates the need for min-energy.
ifelse (gutfull < gutthresh) ;and ([patch-type] of patch-here = "Food") ; if gut is not full, keep feeding, else stop.
[
ask turtle 0
[handle-food
;set label "Feeding"
set has-been-feeding? TRUE]
if [patch-type] of patch-here != "Food"
[set activity-state "S"
set transcount transcount + 1
plotxy xcor ycor
set energy-gain 0]
if reserve-level >= Maximum-reserve ; Turtle will fight between feeding and resting if DEB model not activated i.e. reserve incurs no cost.
[set transcount transcount + 1
plotxy xcor ycor
; ifelse (strategy = "Optimising")
; [set activity-state "S"]
set activity-state "R"
stop]
]
[;set label "Gut is full"
stop]
]
if (activity-state = "S")
[
ask turtle 0
[search
; set label "Searching for food"
]
set searchcount searchcount + 1
if ([patch-type] of patch-here = "Food") ;and ([food-level] of patch-here > min-energy)
[set transcount transcount + 1
plotxy xcor ycor
set activity-state "F"]
]
]
end
;**********************************************************************************************************************
;*********************************************** TO SEARCH ***************************************************
;**********************************************************************************************************************
to search
set reserve-level reserve-level - Movement-cost ; set to small number to avoid turtle exiting green food patches when feeding
bounce
let local-food-patches patches with [(distance myself < [vision-range] of turtle 0) and (patch-type = "Food")]
ifelse any? local-food-patches
[let my-food-patch local-food-patches with-min [distance myself] ;with-max [food-level]
face one-of my-food-patch]
[lt random 180 - 90 ]
fd 1
if [patch-type] of patch-here = "Food"
[set activity-state "F"]
end
;**************************************************************************************************************************
;********************************************** TO BOUNCE **********************************************************
;**************************************************************************************************************************
to bounce
;; Turtles turn a random angle ~180 when encountering a wall
ask turtle 0
[ if abs pxcor = abs max-pxcor or
abs pycor = abs max-pycor
[lt random-float 180 ]
]
end
;**************************************************************************************************************************
;********************************************** TO HANDLE FOOD ****************************************************
;**************************************************************************************************************************
to handle-food
set energy-gain Low-food-gain
;set in-food? TRUE
set feedcount feedcount + 1
set-current-plot "Spatial coordinates of transition between activity states"
set-current-plot-pen "Feeding"
ifelse [pcolor] of patch-here = 45
[set-plot-pen-color 45]
[set-plot-pen-color 55]
plotxy xcor ycor
end
;**************************************************************************************************************************
;******************************************** TO SHADE SEARCH ***************************************************
;**************************************************************************************************************************
to shade-search
set reserve-level reserve-level - Movement-cost ; set to small number to avoid turtle exiting green food patches when feeding
let local-shade-patches patches with [(distance myself < [vision-range] of turtle 0) and (patch-type = "Shade")]
ifelse any? local-shade-patches
[let my-shade-patch local-shade-patches with-min [distance myself] with-max [shade-level]
face one-of my-shade-patch
set shadecount shadecount + 1]
[lt random 180 - 90]
fd 1
; set label "Searching for shade"
; if [patch-type] of patch-here = "Shade"
; [set activity-state "R"]
end
;**************************************************************************************************************************
;********************************************* TO REST *********************************************************
;**************************************************************************************************************************
to rest
ifelse strategy = "Optimising"
[set activity-state "S"]
[set activity-state "R"]
end
;**************************************************************************************************************************
;********************************************* TO STARVE ******************************************************
;**************************************************************************************************************************
to starving
set vision-range vision-range + (max-vision / 6)
ask turtle 0
[set label "Starving"
print "I'm starving"
set has-been-starving? TRUE]
end
;*********************************************************************************************************************************
;*********************************************** TO UPDATE FOOD LEVELS ***************************************************
;*********************************************************************************************************************************
to update-food-levels
let food-deplete food-level - Low-food-gain
if count turtles-here with [activity-state = "F"] > 0
; [ifelse food-level < Large-food-initial
[set food-level food-deplete ; yellow food
set in-food? TRUE
print "In food"]
; [set food-level food-level - (Low-food-gain * 2)] ; green food
; ]
;[set food-level food-level + Food-growth] ; growing food
if food-level < Small-food-initial
[set patch-type "Sun"]
set pcolor PatchColor
end
;*********************************************************************************************************************************
;*********************************************** TO UPDATE WETMASS *******************************************************
;*********************************************************************************************************************************
to update-wetmass
; set V_pres_ V_Pres
; plotxy xcor ycor
; set wetstorage_ wetstorage
; plotxy xcor ycor
; set wetfood_ wetfood
; plotxy xcor ycor
; set wetgonad_ wetgonad
; plotxy xcor ycor
end
;*********************************************************************************************************************************
;*********************************************** TO REPORT PATCH COLOUR ***************************************************
;*********************************************************************************************************************************
to-report PatchColor
let PatColor 0
ifelse food-level >= Large-food-initial
[set PatColor green]
[ifelse food-level >= Small-food-initial
[set PatColor yellow]
[set PatColor brown]
]
report PatColor
end
;*********************************************************************************************************************************
;*********************************************** TO REPORT PATCH-TYPE *****************************************************
;*********************************************************************************************************************************
to report-patch-type
ifelse [patch-type] of patch-here = "Food"
[set in-food? TRUE]
[
ifelse [patch-type] of patch-here = "Shade"
[set in-shade? TRUE]
[set in-shade? FALSE
set in-food? FALSE]
]
end
;*********************************************************************************************************************************
;*********************************************** TO REPORT RESULTS *******************************************************
;*********************************************************************************************************************************
to report-results
output-print (word "Number of real days:,, " precision (ticks * 2 / 60 / 24) 5)
output-print ""
output-print (word "Time spent searching for food (mins/days):, " (searchcount * 2) " , " precision (searchcount * 2 / 60 / 24) 3 "")
output-print ""
output-print (word "Time spent feeding (mins/days):, " (feedcount * 2) " , " precision (feedcount * 2 / 60 / 24) 3 "")
output-print ""
output-print (word "Time spent searching for shade (mins/days):, " (shadecount * 2) " , " precision (shadecount * 2 / 60 / 24) 3 "")
output-print ""
output-print (word "Time spent resting in shade (mins/days):, " (restcount * 2) " , " precision (restcount * 2 / 60 / 24) 3 "")
output-print ""
output-print (word "Time spent in critical starvation (mins/days):, " (starvecount * 2) " , " precision (starvecount * 2 / 60 / 24) 3 "")
output-print ""
output-print (word "Number of transitions between activity states:, " transcount)
output-print ""
ifelse has-been-feeding? = TRUE
[output-print (word "Proportion of feeding to searching:, " precision (feedcount / searchcount) 3)]
[output-print (word "Proportion of feeding to searching:, " 0)]
output-print ""
ifelse has-been-starving? = TRUE
[output-print (word "Proportion of feeding to starving:, " precision (feedcount / starvecount) 3)]
[output-print (word "Proportion of feeding to starving:, " 0)]
output-print ""
output-print (word "Patches with pcolor = brown (eaten): " patches with [pcolor = 35])
stop;die
end
;*********************************************************************************************************************************
;*********************************************** TO SAVE WORLD ***********************************************************
;*********************************************************************************************************************************
to save-world ; This procedure saves the model world. The file output procedure then outputs the saved model world as a .txt file to the Desktop.
let world user-new-file
if ( world != false )
[
file-write world
ask patches
[
file-write pxcor
file-write pycor
if patch-type = "Food"
[file-write pxcor and pycor and (patch-type = "Food") and food-level]
if patch-type = "Shade"
[file-write pxcor and pycor and (patch-type = "Shade") and shade-level]
]
file-close
]
end
to save-plots
;export-plot "Spatial coordinates of transition between activity states" "/Users/matthewmalishev/Documents/Manuscripts/Malishev and Kearney/Figures/Simulations/spatialplottest.csv"
end
;*********************************************************************************************************************************
;*********************************************** SPATIAL PLOT ****************************************************
;*********************************************************************************************************************************
to setup-spatial-plot
set-current-plot "Spatial coordinates of transition between activity states"
set-plot-x-range min-pxcor max-pxcor
set-plot-y-range min-pycor max-pycor
clear-plot
end
;*********************************************************************************************************************************
;*********************************************** GET HOMERANGE ***************************************************
;*********************************************************************************************************************************
to get-homerange
;r:eval "library(adehabitatHR)" ; load the r packages
;r:eval "library(sp)"
;
;r:eval "turtles<-data.frame()" ; make an empty data frame
;
;ask turtle 0
;[
; (r:putdataframe "turtle" "X" X "Y" Y) ; put the X and Y coords into a dataframe
; r:eval (word "turtle<-data.frame(turtle,ID = '"ID"')")
; r:eval "turtles<-rbind(turtles,turtle)"
; ]
;
;r:eval "spdf<-SpatialPointsDataFrame(turtles[1:2], turtles[3])" ; creates a spatial points data frame (adehabitatHR package)
;r:eval "homerange<-mcp(spdf)"
draw-homerange
save-homerange
;plot-area
end
;*********************************************************************************************************************************
;*********************************************** DRAW HOMERANGE **************************************************
;*********************************************************************************************************************************
to draw-homerange
clear-drawing
if any? turtles [
ask turtle 0
[
pu
; calculate homerange points
; r:eval (word "temp <- slot(homerange,'polygons')[[which(slot(homerange,'data')$id == '"ID"')]]@Polygons[[1]]@coords")
; set tempX tempX
; set tempY tempX
; set tempXY tempXY
; hatch a turtle to draw the homerange boundary points
hatch-homeranges 1
[
hide-turtle
; set ID [ID] of myself
set color red
]
; draw the homerange
foreach tempXY
[
ask homeranges
[
move-to patch (item 0 ?) (item 1 ?)
pd
]
]
; close the homerange polygon
ask homeranges
[
let lastpoint first tempXY
move-to patch (item 0 lastpoint) (item 1 lastpoint)
]
]
]
end
;*********************************************************************************************************************************
;*********************************************** SAVE HOMERANGE **************************************************
;*********************************************************************************************************************************
to save-homerange
; save the homerange polygon into a pdf
; r:eval (word "pdf('" Homerange-poly_dir ".pdf')" )
; r:eval (word "plot(homerange, xlim=c(" min-pxcor "," max-pxcor "), ylim=c(" min-pycor "," max-pycor "))")
; r:eval "plot(spdf,col=as.data.frame(spdf)[,1],add=T)"
; r:eval "dev.off()"
;
; ; save a plot of the homerange area level into a pdf
; r:eval (word "pdf('"Homerange-plot_dir".pdf')")
; r:eval "plot(mcp.area(spdf,unout='m2'))"
; ; r:eval (word "plot(mcp.area(spdf,unout='m2'), main=Homerange polygon for "No.-of-days" days with "Shade-patches" shade and "Food-patches" food patches)")
; r:eval "dev.off()"
end
;*********************************************************************************************************************************
;*********************************************** CREATE AND UPDATE SUN *******************************************
;*********************************************************************************************************************************
to create-sun
create-suns 1
[
set shape "orbit 1" ;"clock"
set size 5
set color yellow
setxy (max-pxcor - 3) (max-pycor - 3)
set heading 270
set label (word 0 " " "days")
set heading zenith
set label zenith
]
end
to update-sun
ask suns
[set heading heading + 0.5
set label (word precision (ticks * 2 / 60 / 24) 1 " " "days")
ifelse (heading > 270) or (heading < 90)
[set shape "orbit 1"
set color yellow]
[set shape "moon zenith"
set size 5
set color [pcolor] of patch-here]
set heading zenith
set label ticks
]
end
;*********************************************************************************************************************************
;******************************************* REFERENCES ********************************************************
;*********************************************************************************************************************************
; Auburn, Z. M., Bull, C. M. and Kerr G. D. (2009) The visual perceptual range of a lizard, Tiliqua rugosa, J. Ethol. 27:75-81.
; Brown, G. W. (1991) Ecological feeding analysis of south-eastern Australian Scincids (Reptilia--Lacertilia), Aust. J. Zool. 39:9-29.
; Kooijman, S. A. L. M. (2010) Dynamic Energy Budget theory for metabolic organisation. Cambridge University Press.
; Norman, H. C., Mayberry, D. E., McKenna, D. J., Pearce, K. L. & Revell D. K. (2008) Old man saltbush in agriculture: feeding value for livestock production systems, 2nd International Salinity Forum: Salinity, water and society--global issues, local action.
; Pamula thesis
@#$#@#$#@
GRAPHICS-WINDOW
388
10
1157
800
375
375
1.011
1
10
1
1
1
0
0
0
1
-375
375
-375
375
1
1
1
ticks
30.0
BUTTON
7
502
70
535
NIL
setup
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
BUTTON
136
502
217
535
go once
go
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
BUTTON
72
502
135
535
NIL
go
T
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
MONITOR
805
856
940
901
Time spent feeding
feedcount
17
1
11
PLOT
1166
762
1646
1011
Total wetmass plot
Time
Total wetmass
0.0
10.0
0.0
10.0
true
true
"" "let total 0\n\nset-current-plot-pen \"V_pres\"\nplot-pen-up plotxy ticks total\nset total V_pres + total \nplot-pen-down plotxy ticks total\n\nset-current-plot-pen \"wetstorage\"\nplot-pen-up plotxy ticks total\nset total wetstorage + total \nplot-pen-down plotxy ticks total\n\n\nset-current-plot-pen \"wetfood\"\nplot-pen-up plotxy ticks total\nset total wetfood + total\nplot-pen-down plotxy ticks total\n\nset-current-plot-pen \"wetgonad\"\nplot-pen-up plotxy ticks total\nset total wetgonad + total\nplot-pen-down plotxy ticks total"
PENS
"V_pres" 1.0 0 -955883 true "" ""
"wetstorage" 1.0 0 -6459832 true "" ""
"wetfood" 1.0 0 -13840069 true "" ""
"wetgonad" 1.0 0 -5825686 true "" ""
OUTPUT
425
960
869
1267
13
INPUTBOX
6
572
102
632
Movement-cost
0
1
0
Number
INPUTBOX
106
572
211
632
Maintenance-cost
0
1
0
Number
INPUTBOX
10
758
91
818
Food-growth
30
1
0
Number
TEXTBOX
8
546
158
564
Energy cost of individual
12
0.0
0
TEXTBOX
11
737
122
755
Food patch growth
12
0.0
0
INPUTBOX
9
666
100
726
Low-food-gain
3000
1
0
Number
TEXTBOX
8
642
158
660
Energy gain of individual
12
0.0
0
INPUTBOX
173
852
273
912
Minimum-reserve
100
1
0
Number
TEXTBOX
12
829
130
847
Individual attributes
12
0.0
1
INPUTBOX
97
758
201
818
Large-food-initial
6000
1
0
Number
INPUTBOX
207
759
311
819
Small-food-initial
3000
1
0
Number
PLOT
1166
10
1643
254
Reserve level and starvation reserve over time
NIL
NIL
0.0
10.0
0.0
10.0
true
true
"" ";let t reserve-plot-range \n;if ticks > t \n;[set-plot-x-range (ticks - t) ticks]"
PENS
"Reserve level" 1.0 0 -16777216 true "" "if any? turtles\n[plot [reserve-level] of turtle 0]"
"Starvation reserve" 1.0 0 -5298144 true ";plot Minimum-reserve\nauto-plot-off\nplotxy 0 Minimum-reserve \nplotxy 100000000 0\nauto-plot-on" ""
CHOOSER
6
160
98
205
Strategy
Strategy
"Optimising" "Satisficing"
0
TEXTBOX
7
137
157
155
Individual characteristics\n
12
0.0
0
TEXTBOX
7
12
215
134
*********************************\n********** Instructions **********\n*********************************\n\n1. Set the foraging strategy of the \n individual using the chooser. \n Read the notes within the Info \n tab to learn about the strategies.
12
125.0
1
TEXTBOX
8
463
239