NetLogo有效地创建具有任意度分布的网络

时间:2015-10-07 19:36:51

标签: netlogo

这是NetLogo Efficient way to create fixed number of links的后续问题。专注于避免嵌套的“问”,我现在有了这个代码。它效率更高,但创建了太多链接。显然是一个逻辑错误,但我看不到它。

longest

1 个答案:

答案 0 :(得分:4)

很好的解决方案!请注意,other candidates实际上是iterates through every agent in the agentset,所以它仍会因许多代理而变慢,但不如your other question那么慢,因为它没有让这些代理运行代码。它的运行速度让我印象深刻!

在bug上。在这部分:

if my-links = friends [ set candidates other candidates ]

我想你忘记了count前的my-links

代码仍然可能会以一些小于friends的代理结束,因为世界可能会在到达候选者之外。不确定你对此有多关心。您可以清除链接并重试,直到您拥有正确的号码。只要friends非常小,那就应该没问题。

请注意,您可以将set candidates other candidates置于开头,从而加快代码速度:

set candidates other candidates
if new-links > 0
[ let chosen n-of min (list new-links count candidates) candidates
  create-links-with chosen [ hide-link ]
  ask chosen [ if my-links = friends [ set candidates other candidates ] ]
]

这样,您可以避免多次计算other candidates

相关问题