【发布时间】:2020-04-01 21:28:16
【问题描述】:
我正在研究一个土地利用模型,其中包含一个森林世界,其中海龟(小农和公司)有能力将森林变成农田。我想介绍一个功能,海龟“拥有”它们转换的补丁,并且能够稍后重新访问它们以使这些补丁获得认证。主要问题是,当海龟移动到农田斑块以获得认证时,它们不仅会移动到它们“拥有”的那些,而且还会跳到世界其他海龟的农田斑块并对其进行认证。我尝试了几种不同的解决方法,但最终我似乎遇到了同样的两个问题:
#1 - 错误:不能在补丁上下文中使用 who
我想使用“谁”变量将农田块标记为属于转换该块的乌龟,例如,乌龟 0 进入森林,将其转换为农田,那块农田应该是由海龟 0 '拥有',即,变量所拥有的补丁应该等同于海龟的'谁'。这里的问题是“谁”是海龟自己的变量。因此,当我在补丁上下文中使用它时,它会产生错误。例如,ask smallholders [move-to one-of patches with [[owner = who]] --> 错误。
#2 - 无法设置全局变量 = 'who'
第二,我试图通过使用代理变量来解决这个问题:一个名为“所有者 ID”的全局变量。我会使用set owner-ID who 将海龟的个人编号印在所有者 ID 上。这似乎在某种程度上起作用,即补丁的“所有者”变量对应于转换补丁的海龟。在计算经过认证的和传统的农田龟拥有多少块时,它也可以工作(参见下面的set-land-ownership 命令)。然而,当smallholders-certify-crop-land 命令被触发时,海龟不会坚持自己拥有的补丁,而是“跳跃”到世界各地。当通过命令中心ask turtles [print owner-ID] 提示海龟时,它们都返回相同的所有者 ID 值。我觉得我的移动到命令行可能有错误,但我找不到它。
总结和问题 我希望农田斑块由转换它们的海龟“拥有”,并且希望海龟在认证农田斑块时只移动到它们“拥有”的斑块,而不是它们不拥有的斑块。我想我的问题围绕着是否有可能在补丁上下文中以某种方式使用“谁”变量。而且,如果不是,那么解决该问题的好方法是什么。
相关代码如下(我希望)!
globals [owner-ID]
turtles-own [conventional-land-ownership certified-land-ownership]
patches-own [owned-by owner certified?]
to setup [
ask patches [
set pcolor green ;; green = forest
set certified? "no"
set owner "nobody"
]
]
to go
ask turtles [set-land-ownership]
ask smallholders [check-smallholder-status]
tick
end
to set-land-ownership
ask smallholders [
set owner-ID who
set conventional-land-ownership count patches with [owner = owner-ID and certified? = "no"]
set certified-land-ownership count patches with [owner = owner-ID and certified? = "yes"]
]
end
to check-smallholder-status
if wealth >= 0 and (conventional-land-ownership + certified-land-ownership) < SH_max-land-ownership [
smallholders-choose-activity
]
if wealth < 0 [
set color red
set shape "cow skull"
]
if (conventional-land-ownership + certified-land-ownership) >= SH_max-land-ownership [
set color orange + 2
]
end
;; smallholders-choose-activities is a reporter-based command where turtles choose the most economical option available. One of the outcomes is: smallholders-certify-crop-land
to smallholders-certify-crop-land
let available-patch max-one-of patches with [owner = owner-ID and certified? = "no"] [count neighbors with [certified? = "yes"]]
ifelse not any? turtles-on available-patch [
move-to available-patch
]
[]
set wealth wealth - smallholder-certification-cost
set pcolor brown + 1
set certified? "yes"
end
【问题讨论】:
标签: netlogo