Netlogo:限制代理可以建立的链接数 [英] Netlogo: limit the number of links an agent can make
问题描述
如果乌龟的var1值相等,我会联系它们(这很好).我想将链接数限制为三个.我在代码的链接部分(If count my-links < 3
)之前添加了IF语句,但是它不起作用;代理商继续链接超过我设置的最大值.我阅读了另一个问题如何限制代理在模型中可以建立的链接数量,但这似乎并不能完全解决我在此所做的尝试.我在做什么错了?
I have turtles linking if they have an equal value for var1 (this works fine). I want to limit the number of links to just three. I added an IF statement before the linking part of the code (If count my-links < 3
), but it does not work; the agents continue to link past the max value I set. I read the other question How to limit the number of links an agent can make in a model but that doesn't seem to quite do what I am attempting here. What am I doing wrong?
to communicate
If count my-links < 3
[
ask other xagents in-radius 5 with [var1 = [var1] of myself]
[create-links-with yagents in-radius 5 with [var1 = [var1] of myself]
[
set color white
set thickness 0.1
]
]
]
end
推荐答案
在让乌龟创建新链接之前,请限制它们的链接数:
通过查看完整的模块,就像@JenB提到的那样,似乎没有条件限制目标乌龟用于建立链接的链接数量.
Limit number of links for the turtles before letting them create new ones:
By looking at your complete module, as @JenB mentioned that, it seems that there's no condition to limit number of links that the targeted turtle has for making a link.
这将是第一步:
to communicate
If count my-links < 3
[
ask other xagents in-radius 5 with [(var1 = [var1] of myself) and (count my-links < 3)]
[create-links-with yagents in-radius 5 with [(var1 = [var1] of myself) and (count my-links < 3)]
[
set color white
set thickness 0.1
]
]
]
end
但是,如果没有这样的代理人怎么办? (半径为5,val1相同,链接数小于3)可能需要if语句.
But what if there's no agent like that? (in radius of 5, with the same val1 and links less than 3) Probably an if-statement is needed.
我还认为您需要在代码中使用one-of
,以便在每个步骤中仅建立一个链接.
I also think you need to use one-of
in your code to make only one link in each step.
您可以在communicate
子过程的末尾使用此命令来杀死多余的链接.它具有随机删除链接的缺点,并且可能会从链接数量较少的海龟中删除链接,而不是可能也具有额外链接的链接.
You can have this at the end of your communicate
sub-procedure to kill the extra links. It has a down-side of random removing links and also may remove the link from turtles with fewer link instead of the ones that may also have extra links.
ask turtles with [count my-links > LIMIT] [ if count my-links > LIMIT [ask n-of (count my-links - LIMIT) my-links [die]] ]
这篇关于Netlogo:限制代理可以建立的链接数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!