I’m trying to code a hierarchical network using NetLogo following the paper “Hierarchical organization in complex networks” (2003) by Erzsebet Ravasz and Albert-Laszlo Barabasi. I first would like to build the model in Section II (Hierarchical Network Model) and then Section III (Hierarchical Organization in Real Networks) but struggling to find a way to implement it due to lack of Object Oriented Programming in NetLogo.
text
So far, here’s my code for Section II (Hierarchical Network Model):
globals[dist help generation-count]
turtles-own[
center-node?
generation
model?
]
to setup
ca
set dist 1.2
crt num[
create-links-with other turtles
set shape "dot"
set size 1.5
]
let c 0
repeat (num - 1)[
ask one-of turtles with[xcor = 0 and ycor = 0][
set heading 360 / (num - 1) * c fd dist
]
set c c + 1
]
ask turtles[
ifelse(xcor = 0 and ycor = 0)[set center-node? true][set center-node? false]
set color red
set generation 1
set model? true
]
set generation-count 1
; repeat x[recreate]
end
to recreate
set generation-count generation-count + 1
let c 0
set help count turtles
loop [
ask turtles with[model? = true][
hatch 1 [
set generation generation-count
repeat generation - 1[
set heading 0
set heading (heading + 360 / (num - 1) * c)
fd generation * dist
]
set model? false
]
]
finish-member(turtles with[count link-neighbors = 0])
set c c + 1
ask turtles with[center-node? = false and generation = generation-count][create-links-with other turtles with[center-node? = true and generation = 1]]
;layout
if(count turtles = help * num)[stop]
]
end
to finish-member[people]
ask people[create-links-with other people]
end
to layout
;; the number 3 here is arbitrary; more repetitions slows down the
;; model, but too few gives poor layouts
repeat 100 [
;; Refactoring the link lengths (MODIFY DENSITY HERE?)
;; 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) / 3) ;; Here SF-density-mod influences the distance factor across the network - will impact search function...
;; numbers here are arbitrarily chosen for pleasing appearance
layout-spring turtles links (1 / factor) (7 / factor) (1 / factor)
display ;; for smooth animation
]
;;; Centering network ;;;
;; 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
I was unable to position them like in the paper so I resorted to the NetLogo “layout” procedure but then I realized the way they were being linked is also incorrect; the peripheral outer nodes are not correctly linking to the peripheral central nodes.
Expected
My Model
The attached picture is for when n=2, which is just incorrect.
I want to be able to somehow use recursion so I can also use it for Section III (Hierarchical Organization in Real Networks) as well.
Please help me find a solution to this.
kenjanaki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.