我正在尝试使用NetLogo创建一些节点和一些功能。我的代码中的节点的接受率。此标准表明,节点在给出链接后会降低其链接接受率。模型中的每个新节点(last-turtle)根据其程度(计数我的链接)检查旧节点和前5个节点的接受率,然后链接到它们。
我在此过程中遇到问题:节点无法检查前5个节点的程度。这是代码:
to make-edge
if connection-strategy = "progressive" [
ask turtles [
if sum [count my-links] of turtles >= 1 [ set acceptance-rate 1 ]
if count my-links >= 10 [ set acceptance-rate 0.8]
if count my-links >= 20 [ set acceptance-rate 0.6]
if count my-links >= 30 [ set acceptance-rate 0.4]
if count my-links >= 40 [ set acceptance-rate 0.2] ]
ask last-turtle [
let top-5 sort-on [ count my-in-links ] max-n-of 5 turtles [ count my-in-links ]
show-results top-5 "Top five turtles using max-n-of:"
let sorted-turtles sort-on [ count my-in-links ] turtles
set top-5 n-of 5 sorted-turtles
if (random-float 1 < acceptance-rate) and (random-float 1 <= prob-of-linkage) [
create-link-from top-5 [ set color green ]
move-to top-5
fd 1] ] ]
if connection-strategy = "indifferent" [
ask last-turtle [
let candidate one-of turtles with [ count my-links > 0 ]
if (random-float 1 <= prob-of-linkage) [
set candidate one-of turtles with [ (count my-links) > 0]
create-link-from candidate [ set color green ]
move-to candidate
fd 1
]]]
end
to show-results [ turtle-list title ]
print title
foreach turtle-list [ t -> ask t [ show count my-in-links ] ]
end
谢谢
答案 0 :(得分:1)
我有点猜测,“节点无法检查前5名的程度”是什么意思。我认为您的意思是,已识别出正确的节点(具有最高学位的节点),但接受率未达到您的预期。
这是代码的更干净版本,已删除了不相关的connection-strategy = "indifferent"
代码块,并且缩进显示了代码块的结构。
to make-edge
if connection-strategy = "progressive"
[ ask turtles
[ if sum [count my-links] of turtles >= 1 [ set acceptance-rate 1 ]
if count my-links >= 10 [ set acceptance-rate 0.8]
if count my-links >= 20 [ set acceptance-rate 0.6]
if count my-links >= 30 [ set acceptance-rate 0.4]
if count my-links >= 40 [ set acceptance-rate 0.2]
]
ask last-turtle
[ let top-5 sort-on [ count my-in-links ] max-n-of 5 turtles [ count my-in-links ]
show-results top-5 "Top five turtles using max-n-of:"
let sorted-turtles sort-on [ count my-in-links ] turtles
set top-5 n-of 5 sorted-turtles
if (random-float 1 < acceptance-rate) and (random-float 1 <= prob-of-linkage)
[ create-link-from top-5 [ set color green ]
move-to top-5
fd 1
]
]
]
end
to show-results [ turtle-list title ]
print title
foreach turtle-list [ t -> ask t [ show count my-in-links ] ]
end
您还没有告诉我们什么是最后的乌龟。但是,看着这段代码,我怀疑您的问题出在行中:
if (random-float 1 < acceptance-rate) and (random-float 1 <= prob-of-linkage)
[ create-link-from top-5 [ set color green ]
接受测试的接受率是最后的乌龟。我怀疑您实际上希望相关的接受率是最后一只乌龟想要连接的乌龟所拥有的接受率。
优先连接算法通常的工作方式是将一个新节点连接到网络,并使其边缘化。因此,我的猜测是last-turtle是新节点,并且没有任何链接。这表示其接受率为0。
由于您尚未真正提供足够的信息来知道我的猜测是否正确,所以我不会尝试修复此代码。特别是,正在发生什么行为,这与您的预期有何不同?例如,是否存在未创建边缘或始终创建5个边缘的问题?...
一些注意事项:
move-to
会做什么请提供更多信息,我也许可以提供更好的答案。