【发布时间】:2021-09-09 15:55:13
【问题描述】:
我是 Netlogo 新手,边做边学,希望有人能帮我解决看似简单的操作:
在每个滴答声中,对于每个海龟 X,我想以一定的概率创建或加强到半径 radius 内的其他海龟 Y 的无向链接 createlinkprob。如果 X 和 Y 之间存在链接已经,我想增加该链接的多重性。 (由于 Netlogo 只允许存在一个链接,因此我需要将多重性存储在链接变量中,以指示更强的链接。)我似乎无法弄清楚如何做到这一点。
以下代码大致说明了我想要的,但不起作用。 (在 to generate-event 的内部“询问”中 对于半径内的所有海龟,我的理解是“我自己”是指调用海龟 X,而“自我”是指 Y。这部分似乎有效。我正在尝试使用 who 数字来识别链接,但那部分没有。)
感谢您提供的任何帮助!
links-own
[
multiplicity
]
to setup
clear-all
make-turtles
reset-ticks
end
to make-turtles
create-turtles num-nodes [ set size 3 ]
;; layout-circle turtles max-pxcor - 1
ask turtles [
;; move each turtle to a random point
setxy random-xcor random-ycor
]
end
to go
generate-event
ask turtles
[
fd random 2
rt -5 + random 10
]
ask links
[
if random 100 < removelinkprob
[ifelse multiplicity = 1 [die] [set multiplicity multiplicity - 1]]
]
tick
end
to generate-event
;; at every event - one per tick - each turtle may connect to others in radius R with probability createlinkprob/100.
;; If already connected, the multiplicity value is incremented.
;; Otherwise, the multiplicity value is set to 1 and a link is created.
ask turtles
[
ask other turtles in-radius radius
[if random 100 < createlinkprob [
ifelse in-link-neighbor? myself
[
ask link who (show [who] of myself) set multiplicity (multiplicity + 1)
]
[create-link-with myself [set multiplicity 1]]]
]
]
end
; based on http://ccl.northwestern.edu/netlogo/models/GiantComponent
; Copyright 2005 Uri Wilensky.
; Modified by Michael Frishkopf
; under Creative Commons license: https://creativecommons.org/licenses/by-nc-sa/3.0/
【问题讨论】:
-
您应该提供minimal reproducible example。那些想要帮助您的人需要能够将您提供的代码复制并粘贴到 NetLogo 中,并有一个可以使用的功能示例;而不必围绕您提供的示例自己创建代码,而不是回答问题,而只是开始研究它。
-
谢谢;我提供了一个我认为是最小的示例,尽管由于引用的原因它不会运行。
标签: simulation netlogo agent-based-modeling