NetLogo中的疏散建模
我正在从一个简单的平面图上建立一个疏散模型,该平面图有4个房间和一条走廊。我在将代理从房间导航到走廊以及从走廊导航到主出口时遇到问题。请你给我引路好吗 我写的代码在那里:NetLogo中的疏散建模,netlogo,Netlogo,我正在从一个简单的平面图上建立一个疏散模型,该平面图有4个房间和一条走廊。我在将代理从房间导航到走廊以及从走廊导航到主出口时遇到问题。请你给我引路好吗 我写的代码在那里: globals [ wall window door goal-x goal-y n ] patches-own [path?] turtles-own [direction fast? other-nearby] to setup clear-all setup-patch
globals [
wall
window
door
goal-x goal-y
n
]
patches-own [path?]
turtles-own [direction
fast?
other-nearby]
to setup
clear-all
setup-patches
set-default-shape turtles "person" ;makes them look like people
ask n-of number-room1 patches with [pxcor < 71 and pycor < 79 and pxcor > 0 and pycor > 50 and pcolor = black] ; makes turtles sprout on black patches = room1
[
sprout 1 [
set size 5 ;; setting turtle size
facexy 124 79 ; initial direction faceing
set direction 1
set color yellow ;initial color
]
]
ask n-of number-room2 patches with [pxcor < 112 and pycor < 79 and pxcor > 71 and pycor > 50 and pcolor = black] ; makes turtles sprout on black patches= room2
[
sprout 1 [
set size 5 ;; setting turtle size
facexy 124 79 ; initial direction faceing
set direction 1
set color yellow ;initial color
]
]
ask n-of number-room3 patches with [pxcor < 82 and pycor < 36 and pxcor > 0 and pycor > 0 and pcolor = black] ; makes turtles sprout on black patches= room3
[
sprout 1 [
set size 5 ;; setting turtle size
facexy 124 79 ; initial direction faceing
set direction 1
set color yellow ;initial color
]
]
ask n-of number-room4 patches with [pxcor < 132 and pycor < 36 and pxcor > 82 and pycor > 0 and pcolor = black] ; makes turtles sprout on black patches= room4
[
sprout 1 [
set size 5 ;; setting turtle size
facexy 124 79 ; initial direction faceing
set direction 1
set color yellow ;initial color
]
]
reset-ticks
end
to setup-patches
draw-wall;wall, Windows and Doors
draw-exit
;Labels
ask patch 35 54[
set plabel-color white
set plabel "Room1"
]
ask patch 90 54[
set plabel-color white
set plabel "Room2"
]
ask patch 77 44[
set plabel-color white
set plabel "Corridor"
]
ask patch 41 13[
set plabel-color white
set plabel "Room3"
]
ask patch 105 13[
set plabel-color white
set plabel "Room4"
]
end
to draw-wall
ask patches with [pxcor <= 120.42 and pxcor >= 0 and pycor = 79]
[set pcolor blue]
ask patches with [pxcor <= 132 and pxcor >= 129.57 and pycor = 79]
[set pcolor blue]
ask patches with [pycor <= 79 and pycor >= 0 and pxcor = 132]
[set pcolor blue]
ask patches with [pycor <= 79 and pycor >= 0 and pxcor = 0]
[set pcolor blue]
ask patches with [pxcor <= 34.43 and pxcor >= 0 and pycor = 0]
[set pcolor blue]
ask patches with [pxcor <= 132 and pxcor >= 43.58 and pycor = 0]
[set pcolor blue]
ask patches with [pxcor <= 112 and pxcor >= 108.57 and pycor = 50]
[set pcolor blue]
ask patches with [pxcor <= 49.42 and pxcor >= 0 and pycor = 50]
[set pcolor blue]
ask patches with [pxcor <= 84.425 and pxcor >= 79.575 and pycor = 36]
[set pcolor blue]
ask patches with [pxcor <= 70.425 and pxcor >= 0 and pycor = 36]
[set pcolor blue]
ask patches with [pxcor <= 132 and pxcor >= 93.575 and pycor = 36]
[set pcolor blue]
ask patches with [pycor <= 79 and pycor >= 50 and pxcor = 71]
[set pcolor blue]
ask patches with [pycor <= 79 and pycor >= 50 and pxcor = 112]
[set pcolor blue]
ask patches with [pycor <= 36 and pycor >= 0 and pxcor = 82]
[set pcolor blue]
ask patches with [pxcor <= 99.42 and pxcor >= 58.57 and pycor = 50]
[set pcolor blue]
end
to draw-exit
;room1
ask patches with [pxcor <= 58.57 and pxcor >= 49.42 and pycor = 50]
[set pcolor green]
;room2
ask patches with [pxcor <= 108.57 and pxcor >= 99.42 and pycor = 50]
[set pcolor green]
;room3
ask patches with [pxcor <= 79.575 and pxcor >= 70.425 and pycor = 36]
[set pcolor green]
;room4
ask patches with [pxcor <= 93.575 and pxcor >= 84.425 and pycor = 36]
[set pcolor green]
;main exit
ask patches with [pxcor <= 129.57 and pxcor >= 120.42 and pycor = 79]
[set pcolor red]
;second exit
ask patches with [pxcor <= 43.58 and pxcor >= 34.43 and pycor = 0]
[set pcolor red]
end
to go
ask turtles [walk]
tick
end
to walk
let room1 patches with [pxcor < 71 and pycor < 79 and pxcor > 0 and pycor > 50]
let room2 patches with [pxcor < 112 and pycor < 79 and pxcor > 71 and pycor > 50]
let room3 patches with [pxcor < 82 and pycor < 36 and pxcor > 0 and pycor > 0]
let room4 patches with [pxcor < 132 and pycor < 36 and pxcor > 82 and pycor > 0]
let corridor patches with [pxcor < 132 and pycor < 50 and pxcor > 0 and pycor > 36]
let exitpoint patches with [pxcor < 132 and pycor < 79 and pxcor > 112 and pycor > 50]
ask turtles-on room1
[face one-of patches with [pxcor <= 58.6 and pxcor >= 49.42 and pycor = 50]
fd 0.5
]
ask turtles-on room2
[ face one-of patches with [pxcor <= 108.6 and pxcor >= 99.5 and pycor = 50]
fd 0.5
]
ask turtles-on room3
[ face one-of patches with [pxcor <= 79 and pxcor >= 71 and pycor = 36]
fd 0.5
]
ask turtles-on room4
[ face one-of patches with [pxcor <= 93.6 and pxcor >= 84.5 and pycor = 36]
fd 0.5
]
ask turtles-on corridor
[ face one-of patches with [pxcor <= 132 and pxcor >= 112 and pycor = 50]
fd 1
]
ask turtles-on exitpoint
[ face one-of patches with [pxcor <= 129 and pxcor >= 121 and pycor = 79]
fd 1
]
end
我可以将代理从房间导航到每个房间的门,但我想在走廊中输入代理,然后从走廊进入主出口。我刚刚修改了您的代码,在walk下面添加了doors变量。这告诉那些触摸到绿色区域(你的门)的海龟们向前走两步进入走廊。一旦它们进入道路,就已经有了向出口点移动的命令
to walk
let room1 patches with [pxcor < 71 and pycor < 79 and pxcor > 0 and pycor > 50]
let room2 patches with [pxcor < 112 and pycor < 79 and pxcor > 71 and pycor > 50]
let room3 patches with [pxcor < 82 and pycor < 36 and pxcor > 0 and pycor > 0]
let room4 patches with [pxcor < 132 and pycor < 36 and pxcor > 82 and pycor > 0]
let corridor patches with [pxcor < 123 and pycor < 50 and pxcor > 0 and pycor > 36]
let exitpoint patches with [pxcor < 130 and pycor < 80 and pxcor > 122 and pycor > 38]
let doors patches with [pcolor = green]
ask turtles-on room1
[face one-of patches with [pxcor <= 58.6 and pxcor >= 49.42 and pycor = 50]
fd 0.5
]
ask turtles-on room2
[ face one-of patches with [pxcor <= 108.6 and pxcor >= 99.5 and pycor = 50]
fd 0.5
]
ask turtles-on room3
[ face one-of patches with [pxcor <= 79 and pxcor >= 71 and pycor = 36]
fd 0.5
]
ask turtles-on room4
[ face one-of patches with [pxcor <= 93.6 and pxcor >= 84.5 and pycor = 36]
fd 0.5
]
ask turtles-on corridor
[ face one-of patches with [pxcor <= 130 and pxcor >= 125 and pycor = 45]
fd 1
]
ask turtles-on exitpoint
[ face one-of patches with [pxcor <= 129 and pxcor >= 121 and pycor = 79]
fd 1
]
ask turtles-on doors
[ face one-of patches with [pxcor = 77 and pycor = 44 ]
fd 2
]
如果它们位于门板上,只需向前移动0.5,会发生什么情况?