我下载了修改后的随机集群代码,用于使用 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
;---------------
Run Code Online (Sandbox Code Playgroud)
该代码假设使用由 Saura 和 Martinez-Millan (2000) 开发的修改后的随机聚类方法生成中性景观模型。但是,错误“Nothing named ? has been defined”使代码无法顺利运行。期待思考……
?NetLogo 5.x 中的旧语法被->NetLogo 6 中的新语法替换。请参阅https://ccl.northwestern.edu/netlogo/docs/programming.html#anonymous-procedures
因此,例如,在 NetLogo 5 中,您将编写:
foreach [0 1 2 3] [
print ?
]
Run Code Online (Sandbox Code Playgroud)
在 NetLogo 6 中,你写:
foreach [0 1 2 3] [ x ->
print x
]
Run Code Online (Sandbox Code Playgroud)
Bryan 的答案(第一个过程)和 NetLogo 词典(第二个过程)的组合为您提供以下内容。注释指出了新的位。未测试。
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
Run Code Online (Sandbox Code Playgroud)
reduce对于出现的情况,您可以直接从 NetLogo Dictionary示例中获取过程
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2056 次 |
| 最近记录: |