Random Network Example

Random Network Example preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

code example 

Tagged by Reuven M. Lerner almost 11 years ago

networks 

Tagged by Reuven M. Lerner almost 11 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 2367 times • Downloaded 133 times • Run 1 time
Download the 'Random Network Example' modelDownload this modelEmbed this model

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

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

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.

Uploaded by When Description Download
Uri Wilensky almost 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky over 11 years ago Updated version tag Download this version
Uri Wilensky over 12 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky almost 14 years ago Random Network Example Download this version
Uri Wilensky almost 14 years ago Random Network Example Download this version

Attached files

File Type Description Last updated
Random Network Example.png preview Preview for 'Random Network Example' about 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.