【问题标题】:Netlogo cluster count size: stack overflow (recursion too deep)Netlogo 簇计数大小:堆栈溢出(递归太深)
【发布时间】:2018-06-11 09:27:09
【问题描述】:

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

使用的代码与模型库中的“补丁簇示例”中的代码非常相似,唯一的区别是它只计算红色和绿色补丁。但是当我运行它时,Netlogo 状态“堆栈溢出(递归太深)错误,而观察者运行由过程 FIND-CLUSTERS 调用的 ASK”。这是查找集群的过程:

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

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

【问题讨论】:

    标签: netlogo


    【解决方案1】:

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

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

    你总会找到一个“假和假或真”的补丁,并且永远不会退出循环。考虑将括号放在哪里以表示操作顺序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-12
      • 2012-08-20
      • 1970-01-01
      • 2019-12-01
      • 2015-06-17
      • 2015-04-04
      • 2017-01-20
      • 2018-12-02
      相关资源
      最近更新 更多