限制代理可以生成V2的链接数 [英] Limit the number of links an agent can make V2
问题描述
我知道,这里它是相同的问题。事情是......我一直在努力实现它,但它似乎对我不起作用。我的模拟正在运行,但即使 agentes
面临活动,也会生成0
链接
/ code> at sight-radius
。以下是代码:
I know, here it is the same question. The thing is... I've been trying to implement it but it doesn't seem to work for me. My simulation is running but 0 links
are made even though the agentes
are facing the activities
at sight-radius
. Here is the code:
to participate
ask activities [
if count my-links < n-capacity [
ask other agentes in-radius sight-radius with
[shared-culture = [shared-culture] of other agentes] [
create-participations-with n-of n-capacity agentes
]
ask links [
set color blue]
]
]
end
如果代码不够清楚,我希望活动:
1-知道多少 agentes
他们可以拥有。
2-如果他们有相同的共享文化
,则接受他们,并且他们是 in-radius
。
3-用蓝色链接代表这个接受和参与。
If the code isn't clear enough, I want the activities to:
1- Know how many agentes
they can have.
2- Accept them if they have the same shared-culture
and they are in-radius
.
3- Represent this "acceptance" and "participation" with blue links.
我尝试了与类似的东西,而
但结果为0。
I tried something similar with while
but 0 results.
推荐答案
如果没有看到更多代码,很难说,但是有一些问题可能导致您的问题。根据您的总结,我的理解是您基本上希望活动
代理商在<$ c $内与 agentes
形成链接c>视线半径最多为 n-capacity
定义的数字。但是,在您的代码中,您有活动检查 if count my-links< n-capacity
,在该活动的视线范围内有其他 agentes 来创建与其他代理的参与链接,而不是原始的活动
我知道你想要一些链接的代理。
It's hard to say without seeing more of your code, but there are a few issues that might be causing your problem. According to your summary, my understanding is that you essentially want activities
agents to form links with agentes
within sight-radius
up to the number defined by n-capacity
. However, in your code, you are having activities check if count my-links < n-capacity
, have other agentes in that activity's sight radius to create participation links with other agents rather than with the original activity
agent that I understand you want to have some links.
假设 n-capacity
是活动_拥有
变量,你可以通过切换来接近你想要的东西
Assuming n-capacity
is an activities-own
variable, you may be able to get closer to what you want by just switching
ask other agentes in-radius sight-radius with
[shared-culture = [shared-culture] of other agentes] [
create-participations-with n-of n-capacity agentes
]
到
询问n-capacity agentes in-radius sight -radius与[共享文化= [共享文化]我自己] [创建 - 参与 - 我自己]
编辑:忘记原始
forgot the of
in original
ask n-of n-capacity agentes in-radius sight-radius with
[shared-culture = [shared-culture] of myself] [
create-participation-with myself
]
但是,由于我无法测试,因为我没有您的设置和其他代码,我将向您展示一个不同的示例我知道有效,可能就是你所追求的。下面是所有需要的代码,为设置
设置一个按钮,为设置一个永久按钮
,然后慢慢观察狼群与具有相同颜色的绵羊代理建立最多三个链接:
However, since I can't test that as I don't have your setup and other code, I'll show you a different example that I know works and might be what you're after. Below is all the code needed, make a button for setup
and a forever button for go
, and watch the wolves slowly build up to a maximum of three links with the sheep agents that have the same color:
breed [ wolves wolf ]
breed [ sheeps sheep ]
undirected-link-breed [ participations participation ]
to setup
ca
reset-ticks
create-wolves 3 [
set shape "wolf"
setxy random 32 - 16 random 32 - 16
set color one-of [ blue red ]
set size 2
]
create-sheeps 25 [
set shape "sheep"
setxy random 32 - 16 random 32 - 16
set color one-of [ blue red ]
]
end
to go
ask turtles [
rt random 90 - 45
fd 0.1
]
links-with-if
tick
end
to links-with-if
ask wolves [
if count my-links < 3 [
; Make sure the links a wolf tries to form
; does not exceed the max number of links it can make
; or the number of sheep available
let n-to-link ( 3 - count my-links)
let n-sheep-in-radius count ( sheeps with [ color = [color] of myself ] in-radius 5 )
if n-sheep-in-radius < n-to-link [
set n-to-link n-sheep-in-radius
]
; Ask the appropriate sheeps to form a link with
; the asking wolf
ask n-of n-to-link sheeps with [ color = [color] of myself ] in-radius 5 [
create-participation-with myself [ set color red ]
]
]
]
end
这篇关于限制代理可以生成V2的链接数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!