NetLogo:获取补丁集以排除内存中保存的补丁



我正在NetLogo中建模区域选择。当建立领地时,它还会建立不需要的补丁的记忆(称为"黑名单"的代理集),然后需要在为领地选择新补丁时避开这些补丁。在决定要声明的下一个补丁时,会创建一个称为"可用目标"的新补丁集,根据几个因素从中报告"最高价值"(见下文)。我希望可用目的地检查补丁是否是海龟黑名单的一部分,并排除这些补丁。但是,在修补过程中,我无法弄清楚如何调用的黑名单。有什么建议吗?提前感谢!

这是我的主要代码:

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 运行黑名单时出错。我该如何解决这个问题?


我的替代想法如下:使用补丁变量"避免":

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

回避似乎确实变成了。然而,的黑名单记忆永远不会正确完成——它仍然是空的。此外,最高值的报告器似乎不会排除补丁,即使代理集避免包含。所以,我不知所措。


结论:如果有办法的话,我宁愿用我原来的方法来调用的黑名单。如果我决定走另一条路,我也很想知道我在使用"避免"的想法中做错了什么。谢谢!

还有一个快速的相关问题:如何调用代理集以显示其中的代理列表?我想这样做以检查代码是否按预期工作。在命令中心,"显示 turtle 0 的 [黑名单]"只返回"(代理集,50 个补丁)",而不是这 50 个补丁的列表,这才是我真正想看到的。

您可以使用member?来执行要排除补丁的操作吗?例如:

to-report highest-value           
let available-destinations edge-patches with [ member? self blacklist = false ]  
report max-one-of available-destinations ([benefit-to-me / cost-to-me]) 
end

如果没有您的设置和所有内容,我无法真正测试这一点,但是如果请求代理(在这种情况下,不是而是潜在的可用补丁)属于代理集,则member?报告为真。有关简单的工作示例,请参阅:

to setup
ca
ask patches with [pxcor > 0 ] [
set pcolor white
]
crt 1 
end
to go
ask turtles [
let blacklist patches with [ pcolor = black ]
let northpatches patches with [ pycor > 0 ]
let northred ( northpatches with [ member? self blacklist = false ] )
ask northred [ set pcolor red ]
ask northred [
print self
]
]
end

至于仅显示哪些补丁可用,请查看在上述过程中,如何要求其代理集"northred"中的海龟将自己打印到控制台。这是一个简单的方法!

最新更新