【问题标题】:NetLogo: getting a patch-set to exclude patches held in turtle's memoryNetLogo:获取补丁集以排除海龟内存中保存的补丁
【发布时间】: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


    【解决方案1】:

    您可以使用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
    

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

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

    【讨论】:

    • 谢谢!不幸的是,这会返回相同的错误,“此代码不能由补丁运行,只有海龟--海龟 0 运行 MEMBER 时出错?”和以前一样,我认为这意味着最高值在补丁上下文中,但黑名单在海龟上下文中,对吧?如何解决这个问题?
    • 是的,你是对的——那是行不通的。我认为,如果您打算以这种方式使用报告器,那么该报告器将始终查询补丁。然而,由于你的记者是一个非常简单的两行,你不能使用它(我看不出有必要,特别是因为据我所知,它总是特定于海龟)——只需将这些行放在你的为简单起见,乌龟运动过程。查看this toy version of your model 中的代码作为示例。它几乎肯定不会在您的浏览器中运行,您必须下载或复制/粘贴它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-29
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    相关资源
    最近更新 更多