NetLogo - 海龟在补丁上印记 'who' 并且只移动到与其 'who' 匹配的补丁
NetLogo - turtles to imprint 'who' on patches and only move-to patches which match their 'who'
我正在研究一个以森林世界为特色的土地利用模型,其中海龟(小农户和公司)有能力将森林变成农田。我想介绍一个功能,可以海龟 'own' 他们转换的补丁,并且能够在以后重新访问它们以获得这些补丁的认证。主要问题是,当海龟迁移到农田块以获得认证时,它们不仅会迁移到它们 'own' 的那些区域,还会跳到世界各地其他海龟的农田块并对其进行认证。我尝试了几种不同的解决方法,但我似乎 运行 最终遇到了同样的两个问题:
#1 - 错误:无法在补丁上下文中使用 who
我想使用 'who' 变量将耕地斑块标记为属于转换该斑块的乌龟,例如,乌龟 0 进入森林,将其转换为耕地,然后该斑块耕地的面积应该是海龟 0 的 'owned',即变量拥有的斑块应该等于海龟的 'who'。这里的问题是 'who' 是海龟自己的变量。因此,当我在补丁上下文中使用它时,它会产生错误。例如,ask smallholders [move-to one-of patches with [[owner = who]]
--> 错误。
#2 - 无法设置全局变量 = 'who'
第二,我试图通过使用一个代理变量来解决这个问题:一个名为 'owner-ID' 的全局变量。我会使用 set owner-ID who
将海龟的个人编号印在所有者 ID 上。这似乎在某种程度上起作用,即补丁的 'owner' 变量对应于转换补丁的海龟。它也适用于计算有多少块经过认证的和传统的农田龟拥有(参见下面的 set-land-ownership
命令)。但是,当 smallholders-certify-crop-land
命令被触发时,海龟不会粘在它们拥有的补丁上,而是 'jump' 在世界各地。当通过命令中心 ask turtles [print owner-ID]
提示海龟时,它们都 return 相同的所有者 ID 值。我觉得我的 move-to 命令行可能有错误,但我就是找不到它。
总结与问题
我希望耕地块成为 'owned by' 转换它们的海龟,并希望海龟在验证耕地块时仅移动到它们 'own' 的块,而不是它们不拥有的块。我想我的问题围绕着是否有可能以某种方式在补丁上下文中使用 'who' 变量。而且,如果没有,那么该问题的解决方法应该是什么样子。
相关代码如下(希望如此)!
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
您的第一种方法绝对是正确的方法,只需稍作调整即可解决。
ask smallholders [move-to one-of patches with [owner = who]]
应该是
ask smallholders [move-to one-of patches with [owner = [who] of myself]]
在 with
之后的块中,变量在补丁的上下文中,但 myself
指的是要求补丁检查其所有者的代理,在这种情况下,每个小农。然后不需要全局变量 owner-ID
。如果您在其余代码中执行此操作,您的第二个问题可能会自行解决。
但是,一般来说最好不要使用 who
号码,而是直接参考代理。 (当您将 owner
初始化为 nobody
,即 "no agent" 时,您实际上已经隐含地采用了这种方法。)我看不到您要求补丁设置其所有者的位置,但是如果smallholder
在补丁上,smallholder
会
ask patch-here [set owner myself]
上面的行现在会变成
ask smallholders [move-to one-of patches with [owner = myself]]
NetLogo 大师建议我们仅在没有其他方法时才使用 who
数字。
我正在研究一个以森林世界为特色的土地利用模型,其中海龟(小农户和公司)有能力将森林变成农田。我想介绍一个功能,可以海龟 'own' 他们转换的补丁,并且能够在以后重新访问它们以获得这些补丁的认证。主要问题是,当海龟迁移到农田块以获得认证时,它们不仅会迁移到它们 'own' 的那些区域,还会跳到世界各地其他海龟的农田块并对其进行认证。我尝试了几种不同的解决方法,但我似乎 运行 最终遇到了同样的两个问题:
#1 - 错误:无法在补丁上下文中使用 who
我想使用 'who' 变量将耕地斑块标记为属于转换该斑块的乌龟,例如,乌龟 0 进入森林,将其转换为耕地,然后该斑块耕地的面积应该是海龟 0 的 'owned',即变量拥有的斑块应该等于海龟的 'who'。这里的问题是 'who' 是海龟自己的变量。因此,当我在补丁上下文中使用它时,它会产生错误。例如,ask smallholders [move-to one-of patches with [[owner = who]]
--> 错误。
#2 - 无法设置全局变量 = 'who'
第二,我试图通过使用一个代理变量来解决这个问题:一个名为 'owner-ID' 的全局变量。我会使用 set owner-ID who
将海龟的个人编号印在所有者 ID 上。这似乎在某种程度上起作用,即补丁的 'owner' 变量对应于转换补丁的海龟。它也适用于计算有多少块经过认证的和传统的农田龟拥有(参见下面的 set-land-ownership
命令)。但是,当 smallholders-certify-crop-land
命令被触发时,海龟不会粘在它们拥有的补丁上,而是 'jump' 在世界各地。当通过命令中心 ask turtles [print owner-ID]
提示海龟时,它们都 return 相同的所有者 ID 值。我觉得我的 move-to 命令行可能有错误,但我就是找不到它。
总结与问题 我希望耕地块成为 'owned by' 转换它们的海龟,并希望海龟在验证耕地块时仅移动到它们 'own' 的块,而不是它们不拥有的块。我想我的问题围绕着是否有可能以某种方式在补丁上下文中使用 'who' 变量。而且,如果没有,那么该问题的解决方法应该是什么样子。
相关代码如下(希望如此)!
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
您的第一种方法绝对是正确的方法,只需稍作调整即可解决。
ask smallholders [move-to one-of patches with [owner = who]]
应该是
ask smallholders [move-to one-of patches with [owner = [who] of myself]]
在 with
之后的块中,变量在补丁的上下文中,但 myself
指的是要求补丁检查其所有者的代理,在这种情况下,每个小农。然后不需要全局变量 owner-ID
。如果您在其余代码中执行此操作,您的第二个问题可能会自行解决。
但是,一般来说最好不要使用 who
号码,而是直接参考代理。 (当您将 owner
初始化为 nobody
,即 "no agent" 时,您实际上已经隐含地采用了这种方法。)我看不到您要求补丁设置其所有者的位置,但是如果smallholder
在补丁上,smallholder
会
ask patch-here [set owner myself]
上面的行现在会变成
ask smallholders [move-to one-of patches with [owner = myself]]
NetLogo 大师建议我们仅在没有其他方法时才使用 who
数字。