;;;; SUMMARY ;; Nodes make and break undirected links ;;;; COPYRIGHT ;; Copyright (C) 2006 James P. Steiner ;; ;; ;; globals [ center ] breed [ link2s link2 ] breed [ nodes node ] ;; last defined breed displays front-most to startup setup end to setup ca set-default-shape link2s "link2" set-default-shape nodes "circle" ;; create 15 nodes, cause every node to link ;; with some other node that is not already linked ;; to this node. create-custom-nodes 15 [ __create-link2-with (one-of nodes with [ self != myself and not __link2-neighbor? myself ] ) [ ] ] ;; size nodes based on number of links ask nodes [ set-size-by-link-count ] select-new-center-node layoutx 100 end to layoutx [ x ] repeat x [ __layout-spring nodes .1 5 .5 ] end to layout __layout-spring nodes .05 5 5 end to go no-display every (3 + random-float 2) [ remove-a-random-link ] every (1 + random-float 2) [ make-a-new-random-connection ] every .1 [ update-layout ] every (10 + random-float 5) [ select-new-center-node ] display end to set-size-by-link-count ;; a node sets its size based on the number ;; of links to/from the node set size 1 + .25 * count __my-link2s end to remove-a-random-link ;; pick a random link, ;; ask that link to resize its nodes as if ;; the link wasn't there... ;; then kill the link if any? link2s [ ask one-of link2s [ let e2 __end2 ask __end1 [ __remove-link2-with e2 set-size-by-link-count ] ask __end2 [ set-size-by-link-count ] die ] ] end to make-a-new-random-connection ;; pick a random node ask one-of nodes [ ;; pick another node that is not connected to this node and has the fewest links let n min-one-of nodes with [ self != myself and not __link2-neighbor? myself ] [ count __my-link2s ] ;; if there is any such node, link to it, and change size if is-turtle? n [ __create-link2-with n [ ] set-size-by-link-count ask n [ set-size-by-link-count ] ] ] end to update-layout ;; update the layout, ;; method: ;; move the "center" node toward the center ;; remember that position ;; use the auto-layout tool ;; restore the position of the center node ;; (so it is not affected by the auto-layout tool) ask center [ facexy 0 0 jump .1 ] let x xcor-of center let y ycor-of center layout ask center [ setxy x y ] end to select-new-center-node ;; restore the shape of the old center if is-turtle? center [ ask center [ set shape "circle" ] ] ;; pick a new center (could pick the same one again, that's ok) set center one-of nodes ;; change the shape of the new center ask center [ set shape "open" ] end @#$#@#$#@ GRAPHICS-WINDOW 69 10 284 246 20 20 5.0 1 10 1 1 1 0 0 0 1 -20 20 -20 20 CC-WINDOW 5 260 293 355 Command Center 0 BUTTON 10 10 65 43 NIL setup NIL 1 T OBSERVER NIL NIL BUTTON 10 46 65 79 NIL go T 1 T OBSERVER NIL NIL TEXTBOX 12 90 59 154 Click Go to start and stop animation. @#$#@#$#@ @#$#@#$#@ default true 6 Polygon -13840069 true true 150 5 40 250 150 205 260 250 link true 6 Line -13840069 true 150 0 150 300 link direction true 6 Line -13840069 true 150 150 30 225 Line -13840069 true 150 150 270 225 Circle -13840069 true true 90 30 120 circle false 6 Circle -1 true false 0 0 300 Circle -13840069 true true 30 30 240 link2 true 6 Line -13840069 true 120 0 180 300 Line -13840069 true 180 0 120 300 link2 direction true 6 Polygon -13840069 true true 0 300 150 0 300 300 open false 6 Circle -13840069 true true 0 0 300 Circle -16777216 true false 29 29 242 @#$#@#$#@ NetLogo 3.1.1 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ @#$#@#$#@