【发布时间】:2017-03-28 19:49:29
【问题描述】:
我正在 NetLogo 中为区域选择建模。当乌龟建立一个领地时,它也会建立一个不受欢迎的斑块的记忆(称为“黑名单”的代理集),然后需要在为该领地选择新斑块时避开这些斑块。在决定下一个要申请的补丁时,会创建一个名为“可用目的地”的新补丁集,其中基于几个因素报告“最高值”(见下文)。我希望 available-destinations 检查补丁是否是海龟黑名单的一部分,并排除这些补丁。但是,在补丁程序中,我无法弄清楚如何调用海龟的黑名单。有什么建议吗?提前致谢!
这是我的主要代码:
patches-own
[
owner ;; turtle who claims patch for territory
benefit ;; i.e., food
avoiding ;; turtle who is avoiding this patch
]
turtles-own
[
start-patch ;; my territory center
destination ;; my next patch to claim
territory ;; patches I own
blacklist ;; my agentset of patches to avoid
]
to pick-patch
if patch-here = start-patch [ set destination highest-value ]
if destination != nobody [ travel ]
end
to travel
;; there are a number of actions here, but the relevant one is:
;; check if owned, and avoid it:
if patch-here != destination
[ if owner != nobody ;; if it's owned...
[ if owner != self ;; and not by me...
[ avoid-obstacle
move-to start-patch ]
]
]
end
to avoid-obstacle
ask destination [ set avoiding myself ]
set blacklist (patches with [avoiding = myself])
end
to-report highest-value ;; <--- source of error since using "blacklist"
let available-destinations edge-patches with [blacklist != myself]
report max-one-of available-destinations ([benefit-to-me / cost-to-me])
end
to-report benefit-to-me
report mean [benefit] of patches in-radius 2
end
to-report cost-to-me
report distance [start-patch] of myself
end
to-report edge-patches
report (patch-set [neighbors4] of territory) with [owner = nobody]
end
此代码导致来自最高值报告者的此错误:此代码不能由补丁运行,只有海龟--在海龟 0 运行 BLACKLIST 时出现错误。我该如何解决这个问题?
我的替代想法如下:使用补丁变量“避免”:
to-report highest-value
let available-destinations edge-patches with [avoiding != myself]
report max-one-of available-destinations ([benefit-to-me / cost-to-me])
end
这运行。麻烦的是,正如目前在“避免障碍”程序下设计的那样,补丁知道避免作为单个海龟,如果多个海龟决定避开补丁,这将被覆盖。
所以,如果我要使用它而不是海龟的记忆,避免也应该是一个补丁集。但是,我无法确定如何以这种方式对其进行编码。我试过这个:
to avoid-obstacle
ask destination
[ let now-avoiding myself
set avoiding (turtle-set avoiding now-avoiding) ]
set blacklist (patch-set blacklist patches with [avoiding = myself])
end
避免似乎变成了乌龟集。然而,乌龟的黑名单记忆永远不会正确完成——它一直是空的。另外,即使代理集避免包含海龟,最高值报告者似乎也没有排除补丁。所以,我很茫然。
结论:如果有办法,我更愿意使用我原来调用海龟黑名单的方法。如果我决定走另一条路,我也很想知道我在使用“避免”的想法中做错了什么。谢谢!
还有一个相关的问题:如何调用代理集以显示其中的代理列表?我想这样做以检查代码是否按预期工作。从命令中心,“show [blacklist] of turtle 0”只返回“(agentset,50个补丁)”而不是这50个补丁的列表,这是我真正想看到的。
【问题讨论】:
标签: netlogo