-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathObserverOversightInTraffic.nlogo
1469 lines (1331 loc) · 46.9 KB
/
ObserverOversightInTraffic.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
breed [ cars car]
breed [ police person]
globals [
sign
car-counter ;; keeps track of how many cars from a given lane have passed the roadblock
efficiency-list ;; a list that keeps track of the car-counter values
efficiency-time-left ;; the time between changing lights for the left side (for the viewer)
efficiency-time-right ;;the time between changing lights for the right side (for the viewer)
waiting-list-left ;; splits the efficiency-list to extract the top lane behavior
waiting-list-right ;; splits the efficiency-list to extract the bottom lane behavior
reduce-left ;; the sum of the elements in the waiting-list-left list
reduce-right ;; the sum of the elements in the waiting-list-right list
top-lane ;; defined by all patches in the top lane
bottom-lane ;; defined by all patches in the bottom lane
left-side ;; defined by all patches on the left side of the roadblock
left-cnt ;; the number of cars on the left-side
right-side ;; defined by all patches on the right side of the roadblock
right-cnt ;; the number of cars on the right-side
road-block ;; defined by all the patches of the roadblock
honking-level ;; holds the value of the number of cars honking at the police man
allCarsThrough ;; holds the value of the number of ticks when all cars have passed the roadblock
]
cars-own [
lane ;; this tells which lane a car belongs to (0 is bottom lane, 1 is top lane)
patience ;; a value which reflects how likely a car is to honk at the police man
passed? ;; a boolean that returns true when a car has passed the roadblock at least once
]
patches-own [
signal-patch-top? ;; returns true only for the patch the top lane uses to recieve input from police
signal-patch-bottom? ;; returns true only for the patch the bottom lane uses to recieve input from police
]
;;;;;;;;;;;;;;;;;;;;
;;SETUP PROCEDURES;;
;;;;;;;;;;;;;;;;;;;;
to setup
clear-all
ask patches [ setup-road ]
setup-cars
setup-police
set sign "rightward"
prepare-signs
set allCarsThrough 0
setup-efficiency-list
reset-ticks
end
;; We modified the setup-road procedure from Wilensky's Traffic Basic to create two opposing lanes
;; of traffic. The top lane is moving leftward; the bottom lane is moving rightward.
to setup-road
set pcolor green + 3
;
; setup the top-lane and the bottom-lane
;
set top-lane patches with [pycor = 1]
ask top-lane [ set pcolor gray ]
set bottom-lane patches with [pycor = -1 ]
ask bottom-lane [ set pcolor gray ]
;
; setup the left-side and the right-side
;
set left-side patches with [pycor = -1 and pxcor < -8 and pxcor > -25]
set right-side patches with [pycor = 1 and pxcor > 8 and pxcor < 25]
;
; establish the basic graphics and booleans of the road
;
set signal-patch-top? false ;; default for all patches
set signal-patch-bottom? false ;; default for all patches
if ((pycor > -3) and (pycor < 3)) [ set pcolor gray ]
if ((pycor = 0) and ((pxcor mod 3) = 0)) [ set pcolor yellow ]
if ((pycor = 3) or (pycor = -3)) [ set pcolor black ]
;; setup the parameters of the roadblock in the bottom lane
set road-block patches with [ ((pycor > -3) and (pycor < 0) and (pxcor > -7) and (pxcor < 7)) ]
ask road-block [
set pcolor red ;; provides red graphic of roadbloack
]
;; these if-statements establish which patch is the signal-patch for each lane
;; when a car is on these respective patches, they look to the polieman for stop/go directives
if ((pxcor = -9) and (pycor = -1)) [set signal-patch-bottom? true]
if ((pxcor = 9) and (pycor = 1)) [set signal-patch-top? true]
end
to prepare-signs
ifelse sign = "leftward" ;; a leftward sign means that the top lane is allowed to drive
[ ask patch -2 4 [ set pcolor red ] ;; sign for bottom lane is red
ask patch 2 4 [ set pcolor green ] ;; sign for top lane is green
]
[ ;; else, there is a rightward sign meaning the bottom lane is allowed to drive
ask patch -2 4 [ set pcolor green ] ;; sign for bottom lane is green
ask patch 2 4 [ set pcolor red ] ;; sign for top lane is red
]
end
;; This procedure creates a single turtle of the police breed
to setup-police
set-default-shape police "person police"
ask one-of patches [ sprout-police 1
;; establish the visuals of the police turtle
ask police [
setxy 0 4 ;; position of the police man
set size 2
set color orange + 2
;; when the learning? switch is on, start with the user input from time-between-sign-change
;; slider to initialize the following to variables. Police will update both to increase efficiency.
set efficiency-time-left time-between-sign-change
set efficiency-time-right time-between-sign-change
]
]
end
;; This procedure creates the cars on the road
to setup-cars
if number-of-cars > world-width
[ ;; this user-message is from Wilensky's Traffic Basic model
user-message (word "There are too many cars for the amount of road. Please decrease the NUMBER-OF-CARS slider to below "
(world-width + 1)
" and press the SETUP button again. The setup has stopped.")
stop
]
set-default-shape cars "car"
if top-heavy = true and bottom-heavy = true
[ ;; this user-message occurs when both top and bottom heavy are turned on
user-message (word "There cannot be a situation with both top-heavy and bottom-heavy turned on where "
"both with have higher percentage of cars. Please choose a different combination"
" and press the SETUP button again. The setup has stopped.")
stop
]
if (top-heavy = true and bottom-heavy = false)
[
ask patches [
if count(cars) < number-of-cars [ ;; create the number of cars input by the user
sprout-cars number-of-cars * 0.60 ;;must be 60% minimum to be top-heavy
[
set size 1.5
set passed? false ;; default for all cars at start of model run
set lane 1
;; cars in the top lane are blue and heading leftward
set shape "car-flipped"
setxy random-pxcor 1
set heading 270
set color blue
remove-from-roadblock ;; this procedure removes cars from the roadblock area
separate-cars ;; this procedure makes sure no cars are overlapping
]
sprout-cars number-of-cars * 0.20 ;;must be 20% minimum for the bottom lane
[
set size 1.5
set passed? false ;; default for all cars at start of model run
set lane 0
;; cars in the top lane are blue and heading leftward
setxy random-pxcor -1
set heading 90
set color pink
remove-from-roadblock ;; this procedure removes cars from the roadblock area
separate-cars ;; this procedure makes sure no cars are overlapping
]
sprout-cars number-of-cars - count(cars)
[
set size 1.5
set passed? false ;; default for all cars at start of model run
set lane (random 2) ;; randomly assign cars to either the top (lane = 1) or bottom (lane = 0)
ifelse lane = 0
[ ;; cars in the bottom lane are pink and heading rightward
setxy random-pxcor -1
set heading 90
set color pink
]
[ ;; cars in the top lane are blue and heading leftward
set shape "car-flipped"
setxy random-pxcor 1
set heading 270
set color blue
]
remove-from-roadblock ;; this procedure removes cars from the roadblock area
separate-cars ;; this procedure makes sure no cars are overlapping
]
]
]
]
if (top-heavy = false and bottom-heavy = true)
[
ask patches [
if count(cars) < number-of-cars [ ;; create the number of cars input by the user
sprout-cars (number-of-cars * 0.20) ;;must be 20% minimum
[
set size 1.5
set passed? false ;; default for all cars at start of model run
set lane 1
;; cars in the top lane are blue and heading leftward
set shape "car-flipped"
setxy random-pxcor 1
set heading 270
set color blue
remove-from-roadblock ;; this procedure removes cars from the roadblock area
separate-cars ;; this procedure makes sure no cars are overlapping
]
sprout-cars (number-of-cars * 0.60) ;;must be 26% minimum to be bottom-heavy
[
set size 1.5
set passed? false ;; default for all cars at start of model run
set lane 0
;; cars in the top lane are blue and heading leftward
setxy random-pxcor -1
set heading 90
set color pink
remove-from-roadblock ;; this procedure removes cars from the roadblock area
separate-cars ;; this procedure makes sure no cars are overlapping
]
sprout-cars number-of-cars - count(cars)
[
set size 1.5
set passed? false ;; default for all cars at start of model run
set lane (random 2) ;; randomly assign cars to either the top (lane = 1) or bottom (lane = 0)
ifelse lane = 0
[ ;; cars in the bottom lane are pink and heading rightward
setxy random-pxcor -1
set heading 90
set color pink
]
[ ;; cars in the top lane are blue and heading leftward
set shape "car-flipped"
setxy random-pxcor 1
set heading 270
set color blue
]
remove-from-roadblock ;; this procedure removes cars from the roadblock area
separate-cars ;; this procedure makes sure no cars are overlapping
]
]
]
]
if top-heavy = false and bottom-heavy = false
[
ask patches [
if count(cars) < number-of-cars [ ;; create the number of cars input by the user
sprout-cars number-of-cars
[
set size 1.5
set passed? false ;; default for all cars at start of model run
set lane (random 2) ;; randomly assign cars to either the top (lane = 1) or bottom (lane = 0)
ifelse lane = 0
[ ;; cars in the bottom lane are pink and heading rightward
setxy random-pxcor -1
set heading 90
set color pink
]
[ ;; cars in the top lane are blue and heading leftward
set shape "car-flipped"
setxy random-pxcor 1
set heading 270
set color blue
]
remove-from-roadblock ;; this procedure removes cars from the roadblock area
separate-cars ;; this procedure makes sure no cars are overlapping
]
]
]
]
end
to setup-efficiency-list
;; initialize the following variable and lists
set efficiency-list [ ]
set car-counter 0
set waiting-list-left [ ]
set waiting-list-right [ ]
end
;; this proceedure is based on Wilensky's Traffic Basic model
;; makes sure no cars are overlapping on the same patch
to separate-cars
if any? other turtles-here
[ fd 1
separate-cars ]
end
;; this procedure redistributes the cars in the bottom lane (lane 0) so that they
;; do not start on the roadblock
to remove-from-roadblock
while [ xcor > -10 and xcor < 10 ] ;; while on roadblock
[ set xcor random-pxcor ] ;; assign to a new random location in bottom lane
end
;;;;;;;;;;;;;;;;;;;;;;
;;RUNTIME PROCEDURES;;
;;;;;;;;;;;;;;;;;;;;;;
to go
step
tick
end
to step
move-cars ;; procedure that determines how each car moves forward; calls the drive procedure
ifelse learning? ;; model behaves differently depending on whether the police man can learn or not
[
;; when the learning? switch is ON
ask cars [ set patience (1 + random 99) ] ;; assign each car a random value for patience
ifelse sign = "leftward"
[
;; if sign is leftward
;; whenever the time alloted by efficiency-time-right has passed
if ticks mod (efficiency-time-right) = 0 and ticks != 0
[ ifelse any? cars with [pxcor > -9 and pxcor < 9 ] ;; allow cars passing roadblock to complete maneuver
[ ask patches with [pcolor = green]
[ set pcolor yellow ] ;; change the green sign to yellow
]
[ change-signs ;; once all cars are pass the roadblock, switch the signs
set honking-level 0 ;; reset honking-level
]
]
]
[
;; if sign is rightward
;; whenever the time alloted by efficiency-time-right has passed
if ticks mod (efficiency-time-left) = 0 and ticks != 0
[ ifelse any? cars with [pxcor > -9 and pxcor < 9 ] ;; allow cars passing roadblock to complete maneuver
[ ask patches with [pcolor = green]
[ set pcolor yellow ] ;; change the green sign to yellow
]
[ change-signs ;; once all cars are pass the roadblock, switch the signs
set honking-level 0 ;; reset honking-level
]
]
]
police-learning ;; and finally, execute the police-learning procedure
]
;; when the learning? switch is OFF
;; whenever the time alloted by efficiency-time-right has passed
[ if ticks mod (time-between-sign-change) = 0 and ticks != 0
[ ifelse any? cars with [pxcor > -9 and pxcor < 9] ;; allow cars passing roadblock to complete maneuver
[ ask patches with [pcolor = green]
[ set pcolor yellow ] ;; change the green sign to yellow
]
[ change-signs ] ;; once all cars are pass the roadblock, switch the signs
]
]
update-efficiency-list
;; when the stopwatch? switch is ON
if stopwatch? [
if not any? cars with [passed? = false ] ;; if all cars have passed the roadblock at least once
[ set allCarsThrough ticks ;; set the allCarsThrough value to the number of current ticks
set stopwatch? false ;; turn the switch off
]
]
end
to move-cars
ask cars [
if lane = 0
[ ;; if car is a "bottom lane" car
ifelse [signal-patch-bottom?] of patch-here = true ;; determine if the car on the signal-patch of its lane
[
ifelse sign = "leftward" or [pcolor] of patch -2 4 = yellow ;; if the police person is allowing leftward traffic
[ fd 0 ;; do not proceed forward
ask cars-on left-side [
ask self [
if patience < 60 ;; about 60% chance the car will "honk" at police man
[ set honking-level honking-level + 1 ;; update honking-level
set patience 100 ] ;; this prevents cars from honking more than once
]
]
]
[
merge ;; if the police man is allowing rightward traffic, merge up into top lane
set passed? true ;; update the passed? boolean
]
]
;; if not on the signal patch, just follow the drive procedure
[ drive ]
;; this tells the cars when to merge back down into the bottom lane
if [signal-patch-top?] of patch-at 1 0 = true
[ merge ]
]
if lane = 1
[ ;; car is a "top lane" car
ifelse [signal-patch-top?] of patch-here = true ;; determine if the car on the signal-patch of its lane
[
ifelse sign = "rightward" or [pcolor] of patch 2 4 = yellow ;; if the police person is allowing rightward traffic
[ fd 0 ;; do not proceed forward
ask cars-on right-side [
ask self [
if patience < 60 ;; about 60% chance the car will "honk" at police man
[ set honking-level honking-level + 1 ;; update honking-level
set patience 100 ] ;; this prevents cars from honking more than once
]
]
]
[ fd 1 ;; cars go forward one patch so they can be counted in car-counter
;; drive ;; if the police man is allowing leftward traffic, drive pass roadblock
set passed? true ;; update passed? boolean
]
]
;; if the car is not on a signal patch, then follow the drive proceedure
[ drive ]
]
]
end
to drive
ask self [
;; these first two ifelse statements check to see if the upcoming three patches are the signal patch
;; and if one of them is, the car effectively slows down
ifelse [signal-patch-bottom?] of patch-at 1 0 = true
or [signal-patch-bottom?] of patch-at 2 0 = true
or [signal-patch-bottom?] of patch-at 3 0 = true
[ let car-ahead one-of turtles-on patch-ahead 1
ifelse car-ahead != nobody
[ fd 0 ] ;; if there is a car on the patch in front of you, stop
[ fd 1 ] ;; otherwise, only go forward one patch
]
[ ifelse [signal-patch-top?] of patch-at -1 0 = true
or [signal-patch-top?] of patch-at -2 0 = true
or [signal-patch-bottom?] of patch-at -3 0 = true
[ let car-ahead one-of turtles-on patch-ahead 1
ifelse car-ahead != nobody
[ fd 0 ] ;; if there is a car on the patch in front of you, stop
[ fd 1 ]
]
;; this determines how many patches a car can drive through in one tick
;; to simulate various speeds
[ let car-ahead one-of turtles-on patch-ahead 1
ifelse car-ahead != nobody ;; if there is a car one patch ahead
[ fd 0 ] ;; stop
[
let car-ahead-2 one-of turtles-on patch-ahead 2
ifelse car-ahead-2 != nobody ;; if there is a car two patches ahead
[ fd 1 ;; only go forward one patch
fd 0 ] ;; otherwise, stop
[
let car-ahead-3 one-of turtles-on patch-ahead 3
ifelse car-ahead-3 != nobody ;; if there is a car three patches ahead
[ fd 2 ;; only go forward two patches
fd 0 ] ;; otherwise, stop
[ fd 3 ] ;; if there are no cars ahead for three patches, go forward three patches
]
]
]
]
]
; uncomment this procedure for a very simple drive procedure (for testing/de-bugging)
; ask self [
; let car-ahead one-of turtles-on patch-ahead 1
; ifelse car-ahead = nobody
; [ fd 1 ]
; [ fd 0 ]
; ]
end
;; this procedure is based loosely on Wilensky's Intersection model
to change-signs
;; this procedure switches the two stop/go signs
ifelse sign = "leftward"
[ set sign "rightward"
prepare-signs ;; re-draw the signs
]
[ set sign "leftward"
prepare-signs ;; re-draw the signs
]
end
;; this code block executes if the learning? switch is ON
to police-learning
;; count the number of cars on both the left and right side
set right-cnt count cars-on right-side
set left-cnt count cars-on left-side
ask police [
;; if leftward-moving traffic is just clearing the roadblock
if sign = "leftward" and ([pcolor] of patch 2 4 = yellow)
[ if honking-level / left-cnt > 1.5 ;; and if a certain proportion of the top lane is honking
[ ifelse ( left-cnt ) > right-cnt ;; if there are more cars on the left side than the right
[ if efficiency-time-left < count cars with [color = pink] * 1.5
[set efficiency-time-left efficiency-time-left + 1] ;; allow more time for the top lane to pass
]
[ if efficiency-time-left > 5
[set efficiency-time-left efficiency-time-left - 1] ;; allow less time for the top lane to pass
]
]
]
;; if rightward-moving traffic is just clearing the roadblock
if sign = "rightward" and ([pcolor] of patch -2 4 = yellow)
[ if honking-level / right-cnt > 1.5 ;; and if a certain proportion of the bottom lane is honking
[ifelse ( right-cnt ) > left-cnt ;; if there are more cars on the right side than the left
[ if efficiency-time-right < count cars with [color = blue] * 1.5
[set efficiency-time-right efficiency-time-right + 1 ] ;; allow more time for the bottom lane to pass
]
[if efficiency-time-right > 5
[set efficiency-time-right efficiency-time-right - 1 ] ;; allow less time for the bottom lane to pass
]
]
]
]
end
;; this proceedure describes how a car in the bottom lane should merge past the roadblock
to merge
ask self [
;; if the car is in the bottom lane, merge up
ifelse ycor = -1 [
ifelse (not any? turtles-at 0 2)
[ set ycor 1 ]
[fd 0]
]
[
;; if the car is in the top lane, merge down
ifelse (not any? turtles-at 0 -2)
[ set ycor -1 ]
[fd 0]
]
]
end
to update-efficiency-list
if ticks != 0 [
ifelse sign = "leftward"
;; if leftward moving traffic is allowed to pass the roadblock
[ ifelse ticks mod (time-between-sign-change) = 0 and [pcolor] of patch 2 4 != yellow
;; if the time-between-sign-change is up
[ set waiting-list-left lput car-counter waiting-list-left ;; add car-counter value to efficiency-list
set car-counter 0 ;; then, reset car-counter
]
[ ;; if cars are still allowed through the intersection
if any? cars with [pxcor = 8 and pycor = 1]
[ set car-counter car-counter + 1 ] ;; update car-counter
]
]
;; if rightward moving traffic is allowed to pass the roadblock
[ ifelse ticks mod (time-between-sign-change) = 0 and [pcolor] of patch -2 4 != yellow
;; if the time-between-sign-change is up
[ set waiting-list-right lput car-counter waiting-list-right ;; add car-counter value to efficiency-list
set car-counter 0 ;; then, reset car-counter
]
[ ;; if cars are still allowed through the intersection
if any? cars with [pxcor = -9 and pycor = 1]
[ set car-counter car-counter + 1 ] ; update car-counter
]
]
]
;; if waiting-list-left is not empty
if waiting-list-left != [ ]
[set reduce-left reduce + ( waiting-list-left)] ;; sum up the top lane bahavior
;; if waiting-list-left is not empty
if waiting-list-right != [ ]
[set reduce-right reduce + waiting-list-right] ;; sum up the bottom lane bahavior
end
@#$#@#$#@
GRAPHICS-WINDOW
13
266
782
469
-1
-1
14.9231
1
10
1
1
1
0
1
0
1
-25
25
-6
6
1
1
1
ticks
30.0
BUTTON
73
75
145
116
NIL
setup
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
BUTTON
157
76
228
116
NIL
go
T
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
SLIDER
49
28
253
61
number-of-cars
number-of-cars
1
45
20.0
1
1
NIL
HORIZONTAL
SWITCH
21
133
134
166
learning?
learning?
0
1
-1000
SLIDER
21
172
293
205
time-between-sign-change
time-between-sign-change
0
20
15.0
1
1
ticks
HORIZONTAL
MONITOR
795
277
940
322
#cars to pass roadblock
car-counter
17
1
11
MONITOR
443
214
559
259
#cars in top lane
count cars with [color = blue]
17
1
11
MONITOR
567
214
685
259
#cars in bottom lane
count cars with [color = pink]
17
1
11
MONITOR
880
328
965
373
right side cnt
count cars-on right-side
17
1
11
MONITOR
795
328
873
373
left side cnt
count cars-on left-side
17
1
11
MONITOR
795
379
912
424
NIL
efficiency-time-left
17
1
11
MONITOR
918
379
1042
424
NIL
efficiency-time-right
17
1
11
MONITOR
795
430
881
475
NIL
honking-level
17
1
11
SWITCH
142
133
268
166
stopwatch?
stopwatch?
1
1
-1000
MONITOR
23
215
135
260
stopwatch value
allCarsThrough
17
1
11
SWITCH
145
221
253
254
top-heavy
top-heavy
1
1
-1000
SWITCH
260
221
388
254
bottom-heavy
bottom-heavy
0
1
-1000
PLOT
760
10
1190
207
Total Number of Cars Able to Pass Roadblock
NIL
NIL
0.0
10.0
0.0
10.0
true
true
"" ""
PENS
"top lane" 1.0 0 -13345367 true "" "plot reduce-left"
"bottom lane" 1.0 0 -2064490 true "" "plot reduce-right"
PLOT
319
10
750
207
#Cars that Pass Roadblock Before Sign Changes
NIL
NIL
0.0
10.0
0.0
10.0
true
true
"" ""
PENS
"top lane" 1.0 0 -13345367 true "" "if sign = \"leftward\" [plot car-counter]"
"bottom lane" 1.0 0 -2064490 true "" "if sign = \"rightward\" [plot car-counter]"
@#$#@#$#@
## WHAT IS IT?
This model was created to model the traffic patterns that emerge when two opposing lanes of traffic are forced to cooperate to get passed a roadblock. It is also intended to investigate the role that a traffic director, such as police person, may have on the efficiency of traffic.
In this model, there are two opposing lanes of traffic and a police person. The police person can either follow a very simple rule to direct traffic by allowing each lane to proceed for a given number of ticks or he can learn from the traffic pattern and attempt to maximize efficiency.
The cars drive according to a non-continuous perception of speed. They are allowed to move forward at most three patches as long as the interceding patches are devoid of any other cars. Similarly, cars can either move ahead two patches, one patch, or no patches at all if they are directly behind another car.
## HOW TO USE IT
The "**setup**" button sets up the cars based on the NUMBER slider, which determines how many cars are on the road. The user can also choose to make one lane have a disproportionate number of cars using the "**top-heavy**" and "**bottom-heavy**" switches. If neither switch is on, then both lanes will have approximately the same number of cars. If the "top-heavy" switch is on and the "bottom-heavy" switch is off, then the top lane will have about 60-80% of all the cars. If the "bottom-heavy" switch is on and the "top-heavy" switch is off, then the bottom lane will have about 60-80% of all the cars. Turning both switches on will result in a user-error since it is impossible to have both lanes with a majority of the traffic.
This model allows for the police person to direct traffic based on either learned behavior or a simple rule. To turn on the learning feature, use the "**learning?**" switch.
When the "learning?" switch is not on, the police person will direct traffic based on the "**time-between-sign-change**" slider. This slider determines how many ticks the police person allows to pass before stopping the moving lane of traffic and allowing the waiting lane to proceed.
The "**stopwatch?**" switch measures how long it takes for each car to pass the roadblock at least once and then outputs this value to the "stopwatch value" monitor. This is an important tool when it comes to measuring efficiency.
The "**go**" button starts the model. The cars wrap around the world making the road a continuous loop of traffic.
## THINGS TO NOTICE
When police-learning is turned off, it does not matter if one lane or the other is top heavy; about the same number of cars will be able to pass the roadblock in each lane. However, the more ticks-between-sign-change allowed, the more cars will be able to pass at one time.
The plot titled "Total Number of Cars Able to Pass Roadblock" shows the number of cars from the top lane able to pass the roadblock (the blue line) in reference to the number of cars from the bottom lane able to pass the roadblock (the pink line). There is some variation between these two lines, but there is no significant difference over multiple trial runs.
## THINGS TO TRY
Try changing the number of cars on the road to see how the "stopwatch value" changes. This can be seen as a form of efficiency: the lower the "stopwatch value" the more efficient the traffic pattern.
Try turning the "learning?" switch on and off for different numbers of cars on the road. Again, observe the "stopwatch value." Is traffic more efficienct when the police person is able to learn and adjust his own behavor?
## EXTENDING THE MODEL
It would be interesting to integrate the effects of a more complicated system for driving. Specifically, one could integrate the driving procedure from the Wilensky Basic Traffic model which includes variables for acceleration, deceleration, and speed as opposed to non-continuous patch movement.
One could also enable the police person to implement a few different manners of traffic conducting. In our model, the police person depends largely on measuring the number of cars that make it passed the road block in a given number of ticks. In this way, the police person measures efficiency. Future studies we could allow for an option where the police person decides when to stop one lane or the other depending on a fixed number of cars. So, perhaps the police person would always allow five cars from one direction to pass before stopping them and allowing five from the other to proceed. We might also try to develop a more complicated manner of determining when to change the signals, such as having the police person look down the moving lane and stop traffic at the point where he sees a natural break.
## NETLOGO FEATURES
There are two main monitors and two plots in this model.
The first main monitor, "stopwatch value," shows how many ticks have passed until every car has passed the roadblock at least once. The second main monitor, "Number of Cars to Pass the Roadblock," shows how many cars have passed the roadblock in the moving lane.
The efficiency-time-right and efficiency-time-left monitors display that amount of time that each lane of traffic has to pass the roadblock. These values will only change when the learning switch is on.
The plot "Number Cars that Pass Roadblock Before Sign Changes" depicts the timeline of the total number of cars in each lane that pass the roadblock. The plot "Total Number of Cars able to Pass Roadblock" depicts the sum, or reduce value, of the number of cars that pass the roadblock.
## RELATED MODELS
"Traffic Basic" models the wave-like pattern that evolves from traffic jams.
"Traffic 2 Lanes" models how two lanes of traffic heading in the same direction merge back and forth.
"Intersection" models two lanes of traffic that intersect perpendicularly at a light.
## Authorship
We referred to three models created by Uri Wilensky for insight on our own model:
"Traffic Basic" Copyright 1997, "Traffic 2 Lanes" Copyright 1998, and "Intersection" Copyright 1998.
@#$#@#$#@
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
butterfly
true
0
Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240
Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240
Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163
Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165
Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225
Circle -16777216 true false 135 90 30
Line -16777216 false 150 105 195 60
Line -16777216 false 150 105 105 60
car
false
0
Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180
Circle -16777216 true false 180 180 90
Circle -16777216 true false 30 180 90
Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89
Circle -7500403 true true 47 195 58
Circle -7500403 true true 195 195 58
car-flipped
false
0
Polygon -7500403 true true 0 180 21 164 39 144 60 135 74 132 87 106 97 84 115 63 141 50 165 50 225 60 300 150 300 165 300 225 0 225 0 180
Circle -16777216 true false 30 180 90
Circle -16777216 true false 180 180 90
Polygon -16777216 true false 138 80 168 78 166 135 91 135 106 105 111 96 120 89
Circle -7500403 true true 195 195 58
Circle -7500403 true true 47 195 58
circle
false
0
Circle -7500403 true true 0 0 300
circle 2
false
0
Circle -7500403 true true 0 0 300
Circle -16777216 true false 30 30 240
cow
false
0
Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167
Polygon -7500403 true true 73 210 86 251 62 249 48 208
Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123
cylinder