我正在编写模拟,我试图模拟恐怖组织的招募过程。在这个模型中,海龟有一群朋友,即他们通过链接连接的其他海龟。该模型包括与他们遇到的海龟形成新的联系(链接),如果他们的世界观相似,并且应该有一个机制,可以从他们朋友中与他们最不同的世界观点的朋友中获得机会。
尝试使用以下代码块解决问题但似乎无法正常工作,经常会收到错误消息
"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
]
以下是上述模拟的完整代码。目的是比较两种策略,其中重写者专注于具有最激进世界观的海龟,第二种策略首先针对网络中最中心的海龟。
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
答案 0 :(得分:1)
您的问题是,您无法正确切换上下文(即,代码是当前&#39;在乌龟或链接的角度)。
你从ask turtles
开始 - 假装你现在是第一个被问到的乌龟。首先计算一个值,然后将其与随机数进行比较 - 假设满足if
。代码仍然在turtle上下文中,因此[]
中的代码将应用于第一个乌龟。
代码创建一个名为friend_dif的变量,并将其值指定为自身与一个随机选择的网络邻居之间的世界视图差异。在您的代码中,您拥有max-one-of links [friend_dif]
。但是,如果(1)friend_dif为link
属性,则仅选择最大值为friend_dif的links-own
;(2)所有链接的friend_dif值均为set
。两者都不是真的。此外,通过询问max-one-of links [friend_dif]
,您要求模型中所有link
的{{1}}值最高,而不仅仅是links
感兴趣的turtle
一端。
因此,您需要让turtle
计算其所有link-neighbors
的差异,然后将上下文切换为连接两只海龟的link
,然后再询问{{1} } link
。
未经测试。它应该做的是识别返回世界观值最大差异的网络邻居,然后使用die
的名称(由两端给出)来询问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]
]
]
属性来存储世界观中差异的值(下面称为dif),然后执行以下操作:
link