NetLogo:获取一个补丁集,以排除turtle中的补丁';记忆

NetLogo:获取一个补丁集,以排除turtle中的补丁';记忆,netlogo,Netlogo,我正在NetLogo中为区域选择建模。当海龟建立一个区域时,它也会建立一个不受欢迎的补丁(一个称为“黑名单”的代理集)的内存,然后需要在为该区域选择新补丁时避免这些补丁。在决定下一个要申请的修补程序时,将创建一个称为“可用目的地”的新修补程序集,根据几个因素报告“最高值”(见下文)。我希望可用目的地检查补丁是否属于海龟黑名单的一部分,并排除这些补丁。然而,在补丁程序中,我不知道如何调用海龟的黑名单。有什么建议吗?提前谢谢 这是我的主要代码: patches-own [ owner ;; t

我正在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
这是我的。问题是,正如目前在“避开障碍物”程序下设计的那样,补丁程序将避开视为一只海龟,如果多只海龟决定避开补丁程序,这一点就会被覆盖

所以,如果我打算用它来代替海龟的记忆,那么避免也应该是一个补丁集。然而,我还不能确定如何以这种方式编写代码。我试过这个:

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
回避似乎成了乌龟的一套。然而,乌龟对黑名单的记忆永远不会正确地完成——它一直是空的。另外,即使代理集包含海龟,最高值的reporter也不会排除补丁。所以,我不知所措


结论:如果有办法的话,我更愿意使用我最初的方法来调用海龟黑名单。如果我决定走另一条路,我也想知道我用“避免”这个词的想法有什么不对。谢谢


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

你能使用
成员吗?
来做你想排除补丁的事情吗?例如:

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?
会报告true。有关简单的工作示例,请参见:

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”中要求海龟将自己打印到控制台。这是一个简单的方法

谢谢!不幸的是,这返回了相同的错误,“这段代码不能由修补程序运行,只有一个turtle——当turtle 0运行成员时出错?”和以前一样,我认为这意味着最高值在修补程序上下文中,但黑名单在turtle上下文中,对吗?怎么解决这个问题?是的,你是对的,那是行不通的。我认为,如果你开始以这种方式使用报告程序,那么该报告程序将始终查询补丁程序。然而,由于你的记者是一个非常简单的两行,你不能使用它(我不认为有必要,特别是因为,据我所知,它总是特定于海龟)——为了简单起见,只需将这些行放在海龟移动程序中。查看中的代码以获取示例。它几乎肯定不会在您的浏览器中运行,您必须下载或复制/粘贴它。
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