NW 扩展和代理导航

NW Extension and Agent Navigation

我正在研究如何实现代理导航。我已将我的模型设置为在我的疏散模型中的每个 "floor" 补丁上发芽节点。我还 link 将海龟编辑到各自的节点。我想要做的是让撤离人员绘制一条通往出口的路径并同时执行撤离。我使用的 png 图像是一个带有白色地板和黑色 walls/obstacles 的基本平面图,我认为通过在白色地板上出现节点,代理将自动绕过所述障碍物。我知道使用 nw 扩展是可能的,但是我未能将它合并到我的模型中。我看过 link 行走的乌龟示例,但仍然无法弄清楚。有没有人对如何根据下面的代码完成这项工作有任何建议?或关于如何在一般情况下纳入寻路的任何建议?任何帮助将不胜感激。

breed [nodes node]
breed [cells cell]
breed [evacuees evacuee]

evacuees-own
 [ target   
  direction  
 ]


to setup
clear-all

set-default-shape turtles "person";
import-pcolors "floorplan.png"


ask n-of evacnum patches with [pcolor = white]
   [
     sprout-evacuees 1 [
     set size 7
     set color green
    ;set speed 1 + random-float 1.5


  ifelse random 2 = 0
    [ set direction 1     
       ]
   [ set direction -1    
      ]




  ]
  ]


  ask patches with [ pcolor = white ] [

 sprout-nodes 1 [
  set size 0.5
  set shape "circle"
  set color grey
  ]
 ]

 ask nodes [
 create-links-with turtles-on neighbors4 [
  set color grey
 ]
 ]

ask patch 146 199
 [

  sprout-cells 1 [
    set size 1.5
    set shape "box"
    set color yellow
  ]
  ]

 ask evacuees
 [ set target one-of min-n-of 5 nodes [distance myself]
 face target
  ]


  reset-ticks
  end

  to go
  move
  tick
  end

  to move
  ask evacuees

   [
    walk
   forward 0.25
   if distance target < 0.2
   [ set target one-of min-n-of 5 nodes [distance myself]
   ]
   face target
    ]



   end


   to walk
    if not wall? (90 * direction) and wall? (135 * direction) [ rt 90 * 
   direction ]
   while [wall? 0] [ lt 90 * direction ]
   end

   to-report wall? [angle]
   report black = [pcolor] of patch-right-and-ahead angle 1
   end

此答案是我的答案 的简化版本,因此有关更多详细信息或更灵活的实现,请查看它。这种简单的方法让疏散人员检查相邻补丁上的哪些节点最接近 exit-node,然后他们移动到该节点。根据您上面的代码进行简单设置(但没有平面布置图,我看不到它已发布):

extensions [ nw ]

breed [nodes node]
breed [cells cell]
breed [evacuees evacuee]
globals [ exit-node ]

to setup
  clear-all

  set-default-shape turtles "person";
  ask patches [ set pcolor white ]
  ask patches with [ pxcor mod 5 = 0 ] [
    set pcolor black 
  ]
  ask patches with [ pycor mod 10 = 0 ] [
    set pcolor white 
  ]

  ask n-of 5 patches with [pcolor = white] [
    sprout-evacuees 1 [
      set size 2
      set color green
    ]
  ]

  ask patches with [ pcolor = white ] [  
    sprout-nodes 1 [
      set size 0.5
      set shape "circle"
      set color grey
    ]
  ]

  ask nodes [
    create-links-with nodes-on neighbors4 [
      set color grey
    ]
  ]

  ask patch 16 0 [
    sprout-cells 1 [
      set size 1.5
      set shape "box"
      set color yellow
    ]
  ]
  ask one-of cells [
    set exit-node one-of nodes-here 
  ]
  reset-ticks
end

现在,一些简单的移动代码:

to go
  ask evacuees [
    let target min-one-of nodes-on neighbors4 [
      length nw:turtles-on-path-to exit-node
    ] 
    move-to target
    if any? cells-here [
      show "I HAVE EVACUATED!"
      die
    ]
  ]  
  tick
end

获得类似的行为:

编辑:

将全局变量更改为 globals [ exits ] 并替换为:

  ask patch 16 0 [
    sprout-cells 1 [
      set size 1.5
      set shape "box"
      set color yellow
    ]
  ]
  ask one-of cells [
    set exit-node one-of nodes-here 
  ]

有了这个:

  set exits nodes-on ( patch-set patch 16 0 patch -16 0 )

  ask exits [
    hatch-cells 1 [
      set size 1.5
      set shape "box"
      set color yellow
    ]
  ]

并且您应该能够使用下面经过修改的 go 让疏散人员寻找最近的门:

to go
  ask evacuees [
    let my-node one-of nodes-on patch-here
    let my-exit min-one-of exits [
      length nw:turtles-on-path-to my-node
    ]
    let target min-one-of nodes-on neighbors4 [
      length nw:turtles-on-path-to my-exit
    ]
    move-to target
    if any? cells-here [
      show "I HAVE EVACUATED!"
      die
    ]
  ]
  tick
end