Crowded Station
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
This model simulates people flow in a subway station, specifically from ticket gate to the metro, including elevator, escalator or stairs and platform area. Each passenger starts at the ticket gate with a certain speed and finds the nearest way to the metro.
A subway station contains walking area and walls. Passengers can only walk through walking areas and will not run into walls or other passengers. When a passenger can not move forward along the path it chosen, whether because of the walls or other passengers in front of it, it will try to find another nearest path without moving back. If there is no other path that it could find, it will stay where it was and wait until it can move forward again.
After a passenger has found the metro, it may wait outside until a metro’s arrival or get on the metro if one has arrived. This model doesn’t consider the passengers getting off from the metro and assume metro has enough room for boarding passengers. Once a passenger has got on the metro, it disappears from the model and reports the time it spent from the ticket gate to the metro, as well as the wait time, total time when it stayed on the same spot.
Passengers continually appears outside the ticket gate and do the same activity.
HOW IT WORKS
At each tick, create a certain number passengers at random spots on the top or bottom outside the wall. Each passenger first locates itself. If it is at entrance area (outside the wall), it will find the nearest stair it can get and set the destination to this stair. If it is on stairs/escalator/elevator, it will set the destination to the end of the stairs facility. If it is on the platform, it will set the destination to a random car of the metro. If it has reached the destination (outside the metro), it will check whether the metro is here or not. If the metro is here, it will get on the metro (die) and report the wait time and whole travel time. If the metro has not arrived yet, it will stay and wait.
Then a passenger that has not reached the destination, detect whether there are obstacles (wall or other passengers) on its way to the destination. If no obstacles, it will move forward based on its speed. If there is any obstacle, it will find other nearest path starting from its neighbour patches without going back. If it found a nearest path, it will move to the neighbour that on the way to destination. If there is no path it could get to the destination from any of its neighbours, it will stay on the current patch and wait.
At each tick, patches representing train/tracks calculates the time to decide whether the metro should arrive or not. If metro should arrive, they will change their color to green showing passengers that they could board now. If not, they will set their color red.
HOW TO USE IT
way-to-platform: one of three ways to get to platform (stairs, escalator and elevator) stair-spacing: the distance between two stair equipments width: width of stairs (number of turtles can get though at the same time) / capacity of escalator to elevator flow-rate: number of passengers arriving at this station train-interval: how long will the next metro arrive after the last one’s leaving train-stop-time: how long will the metro stay at this station turtle-base-speed: speed of the slowest turtle escalator-speed: speed of escalator elevator-speed: speed of elevator ahead-range: a neural network parameter. Specify the area that in front of a passenger neural-net-on?: passengers find cars randomly or based on the neural net
RELATED MODELS
My Neural Net.nlogo
Comments and Questions
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' | over 9 years ago, by Ye Xue | Download |
YeXue_May16.pdf | project progress | over 9 years ago, by Ye Xue | Download | |
YeXue_May23.pdf | project progress | over 9 years ago, by Ye Xue | Download | |
YeXue_May29.pdf | project progress | over 9 years ago, by Ye Xue | Download | |
YeXue_May7.pdf | project progress | over 9 years ago, by Ye Xue | Download |