netlogo - 设置新的目标补丁,但不包括 Netlogo 中的当前补丁
问题描述
我正在创建一个复制商店扒手行为的模拟。海龟分为“专业”和“新手”扒手,如果“专业”被商店保安逮捕,他们可能(1/2)想要选择一家新商店来定位“需要新商店”。
“专业”扒手瞄准特定半径内“安全”值最低的商店,所有值都是在创建时设置的。
我正在尝试设置一个新的“目标商店”,半径为 10 的“商店”,具有第二低的“安全性”,即不包括当前的“目标商店”,但我遇到了困难。
到目前为止,我已尝试对以下代码进行几处添加以排除当前的目标商店,这包括“会员?我的补丁”的变体,因为已将扒手被捕的“商店”添加到此“补丁集”这将通知稍后的命令。我还列出了一个递增的“安全”值列表,告诉“扒手”以“安全”(确定商店漏洞的值)作为目标的“商店”,与列表中的第 1 项相同,但我担心这可能不起作用,因为它们的原始目标商店可能不一定是项目 0,因为它们以 10 单位半径内“安全性”最低的商店为目标。
这些是我目前正在使用的代码行,任何建议将不胜感激。
***编辑:理想情况下,我可以喜欢使用“mypatches”的代码,因此每次在商店逮捕专业扒手时,可以将商店添加到 mypatches 中,随后的目标商店可以排除所有属于我的补丁。
to new-target-store
ask turtles [ if
new-store-required = 1 and professional = 1 and (random-float 1 < 0.5) [
set target-store min-one-of store in-radius 10 [security]
]
]
end
编辑2:我已经解决了问题。
解决方案
您可能希望包含您的setup
代码,或者如果它真的很长,则可以包含它的精简版本,以确保答案符合您使用的结构。我会通过有一个turtles-own
变量来存储他们当前的目标来解决这个问题,如果它是空的,他们可以尝试填充它(而不是为此目的使用额外的布尔值)。此外,您可能希望将 1/0 选项转换为true
/false
以获得更清晰的代码。查看此示例设置:
globals [ stores ]
patches-own [ security ]
turtles-own [
current-target
professional?
mypatches
]
to setup
ca
ask n-of 20 patches [
set pcolor green
set security 1 + random 10
]
set stores patches with [ pcolor = green ]
crt 5 [
setxy random-xcor random-ycor
pd
set professional? one-of [ true false ]
set current-target nobody
set mypatches ( patch-set )
]
reset-ticks
end
这设置了一个包含一些绿色补丁的世界,这些补丁被分组到被patch-set
调用的stores
. 此外,您有一些将布尔值professional?
设置为 true 或 false 的海龟。它们在没有current-target
存储和空mypatches
patch-set
变量的情况下进行初始化。
现在,您可以让海龟检查它们是否current-target
存在。如果没有,他们可以possible-targets
从不等于patch-here
请求海龟的存储集(这里)中为该变量分配一个存储。专业窃贼可以通过排除属于其变量成员的任何商店来进一步改进possible-targets
以排除他们被逮捕的任何商店。mypatches
patch-set
评论中的更多细节:
to go
ask turtles [
; if you have no target currently
if current-target = nobody [
; Create a temporary patch set made up of all stores except for
; the one that I'm currently in
let possible-targets stores with [ self != [patch-here] of myself ]
ifelse professional? [
; Have professional thieves revise their possible targets to exclude
; any in the patchset mypatches, then choose a possible target
set possible-targets possible-targets with [ not member? self [mypatches] of myself ]
set current-target min-one-of possible-targets in-radius 10 [ security ]
] [
; Have amateur thieves choose randomly from the possible targets
set current-target one-of possible-targets
]
]
; move closer to your current target, or
; move to it exactly if you're near enough
ifelse current-target != nobody [
face current-target
ifelse distance current-target > 1 [
fd 1
] [
move-to current-target
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; *** do your shoplifting attempt/check here ***
; For this example, just have professional thieves sometimes
; add this patch to their mypatches patchset
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
if professional? and random-float 1 < 0.5 [
set mypatches ( patch-set mypatches patch-here )
]
; Reset current-target to nobody
set current-target nobody
]
] [
; if no suitable nearby targets, wander randomly
rt random 61 - 30
fd 1
]
]
tick
end
如果您运行的时间足够长,最终您的专业窃贼将无法找到目标商店,因为他们已将所有商店添加到他们的mypatches
变量中。
推荐阅读
- postgresql - 如何索引 32 个字符的文本 ID
- angular - 如何在Angular材料中添加多个表,每个表都具有过滤器、排序、分页?
- python - 在 for 循环之后将 CSV 上传到 S3
- regex - 如何使用 Perl 在正则表达式中正确匹配 TAB?
- python - Python - ImportError:尝试在没有已知父包的情况下进行相对导入
- matlab - 如何使用 matlab 或 gmail 自动发送邮件?
- java - 如何使用 GenericStoredProcedure 在 Spring Boot 中将 String 设置为输入参数?
- css - 解释这个 CSS 自定义属性行为
- google-cloud-platform - 大查询数据传输 - 如何避免文件限制?
- c++ - RSA_PKCS1 签名验证