Network Import Example
Model was written in NetLogo 5.0.4
•
Viewed 303 times
•
Downloaded 30 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
turtles-own [node-id] links-own [strength] globals [links-list] to import-network clear-all set-default-shape turtles "circle" import-attributes layout-spring turtles links 0.3 (world-width / (sqrt 62)) 1 import-links end ;; This procedure reads in a files that contains node-specific attributes ;; including an unique identification number to import-attributes ;; This opens the file, so we can use it. file-open "attributes.txt" ;; Read in all the data in the file ;; data on the line is in this order: ;; node-id attribute1 attribute2 while [not file-at-end?] [ ;; this reads a single line into a three-item list ;let patch-elevations file-read ; print (file-read) ;let items read-from-string (word "[" file-read-line "]") ;let next-turtle file-read crt 1 [ let next-node-id file-read ; set node-id item 0 items ;set size item 1 items ;set color item 2 items set label next-node-id ] ] file-close end ;; This procedure reads in a file that contains all the links ;; The file is simply 3 columns separated by spaces. In this ;; example, the links are directed. The first column contains ;; the node-id of the node originating the link. The second ;; column the node-id of the node on the other end of the link. ;; The third column is the strength of the link. to import-links ;; This opens the file, so we can use it. file-open "links.txt" ; show file-read-line ;; Read in all the data in the file while [not file-at-end?] [ ;; this reads a single line into a three-item list let items read-from-string (word "[" file-read-line "]") ask get-node (item 0 items) [ create-link-with get-node (item 1 items) ; [ set label item 2 items ] ] ] file-close end ;; Helper procedure for looking up a node by node-id. to-report get-node [id] report one-of turtles with [node-id = id] end ; Public Domain: ; To the extent possible under law, Uri Wilensky has waived all ; copyright and related or neighboring rights to this model.
There is only one version of this model, created about 12 years ago by wang liting.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Network Import Example.png | preview | Preview for 'Network Import Example' | about 12 years ago, by wang liting | Download |
This model does not have any ancestors.
This model does not have any descendants.