我正在尝试将Netlogo模型库中的优先附件模型扩展到Bianconi-Barabasi模型(https://en.wikipedia.org/wiki/Bianconi%E2%80%93Barab%C3%A1si_model),我仍然坚持如何去做。随着"最新"模型库中的模型,我们有
to-report find-partner
report [one-of both-ends] of one-of links
end
我理解它是如何导致优先依恋的。但我不知道如何融入健身"进入这个简单的程序。
此外,在模型库中的先前版本的优先附件模型中,我们有
to-report find-partner
let total random-float sum [count link-neighbors] of turtles
let partner nobody
ask turtles
[
let nc count link-neighbors
;; if there's no winner yet...
if partner = nobody
[
ifelse nc > total
[ set partner self ]
[ set total total - nc ]
]
]
report partner
end
我再次想知道如何将适应性纳入此程序。我希望将指数分布的均衡性与均值1结合起来,所以,让我们说,我是否会增加类似"让nc(计数链接 - 邻居)*随机指数1?&# 34;请告诉我。
答案 0 :(得分:2)
JenB,谢谢。我重写了我的代码,如下所示,似乎这个代码产生了Bianconi和Barabasi在他们的论文中所描述的内容。再一次,谢谢你。
;;;;;;;;;;;;;;;;;;;;;;;
;;; Setup Procedures ;;;
;;;;;;;;;;;;;;;;;;;;;;;;
turtles-own [fitness]
to setup
clear-all
set-default-shape turtles "circle"
;; make the initial network of two turtles and an edge
make-node nobody ;; first node, unattached
make-node turtle 0 ;; second node, attached to first node
reset-ticks
end
;;;;;;;;;;;;;;;;;;;;;;;
;;; Main Procedures ;;;
;;;;;;;;;;;;;;;;;;;;;;;
to go
;; new edge is green, old edges are gray
ask links [ set color gray ]
make-node find-partner ;; find partner & use it as attachment
;; point for new node
tick
if layout? [ layout ]
end
;; used for creating a new node
to make-node [old-node]
crt 1
[
set color red
set fitness random-exponential 1
if old-node != nobody
[ create-link-with old-node [ set color green ]
;; position the new node near its partner
move-to old-node
fd 8
]
]
end
;; This code is the heart of the "preferential attachment" mechanism, and acts like
;; a lottery where each node gets a ticket for every connection it already has.
;; While the basic idea is the same as in the Lottery Example (in the Code Examples
;; section of the Models Library), things are made simpler here by the fact that we
;; can just use the links as if they were the "tickets": we first pick a random link,
;; and than we pick one of the two ends of that link.
to-report find-partner
let total random-float sum [(count link-neighbors) * fitness] of turtles
let partner nobody
ask turtles
[
let nc (count link-neighbors) * fitness
;; if there's no winner yet...
if partner = nobody
[
ifelse nc > total
[ set partner self ]
[ set total total - nc ]
]
]
report partner
end
;;;;;;;;;;;;;;
;;; Layout ;;;
;;;;;;;;;;;;;;
;; resize-nodes, change back and forth from size based on degree to a size of 1
to resize-nodes
ifelse all? turtles [size <= 1]
[
;; a node is a circle with diameter determined by
;; the SIZE variable; using SQRT makes the circle's
;; area proportional to its degree
ask turtles [ set size (sqrt count link-neighbors) ]
]
[
ask turtles [ set size 1 ]
]
end
to layout
;; the number 3 here is arbitrary; more repetitions slows down the
;; model, but too few gives poor layouts
repeat 3 [
;; the more turtles we have to fit into the same amount of space,
;; the smaller the inputs to layout-spring we'll need to use
let factor (sqrt count turtles)
;; numbers here are arbitrarily chosen for pleasing appearance
layout-spring turtles links (1 / factor) (7 / factor) (1 / factor)
display ;; for smooth animation
]
;; don't bump the edges of the world
let x-offset max [xcor] of turtles + min [xcor] of turtles
let y-offset max [ycor] of turtles + min [ycor] of turtles
;; big jumps look funny, so only adjust a little each time
set x-offset limit-magnitude x-offset 0.1
set y-offset limit-magnitude y-offset 0.1
ask turtles [ setxy (xcor - x-offset / 2) (ycor - y-offset / 2) ]
end
to-report limit-magnitude [number limit]
if number > limit [ report limit ]
if number < (- limit) [ report (- limit) ]
report number
end
; Copyright 2005 Uri Wilensky.
; See Info tab for full copyright and license.
答案 1 :(得分:1)
如果按照建议进行操作,则每次调用该过程时都会重新生成随机数。在我看来,每个节点的适应性是随机分配的,但一旦分配,它就是该节点的固定值。如果我正确地解释了模型,您需要在turtles-own
列表中添加一个变量以进行适应性,并在创建龟时简单地分配它。那么你将需要一个加权概率选择,你必须从头开始构建(我认为),没有明显的方法来修改你提供的程序。有关加权选择的想法,请查看this question。