Diffusion on a Directed Network

Diffusion on a Directed Network preview image

2 collaborators

Uri_dolphin3 Uri Wilensky (Author)



Tagged by Reuven M. Lerner about 11 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 1113 times • Downloaded 95 times • Run 3 times
Download the 'Diffusion on a Directed Network' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


This model demonstrates diffusion of a quantity through a directed network. The quantity moves among nodes in the network only along established, directed links between two nodes.

The simple rules that drive this diffusion lead to interesting patterns related to the topology, density, and stability of the network. Furthermore, the model may be useful in understanding the basic properties of dynamic processes on networks, and provides a useful starting point for designing more complex and realistic network-based models.


In each tick, each node shares some percentage (defined by the DIFFUSION-RATE slider) of its "value" quantity with its neighbors in the network. Specifically, the amount of shared value is divided equally and sent along each of the outgoing links from each node to each other node. If a node has no outgoing links, then it doesn't share any of it's value; it just accumulates any that its neighbors have provided via incoming links.

Note that because it is a directed network, node B may give value to node A even if node A doesn't give back.

The size of each node shows how much "value" that node has, where the area of the node is proportional to its value. The brightness of a link represents how much value just flowed through that edge.


Choose the size of network that you want to model using the GRID-SIZE slider.
Choose the expected density of links in the network using the LINK-CHANCE slider.

To create the network with these properties, press SETUP.

The DIFFUSION-RATE slider controls how much "value" each node shares with its neighbors during a given time step.

Press the GO button to run the model.

The REWIRE-A-LINK button causes one link to disappear, and a new one to appear elsewhere in the grid.

The KEEP-REWIRING button causes a continual rewiring of links to occur.

The histogram displays the number of nodes whose values fall into certain ranges. For instance, you might see that there are many nodes with nearly zero value, while there are just a few nodes with very large value.


As time passes, the network tends toward an equilibrium state. (Is that always the case, or is it possible for a network to never settle down?)

However, if you run both the GO and KEEP-REWIRING buttons at the same time, then the network will never completely settle down. If you ran the model in this way for a long long time, would the distribution of value across the nodes in the network be uniform, if you averaged across time? Or would nodes near the edges of the grid tend to have more or less value?


Try running the model with a small 3x3 grid. How many nodes end up with positive value (not approaching zero) after running the model for a while? Sometimes just a single node ends up with all of the value, while other times every node in the network can sustain a positive value. What properties of the network are necessary in order for every node to sustain a positive value? Are these properties more or less likely to occur with large networks?


Imagine you are modeling a business economy, where each node is a business, and it has suppliers and customers (represented by directed links from that node). Is it reasonable to assume that as a business accumulates more profit from sales, it will in turn purchase more from its suppliers? In order to more accurately match this economic model, change the model into a supply chain model where each node also has an inventory level, and a price they are charging per unit. Try to come up with reasonable rules for how many units each business decides to buy or sell.

How would you change this model to more accurately represent water flowing (or being pumped) through pipes? Should the links be directed or undirected? What if water is continually flowing in or out of the system at certain locations?


This model works in a manner analogous to NetLogo's diffuse command, which causes patches to all share with their neighbors portions of the value of some variable.
However, whereas the neighbor relationship in patches is symmetric, this model uses directed links, which can be used to create asymmetric relationships between agents. If you used undirected links, the behavior of this model would more closely resemble the diffuse command, where the value of all the nodes would eventually become the same.

In this model, there are two link-breeds: one for active links (which are shown in the view) and another for inactive links (which are invisible). This makes "rewiring" of links easier, because rather than killing a link and creating a new link, we can just change the breed of a link and hide or show it.


Virus on a Network


If you mention this model in a publication, we ask that you include these citations for the model itself and for the NetLogo software:


Copyright 2008 Uri Wilensky.


This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at uri@northwestern.edu.

Comments and Questions

Click to Run Model

directed-link-breed [active-links active-link]
directed-link-breed [inactive-links inactive-link]

turtles-own [ val new-val ] ; a node's past and current quantity, represented as size
links-own [ current-flow ]  ; the amount of quantity that has passed through a link
                            ; in a given step

globals [
  total-val                 ; total quantity in the system
  max-val                   ; maximum quantity held by a single node in the system
  max-flow                  ; maximum quantity that has passed through a link in the system
  mean-flow                 ; average quantity that is passing through an arbitrary
                            ; link in the system

;;; Setup Procedures ;;;

to setup
  set-default-shape turtles "circle"
  set-default-shape links "small-arrow-link"
  ; create the grid of nodes
  ask patches with [abs pxcor < (grid-size / 2) and abs pycor < (grid-size / 2)]
    [ sprout 1 [ set color blue ] ]

  ; create a directed network such that each node has a LINK-CHANCE percent chance of
  ; having a link established from a given node to one of its neighbors
  ask turtles [
    set val 1
    let neighbor-nodes turtle-set [turtles-here] of neighbors4
    create-active-links-to neighbor-nodes
      set current-flow 0
      if random-float 100 > link-chance
        set breed inactive-links
  ; spread the nodes out
  ask turtles [
    setxy (xcor * (max-pxcor - 1) / (grid-size / 2 - 0.5))
          (ycor * (max-pycor - 1) / (grid-size / 2 - 0.5))

;;; Main Procedure  ;;;

to go
  ask turtles [ set new-val 0 ]
  ask turtles [
    let recipients out-active-link-neighbors
    ifelse any? recipients [
      let val-to-keep val * (1 - diffusion-rate / 100)
      ; we keep some amount of our value from one turn to the next
      set new-val new-val + val-to-keep
      ; What we don't keep for ourselves, we divide evenly among our out-link-neighbors.
      let val-increment ((val - val-to-keep) / count recipients)
      ask recipients [
        set new-val new-val + val-increment
        ask in-active-link-from myself [ set current-flow val-increment ]
    ] [
      set new-val new-val + val
  ask turtles [ set val new-val ]

to rewire-a-link
  if any? active-links [
    ask one-of active-links [
      set breed inactive-links
    ask one-of inactive-links [
      set breed active-links

;;;     Updates     ;;;

to update-globals
  set total-val sum [ val ] of turtles
  set max-val max [ val ] of turtles
  if any? active-links [
    set max-flow max [current-flow] of active-links
    set mean-flow mean [current-flow] of active-links

to update-visuals
  ask turtles [ update-node-appearance ]
  ask active-links [ update-link-appearance ]

to update-node-appearance ; node procedure
  ; scale the size to be between 0.1 and 5.0
  set size 0.1 + 5 * sqrt (val / total-val)

to update-link-appearance ; link procedure
  ; scale color to be brighter when more value is flowing through it
  set color scale-color gray (current-flow / (2 * mean-flow + 0.00001)) -0.4 1

; Copyright 2008 Uri Wilensky.
; See Info tab for full copyright and license.

There are 10 versions of this model.

Uploaded by When Description Download
Uri Wilensky about 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 11 years ago Updated to version from NetLogo 5.0.3 distribution Download this version
Uri Wilensky over 12 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky about 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky about 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky about 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky about 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky about 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky about 14 years ago Diffusion on a Directed Network Download this version

Attached files

File Type Description Last updated
Diffusion on a Directed Network.png preview Preview for 'Diffusion on a Directed Network' over 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.