powered by NetLogo
view/download model file: SmallWorldDiffusionSIS.nlogo
This is an SIS model on a Watts-Strogatz small world topology. Nodes are either susceptible (S) or infected (I).
"This model is an adaptation of a model proposed by Duncan Watts and Steve Strogatz (1998). It begins with a network where each person (or "node") is connected to his or her two neighbors on either side... The REWIRING-PROBABILITY slider determines the probability that an edge will get rewired" (so that one of its endpoints goes to a random node instead of a neighbor). Clicking the setup button will produce different network configurations, all with the same rewiring probability.
The prob-infection slider determines the probability that an infected individual will infect a susceptible contact at every time step.
The prob-recover slider determines the probability that an infected individual will recover and itself rejoin the susceptible population rather than infecting its neighbors.
"The NUM-NODES slider controls the size of the network. Choose a size and press SETUP.
Changing the REWIRING-PROBABILITY slider changes the fraction of nodes rewired." Press SETUP to generate the new network. SETUP will also infect one node.
Adjust the prob-infection value to determine the infectiousness of the spreading agent.
To re-infect one will infect a single individual while keeping the same topology - press "reinfect-one".
Now to allow the disease to spread, you can advance on time step at a time (each infected node will infect each of its neighbors with probability prob-infection) with the "spread once" button. To let the disease run its full course, you can click the "spread complete" button.
You can also slow down the process using the slower-faster slider at the top of the model interface.
Try plotting the values for different rewiring probabilities and observe how long the infection survives in the network, and how far it spreads.
What happens as the probability of recovery increases?
What happens as the probability of infection increases?
Can you find a critical threshold in the infection and recovery probabilities such that for a given rewiring probability, below these threshold values the disease always dies out, and above the threshold value, it tends to persist in the network? In this case you are looking for the conditions under which you will observe epidemics - outbreaks that affect a significant fraction of the network, vs. conditions under which the outbreak remains small and contained.
See other models in the Networks section of the Models Library, such as Giant Component and Preferential Attachment. Also check out Lada's other NetLogo models:
This model was adapted from: Wilensky, U. (2005). NetLogo Small Worlds model. http://ccl.northwestern.edu/netlogo/models/SmallWorlds. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.
It was written by Lada Adamic and Eytan Bakshy in 2007 and 2008
globals [ num-infected infected-size ] turtles-own [ infected? ;; true if agent has been infected ] ;;;;;;;;;;;;;;;;;;;;;;; ;;; Main Procedures ;;; ;;;;;;;;;;;;;;;;;;;;;;; to spread ;; or if every agent has already been infected if all? turtles [infected?] [stop] ask turtles with [ infected? = true ] [ ifelse (random-float 1 <= prob-recover) [ reset-node ] [ ;; infect neighbors ask link-neighbors [ if ( random-float 1 <= prob-infection ) ;; infect with probability p [ if not infected? ;; agents can be infected only once [ set infected? true show-turtle set color yellow set size infected-size ;; color the link with the node doing the infection ask link-with myself [set color yellow show-link] ;; increment the total number of infected agents ] ] ] ] ] do-plotting set num-infected count turtles with [infected? = true] tick end ;;layout all nodes and links to do-layout repeat 5 [layout-spring turtles links 0.2 4 0.9] display end ;;;;;;;;;;;;;;;;;;;;;;;; ;;; Setup Procedures ;;; ;;;;;;;;;;;;;;;;;;;;;;;; to generate-topology ca set infected-size 4 set-default-shape turtles "outlined circle" ;; setup small world topology create-turtles num-nodes create-lattice rewire-network setup end to setup set infected-size 4 ask turtles [reset-node] ask links [set color gray + 1.5] ;; infect a single agent ask one-of turtles [ set infected? true set color yellow set size infected-size ] set num-infected 1 ;; Layout turtles: layout-circle (sort turtles) max-pxcor - 8 ;; space out turtles to see clustering ask turtles [ facexy 0 0 if who mod 2 = 0 [fd 4] ] display end to reset-node set color gray + 1.5 set size 3 set infected? false end ;; WARNING: the simplified rewiring algorithm does not certain checks (ie disconnected graph) ;; for large networksthis shouldn't be too much of an issue. to rewire-network ask links [ ;; whether to rewire it or not? if (random-float 1) < rewiring-probability [ ask end1 [ create-link-with one-of other turtles with [not link-neighbor? myself ] [set color gray + 1.5] ] die ] ] end ;; creates a new lattice to create-lattice ;; iterate over the nodes let n 0 while [n < count turtles] [ ;; make links with the next two neighbors ;; this makes a lattice with average degree of 4 make-link-between turtle n turtle ((n + 1) mod count turtles) make-link-between turtle n turtle ((n + 2) mod count turtles) set n n + 1 ] end ;; connects the two nodes to make-link-between [node1 node2] ask node1 [ create-link-with node2 [ set color gray + 1.5] ] end ;;;;;;;;;;;;;;;; ;;; Plotting ;;; ;;;;;;;;;;;;;;;; to do-plotting ;; plot the number of infected individuals at each step set-current-plot "% infected" set-current-plot-pen "inf" let percent-inf 100 * (num-infected ) / (count turtles) plotxy ticks percent-inf end