[If applet doesn't load (e.g. in Firefox on Mac), please try another browser.]
powered by NetLogo
view/download model file: LatticePercolation.nlogo
This model shows site percolation on a 2D square lattice
Push the SETUP-LATTICE button once to activate a percentage p of the sites. Sites can only connect to those directly above, below, or left or right. They cannot connect diagonally.
The applet will then find the largest connected component, and mark its size, and the value of p on the plot with a black dot.
If you want to systematically vary p from 0 to 90%, then click the corresponding button. A red curve will show how the size of the giant component varies as p is varied.
Is there a critical value of p at which a giant cluster forms?
; Copyright 2008 by Lada Adamic.
; This model is licensed under a Creative Commons Attribution 3.0 License.
; You can refer to this model as:
; A model of site percolation on a 2D lattice globals [ giant-component-size giant-start-patch component-size to-visit ] patches-own [ explored? ; whether patch has been visited alive? ; whether patch is on ] to setup-lattice-once setup do-plot-once end to setup set to-visit  set giant-start-patch nobody ask patches [ ; with probability p, turn the patch on ifelse (random-float 100.0 < p) [ set pcolor black set alive? true ][ set pcolor white set alive? false ] ] find-all-components color-giant-component display end ; vary p from 0 to 90% to vary-p clear-plot set p 0 while [p < 91] [ setup set p p + 1 do-plot ] end ;; to find all the percolating clusters in the lattice, their sizes and starting patches ;; this code adapted from: See http://ccl.northwestern.edu/netlogo/models/GiantComponent to find-all-components set giant-component-size 0 ask patches [ set explored? false ] loop [ ;; pick a node that has not yet been explored let start one-of patches with [ not explored? and alive?] ; print (count patches with [not explored? and alive?]) if start = nobody [ stop ] ; print start set component-size 0 ;; at this stage, we recolor everything to light gray ; ask start [ explore item ( random length base-colors ) base-colors ] set to-visit fput start to-visit explore (gray + 2) ;; the explore procedure updates the component-size variable. ;; so check, have we found a new giant component? if component-size > giant-component-size [ set giant-component-size component-size set giant-start-patch start ] ] end ;; Finds all pathes reachable from this patch (and recolors them) ;; this code adapted from http://ccl.northwestern.edu/netlogo/models/GiantComponent to explore [new-color] let current-patch nobody while [not empty? to-visit] [ set current-patch item 0 to-visit set to-visit remove-item 0 to-visit ; print current-patch ask current-patch [ if explored? [stop] set explored? true if (not alive?) [stop] set component-size component-size + 1 set pcolor new-color ask patches at-points [[-1 0] [1 0] [0 1] [0 -1]] with [(not explored?) and alive?] [ if (not explored?) [ set to-visit fput self to-visit ] ] ] ] end ;; color the largest percolation cluster red to color-giant-component ask patches [ set explored? false ] if (giant-start-patch != nobody) [ set to-visit fput giant-start-patch to-visit explore red ] end to do-plot ;; This plot displays the number of patches that are in the giant component. set-current-plot "percolation" set-current-plot-pen "default" plotxy p giant-component-size end to do-plot-once ;; This plot displays the number of patches that are in the giant component. set-current-plot "percolation" set-current-plot-pen "oneplot" plotxy p giant-component-size end ; *** NetLogo 4.0 Model Copyright Notice *** ; ; Copyright 2008 by Lada Adamic. ; ; This model is licensed under a Creative Commons Attribution 3.0 License. ; http://creativecommons.org/licenses/by/3.0/ ; ; You can refer to this model as: ; http://projects.si.umich.edu/netlearn/NetLogo4/LatticePercolation.html ; ; *** End of NetLogo 4.0 Model Copyright Notice ***