breed [cars car] breed [trucks truck] breed[houses house] breed[trees tree] breed[crossings crossing] breed [emergencies emergency] breed [pedestrians pedestrian] breed[lightsR lightR] breed [lightsL lightL] breed [lightsU lightU] breed [lightsD lightD] breed[lightsK lightK] breed [lightsM lightM] breed [lightsN lightN] breed [lightsO lightO] patches-own[ meaning ;;the role of the patch will-cross? ;;is anybody going to cross this crossing? used ;;tells how many pedestrians are using this crossing traffic ;;tells how many car will cross this crossing, if traffic > 0, it's dangerous for pedestrians ] globals[ redV ;;this variable is used to switch traffic lights..it means how many times there was red in the vertical direction greenV ;;how many times there was green in the vertical direction redH ;;how many times there was red in the horizontal direction greenH ;;how many times there was green in the horizontal direction redN ;;this variable is used to switch traffic lights..it means how many times there was red in the vertical direction greenN ;;how many times there was green in the vertical direction redM ;;how many times there was red in the horizontal direction greenM ;;how many times there was green in the horizontal direction speedLimit ;;the global maximum speed in the Argentinska part ] pedestrians-own[ speed ;;current speed of person walk-time ;;how long they will walk before crossing the road crossing-part ;;it divides the crossing to parts waiting? ;;is pedestrian waiting for crossing the road? ] cars-own[ speed ;;car's current speed maxSpeed ;;each car has its own maximum speed depending on the global maximum speeed (little bit lower or higher) will-turn? ;;whether car is going to turn or not will-die? turnX ;;coordinates of patch where car will change its direction when turning left turnY ;;coordinates of patch where car will change its direction when turning left will-stop? ;;whether the car will stop and let pedestrian(s) to cross the road ] to setup clear-all draw-roads draw-crossings draw-sidewalk draw-trees draw-houses place-lights place-people place-cars draw-ends draw-starts reset-ticks tick end to go move-cars move-pedestrians begone tick end to control-traffic-lights if ticks mod (50 * lights-interval * greenV + 65 * lights-interval * redV ) = 0 [change-color lightsR "V" change-color lightsL "V"] ; change color of horizontal lights if ticks mod (50 * lights-interval * greenH + 65 * lights-interval * redH ) = 0 [ change-color lightsD "H"] ; change color of vertical lights if ticks mod (50 * lights-interval * greenN + 65 * lights-interval * redN ) = 0 [change-color2 lightsK "N" change-color lightsM "N" change-color lightsN "N"] ; change color of horizontal lights if ticks mod (50 * lights-interval * greenM + 65 * lights-interval * redM ) = 0 [ change-color2 lightsO "M" change-color2 lightsU "M"] ; change color of vertical lights end to change-color [lights D] ask one-of lights [ ifelse color = red [ ifelse D = "H" [ set greenH greenH + 1 ; if color of lights is red and direction is horizotal, increase green horizontal counter by one ] [ set greenV greenV + 1] ; else increase green vertical counter by one ] ; If color is green... [ ifelse D = "H" [ set redH redH + 1 ; if color of lights is red and direction is horizotal, increase red horizontal counter by one ] [ set redV redV + 1 ; else increase red vertical counter by one ] ] ] ask lights [ ifelse color = red [set color green][set color red] ] end to change-color2 [lights O] ask one-of lights [ ifelse color = red [ ifelse O = "M" [ set greenM greenM + 1 ; if color of lights is red and direction is horizotal, increase green horizontal counter by one ] [ set greenN greenN + 1] ; else increase green vertical counter by one ] ; If color is green... [ ifelse O = "M" [ set redM redM + 1 ; if color of lights is red and direction is horizotal, increase red horizontal counter by one ] [ set redN redN + 1 ; else increase red vertical counter by one ] ] ] ask lights [ ifelse color = red [set color green][set color red] ] end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; to draw-roads ;create main road Argentinska up ask patches with [(pxcor = 0) or (pxcor = 1)] [ set pcolor grey sprout 1 [ set shape "road2" set color grey set meaning "Argentinskaup" if (pxcor = 0) [set heading 270] if (pxcor = 1) [set heading 90] stamp die ] ] ;create flow Argentinska -> Jatecni ask patches with [(pxcor = 2 and pycor < -15)] [ set pcolor grey sprout 1 [ set shape "road2" set color grey set meaning "Argentinskaup2" set heading 90 stamp die ] ] ;create flow Argentinska -> Viadukt ask patches with [(pxcor = -1 and pycor < -12)] [ set pcolor grey sprout 1 [ set shape "road2" set color grey set meaning "Argentinskaup3" set heading 270 stamp die ] ] ;create Delnicka to Argentinska ask patches with [(pxcor > 0 and pycor = 16) or (pxcor > 0 and pycor = 17)] [ set pcolor grey sprout 1 [ set shape "road2" set meaning "Delnicka" set color grey if (pycor = 16) [set heading 180] if (pycor = 17) [set heading 0] stamp die ] ] ;create Delnicka to Argentinska ask patches with [(pxcor = -1 and pycor = 16) or (pxcor = -2 and pycor = 16)] [ set pcolor grey sprout 1 [ set meaning "Delnicka1" set color grey stamp die ] ] ;create Delnicka from Argentinska ask patches with [(pxcor > 0) and (pycor = 14)] [ set pcolor grey sprout 1 [ set color grey set heading 180 stamp die ] ] ;create Tusarova ask patches with [(pxcor > 0) and (pycor = 0)] [ set pcolor grey sprout 1 [ set color grey set heading 0 stamp die ] ] ;create Jatecni from Argentinska ask patches with [(pxcor > 0) and (pycor = -15)] [ set pcolor grey sprout 1 [ set color grey set heading 180 stamp die ] ] ;create Jatecni to Argentinska ask patches with [ (pycor = -13 and pxcor > 1) or (pycor = -12 and pxcor > 1)] [ set pcolor grey sprout 1 [ set shape "road2" set meaning "Jatecni" set color grey if (pycor = -13) [set heading 180] if (pycor = -12) [set heading 0] stamp die ] ] ;create za Viaduktem ; ask patches with [ (pxcor < -2 and pxcor > -11) and (pycor < -11) ] [ ask patches with [ (pxcor < 0 and pycor = -12) or (pxcor < 0 and pycor = -13) ][ set pcolor grey sprout 1 [ set shape "road2" set meaning "ZaViaduktem" set color grey if (pycor = -13) [set heading 180] if (pycor = -12) [set heading 0] stamp die ] ] ;create main road Argentinska down ask patches with [(pxcor = -3) and (pycor > -12) or (pxcor = -4) and (pycor > -12)] [ set pcolor grey sprout 1 [ set shape "road2" set meaning "Argentinskadown" set color grey if (pxcor = -4) [set heading 270] if (pxcor = -3) [set heading 90] stamp die ] ] ask patches with [(pxcor = 2 and pycor = -15) or (pxcor = 1 and pycor = 0) or (pxcor = 1 and pycor = 14)] [ set pcolor blue sprout 1[ set shape "arrow" set heading 90 set meaning "rightturn" ] ] ask patches with [(pxcor = 1 and pycor = 0) ] [ set pcolor blue sprout 1[ set shape "arrow" set heading 90 set meaning "rightturn" ] ] ask patches with [(pxcor = 1 and pycor = 14)] [ set pcolor blue sprout 1[ set shape "arrow" set heading 90 set meaning "rightturn" ] ] ask patches with [(pxcor = -1 and pycor = -13)] [ set pcolor blue sprout 1[ set shape "arrow" set heading 270 set meaning "leftturn" ] ] ask patches with [(pxcor = -4 and pycor = -12)] [ set pcolor blue sprout 1[ set shape "arrow" set heading 270 set meaning "leftturn" ] ] ask patches with [(pxcor = -3 and pycor = -13)] [ set pcolor blue sprout 1[ set shape "arrow" set heading 270 set meaning "leftturn" ] ] ask patches with [(pxcor = 1 and pycor = 17)] [ set pcolor blue sprout 1[ set shape "arrow" set heading 0 set meaning "upturn" ] ] ask patches with [(pxcor = 1 and pycor = -12)] [ set pcolor blue sprout 1[ set shape "arrow" set heading 0 set meaning "upturn" ] ] ask patches with [(pxcor = -3 and pycor = 16)] [ set pcolor blue sprout 1[ set shape "arrow" set heading 180 set meaning "downturn" ] ] end to draw-ends ask patches with [(pxcor = 0 and pycor = max-pycor) or (pxcor = 1 and pycor = max-pycor) or (pxcor = max-pxcor and pycor = 0) or (pxcor = max-pxcor and pycor = 14) or (pxcor = max-pxcor and pycor = -15) or (pxcor = min-pxcor and pycor = -12) or (pxcor = min-pxcor and pycor = -13)] [ set pcolor red sprout 1[ set shape "x" set meaning "end" ] ] end to draw-starts ask patches with [ (pycor = min-pycor and pxcor = 2) or (pycor = min-pycor and pxcor = 1) or (pycor = min-pycor and pxcor = 0) or (pycor = min-pycor and pxcor = -1)] [ set pcolor green sprout 1[ set shape "circle" set meaning "start1" ] ] ask patches with [ (pxcor = max-pxcor and pycor = 17) or (pxcor = max-pxcor and pycor = 16) or (pxcor = max-pxcor and pycor = -12) or (pxcor = max-pxcor and pycor = -13)] [ set pcolor green sprout 1[ set shape "circle" set meaning "start2" ] ] ask patches with [(pxcor = -4 and pycor = max-pycor) or (pxcor = -3 and pycor = max-pycor) ] [ set pcolor green sprout 1[ set shape "circle" set meaning "start3" ] ] end to draw-sidewalk ;sidewalks ask patches with [(pxcor = 2 or pxcor = 3) and (pycor != -13) and (pycor != -12) and (pycor != 0) and (pycor != 14) and (pycor != 16) and (pycor != 17) and (pycor > -14) ] [ set pcolor brown + 2 sprout 1 [ set shape "tile stones" set meaning "sidewalk" set color 36 stamp die ] ] ask patches with [(pxcor = 4 or pxcor = 3) and (pycor < -15) ] [ set pcolor brown + 2 sprout 1 [ set shape "tile stones" set meaning "sidewalk" set color 36 stamp die ] ] ask patches with [(pxcor = -5 ) and (pycor > -12) ] [ set pcolor brown + 2 sprout 1 [ set shape "tile stones" set meaning "sidewalk" set color 36 stamp die ] ] ask patches with [(pxcor > 1) and (pycor = 13) ] [ set pcolor brown + 2 sprout 1 [ set shape "tile stones" set meaning "sidewalk" set color 36 stamp die ] ] ask patches with [(pxcor > 1) and (pycor = 18) ] [ set pcolor brown + 2 sprout 1 [ set shape "tile stones" set meaning "sidewalk" set color 36 stamp die ] ] ask patches with [(pxcor > 1) and (pycor = 1) ] [ set pcolor brown + 2 sprout 1 [ set shape "tile stones" set meaning "sidewalk" set color 36 stamp die ] ] ask patches with [(pxcor > 1) and (pycor = -1) ] [ set pcolor brown + 2 sprout 1 [ set shape "tile stones" set meaning "sidewalk" set color 36 stamp die ] ] ask patches with [(pxcor > 1) and (pycor = -14) ] [ set pcolor brown + 2 sprout 1 [ set shape "tile stones" set meaning "sidewalk" set color 36 stamp die ] ] ask patches with [(pxcor > 1) and (pycor = -11) ] [ set pcolor brown + 2 sprout 1 [ set shape "tile stones" set meaning "sidewalk" set color 36 stamp die ] ] ask patches with [(pxcor < -4) and (pycor = -11) ] [ set pcolor brown + 2 sprout 1 [ set shape "tile stones" set meaning "sidewalk" set color 36 stamp die ] ] ask patches with [(pxcor > 1) and (pycor = -16) ] [ set pcolor brown + 2 sprout 1 [ set shape "tile stones" set meaning "sidewalk" set color 36 stamp die ] ] ask patches with [(pxcor > 1) and (pycor = 13) ] [ set pcolor brown + 2 sprout 1 [ set shape "tile stones" set meaning "sidewalk" set color 36 stamp die ] ] end to draw-houses ;create couple of houses ask patches with [pcolor = black] [ if count neighbors with [pcolor = black] = 8 and not any? turtles in-radius 4 [ sprout-houses 1 [ set shape one-of ["house" "house colonial" "house efficiency" "house two story"] set size 4 stamp ] ] ] ask houses [die] end to draw-trees ;create couple of trees ask patches with [pcolor = black] [ if count neighbors with [pcolor = black] = 8 and not any? turtles in-radius 2 [ if random 100 > 90 [ sprout-trees 1 [ set shape one-of ["tree" "tree pine"] set size 4 set color green stamp ] ] ] ] ask trees [die] end to draw-crossings ;c crossing on Tusarova ask patches with [ (pycor = 0 )and (pxcor = 2 or pxcor = 3)][ sprout-crossings 1 [ set shape "crossing" set meaning "crossing" set color white set heading 90 set size 1 ] ] ;c crossing on Delnicka ask patches with [ (pycor = 14 and pxcor = 2) or (pycor = 16 and pxcor = 2) or (pycor = 17 and pxcor = 2) ][ sprout-crossings 1 [ set shape "crossing" set meaning "crossing" set color white set heading 90 set size 1 ] ] ;c crossing on Argentinska - Delnicka ask patches with [ (pycor = 13 and pxcor = -3) or (pycor = 13 and pxcor = -4) or (pycor = 13 and pxcor = 0) or (pycor = 13 and pxcor = 1)][ sprout-crossings 1 [ set shape "crossing" set meaning "crossing" set color white set heading 180 set size 1 ] ] ;c crossing on Argentinska - Jatecni ask patches with [ (pycor = -15 and pxcor = 3) or (pycor = -13 and pxcor = 2) or (pycor = -12 and pxcor = 2) ][ sprout-crossings 1 [ set shape "crossing" set meaning "crossing" set color white set heading 90 set size 1 ] ] ;c crossing Viadukt - Argentinska ask patches with [ (pycor = -11 and pxcor = -3) or (pycor = -11 and pxcor = -4) or (pycor = -11 and pxcor = 0) or (pycor = -11 and pxcor = 1) ][ sprout-crossings 1 [ set shape "crossing" set meaning "crossing" set color white set heading 180 set size 1 ] ] ;create waitpoints for pedestrians ask crossings with [(pycor = -1 and pxcor = 1)] [ set shape "waitpoint" set meaning "waitpoint2" set color black + 1 stamp die ] ;necessary row for crossings on the edges (function in-radius doesn't work) ask crossings [ set will-cross? false set meaning "crossing" stamp die ] ask patches with [meaning = "crossing"] [ ask neighbors4 [ if meaning = "sidewalk" [ set meaning "waitpoint" ] ] ] end to place-lights ask patches with [(pycor = 18 and pxcor = -4) or (pycor = 18 and pxcor = -3) ] [ sprout-lightsL 1 [ set color red set shape "lights" ] ] ask patches with [(pycor = 12 and pxcor = 0) or (pycor = 12 and pxcor = 1) ] [ sprout-lightsR 1 [ set color red set shape "lights" ] ] ask patches with [(pycor = 16 and pxcor = 3) or (pycor = 17 and pxcor = 3) ] [ sprout-lightsD 1 [ set color green set shape "lights" ] ] set greenM 0 set redM 1 set redN 0 set greenN 1 ask patches with [(pycor = -9 and pxcor = -4) or (pycor = -9 and pxcor = -3) ] [ sprout-lightsU 1 [ set color red set shape "lights" ] ] ask patches with [(pycor = -12 and pxcor = 3) or (pycor = -13 and pxcor = 3) ] [ sprout-lightsK 1 [ set color green set shape "lights" ] ] ask patches with [(pycor = -16 and pxcor = 2) ] [ sprout-lightsM 1 [ set color green set shape "lights" ] ] ask patches with [(pycor = -16 and pxcor = -1) ] [ sprout-lightsN 1 [ set color green set shape "lights" ] ] ask patches with [(pycor = -16 and pxcor = 0) or (pycor = -16 and pxcor = 1) ] [ sprout-lightsO 1 [ set color red set shape "lights" ] ] set greenH 0 set redH 1 set redV 0 set greenV 1 end to place-people while [count pedestrians < num-of-people] [ ask one-of patches with [meaning = "sidewalk"] [ sprout-pedestrians 1 [ set speed random 7 + 5 set size 1 set waiting? false set walk-time random time-to-crossing set shape one-of ["person" ] ] ] ] end to place-cars ;make a random placement of cars ask n-of (num-of-cars / 3) patches with [meaning = "Argentinskaup" or meaning = "Argentinskaup2" ] [ if not any? cars-on patch pxcor (pycor - 1) and not any? cars-here and not any? cars-on patch pxcor (pycor - 1) [ sprout-cars 1 [ set size 2 set will-turn? "maybe" set will-stop? "maybe" set shape "car top" set heading 0 let s random 10 if s < 7 [set maxSpeed speed-limit - 15 + random 16] if s = 7 [set maxSpeed speed-limit - 20 + random 6] if s > 7 [set maxSpeed speed-limit + random 16] set speed maxSpeed - random 20 ] ] ] ask n-of (num-of-cars / 3) patches with [ meaning = "Argentinskaup3"] [ if not any? cars-on patch pxcor (pycor - 1) and not any? cars-here and not any? cars-on patch pxcor (pycor - 1) [ sprout-cars 1 [ set size 2 set will-turn? "maybe" set will-stop? "maybe" set shape "car top" if (pycor < -13) [set heading 0] if (pycor = -13) [set heading 270] let s random 10 if s < 7 [set maxSpeed speed-limit - 15 + random 16] if s = 7 [set maxSpeed speed-limit - 20 + random 6] if s > 7 [set maxSpeed speed-limit + random 16] set speed maxSpeed - random 20 ] ] ] ask n-of (num-of-cars / 3) patches with [meaning = "Argentinskadown" ] [ if not any? cars-on patch pxcor (pycor - 1) and not any? cars-here and not any? cars-on patch pxcor (pycor - 1) [ sprout-cars 1 [ set size 2 set will-turn? "maybe" set will-stop? "maybe" set shape "car top" set heading 180 let s random 10 if s < 7 [set maxSpeed speed-limit - 15 + random 16] if s = 7 [set maxSpeed speed-limit - 20 + random 6] if s > 7 [set maxSpeed speed-limit + random 16] set speed maxSpeed - random 20 ] ] ] ask n-of (num-of-cars / 3) patches with [meaning = "Delnicka" ] [ if not any? cars-on patch pxcor (pycor - 1) and not any? cars-here and not any? cars-on patch pxcor (pycor - 1) [ sprout-cars 1 [ set size 2 set will-turn? "maybe" set will-stop? "maybe" set shape "car top" set heading 270 let s random 10 if s < 7 [set maxSpeed speed-limit - 15 + random 16] if s = 7 [set maxSpeed speed-limit - 20 + random 6] if s > 7 [set maxSpeed speed-limit + random 16] set speed maxSpeed - random 20 ] ] ] ask n-of (num-of-cars / 3) patches with [meaning = "Jatecni" ] [ if not any? cars-on patch pxcor (pycor - 1) and not any? cars-here and not any? cars-on patch pxcor (pycor - 1) [ sprout-cars 1 [ set size 2 set will-turn? "maybe" set will-stop? "maybe" set shape "car top" set heading 270 let s random 10 if s < 7 [set maxSpeed speed-limit - 15 + random 16] if s = 7 [set maxSpeed speed-limit - 20 + random 6] if s > 7 [set maxSpeed speed-limit + random 16] set speed maxSpeed - random 20 ] ] ] end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Go ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; to-report can-turn-right? if meaning = "rightturn" [report true] report false end to-report can-turn-left? if meaning = "leftturn" [report true] report false end to-report can-turn-up? if meaning = "upturn" [report true] report false end to-report can-turn-down? if meaning = "downturn" [report true] report false end to move-cars put-cars ask cars [ control-speed if not any? cars-on patch-ahead 1 and not any? cars-on patch-ahead 2 and not any? (lightsR-on patch-ahead 1.5) with [color = red] and not any? (lightsL-on patch-ahead 1.5) with [color = red] and not any? (lightsD-on patch-ahead 1.5) with [color = red] and not any? (lightsU-on patch-ahead 1.5) with [color = red] and not any? (lightsK-on patch-ahead 1.5) with [color = red] and not any? (lightsM-on patch-ahead 1.5) with [color = red] and not any? (lightsN-on patch-ahead 1.5) with [color = red] and not any? (lightsO-on patch-ahead 1.5) with [color = red] [move-to patch-ahead 1] if will-turn? = "maybe" [ if can-turn-left? [set heading 270] if can-turn-right? [set heading 90] if can-turn-up? [set heading 0]if can-turn-down? [set heading 180] ] ] end to begone ask cars [ ask patch-here [ if ( meaning = "end" or pcolor = black or meaning = "sidewalk") [ ask myself [die] ] ] ] end to put-cars ;make a random placement of cars ask n-of (num-of-cars / 5) patches with [meaning = "start1"] [ if not any? cars-on patch pxcor (pycor - 1) and not any? cars-here and not any? cars-on patch pxcor (pycor - 1) [ sprout-cars 1 [ set size 2 set will-turn? "maybe" set will-stop? "maybe" set shape "car top" set heading 0 ] ] ] ask n-of (num-of-cars / 5) patches with [meaning = "start2"] [ if not any? cars-on patch pxcor (pycor - 1) and not any? cars-here and not any? cars-on patch pxcor (pycor - 1) [ sprout-cars 1 [ set size 2 set will-turn? "maybe" set will-stop? "maybe" set shape "car top" set heading 270 ] ] ] ask n-of (num-of-cars / 5) patches with [meaning = "start3"] [ if not any? cars-on patch pxcor (pycor - 1) and not any? cars-here and not any? cars-on patch pxcor (pycor - 1) [ sprout-cars 1 [ set size 2 set will-turn? "maybe" set will-stop? "maybe" set shape "car top" set heading 180 ] ] ] end to control-speed let car-ahead one-of cars-on patch-ahead 1.5 ifelse car-ahead = nobody [ ifelse speed < maxSpeed [set speed speed + acceleration] [set speed speed - deceleration] ] [ ifelse [speed] of car-ahead = 0 [set speed 0] [ ifelse [speed] of car-ahead >= maxSpeed [ set speed maxSpeed set speed speed - deceleration ] [ ;try to overtake ifelse [meaning] of patch-left-and-ahead 90 1 = meaning and not any? turtles-on patch-left-and-ahead 90 1 and [meaning] of patch-left-and-ahead 90 1 != "crossroad" and meaning != "crossing" and [meaning] of patch-left-and-ahead 180 1.3 != "crossing" and not any? turtles-on patch-left-and-ahead 169 3 and not any? turtles-on patch-left-and-ahead 45 1 and not any? turtles-on patch-left-and-ahead 135 1 and not any? turtles-on patch-left-and-ahead 23 2 and not any? turtles-on patch-left-and-ahead 157 2 and not any? turtles-on patch-left-and-ahead 12 3 and [meaning] of patch-ahead 1 != "crossing" [move-to patch-left-and-ahead 90 1] [ ifelse [meaning] of patch-right-and-ahead 90 1 = meaning and not any? turtles-on patch-right-and-ahead 90 14 and [meaning] of patch-right-and-ahead 90 1 != "crossroad" and meaning != "crossing" and [meaning] of patch-right-and-ahead 180 1.3 != "crossing" and not any? turtles-on patch-right-and-ahead 12 3 and not any? turtles-on patch-right-and-ahead 45 1 and not any? turtles-on patch-right-and-ahead 135 1 and not any? turtles-on patch-right-and-ahead 23 2 and not any? turtles-on patch-right-and-ahead 157 2 and not any? turtles-on patch-right-and-ahead 169 3 and [meaning] of patch-ahead 1 != "crossing"[move-to patch-right-and-ahead 90 1] [ set speed [speed] of car-ahead set speed speed - deceleration] ] ] ] ] end to move-pedestrians ask pedestrians [ walk ] end to walk ifelse [meaning] of patch-ahead 1 = "sidewalk" or [meaning] of patch-ahead 1 = "waitpoint2" [ ifelse any? other pedestrians-on patch-ahead 1 [ rt random 90 lt random 90 set walk-time walk-time + 1 ] [fd speed / 200 set walk-time walk-time + 1] ] [ rt random 120 lt random 120 if [meaning] of patch-ahead 1 = "sidewalk" or [meaning] of patch-ahead 1 = "waitpoint2" [ fd speed / 200 ] set walk-time walk-time + 1 ] end to cross-the-street if crossing-part = 1[ face min-one-of patches with [meaning = "waitpoint2"] in-radius 4 [abs([xcor] of myself - pxcor)] ask patches in-cone 3 180 with [meaning = "crossing"] [set used used + 1] set crossing-part 2 ] if crossing-part = 2 [ if heading > 315 and heading < 45 [set heading 0] if heading > 45 and heading < 135 [set heading 90] if heading > 135 and heading < 225 [set heading 180] if heading > 225 and heading < 315 [set heading 270] ] if meaning = "waitpoint2" and crossing-part = 2 [ rt 180 ask patches in-cone 3 180 with [meaning = "crossing"] [set used used - 1] lt 180 ask patches in-cone 3 180 with [meaning = "crossing"] [set used used + 1] set crossing-part 3 ] if crossing-part = 3 and meaning = "waitpoint" [ rt 180 ask patches in-cone 3 180 with [meaning = "crossing"] [set used used - 1] lt 180 set crossing-part 0 set walk-time 0 ] ifelse meaning = "waitpoint" and crossing-part = 2 and ([traffic] of patch-ahead 1 > 0 or [traffic] of patch-ahead 2 > 0) [ fd 0 set waiting? true ] [ ifelse meaning = "waitpoint2" and crossing-part = 3 and ([traffic] of patch-ahead 1 > 0 or [traffic] of patch-ahead 2 > 0)[ fd 0 set waiting? true ] [ if not any? cars-on patch-ahead 1 [ fd speed / 200 set waiting? false ] ] ] end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Plot ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; to plot-carswaiting set-current-plot "Number of waiting cars" set-current-plot-pen "Waiting cars" plot (count cars with [waiting? = true]) end @#$#@#$#@ GRAPHICS-WINDOW 543 12 1234 704 -1 -1 11.2 1 10 1 1 1 0 1 1 1 -30 30 -30 30 0 0 1 ticks 30.0 BUTTON 386 28 450 61 NIL Setup NIL 1 T OBSERVER NIL S NIL NIL 1 BUTTON 452 28 516 62 NIL Go T 1 T OBSERVER NIL NIL NIL NIL 1 SLIDER 115 245 288 278 num-of-people num-of-people 0 100 23.0 1 1 NIL HORIZONTAL SLIDER 115 278 288 311 time-to-crossing time-to-crossing 0 100 9.0 1 1 NIL HORIZONTAL SLIDER 116 310 289 343 Num-of-cars Num-of-cars 0 100 8.0 1 1 NIL HORIZONTAL SLIDER 115 212 288 245 speed-limit speed-limit 0 100 20.0 1 1 NIL HORIZONTAL SLIDER 115 178 287 211 prob-of-turning prob-of-turning 0 100 50.0 1 1 NIL HORIZONTAL SLIDER 117 342 289 375 acceleration acceleration 0 1 0.172 0.001 1 NIL HORIZONTAL SLIDER 116 375 288 408 deceleration deceleration 0 1 0.089 0.001 1 NIL HORIZONTAL SLIDER 116 147 288 180 lights-interval lights-interval 0 20 6.0 1 1 NIL HORIZONTAL PLOT 114 418 314 568 Number of waiting pedestrians Time Waiting cars 0.0 10.0 0.0 10.0 true false "" "" PENS "cars" 1.0 0 -8732573 true "" "plot count turtles" @#$#@#$#@ ## WHAT IS IT? (a general understanding of what the model is trying to show or explain) ## HOW IT WORKS (what rules the agents use to create the overall behavior of the model) ## HOW TO USE IT (how to use the model, including a description of each of the items in the Interface tab) ## THINGS TO NOTICE (suggested things for the user to notice while running the model) ## THINGS TO TRY (suggested things for the user to try to do (move sliders, switches, etc.) with the model) ## EXTENDING THE MODEL (suggested things to add or change in the Code tab to make the model more complicated, detailed, accurate, etc.) ## NETLOGO FEATURES (interesting or unusual features of NetLogo that the model uses, particularly in the Code tab; or where workarounds were needed for missing features) ## RELATED MODELS (models in the NetLogo Models Library and elsewhere which are of related interest) ## CREDITS AND REFERENCES (a reference to the model's URL on the web if it has one, as well as any other necessary credits, citations, and links) @#$#@#$#@ 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 true 210 165 195 165 Line -7500403 true 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 crossing true 15 Line -16777216 false 150 90 150 210 Line -16777216 false 120 90 120 210 Line -16777216 false 90 90 90 210 Line -16777216 false 240 90 240 210 Line -16777216 false 270 90 270 210 Line -16777216 false 30 90 30 210 Line -16777216 false 60 90 60 210 Line -16777216 false 210 90 210 210 Line -16777216 false 180 90 180 210 Rectangle -1 true true 0 0 30 300 Rectangle -7500403 true false 120 0 150 300 Rectangle -1 true true 180 0 210 300 Rectangle -7500403 true false 240 0 270 300 Rectangle -1 true true 30 0 60 300 Rectangle -7500403 true false 90 0 120 300 Rectangle -1 true true 150 0 180 300 Rectangle -7500403 true false 270 0 300 300 Rectangle -1 true true 60 0 90 300 Rectangle -1 true true 210 0 240 300 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 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 house bungalow false 0 Rectangle -7500403 true true 210 75 225 255 Rectangle -7500403 true true 90 135 210 255 Rectangle -16777216 true false 165 195 195 255 Line -16777216 false 210 135 210 255 Rectangle -16777216 true false 105 202 135 240 Polygon -7500403 true true 225 150 75 150 150 75 Line -16777216 false 75 150 225 150 Line -16777216 false 195 120 225 150 Polygon -16777216 false false 165 195 150 195 180 165 210 195 Rectangle -16777216 true false 135 105 165 135 house colonial false 0 Rectangle -7500403 true true 270 75 285 255 Rectangle -7500403 true true 45 135 270 255 Rectangle -16777216 true false 124 195 187 256 Rectangle -16777216 true false 60 195 105 240 Rectangle -16777216 true false 60 150 105 180 Rectangle -16777216 true false 210 150 255 180 Line -16777216 false 270 135 270 255 Polygon -7500403 true true 30 135 285 135 240 90 75 90 Line -16777216 false 30 135 285 135 Line -16777216 false 255 105 285 135 Line -7500403 true 154 195 154 255 Rectangle -16777216 true false 210 195 255 240 Rectangle -16777216 true false 135 150 180 180 house efficiency false 0 Rectangle -7500403 true true 180 90 195 195 Rectangle -7500403 true true 90 165 210 255 Rectangle -16777216 true false 165 195 195 255 Rectangle -16777216 true false 105 202 135 240 Polygon -7500403 true true 225 165 75 165 150 90 Line -16777216 false 75 165 225 165 house two story false 0 Polygon -7500403 true true 2 180 227 180 152 150 32 150 Rectangle -7500403 true true 270 75 285 255 Rectangle -7500403 true true 75 135 270 255 Rectangle -16777216 true false 124 195 187 256 Rectangle -16777216 true false 210 195 255 240 Rectangle -16777216 true false 90 150 135 180 Rectangle -16777216 true false 210 150 255 180 Line -16777216 false 270 135 270 255 Rectangle -7500403 true true 15 180 75 255 Polygon -7500403 true true 60 135 285 135 240 90 105 90 Line -16777216 false 75 135 75 180 Rectangle -16777216 true false 30 195 93 240 Line -16777216 false 60 135 285 135 Line -16777216 false 255 105 285 135 Line -16777216 false 0 180 75 180 Line -7500403 true 60 195 60 240 Line -7500403 true 154 195 154 255 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 lights false 0 Rectangle -16777216 true false 15 15 285 285 Rectangle -7500403 true true 30 30 270 270 line true 0 Line -7500403 true 150 0 150 300 line half true 0 Line -7500403 true 150 0 150 150 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 road-middle true 0 Rectangle -7500403 true true 0 0 300 300 Rectangle -10899396 true false 0 45 300 255 road2 true 0 Rectangle -7500403 true true 0 0 300 300 Rectangle -1 true false 60 255 225 390 sheep false 15 Circle -1 true true 203 65 88 Circle -1 true true 70 65 162 Circle -1 true true 150 105 120 Polygon -7500403 true false 218 120 240 165 255 165 278 120 Circle -7500403 true false 214 72 67 Rectangle -1 true true 164 223 179 298 Polygon -1 true true 45 285 30 285 30 240 15 195 45 210 Circle -1 true true 3 83 150 Rectangle -1 true true 65 221 80 296 Polygon -1 true true 195 285 210 285 210 240 240 210 195 210 Polygon -7500403 true false 276 85 285 105 302 99 294 83 Polygon -7500403 true false 219 85 210 105 193 99 201 83 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 tile stones false 0 Polygon -7500403 true true 0 240 45 195 75 180 90 165 90 135 45 120 0 135 Polygon -7500403 true true 300 240 285 210 270 180 270 150 300 135 300 225 Polygon -7500403 true true 225 300 240 270 270 255 285 255 300 285 300 300 Polygon -7500403 true true 0 285 30 300 0 300 Polygon -7500403 true true 225 0 210 15 210 30 255 60 285 45 300 30 300 0 Polygon -7500403 true true 0 30 30 0 0 0 Polygon -7500403 true true 15 30 75 0 180 0 195 30 225 60 210 90 135 60 45 60 Polygon -7500403 true true 0 105 30 105 75 120 105 105 90 75 45 75 0 60 Polygon -7500403 true true 300 60 240 75 255 105 285 120 300 105 Polygon -7500403 true true 120 75 120 105 105 135 105 165 165 150 240 150 255 135 240 105 210 105 180 90 150 75 Polygon -7500403 true true 75 300 135 285 195 300 Polygon -7500403 true true 30 285 75 285 120 270 150 270 150 210 90 195 60 210 15 255 Polygon -7500403 true true 180 285 240 255 255 225 255 195 240 165 195 165 150 165 135 195 165 210 165 255 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 tree pine false 0 Rectangle -6459832 true false 120 225 180 300 Polygon -7500403 true true 150 240 240 270 150 135 60 270 Polygon -7500403 true true 150 75 75 210 150 195 225 210 Polygon -7500403 true true 150 7 90 157 150 142 210 157 150 7 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 waitpoint false 14 Rectangle -16777216 true true 15 15 285 285 Rectangle -7500403 true false 30 30 270 270 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 wolf false 0 Polygon -16777216 true false 253 133 245 131 245 133 Polygon -7500403 true true 2 194 13 197 30 191 38 193 38 205 20 226 20 257 27 265 38 266 40 260 31 253 31 230 60 206 68 198 75 209 66 228 65 243 82 261 84 268 100 267 103 261 77 239 79 231 100 207 98 196 119 201 143 202 160 195 166 210 172 213 173 238 167 251 160 248 154 265 169 264 178 247 186 240 198 260 200 271 217 271 219 262 207 258 195 230 192 198 210 184 227 164 242 144 259 145 284 151 277 141 293 140 299 134 297 127 273 119 270 105 Polygon -7500403 true true -1 195 14 180 36 166 40 153 53 140 82 131 134 133 159 126 188 115 227 108 236 102 238 98 268 86 269 92 281 87 269 103 269 113 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 6.0.4 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ default 0.0 -0.2 0 0.0 1.0 0.0 1 1.0 0.0 0.2 0 0.0 1.0 link direction true 0 Line -7500403 true 150 150 90 180 Line -7500403 true 150 150 210 180 @#$#@#$#@ 0 @#$#@#$#@