Netlogo,如何根据海龟拥有的价值在海龟之间删除 link
Netlogo, how to delete link between turtles based on value they own
我正在编写模拟,我正在尝试模拟 terrorost 组织的招聘过程。在这个模型中,海龟有一群朋友,即它们通过链接连接到的其他海龟。该模型包括与他们遇到的海龟形成新的联系(链接),如果他们的世界观相似,并且应该有一种机制来与他们的朋友中世界观最不同的朋友断开连接。
尝试解决以下代码块的问题,但似乎无法正常工作,经常收到错误消息
"OF expected input to be a turtle agentset or turtle but got NOBODY instead."
与 friend_dif
的值相关
ask turtles with [(connections > 0) and (color = blue)][
let friends_inverse ( 1 / connections )
if friends_inverse > random-float 1[
let friend_dif abs([world_view] of self - [world_view] of one-of other link-neighbors)
ask max-one-of links [friend_dif][
die
]
]
set connections count link-neighbors
]
下面是上述模拟的完整代码。目的是比较两种策略,一种是 recriters 专注于具有最激进世界观的海龟,第二种是他们首先针对网络中最中心的海龟。
turtles-own [connections world_view]
to setup
ca
crt potential_recruits [setxy random-xcor random-ycor set color blue]
ask turtles with [color = blue][
let przypisania random max_start_recruits_connections
;; 0-0.4 non interested, 0.4-0.7 moderate, 0.7-0.9 symphatizing, >0.9 radical - can be recrouted
set world_view random-float 1
if count my-links < 10 [
repeat przypisania [
create-link-with one-of other turtles with [(count link-neighbors < 10) and (color = blue)]
]
]
show link-neighbors
set connections count link-neighbors
]
crt recruiters [setxy random-xcor random-ycor set color orange]
ask turtles with [color = orange][
set world_view 1
if strategy = "world view"[
recruit_view
]
if strategy = "most central"[
recruit_central
]
]
;;show count links
reset-ticks
setup-plots
update-plots
end
to go
;;creating new links with turtles they meet and movement which is random
ask turtles [
rt random-float 360
fd 1
if any? other turtles-here[
let world_view1 [world_view] of one-of turtles-here
let world_view2 [world_view] of one-of other turtles-here
let connection_chance abs(world_view1 - world_view2)
if connection_chance <= 0.2 [
;;show connection_chance
create-links-with other turtles-here
]
]
;;show link-neighbors
set connections count link-neighbors
]
;;how recruiting works in this model
ask turtles with [world_view > 0.9][
if count in-link-neighbors with [color = orange] > 0[
set color orange
set world_view 1
]
]
;; friend's influence on turtles
ask turtles with [(count link-neighbors > 0) and (color = blue)][
let friends_view (sum [world_view] of link-neighbors / count link-neighbors)
let view_dev (friends_view - world_view)
;;show world_view show view_dev
set world_view world_view + (view_dev / 2)
]
;; removing turtles from with most different opinion from our colleagues
ask turtles with [(connections > 0) and (color = blue)][
let friends_inverse ( 1 / connections )
if friends_inverse > random-float 1[
let friend_dif abs([world_view] of self - [world_view] of one-of other link-neighbors)
ask max-one-of links [friend_dif][
die
]
]
set connections count link-neighbors
]
;show count links
tick
update-plots
end
to recruit_view
ask max-n-of start_recruiters_connections turtles with [ color = blue][world_view][
repeat start_recruiters_connections[
create-link-with one-of other turtles with [ color = orange]
]
]
ask turtles with [color = orange][
set connections count link-neighbors
]
end
to recruit_central
ask max-n-of start_recruiters_connections turtles with [ color = blue][count my-links][
repeat start_recruiters_connections[
create-link-with one-of other turtles with [ color = orange]
]
]
ask turtles with [color = orange][
set connections count link-neighbors
]
end
to batch
repeat 50 [
go
]
end
你的问题是你没有正确切换上下文(也就是说,代码是 'currently' 乌龟还是 link 的角度)。
你从 ask turtles
开始 - 假装你现在是第一只被问到的乌龟。首先计算一个值,然后与随机数进行比较 - 假设满足 if
。代码仍在海龟上下文中,因此 []
中的代码应用于第一只海龟。
该代码创建了一个名为 friend_dif 的变量,并将其值分配为它与一个随机选择的网络邻居之间的世界观差异。在你的代码中,你有 max-one-of links [friend_dif]
。但是,如果 (1) friend_dif 是 links-own
属性且 (2) friend_dif 的值,则仅选择最大值 friend_dif 的 link
所有 link 都是 set
。两者都不是真的。此外,通过询问 max-one-of links [friend_dif]
,您是在询问模型中所有 links
中具有最高值的 link
,而不仅仅是具有 turtle
的感兴趣的 turtle
一端。
所以你需要让你的 turtle
计算所有 link-neighbors
的差异,然后将上下文切换到连接两只海龟的 link
,然后再询问 link
到 die
.
这没有经过测试。它应该做的是识别returns世界观值差异最大的网络邻居,然后使用link
的名称(由两端给出)请求它die
.
ask turtles with [ count my-links > 0 and color = blue]
[ if random-float 1 < 1 / count my-links
[ let bigdif max-one-of link-neighbours [abs ([worldview] - [worldview] of myself)
ask link self bigdif [die]
]
]
或者(并且更易于阅读),您可以创建一个 link
属性来存储世界观差异的值(下面称为 dif),然后执行如下操作:
ask links [ set dif abs ([worldview] of end1 - [worldview] of end2) ]
ask turtles with [ count my-links > 0 and color = blue]
[ if random-float 1 < 1 / count my-links
[ ask max-one-of my-links [dif] [die]
]
]
我正在编写模拟,我正在尝试模拟 terrorost 组织的招聘过程。在这个模型中,海龟有一群朋友,即它们通过链接连接到的其他海龟。该模型包括与他们遇到的海龟形成新的联系(链接),如果他们的世界观相似,并且应该有一种机制来与他们的朋友中世界观最不同的朋友断开连接。
尝试解决以下代码块的问题,但似乎无法正常工作,经常收到错误消息
"OF expected input to be a turtle agentset or turtle but got NOBODY instead."
与 friend_dif
的值相关 ask turtles with [(connections > 0) and (color = blue)][
let friends_inverse ( 1 / connections )
if friends_inverse > random-float 1[
let friend_dif abs([world_view] of self - [world_view] of one-of other link-neighbors)
ask max-one-of links [friend_dif][
die
]
]
set connections count link-neighbors
]
下面是上述模拟的完整代码。目的是比较两种策略,一种是 recriters 专注于具有最激进世界观的海龟,第二种是他们首先针对网络中最中心的海龟。
turtles-own [connections world_view]
to setup
ca
crt potential_recruits [setxy random-xcor random-ycor set color blue]
ask turtles with [color = blue][
let przypisania random max_start_recruits_connections
;; 0-0.4 non interested, 0.4-0.7 moderate, 0.7-0.9 symphatizing, >0.9 radical - can be recrouted
set world_view random-float 1
if count my-links < 10 [
repeat przypisania [
create-link-with one-of other turtles with [(count link-neighbors < 10) and (color = blue)]
]
]
show link-neighbors
set connections count link-neighbors
]
crt recruiters [setxy random-xcor random-ycor set color orange]
ask turtles with [color = orange][
set world_view 1
if strategy = "world view"[
recruit_view
]
if strategy = "most central"[
recruit_central
]
]
;;show count links
reset-ticks
setup-plots
update-plots
end
to go
;;creating new links with turtles they meet and movement which is random
ask turtles [
rt random-float 360
fd 1
if any? other turtles-here[
let world_view1 [world_view] of one-of turtles-here
let world_view2 [world_view] of one-of other turtles-here
let connection_chance abs(world_view1 - world_view2)
if connection_chance <= 0.2 [
;;show connection_chance
create-links-with other turtles-here
]
]
;;show link-neighbors
set connections count link-neighbors
]
;;how recruiting works in this model
ask turtles with [world_view > 0.9][
if count in-link-neighbors with [color = orange] > 0[
set color orange
set world_view 1
]
]
;; friend's influence on turtles
ask turtles with [(count link-neighbors > 0) and (color = blue)][
let friends_view (sum [world_view] of link-neighbors / count link-neighbors)
let view_dev (friends_view - world_view)
;;show world_view show view_dev
set world_view world_view + (view_dev / 2)
]
;; removing turtles from with most different opinion from our colleagues
ask turtles with [(connections > 0) and (color = blue)][
let friends_inverse ( 1 / connections )
if friends_inverse > random-float 1[
let friend_dif abs([world_view] of self - [world_view] of one-of other link-neighbors)
ask max-one-of links [friend_dif][
die
]
]
set connections count link-neighbors
]
;show count links
tick
update-plots
end
to recruit_view
ask max-n-of start_recruiters_connections turtles with [ color = blue][world_view][
repeat start_recruiters_connections[
create-link-with one-of other turtles with [ color = orange]
]
]
ask turtles with [color = orange][
set connections count link-neighbors
]
end
to recruit_central
ask max-n-of start_recruiters_connections turtles with [ color = blue][count my-links][
repeat start_recruiters_connections[
create-link-with one-of other turtles with [ color = orange]
]
]
ask turtles with [color = orange][
set connections count link-neighbors
]
end
to batch
repeat 50 [
go
]
end
你的问题是你没有正确切换上下文(也就是说,代码是 'currently' 乌龟还是 link 的角度)。
你从 ask turtles
开始 - 假装你现在是第一只被问到的乌龟。首先计算一个值,然后与随机数进行比较 - 假设满足 if
。代码仍在海龟上下文中,因此 []
中的代码应用于第一只海龟。
该代码创建了一个名为 friend_dif 的变量,并将其值分配为它与一个随机选择的网络邻居之间的世界观差异。在你的代码中,你有 max-one-of links [friend_dif]
。但是,如果 (1) friend_dif 是 links-own
属性且 (2) friend_dif 的值,则仅选择最大值 friend_dif 的 link
所有 link 都是 set
。两者都不是真的。此外,通过询问 max-one-of links [friend_dif]
,您是在询问模型中所有 links
中具有最高值的 link
,而不仅仅是具有 turtle
的感兴趣的 turtle
一端。
所以你需要让你的 turtle
计算所有 link-neighbors
的差异,然后将上下文切换到连接两只海龟的 link
,然后再询问 link
到 die
.
这没有经过测试。它应该做的是识别returns世界观值差异最大的网络邻居,然后使用link
的名称(由两端给出)请求它die
.
ask turtles with [ count my-links > 0 and color = blue]
[ if random-float 1 < 1 / count my-links
[ let bigdif max-one-of link-neighbours [abs ([worldview] - [worldview] of myself)
ask link self bigdif [die]
]
]
或者(并且更易于阅读),您可以创建一个 link
属性来存储世界观差异的值(下面称为 dif),然后执行如下操作:
ask links [ set dif abs ([worldview] of end1 - [worldview] of end2) ]
ask turtles with [ count my-links > 0 and color = blue]
[ if random-float 1 < 1 / count my-links
[ ask max-one-of my-links [dif] [die]
]
]