【问题标题】:How to fix "Nothing named ? has been defined" error in NetLogo 6.0.4如何修复 NetLogo 6.0.4 中的“Nothing named ? has been defined”错误
【发布时间】:2019-02-04 07:27:35
【问题描述】:

我下载了修改后的随机集群代码,用于在 NetLogo 建模共享中使用 Millington 版本的修改后的随机集群方法生成中性景观模型。当我单击“generate-landscape”按钮时,代码中的“fill-landscape”过程会导致“Nothing named ? has been defined”错误。

当我创建附加的界面图像并尝试运行下面的相邻代码时。该问题似乎与“发生”报告功能中的问号有关。 reduce 功能未按预期工作。有解决办法吗?查看界面,然后代码如下:

  ifelse ( any? neighbours with [ cluster != nobody ] )  ;; check if there are any assigned patches in neighbourhood
  [

    let covers []

    ask neighbours with [ cluster != nobody ]
    [
      set covers fput cover covers    ;;ask neighbours to add their covers to the list
    ]

    let unique-covers remove-duplicates covers    ;;create a list of unique covers

    let max-cover-count -1                 ;the number of neighbours with the maximum cover
    let max-cover -1                       ;the maximum cover

    ifelse(length unique-covers > 1)
    [
      ;if there is more than one unique-cover
      foreach unique-covers                  ;for each of the unique covers
      [
        let occ occurrences ? covers          ;count how many neighbours had this cover

        ifelse(occ > max-cover-count)        ;if the count is greater than the current maximum count
        [ 
          set max-cover ?                    ;set this as the dominant cover
          set max-cover-count occ            ;update the current maximum count

;---------------

to-report occurrences [x the-list]
  report reduce
    [ifelse-value (?2 = x) [?1 + 1] [?1]] (fput 0 the-list)
end 
;---------------    

假设代码使用 Saura 和 Martinez-Millan (2000) 开发的改进的随机聚类方法生成中性景观模型。但是,错误“Nothing named ? has been defined”会导致代码无法顺利运行。期待想法...

【问题讨论】:

    标签: netlogo


    【解决方案1】:

    NetLogo 5.x 中的旧 ? 语法已被 NetLogo 6 中的新 -> 语法取代。请参阅 https://ccl.northwestern.edu/netlogo/docs/programming.html#anonymous-procedures

    因此,例如,在 NetLogo 5 中,您会这样写:

    foreach [0 1 2 3] [
      print ?
    ]
    

    在 NetLogo 6 中,你写:

    foreach [0 1 2 3] [ x ->
      print x
    ]
    

    【讨论】:

    • 那么你将如何用“?”重写这些部分。如果我可以问的话,在我的代码中?
    • 请编辑您的问题,以便仅显示相关程序
    • @JenB 我已经编辑了问题,只留下了相关程序。我期待你的想法。
    • 抱歉,我还是看不到。我可以看到“发生”程序需要修改,但在漫长的程序中我看不到任何东西。你可以只做可能需要它的部分吗?
    • @JenB 我已经删除了“填充横向”过程中没有“?”的部分。在它们中,只有与“?”直接相关的行节目。我期待你的想法。
    【解决方案2】:

    结合 Bryan 的答案(第一个过程)和 NetLogo 词典(第二个过程)为您提供以下信息。 cmets 表示新位。未测试。

    ifelse ( any? neighbours with [ cluster != nobody ] )
    [ let covers []
      ask neighbours with [ cluster != nobody ]
      [ set covers fput cover covers
      ]
      let unique-covers remove-duplicates covers
      let max-cover-count - 1  ; added a space around subtraction
      let max-cover - 1        ; more spacing
      ifelse(length unique-covers > 1)
      [ foreach unique-covers
        [ this-cover ->                  ; here's the new bit, calling ? 'this-cover'
          let occ occurrences this-cover covers ; passes to the occurrences procedure
          ifelse(occ > max-cover-count)
          [ set max-cover this-cover     ; using the name this-cover again
            set max-cover-count occ
    

    对于出现的情况,您可以直接从 NetLogo Dictionary reduce 示例中获取该过程

    to-report occurrences [#x #the-list]
      report reduce
        [ [occurrence-count next-item] -> ifelse-value (next-item = #x)
            [occurrence-count + 1] [occurrence-count] ] (fput 0 #the-list)
    end
    

    【讨论】:

      猜你喜欢
      • 2021-11-09
      • 1970-01-01
      • 2017-10-16
      • 1970-01-01
      • 2013-05-04
      • 1970-01-01
      • 2019-04-25
      • 2011-01-20
      • 2021-12-25
      相关资源
      最近更新 更多