在 NetLogo 中使用 "n-of" 到 select 特定补丁时出错
Error using "n-of" in NetLogo to select specific patches
我是 NetLogo 的新手,我正在研究一个森林砍伐模型,农民是我的代理人。他们有一个 ID 变量 (lotid-farmer) 与他们拥有的补丁 (lotid-patch) 中的 ID 相匹配。基本上,农民检查他们需要多少金钱和劳动力来砍伐一些森林斑块或放弃他们农场中的一些农业斑块(pcolor = 红色)。在后一个程序结束时,农民计算出 "n-aband" 值,这是他们将在农场内(随机)放弃的补丁数量(pcolor = 黄色)。这是应该执行此操作的代码段:
ask farmers [
...
if pcolor = red and lotid-patch = [ lotid-farmer ] of self [ ; Asks the farmer to randomly convert a # of the agricultural patches without maintenance to regrowth...
ask n-of n-aband patches [ set pcolor yellow ] ; ... among all agricultural patches own by the farmer
]
...
然而,当我 运行 代码时,农民开始 "abandoning" 补丁,他们 不拥有 。我认为那是因为我在使用 "ask n-of n-aband patches" 时没有设置正确的 "restriction" 但我认为这应该隐含在我在上面一行中的 "if" 语句中,不是吗?我也试过:
ask n-of n-aband patches with [ pcolor = red and lotid-patch = [ lotid-farmer ] of self ] [ set pcolor yellow ]
但是我运行出错了:
A patch can't access a turtle variable without specifying which turtle.
error while patch 390 414 running OF
called by procedure CALCULATE-DEFORESTATION
called by procedure GO
called by Button 'Go'
关于如何让这篇文章发挥作用有什么建议吗?提前谢谢你。
为此,您只需考虑农民拥有的补丁。
ask farmers [
let _id lotid-farmer
let _candidates (patches with [lotid-patch = _id and pcolor = red])
let _n-aband min (list n-aband count _candidates)
ask n-of _n-aband _candidates [set pcolor yellow]
]
但是...不使用 ID。与代理商合作。让每个补丁都有一个所有者,
这是一个农民或没有人。让每个农民维护一个列表(或代理集)
它拥有的补丁数。
我是 NetLogo 的新手,我正在研究一个森林砍伐模型,农民是我的代理人。他们有一个 ID 变量 (lotid-farmer) 与他们拥有的补丁 (lotid-patch) 中的 ID 相匹配。基本上,农民检查他们需要多少金钱和劳动力来砍伐一些森林斑块或放弃他们农场中的一些农业斑块(pcolor = 红色)。在后一个程序结束时,农民计算出 "n-aband" 值,这是他们将在农场内(随机)放弃的补丁数量(pcolor = 黄色)。这是应该执行此操作的代码段:
ask farmers [
...
if pcolor = red and lotid-patch = [ lotid-farmer ] of self [ ; Asks the farmer to randomly convert a # of the agricultural patches without maintenance to regrowth...
ask n-of n-aband patches [ set pcolor yellow ] ; ... among all agricultural patches own by the farmer
]
...
然而,当我 运行 代码时,农民开始 "abandoning" 补丁,他们 不拥有 。我认为那是因为我在使用 "ask n-of n-aband patches" 时没有设置正确的 "restriction" 但我认为这应该隐含在我在上面一行中的 "if" 语句中,不是吗?我也试过:
ask n-of n-aband patches with [ pcolor = red and lotid-patch = [ lotid-farmer ] of self ] [ set pcolor yellow ]
但是我运行出错了:
A patch can't access a turtle variable without specifying which turtle.
error while patch 390 414 running OF
called by procedure CALCULATE-DEFORESTATION
called by procedure GO
called by Button 'Go'
关于如何让这篇文章发挥作用有什么建议吗?提前谢谢你。
为此,您只需考虑农民拥有的补丁。
ask farmers [
let _id lotid-farmer
let _candidates (patches with [lotid-patch = _id and pcolor = red])
let _n-aband min (list n-aband count _candidates)
ask n-of _n-aband _candidates [set pcolor yellow]
]
但是...不使用 ID。与代理商合作。让每个补丁都有一个所有者, 这是一个农民或没有人。让每个农民维护一个列表(或代理集) 它拥有的补丁数。