设置新的目标补丁但不包括 Netlogo 中的当前补丁

Setting new target patch but excluding current in Netlogo

我正在创建一个模拟商店扒手行为的模拟。海龟分为 "professional" 和 "novice" 个商店扒手,如果 "professionals" 被商店保安逮捕,他们可能 (1/2) 想要 select 一家新商店作为目标 "new-store-required".

"professional" 小偷以一定半径内 "security" 值最低的商店为目标,所有值都是在创建时设置的。

我正在尝试设置一个新的 "target-store",半径为 10 的 "store" 第二低 "security",即排除当前的 "target-store" 但我是有困难。

到目前为止,我已尝试对以下代码进行几处添加以排除当前目标商店,这包括 "member? my patches" 的变体,因为 "store" 商店扒手已被逮捕这个 "patch-set" 将通知稍后的命令。我还制作了一个升序 "security" 值列表,告诉 "shoplifter" 以 "security" 为目标 "store"(确定商店漏洞的值)与第 1 项相同列表,但我担心这可能行不通,因为他们原来的目标商店可能不一定是项目 0,因为他们以 10 个单位半径内最低 "security" 为目标的商店。

这些是我目前正在使用的代码行,如有任何建议,我们将不胜感激。

***编辑:理想情况下,我希望代码能够使用 "mypatches",这样每次在一家商店逮捕专业扒手时,该商店都可以添加到 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 是否存在。如果没有,他们可以从不等于询问海龟的 patch-here 的商店集合(possible-targets,此处)中为该变量分配一个商店。专业小偷可以进一步细化 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 变量中。