NW扩展和代理导航

时间:2019-04-11 02:43:21

标签: netlogo

我正在尝试弄清如何实现代理导航。我已经建立了模型,以便在疏散模型中的每个“地板”贴片上发芽节点。我也将乌龟链接到各个节点。我想做的是让疏散人员为通往出口的道路画一条路,并同时执行疏散。我使用的png图像是带有白色地板和黑色墙壁/障碍物的基本平面图,我通过在白色地板上萌发节点发现代理人将自动绕过所述障碍物。我知道使用nw扩展名是可能的,但是我未能将其合并到我的模型中。我看过链接行走的乌龟示例,但仍然无法弄清楚。是否有人根据以下代码获得有关如何完成此操作的建议?或关于如何合并寻路的任何建议?任何帮助将不胜感激。

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

1 个答案:

答案 0 :(得分:1)

此答案是我的答案here的简化版本,因此,有关更多详细信息或更灵活的实现,请查看一下。通过这种简单的方法,撤离人员可以检查相邻补丁中的哪个节点最靠近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

要获得类似的行为:

enter image description here

编辑:

将全局变量更改为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