将海龟放在补丁簇的边缘

时间:2014-05-27 03:42:37

标签: netlogo

我正在寻找一种快速将龟放在补丁簇边缘的方法。我尝试了这段代码,但是当我增加学习区域的大小时,我发现它有点慢:

to draw-edges [ID-cluster]
ask patches with [cluster != ID-cluster] [ 
ask neighbors with [cluster = ID-cluster] [ 
  if not any? turtles-here [ 
    sprout 1 [ 
      set shape "x" ] ] ] ] 
end 

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:3)

您目前要求群集外的整个世界检查群集中的邻居。要求 部分群集的补丁检查它们是否在外部补丁旁边应该更快:

to draw-edges [ ID-cluster ]
  ask patches with [
    cluster = ID-cluster and
    any? neighbors with [cluster != ID-cluster] and
    not any? turtles-here
  ] [
    sprout 1
    set shape "x"
  ] 
end