Roundabout

Roundabout preview image

1 collaborator

Default-person Pradeesh K V (Author)

Tags

roundabout 

Tagged by Pradeesh K V almost 7 years ago

traffic 

Tagged by Pradeesh K V almost 7 years ago

Visible to everyone | Changeable by the author
Model was written in NetLogo 6.0.4 • Viewed 865 times • Downloaded 43 times • Run 0 times
Download the 'Roundabout' modelDownload this modelEmbed this model

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


WHAT IS IT?

This model shows a three lane roundabout traffic. The objective of the model is to highlight the emergent traffic patterns as a result of the driver's level of patience when trying to negotiate the roundabout.

HOW IT WORKS

Cars from each of the four segments arrive at the roundabout. When the cars are over the thin red patches, they stop and look for traffic on their left side. If there is no traffic, the cars proceed into the roundabout.

Once on the green patch, their motion is changed into a circular motion taking them to the desired exit. The desired exit is pre-programmed for a car depending on from which segment it enters the roundabout and its lane.

The cars keep a count of the number of yellow patches traveresed. When the desired exit is reached, the yellow patch counts meets a criteria and the exit actions are performed.

Once they exit, they die after reaching end of the road.

HOW TO USE IT

SETUP - Sets up the roundabout

GO - The go command sprouts cars based on the interarrival time. The interarrival time is not a distribution but only used in a proxy mode (by means of the random function) to replicate traffic density.

Interarrival Time Slider - A lower interarrival time means more arrivals and vice versa. Rush hour will have a low interarrival time whereas off peak time will have large interarrival time

Patience Chooser - Two scenarios are provided. In one case, all drivers are patient and are therefore willing to wait for all cars to clear from their left side before they enter the roundabout.

On the other hand, when drivers are impatient, they enter the roundabout about even if there are about 2 -3 cars arriving from their left side.

THINGS TO NOTICE

Cars entering the roundabout will stop if there is any car in front of them. When they stop, their color changes to yellow. Once they start moving again, color changes back to their original color.

So when the cars stop and start moving again quite quickly, the color change appear as blinks. These blinks is similar to the application of brake lights and indicates that the car has slowed down.

It can be noticed that when the driver is impatient and it is rushour, the roundabout becomes increasingly choked since every one is trying to save on waiting time and trying to clear the roundabout.

On the other hand, when the driver is patient even during heavy traffic, the roundabout is less congested and traffic always clears.

THINGS TO TRY

The two scenarios namely patient and impatient can be tried with multiple values of interarrival time. Significant increase in congestion can be observed only when the interarrival time is small.

It is aslo suggested to run the model with low interarrival time in the patient scenario mode and observe the roundabout traffic. Now change scenario to impatient mode and observe the increased congestion and blocks. Now change scenario again to patient mode and observe how the block clears from the roundabout.

A plot of the mean car life time in the simulation is included. The variation of the mean life with different scenarios and settings can be explored. Some results can be counterintuitive. It is suggested that the user predict the expected outcome and compare it with the actuals.

EXTENDING THE MODEL

Additional scenarios: The model can be extended with additional scenarios such as assigning random patience among drivers. Also the traffic flow can be different for each of the segments and see how it affects the traffic in the roundabout.

The level of patience can also be expanded and explored.

Plots: Additional plots can be added such as time spent waiting to enter roundabout and time spent for clearing roundabout

NETLOGO FEATURES

RELATED MODELS

Traffic Basic and Circular path example were referred to understand and code the car movement behavior

CREDITS AND REFERENCES

  1. Traffic Basic Netlogo model

  2. Circular Path Example Netlogo model

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 almost 7 years ago by Pradeesh K V.

Attached files

File Type Description Last updated
Roundabout.png preview Preview for 'Roundabout' almost 7 years ago, by Pradeesh K V Download

This model does not have any ancestors.

This model does not have any descendants.