# Roundabout

Model was written in NetLogo 6.0.4
•
Viewed 126 times
•
Downloaded 5 times
•
Run 0 times

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)

## Comments and Questions

Please start the discussion about this model!
(You'll first need to log in.)

Click to Run Model

globals [ count-of-turtles patchset-A1 patchset-A2 patchset-B1 patchset-B2 patchset-C1 patchset-C2 patchset-D1 patchset-D2 patiencevalue ] turtles-own [ speed status speedlimit entry-point acceleration yellow-patch-count segment lane prime num1 num2 num3 num4 num5 num6 num7 num8 life ] to setup ca ask patches [set pcolor green] ;; construct main approach roads ask patches [ if pxcor > -82 and pxcor < 82 [ set pcolor black] if pycor > -82 and pycor < 82 [ set pcolor black] ;; draw central lines if pxcor > -1 and pxcor < 1 [set pcolor brown] if pycor > -1 and pycor < 1 [set pcolor brown] ;; draw lanes if pxcor > 25 and pxcor < 27 [ set pcolor white] if pxcor > 52 and pxcor < 54 [ set pcolor white] if pxcor > 79 and pxcor < 81 [ set pcolor white] if pxcor > -27 and pxcor < -25 [ set pcolor white] if pxcor > -54 and pxcor < -52 [ set pcolor white] if pxcor > -81 and pxcor < -79 [ set pcolor white] if pycor > 25 and pycor < 27 [ set pcolor white] if pycor > 52 and pycor < 54 [ set pcolor white] if pycor > 79 and pycor < 81 [ set pcolor white] if pycor > -27 and pycor < -25 [ set pcolor white] if pycor > -54 and pycor < -52 [ set pcolor white] if pycor > -81 and pycor < -79 [ set pcolor white] ] ;; Construct roundabout ask patches [ if (distancexy 0 0) < 30 [ set pcolor white ] if (distancexy 0 0) > 30 and (distancexy 0 0) < 109 [ set pcolor black ] if (distancexy 0 0) > 55 and (distancexy 0 0) < 57 [ set pcolor white ] if (distancexy 0 0) > 82 and (distancexy 0 0) < 84 [ set pcolor white ] if (distancexy 0 0) > 109 and (distancexy 0 0) < 111 [ set pcolor white ] ] ;; Construct entry points for inner lane ask patches [ if ((pxcor > 10 and pxcor < 25) and (pycor > -50 and pycor < -35)) or ((pxcor > -25 and pxcor < -10) and (pycor < 50 and pycor > 35)) or ((pxcor > -50 and pxcor < -35) and (pycor < -10 and pycor > -25)) or ((pxcor < 50 and pxcor > 35) and (pycor > 10 and pycor < 25)) [ set pcolor green] ] ;; Construct exit points for inner lane ask patches [ if ((pxcor < -10 and pxcor > -25) and (pycor > -45 and pycor < -30)) or ((pxcor < 25 and pxcor > 10) and (pycor < 45 and pycor > 30)) or ((pxcor > -50 and pxcor < -35) and (pycor > 10 and pycor < 25)) or ((pxcor < 50 and pxcor > 35) and (pycor < -10 and pycor > -25)) [ set pcolor yellow ] ] ;; Construct entry points for middle lane ask patches [ if ((pxcor > 35 and pxcor < 50) and (pycor > -65 and pycor < -50)) or ((pxcor > -50 and pxcor < -35) and (pycor < 65 and pycor > 50)) or ((pxcor > -65 and pxcor < -50) and (pycor < -30 and pycor > -45 )) or ((pxcor < 65 and pxcor > 50) and (pycor > 30 and pycor < 45)) [ set pcolor green] ] ;; Construct exit points for middle lane ask patches [ if ((pxcor < -35 and pxcor > -50) and (pycor > -65 and pycor < -50)) or ((pxcor < 50 and pxcor > 35) and (pycor < 65 and pycor > 50)) or ((pxcor > -65 and pxcor < -50) and (pycor > 35 and pycor < 50)) or ((pxcor < 65 and pxcor > 50) and (pycor < -35 and pycor > -50)) [ set pcolor yellow ] ] ;; Construct entry points for outer lane ask patches [ if ((pxcor > 60 and pxcor < 70) and (pycor > -85 and pycor < -75)) or ((pxcor > -70 and pxcor < -60) and (pycor < 85 and pycor > 75)) or ((pxcor > -85 and pxcor < -75) and (pycor < -60 and pycor > -70 )) or ((pxcor < 85 and pxcor > 75) and (pycor > 60 and pycor < 70)) [ set pcolor green] ] ;; Construct exit points for outer lane ask patches [ if ((pxcor < -60 and pxcor > -70) and (pycor > -85 and pycor < -75)) or ((pxcor < 70 and pxcor > 60) and (pycor < 85 and pycor > 75)) or ((pxcor > -85 and pxcor < -75) and (pycor > 60 and pycor < 70)) or ((pxcor < 85 and pxcor > 75) and (pycor < -60 and pycor > -70)) [ set pcolor yellow ] ] ;; construct roundabout entry stop points ask patches [ if ((pxcor > 10 and pxcor < 20) and (pycor < -110 and pycor > -112)) or ((pxcor > -20 and pxcor < -10) and (pycor > 110 and pycor < 112)) or ((pxcor > 35 and pxcor < 45) and (pycor < -104 and pycor > -106)) or ((pxcor > 60 and pxcor < 70) and (pycor < -92 and pycor > -94)) or ((pxcor > -45 and pxcor < -35) and (pycor > 104 and pycor < 106)) or ((pxcor > -70 and pxcor < -60) and (pycor > 92 and pycor < 94)) or ((pxcor > 110 and pxcor < 112) and (pycor > 10 and pycor < 20)) or ((pxcor > 104 and pxcor < 106) and (pycor > 35 and pycor < 45)) or ((pxcor > 92 and pxcor < 94) and (pycor > 60 and pycor < 70)) or ((pxcor < -110 and pxcor > -112) and (pycor < -10 and pycor > -20)) or ((pxcor < -104 and pxcor > -106) and (pycor < -35 and pycor > -45)) or ((pxcor < -92 and pxcor > -94) and (pycor < -60 and pycor > -70)) [set pcolor red] ] crt 1 [ setxy 15 -111 set heading 335 set prime 1] crt 1 [ setxy 40 -105 set heading 325 set prime 2] crt 1 [setxy 111 15 set heading 245 set prime 3 ] crt 1 [setxy 105 40 set heading 235 set prime 4 ] crt 1 [setxy -15 111 set heading 155 set prime 5 ] crt 1 [setxy -30 105 set heading 145 set prime 6 ] crt 1 [setxy -111 -15 set heading 65 set prime 7 ] crt 1 [setxy -105 -40 set heading 55 set prime 8 ] ask turtles [ if prime = 1 [ set patchset-A1 patches in-cone 100 40] ; ask patchset-A1 [ set pcolor pink]] if prime = 2 [ set patchset-A2 patches in-cone 80 40 ] ;ask patchset-A2 [ set pcolor green]] if prime = 3 [ set patchset-B1 patches in-cone 100 40 ] ; ask patchset-B1 [ set pcolor pink]] if prime = 4 [ set patchset-B2 patches in-cone 80 40 ] ; ask patchset-B2 [ set pcolor green]] if prime = 5 [ set patchset-C1 patches in-cone 100 40 ] ; ask patchset-C1 [ set pcolor pink]] if prime = 6 [ set patchset-C2 patches in-cone 80 40 ] ; ask patchset-C2 [ set pcolor green]] if prime = 7 [ set patchset-D1 patches in-cone 100 40 ] ; ask patchset-D1 [ set pcolor pink]] if prime = 8 [ set patchset-D2 patches in-cone 80 40 ] ; ask patchset-D2 [ set pcolor green]] die ] reset-ticks end to go ;; create car in section A ask patch 15 -190 [ if not any? turtles in-radius 10 and random int-arr-time = 1 [ sprout 1 [set shape "car" set size 13 set entry-point "A1" set color red set heading 0 set speed 0.2 set status "Entry" set yellow-patch-count 0 set segment "A" set lane 1 set life 0] ] ] ask patch 40 -190 [ if not any? turtles in-radius 10 and random int-arr-time = 1 [ sprout 1 [ set shape "car" set size 13 set entry-point "A2" set color red set heading 0 set speed 0.2 set status "Entry" set yellow-patch-count 0 set segment "A" set lane 2 set life 0] ] ] ask patch 65 -190 [ if not any? turtles in-radius 10 and random int-arr-time = 1 [ sprout 1 [ set shape "car" set size 13 set entry-point "A3" set color red set heading 0 set speed 0.2 set status "Entry" set yellow-patch-count 0 set segment "A" set lane 3 set life 0] ] ] ;; create car in section B ask patch 190 15 [ if not any? turtles in-radius 10 and random int-arr-time = 1 [ sprout 1 [set shape "car" set size 13 set entry-point "B1" set color blue set heading -90 set speed 0.2 set status "Entry" set yellow-patch-count 0 set segment "B" set lane 1 set life 0] ] ] ask patch 190 40 [ if not any? turtles in-radius 10 and random int-arr-time = 1 [ sprout 1 [ set shape "car" set size 13 set entry-point "B2" set color blue set heading -90 set speed 0.2 set status "Entry" set yellow-patch-count 0 set segment "B" set lane 2 set life 0] ] ] ask patch 190 65 [ if not any? turtles in-radius 10 and random int-arr-time = 1 [ sprout 1 [ set shape "car" set size 13 set entry-point "B3" set color blue set heading -90 set speed 0.2 set status "Entry" set yellow-patch-count 0 set segment "B" set lane 3 set life 0] ] ] ;; create car in section C ask patch -15 190 [ if not any? turtles in-radius 10 and random int-arr-time = 1 [ sprout 1 [set shape "car" set size 13 set entry-point "C1" set color orange set heading 180 set speed 0.2 set status "Entry" set yellow-patch-count 0 set segment "C" set lane 1 set life 0] ] ] ask patch -40 190 [ if not any? turtles in-radius 10 and random int-arr-time = 1 [ sprout 1 [ set shape "car" set size 13 set entry-point "C2" set color orange set heading 180 set speed 0.2 set status "Entry" set yellow-patch-count 0 set segment "C" set lane 2 set life 0] ] ] ask patch -65 190 [ if not any? turtles in-radius 10 and random int-arr-time = 1 [ sprout 1 [ set shape "car" set size 13 set entry-point "C3" set color orange set heading 180 set speed 0.2 set status "Entry" set yellow-patch-count 0 set segment "C" set lane 3 set life 0] ] ] ;; create car in section D ask patch -190 -15 [ if not any? turtles in-radius 10 and random int-arr-time = 1 [ sprout 1 [set shape "car" set size 13 set entry-point "D1" set color magenta set heading 90 set speed 0.2 set status "Entry" set yellow-patch-count 0 set segment "D" set lane 1 set life 0] ] ] ask patch -190 -40 [ if not any? turtles in-radius 10 and random int-arr-time = 1 [ sprout 1 [ set shape "car" set size 13 set entry-point "D2" set color magenta set heading 90 set speed 0.2 set status "Entry" set yellow-patch-count 0 set segment "D" set lane 2 set life 0] ] ] ask patch -190 -65 [ if not any? turtles in-radius 10 and random int-arr-time = 1 [ sprout 1 [ set shape "car" set size 13 set entry-point "D3" set color magenta set heading 90 set speed 0.2 set status "Entry" set yellow-patch-count 0 set segment "D" set lane 3 set life 0] ] ] ask turtles [ set speedlimit 0.6 set acceleration 0.1 move-on-road set life life + 1 let-turtle-die] tick end ;; procedure for turtle to move on the road i.e. approaching roundabout, entering roundabout, travelling in roundabout, exiting roundabout and onward travel ;; to move-on-road ;; light red patch at the entrance of the roundabout is the location where each car has to stop and check for traffic before proceeding into the roundabout if [pcolor] of patch-here = red and lane != 3 [ if any? other turtles-on patch-here [ die ] set speed 0.0 set status "Stop" set num1 count turtles-on patchset-A1 set num2 count turtles-on patchset-A2 set num3 count turtles-on patchset-B1 set num4 count turtles-on patchset-B2 set num5 count turtles-on patchset-C1 set num6 count turtles-on patchset-C2 set num7 count turtles-on patchset-D1 set num8 count turtles-on patchset-D2 ;; if driver is patient, then she will wait for all cars to clear. If not, she will try to enter roundabout even with cars approaching from her left side. ifelse patience = "patient" [ set patiencevalue 2] [ set patiencevalue 5] if entry-point = "A1" and num1 < patiencevalue [ fd 2 set status "Go" ] if entry-point = "A2" [ if num2 < patiencevalue [ fd 2 set status "Go" ] if [ entry-point ] of turtles-on patchset-A2 = "A1" [ fd 2 set status "Go" ]] if entry-point = "B1" and num3 < patiencevalue [ fd 2 set status "Go" ] if entry-point = "B2" [ if num4 < patiencevalue [ fd 2 set status "Go" ] if [ entry-point ] of turtles-on patchset-B2 = "B1" [ fd 2 set status "Go" ]] if entry-point = "C1" and num5 < patiencevalue [ fd 2 set status "Go" ] if entry-point = "C2" [ if num6 < patiencevalue [ fd 2 set status "Go" ] if [ entry-point ] of turtles-on patchset-C2 = "C1" [ fd 2 set status "Go" ]] if entry-point = "D1" and num7 < patiencevalue [ fd 2 set status "Go" ] if entry-point = "D2" [ if num8 < patiencevalue [ fd 2 set status "Go" ] if [ entry-point ] of turtles-on patchset-D2 = "B1" [ fd 2 set status "Go" ] ] set num1 0 set num2 0 set num3 0 set num4 0 set num5 0 set num6 0 set num7 0 set num8 0 ] ;; Green colored patch provides a circular motion for the cars within the roundabout if [pcolor] of patch-here = green [ if entry-point = "A1" or entry-point = "B1" or entry-point = "C1" or entry-point = "D1" and status = "Go" [ set speed 0.6 rt 50 set status "RAinner" fd 10 ] if entry-point = "A2" or entry-point = "B2" or entry-point = "C2" or entry-point = "D2" and status = "Go" [ set speed 0.6 rt 50 set status "RAmiddle" fd 10 ] if entry-point = "A3" or entry-point = "B3" or entry-point = "C3" or entry-point = "D3" and status = "Entry" [ set speed 0.6 rt 45 set status "RAouter" fd 7 ]] ;; Circular path for cars travelling the innermost lane if status = "RAinner" [ if speed != 0 [ lt 0.75 ] ;; Car stops if there is another car ahead and its color changes to yellow. Color changes back to original color once speed becomes more than 0 let car-ahead-conei one-of turtles in-cone 20 90 ifelse car-ahead-conei != nobody and car-ahead-conei != self [set speed 0 set color yellow] [if speed < speedlimit [set speed 0.6 if segment = "A" [ set color red ] if segment = "B" [ set color blue] if segment = "C" [ set color orange ] if segment = "D" [ set color magenta ]] ifelse [ pcolor] of patch-here = yellow and yellow-patch-count > 200 [ set status "Exit" rt 42] [ set yellow-patch-count yellow-patch-count + 1 ] ]] ;; Circular path for cars travelling in the middle lane if status = "RAmiddle" [if speed != 0 [lt 0.5] ;; Car stops if there is another car ahead and its color changes to yellow. Color changes back to original color once speed becomes more than 0 let car-ahead-conem one-of turtles in-cone 20 90 ifelse car-ahead-conem != nobody and car-ahead-conem != self [set speed 0 set color yellow ] [if speed < speedlimit [set speed 0.6 if segment = "A" [ set color red ] if segment = "B" [ set color blue] if segment = "C" [ set color orange ] if segment = "D" [ set color magenta ]] ifelse [ pcolor] of patch-here = yellow and yellow-patch-count > 60 [ set status "Exit" rt 55] [ set yellow-patch-count yellow-patch-count + 1 ] ]] ;; Path for cars travelling in the outermost lane if status = "RAouter" [lt 0.3 ifelse [ pcolor] of patch-here = yellow [ set status "Exit" rt 48] [ set yellow-patch-count yellow-patch-count + 1 ] ] ;; Forward motion of the car. When the car enters the roundabout (i.e. before Green patch), car is in "Go" state and checks for car ahead and stops if there are any. if status = "Entry" or status = "Exit" or status = "Go" [ car-ahead-action if status = "Go" [ car-ahead-incone ] ] fd speed end ;; procedure for turtle to enter the roundabout from the road to car-ahead-action let car-ahead one-of turtles-on patch-ahead 10 ifelse car-ahead != nobody [set speed [ speed ] of car-ahead ] [if speed < speedlimit [set speed speed + 0.1 ] ] end ;; procedure for turtle to move in the roundabout to car-ahead-incone let car-ahead one-of turtles in-cone 20 10 ifelse car-ahead != nobody and car-ahead != self [set speed 0 set color yellow] [if speed < speedlimit [set speed 0.6 if segment = "A" [ set color red ] if segment = "B" [ set color blue] if segment = "C" [ set color orange ] if segment = "D" [ set color magenta ]] ] end ;; procedure for turtle to die to let-turtle-die if ((entry-point = "A1" or entry-point = "B2" or entry-point = "C3") and xcor < -170) or ((entry-point = "A2" or entry-point = "B3" or entry-point = "D1") and ycor > 170) or ((entry-point = "A3" or entry-point = "D2" or entry-point = "C1") and xcor > 170) or ((entry-point = "B1" or entry-point = "C2" or entry-point = "D3") and ycor < -170) [ die ] end

There is only one version of this model, created 9 months ago by Pradeesh K V.

## Attached files

File | Type | Description | Last updated | |
---|---|---|---|---|

Roundabout.png | preview | Preview for 'Roundabout' | 9 months ago, by Pradeesh K V | Download |

This model does not have any ancestors.

This model does not have any descendants.