微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

连接一定半径内的海龟

如何解决连接一定半径内的海龟

我在Netlogo中使用nw扩展名来创建网络。

我的目标是:

  1. 检查附近是否有海龟
  2. 如果附近有海龟(我尝试了下3个补丁,但可能会改变),请与它们连接+可能存在的链接上限

我尝试(并且我认为成功了)实施该方法,如here所述。这意味着上限有效。但是,我不能仅链接到附近的海龟。如果附近没有乌龟,我还需要一些东西来捕捉错误。我尝试使用in-radius命令,但由于某些原因,它无法满足我的要求。

extensions [nw]

breed [ AT1s AT1]

turtles-own [ friends ]

to setup
  ca
  create-AT1s 20 [
   setxy random-xcor random-ycor
   set friends 3
   set color green
   get-radius-friends friends AT1s
  ]
end

to get-radius-friends [ x AgentT]
  let lonely AgentT with [count my-links < x]
  let candidates other AgentT with [ any? AgentT in-radius 3 AND count my-links < x ]
   let new-links x - count my-links
    if new-links > 0 AND any? AgentT in-radius 3
    [ let chosen n-of min (list new-links count other candidates) other candidates
      create-links-with chosen [ hide-link ]
      set candidates other candidates
      ask chosen [ if my-links = x [ set candidates other candidates ] ]
    ] 
end

我还找到了neighborsdistance命令,但是这些命令只考虑了我不需要的周围环境。

解决方法

实际上,如果要在空间上限制海龟,这不是最好的问题。在乌龟创建模块中建立连接存在一个严重的问题,因为首先创建的乌龟没有潜在的朋友。除非您有大量的海龟,否则您不必担心效率。

我也认为变量'x'是不必要的,因为您有可用的变量'friends'(这似乎是您希望乌龟拥有的链接数)。并且有一个新的报告器up-to-n-of,使整个listmin都不需要。

我认为这可以满足您的需求。您可能想测试是否没有hide-link,以便可以看到它的作用。

breed [ AT1s AT1]

turtles-own [ friends ]

    to setup
      clear-all
      create-AT1s 100
      [ setxy random-xcor random-ycor
        set friends 3
        set color green
      ]
      get-radius-friends 10 AT1s
    end
    
    to get-radius-friends [ #radius #breed ]
      let linkers turtles with [breed = #breed ]
      ask linkers
      [ let new-links friends - count my-links
        if new-links > 0
        [ let candidates other linkers with [ count my-links < friends ] in-radius #radius
          let chosen up-to-n-of new-links candidates
          create-links-with chosen [ hide-link ]
        ]
      ]
    end

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。