globals [ sample-car ticks ] turtles-own [ speed speed-limit speed-min ] to setup ca set ticks 0 ask patches [ setup-road ] setup-cars end to setup-road if ( pycor < 2 ) and ( pycor > -2 ) [ set pcolor white ] end to setup-cars if ( number > screen-size-x ) [ user-message "There are too many cars for the amount of road. Please decrease the NUMBER slider to below " + (screen-size-x + 1) + " and press the SETUP button again. The setup has stopped." stop ] set-default-shape turtles "car" cct number [ set color blue set xcor random-float screen-size-x set ycor 0 set heading 90 ;;; set initial speed to be in range 0.1 to 1.0 set speed 0.1 + random 9.9 set speed-limit 1 set speed-min 0 separate-cars ] set sample-car one-of turtles ask sample-car [ set color red ] end ; this function is needed so when we click "Setup" we ; don't end up with any two cars on the same patch to separate-cars ; turtle procedure if any? other-turtles-here [ fd 1 separate-cars ] end to drive set ticks ticks + 1 ;; if there is a car right ahead of you, match its speed then slow down ask turtles [ ifelse any? turtles-at 1 0 [ set speed (speed-of one-of turtles-at 1 0) slow-down-car ] ;; otherwise, speed up [ speed-up-car ] ;;; don't slow down below speed minimum or speed up beyond speed limit if speed < speed-min [ set speed speed-min ] if speed > speed-limit [ set speed speed-limit ] fd speed ] plot-cars end to slow-down-car set speed speed - ( slow-down / 1000 ) end to speed-up-car set speed ( speed + ( speed-up / 10000 ) ) end to plot-cars set-current-plot "Car Speed" set-current-plot-pen "Red Car Speed" plot (100 * (speed-of sample-car)) set-current-plot-pen "Min Speed" plot (100 * (min values-from turtles [speed])) set-current-plot-pen "Max Speed" plot (100 * (max values-from turtles [speed])) end to-report red-car-speed ifelse any? turtles [ report ( 100 * speed-of sample-car ) ] [ report 0 ] end ; *** NetLogo Model Copyright Notice *** ; ; 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. ; ; Copyright 1997 by Uri Wilensky. All rights reserved. ; ; Permission to use, modify or redistribute this model is hereby granted, ; provided that both of the following requirements are followed: ; a) this copyright notice is included. ; b) this model will not be redistributed for profit without permission ; from Uri Wilensky. ; Contact Uri Wilensky for appropriate licenses for redistribution for ; profit. ; ; This model was converted to NetLogo as part of the project: ; PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN ; CLASSROOMS. The project gratefully acknowledges the support of the ; National Science Foundation (REPP program) -- grant number REC #9814682. ; Converted from StarLogoT to NetLogo, 2001. Updated 2002. ; ; To refer to this model in academic publications, please use: ; Wilensky, U. (1997). NetLogo Traffic Basic model. ; http://ccl.northwestern.edu/netlogo/models/TrafficBasic. ; Center for Connected Learning and Computer-Based Modeling, ; Northwestern University, Evanston, IL. ; ; In other publications, please use: ; Copyright 1998 by Uri Wilensky. All rights reserved. See ; http://ccl.northwestern.edu/netlogo/models/TrafficBasic ; for terms of use. ; ; *** End of NetLogo Model Copyright Notice *** @#$#@#$#@ GRAPHICS-WINDOW 263 10 683 211 20 8 10.0 1 10 1 1 1 CC-WINDOW 378 224 673 414 Command Center BUTTON 19 49 91 90 NIL setup NIL 1 T OBSERVER T BUTTON 144 50 215 90 NIL drive T 1 T OBSERVER T SLIDER 6 113 118 146 number number 1 41 20 1 1 NIL SLIDER 127 158 254 191 slow-down slow-down 0.0 99.0 26.0 1.0 1 NIL SLIDER 127 113 254 146 speed-up speed-up 0.0 99.0 45.0 1.0 1 NIL PLOT 11 217 254 414 Car Speed time speed 0.0 300.0 0.0 110.0 true false PENS "Red Car Speed" 1.0 0 -65536 true "Min Speed" 1.0 0 -16776961 true "Max Speed" 1.0 0 -11352576 true MONITOR 265 245 362 294 red car speed red-car-speed 2 1 @#$#@#$#@ WHAT IS IT? ----------- This project models the movement of cars on a highway. Each car follows a simple set of rules: it slows down if it sees a car close ahead, and speeds up if it doesn't see a car ahead. The project demonstrates how traffic jams can form even without any accidents, broken bridges, or overturned trucks. No "centralized cause" is needed for a traffic jam to form. HOW TO USE IT ------------- Click on the SETUP button to set up the cars. Set the NUMBER slider to change the number of cars on the road. Click on DRIVE to start the cars moving. Note that they wrap the screen as they move, so the road is like a continuous loop. The SPEED-UP slider controls the rate at which cars accelerate when there are no cars ahead. When a car sees another car right in front, it matches that car's speed and then slows down a bit more. How much slower it goes than the car in front of it is controlled by the SLOW-DOWN slider. THINGS TO NOTICE ---------------- Traffic jams can start from small "seeds." These cars start with random positions and random speeds. If some cars are clustered together, they will move slowly, causing cars behind them to slow down, and a traffic jam forms. Even though all of the cars are moving forward, the traffic jams tend to move backwards. This behavior is common in wave phenomena: the behavior of the group is often very different from the behavior of the individuals that make up the group. Plotwindow 1 plots three values as the model runs: - the fastest speed of any car (this doesn't exceed the speed limit!) - the slowest speed of any car - the speed of a single car (turtle 0), painted red so it can be watched. Notice not only the maximum and minimum, but also the variability -- the "jerkiness" of one vehicle. THINGS TO TRY -------------- In this model there are three variables that can affect the tendency to create traffic jams: the initial NUMBER of cars, SPEED-UP, and SLOW-DOWN. Look for patterns in how the three settings affect the traffic flow. Which variable has the greatest effect? Do the patterns make sense? Do they seem to be consistent with your driving experiences? Set SLOW-DOWN to zero. What happens to the flow? Gradually increase SLOW-DOWN while the model runs. At what point does the flow "break down"? EXTENDING THE MODEL ------------ Try other rules for speeding up and slowing down. Is the rule presented here realistic? Are there other rules that are more accurate or represent better driving strategies? In reality, different vehicles may follow different rules. Try giving different rules or speedup/slowdown values to some of the cars. Can one bad driver mess things up? What could you change to minimize the chances of traffic jams forming? What could you change to make traffic jams move forward rather than backward? Make a model for two-lane traffic. NETLOGO FEATURES ----------------- The turtles/cars use SPEED-AT to find out the value of the SPEED variable for other turtles/cars. The plotwindow can plot both global values and the value for a single turtle, which helps one watch overall patterns and individual behavior at the same time. The cars have decimal speeds and positions that are updated much more often than the time it takes for a car to move one space. Position is rounded off to deterimine which patch the car is on. RELATED MODELS --------------- "Traffic" (in StarLogoT) adds graphics, trucks, and a radar trap. "Gridlock" (a HubNet model which can be run as a participatory simulation) looks at traffic in a grid with many intersections. CREDITS AND REFERENCES ----------------------- This model was developed at the MIT Media Lab. See Resnick, M. (1994) "Turtles, Termites and Traffic Jams: Explorations in Massively Parallel Microworlds." Cambridge, Ma: MIT Press. Adapted to StarLogoT, 1997, as part of the Connected Mathematics Project. Adapted to NetLogo, 2000, as part of the Participatory Simulations Project. To refer to this model in academic publications, please use: Wilensky, U. (1997). NetLogo Traffic Basic model. http://ccl.northwestern.edu/netlogo/models/TrafficBasic. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. In other publications, please use: Copyright 1997 by Uri Wilensky. All rights reserved. See http://ccl.northwestern.edu/netlogo/models/TrafficBasic for terms of use. @#$#@#$#@ default true 0 Polygon -7566196 true true 150 5 40 250 150 205 260 250 car true 15 Circle -1 false true 185 55 60 Circle -1 false true 183 186 61 Polygon -1 true true 214 52 214 22 182 26 162 38 144 74 138 102 100 120 99 161 102 201 118 246 152 267 190 275 210 251 187 240 178 200 204 182 215 181 214 118 193 112 182 98 181 72 198 52 house true 14 Rectangle -7566196 true false 33 90 258 243 Polygon -7566196 true false 13 89 151 1 288 89 Rectangle -7566196 true false 120 158 167 242 Rectangle -16777216 true true 118 154 170 241 Rectangle -16777216 true true 181 114 242 148 Rectangle -16777216 true true 126 180 152 184 Rectangle -7566196 true false 195 17 230 55 person false 0 Circle -7566196 true true 155 20 63 Rectangle -7566196 true true 158 79 217 164 Polygon -7566196 true true 158 81 110 129 131 143 158 109 165 110 Polygon -7566196 true true 216 83 267 123 248 143 215 107 Polygon -7566196 true true 167 163 145 234 183 234 183 163 Polygon -7566196 true true 195 163 195 233 227 233 206 159 stop sign true 0 Polygon -7566196 true true 78 119 135 75 197 75 244 121 245 181 197 224 136 224 88 183 89 112 90 112 136 75 137 77 street light true 0 Rectangle -7566196 true true 61 79 75 270 Rectangle -7566196 true true 62 78 134 104 Line -7566196 true 99 106 80 128 Line -7566196 true 101 108 100 128 Line -7566196 true 108 108 117 126 Line -7566196 true 121 108 136 132 Line -7566196 true 118 111 125 126 truck-right false 0 Polygon -7566196 true true 180 135 75 135 75 210 225 210 225 165 195 165 Polygon -8716033 true false 210 210 195 225 180 210 Polygon -8716033 true false 120 210 105 225 90 210 @#$#@#$#@ NetLogo 2.0beta5 @#$#@#$#@ setup repeat 150 [ drive ] @#$#@#$#@ @#$#@#$#@