当x个补丁离开时,断开与其他海龟的链接



当海龟偏离与其链接的海龟x数量的补丁时,我如何让它们断开链接?我试过这行代码,我认为它可以用to break-link if cooperator link in-radius linking-radius > max-link-radius [ ask one-of links [ die ] ] end,但我得到了错误"链接需要2个输入,一个数字和一个数字"。任何帮助都将不胜感激,谢谢。张贴在下方的代码

turtles-own [ energy ] 
breed [ cooperators cooperator ] 
breed [ uncooperators uncooperator ]


to setup 
ca
ask patches [
set pcolor green
]
create-uncooperators num-uncooperators [
setxy random-xcor random-ycor
set color red
set energy random 100
]set-default-shape turtles "person"
create-cooperators num-cooperators [
setxy random-xcor random-ycor
set color yellow
set energy random 100
]
reset-ticks
end
to go 
if not any? turtles [ stop ] 
ask cooperators [
set energy energy - 1
move
communicate
cooperate
break-link
]
ask uncooperators [
set energy energy - 1
move 
]
tick
end
to move
lt 50
rt 50
fd 1
end

to communicate
if count my-links < 1 [
create-link-to one-of uncooperators in-radius linking-radius
]
end
to break-link
if cooperator link in-radius linking-radius > max-link-radius [ ask one-of links [ die ] ]
end

请只发布相关代码,通常是针对NetLogo的,这是给你错误的过程和调用它的过程。所以这是给出错误消息的行:

to break-link
if cooperator link in-radius linking-radius > max-link-radius
[ ask one-of links [ die ]
]
end

NetLogo告诉你,它不知道你指的是哪一个link,因为链接由两个数字标识——两端的乌龟。如果你查看你的代码,你会发现单词link后面跟着两个数字(半径和链接半径中的变量(,但这些不是海龟标识符。我认为你想做一些事情,比如让长链接断开,在这种情况下,你将物理/空间距离与网络距离(要经过多少链接(混合在一起。你想要这样的东西吗?

to break-link
ask cooperators
[ if distance one-of link-neighbors > max-link-radius
[ ask one-of links [ die ]
]
]
end

link-neigbors用于查找与正在进行询问的乌龟相连的乌龟。但这不会达到你的目标,因为随机链接会死亡,而不是满足距离条件的链接。也许这个(未测试(:

to break-link         ; called by a cooperator turtle
let furthest-friend max-one-of link-neighbors [distance myself]
if distance furthest-friend > max-link-radius
[ ask link-with furthest-friend [ die ]
]
end

最新更新