⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ---peernet.nlogo

📁 NETLOGO
💻 NLOGO
📖 第 1 页 / 共 2 页
字号:
; ToDo: Seth Tisue: Make inEdges/outEdges lists of turtles thus agentlists; Make controls clearer w/ In/Out labels;globals [    steps         ; Number of steps the model has made (think hours for peers)    graphs        ; List of connected sub graphs in peer network    maxgraph      ; The ID of the graph with the largest number of nodes    percent       ; Percent of total maxgraphsize is    maxgraphsize  ; The number of nodes is has    totalEdges    ; Total number of edges]turtles-own [    inEdges       ; List of IDs of nodes pointing to me    outEdges      ; List of IDs of nodes I point to    numOutEdges   ; Number of out edges I'm supposed to maintain    nhood         ; The nodes in my neighborhood    ttl           ; The number of steps until I go off the air    graph         ; The subnet I currently belong to]to-report edgeCount    report length outEdges + length inEdgesendto setup    clear-all    set-default-shape turtles "circle"    set steps 0    create-custom-turtles (screen-size-x * screen-size-y) [        set ycor (screen-edge-y - floor (who / screen-size-x))        set xcor (who mod screen-size-x) - screen-edge-x        set color gray        set inEdges []        set outEdges []        set ttl 0        set numOutEdges 0        ifelse drawLabels? [set label  0 + " "][set label no-label]    ]    ask turtles [ ; need second pass for nhood: all turtles created & in place        set nhood turtles with [            (distance myself <= radiusRange) and (who != who-of myself)        ]    ]endto step    set steps steps + 1    ask turtles [        ifelse (ttl = 0) [            if ( random 100 < birthProbability ) [createNode]        ] [            set ttl ttl - 1            if (ttl = 0) [destroyNode]        ]    ]    ; nodes may need to add links anytime they are reduced    ; by deletions or because there were previously too     ; few "on" neighbors available    ask turtles with [numOutEdges > length outEdges] [        addOutEdges (numOutEdges - length outEdges)    ]    calcGraphs    set totalEdges 0    ask turtles [        ;set edgeCount length outEdges + length inEdges        ifelse (ttl = 0) [hideturtle][            set totalEdges totalEdges + edgeCount            set color (position graph graphs) * 10 + red            ifelse drawLabels?                 [set label (length outEdges + length inEdges) + " "]                [set label no-label]            showturtle        ]    ]    set totalEdges totalEdges / 2 ; Resolve double count    doPlotsendto createNode    set ttl 1 + random lifeRange    set numOutEdges 1 + random edgesRangeendto destroyNode    locals [myID]    set ttl 0    set numOutEdges 0    set myID who    ask nhood [        set inEdges remove myID inEdges        set outEdges remove myID outEdges    ]    set inEdges []    set outEdges []endto addOutEdges [numEdges]    locals [myID theirID them]    set myid who    repeat numEdges [        set them random-one-of nhood with [            not (member? myID outEdges or member? myID inEdges or ttl = 0)        ]        if (them != nobody) [            ask them [                set inEdges fput myID inEdges                set theirID who            ]            set outEdges fput theirID outEdges        ]    ]endto calcGraphs    locals[stack node edges graphsize]    set graphs [] ; reset list of graphs    set maxgraphsize 0    ask turtles [set graph -1] ; reset which graph each turtle belongs to    ask turtles with [ttl > 0] [        ; important! must be sequential due to state kept in turtles        without-interruption [             if (graph = -1) [ ; if this turtle not yet in a graph, make root of next graph                set stack [] ; stack of current batch of turtles to be processed                set stack fput turtle who stack                set graph who                set graphs lput who graphs                set graphsize 0                while [length stack > 0] [                    set node first stack                    set stack but-first stack                    set graphsize graphsize + 1                    set edges sentence inEdges-of node outEdges-of node                    while [length edges > 0] [                        set node turtle first edges                        set edges but-first edges                        if (graph-of node = -1) [                            set graph-of node who                            set stack lput node stack                        ]                    ]                    if (graphsize > maxgraphsize) [                        set maxgraph who                        set maxgraphsize graphsize                    ]                ]            ]        ]    ]    set graphs sentence maxgraph remove maxgraph graphs    set percent maxgraphsize / count turtles with [ ttl > 0 ]endto doPlots    set-current-plot "Nodes"    set-current-plot-pen "One"        plot count turtles with [edgeCount = 1]    set-current-plot-pen "Two"        plot count turtles with [edgeCount = 2]    set-current-plot-pen "Three"        plot count turtles with [edgeCount = 3]    set-current-plot-pen "Four"        plot count turtles with [edgeCount = 4]    set-current-plot-pen "Five"        plot count turtles with [edgeCount = 5]    set-current-plot-pen "Six"        plot count turtles with [edgeCount = 6]    set-current-plot-pen ">Six"        plot count turtles with [edgeCount > 6]    set-current-plot "EdgeHistogram"    set-histogram-num-bars 10    histogram-from turtles with [ttl > 0] [edgeCount]end@#$#@#$#@GRAPHICS-WINDOW30910739461101020.0112000CC-WINDOW309467731587Command CenterBUTTON6436176NILsetupNIL1TOBSERVERTSLIDER13179303112lifeRangelifeRange110411NILBUTTON67861111NILstepNIL1TOBSERVERTSLIDER131117303150radiusRangeradiusRange15211NILSLIDER1314230375birthProbabilitybirthProbability11002011NILSLIDER131153304186edgesRangeedgesRange18211NILBUTTON611262145gostepT1TOBSERVERTMONITOR674412493NILsteps

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -