我正在尝试为我的乌龟在我的设置上创建一个影响网络。每只海龟都有一个随机设置在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
]
]
谢谢!
发布于 2019-01-26 22:15:39
从你的代码中,我认为你想要(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
]
...
https://stackoverflow.com/questions/54377614
复制相似问题