连接一定半径内的海龟

问题描述

我在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

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...