-
Notifications
You must be signed in to change notification settings - Fork 1
/
Ross Sim (11).nlogo
1326 lines (1198 loc) · 27.7 KB
/
Ross Sim (11).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
;Robert Lichenstein & Peter Bromley // CS390 // Ross Dining Hall Simulation
;Credits to Professor Dickerson in teaching us a lot of the stuff we did
__includes["linesfile.nls" "movementfile.nls"]
globals[
time ;the current time in hours/minutes/seconds
line-length ;the average line-length of all lines, something the turtles can see
salad-queue ;global visible queue for the salad bar
station-1-queue ;global visible queue for food station 1
station-2-queue ;global visible queue for food sation 2
pizza-queue ;global visible queue for the pizza line
taco-queue-1 ;global visible queue for top taco line
taco-queue-2 ;global visible queue for bottom taco line
max-speed ;max speed of a student
salad-move-sequence ;movement sequence to make a salad
pizza-move-sequence ;movement sequence to gather pizza
station-1-move-sequence ;movement sequence to get food from station 1
station-2-move-sequence ;movement sequence to get food from station 1
taco-move-sequence
]
turtles-own[
restrictions ;a student dietary restrictions
priority ;the student current movement priority
mqueue ;the priority queue of what a student needs to do
desires ; the desires of a student
stations ;queue list of food stations a student will visit
my-seat ; a patch to remember their seat
tte ;time-to-eat, abbreviated, determines how long a student takes to eat
athlete? ;determines if a student is an athlete
restricted? ;determines if a student has a dietary restriction
in-line? ;determines if a student is in a food line
speed ;the turtles current speed
sequence ;current movement sequence of the turtle
sequence-ticks ;cooldown time for each sequence move
patience ;determines a turtle's patience threshold (based on line length and num students in ross)
]
patches-own[
walk? ;is the patch walkable?
seating? ;is the patch a seat?
food-type ;used for snack/drink patches, tells us what type of stuff is being served
salad-line ;whether a patch is in the salad-line, or the back of the salad-line
station-1-line ;similar to above, info on patches in station-1-line
station-2-line ;similar to above, info on patches in station-2-line
pizza-line ;similar to above, info on patches in pizza-line
taco-line
]
;Observer Context
;sets up our patches by:
;loading from png
;labeling the patches
;and setting up lines
to setup
ca
reset-ticks ;initializes our ticks and our time
set time 0
ifelse not taco? [
import-pcolors "rossdining.png" ;imports the proper patches we have painstakingly painted
] [
import-pcolors "rossdining-with-taco.png"
]
label-patches ;labels/inits patches properly by color
set max-speed 5.0 ;init max turt speed
init-salad-line ;inits all of the line patches below
init-station-1-line
init-station-2-line
init-pizza-line
init-taco-line
;the following are hardcoded movement sequences for turtles to follow to simulate
;gathering food from a counter top
;u = up, r = right, l = left
set salad-move-sequence (list "u" "u" "u" "u" "u" "u" "u" "u" "r" "u" "r" "r" "u")
set station-1-move-sequence (list "r" "u" "r" "r" "u" "r" "u" "r" "r" "u" "r" "r" "r")
set station-2-move-sequence (list "l" "l" "l" "l" "l" "l" "l" "l" "l" "l" "l" "l" "u" "l" "l" "u" "l" "l" "u" "l" "l")
set pizza-move-sequence (list "l" "l" "l" "l" "l" "l")
if taco? [ set taco-move-sequence (list "l" "l" "l" "l" "l" "l" "l" "l" "l" "l" "l" "l" "l" "l") ]
end
;Observer Context
;our go function, everything tick based happens in here
to go
tick
generate-people ;this generates people with probabilities based on
;swipe numbers given to us from ross dining hall
ask turtles[
;here we ask all of our turtles to follow the move-students function
;;move students is our default movement algorithm for students not in a line
move-students
]
move-salad-queue ;;the following functions handle movement for students in a line
move-pizza-queue ;;this moves up the priority queue for movement
move-station-1-queue
move-station-2-queue
if taco? [
move-taco-queue-1
move-taco-queue-2
]
move-in-sequence ;;move-in-sequence handles what happens to a turtle popped off of a
;food line priority queue, and moves them through the proper steps for retrieving food
update-time ;update our system time
if ticks = 12600 [ ;stop after 3.5 hours, or at 8:30 PM
stop
]
end
;Observer Context
;updates our system time, turning ticks into hours/minutes/seconds
;we also update average line length here, for convenience
to update-time
let hours floor (ticks / 3600)
let minutes (floor ((ticks mod 3600) / 60))
set time (word "" (5 + hours) word ":" minutes word ":" (ticks mod 60))
set line-length ((length salad-queue + length station-1-queue + length station-2-queue + length pizza-queue) / 4)
if taco? [ set line-length (line-length + length taco-queue-1 + length taco-queue-2) ]
end
to paint
if mouse-down? = true[
ask patch mouse-xcor mouse-ycor[set pcolor culler]
]
wait 0.1
end
to paint-row
if mouse-down? = true[
ask patch mouse-xcor mouse-ycor[set pcolor culler]
ask patch mouse-xcor (mouse-ycor - 2) [set pcolor culler]
ask patch mouse-xcor (mouse-ycor - 4) [set pcolor culler]
ask patch mouse-xcor (mouse-ycor - 6) [set pcolor culler]
ask patch mouse-xcor (mouse-ycor - 8) [set pcolor culler]
]
wait 0.1
end
to fill
if mouse-down? = true[
ask patch mouse-xcor mouse-ycor[
ask neighbors with [pcolor = [pcolor] of myself][
set pcolor culler
]
set pcolor culler
]
]
wait 0.1
end
to spawn
if mouse-down? = true[
ask patch mouse-xcor mouse-ycor[spawn-student]
]
wait 0.1
end
;Observer context
;generates people at a specific probabilities dependent on the time
to generate-people
let gen-prob 0.0
ifelse ticks < 1800 [ ;we use our ticks as time, as each tick = 1 second
set gen-prob 0.075 * (ticks / 1800)
] [
ifelse ticks < 5400 [
let prob-start 0.075
set gen-prob prob-start + (0.2 * ((ticks - 1800) / 3600))
] [
ifelse ticks < 8100 [
set gen-prob 0.275
] [
ifelse ticks < 10800 [
let prob-start 0.275
set gen-prob prob-start - (0.25 * ((ticks - 8100) / 2700))
] [
let prob-start 0.025
set gen-prob prob-start - (0.025 * ((ticks - 10800) / 1800))
]
]
]
]
if random-float 1 < gen-prob [ ; we use one random after setting the gen-prob properly
ask patch -8 37 [ ;;patch -8 37 is our entrance patch
spawn-student ;spawn-student gives us a random student
]
]
end
;patch context
;spawns a properly initialized student on the desired patch
to spawn-student
sprout 1[
set size 2
set my-seat 0
set mqueue (list [])
set stations (list [])
set sequence []
set sequence-ticks 8
set color blue
set-restrictions-and-desires
ifelse ticks < 3600 [
ifelse random-float 1.0 < 0.05 [
set athlete? true
set color pink
][
set athlete? false
]
][
ifelse random-float 1.0 < 0.35 [ ;;35 % likelihood gathered from midd data
set athlete? true
set color pink
][
set athlete? false
]
]
set patience random 5 + 15
ifelse (patience < line-length) [
set mqueue (list "enter" "leave")
set in-line? false
] [
set-mqueue-and-stations
]
]
end
;Turtle Context
;initializes whether a turtle has dietary restrictions or not,
;then initializes its desires, to snack, eat dessert, a meal, work
;or get something to go.
to set-restrictions-and-desires
;we have a slider for how many people have a dietary restriction
if random-float 1.0 < dietary-restriction-pct[
set restricted? true
;;these are roughly realistic numbers, not including gluten free
;;of vegans being much more unlikely than vegetarians
ifelse random-float 1.0 < 9.0 [
set restrictions "vegetarian"
set color green
]
[
set restrictions "vegan"
set color green + 3
]
]
;the below line determines the likelihood of someone getting a snack or dessert,
;and it is scaled such that if the meal-quality is 0 (out of 10) we havea 22% chance of
;skipping a meal entirely and just getting a snack or dessert
ifelse random-float 1.0 < (0.22 - ((meal-quality / 100) * 2)) [
set desires one-of ["snack" "dessert"]
;we set an appropriate time to eat
set tte 600
][
;;otherwise there is a 15% chance of getting something to go, because we are
;;busy midd students
ifelse random-float 1.0 < 0.15 [
set desires "to-go"
]
[
;a 1% chance of working, because working in ross dining hall is weird and noisy
ifelse random-float 1.0 < 0.01 [
set desires "work"
set tte 3600
]
[
;;and everyone else just gets a meal
set desires "meal"
set tte random (max-meal-length * 60) ;;setting time-to-eat proportional to the desire,
]
]
]
end
;turtle context
;initializes the turtles movement queue and stations (which
;are the food stations it wants to visit) based on the initialized desires
to set-mqueue-and-stations
let stationlist (list "station-1" "station-2" "pizza" "salad-bar") ;;the list of possible stations for a normal meal
let v-stationlist (list "salad-bar" "station-2" "bagel" "vfridge" "vsnackfridge") ;;the list of stations for a vegan/vegetarian
let snack-stationlist (list "bagel" "pizza" "panini" "cereal") ;the list of "snack" stations
ifelse desires = "meal" [ ;;set our stations if they want a full meal
set mqueue (list "food" "drink" "sit" "leave")
ifelse restrictions != "vegan" and restrictions != "vegetarian" [ ;if they arent restricted
ifelse athlete? [
set stations n-of 3 stationlist ;;athletes eat more
][
set stations n-of 2 stationlist
]
if taco? and (random-float 1 < 0.9) [
set stations remove-item 0 stations
set stations fput "taco" stations
]
][
;;if they are restricted, we only go to the stations for dietary restrictions
set stations n-of 2 v-stationlist
]
][ifelse desires = "work" [ ;;we only need to sit and leave if we came to work
set mqueue (list "sit" "leave")
][
ifelse desires = "snack"[ ;;snacking involves only going to snack stations
set mqueue (list "food" "sit" "leave")
set stations (list one-of snack-stationlist)
][ifelse desires = "to-go"[ ;to-go involves just getting food and leaving
set mqueue (list "food" "leave")
set stations n-of 2 (sentence stationlist snack-stationlist)
][if desires = "dessert"[ ;;dessert follows the same principle
set mqueue (list "food" "sit" "leave")
set stations (list "dessert")
]
]
]
]
]
;after we set up our movement queue, we have to remember to enter
;;and init in-line
set mqueue fput "enter" mqueue
set in-line? false
end
;LINE INIT FUNCTIONS
;OBSERVER CONTEXT
;the following line-init functions are identical in structure so only
;one will be commented
;for the respective lines they create, they initialize the patch values of
;properly colored patches to create a "line" of patches
;and then recolor those patches so lines are not visible
;initializes the salad line
to init-salad-line
set salad-queue [] ;we set the global salad queue to zero
ask patches with [pcolor = 56] [ ;;this is our chosen color for salad-line patches
ifelse (pxcor = 32) and (pycor = -21) [
;;our start patch is hardcoded as the "back" of the line
;;and starts as both the back and the front of the line when the queue is empty
set salad-line "back"
set walk? true
] [
;;all other patches are not the back, there is only one back
set salad-line "yes"
set walk? true
]
;;afterwards we set the pcolor of these patches to white, so you cannot see them
set pcolor 9.9
]
end
;initializes the station 1 line, identical to above
to init-station-1-line
set station-1-queue []
ask patches with [pcolor = 14] [
ifelse (pxcor = 68) and (pycor = -15) [
set station-1-line "back"
set walk? true
] [
set station-1-line "yes"
set walk? true
]
set pcolor 9.9
]
end
;initializes the station 2 line, identical to above
to init-station-2-line
set station-2-queue []
ask patches with [pcolor = 13] [
ifelse (pxcor = 89) and (pycor = -2) [
set station-2-line "back"
set walk? true
] [
set station-2-line "yes"
set walk? true
]
set pcolor 9.9
]
end
;initializzes the pizza line, identical to above
to init-pizza-line
set pizza-queue []
ask patches with [pcolor = 12] [
ifelse (pxcor = 47) and (pycor = 7) [
set pizza-line "back"
set walk? true
] [
set pizza-line "yes"
set walk? true
]
set pcolor 9.9
]
end
;initializes the taco line, identical to above
to init-taco-line
set taco-queue-1 []
set taco-queue-2 []
ask patches with [pcolor = 34] [
ifelse ((pxcor = 70) and (pycor = -8)) or ((pxcor = 70) and (pycor = -3)) [
set taco-line "back"
set walk? true
] [
set taco-line "yes"
set walk? true
]
set pcolor 9.9
]
end
;;patch context
;;here we just label the patches based on the colors of the loaded in picture
to label-patches
ask patches [
ifelse pcolor = white or pcolor = 45[ set walk? true ][set walk? false] ; set walkable patches
if pcolor = 9 [ set seating? true ] ; set seating
if pycor = 18 and (-45 < pxcor and pxcor <= -43)[ ; set food types based on patch color
set food-type "dessert"
]
if pxcor = 94 and (-3 > pycor and pycor > -7)[
set food-type "bagel"
]
if pxcor = -66 and (1 < pycor and pycor < 7)[
set food-type "panini"
]
if pxcor = -15 and (26 < pycor and pycor < 35)[
set food-type "cereal"
]
if pxcor = -15 and (22 < pycor and pycor < 25)[
set food-type "vfridge"
]
if pxcor = -37 and (20 < pycor and pycor < 23)[
set food-type "vsnackfridge"
]
if pcolor = 95.1 [
if ([pcolor] of (patch pxcor (pycor - 1))) != 95.1 [ ; set drinks
ask patch pxcor (pycor - 1) [
set food-type "drink"
]
]
]
if count neighbors4 with [pcolor = 9 and pxcor = [pxcor] of myself] = 2 [
set walk? false
]
]
end
@#$#@#$#@
GRAPHICS-WINDOW
203
15
2221
1034
-1
-1
10.0
1
10
1
1
1
0
0
0
1
-100
100
-50
50
0
0
1
ticks
30.0
BUTTON
24
25
88
59
NIL
setup\n
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
BUTTON
42
617
106
651
NIL
go
T
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
MONITOR
2079
24
2216
69
NIL
time
17
1
11
SLIDER
24
433
199
466
dietary-restriction-pct
dietary-restriction-pct
0
1.0
0.09
0.01
1
NIL
HORIZONTAL
CHOOSER
22
823
161
868
culler
culler
9.9 9 0 15 55 56 105 14 13 12 5 125 45 35 34
14
BUTTON
20
868
84
902
NIL
paint\n
T
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
BUTTON
23
910
87
944
NIL
fill
T
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
TEXTBOX
1634
418
1822
442
pizza\n
16
0.0
1
TEXTBOX
1944
649
2132
673
food station 1\n
16
0.0
1
TEXTBOX
1972
484
2160
508
food station 2\n
16
0.0
1
TEXTBOX
2170
549
2193
611
BAGELS\n\n
16
0.0
1
BUTTON
97
913
165
947
NIL
spawn
T
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
TEXTBOX
1267
305
1315
324
drinks\n
16
0.0
1
TEXTBOX
1427
302
1481
326
drinks
16
0.0
1
TEXTBOX
1575
657
1650
685
salad bar
16
0.0
1
TEXTBOX
529
455
548
625
P A N I N I
16
0.0
1
TEXTBOX
1075
157
1093
269
C E R E A L
13
0.0
1
TEXTBOX
817
299
835
327
V GF
11
0.0
1
TEXTBOX
1074
284
1097
312
V\nGF
11
0.0
1
TEXTBOX
740
317
798
336
Dessert
15
0.0
1
TEXTBOX
680
315
729
335
drinks
16
0.0
1
BUTTON
93
873
178
907
NIL
paint-row
T
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
MONITOR
1939
198
2029
243
# of Students
count turtles
17
1
11
TEXTBOX
893
359
1136
399
S e a t i n g b l o c k A
17
0.0
1
TEXTBOX
889
149
1077
174
Seating Block B
17
0.0
1
TEXTBOX
1263
557
1451
582
Seating Block C
17
0.0
1
BUTTON
109
617
173
651
NIL
go
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
TEXTBOX
40
785
175
825
Dev Tools
16
0.0
1
SWITCH
88
382
192
415
Swipes?
Swipes?
0
1
-1000
SLIDER
28
484
201
517
meal-quality
meal-quality
0
10
10.0
1
1
NIL
HORIZONTAL
SLIDER
23
530
205
563
max-meal-length
max-meal-length
15
90
27.0
1
1
minutes
HORIZONTAL
PLOT
1870
33
2070
183
Students Over Time
Time
students
0.0
10.0
0.0
10.0
true
false
"" ""
PENS
"default" 1.0 0 -16777216 true "" "plot count turtles"
PLOT
1654
35
1854
185
Seating Over Time
Time
Open Seats
0.0
10.0
0.0
10.0
true
false
"" ""
PENS
"default" 1.0 0 -16777216 true "" "plot count patches with [seating? = true and not any? turtles-here]"
PLOT
1430
35
1630
185
Avg Line-Length Over Time
Time
Avg. Line Length
0.0
10.0
0.0
10.0
true
false
"" ""
PENS
"default" 1.0 0 -16777216 true "" "plot line-length"
MONITOR
1715
199
1794
244
Open Seats
count patches with [seating? = true and not any? turtles-here]
17
1
11
MONITOR
1492
195
1599
240
Avg. Line Length
line-length
17
1
11
SWITCH
89
348
194
381
taco?
taco?
0
1
-1000
@#$#@#$#@
## Middlebury Ross Dining Hall Simulation
@#$#@#$#@
default
true
0
Polygon -7500403 true true 150 5 40 250 150 205 260 250
airplane
true
0
Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15
arrow
true
0
Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150
box
false
0
Polygon -7500403 true true 150 285 285 225 285 75 150 135
Polygon -7500403 true true 150 135 15 75 150 15 285 75
Polygon -7500403 true true 15 75 15 225 150 285 150 135
Line -16777216 false 150 285 150 135
Line -16777216 false 150 135 15 75
Line -16777216 false 150 135 285 75
bug
true
0
Circle -7500403 true true 96 182 108
Circle -7500403 true true 110 127 80
Circle -7500403 true true 110 75 80
Line -7500403 true 150 100 80 30
Line -7500403 true 150 100 220 30