如何解决NetLogo代码中的“堆栈溢出(递归太深)”错误

时间:2019-02-06 20:46:24

标签: netlogo

我正在尝试解决NetLogo中的代码出现的“堆栈溢出(递归太深)”错误。此代码生成补丁集,以将其指定为中性景观模型中的土地覆盖类。但是,设置覆盖过程将导致“堆栈溢出(递归太深)”错误。

我尝试在grow-cover_cluster中的过程中注释掉grow-cover_cluster调用,但是它不能解决问题

to generate-landscape
  set cluster-area-list []
  set_random_seeds ;; randomly distribute 
  cluster seeds (Step 1 in Saura & Martinez-Millan 2000 p.664)
  set-cover ;; identify and label clusters (Steps 2 & 3 in above)
  fill_landscape ;; fill remaining patches to dominant neighbour     
  ask patches [ set pcolor (cover * 10) + 5 ] ;; color patches by cover 
end

to set-cover
  loop
   [
    let seed one-of patches with [ ( cluster = nobody and pcolor = blue ) ]   
    ;; pick a random seed we haven't labelled yet
    if seed = nobody ;; if we have labelled all seeds stop
      [ stop ]
    ask seed
      [
        set cluster self ;; make the seed the "leader" of a new cluster
        set cover ( random Number-of-Types ) ;; assign as cover "leader" 
        grow-cover_cluster ;; generate rest of cluster
        set cluster-area-list fput count patches with [cluster = myself] 
        cluster-area-list
     ]
   ]
end

to grow-cover_cluster
  without-interruption 
  [
    let neighbours nobody
    ifelse(Neighbourhood = "Moore")
    [ 
    set neighbours neighbors with [ cluster = nobody and pcolor = [pcolor] of myself ] ]
[ 
   set neighbours neighbors4 with [ cluster = nobody and pcolor = [pcolor] of myself ] ]
    ask neighbours
    [
      set cluster [cluster] of myself ;;make neighboring patch to seed cluster
      set cover [cover] of myself ;;make neighboring patch to patch cover
      set cluster_ID [cluster_ID] of myself
      ;grow-cover_cluster ;;recursive call!
    ]
   ]
end

与最终在中性景观模型中形成覆盖类相比,代码应生成随机种子的补丁,将其他周围的补丁累积起来以形成簇。但是,上述当前形式的代码会产生“堆栈溢出(递归太深)”错误。

0 个答案:

没有答案