📄 ---student_movement.nlogo
字号:
patches-own [ barrier]breeds [ inside outside ]globals [ time num-outside num-inside ]to setup ca ask patches [ setup-school] ;;setup hallways setup-students ;;place students set time 0 setup-plot update-monitors ;;reports number of students left update-plotsendto setup-school set pcolor gray + 4 ifelse ( pycor > 16 ) [ set barrier true ] [set barrier false] ;;top boundary if ( pxcor < -3 ) and ( pycor > -9 ) and ( pycor < 11 ) [ set barrier true ] ;;left block if ( pxcor > 3 ) and ( pycor > -9 ) and ( pycor < 11 ) [ set barrier true ] ;;right block if ( pxcor = -17 ) and ( pycor > 4 ) [ set barrier true ] ;;left wall if ( pxcor = 17 ) and ( pycor > 4 ) [ set barrier true ] ;;right wall if barrier = true [ set pcolor red - 2 ] ;;indentifies barrierendto setup-students create-inside num-students-in ;;choose number of students starting inside ask inside [ setxy ( 0 + random 16 - random 16 ) 14 ] ;;puts turtles in random line inside building create-outside num-students-out ;;choose number of students starting outiside ask outside [ setxy (random screen-size-x) -14 ] ;;puts turtles in random line outside building set-default-shape inside "student" set-default-shape outside "student-boy" ask turtles [if count turtles-here > 1 or barrier = true [find-new-spot]] ;;turtles begin separatedendto setup-plot ;;puts data into graph set-current-plot "Students Left" set-plot-y-range 0 num-students-in + 10endto find-new-spot rt random 360 fd 1 ifelse count turtles-here > 1 or barrier = true ;;turtles cannot be on the same spot as another turtle, or on a barrier [find-new-spot] [set heading 180]endto go ifelse wait-inside? [ask inside ;;turtles will have to wait if the switch is engaged [if time > wait-time [ go-inside ]]] [ask inside [go-inside]] ifelse wait-outside? [ask outside [if time > wait-time [go-outside]]] [ask outside [ go-outside ]] if count turtles > 0 [ set time time + .01 ] ;;time will be recorded in order to keep track of how long the model has been running. update-monitors ;;it will stop when there are no more turtles on the screen if count turtles > 0 [ update-plots ]endto go-inside ask inside [ifelse (xcor < 0) [set heading 90 + random 90 ] [set heading 270 - random 90] ] ;;sets heading in the general direction of the hallway ask inside [if ((pcolor-of patch-at dx dy) = red - 2 and xcor < 0) [lt 90 ]] ;;to avoid walking within the barriers ask inside [if ((pcolor-of patch-at dx dy) = red - 2 and xcor > 0) [rt 90 ]] ask inside [ ifelse (any turtles-at dx dy) [set heading heading + random 90 - random 10] ;;turtles can only move if the space is not occupied by another turtle and the space is not a wall [if pcolor-of patch-at dx dy != red - 2 [fd .01]]] ask inside [if (ycor <= -15) [ die ]] ;;after the turtles reach their destination, they dieendto go-outside ask outside [ifelse (xcor < 0) [set heading 90 - random 90 ] [set heading 270 + random 90] ] ;;sets heading in the general direction of the hallway ask outside [if ((pcolor-of patch-at dx dy) = red - 2 and xcor < 0) [rt 90]] ;;to avoid walking within the barriers ask outside [if ((pcolor-of patch-at dx dy) = red - 2 and xcor > 0) [lt 90]] ask outside [ ifelse (any turtles-at dx dy) [set heading heading + random 90 - random 10] ;;turtles can only move if the space is not occupied by another turtle and the space is not a wall [if pcolor-of patch-at dx dy != red - 2 [fd .01]]] ask outside [if (ycor >= 15) [ die ]] ;;after the turtles reach their destination, they dieendto update-monitors ;;records the number of turtles left to reach destination set num-inside (count inside) set num-outside (count outside)endto update-plots ;;plots the number of turtles left to reach destination set-current-plot-pen "num-inside" plot num-inside set-current-plot-pen "num-outside" plot num-outsideend@#$#@#$#@GRAPHICS-WINDOW25121720490171713.411000CC-WINDOW303504618624Command CenterBUTTON14218154NILsetupNIL1TOBSERVERSLIDER1899190132num-students-innum-students-in01002511NILSLIDER19150191183num-students-outnum-students-out01007011NILBUTTON1282119154NILgoT1TOBSERVERMONITOR1720182250NILtime31MONITOR17259103308NILnum-inside31MONITOR17319111368NILnum-outside31PLOT771341209482Students LeftTimeStudents0.015.00.0100.0truefalsePENS"default" 100.0 0 -16777216 true"num-inside" 0.01 0 -65413 true"num-outside" 0.01 0 -16776961 trueSWITCH18384150417wait-inside?wait-inside?01-1000SLIDER18464190497wait-timewait-time070.50.11NILSWITCH18420158453wait-outside?wait-outside?11-1000@#$#@#$#@WHAT IS IT?-----------Confliction flow is a problem with movement in many situations. In order to clear the congestion and find the most efficient way to move, the agents must organize for what is best for the group. In this model, the setting of a school provides a problem when students are trying to get from class to class. When class ends, students exit classrooms in large masses, intending to get to the next class within a time limit set by a bell schedule. However, there are students both coming in from the outside and gong out from the inside. Students are slowed down by other students that are crowded around them and by other students trying to go in the opposite direction. This model offers a demonstration of how changing certain parameters can organize student movement within a school's hallways as students are both entering and exiting the building to get to the next class.HOW IT WORKS------------All students are going to the opposite location of where they begin. If a students starts inside, his destination is outside, and vise versa. When each student exits his initial class, he sets his heading toward the hallway. If the student encounters other students in his paths, he will turn to a general right direction to avoid a collision. If he encounters a wall, he will also turn right or left (depending on his current position) toward the direction of the hallway. The student will not be able to go forward if he is blocked by a wall or another student. When the student reaches his destination, he will disappear into the classroom.HOW TO USE IT-------------Press SETUP to set the layout of the model.Press GO to begin the model.NUM-STUDENTS-IN: This slider allows one to change the number of students that originate from inside the building.NUM-STUDENTS-OUT: This slider allows one to change the number of students that originate outside the building.WAIT-INSIDE?/WAIT-OUTSIDE?: These switches allow one to decide if the students inside or outside wait a certain time before trying to get to the next class.WAIT-TIME: This slider allows one to decide how much time the students will wait if either of the wait? switches are engaged.THINGS TO NOTICE----------------The monitor TIME will log how much time has passed. You can use this monitor to see how changes in variables cause a change in time needed for all students to reach their destinations.The monitors NUM-INSIDE and NUM-OUTSIDE keep a count of how many students are still on their way to their destinations.The graph STUDENTS LEFT give a visual to the monitors on how many students are left.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -