;;;;;;;;;;;;;;;;;;;;;;; ;;;;; EDITING TOOLS ;;;;;;;;;;;;;;;;;;;;;;; to edit-world if mouse-down? [ ; Store patch under cursor in local variable let mouse-patch patch-at mouse-xcor mouse-ycor ; Perform action on patch depending on edit tool if EDIT_TOOL = "Road" or EDIT_TOOL = "HOV Road" [ ask mouse-patch [ set road? true ifelse EDIT_TOOL = "HOV Road" [ set hov? true set pcolor red - 2 ] [ set hov? false set pcolor black ] ] set roads patches with [road?] ; re-evaluate roads set ] if EDIT_TOOL = "Grass" [ ask mouse-patch [ set pcolor green - 2.5 set road? false set hov? false set directions [] set plabel "" ] set roads patches with [road?] ; re-evaluate roads set ] if EDIT_TOOL = "Flow Counter" [ ifelse any? counters-on mouse-patch [ask counters-on mouse-patch [die]] [ask mouse-patch [sprout-counters 1 [init-counter]]] wait 0.1 ] if EDIT_TOOL = "Car" [ ifelse any? vehicles-on mouse-patch [ask vehicles-on mouse-patch [die]] [ask mouse-patch [sprout-vehicles 1 [init-vehicle]]] wait 0.1 ] if EDIT_TOOL = "Traffic Lights" [ ifelse any? lights-on mouse-patch [ask lights-on mouse-patch [die]] [ carefully [ let EW sum (list read-from-string user-input "How many seconds to stay green on horizontal link?") let NS sum (list read-from-string user-input "How many seconds to stay green on vertical link?") ask mouse-patch [ sprout-lights 1 [ init-lights EW NS ] ] ] [ user-message "You didn't enter a number; try again." ] ] wait 0.1 ] if EDIT_TOOL = "Source" [ ifelse any? sources-on mouse-patch [ask sources-on mouse-patch [die]] [ carefully [ let inp sum (list read-from-string user-input "Sprout a vehicle every how many seconds?") ask mouse-patch [ sprout-sources 1 [ set influx-every inp set label influx-every ] ] ] [ user-message "You didn't enter a number; try again." ] ] wait 0.1 ] if EDIT_TOOL = "Sink" [ ifelse any? sinks-on mouse-patch [ask sinks-on mouse-patch [die]] [ask mouse-patch [sprout-sinks 1 []]] wait 0.1 ] ] end to edit-speed-limit ; Always show speed limit ask roads [set plabel int (speed-limit * 3.6)] ; Convert m/s to km/h if mouse-down? [ ; Store patch under cursor in local variable let mouse-patch patch-at mouse-xcor mouse-ycor ; Set speed limit in meters per second. set speed-limit-of mouse-patch SPEED_LIMIT * 1000 / (60 * 60) ] end to edit-road-directions ; Always show directions ask roads [set plabel list-to-string directions] if mouse-down? [ ; Store patch under cursor in local variable let mouse-patch patch-at mouse-xcor mouse-ycor ; If clicking on a road, set it's directions. if road?-of mouse-patch [ ; Add or remove chosen direction from list of possible directions. if ROAD_DIRECTION = "North" [ask mouse-patch [edit-road-directions-list "N"]] if ROAD_DIRECTION = "East" [ask mouse-patch [edit-road-directions-list "E"]] if ROAD_DIRECTION = "South" [ask mouse-patch [edit-road-directions-list "S"]] if ROAD_DIRECTION = "West" [ask mouse-patch [edit-road-directions-list "W"]] if ROAD_DIRECTION = "Clear" [ask mouse-patch [set directions []]] ] ] end to edit-road-directions-list [direct] ; If selected direction is already in the list... ifelse member? direct directions [];set directions sort remove direct directions] ; Remove selected direction. [ let new-directions sort fput direct directions ; union existing list set directions new-directions ; Ask all patches with same directions in the same line to add the new direction. ; ifelse direct = "N" or direct = "S" [ ; ask roads with [pxcor = pxcor-of myself and directions = directions-of myself] ; [set directions new-directions] ; ] [ ; ask roads with [pycor = pycor-of myself and directions = directions-of myself] ; [set directions new-directions] ; ] ] ; Add selected direction. ; wait 0.1 ; So patches dont get swapped back and forth too quickly end to load-model let filename user-choose-file if (filename != false) [ import-world filename ] end to save-model let filename user-choose-new-file if (filename != false) [ export-world filename ] end to clear-model set-default-shape vehicles "car top" set-default-shape sources "circle" set-default-shape sinks "target" set-default-shape counters "flow counter" set PATCH_LENGTH 7.5 ; meters ask turtles [die] ask patches [ set directions [] set pcolor green - 2.5 set plabel "" set speed-limit 0 ; no limit set road? false set hov? false ] set roads patches with [road?] ; Re-evaluate road set (will be empty) setup ; Set all per-run variables to default. end ;;;;;;;;;;;;;;;;;;; ;;;; VARIABLES ;;;;;;;;;;;;;;;;;;; breed [vehicles vehicle] breed [lights light] breed [sources source] breed [sinks sink] breed [counters counter] globals [ PATCH_LENGTH ; usually 7.5m as per standard CA traffic simulation. SIMULATED_TIME ; Current simulation time elapsed in seconds. Speed depends on time slice. REAL_TIME_DIFF ; Number of simulation seconds per realtime second. Used for real-time switch. REAL_TIME_RATIO ; To show speed ratio FLOW_COUNTER ; Total number of vehicles to cross flow points. LAST_PLOT_TIME ; Simulated time of last plot. So we dont plot many times per simulated second. ALL_LANE_CHANGE ; Sim time of last global lane change, do it once a simulated second roads ; Agentset of all road patches. equivalent to "patches with [road?]" VEHICLES_EXITED ; For AVO calculation. PEOPLE_EXITED ; For AVO calculation. ] patches-own [ road? ; Is this patch a road? directions ; List of strings N/E/S/W - which direction(s) can be taken from this patch? speed-limit ; in m/s, 0 = no limit. hov? ; Boolean, true = only cars with 2+ people can use the road. ] vehicles-own [ LAST_PLOT_X ; So we can detect when plot wraps. LAST_TURN_PATCH ; So we only evaluate turning once per patch. LAST_LANE_CHANGE ; So we dont change lanes too often. TIME_ENTERED ; to calculate journey time. speed ; Current speed. In meters per second. (m/s) Patch = 7.5m desired-speed ; Driver's desired speed m/s (always try to reach and maintain this) max-speed ; Vehicles maximum speed m/s max-acceleration ; Max difference in speed per tick when accelerating m/sē max-deceleration ; Max difference in speed per tick when decelerating m/sē passengers ; Number of people in the vehicle. ] lights-own [ green-time-h ; How many simulated seconds to stay green for horizontal direction. green-time-v ; same for vertical yellow-time ; How many simulated seconds to stay yellow after green. event-time ; What simulation time does the light next need to change state? ] sources-own [ influx-every ; How often in simulated seconds to create new vehicles last-influx ; Simulated time of last vehicle creation ] counters-own [ last-vehicle ; The latest vehicle to go over this counter for flow calculations. ] ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;; INITIALIALISATION ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; stuff that only needs to run once. allows it to be saved into model file if changed. to startup clear-model ; move some setup stuff around. loop [ every 1 [ ask roads [set plabel ""] ] ] end ;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;; SETUP ;;;;;;;;;;;;;;;;;;;;; ; Do everything required to reset a simulation run. to setup ask lights [set event-time event-time - int SIMULATED_TIME] ; stay in current sync set SIMULATED_TIME 0 set LAST_PLOT_TIME 0 ; So it doesn't plot flow 0 after reset set FLOW_COUNTER 0 set REAL_TIME_DIFF -1 ; HACK to stop the flow plotter from crashing when div by 0 set REAL_TIME_RATIO 1 ; No way to know how fast it will run. Guess in real time. set VEHICLES_EXITED 0 set PEOPLE_EXITED 0 ask vehicles [set LAST_LANE_CHANGE 0] ; No car has ever changed lanes init-timespace ; Clear and Reset time-space plot ; Clear and reset basic plots set-current-plot "Journey Times" clear-plot set-current-plot "AVO" clear-plot end ; Kill all vehicles, then make new ones on random roads. to regenerate-vehicles if count roads < NUMBER_OF_VEHICLES [ user-message "There are not enough roads for that number of vehicles. Setup will halt." stop ] ask vehicles [die] repeat NUMBER_OF_VEHICLES [ ask one-of roads with [count vehicles-here = 0] [ sprout-vehicles 1 [ init-vehicle ] ] ] end ; Run when every new vehicle agent is born to init-vehicle let road-heading "E" if not empty? directions [set road-heading one-of directions] ; pick a direction in which road goes. ; Default is East incase of no directions (eg blank world) set heading heading-from-direction road-heading set speed 0 ; All cars start "stopped" set max-speed (20 + random 20) ; 60 mph = 26.8 m/s. 100 mph = 44.7 m/s. set max-acceleration 2 + random 2 ; Slow cars 0-60 in 13secs (2 m/sē), fast cars 7secs (4 m/sē) set max-deceleration 5 + random 3 ; Braking power 5 m/sē to 8 m/sē. ifelse random 100 < %_HOV [ ; Make 2+ cars with %_HOV probability set passengers 2 + random 4 ; Cars have 2 to 5 passengers. Maybe higher would make up for buses? set color red ] [ set passengers 1 set color blue ] set LAST_PLOT_X 0 set LAST_TURN_PATCH nobody ; HACK - Only set time entered for cars entering from the ring road. set TIME_ENTERED SIMULATED_TIME ; Make a note of what time I entered... end ; Run when each traffic light agent is born. to init-lights [h v] set shape "Traffic Light" set heading 90 ; Greens start on North-south link (V) set color green ; Green or yellow set green-time-h h ; green time for east-west link set green-time-v v ; and for north-south link. set yellow-time 3 set event-time int SIMULATED_TIME + green-time-v end to init-counter if not empty? directions [ set heading heading-from-direction one-of directions ] end to init-timespace set-current-plot "Time-Space" clear-plot set-plot-x-range min-pxcor - 0.5 max-pxcor + 0.5 ; So autoplot doesnt adjust when points go out ask vehicles [ create-temporary-plot-pen (word who) ] end ;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;; RUNTIME PROCS ;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Runs one time-step of simulation. I believe the order of calls is important. to go no-display ; Don't update visualisation until all objects updated. if PLOT_TIMESPACE? [ ; Save some cycles if we dont want them measure-timespace ; update the time-space data and graph ] measure-flow ; update flow-density data and graph update-lights ; Change traffic lights when they time out if SOURCES_ACTIVE? [ process-sources ; Add cars if required from sources ] update-vehicles ; move all vehicles process-sinks ; Remove cars which are on a sink update-time ; must be last (or first i suppose) display ; Update the visualisation now. end to measure-timespace set-current-plot "Time-Space" ask vehicles [ create-temporary-plot-pen (word who) ; Creates if it doesnt exist, uses if it does ; Cars in a queue show up red! ifelse speed = 0 [set-plot-pen-color red] [set-plot-pen-color black] ; This means no horizontal lines when plotting from xmax to xmin. Only for EASTBOUND cars! ifelse LAST_PLOT_X > xcor [ plot-pen-up plotxy xcor SIMULATED_TIME plot-pen-down ] [ plotxy xcor SIMULATED_TIME ] set LAST_PLOT_X xcor ] end ; Ask sinks to remove any vehicles on them to process-sinks ask sinks [ ask vehicles-here [ ; Draw on the journey times chart set-current-plot "Journey Times" ifelse passengers > 1 [set-current-plot-pen "hov"] [set-current-plot-pen "car"] plotxy SIMULATED_TIME SIMULATED_TIME - TIME_ENTERED die ] ] end ; Ask sources to make new vehicle as often as they are set to. to process-sources ask sources [ if (int SIMULATED_TIME != last-influx) and (int SIMULATED_TIME mod influx-every = 0) [ set last-influx int SIMULATED_TIME ; Dont create new vehicles on top of queuing ones if not any? vehicles-here [ ask patch-here [ sprout-vehicles 1 [ init-vehicle let vehicle-infront min-one-of vehicles with [self != myself] in-cone 20 0 [distance myself] ifelse vehicle-infront != nobody [ set speed speed-of vehicle-infront ] [ set speed min list max-speed speed-limit ] ] ] ] ] ] end to update-lights every 1 [ask lights [set label event-time - int SIMULATED_TIME]] ask lights [ ; A light change is scheduled... if int SIMULATED_TIME = event-time [ ifelse color = yellow [ set color green rt 90 ifelse heading = 0 or heading = 180 [ set event-time int SIMULATED_TIME + green-time-h ] [ set event-time int SIMULATED_TIME + green-time-v ] ] ; Else, need to go yellow. [ set color yellow set event-time int SIMULATED_TIME + yellow-time ] ] ] end to measure-flow if any? counters [ ; Ask all flow counters to check if a new vehicle is on them. Doesn't work with 1 vehicle. ask counters [ if any? vehicles-here with [who != last-vehicle-of myself] [ set last-vehicle who-of one-of vehicles-here ; Flow stuff set FLOW_COUNTER FLOW_COUNTER + 1 set VEHICLES_EXITED VEHICLES_EXITED + 1 ; AVO stuff set PEOPLE_EXITED PEOPLE_EXITED + passengers-of one-of vehicles-here ] ] ; Plot flow and density, and AVO once per simulated minute. if (int SIMULATED_TIME != LAST_PLOT_TIME) and (int SIMULATED_TIME mod FLOW_PLOT_PERIOD = 0) [ ; FLOW STUFF set LAST_PLOT_TIME int SIMULATED_TIME ; So we don't plot again this second. let density (count vehicles / count roads * 100) let flow FLOW_COUNTER * 60 * (60 / FLOW_PLOT_PERIOD) / count counters set FLOW_COUNTER 0 set-current-plot "Flow-Density" plotxy density flow ; AVO STUFF if VEHICLES_EXITED > 0 [ set-current-plot "AVO" plotxy SIMULATED_TIME PEOPLE_EXITED / VEHICLES_EXITED set PEOPLE_EXITED 0 set VEHICLES_EXITED 0 ] ] ] end ; Update the position and variables for all vehicles. to update-vehicles ask vehicles [ vehicle-turn-behaviour ; Processes changes of direction. Must do before lane change, or vehicle looks at directions wrong. ] ; Lane changing and turning is completed before any vehicles decide speed or move. ; Check all vehicles for lane change worthiness every 1 sim second. if int SIMULATED_TIME != ALL_LANE_CHANGE [ set ALL_LANE_CHANGE int SIMULATED_TIME ; So we don't change lanes again this second. ask vehicles [ if SIMULATED_TIME > LAST_LANE_CHANGE + 5 [ ; Dont change lanes except every 5 seconds without-interruption [lane-changing] ; Make sure other vehicles dont see u fake changing ] ] ] ; Vehicles decide their desired speed based on the environment. ask vehicles [ ; Run the vehicle following scheme. This sets the driver's desired speed. simple-vehicle-following ; Vehicle-following scheme can be overriden by traffic light behaviour. traffic-light-behaviour ] ; Ensure all vehicles have decided before any vehicle moves position. ask vehicles [ move-vehicle ; Update vehicle speed and position based on desired-speed ] end to move-vehicle ; Change vehicle speed if it is not equal to max "possible" speed if speed != min list desired-speed max-speed [ ; Need to go faster = first block ifelse (speed < desired-speed) [ set speed speed + (max-acceleration * TIME_SLICE) if speed > desired-speed [set speed desired-speed] ; Restrict to desired speed if speed > max-speed [set speed max-speed] ; Restrict by maximum vehicle speed. ] [ ; need to slow down set speed speed - (max-deceleration * TIME_SLICE) if speed < desired-speed [set speed desired-speed] ] ] ; Move the amount you would move in a single time-slice, in patches not meters. fd speed * TIME_SLICE / PATCH_LENGTH end to vehicle-turn-behaviour ; Should check if we're going too fast to make a turn...... ; If this road has directions set, and it hasn't been evaluated yet for this vehicle... if not empty? directions and patch-here != LAST_TURN_PATCH [ let my-dir direction-from-heading heading ; If the road has turned, pick one of the new directions at random. ifelse not member? my-dir directions [ set heading heading-from-direction one-of directions setxy pxcor pycor ; Bit of inaccuracy here. should go back however much were onto patch. ; This is a hack because we can't see round corners. If a car is now ahead, slow to match its speed. let new-leader min-one-of vehicles with [self != myself] in-cone (stopping-distance + 1) 0 [distance myself] if new-leader != nobody [ set speed speed-of new-leader ] ] [ ; If the road has other directions, change direction with a 1 in 5 chance. if length directions > 1 and random 5 = 0 [ ; Pick a new direction to think about let old-heading heading set heading heading-from-direction one-of remove my-dir directions ; Check if you're in the right lane to make this turn; Does next patch go in my old direction? If so, wrong lane! ifelse member? my-dir directions-of patch-ahead 1 [ set heading old-heading ] [ ; Move to center of patch to check for vehicles in-cone (else only works when close to center) let oldx xcor let oldy ycor setxy pxcor pycor ; If theres a car too close to stop for, dont turn. i.e. change back heading and position. ifelse any? vehicles in-cone (stopping-distance + 1) 5 with [self != myself] [ set heading old-heading setxy oldx oldy ] [ set LAST_LANE_CHANGE SIMULATED_TIME ; Treat as a lane change - dont want to change lanes straight after turn. ] ] ; right lane? ] ; other directions? ] ; if not forced to turn ; Remember the patch that we just evaluated so we don't do it again just yet. set LAST_TURN_PATCH patch-here ] end to lane-changing ; Only think about changing lanes if the current road only has one direction if length directions = 1 [ ; Remember the current vehicle ahead of you, if they are imminent to slowing you down let old-leader min-one-of vehicles with [self != myself] in-cone (stopping-distance + 2) 0 [distance myself] ; INCENTIVE: Boolean whether or not current lane is free i.e. no slower cars close ahead let straight-free old-leader = nobody or (speed-of old-leader > speed) ; Incentive: If you're on the HOV but you don't have 2+. could factor 90% dont break rule. let must-change (hov? and passengers < 2) ; If no leader, or the leader isnt slowing you down, think about moving left. if straight-free [ lane-change-left ] if not straight-free or must-change [ ; Your leader is slowing you down. Consider moving right. lane-change-right ] ] end to lane-change-left ; If there is a lane to the left if directions = directions-of patch-left-and-ahead 90 1 [ lt 90 jump 1 lt 90 jump -1 ; Move to it, face backwards so you can look over where u would be placed ; safe distance between cars, Assuming we're going faster than them. let new-follower min-one-of vehicles with [self != myself] in-cone 3 0 [distance myself] ; If no vehicle behind, back safety OK. ifelse new-follower = nobody and (not hov? or passengers > 1) [ jump 1 lt 180 ; face forward let new-leader min-one-of vehicles with [self != myself] in-cone (stopping-distance + 1) 0 [distance myself] ; Finally, if the new leader (within stopping distance) is going slower than you then ABORT. ifelse new-leader != nobody and speed-of new-leader < speed [ rt 90 jump 1 lt 90 ; move back ] [ set LAST_LANE_CHANGE SIMULATED_TIME ; Lane change complete! ] ] [ ; not safe because of vehicles behind. jump 1 lt 90 jump 1 lt 90 ; move back ] ] end to lane-change-right ; If there is a lane to the right - logistics. if directions = directions-of patch-right-and-ahead 90 1 [ rt 90 jump 1 rt 90 jump -1 ; Move to it, face backwards so you can look over where u would be placed ; Follower, if they are potentially too close to stop. 10 = max stopping distance, actually ~20 patches. let new-follower min-one-of vehicles with [self != myself and stopping-distance + 2 > distance myself] in-cone 10 0 [distance myself] ; If no vehicle close behind, or they are going slower than you, consider moving right. ifelse new-follower = nobody or (speed-of new-follower < speed and distance new-follower > 2) [ jump 1 lt 180 ; face forward let new-leader min-one-of vehicles with [self != myself] in-cone (stopping-distance + 1) 0 [distance myself] ; Finally, if the new leader (within stopping distance) is going slower than you then ABORT. ifelse new-leader != nobody and (speed-of new-leader < speed) [ lt 90 jump 1 rt 90 ; move back ] [ set LAST_LANE_CHANGE SIMULATED_TIME ; Lane change complete! ] ] [ ; Not safe because of vehicles behind. jump 1 rt 90 jump 1 rt 90 ; move back ] ] end ; Simple car following rule - If vehicles within stopping distance, slow down. Else speed up. to simple-vehicle-following ; Agentset of all vehicles within my stopping distance in front (+ 1 car's space) let vehicles-infront (vehicles-on patches in-cone (stopping-distance + 1) 0) ; let vehicles-infront vehicles in-cone (stopping-distance + 1 + random 1) 0 ; Apply vehicle following rule to desired-speed. ifelse any? vehicles-infront with [self != myself] ; Any cars infront? excluding myself [set desired-speed 0] [ifelse speed-limit = 0 [set desired-speed max-speed] [set desired-speed speed-limit]] end to traffic-light-behaviour ; Ignore the lights if you are already on them (or adjacent ones) if not any? lights-here [ ; All lights within stopping distance. Ignore those you're going too fast to stop for. let lights-infront lights in-cone (stopping-distance + 1) 0 with [distance myself > value-from myself [stopping-distance]] ; If any lights infront which are red in my direction, stop! ifelse any? lights-infront with [member? subtract-headings heading heading-of myself list 0 180] [set desired-speed 0] ; Else could still be yellow/green lights infront. if yellow stop too. [if any? lights-infront with [color = yellow] [set desired-speed 0]] ] end ; Stopping distance in meters. Turn into vehicle attribute if used more than once! to-report stopping-distance report ((speed ^ 2) / (2 * max-deceleration)) / PATCH_LENGTH end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;; SIMULATION TIME MANAGEMENT ;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Update the current simulation time. Called every tick. to update-time ; Auto-adjust the time slice so the simulation runs in real time. every 1 [ set REAL_TIME_RATIO SIMULATED_TIME - REAL_TIME_DIFF ; set-current-plot "Simulation Speed" ; plotxy count vehicles REAL_TIME_RATIO if REAL_TIME? [ set TIME_SLICE TIME_SLICE / REAL_TIME_RATIO ] set REAL_TIME_DIFF SIMULATED_TIME ] ; Update simulation time by the time slice value. set SIMULATED_TIME SIMULATED_TIME + TIME_SLICE end ; Reports a string in the form "X hours X mins X secs" representing current simulation time. to-report readable-time-string let calc-mins int (SIMULATED_TIME / 60) let hrs int (calc-mins / 60) let secs int (SIMULATED_TIME - (calc-mins * 60)) let mins int (calc-mins - (hrs * 60)) report hrs + " hours " + mins + " mins " + secs + " secs" end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;; HELPER FUNCTIONS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Report the heading that corresponds to the NESW direction (string) to-report heading-from-direction [dir] if dir = "N" [report 0] if dir = "E" [report 90] if dir = "S" [report 180] if dir = "W" [report 270] report false end ; Report the direction (NESW) that corresponds to the heading number. to-report direction-from-heading [head] if head = 0 [report "N"] if head = 90 [report "E"] if head = 180 [report "S"] if head = 270 [report "W"] report false end to-report list-to-string [l] let s "" foreach l [ set s (s + ?) ] report s end @#$#@#$#@ GRAPHICS-WINDOW 228 292 976 521 20 5 18.0 1 10 1 1 1 0 1 0 1 -20 20 -5 5 CC-WINDOW 5 625 2087 720 Command Center 0 TEXTBOX 107 10 233 28 Model Editing Tools CHOOSER 18 115 120 160 EDIT_TOOL EDIT_TOOL "Road" "HOV Road" "Grass" "Car" "Flow Counter" "Traffic Lights" "Source" "Sink" 0 BUTTON 123 123 186 156 Apply edit-world T 1 T OBSERVER T A BUTTON 18 77 91 110 New Model clear-model NIL 1 T OBSERVER T NIL SLIDER 280 32 454 65 NUMBER_OF_VEHICLES NUMBER_OF_VEHICLES 0 150 10 1 1 NIL BUTTON 296 199 351 232 Setup setup NIL 1 T OBSERVER T S BUTTON 357 199 412 232 Go go T 1 T OBSERVER NIL G SLIDER 547 32 783 65 TIME_SLICE TIME_SLICE 0.01 0.5 0.2 0.01 1 seconds MONITOR 558 212 690 261 Simulation Time readable-time-string 3 1 BUTTON 664 157 719 190 3D cars set-default-shape vehicles "car"\nask vehicles [set shape "car"] NIL 1 T OBSERVER T NIL BUTTON 597 157 652 190 2D cars set-default-shape vehicles "car top"\nask vehicles [set shape "car top"] NIL 1 T OBSERVER T NIL TEXTBOX 305 10 456 28 Regenerate-Vehicles Settings TEXTBOX 615 10 739 28 Runtime Parameters SWITCH 659 75 799 108 PLOT_TIMESPACE? PLOT_TIMESPACE? 0 1 -1000 SWITCH 548 74 654 107 REAL_TIME? REAL_TIME? 1 1 -1000 PLOT 934 19 1322 241 Flow-Density Density (% occupied) Flow (veh/hr/lane) 0.0 100.0 0.0 2100.0 true false PENS "default" 1.0 2 -16777216 true MONITOR 818 65 913 114 Flow Counter FLOW_COUNTER 3 1 CHOOSER 18 165 120 210 ROAD_DIRECTION ROAD_DIRECTION "North" "East" "South" "West" "Clear" 1 BUTTON 123 172 186 205 Apply edit-road-directions T 1 T OBSERVER T NIL MONITOR 698 212 764 261 x Realtime REAL_TIME_RATIO 2 1 BUTTON 92 263 187 296 Clear labels ask patches [set plabel ""] NIL 1 T OBSERVER T NIL SLIDER 18 216 120 249 SPEED_LIMIT SPEED_LIMIT 0 120 10 10 1 km/h BUTTON 123 216 186 249 Apply edit-speed-limit T 1 T OBSERVER T NIL TEXTBOX 3 87 18 105 1. TEXTBOX 3 133 18 151 2. TEXTBOX 3 180 18 198 3. BUTTON 460 32 515 106 Regen regenerate-vehicles NIL 1 T OBSERVER T NIL PLOT 4 307 212 611 Time-Space Space -> Time -> 0.0 0.0 0.0 0.0 true false PENS "default" 1.0 0 -7500403 true TEXTBOX 3 225 18 243 4. CHOOSER 18 26 183 71 EXISTING_MODELS EXISTING_MODELS "T1.csv" "T2.csv" "T3.csv" "T4.csv" "T5.csv" "T6.csv" "T7.csv" "T8.csv" 0 BUTTON 186 31 241 64 Load import-world EXISTING_MODELS NIL 1 T OBSERVER T NIL BUTTON 417 199 472 232 Step go NIL 1 T OBSERVER T P SLIDER 280 73 454 106 %_HOV %_HOV 0 100 0 1 1 NIL TEXTBOX 334 176 441 194 Simulation Controls BUTTON 32 263 87 296 Show ask patches with [pxcor mod 5 = 0 and pycor mod 5 = 0] [set plabel pxcor + "," + pycor] NIL 1 T OBSERVER T NIL TEXTBOX 3 274 31 292 Grid: MONITOR 820 122 912 171 Vehicle Count count vehicles 3 1 PLOT 1331 17 1718 243 Journey Times Elapsed Secs Journey Secs 0.0 10.0 0.0 10.0 true true PENS "car" 1.0 2 -16777216 true "hov" 1.0 2 -2674135 true PLOT 1731 14 2078 258 AVO Elapsed Secs AVO 0.0 10.0 0.0 2.0 true false BUTTON 818 23 914 57 Clear Flow-D set-current-plot "Flow-Density"\nclear-plot NIL 1 T OBSERVER T NIL SWITCH 280 113 425 146 SOURCES_ACTIVE? SOURCES_ACTIVE? 0 1 -1000 BUTTON 562 115 654 148 Increase Vehicles let veh1 max-one-of vehicles [distance min-one-of vehicles with [self != myself] in-cone 50 0 [distance myself]] \nask veh1 [\nlet vehP min-one-of vehicles with [self != myself] in-cone 50 0 [distance myself]\nask vehP [\nask patch-at -1 0 [\nsprout-vehicles 1 [\ninit-vehicle\nset speed speed-of min-one-of vehicles with [self != myself] in-cone 20 0 [distance myself] \n]\n]\n]\n]\n\n NIL 1 T OBSERVER T NIL SLIDER 1021 251 1239 284 FLOW_PLOT_PERIOD FLOW_PLOT_PERIOD 10 300 60 5 1 seconds BUTTON 662 115 759 148 Decrease Vehicles ask one-of vehicles with [speed > 0] [die] NIL 1 T OBSERVER T NIL @#$#@#$#@ WHAT IS IT? ----------- This section could give a general understanding of what the model is trying to show or explain. HOW IT WORKS ------------ This section could explain what rules the agents use to create the overall behavior of the model. HOW TO USE IT ------------- This section could explain how to use the model, including a description of each of the items in the interface tab. THINGS TO NOTICE ---------------- This section could give some ideas of things for the user to notice while running the model. THINGS TO TRY ------------- This section could give some ideas of things for the user to try to do (move sliders, switches, etc.) with the model. EXTENDING THE MODEL ------------------- This section could give some ideas of things to add or change in the procedures tab to make the model more complicated, detailed, accurate, etc. NETLOGO FEATURES ---------------- This section could point out any especially interesting or unusual features of NetLogo that the model makes use of, particularly in the Procedures tab. It might also point out places where workarounds were needed because of missing features. RELATED MODELS -------------- This section could give the names of models in the NetLogo Models Library or elsewhere which are of related interest. CREDITS AND REFERENCES ---------------------- This section could contain a reference to the model's URL on the web if it has one, as well as any other necessary credits or references. @#$#@#$#@ 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 top true 0 Polygon -7500403 true true 151 8 119 10 98 25 86 48 82 225 90 270 105 289 150 294 195 291 210 270 219 225 214 47 201 24 181 11 Polygon -16777216 true false 210 195 195 210 195 135 210 105 Polygon -16777216 true false 105 255 120 270 180 270 195 255 195 225 105 225 Polygon -16777216 true false 90 195 105 210 105 135 90 105 Polygon -1 true false 205 29 180 30 181 11 Line -7500403 false 210 165 195 165 Line -7500403 false 90 165 105 165 Polygon -16777216 true false 121 135 180 134 204 97 182 89 153 85 120 89 98 97 Line -16777216 false 210 90 195 30 Line -16777216 false 90 90 105 30 Polygon -1 true false 95 29 120 30 119 11 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 false 0 Circle -7500403 true true 0 0 300 dot false 0 Circle -7500403 true true 90 90 120 face happy false 0 Circle -7500403 true true 8 8 285 Circle -16777216 true false 60 75 60 Circle -16777216 true false 180 75 60 Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240 face neutral false 0 Circle -7500403 true true 8 7 285 Circle -16777216 true false 60 75 60 Circle -16777216 true false 180 75 60 Rectangle -16777216 true false 60 195 240 225 face sad false 0 Circle -7500403 true true 8 8 285 Circle -16777216 true false 60 75 60 Circle -16777216 true false 180 75 60 Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183 fish false 0 Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166 Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165 Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60 Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166 Circle -16777216 true false 215 106 30 flag false 0 Rectangle -7500403 true true 60 15 75 300 Polygon -7500403 true true 90 150 270 90 90 30 Line -7500403 true 75 135 90 135 Line -7500403 true 75 45 90 45 flow counter true 0 Rectangle -1184463 true false 30 135 270 165 Polygon -1184463 true false 30 165 0 195 0 105 30 135 Polygon -1184463 true false 270 165 300 195 300 105 270 135 flower false 0 Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135 Circle -7500403 true true 85 132 38 Circle -7500403 true true 130 147 38 Circle -7500403 true true 192 85 38 Circle -7500403 true true 85 40 38 Circle -7500403 true true 177 40 38 Circle -7500403 true true 177 132 38 Circle -7500403 true true 70 85 38 Circle -7500403 true true 130 25 38 Circle -7500403 true true 96 51 108 Circle -16777216 true false 113 68 74 Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218 Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240 house false 0 Rectangle -7500403 true true 45 120 255 285 Rectangle -16777216 true false 120 210 180 285 Polygon -7500403 true true 15 120 150 15 285 120 Line -16777216 false 30 120 270 120 leaf false 0 Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195 Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195 line true 0 Line -7500403 true 150 0 150 300 line half true 0 Line -7500403 true 150 0 150 150 link true 0 Line -7500403 true 150 0 150 300 pentagon false 0 Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120 person false 0 Circle -7500403 true true 110 5 80 Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90 Rectangle -7500403 true true 127 79 172 94 Polygon -7500403 true true 195 90 240 150 225 180 165 105 Polygon -7500403 true true 105 90 60 150 75 180 135 105 plant false 0 Rectangle -7500403 true true 135 90 165 300 Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285 Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285 Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210 Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135 Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135 Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60 Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90 square false 0 Rectangle -7500403 true true 30 30 270 270 square 2 false 0 Rectangle -7500403 true true 30 30 270 270 Rectangle -16777216 true false 60 60 240 240 star false 0 Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108 target false 0 Circle -7500403 true true 0 0 300 Circle -16777216 true false 30 30 240 Circle -7500403 true true 60 60 180 Circle -16777216 true false 90 90 120 Circle -7500403 true true 120 120 60 traffic light true 6 Circle -2674135 true false 14 225 62 Circle -2674135 true false 224 15 62 Circle -13840069 true true 14 15 62 Circle -13840069 true true 224 225 62 tree false 0 Circle -7500403 true true 118 3 94 Rectangle -6459832 true false 120 195 180 300 Circle -7500403 true true 65 21 108 Circle -7500403 true true 116 41 127 Circle -7500403 true true 45 90 120 Circle -7500403 true true 104 74 152 triangle false 0 Polygon -7500403 true true 150 30 15 255 285 255 triangle 2 false 0 Polygon -7500403 true true 150 30 15 255 285 255 Polygon -16777216 true false 151 99 225 223 75 224 truck false 0 Rectangle -7500403 true true 4 45 195 187 Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194 Rectangle -1 true false 195 60 195 105 Polygon -16777216 true false 238 112 252 141 219 141 218 112 Circle -16777216 true false 234 174 42 Rectangle -7500403 true true 181 185 214 194 Circle -16777216 true false 144 174 42 Circle -16777216 true false 24 174 42 Circle -7500403 false true 24 174 42 Circle -7500403 false true 144 174 42 Circle -7500403 false true 234 174 42 turtle true 0 Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210 Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105 Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105 Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87 Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210 Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99 wheel false 0 Circle -7500403 true true 3 3 294 Circle -16777216 true false 30 30 240 Line -7500403 true 150 285 150 15 Line -7500403 true 15 150 285 150 Circle -7500403 true true 120 120 60 Line -7500403 true 216 40 79 269 Line -7500403 true 40 84 269 221 Line -7500403 true 40 216 269 79 Line -7500403 true 84 40 221 269 x false 0 Polygon -7500403 true true 270 75 225 30 30 225 75 270 Polygon -7500403 true true 30 75 75 30 270 225 225 270 @#$#@#$#@ NetLogo 3.1beta1 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ regenerate-vehicles setup go SIMULATED_TIME > 121 @#$#@#$#@