Netlogo 在疏散模型中行走

Netlogo 在疏散模型中行走,netlogo,Netlogo,我正在模拟一层楼的疏散行为,我编写了代码,Netlogo没有任何错误,但我不知道为什么我的模型不起作用 to go ask turtles with [pcolor = yellow] [walk] tick end to walk ;room1 ask turtles with [pxcor < 71 and pycor < 79 and pxcor > 0 and pycor > 50] [ face one-of patches with [

我正在模拟一层楼的疏散行为,我编写了代码,Netlogo没有任何错误,但我不知道为什么我的模型不起作用

to go
  ask turtles with [pcolor = yellow] [walk] 
  tick
end

to walk
  ;room1
  ask turtles with [pxcor < 71 and pycor < 79 and pxcor > 0 and pycor > 50]
  [ face one-of patches with [pxcor <= 58.57 and pxcor >= 49.42 and pycor = 50]] 
  ;room2
  ask turtles with [pxcor < 112 and pycor < 79 and pxcor > 71 and pycor > 50]
  [ face one-of patches with [pxcor <= 108.57 and pxcor >= 99.42 and pycor = 50]] 
  ;room3
  ask turtles with [pxcor < 82 and pycor < 36 and pxcor > 0 and pycor > 0]
  [face one-of patches with [pxcor <= 79.575 and pxcor >= 70.425 and pycor = 36]] 
  ;room4
  ask turtles with [pxcor < 132 and pycor < 36 and pxcor > 82 and pycor > 0]
  [face one-of patches with [pxcor <= 93.575 and pxcor >= 84.425 and pycor = 36]] 
  fd 0.5

  ;corridor
  ask turtles with [pxcor < 132 and pycor < 50 and pxcor > 0 and pycor > 36]
  [face one-of patches with [pxcor <= 132 and pxcor >= 112 and pycor = 50]] 
  ;exit
  ask turtles with [pxcor < 132 and pycor < 79 and pxcor >= 112 and pycor >= 50]
  [face one-of patches with [pxcor <= 129.57 and pxcor >= 120.42 and pycor = 79]] 
  fd 1

end

您的问题不是特别清楚,因为“不起作用”没有提供有关问题的足够信息。为了得到更有用的答案,你应该描述你期望的行为和你实际得到的行为。尽管如此,您的代码中存在一个明显的问题,这可能就是您所要问的

在你的go声明中,你让海龟们称之为步行程序。在漫游过程中,ask turtles括号内有face命令,但括号外有fd命令。我假设这是有意的,你要做的是让四个if语句使海龟面向你想要的方向,然后fd移动它

然而,在行走过程中,你重复了询问海龟。你可能想做的只是改变一只海龟的头部,也就是被要求行走的海龟

to go
  ask turtles with [pcolor = yellow] [walk] 
  tick
end

to walk
  ;room1
  if pxcor < 71 and pycor < 79 and pxcor > 0 and pycor > 50
  [ face one-of patches with [pxcor <= 58.57 and pxcor >= 49.42 and pycor = 50]
  ] 
  ;room2
  if pxcor < 112 and pycor < 79 and pxcor > 71 and pycor > 50
  [ face one-of patches with [pxcor <= 108.57 and pxcor >= 99.42 and pycor = 50]
  ] 
  ;room3
  if pxcor < 82 and pycor < 36 and pxcor > 0 and pycor > 0
  [ face one-of patches with [pxcor <= 79.575 and pxcor >= 70.425 and pycor = 36]
  ] 
  ;room4
  if pxcor < 132 and pycor < 36 and pxcor > 82 and pycor > 0
  [ face one-of patches with [pxcor <= 93.575 and pxcor >= 84.425 and pycor = 36]
  ] 
  fd 0.5

  ;corridor
  if pxcor < 132 and pycor < 50 and pxcor > 0 and pycor > 36
  [ face one-of patches with [pxcor <= 132 and pxcor >= 112 and pycor = 50]
  ] 
  ;exit
  if pxcor < 132 and pycor < 79 and pxcor >= 112 and pycor >= 50
  [face one-of patches with [pxcor <= 129.57 and pxcor >= 120.42 and pycor = 79]
  ] 
  fd 1

end
请注意,这与您的不同,因为我不知道哪些补丁是黄色的。您必须修改以处理此问题


我将ask turtles移到过程中的原因是,补丁集只创建一次。如果您打算在其他地方使用这些房间等,将它们作为全局变量并将其结构放入您的设置中是值得的。

@JenB您所说的所有更改我都做了。我有一个4个房间的平面图,所有房间都在走廊中开放,走廊尽头有一个主出口。我想让我的代理人从房间到走廊,从走廊到主出口。我有一个问题,代理停留在房间的出口门,他们不会从房间穿过走廊,在所有代理都在走廊后,我想引导他们到主出口。请您指导我。您还可以为所有门创建一个补丁集,并在门上添加一行ask turtles[rt 50 lt 50 fd 0.5],这将使它们保持与到达门前大致相同的方向。
to go
  ask turtles with [pcolor = yellow] [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 and pxcor >= 50 and pycor = 50
    fd 0.5
  ]
  ask turtles-on room2
  [ face one-of patches with [pxcor <= 108 and pxcor >= 100 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 and pxcor >= 85 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