在土地利用模型中,我想计算绿色和红色星团的大小,如下图所示:
使用的代码非常类似于" Patch Clusters示例"来自模型库,唯一的区别是它只计算红色和绿色补丁。但是当我运行它时,Netlogo声明"堆栈溢出(递归太深)错误,同时运行ASK的观察者调用过程FIND-CLUSTERS"。这是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
该消息的含义是什么?如何解决?感谢。
答案 0 :(得分:2)
仔细检查你的第一个if语句。
let seed one-of patches with [cluster = nobody and pcolor = 64 or
pcolor = 14]
您将始终找到“假,假或真”的补丁,并且永远不会退出循环。想一想把括号括在哪里作为操作的顺序。