Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Netlogo群集计数大小:堆栈溢出(递归太深)_Netlogo - Fatal编程技术网

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

Netlogo群集计数大小:堆栈溢出(递归太深),netlogo,Netlogo,在土地利用模型中,我想计算绿色和红色簇的大小,如下图所示: 所使用的代码与模型库中“Patch Clusters example”中的代码非常相似,唯一的区别是它只计算红色和绿色的补丁。但当我运行它时,Netlogo声明“当观测者运行FIND-CLUSTERS过程调用的ASK时,堆栈溢出(递归太深)错误”。以下是查找群集过程: to find-clusters loop [ ;; pick a random patch that isn't in a cluster yet

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

所使用的代码与模型库中“Patch Clusters example”中的代码非常相似,唯一的区别是它只计算红色和绿色的补丁。但当我运行它时,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
以及“成长群集”过程:

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”,并且永远不会退出循环。考虑将括号放在哪里表示操作顺序。

仔细检查第一条if语句

let seed one-of patches with [cluster = nobody and pcolor = 64 or 
pcolor = 14]
你总是会发现一个补丁是“false and false or true”,并且永远不会退出循环。想一想操作顺序的括号放在哪里