-
Notifications
You must be signed in to change notification settings - Fork 4
/
HumanEcology.nlogo
1614 lines (1376 loc) · 45.7 KB
/
HumanEcology.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
globals [food_collection_left food_collection_right predatorx predatory pher_ahead new_distance curr_distance dist pile_radius GAdev GAevap GArecruit GAtrail_drop GAtrail GAsite GAexpand
rfood_counter1 rfood_counter2 sfood_counter1 sfood_counter2 mfood_counter1 mfood_counter2 lfood_counter1 lfood_counter2 food_totall food_totalr]
breed [humans human]
humans-own [trail_ahead behavior nestx boundary? has_food? foodx foody fidelity recruit]
patches-own [sfood? mfood? lfood? ofood? pheremone? ]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;main setup function;;;;;;;;;;main setup function;;;;;;;;;;main setup function;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to setup_world
;; (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
create_large_food
create_medium_food
create_small_food
create_other_food
setup_humans
ask patches [
set pcolor red
if pxcor < 1 and pxcor > -1
[ set pcolor black
]
]
end
to setup_save ;function re-generates a perviously saved pile configuration
ask patches [
set pheremone? 0 ;resets all pheromone values
set pcolor green ;refreshes the world in base green color
if pxcor < 1 and pxcor > -1 [
set pcolor black
]
if lfood? = 1 [
set pcolor red ;colors red dense piles
]
if mfood? = 1 [
set pcolor yellow ;colors medium density piles
]
if sfood? = 1 [
set pcolor 7 ;colors random seeds
]
if ofood? = 1 [
set pcolor 123 ;colors low density piles
]
]
ask humans [ ;resets all humans by removing existing humans
die
]
setup_humans ;re-generates human city
clear-all-plots ;resets the graph
reset-ticks ;resets the time step
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;creates locations for food piles;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to create_large_food ;function for dense food pile creation
set pile_radius 100 ;creates a circle with an area of exactly 256 pixels
ask patches [
set pcolor green ;;colors entire world green
if pxcor < 1 and pxcor > -1 [
set pcolor black
]
]
let xl 1 ;local variable for the x location of large food
let yl 1 ;local variable for the y location of large food
let pile_true 1 ;defines feasible location for piles
let head 1
let pile_count 0 ;counter for existing piles
while [pile_count < Large_piles] [ ;iterates function until number of food piles is equal to the number in the slider
set pile_true 1
set xl (-190 + random 180) ;if piles are generated ontop of each other, picks a new random pile location
set yl (-90 + random 181)
ask patch xl yl [
repeat 360 [
set head (head + 1) ;scans all patches in a circle around pile location
ask patch-at-heading-and-distance head 10 [
if pcolor = red [
set pile_true 0 ;checks to see if piles are being generated ontop of each other
]
]
]
]
if pile_true = 1 [
set pile_count (pile_count + 1) ;increments pile counter
ask patches [
if (distancexy xl yl) <= pile_radius [ ;;creates a circle of food with area equivalent to 256 seeds
set pcolor red
ask patch-at 200 0 [
set pcolor red
]
]
]
]
]
set lfood_counter1 count patches with [pcolor = red and pxcor < 0]
set lfood_counter2 count patches with [pcolor = red and pxcor > 0]
end
to create_medium_food ;function for medium density food creation
set pile_radius 9.027033336764101
let xm 1 ;pile x coordinate
let ym 1 ;pile y coordinate
let pile_true 1 ;checks for pile location validity
let head 1
let pile_count 0 ;value to determine number of generated piles
while [pile_count < Medium_piles] [ ;iterates function until number of food piles is equal to the number in the slider
set pile_true 1
set xm (-190 + random 180) ;if piles are generated ontop of each other, picks a new random pile location
set ym (-90 + random 181)
ask patch xm ym [
repeat 360 [
set head (head + 1) ;scans all patches in a circle around pile location
ask patch-at-heading-and-distance head 10 [
if pcolor = red or pcolor = yellow [ ;checks to see if piles are being generated ontop of each other
set pile_true 0
]
]
]
]
if pile_true = 1 [
set pile_count (pile_count + 1) ;increments pile counter
ask patches [
if (distancexy xm ym) <= pile_radius [ ;;creates a circle of food with area equivalent to 256 seeds
if random 4 < 1 [
set pcolor yellow
ask patch-at 200 0 [
set pcolor yellow
]
]
]
]
]
]
set mfood_counter1 count patches with [pcolor = yellow and pxcor < 0]
set mfood_counter2 count patches with [pcolor = yellow and pxcor > 0]
end
to create_other_food ;function for medium density food creation
set pile_radius 9.027033336764101
let xo 1 ;pile x coordinate
let yo 1 ;pile y coordinate
let pile_true 1 ;checks for pile location validity
let head 1
let pile_count 0 ;value to determine number of generated piles
while [pile_count < Low_density_piles] [ ;iterates function until number of food piles is equal to the number in the slider
set pile_true 1
set xo (-190 + random 180) ;if piles are generated ontop of each other, picks a new random pile location
set yo (-90 + random 181)
ask patch xo yo [
repeat 360 [
set head (head + 1) ;scans all patches in a circle around pile location
ask patch-at-heading-and-distance head 10 [
if pcolor = red or pcolor = yellow or pcolor = 123 [ ;checks to see if piles are being generated ontop of each other
set pile_true 0
]
]
]
]
if pile_true = 1 [
set pile_count (pile_count + 1) ;increments pile counter
ask patches [
if (distancexy xo yo) <= pile_radius [ ;;creates a circle of food with area equivalent to 256 seeds
if random 16 < 1 [
set pcolor 123
ask patch-at 200 0 [
set pcolor 123
]
]
]
]
]
]
set sfood_counter1 count patches with [pcolor = 123 and pxcor < 0]
set sfood_counter2 count patches with [pcolor = 123 and pxcor > 0]
end
to create_small_food
let num 0
while [num < Random_seeds] [ ;;colors individual patches until he total number is 512
ask one-of patches [
if pcolor = green [ ;will only generate on places without pre-existing food
if pxcor < -1 and pxcor > -198 [
set pcolor 7
ask patch-at 200 0 [
set pcolor 7
]
set num (num + 1) ;increments sparse food counter
]
]
]
]
set rfood_counter1 count patches with [pcolor = 7 and pxcor < 0]
set rfood_counter2 count patches with [pcolor = 7 and pxcor > 0]
end
to setup_humans
set-default-shape humans "dot" ;human shape
ask patch 100 0 [
sprout-humans city_size
]
ask patch -100 0 [
sprout-humans city_size
]
ask humans [
set color black ;human color
set ycor (-7 + random 14) ;human location
set xcor ((xcor - 7) + random 14)
set heading random 360 ;human heading
set behavior 0 ;sets the humans to their initial behavior condition
set size 1
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;main runtime function;;;;;;;;;;;;;;;;;;;;;main runtime function;;;;;;;;;;;;;;;main runtime function;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to go_density_recruit ;;function executed by the "run" button
;Predetermined GA parameters are defined here
set GArecruit -.369849
set GAtrail_drop .00114605
set GAevap .0250054
set GAdev .269567
set GAtrail .92328
set GAsite 1.0
set GAexpand 0.9836
if ticks > 5000 [ ;simulation resets after 5000 ticks
set food_collection_right 0
set food_collection_left 0
clear-patches
clear-all-plots
clear-turtles
reset-ticks
create_large_food
create_medium_food
create_small_food
create_other_food
setup_humans
]
evaporate_trail ;;;decrements all trails pheremone value (ctrl+F "evaporate trail" for details)
ask humans [ ;splits the humans behavior into halves based on location.
;humans on the left will bring food to the left nest and humans on the right will bring food to the right nest.
ifelse xcor > 0 [
set nestx 100
]
[set nestx -100
]
if not can-move? 1 or pcolor = black[ ;if humans are near the world boundary, will turn 180 degrees and move away 1 unit
rt 180
fd 1
]
;;At each tick, humans decide on an individual basis to execute one of six behviors.
;;Different stimuli such as the presence of trails or food will cause humans to change their behaviors
;;on an individual bases.
stop_search? ;function determining random chance of giving up (ctrl+F "stop_search?" for details)
if behavior = 0 [ ;function for initial expansion of the humans (ctrl+F "move_away" for details)
move_away
]
if behavior = 1 [ ;function for random walking and food searching behavior (crtl+F "random_walk" or "check_food" for details)
random_walk
check_food
]
if behavior = 2 [ ;function for trail following behavior (ctrl+F "scan_trail" for details)
scan_trail
]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;returning to the nest;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
if behavior = 3 [ ;function for when the humans choose to return home without marking a trail (ctrl+F "return_home" for details)
return_home
]
if behavior = 4 [ ;function when humans choose to return home while marking a trail or incrementing existing trail (ctrl+F "color_trail" for details)
color_trail
return_home
]
if behavior = 6 [ ;function where humans use site fidelity to return to the last known food location (ctrl+F "find_food" for details)
find_food
]
]
tick ;next time step
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;human behavioral fuctions;;;;;;;;;;;;;;;;human behavioral fuctions;;;;;;;;;;;;;;;;human behavioral fuctions;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to return_home ;function for human behavior when returning to the nest
let max_pher 0
let x -1
let y -1
let trail_follow? 0
let x2 nestx
ifelse (distancexy nestx 0) > 0 [ ;if human is not at nest, execute movement
facexy nestx 0
set curr_distance (distancexy nestx 0) ; registers current distance from nest
rt random-normal 0 20 ;random wiggle movement
ask patch-ahead 1 [
set new_distance (distancexy x2 0) ;registers future position from nest
]
if new_distance < curr_distance[ ;only moves if future position from nest is closer than current position
face patch-ahead 1
forward distance patch-ahead 1 ;moves to the patch 1 unit ahead
setxy pxcor pycor ;centers on the patch after moving
]
]
[ if has_food? = 1 [ ;increments the food collection counters on the respective side of the simulation upon returing food to the nest
ifelse xcor < 0 [
set food_collection_left (food_collection_left + 1)
set food_totall (food_totall + 1)
]
[ set food_collection_right (food_collection_right + 1)
set food_totalr (food_totalr + 1)
]
]
set has_food? 0
while [x < 2] [
set y -1
while [y < 2] [ ;while loops used to ask all surrounding patches for pheremone
if x != nestx or y != 0 [ ;does not look for pheromone on the nest
ask patch-at x y [
if pheremone? > max_pher [ ;sets maximum pheremone value to highest surrounding pheremone value
set max_pher pheremone?
]
]
]
set y (y + 1)
]
set x (x + 1)
]
ifelse recruit = 1 [
ifelse max_pher > 0 [
set xcor nestx
set ycor 0
while [xcor = nestx and ycor = 0 and behavior != 2] [ ;If human enters trail follow behavior, executes loop until human moves away from the nest
set heading (random 360)
scan_ahead ;scans 1 patch at every random heading
if pher_ahead >= (random-float max_pher) [ ;random chance based on the maximum pheremone to follow current pheremone trail
face patch-ahead 1
fd distance patch-ahead 1 ;moves onto 1 patch ahead
setxy pxcor pycor ;centers on current patch
set behavior 2
]
]
]
[ set heading (random 360) ;if no pheremone is present, human enters search mode
set behavior 1
]
]
[
ifelse fidelity = 1 [
facexy foodx foody
set behavior 6
]
[ set heading (random 360)
set behavior 1
]
]
]
end
to random_walk
set color black
let st_dev 0
ifelse pxcor > 0 [
set st_dev GAdev
]
[ set st_dev turn_while_searching
]
;behavior executed during behavior 1
if ticks mod 4 = 0 [
rt random-normal 0 (st_dev * 180 / pi)
]
fd .25 ;turns up to 30 degrees off of current heading and moves forward 1/4 of maximum speed
end
to evaporate_trail
ask patches with [pheremone? > 0] [
let evapo 0
ifelse pxcor > 0 [ ;defines trail evaporation consthuman based on GA and user input parameters
set evapo GAevap
]
[ set evapo Evaporation_rate
]
set pheremone? (pheremone? * (1 - evapo)) ;pheremone evaporation function
if pheremone? < .001 [set pheremone? 0] ;if pheremone becomes almost undetectable, sets value to 0
if pcolor != red and pcolor != yellow and pcolor != 123 and pcolor != 7 [ ;pheremone is only visually represented on pixels without food
if pheremone? >= 6 [set pcolor 99]
if pheremone? >= 5 and pheremone? < 6 [set pcolor 98] ;color gets darker as pheremone gets weaker
if pheremone? >= 4 and pheremone? < 5 [set pcolor 97]
if pheremone? >= 3 and pheremone? < 4 [set pcolor 96]
if pheremone? >= 2 and pheremone? < 3 [set pcolor 95]
if pheremone? >= 1 and pheremone? < 2 [set pcolor 94]
if pheremone? >= .1 and pheremone? < 1 [set pcolor 93]
if pheremone? >= .01 and pheremone? < .1 [set pcolor 92]
if pheremone? = 0 and pcolor = 92 [set pcolor green]
]
]
end
to find_food
set color blue ;humans turn blue while executing site fidelity
if (abs xcor) < ( abs foodx + 2) and (abs xcor) > ( abs foodx - 2) [ ;if the human is within 2 pixels of last known food location, exits site fidelity behavior
if (abs ycor) < ( abs foody + 2) and (abs ycor) > ( abs foody - 2) [
set behavior 1
]
]
facexy foodx foody ;moves towards last known food location
rt (-20 + random 40)
fd 1
setxy xcor ycor
end
to stop_search?
if random 10000 = 1 [ ;determines the percentage chance for humans to give up and return to the nest
set behavior 3
]
end
to move_away
ifelse not can-move? 1
[ set behavior 1 ]
[ ifelse (xcor < 0)
[ ;probability to begin search is determined by GA and user parameters
ifelse (random 10000 / 10000 < 1 - initial_expansion)
[ set behavior 1 ]
[ fd 1 ] ;if search mode is not engaged, moves outward at full speed
]
[ ifelse (random 10000 / 10000 < 1 - GAexpand)
[ set behavior 1 ]
[ fd 1 ];if search mode is not engaged, moves outward at full speed
]
]
end
to check_food
let x -1
let y -1
let seed_count 0
let food? 0
let p 0
let rec_factor 0
set recruit 0
set fidelity 0
ifelse xcor > 0 [ ;defines trail creation probabiity based on Ga and user inputs
set rec_factor GArecruit
]
[ set rec_factor lay_a_trail
]
ask patch-here [ ;collects food on a patch
if pcolor = red or pcolor = yellow or pcolor = 7 or pcolor = 123[
if count turtles-here >= 1 [
set food? 1
;decrements food counters and updates real-time graphs for each food source
if pcolor = red [ ;dense food
ifelse pxcor < 0 [
set lfood_counter1 (lfood_counter1 - 1)
]
[ set lfood_counter2 (lfood_counter2 - 1)
]
]
if pcolor = yellow [ ;medium density food
ifelse pxcor < 0 [
set mfood_counter1 (mfood_counter1 - 1)
]
[ set mfood_counter2 (mfood_counter2 - 1)
]
]
if pcolor = 7 [ ;low density food
ifelse pxcor < 0 [
set rfood_counter1 (rfood_counter1 - 1)
]
[ set rfood_counter2 (rfood_counter2 - 1)
]
]
if pcolor = 123 [ ;random food
ifelse pxcor < 0 [
set sfood_counter1 (sfood_counter1 - 1)
]
[ set sfood_counter2 (sfood_counter2 - 1)
]
]
]
]
]
if behavior = 1 or behavior = 2 and food? = 1[ ;executes once food has been collected
set has_food? 1
set seed_count 0
set pcolor green ;removes visual represenation of food from the patch
while [x < 2] [ ;uses while loops to scan surrounding eight patches for food
set y -1
while [y < 2] [
if (pxcor + x) > (- world-width / 2 + 1) and (pxcor + x) < (world-width / 2 - 1) [
if (pycor + y) > (- world-height / 2 + 1) and (pycor + y) < (world-height / 2 - 1) [
ask patch-at x y [
if pcolor = red or pcolor = yellow or pcolor = 7 or pcolor = 123[
set seed_count (seed_count + 1) ;number of uncollected food nearby
]
]
]
]
set y (y + 1)
]
set x (x + 1)
]
set foodx xcor
set foody ycor
set p (random 100 / 100)
ifelse p <= seed_count + rec_factor [ ;function to determine wether to lay a trail
set behavior 4
]
[set behavior 3
]
]
ifelse xcor < 0 [ ;probability to use site fidelity or density recruitment upon finding a seed is determined by GA and user parameters
if random-float 1 < ((Site_fidelity / 100) + seed_count) [
set fidelity 1
]
if random-float 1 < ((Density_recruit / 100) - seed_count) [
set recruit 1
]
]
[ if random-float 1 < (GAsite + seed_count) [
set fidelity 1
]
if random-float 1 < (GAtrail - seed_count) [
set recruit 1
]
]
end
to scan_ahead ;humans look for pheromone directly infront of themselves
let nx nestx
if can-move? 1 [ ;checks for the world boundaries
ask patch-ahead 1 [
ifelse pheremone? > 0 [ ;if pheremone ahead, return true
set pher_ahead pheremone?
set dist distancexy nx 0
ask humans [
set trail_ahead 1
]
]
[ set pher_ahead 0
ask humans [
set trail_ahead 0
]
]
]
]
end
to scan_trail ;function to follow pheromone trails
let max_pher 0
let x2 xcor
let y2 ycor
let nx nestx
let tdrop 0
ifelse pxcor > 0 [
set tdrop GAtrail_drop ;assigns trail drop rate parameter to GA and user controlled values
]
[ set tdrop abandon_trail
]
set curr_distance (distancexy nestx 0) ;will not follow trails that get closer to the nest
ask neighbors [
if distancexy nx 0 > curr_distance[
if pheremone? > 0 [
if pheremone? > max_pher [
set max_pher pheremone?
]
]
]
]
ifelse max_pher > 0 [
while [xcor = x2 and ycor = y2] [
set heading (random 360)
set color white ;turn white while following a trail for visual effect
scan_ahead
if pher_ahead > random max_pher [
if dist >= distancexy nestx 0 [
face patch-ahead 1
fd distance patch-ahead 1
setxy pxcor pycor
]
]
]
if (random 10000) / 10000 < tdrop [ ;small chance to abandon a trail and begin searching
set behavior 1
set color black
set heading random 360
]
]
[
set behavior 1 ;when the trail is gone, humans revert to search behavior
set color black
set heading random 360
]
end
to color_trail
ask patch-here [
if ((pycor != 0) or (pxcor != -100)) and ((pycor != 0) or (pxcor != 100)) [ ;will not lay pheromone ontop of the nest
;function to lay down pheremone during behvaior 3
set pheremone? (pheremone? + 1) ;increments pheremone by 1 every tick
if pcolor != red and pcolor != yellow and pcolor != 123 and pcolor != 7 [ ;only draws pheremone on pixels without food
if pheremone? >= 6 [set pcolor 99] ;gradual progression from dark blue to white based on pheremone strength
if pheremone? >= 5 and pheremone? < 6 [set pcolor 98]
if pheremone? >= 4 and pheremone? < 5 [set pcolor 97]
if pheremone? >= 3 and pheremone? < 4 [set pcolor 96]
if pheremone? >= 2 and pheremone? < 3 [set pcolor 95]
if pheremone? >= 1 and pheremone? < 2 [set pcolor 94]
if pheremone? < 1 and pcolor = green [set pcolor 93] ;will not draw pheremone over food, only green space
; set trail_evaporation trail_evaporation
]
]
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;plotting and data-exporting;;;;;;;;plotting and data-exporting;;;;;;;;;;;;;;;;;plotting and data-exporting;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to do-plotting-left
set-current-plot "User controlled human city" ;plot name
if plot? [
set-current-plot-pen "large piles"
plot-pen-down
plotxy ticks lfood_counter1;count patches with [pcolor = red and pxcor < 0] ;plot high density food quhumanity in red
set-current-plot-pen "medium piles"
plot-pen-down
plotxy ticks mfood_counter1;count patches with [pcolor = yellow and pxcor < 0] ;plot medium density food quhumanity in yellow
set-current-plot-pen "random food"
plot-pen-down
plotxy ticks rfood_counter1;count patches with [pcolor = 7 and pxcor < 0] ;plot random food distribution quhumanity in white
set-current-plot-pen "sparse piles"
plot-pen-down
plotxy ticks sfood_counter1;count patches with [pcolor = 123 and pxcor < 0] ;plot low density food quhumanity in brown
]
if not plot? [
;clear-all-plots ;if plot switch is off, clears all plot lines and stops drawing plot values
set-current-plot-pen "large piles"
plot-pen-up
set-current-plot-pen "medium piles"
plot-pen-up
set-current-plot-pen "random food"
plot-pen-up
set-current-plot-pen "sparse piles"
plot-pen-up
]
end
to do-plotting-right
set-current-plot "GA human city" ;plot name
if plot_2? [
set-current-plot-pen "large piles"
plot-pen-down
plotxy ticks lfood_counter2 ;plot high density food quhumanity in red
set-current-plot-pen "medium piles"
plot-pen-down
plotxy ticks mfood_counter2 ;plot medium density food quhumanity in yellow
set-current-plot-pen "random food"
plot-pen-down
plotxy ticks rfood_counter2 ;plot random food distribution quhumanity in white
set-current-plot-pen "sparse piles"
plot-pen-down
plotxy ticks sfood_counter2 ;plot low density food quhumanity in brown
]
if not plot_2? [ ;if plot switch is off stops drawing plot values
set-current-plot-pen "large piles"
plot-pen-up
set-current-plot-pen "medium piles"
plot-pen-up
set-current-plot-pen "random food"
plot-pen-up
set-current-plot-pen "sparse piles"
plot-pen-up
]
end
to save_pile_config
ask patches [
set lfood? 0 ;resets all different pile configurations to 0
set mfood? 0
set sfood? 0
set ofood? 0
if pcolor = 7 [set sfood? 1] ;defines existing food locations and stores them in variables
if pcolor = yellow [set mfood? 1]
if pcolor = red [set lfood? 1]
if pcolor = 123 [set ofood? 1]
]
end
@#$#@#$#@
GRAPHICS-WINDOW
497
23
1309
456
200
100
2.0
1
10
1
1
1
0
0
0
1
-200
200
-100
100
1
1
1
ticks
30.0
BUTTON
102
239
277
274
New Setup
setup_world\nif ticks > 4 [\nfile-delete \"netlogo food log.txt\"\n]\n
NIL
1
T
OBSERVER
NIL
N
NIL
NIL
1
SLIDER
194
141
366
174
City_size
City_size
1
1000
20
1
1
ants
HORIZONTAL
BUTTON
289
239
466
275
Run
go_density_recruit\ndo-plotting-right\ndo-plotting-left\n;test
T
1
T
OBSERVER
NIL
R
NIL
NIL
1
SLIDER
100
377
276
410
Evaporation_rate
Evaporation_rate
.0001
.1
1.0E-4
.0001
1
NIL
HORIZONTAL
PLOT
497
453
904
578
User controlled human city
time
food
0.0
600.0
0.0
300.0
true
true
"" ""
PENS
"large piles" 1.0 0 -2674135 true "" ""
"medium piles" 1.0 0 -1184463 true "" ""
"sparse piles" 1.0 0 -5825686 true "" ""
"random food" 1.0 0 -16777216 true "" ""
MONITOR
1216
409
1308
454
food collected
food_collection_right
0
1
11
SLIDER
102
101
277
134
Medium_piles
Medium_piles
0
20
0
1
1
NIL
HORIZONTAL
SLIDER
102
59
276
92
Large_piles
Large_piles
0
5
0
1
1
NIL
HORIZONTAL
SLIDER
290
333
466
366
Initial_expansion
Initial_expansion
0.9
1.0
0.9
.0001
1
NIL
HORIZONTAL
SLIDER
100
332
276
365
Lay_a_trail
Lay_a_trail
-9
1
1
.01
1
NIL
HORIZONTAL
TEXTBOX
262
30
412