NetLogo:计算补丁集的周长

时间:2017-03-28 21:48:07

标签: netlogo

我在NetLogo中建模区域选择,并希望我的海龟在建立后计算其领土的周长。我一直试图想出如何做到这一点的想法,但尚未找到一个好的方法。有什么想法吗?

enter image description here

_id

提前感谢任何建议!

1 个答案:

答案 0 :(得分:1)

我对你的最后答复的修改:

to setup
  ca
  ask patches with [pxcor > 0 ] [
    set pcolor white
  ]
  crt 1 
end

to go
  ask turtles [
    let blacklist patches with [ pcolor = black ]
    let northpatches patches with [ pycor > 0 ]
    let northred ( northpatches with [ member? self blacklist = false ] )
    ask northred [ set pcolor red ]
    let border northred with [ any? neighbors4 with [ pcolor != red ] ]
    ask border [
      set pcolor blue 
    ]
    print count border
  ]
end

您可以将边框/周边修补程序指定为具有区域的邻居的任何区域修补程序。对你而言,它可能看起来像:

  ask turtles [
    print count territory with [ any? neighbors4 with [owner != myself ] 
    ]
  ]

同样,如果没有您的设置,我无法测试它,因此您必须进行修改。

编辑在下方

要计算边框上的修补程序的边缘,您可以让它们计算属于另一只乌龟的neighbors4。然后,他们可以将它们添加到该龟的周长。例如:

to assess-perimeter  ;;; must be called by a turtle
  print ("Assessing perimeter")
  let current-turtle who
  let temp-per-len 0
  let border-patches patches with [ owner = current-turtle and any? neighbors4 with [ owner != current-turtle ] ]
  show (word "I have " count border-patches " border patches")
  ask border-patches [   
    ;; One way to get each border patch to check each of its neighbors 
    let nobodies 4 - count neighbors4 ;; if any patches are on the edge of the world, returns the number of those edges
    let non-territory-edges count neighbors4 with [ owner != current-turtle ]
    let border-edges nobodies + non-territory-edges
    set temp-per-len temp-per-len + border-edges
  ]
  show (word "My perimeter length: " temp-per-len )
  set perimeter-length temp-per-len
end

如果在所有海龟都选择了整个家庭范围之后调用它,那就是每只乌龟评估其家乡范围的边界。然后,它具有每个边界补丁计数具有不同所有者的neighbors4。我使用“temp-per-len”作为循环中的求和变量,然后用于设置turtles-own“周长”。完整的模型代码,包括设置和定义,here。注意 - 您必须下载或复制代码,模型太笨重,无法以HTML格式运行。

另外,我并没有真正考虑确保这项工作完美 - 我做了一个快速版本并且用手指交叉,但我认为这个想法很有意义,希望能让你开始。