gpt4 book ai didi

simulation - Netlogo,如何根据海龟拥有的值(value)删除海龟之间的链接

转载 作者:行者123 更新时间:2023-12-05 04:05:46 24 4
gpt4 key购买 nike

我正在编写模拟,我正在尝试模拟 terrorost 组织的招聘过程。在这个模型中,海龟有一群 friend ,即它们通过链接连接到的其他海龟。该模型包括与他们遇到的海龟形成新的联系(链接),如果他们的世界观相似,并且应该有一种机制来断开与他们的 friend 之间世界观最不同的 friend 。

尝试用以下代码块解决问题,但似乎无法正常工作,经常收到错误消息

"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

最佳答案

你的问题是你没有正确地切换上下文(也就是说,代码是“当前”在乌龟还是链接的角度)。

您从 ask turtles 开始 - 假装您现在是第一只被询问的乌龟。首先计算一个值,然后与随机数进行比较 - 假设满足 if。代码仍在海龟上下文中,因此 [] 中的代码应用于第一只海龟。

代码创建了一个名为 friend_dif 的变量,并将其值分配为它自己与一个随机选择的网络邻居之间的世界观差异。在您的代码中,您将拥有 max-one-of links [friend_dif]。但是,如果 (1) friend_dif 是一个 links-own 属性并且 (2) friend_dif 的值为 为所有链接设置。两者都不是真的。此外,通过请求 max-one-of links [friend_dif],您是在请求所有 links 中具有最高值的 link模型,而不仅仅是一端有感兴趣的 turtle 的模型。

所以你需要让你的 turtle 计算它的所有 link-neighbors 的差异,然后将上下文切换到连接的 link两只乌龟,在请求 linkdie 之前。

这没有经过测试。它应该做的是识别返回世界观值最大差异的网络邻居,然后使用 link 的名称(由两端给出)向它请求

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]
]
]

关于simulation - Netlogo,如何根据海龟拥有的值(value)删除海龟之间的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50785554/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com