0

我正在尝试在我的设置中为我的海龟创建一个影响网络。每只海龟都有一个随机设置在 0 和 1 之间的 AD 变量。它们中的每一个都会创建 5 个无向链接。现在,如果他们的 AD 低(低于 0.3),他们应该在他们的网络中寻找 AD 高的人(高于 0.7)并创建指向该人的链接(成为追随者)。

我尝试过这段代码不起作用,因为某些网络不会有任何 AD > 0.7 的人,所以当我试图杀死链接时,我得到了运行时。有人知道解决方法吗?(特别是如果我们可以避免两步过程并在满足条件时直接创建链接)。

to setup
  ask turtles [
    create-links-with n-of 5 other turtles 
    if (AD < 0.3) [
      let target one-of (other turtles with [link-neighbor? myself and (AD > 0.7)])
    ask link-with target [die]
      create-link-to target
    ]
    ]

谢谢!

4

1 回答 1

1

从您的代码中,我认为您希望(1)每个代理都与其他 5 个代理建立链接(因此平均而言,他们都有 10 个,因为他们也会从其他代理那里获得链接)。(2)如果自己的AD低,则至少有一个链路具有高值AD节点。以下代码创建一个链接(如果需要,使用 AD),然后创建另一个 4。

to setup
  ask turtles
  [ ifelse AD < 0.3
    [ create-links with one-of other turtles with [AD > 0.7] ]
    [ create-links-with one-of 5 other turtles ]
    create-links with n-of 4 other turtles
  ]
end

由于更具体的问题而更新。避免错误的正常方法是创建一个可能的代理集,然后测试是否有任何成员。看起来有点像这样:

...
let candidates turtles with [AD > 0.7]
if any? candidates
[ create-links-with one-of candidates
]
...
于 2019-01-26T14:15:38.893 回答