Netlogo 簇计数大小:堆栈溢出(递归太深)

Netlogo cluster count size: stack overflow (recursion too deep)

在土地利用模型中,我想计算绿色和红色簇的大小,如下图所示:

使用的代码与模型库中 "Patch Clusters example" 中的代码非常相似,唯一的区别是它只计算红色和绿色补丁。但是当我 运行 它时,Netlogo 状态为 "stack overflow (recursion too deep) error while observer running ASK called by procedure FIND-CLUSTERS"。这是查找集群的过程:

to find-clusters
  loop [
    ;; pick a random patch that isn't in a cluster yet
    let seed one-of patches with [cluster = nobody and pcolor = 64 or 
pcolor = 14]
    ;; if we can't find one, then we're done!
    if seed = nobody
    [ show-clusters
      stop ]
    ;; otherwise, make the patch the "leader" of a new cluster
    ;; by assigning itself to its own cluster, then call
    ;; grow-cluster to find the rest of the cluster
    ask seed
    [ set cluster self
      grow-cluster ]
  ]
  display
end

和集群增长过程:

to grow-cluster  ;; patch procedure
  ask neighbors4 with [(cluster = nobody) and
    (pcolor = [pcolor] of myself)]
  [ set cluster [cluster] of myself
    grow-cluster ]
end

该消息是什么意思,我该如何解决?谢谢

仔细检查您的第一个 if 语句。

let seed one-of patches with [cluster = nobody and pcolor = 64 or 
pcolor = 14]

你总能找到 "false and false or true" 并且永远不会退出循环的补丁。想想把你的括号放在哪里的操作顺序。