2

I am trying to extend the preferential attachment model that is in the model library of Netlogo to Bianconi-Barabasi model (https://en.wikipedia.org/wiki/Bianconi%E2%80%93Barab%C3%A1si_model), and I am stuck with how to do it. With the "newest" model in the model library, we have

to-report find-partner
  report [one-of both-ends] of one-of links
end

and I understand how it causes the preferential attachment. But I do not know how to incorporate the "fitness" into this simple procedure.

Also, in the previous version of the preferential attachment model that was in the model library, we have

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

and I am again wondering how to incorporate the fitness into this procedure. I want to incorporate the fitness that comes from the exponential distribution with mean 1, so, let's say, do I multiply something like "let nc (count link-neighbors) * random-exponential 1?" Please let me know.

Robert
  • 51
  • 3

2 Answers2

2

JenB, thank you. I rewrote my code as below, and it seems this one produces what Bianconi and Barabasi described in their paper. Once again, thank you.

;;;;;;;;;;;;;;;;;;;;;;;
;;; 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.
Robert
  • 51
  • 3
1

If you do as you suggest, then the random number will be regenerated each time the procedure is called. It looks to me like the fitness for each node is assigned randomly but, once assigned, it is a fixed value for that node. If I have interpreted the model correctly, you will need to add a variable to the turtles-own list for fitness and simply assign it when the turtle is created. Then you are going to need a weighted probability selection, which you will have to build from scratch (I think), there's no obvious way to modify the procedure you have provided. Have a look at this question for weighted selection ideas.

Community
  • 1
  • 1
JenB
  • 17,620
  • 2
  • 17
  • 45