# Crowded Station

Model was written in NetLogo 6.0-M5
•
Viewed 409 times
•
Downloaded 34 times
•
Run 0 times

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)

Info tab cannot be displayed because of an encoding error

## Comments and Questions

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

Click to Run Model

extensions [ls] globals [ walls roads train stop-line stair-y-list stair-x stair-end-x train-x total-time total-wait-time total-number total-time-hour total-wait-time-hour total-number-hour neural-net-setted? escalator? elevator? ;escalator-speed ;elevator-speed ;real-data? real-flow-list ] turtles-own [ entrance-path-found? train-path-found? dest-x dest-y speed wait-time on-train-time density-right ; density on the right side of it density-left ; density on the left side of it density-ahead ; density in front of it ahead-left-bound ; ycor of begining of left side area ahead-right-bound ; ycor of begining of right side area ] patches-own [ dist-to-entrance ] ;;;;;;;;;;;;;;;;;;;;; ;; SETUP PROCEDURE ;; ;;;;;;;;;;;;;;;;;;;;; to setup clear-all make-station make-train set total-time 0 set total-wait-time 0 set total-number 1 set total-time-hour 0 set total-wait-time-hour 0 set total-number-hour 1 ifelse way-to-platform = "escalators" [ escalators ] [ if way-to-platform = "elevators" [ elevators ] ] set real-flow-list (list 0 0 0 0 0.008 0.008 0.008 0.15 0.416 0.75 0.83 0.83 0.75 0.75 0.75 0.79 0.916 1 0.916 0.75 0.5 0.16 0 0) reset-ticks end ;; setup with standard inputs (designed to simulate settings in reality) to standard-setup clear-all ifelse way-to-platform = "stairs" [ set width 3 ] [ set width 2 ] set stair-spacing 16 set height-of-floor 6 set width-of-platform 9 make-station make-train set total-time 0 set total-wait-time 0 set total-number 1 set total-time-hour 0 set total-wait-time-hour 0 set total-number-hour 1 ifelse way-to-platform = "escalators" [ escalators ] [ if way-to-platform = "elevators" [ elevators ] ] set turtle-base-speed 1 set escalator-speed 2 set elevator-speed 2 set flow-rate 3 set real-data? true ; 3 people per tick == 1 set real-flow-list (list 0 0 0 0 0.008 0.008 0.008 0.15 0.416 0.75 0.83 0.83 0.75 0.75 0.75 0.79 0.916 1 0.916 0.75 0.5 0.16 0 0) set train-interval 20 set train-stop-time 5 reset-ticks end ;; setup neural net model to setup-neural-net if neural-net-setted? = 0 and neural-net-on? [ ls:reset ls:load-headless-model "My Neural Net.nlogo" ls:ask ls:models [ setup repeat 1000 [ train ] ] set neural-net-setted? true ] end ;; create whole structure of the station to make-station ;; walking area are white ask patches [ set pcolor white ] let y stair-spacing / 2 set stair-y-list [] set stair-x -6 set stair-end-x stair-x + height-of-floor ;; create walls ifelse width = 1 [ set walls patches with [ pxcor >= stair-x and pxcor <= stair-end-x and pycor != y and pycor != (0 - y) ] set stair-y-list lput y stair-y-list set stair-y-list lput (0 - y) stair-y-list ] [ ifelse width = 2 [ set walls patches with [ pxcor >= stair-x and pxcor <= stair-end-x and pycor != y and pycor != (y + 1) and pycor != (0 - y) and pycor != (-1 - y) ] set stair-y-list lput y stair-y-list set stair-y-list lput (y + 1) stair-y-list set stair-y-list lput (0 - y) stair-y-list set stair-y-list lput (-1 - y) stair-y-list ] [ set walls patches with [ pxcor >= stair-x and pxcor <= stair-end-x and pycor != y and pycor != (y + 1) and pycor != (y + 2) and pycor != (0 - y) and pycor != (-1 - y) and pycor != (-2 - y) ] set stair-y-list lput y stair-y-list set stair-y-list lput (y + 1) stair-y-list set stair-y-list lput (y + 2) stair-y-list set stair-y-list lput (0 - y) stair-y-list set stair-y-list lput (-1 - y) stair-y-list set stair-y-list lput (-2 - y) stair-y-list ] ] ask walls [ set pcolor black set dist-to-entrance 1000 ] end ;; create train/tracks to make-train set train-x stair-end-x + width-of-platform set train patches with [ pxcor = train-x ] ask train [ set pcolor red ] set stop-line train-x - 2 end ;; set stair equipment to escalator to escalators set escalator? true set elevator? false end ;; set stair equipment to elevator to elevators set elevator? true set escalator? false end ;;;;;;;;;;;;;;;;;;;;;; ;;;; GO PROCEDURE ;;;; ;;;;;;;;;;;;;;;;;;;;;; to go setup-neural-net create-passenger train-arrival boarding find-platform down-stairs find-train moving count-time recolor tick end ;; create passengers based on real data or user inputs to create-passenger ifelse real-data? = true [ let percentage item ((ticks / 400) mod 24) real-flow-list if random-float 1 < percentage [ create-turtle ] ] [ create-turtle ] end ;; create trutles at specific locations to create-turtle crt flow-rate [ setxy random-float (stair-x - min-pxcor - 2) - max-pxcor one-of (list min-pycor max-pycor) set shape "circle" set size 0.7 set color red + 3 set entrance-path-found? false set train-path-found? false set speed random-float 1 + turtle-base-speed if any? other turtles-here [ ask other turtles-here [ die ] ] ] end ;; change color of train patches to show its arrival to train-arrival ifelse ticks mod train-interval >= 0 and ticks mod train-interval <= train-stop-time [ ask train [ set pcolor green ] ] [ ask train [ set pcolor red ] ] end ;; turtle procedure ;; detect obstacles in front of it ;; find new path if it can't move forward to avoid-walls if not can-move? speed or [pcolor] of patch-ahead speed = black [ find-nearest-patch ] if patch-ahead speed != nobody [ ifelse not any? other turtles-on patch-ahead speed [ fd speed ] [ set wait-time wait-time + 1 move-to-neighbor ] ] end ;; turtle procedure ;; get on the train, report time and die to boarding ask turtles with [ xcor >= stop-line ] [ if [ pcolor ] of one-of train = green [ set total-time total-time + on-train-time set total-wait-time total-wait-time + wait-time set total-number total-number + 1 set total-time-hour total-time-hour + on-train-time set total-wait-time-hour total-wait-time-hour + wait-time set total-number-hour total-number-hour + 1 die ] ] end ;; set destination of turtles outside the wall to platform to find-platform ask turtles with [ pxcor < stair-x] [ set dest-x stair-x set dest-y nearest-stair set entrance-path-found? true set train-path-found? false ] end ;; go down by using stair equipment to down-stairs ifelse escalator? = true [ use-escalator ] [ ifelse elevator? = true [ use-elevator ] [ use-stair ] ] end ;; set destination of turtles on platform the train to find-train ifelse neural-net-on? [ ask turtles with [ train-path-found? = false and pxcor >= stair-end-x ] [ set dest-x train-x calculate-ahead-bound calculate-density set dest-y best-car set speed random-float 1 + 1 set train-path-found? true ] ] [ ask turtles with [ train-path-found? = false and pxcor >= stair-end-x ] [ set dest-x train-x set dest-y random-float (2 * max-pycor) - max-pycor set speed random-float 1 + 1 set train-path-found? true ] ] end ;; turtle procedure ;; moving towards destination to moving ask turtles with [ entrance-path-found? = true or train-path-found? = true ] [ ifelse xcor >= stair-x and xcor < stair-end-x and escalator? = true [ facexy dest-x dest-y fd speed ] [ if xcor < stop-line [ facexy dest-x dest-y avoid-walls ] ] ] end ;; update measurements to count-time ask turtles [ set on-train-time on-train-time + 1 ] if (ticks mod 400) = 0 [ set total-time-hour 0 set total-wait-time-hour 0 set total-number-hour 1 ] ;ask turtles with [ wait-time > 50 ] [ die ] end ;; update turtles' color to recolor ask turtles [ set color scale-color red (25 - wait-time) -10 30 ] end ;;;;;;;;;;;;;;;;;;;;;;;;; ;;; HELPER PROCEDURES ;;; ;;;;;;;;;;;;;;;;;;;;;;;;; ;; walk on stairs to use-stair ask turtles with [ pxcor >= stair-x and pxcor < stair-end-x ] [ set dest-x stair-end-x set dest-y pycor set train-path-found? false ] end ;; stand on escalator to use-escalator ask turtles with [ pxcor >= stair-x and pxcor < stair-end-x ] [ set dest-x stair-end-x set dest-y pycor set train-path-found? false set speed escalator-speed ] end ;; use elevator to use-elevator ask turtles with [ pxcor >= stair-x and pxcor < stair-end-x ] [ set dest-x stair-end-x set dest-y pycor set train-path-found? false ifelse ticks mod ((stair-end-x - stair-x) / elevator-speed * 2) = 0 [ set speed (stair-end-x - stair-x) + 1 ] [ set speed 0 ] ] end ;; reporter procedure ;; report the car that a turtle is going to board to-report best-car ls:let i1 round density-left ls:let i2 round density-ahead ls:let i3 round density-right ls:ask ls:models [ set input-1 i1 set input-2 i2 set input-3 i3 test ] let choice first [ output ] ls:of ls:models ifelse choice = 0 [ report random (max-pycor - ahead-left-bound) + ahead-left-bound ] [ ifelse choice = 1 [ report random (ahead-right-bound - min-pycor) + min-pycor ] [ report random (ahead-left-bound - ahead-right-bound) + ahead-right-bound ] ] end ;; turtle procedure ;; set the bound the area that in front of it to calculate-ahead-bound set ahead-left-bound ycor + ahead-range set ahead-right-bound ycor - ahead-range if ahead-left-bound > max-pycor [ set ahead-left-bound max-pycor ] if ahead-right-bound < min-pycor [ set ahead-right-bound min-pycor ] end ;; turtle procedure ;; calculate density distribution of turtles ahead it to calculate-density ifelse ahead-left-bound = max-pycor [ set density-left 1000 ] [ set density-left count turtles with [ ycor > ahead-left-bound and xcor >= [xcor] of myself ] / (max-pycor - ahead-left-bound) ] ifelse ahead-right-bound = min-pycor [ set density-right 1000 ] [ set density-right count turtles with [ ycor < ahead-right-bound and xcor >= [xcor] of myself ] / (ahead-right-bound - min-pycor) ] set density-ahead count turtles with [ ycor >= ahead-right-bound and pycor <= ahead-left-bound and xcor >= [xcor] of myself ] / (ahead-left-bound - ahead-right-bound + 1) end ;; reporter procedure ;; report the nearest stair for a turtle to-report nearest-stair let min-dist 1000 let y 0 foreach stair-y-list [ let cur-dist distancexy stair-x ? if cur-dist < min-dist [ set min-dist cur-dist set y ? ] ] report y end ;; turtle procedure ;; find new nearest path to destination to find-nearest-patch ask neighbors with [ pcolor != black ] [ set dist-to-entrance distancexy [ dest-x ] of myself [ dest-y ] of myself ] let nearest-neighbor one-of min-n-of 1 neighbors [ dist-to-entrance ] facexy [pxcor] of nearest-neighbor [pycor] of nearest-neighbor end ;; turtle procedure ;; move to one of neighors ahead a turtle to move-to-neighbor ; allow move back ;let valid-neighbor one-of neighbors with [ pcolor != black and not any? other turtles-here ] ; never move back let valid-neighbor one-of neighbors with [ pcolor != black and not any? other turtles-here and (([xcor] of myself - pxcor ) * (pxcor - [dest-x] of myself) < 0) ] if valid-neighbor != nobody [ move-to valid-neighbor ] end

There are 6 versions of this model.

## Attached files

File | Type | Description | Last updated | |
---|---|---|---|---|

Crowded Station.png | preview | Preview for 'Crowded Station' | almost 3 years ago, by Ye Xue | Download |

YeXue_May16.pdf | project progress | almost 3 years ago, by Ye Xue | Download | |

YeXue_May23.pdf | project progress | almost 3 years ago, by Ye Xue | Download | |

YeXue_May29.pdf | project progress | almost 3 years ago, by Ye Xue | Download | |

YeXue_May7.pdf | project progress | almost 3 years ago, by Ye Xue | Download |