我知道,这里是question。问题是......我一直试图实施它,但它似乎并不适合我。我的模拟正在运行,但即使links
面向agentes
activities
,也会{0} sight-radius
。这是代码:
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-如果他们具有相同的shared-culture
并且他们是in-radius
,则接受他们。
3-代表这个&#34;接受&#34;和&#34;参与&#34;蓝色链接。
我尝试了与while
相似但结果为0的内容。
答案 0 :(得分:1)
如果没有看到更多代码,很难说,但是有一些问题可能导致您的问题。根据您的摘要,我的理解是,您基本上希望activities
代理在agentes
内与sight-radius
形成链接,直至n-capacity
定义的数字。但是,在您的代码中,您有活动检查if count my-links < n-capacity
,在该活动的视线范围内有其他 agentes 来创建与其他代理的参与链接,而不是原来的activity
代理我明白你想要一些链接。
假设n-capacity
是activities-own
变量,您可以通过切换
ask other agentes in-radius sight-radius with
[shared-culture = [shared-culture] of other agentes] [
create-participations-with n-of n-capacity agentes
]
到
用[共享文化= [共享文化]自己] [创建参与 - 自己]
修改:忘记原始的of
ask n-of n-capacity agentes in-radius sight-radius with
[shared-culture = [shared-culture] of myself] [
create-participation-with myself
]
但是,由于我无法测试,因为我没有您的设置和其他代码,我将向您展示一个我知道有效的不同示例,可能就是您的后。下面是所有需要的代码,为setup
创建一个按钮,为go
创建一个永久按钮,并观察狼与具有相同颜色的绵羊代理最多建立三个链接:
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