我正试图在我的设置上为我的乌龟创建一个影响力网络。每只乌龟都有一个随机设置在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
]
]
谢谢!
从您的代码中我认为您希望(1)每个代理与其他代理建立链接(因此平均而言,他们都将拥有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
]
...