如何基于Ravasz-Barabási层级网络论文用NetLogo实现递归式层级网络?
NetLogo实现Ravasz-Barabási层级网络模型的问题
问题概述
目标是基于Erzsebet Ravasz与Albert-Laszlo Barabási在2003年发表的论文《Hierarchical organization in complex networks》,用NetLogo实现第二章的层级网络模型及第三章的真实网络层级组织。但因NetLogo缺乏面向对象编程特性遇到阻碍,当前状态如下:
- 已完成第二章的初步代码,但无法按论文要求精确定位节点;改用NetLogo自带
layout过程后,节点连接逻辑出错(当n=2时,外围节点未正确连接到对应中心节点) - 尚未实现递归逻辑,无法适配第三章的需求
当前实现代码
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
内容的提问来源于stack exchange,提问作者kenjanaki
相关产品推荐
相关产品推荐

