Traffic Intersection

Traffic Intersection preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

complex systems 

Tagged by Reuven M. Lerner over 11 years ago

social science 

Tagged by Reuven M. Lerner about 11 years ago

traffic 

Tagged by Reuven M. Lerner over 11 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 1923 times • Downloaded 149 times • Run 5 times
Download the 'Traffic Intersection' 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?

In this model the turtles are cars traveling through an intersection. The user has the ability to control the frequency of cars coming from each direction, the speed of the cars, and the timing of the light at the traffic intersection. Once the frequency and speed of cars is selected, the user should run the simulation and adjust the timing of the traffic light so as to minimize the amount of waiting time of cars traveling through the intersection.

HOW IT WORKS

The rules for each car are:

  • I can only go in the direction I started in, or stop.
  • I stop for cars in front of me and red lights, and I slow down at a yellow light.
  • If I am moving quickly and I see that I will have to stop soon, I slow down proportional to the distance of non-free space up to MAX-BRAKE.
  • If I see that I have free space in front of me, I speed up proportional to the amount of free space up to MAX-ACCEL.
  • If I am on the same space as another car, we crash and die.

HOW TO USE IT

WAIT-TIME-OVERALL shows how many cars are waiting during the given clock tick.
WAIT-TIME-EASTBOUND shows how many eastbound cars are waiting during the given clock tick.
WAIT-TIME-NORTHBOUND shows how many northbound cars are waiting during the given clock tick.

CLOCK shows how many ticks have elapsed.

Use the FREQ-EAST slider to select how often new eastbound cars travel on the road.
Use the FREQ-NORTH slider to select how often new northbound cars travel on the road.

Use the SPEED-LIMIT slider to select how fast the cars will travel.
Use the MAX-ACCEL slider to determine how fast the cars can accelerate.
Use the MAX-BRAKE slider to determine how fast the cars can decelerate.

Use the GREEN-LENGTH slider to set how long the light will remain green.
Use the YELLOW-LENGTH slider to set how long the light will remain yellow.

Press GO ONCE to make the cars move once.
Press GO to make the cars move continuously.
To stop the cars, press the GO button again.

THINGS TO NOTICE

Cars start out evenly spaced but over time, they form bunches. What kinds of patterns appear in the traffic flow?

Under what conditions do the cars appear to be moving backwards?

Gridlock happens when cars are unable to move because cars from the other direction are in their path. What settings cause gridlock in this model? What settings can be changed to end the gridlock?

THINGS TO TRY

Try to answer the following questions before running the simulations.

Record your predictions.

Compare your predicted results with the actual results.

  • What reasoning led you to correct predictions?
  • What assumptions that you made need to be revised?

Try different numbers of eastbound cars while keeping all other slider values the same.
Try different numbers of northbound cars while keeping all other slider values the same.
Try different values of SPEED-LIMIT while keeping all other slider values the same.
Try different values of MAX-ACCEL while keeping all other slider values the same.
Try different values of GREEN-LENGTH and YELLOW-LENGTH while keeping all other slider values the same.

For all of the above cases, consider the following:

  • What happens to the waiting time of eastbound cars?
  • What happens to the waiting time of northbound cars?
  • What happens to the overall waiting time?
  • What generalizations can you make about the impact of each variable on the waiting time of cars?
  • What kind of relationship exists between the number of cars and the waiting time they experience?
  • What kind of relationship exists between the speed of cars and the waiting time they experience?
  • What kind of relationship exists between the number of ticks of green light and the waiting time cars experience?

Use your answers to the above questions to come up with a strategy for minimizing the waiting time of cars.

What factor (or combination of factors) has the most influence over the waiting time experienced by the cars?

EXTENDING THE MODEL

Find a realistic way to eliminate all crashes by only changing car behavior.

Allow different light lengths for each direction in order to control wait time better.

In the model, the yellow light is only for visual effect. In real life, it tells cars that they need to start braking if they're going to be able to stop before the light turns red. Make the cars use this information, and see how it affects the model.

Is there a better way to measure the efficiency of an intersection than the current number of stopped cars?

HOW TO CITE

If you mention this model in a publication, we ask that you include these citations for the model itself and for the NetLogo software:

COPYRIGHT AND LICENSE

Copyright 1998 Uri Wilensky.

CC BY-NC-SA 3.0

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at uri@northwestern.edu.

This model was created as part of the project: CONNECTED MATHEMATICS: MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL MODELS (OBPML). The project gratefully acknowledges the support of the National Science Foundation (Applications of Advanced Technologies Program) -- grant numbers RED #9552950 and REC #9632612.

This model was converted to NetLogo as part of the projects: PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS and/or INTEGRATED SIMULATION AND MODELING ENVIRONMENT. The project gratefully acknowledges the support of the National Science Foundation (REPP & ROLE programs) -- grant numbers REC #9814682 and REC-0126227. Converted from StarLogoT to NetLogo, 2002.

Comments and Questions

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

Click to Run Model

globals [ stop-light ]
turtles-own [ speed ]
patches-own [ clear-in ]

;;;;;;;;;;;;;;;;;;;;
;;SETUP PROCEDURES;;
;;;;;;;;;;;;;;;;;;;;

to setup
  clear-all
  set-default-shape turtles "car"
  ask patches
    [ set pcolor green - 1
      if abs pxcor <= 1 or abs pycor <= 1
        [ set pcolor black ]
    ]
  set stop-light "north"
  draw-stop-light
  reset-ticks
end 

to draw-stop-light
  ask patches with [abs pxcor <= 1 and abs pycor <= 1]
    [ set pcolor black ]
  ifelse stop-light = "north"
  [ ask patch 0 -1 [ set pcolor red ]
    ask patch -1 0 [ set pcolor green ]
  ]
  [ ask patch 0 -1 [ set pcolor green ]
    ask patch -1 0 [ set pcolor red ]
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;
;;RUNTIME PROCEDURES;;
;;;;;;;;;;;;;;;;;;;;;;

to go
  move-cars
  make-new-cars
  if auto? ;; switch the light automatically
  [ if ticks mod (green-length + yellow-length) = 0
    [ switch ]
    if ticks mod (green-length + yellow-length) > green-length
    [ ask patches with [pcolor = green]
      [ set pcolor yellow ]
    ]
  ]
  tick
end 

to make-new-cars
  if (random-float 100 < freq-north) and not any? turtles-on patch 0 min-pycor
    [
      crt 1
        [ set ycor min-pycor
          set heading 0
          set color 5 + 10 * random 14
          set speed min (list clear-ahead speed-limit)
        ]
    ]
  if (random-float 100 < freq-east) and not any? turtles-on patch min-pxcor 0
    [
      crt 1
        [ set xcor min-pxcor
          set heading 90
          set color 5 + 10 * random 14
          set speed min (list clear-ahead speed-limit)
        ]
    ]
end 

to move-cars
  ask turtles [ move ]
  check-for-collisions
end 

to move ;; turtle procedure
  let clear-to clear-ahead
  ifelse clear-to > speed
  [ if speed < speed-limit
    [ set speed speed + min (list max-accel (clear-to - 1 - speed)) ] ;; accelerate
    if speed > speed-limit
    [ set speed speed-limit ] ;; but don't speed
  ]
  [ set speed speed - min (list max-brake (speed - (clear-to - 1))) ;; brake
    if speed < 0 [ set speed 0 ]
  ]
  repeat speed ;; move ahead the correct amount
  [
    fd 1
    if not can-move? 1
    [ die ]

    if pcolor = orange
    [ set clear-in 5  ;; if you hit an accident you cause another one
      die
    ]
  ]
end 

to-report clear-ahead ;;turtle procedure
  let n 1
  repeat max-accel + speed  ;; look ahead the number of patches that could be travelled
  [ if (n * dx + pxcor <= max-pxcor) and (n * dy + pycor <= max-pycor)
    [ if([pcolor] of patch-ahead n = red) or
        ([pcolor] of patch-ahead n = orange) or
        (any? turtles-on patch-ahead n)
      [ report n ]
      set n n + 1
    ]
  ]
  report n
end 

to check-for-collisions
  ask patches with [ pcolor = orange ]
  [ set clear-in clear-in - 1
    if clear-in = 0
    [ set pcolor black ]
  ]
  ask patches with [ count turtles-here > 1 ]
  [
    set pcolor orange
    set clear-in 5
    ask turtles-here [ die ]
  ]
end 

to switch
  ifelse stop-light = "north"
  [ set stop-light "east"
    draw-stop-light
  ]
  [ set stop-light "north"
    draw-stop-light
  ]
end 


; Copyright 1998 Uri Wilensky.
; See Info tab for full copyright and license.

There are 10 versions of this model.

Uploaded by When Description Download
Uri Wilensky over 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky almost 12 years ago Updated version tag Download this version
Uri Wilensky almost 12 years ago Updated to version from NetLogo 5.0.3 distribution Download this version
Uri Wilensky over 12 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky over 14 years ago Traffic Intersection Download this version

Attached files

File Type Description Last updated
Traffic Intersection.png preview Preview for 'Traffic Intersection' over 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.