;global variables globals [ clock ;time steps cars-size ;the size (height as well as width) of the vehicles lane-width ;the width of the lanes speed-limit ;speed limit for the vehicles total-finished-cars ;number of cars that have finished their trip total-cars ;number of cars that have been spawned (finished and unfinished) active-cars ;number of cars that are still traveling maximum-delay ;the max value that a car has been delayed expected-maximum-delay ;the expected value for maximum-delay total-delay ;the sum of the delays of all the cars that have finished their trip expected-average-delay ;the expected value for the average delay tiles ;a matrix representing the tiles in the intersection when using Reservation System model tile-width ;the width of the tiles in the intersection when using Reservation System model tile-height ;the height of the tiles in the intersection when using Reservation System model green-breed ;the turtle breed that has the green light (north, east, or none) second ;Is 1 / ticks-by-second ;;Patches working as lights north-ligths east-lights west-lights south-ligths ;;They are some list used in the experiment 3 list-Period10 list-Period30 list-Period50 list-reservation ] turtles-own [ speed max-speed delay acceleration acceleration-step deceleration-step ;speed and acceleration related variables reservation-made reservation-time reservation-xcor reservation-ycor reservation-speed ;reservation related variables reservation-tiles traveled-distance ;;The distance the car has traveled. ] breeds [ east west north south ] ;;;;;;;;;;;;;;;;;;;;;;; ;;SETUP PROCEDURES;; ;;;;;;;;;;;;;;;;;;;;;;; to setup ;;setup button ca start-variables end to start-variables ;;set global variables to their initial values set clock 0 set lane-width 4 set cars-size 4 set tile-width (lanes * 2 * lane-width) / granularity set tile-height tile-width set tiles n-values granularity [(list -1)] set tiles n-values granularity [tiles] set speed-limit 27 set total-delay 0 set total-cars 0 set active-cars 0 set maximum-delay 0 set second 1 / ticks-by-second set total-finished-cars 0 set expected-maximum-delay (1 - alpha) * period set expected-average-delay (1 / 2) * ((1 - alpha) ^ 2) * period draw-lanes let light-height lanes * lane-width set north-ligths patches with [ pxcor <= 0 and pxcor >= (- light-height) and pycor = light-height ] set east-lights patches with [ pxcor = (- light-height) and pycor <= 0 and pycor >= (- light-height) ] set west-lights patches with [ pxcor = light-height and pycor >= 0 and pycor <= light-height ] set south-ligths patches with [ pxcor >= 0 and pxcor <= light-height and pycor = (- light-height) ] if (model = "Trafic Light") [ draw-lights ifelse green-light north [set green-breed north] [ ifelse green-light east [set green-breed east] [set green-breed "none"] ] ] end to draw-lanes ;; draws the lanes ask patches [ set pcolor green - 1 if (abs pxcor <= lane-width * lanes or abs pycor <= lane-width * lanes) [ set pcolor black ] ] end to draw-lights ;; draws the lights in the intersection when using Traffic Light model let color-east-west black let color-north-south black ifelse green-light north [ set color-north-south green set color-east-west red ] [ ifelse green-light east [ set color-north-south red set color-east-west green ] [if green-light "none" [ set color-east-west red set color-north-south red ]] ] let light-height lanes * lane-width ask east-lights [set pcolor color-east-west] ;draw east light ask west-lights [set pcolor color-east-west] ;draw west light ask north-ligths [set pcolor color-north-south] ;draw north light ask south-ligths [set pcolor color-north-south] ;draw south light end to go ;;go button set second 1 / ticks-by-second without-interruption [ spawn-cars ;spawns new cars using the spawn probabilities move-cars ;move the cars, performs one time step set clock clock + 1 ;increases the time steps counter if (model = "Trafic Light") [ ; checks when lights have to be redrawn when using Trafic Light model if not green-light green-breed [ ifelse green-light north [set green-breed north] [ ifelse green-light east [set green-breed east] [set green-breed "none"] ] draw-lights ] ] if plotting [ do-plotting1] ] end to move-cars ;;move the cars, performs one time step ask turtles [ move ] end to spawn-cars ;;spawns new cars using the spawn probabilities ;spawn cars in east direction let ycor-east (- ((lane-width / 2) + ((random lanes) * lane-width))) if (random-float 100 < spawn-probability-E * 100) and not any? turtles-at (- screen-edge-x) ycor-east [ create-custom-east 1 [ set xcor (- screen-edge-x) set ycor ycor-east set heading 90 set-common-values ifelse not should-spawn [ die] [ set total-cars total-cars + 1 set active-cars active-cars + 1 ] ] ] ;spawn cars in west direction let ycor-west ((lane-width / 2) + ((random lanes) * lane-width)) if (random-float 100 < spawn-probability-W * 100) and not any? turtles-at (- screen-edge-x) ycor-west [ create-custom-west 1 [ set xcor (screen-edge-x) set ycor ycor-west set heading 270 set-common-values ifelse not should-spawn [ die] [ set total-cars total-cars + 1 set active-cars active-cars + 1 ] ] ] ;spawn cars in north direction let xcor-north ((lane-width / 2) + ((random lanes) * lane-width)) if (random-float 100 < spawn-probability-N * 100) and not any? turtles-at xcor-north (- screen-edge-y) [ create-custom-north 1 [ set xcor xcor-north set ycor (- screen-edge-y) set heading 0 set-common-values ifelse not should-spawn [ die] [ set total-cars total-cars + 1 set active-cars active-cars + 1 ] ] ] ;spawn cars in south direction let xcor-south (- ((lane-width / 2) + ((random lanes) * lane-width))) ;(- ((random lanes) + 1) * lane-width / 2) if (random-float 100 < spawn-probability-S * 100) and not any? turtles-at 0 (- screen-edge-y) [ create-custom-south 1 [ set xcor xcor-south set ycor (screen-edge-y) set heading 180 set-common-values ifelse not should-spawn [ die] [ set total-cars total-cars + 1 set active-cars active-cars + 1 ] ] ] end to-report should-spawn ;; reports true if the vehicle can be spawn without a collision danger (due to a vehicle ahead too close) ;; false otherwise report (not vehicle-ahead-too-close) end to set-common-values ;; set common values for turtles variables set shape "car" set color blue set size cars-size set max-speed 50 set delay 0 set speed min (list max-speed speed-limit) set acceleration 0 set acceleration-step 3 set deceleration-step 15 set reservation-made false set traveled-distance 0 end ;;;;;;;;;;;;;;;;;;;;;;; ;;TURTLES PROCEDURES;; ;;;;;;;;;;;;;;;;;;;;;;; to move ;;move the car one time step ;;behavior of the driver agent (steps in paper) coast if speed < speed-limit ;and green-light breed [accelerate] if vehicle-ahead-too-close [decelerate] if (model = "Trafic Light") or (model = "Reservation") [ interact-with-intersection ] interact-with-physics ;; sets delay value for the car set delay delay + (second - (speed * second) / min(list max-speed speed-limit)) ;; sets the speed for the vehicle, according to the acceleration value set in the steps above (behavior of the agent) let d1 speed + acceleration * second ifelse (d1 > max-speed) [ set speed max-speed ] [ ifelse(d1 < 0.0) [set speed 0.0] [set speed d1] ] ;; moves one secondth of second (1 second = tikcs-by-second timesteps) in the paper it is a 1/50 fd speed * second set traveled-distance traveled-distance + speed * second ;; checks for vehicles that have to be removed from the screen (finished) ;;if (breed = east and pxcor >= screen-edge-x) or (breed = west and pxcor <= (- screen-edge-x)) or (breed = north and pycor >= screen-edge-y) or (breed = south and pycor <= (- screen-edge-y)) if traveled-distance >= screen-size-x [ ;turtle have left the domain of the simulator set total-finished-cars total-finished-cars + 1 set active-cars active-cars - 1 set total-delay total-delay + delay if delay > maximum-delay [set maximum-delay delay] ;; kill the turtle die ] end to interact-with-intersection ;; interacts with intersection as specified for each control policy in section 5 of paper if speed > 0 [ if distance-to-intersection >= 0 [ ifelse (model = "Trafic Light") [ ;; Traffic Light model control policies ifelse (any? turtles-on patch-ahead (cars-size)) and (not green-light breed) ; [decelerate] [ ifelse (distance-to-intersection < cars-size) and (not green-light breed) [decelerate] [ if distance-to-intersection > 0 [ let d1 distance-to-intersection / speed let d2 next-green-period d1 let current-time (clock / (1 / second)) if d2 != current-time + d1 [ if distance-to-intersection <= speed * second + (speed * speed) / (deceleration-step) [decelerate] ] ] ]] ] [ ;; Reservation System model control policies ifelse (reservation-made) [ ifelse (can-keep-reservation) [ coast ] [ cancel-reservation make-reservation ] ] [ make-reservation ] ] ]] end to interact-with-physics ;; some needed rules if (speed = max-speed) and (acceleration > 0) [coast] if (speed = 0) and (acceleration < 0) [coast] if (speed > speed-limit) [decelerate] end to-report distance-to-intersection ;; reports the distance from this turtle to the beggining of the intersection let result 1000000 let intersection-width lanes * lane-width if breed = north [ set result distancexy xcor (- intersection-width) if ycor > (- intersection-width) [set result (- result)] ] if breed = south [ set result distancexy xcor intersection-width if ycor < intersection-width [set result (- result)] ] if breed = east [ set result distancexy (- intersection-width) ycor if xcor > (- intersection-width) [set result (- result)] ] if breed = west [ set result distancexy intersection-width ycor if xcor < intersection-width [set result (- result)] ] report result end to-report can-keep-reservation ;; reports true if the vehicle can keep the reservation it has already made ;; false otherwise let result false let d1 speed * second let d2 distance-to-intersection mod d1 let j distance-to-intersection / d1 let i j + clock let d speed let sigo true if (vehicle-ahead != nobody) [if (i <= reservation-time-of vehicle-ahead) [ set sigo false ]] if sigo [ ifelse (abs (d - reservation-speed) < 0.001) and (abs (i - reservation-time) < 1) [ set result true ] [ set result false ] ] report result end to cancel-reservation ;; called when the vehicle determined that it can not keep the reservation ;; cancels the reservation it has already made set reservation-made false foreach reservation-tiles [ ;; make the tiles in the intersection available at the times the vehicle had a reservation on them set tiles replace-item (item 0 ?) tiles (replace-item (item 1 ?) (item (item 0 ?) tiles) remove (item 2 ?) (item (item 1 ?) (item (item 0 ?) tiles))) ] end to make-reservation ;; reservation making process let vahead vehicle-ahead let sigo true if (vahead != nobody) [set sigo reservation-made-of vahead] if sigo [ ifelse (request-reservation) [ coast ] ;; if the proccess of requesting a reservation to the intersection is successful, the vehicle keep the same speed [ decelerate ] ;; otherwise, decelerate and it will try again at the next time step ] end to-report request-reservation ;; proccess of requesting a reservation to the intersection ;; reports true if a reservation can be made ;; false otherwise let result false let d1 speed * second let d2 distance-to-intersection mod d1 let steps-to-intersection floor (distance-to-intersection / d1) let i steps-to-intersection + clock let xpoint-before-reaching-intersection xcor let ypoint-before-reaching-intersection ycor if breed = north [ set ypoint-before-reaching-intersection (- (lanes * lane-width + d2)) ] if breed = east [ set xpoint-before-reaching-intersection (- (lanes * lane-width + d2)) ] if breed = south [ set ypoint-before-reaching-intersection lanes * lane-width + d2 ] if breed = west [ set xpoint-before-reaching-intersection lanes * lane-width + d2 ] let sigo true if (vehicle-ahead != nobody) [if (i <= reservation-time-of vehicle-ahead) [ set sigo false ]] if sigo [ let tiles-to-reserve intersection-is-free i speed xpoint-before-reaching-intersection ypoint-before-reaching-intersection ifelse empty? tiles-to-reserve [ ;; reservation cannot be made set result false ] [ ;; reservation can be made ;; sets the reservation variables of the turtle and makes the reservation of the tiles set reservation-time i set reservation-xcor xpoint-before-reaching-intersection set reservation-ycor ypoint-before-reaching-intersection set reservation-speed speed set reservation-made true set reservation-tiles tiles-to-reserve reserve tiles-to-reserve ;makes the reservation of the tiles set result true ] ] report result end to reserve [list-tiles-to-reserve] ;; reserves the tiles in the intersection at the time the vehicle will pass by them foreach list-tiles-to-reserve [ set tiles replace-item (item 0 ?) tiles (replace-item (item 1 ?) (item (item 0 ?) tiles) lput (item 2 ?) (item (item 1 ?) (item (item 0 ?) tiles))) ] end to-report vehicle-ahead ;; reports the vehicle ahead of the calling turtle let result 0 let turtles-ahead 0 let myxcor xcor let myycor ycor if breed = south [ set turtles-ahead turtles with [(xcor = myxcor) and (ycor < myycor)] set result max-one-of turtles-ahead [ycor] ] if breed = north [ set turtles-ahead turtles with [(xcor = myxcor) and (ycor > myycor)] set result min-one-of turtles-ahead [ycor] ] if breed = east [ set turtles-ahead turtles with [(ycor = myycor) and (xcor > myxcor)] set result min-one-of turtles-ahead [xcor] ] if breed = west [ set turtles-ahead turtles with [(ycor = myycor) and (xcor < myxcor)] set result max-one-of turtles-ahead [xcor] ] report result end to-report intersection-is-free [time d xpoint-before-reaching-intersection ypoint-before-reaching-intersection] ;; if the tiles in the intersection that need to be reserved by the calling vehicle are free ;; at the time the vehicle will cross them, this reporter reports a list containing ;; the tiles and times of reservation ;; it reports an empty list otherwise let result [] let free true let time-test time let x (- lanes * lane-width) ;xcor of top-left corner of intersection let y lanes * lane-width ;ycor of top-left corner of intersection if breed = north [ let xleft xpoint-before-reaching-intersection - cars-size / 2 let xright xpoint-before-reaching-intersection + cars-size / 2 let left-tile-number max (list 0 (floor ((xleft - x) / tile-width)) ) let right-tile-number min (list (granularity - 1) (floor ((xright - x) / tile-width)) ) let ytop 0 let ybottom 0 let top-tile-number 0 let bottom-tile-number 0 let counter1 0 let counter2 0 let yaux ypoint-before-reaching-intersection while [yaux - cars-size <= y] ;/ 2 [ set ytop yaux + cars-size / 2 set ybottom yaux - cars-size / 2 set top-tile-number max (list 0 floor ((y - ytop) / tile-height)) set bottom-tile-number min (list (granularity - 1) floor ((y - ybottom) / tile-height)) set counter1 top-tile-number repeat bottom-tile-number - top-tile-number + 1 [ set counter2 left-tile-number repeat right-tile-number - left-tile-number + 1 [ if (counter2 <= granularity - 1) and (counter1 <= granularity - 1) [ set result lput (list counter2 counter1 time-test) result if (reserved-tiles counter2 counter1 time-test) [set free false] ;; if there is a tile already reserved, the reservation cannot be made ] set counter2 counter2 + 1 ] set counter1 counter1 + 1 ] set yaux yaux + d * second set time-test time-test + 1 ] ] if breed = south [ let xleft xpoint-before-reaching-intersection - cars-size / 2 let xright xpoint-before-reaching-intersection + cars-size / 2 let left-tile-number max (list 0 (floor ((xleft - x) / tile-width)) ) let right-tile-number min (list (granularity - 1) (floor ((xright - x) / tile-width)) ) let ytop 0 let ybottom 0 let top-tile-number 0 let bottom-tile-number 0 let counter1 0 let counter2 0 let yaux ypoint-before-reaching-intersection while [yaux + cars-size >= y - (lanes * 2 * lane-width)] ;/ 2 [ set ytop yaux + cars-size / 2 set ybottom yaux - cars-size / 2 set top-tile-number max (list 0 floor ((y - ytop) / tile-height)) set bottom-tile-number min (list (granularity - 1) floor ((y - ybottom) / tile-height)) set counter1 top-tile-number repeat bottom-tile-number - top-tile-number + 1 [ set counter2 left-tile-number repeat right-tile-number - left-tile-number + 1 [ if (counter2 <= granularity - 1) and (counter1 <= granularity - 1) [ set result lput (list counter2 counter1 time-test) result if (reserved-tiles counter2 counter1 time-test) [set free false] ;; if there is a tile already reserved, the reservation cannot be made ] set counter2 counter2 + 1 ] set counter1 counter1 + 1 ] set yaux yaux - d * second set time-test time-test + 1 ] ] if breed = east [ let xaux xpoint-before-reaching-intersection let ytop ypoint-before-reaching-intersection + cars-size / 2 let ybottom ypoint-before-reaching-intersection - cars-size / 2 let top-tile-number max (list 0 floor ((y - ytop) / tile-height)) let bottom-tile-number min (list (granularity - 1) floor ((y - ybottom) / tile-height)) let xleft 0 let xright 0 let left-tile-number 0 let right-tile-number 0 let counter1 0 let counter2 0 while [xaux - cars-size <= x + lanes * 2 * lane-width] [ set xleft xaux - cars-size / 2 set xright xaux + cars-size / 2 set left-tile-number max (list 0 floor((xleft - x) / tile-width)) set right-tile-number min (list (granularity - 1) floor((xright - x) / tile-width)) set counter1 top-tile-number repeat bottom-tile-number - top-tile-number + 1 [ set counter2 left-tile-number repeat right-tile-number - left-tile-number + 1 [ if (counter2 <= granularity - 1) and (counter1 <= granularity - 1) [ set result lput (list counter2 counter1 time-test) result if (reserved-tiles counter2 counter1 time-test) [set free false] ;; if there is a tile already reserved, the reservation cannot be made ] set counter2 counter2 + 1 ] set counter1 counter1 + 1 ] set xaux xaux + d * second set time-test time-test + 1 ] ] if breed = west [ let xaux xpoint-before-reaching-intersection let ytop ypoint-before-reaching-intersection + cars-size / 2 let ybottom ypoint-before-reaching-intersection - cars-size / 2 let top-tile-number max (list 0 floor ((y - ytop) / tile-height)) let bottom-tile-number min (list (granularity - 1) floor ((y - ybottom) / tile-height)) let xleft 0 let xright 0 let left-tile-number 0 let right-tile-number 0 let counter1 0 let counter2 0 while [xaux + cars-size / 2 >= x] [ set xleft xaux - cars-size / 2 set xright xaux + cars-size / 2 set left-tile-number max (list 0 floor((xleft - x) / tile-width)) set right-tile-number min (list (granularity - 1) floor((xright - x) / tile-width)) set counter1 top-tile-number repeat bottom-tile-number - top-tile-number + 1 [ set counter2 left-tile-number repeat right-tile-number - left-tile-number + 1 [ if (counter2 <= granularity - 1) and (counter1 <= granularity - 1) [ set result lput (list counter2 counter1 time-test) result if (reserved-tiles counter2 counter1 time-test) [set free false] ;; if there is a tile already reserved, the reservation cannot be made ] set counter2 counter2 + 1 ] set counter1 counter1 + 1 ] set xaux xaux - d * second set time-test time-test + 1 ] ] if not free [set result []] report result end to-report reserved-tiles [x-num-tile y-num-tile time] ;; reports true if the tile (x-num-tile, y-num-tile) is reserved at the given time ;; false otherwise let times-reserved item y-num-tile (item x-num-tile tiles) report member? time times-reserved end to-report next-green-period [param1] ;; reports the next time step at which the light will be green for the caller turtle ;; param1 = distance-to-intersection / speed let result 100000000 let current-time (clock / (1 / second)) let d (current-time + param1) mod period ifelse (breed = north) or (breed = south) [ ifelse d < (alpha * period) [ set result current-time + param1 ] [ set result current-time + param1 + period - d ] ] [ ifelse (d >= ((alpha + beta) * period)) and (d < ((1.0 - beta) * period)) [ set result current-time + param1 ] [ ifelse (d < (alpha + beta) * period) [ set result current-time + param1 + ((alpha + beta) * period - d)] [ set result current-time + param1 + (period - d) + (alpha + beta) * period] ] ] report result end to-report green-light [turtle-breed] ;; reports true if the light is green for the "turtle-breed" direction ;; false otherwise let result false let current-time (clock / (1 / second)) let d current-time mod period ifelse (turtle-breed = north) or (turtle-breed = south) [set result (d < alpha * period)] [ ifelse (turtle-breed = east) or (turtle-breed = west) [set result ((d >= (alpha + beta) * period) and (d < (1.0 - beta) * period))] [if (turtle-breed = "none") [set result (not (d < alpha * period)) and (not ((d >= (alpha + beta) * period) and (d < (1.0 - beta) * period)))]] ] report result end to-report vehicle-ahead-too-close ;; reports true if the vehicle ahead of the caller if within "speed" distance (one second) ahead ;; false otherwise let result false let x 1 repeat speed [ if (any? turtles-on patch-ahead x) [set result true] set x x + 1 ] report result end to accelerate ;; set acceleration to the acceleration-step set acceleration acceleration-step end to coast ;; set acceleration to 0 set acceleration 0 end to decelerate ;; set acceleration to deceleration-step set acceleration (- 1 * deceleration-step) end ;;;;;;;;;;;;;;;;;;;;;;;;;; ;;EXPERIMENTS PROCEDURES;; ;;;;;;;;;;;;;;;;;;;;;;;;;; to experiment1 set lanes 1 set plotting false set model "Trafic Light" set period 10 set beta 0 set alpha 0.45 set spawn-probability-N .001 set spawn-probability-S .001 set spawn-probability-E 0 set spawn-probability-W 0 set ticks-by-second 50 setup set-current-plot "Figure a" set-plot-x-range 10 200 set-current-plot "Figure b" set-plot-x-range 10 200 while [period <= 200] [ start-variables ask turtles [die] while [clock <= 20000] [ go ] do-plotting set period period + 1 ] end to experiment2 set lanes 1 set plotting false set model "Trafic Light" set period 30 set beta 0 set alpha 0.1 set spawn-probability-N .001 set spawn-probability-S .001 set spawn-probability-E 0 set spawn-probability-W 0 set ticks-by-second 50 setup set-current-plot "Figure a" set-plot-x-range 0.10 .89 set-current-plot-pen "Theoretical" set-plot-pen-interval 0.1 set-current-plot-pen "Empirical" set-plot-pen-interval 0.1 set-current-plot "Figure b" set-plot-x-range 0.10 .89 set-current-plot-pen "Theoretical" set-plot-pen-interval 0.1 set-current-plot-pen "Empirical" set-plot-pen-interval 0.1 while [alpha <= .89] [ start-variables ask turtles [die] while [clock <= 20000] [ go ] do-plotting set alpha alpha + .1 ] end to experiment3 set lanes 1 set plotting false ;;Lists with the results of each experiment set model "Trafic Light" set period 10 set beta 0 set alpha 0.45 set spawn-probability-N .001 set spawn-probability-S .001 set spawn-probability-E 0 set spawn-probability-W 0 set ticks-by-second 50 setup set list-Period10 [] while [spawn-probability-N <= .02 ] [ start-variables ask turtles [die] while [clock <= 20000] [ go ] set spawn-probability-N spawn-probability-N + .001 set spawn-probability-S spawn-probability-N set list-Period10 lput (total-delay / total-finished-cars) list-Period10 ] set model "Trafic Light" set period 30 set beta 0 set alpha 0.45 set spawn-probability-N .001 set spawn-probability-S .001 set spawn-probability-E 0 set spawn-probability-W 0 set ticks-by-second 50 ask turtles [die] set list-Period30 [] while [spawn-probability-N <= .02] [ start-variables ask turtles [die] while [clock <= 20000] [ go ] set spawn-probability-N spawn-probability-N + .001 set spawn-probability-S spawn-probability-N + .001 set list-Period30 lput (total-delay / total-finished-cars) list-Period30 ] set model "Trafic Light" set period 50 set beta 0 set alpha 0.45 set spawn-probability-N .001 set spawn-probability-S .001 set spawn-probability-E 0 set spawn-probability-W 0 set ticks-by-second 50 ask turtles [die] set list-Period50 [] while [spawn-probability-N <= .02] [ start-variables ask turtles [die] while [clock <= 20000] [ go ] set spawn-probability-N spawn-probability-N + .001 set spawn-probability-S spawn-probability-N set list-Period50 lput (total-delay / total-finished-cars) list-Period50 ] set model "Reservation" set granularity 1 set period 30 set beta 0 set alpha 0.1 set spawn-probability-N .001 set spawn-probability-S .001 set spawn-probability-E .0 set spawn-probability-W .0 set ticks-by-second 50 ask turtles [die] set list-reservation [] while [spawn-probability-N <= .02] [ start-variables ask turtles [die] while [clock <= 20000] [ go ] set spawn-probability-N spawn-probability-N + .001 set spawn-probability-S spawn-probability-N set list-reservation lput (total-delay / total-finished-cars) list-reservation ] do-plotting3 end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;; to experiment4 set lanes 1 set plotting false set model "Reservation" set granularity 1 set period 30 set beta 0 set alpha 0.1 set spawn-probability-N .001 set spawn-probability-S .001 set spawn-probability-E .000 set spawn-probability-W .000 set ticks-by-second 50 setup while [spawn-probability-N <= .02] [ start-variables ask turtles [die] while [clock <= 20000] [ go ] do-plotting2a set spawn-probability-N spawn-probability-N + .001 set spawn-probability-S spawn-probability-N ] set granularity 2 set period 30 set beta 0 set alpha 0.1 set spawn-probability-N .001 set spawn-probability-S .001 set spawn-probability-E .001 set spawn-probability-W .001 set ticks-by-second 50 ask turtles [die] while [spawn-probability-N <= .02] [ start-variables ask turtles [die] while [clock <= 20000] [ go ] do-plotting2a set spawn-probability-N spawn-probability-N + .001 set spawn-probability-S spawn-probability-N ] end ;;;;;;;;;;;;;;;;;;;;;;; ;;PLOTTING PROCEDURES;; ;;;;;;;;;;;;;;;;;;;;;;; to do-plotting1 set-current-plot "Average Delay" set-current-plot-pen "default" ifelse total-finished-cars > 0 [ plot total-delay / total-finished-cars] [plot 0] set-current-plot "Maximum Delay" plot maximum-delay end to do-plotting set-current-plot "Figure a" set-current-plot-pen "Theoretical" plot expected-average-delay set-current-plot-pen "Empirical" plot total-delay / total-finished-cars set-current-plot "Figure b" set-current-plot-pen "Theoretical" plot expected-maximum-delay set-current-plot-pen "Empirical" plot maximum-delay end to do-plotting2a set-current-plot "Figure c" set-current-plot-pen "Granu. 1" plot total-delay / total-finished-cars end to do-plotting2b set-current-plot "Figure c" set-current-plot-pen "Granu. 2" plot total-delay / total-finished-cars end to do-plotting3 set-current-plot "Figure d" foreach list-period10 [ set-current-plot-pen "Period 10" plot ? set-current-plot-pen "Period 30" plot first list-period30 set list-period30 but-first list-period30 set-current-plot-pen "Period 50" plot first list-period50 set list-period50 but-first list-period50 set-current-plot-pen "Reservation" plot first list-reservation set list-reservation but-first list-reservation ] end @#$#@#$#@ GRAPHICS-WINDOW 176 87 587 519 200 200 1.0 0 10 1 1 1 0 CC-WINDOW 5 541 1050 636 Command Center BUTTON 8 10 107 43 Setup setup NIL 1 T OBSERVER T NIL BUTTON 9 46 92 79 Go go T 1 T OBSERVER T NIL MONITOR 602 10 659 59 NIL clock 3 1 PLOT 592 162 815 313 Figure a Period or Alpha Average Delay 0.0 0.0 0.0 10.0 true true PENS "Theoretical" 1.0 0 -16776961 true "Empirical" 1.0 0 -65536 true BUTTON 110 11 176 44 go once go NIL 1 T OBSERVER T NIL CHOICE 10 97 148 142 model model "Overpass" "Trafic Light" "Reservation" 2 SLIDER 10 143 173 176 lanes lanes 1 6 3 1 1 NIL SLIDER 8 176 173 209 spawn-probability-N spawn-probability-N 0.0 1.0 0.015 0.0010 1 NIL MONITOR 603 111 670 160 Total Delay total-delay\n 3 1 SLIDER 12 316 170 349 period period 10 200 30 1 1 NIL SLIDER 12 350 171 383 alpha alpha 0 1 0.45 0.05 1 NIL SLIDER 12 384 171 417 beta beta 0 1 0.1 0.1 1 NIL MONITOR 795 10 890 59 Finished Cars total-finished-cars 3 1 MONITOR 671 111 768 160 Average Delay total-delay / total-finished-cars 3 1 BUTTON 13 461 90 494 Experiment 1 experiment1 NIL 1 T OBSERVER T NIL PLOT 817 162 1041 312 Figure b Period or Alpha Maximum Delay 0.0 0.0 0.0 10.0 true true PENS "Theoretical" 1.0 0 -16776961 true "Empirical" 1.0 0 -65536 true BUTTON 96 462 167 495 Experiment 2 experiment2 NIL 1 T OBSERVER T NIL SLIDER 12 419 171 452 granularity granularity 1 50 2 1 1 NIL MONITOR 768 60 870 109 Expec. Max. Delay expected-maximum-delay 3 1 MONITOR 671 61 768 110 Expec. Avg. Delay expected-average-delay 3 1 MONITOR 770 110 844 159 Max. Delay maximum-delay 3 1 MONITOR 671 10 725 59 NIL total-cars 3 1 MONITOR 727 10 794 59 NIL active-cars 3 1 MONITOR 603 61 666 110 Seconds clock * .02 3 1 SLIDER 9 210 173 243 spawn-probability-S spawn-probability-S 0 1 0.015 0.0010 1 NIL SLIDER 9 244 172 277 spawn-probability-E spawn-probability-E 0 1 0.015 0.0010 1 NIL SLIDER 10 279 171 312 spawn-probability-W spawn-probability-W 0 1 0.015 0.0010 1 NIL BUTTON 96 494 167 527 Experiment 4 experiment4 NIL 1 T OBSERVER T NIL PLOT 592 316 814 466 Figure c % Chance to Spawn AverageDelay 0.0 0.0010 0.0 0.1 true false PENS "Granu. 1" 1.0 0 -16776961 true "Granu. 2" 1.0 0 -65536 true BUTTON 13 494 90 527 NIL Experiment3 NIL 1 T OBSERVER T NIL PLOT 816 316 1040 466 Figure d % Spawn Average Delay 0.0 10.0 0.0 10.0 true true PENS "Period 10" 1.0 0 -11352576 true "Period 30" 1.0 0 -16776961 true "Period 50" 1.0 0 -65413 true "Reservation" 1.0 0 -16711738 true PLOT 184 114 344 234 Average Delay NIL NIL 0.0 1.0 0.0 1.0 true false PENS "default" 1.0 0 -16776961 true PLOT 422 115 582 235 Maximum Delay NIL NIL 0.0 1.0 0.0 1.0 true false PENS "default" 1.0 0 -16745473 true SWITCH 95 47 185 80 plotting plotting 0 1 -1000 SLIDER 209 8 381 41 ticks-by-second ticks-by-second 1 50 10 1 1 NIL @#$#@#$#@ Title: Traffic Management Author: Benito Mendoza Garcia and Kurt Dresner Description: This program is a translation into NetLogo of an original Java simulator written by Kurt Dresner and described in