我的模型中有大约 5000 个代理(人)。我想给他们任意数量的朋友,并有互惠但随机的配对。因此,如果 A 选择 B 则 B 也选择 A。我的代码运行良好,但速度相当慢。我很可能想在未来增加朋友的数量和人数。有更快的建议吗?
ask people
[ let new-links friends - count my-links
if new-links > 0
[ let candidates other people with [ count my-links < friends ]
create-links-with n-of min (list new-links count candidates) candidates
[ hide-link ]
]
]
Run Code Online (Sandbox Code Playgroud)
请注意,在上面的代码中,朋友是一个全局变量,但我最终的代码可能会概括wanted-number-of-friends为人的一个属性。
已编辑添加了if new-links > 0条件,以便在ask不需要找到候选时避免嵌套。这提高了速度,但仍然不能真正扩展。