NetLogo banner

 Home
 Download
 Help
 Resources
 Extensions
 FAQ
 NetLogo Publications
 Contact Us
 Donate

 Models:
 Library
 Community
 Modeling Commons

 User Manuals:
 Web
 Printable
 Chinese
 Czech
 Farsi / Persian
 Japanese
 Spanish

  Donate

NetLogo Models Library:
Code Examples

(back to the library)

Random Network Example

[screen shot]

If you download the NetLogo application, this model is included. You can also Try running it in NetLogo Web

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

(back to the NetLogo Models Library)