Random Network Example
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
This shows how to create two different kinds of random networks. In an Erdos-Renyi network, each possible link is given a fixed probability of being created. In a simple random network, a fixed number of links are created between random nodes.
THINGS TO NOTICE
SETUP-SIMPLE-RANDOM is fast as long as the number of links is small relative to the number of nodes. If you are making networks which are nearly fully connected, then we suggest using the following code instead:
ask turtles [ create-links-with other turtles ]
ask n-of (count links - num-links) links [ die ]
SETUP-ERDOS-RENYI can also be written using the same idiom:
ask turtles [ create-links-with other turtles ]
ask links with [random-float 1.0 > probability] [ die ]
Compared to the code in the Code tab, this avoids the potentially confusing use of self > myself
, but runs somewhat slower, especially if the linking probability is small.
EXTENDING THE MODEL
Use the layout-spring
command, or one of the other layout-*
commands, to give the network a visually pleasing layout.
RELATED MODELS
Network Example - how to dynamically create and destroy links Preferential Attachment and Small Worlds (found under Sample Models, not under Code Examples) - how to create some other kinds of networks Network Import Example - how to create a network based on data from a file
CREDITS AND REFERENCES
Comments and Questions
to setup-simple-random clear-all ;; Make a circle of turtles create-turtles num-nodes layout-circle turtles (max-pxcor - 1) ;; Now make links one at a time until we have enough while [count links < num-links] [ ;; Note that if the link already exists, nothing happens ask one-of turtles [ create-link-with one-of other turtles ] ] end to setup-erdos-renyi clear-all ;; Make a circle of turtles create-turtles num-nodes layout-circle turtles (max-pxcor - 1) ;; Now give each pair of turtles an equal chance ;; of creating a link ask turtles [ ;; we use "self > myself" here so that each pair of turtles ;; is only considered once create-links-with turtles with [self > myself and random-float 1.0 < probability] ] end ; Public Domain: ; To the extent possible under law, Uri Wilensky has waived all ; copyright and related or neighboring rights to this model.
There are 10 versions of this model.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Random Network Example.png | preview | Preview for 'Random Network Example' | over 11 years ago, by Uri Wilensky | Download |
This model does not have any ancestors.
This model does not have any descendants.