Epidemic information diffusion for mobile nodes
This protocol defines an epidemic infection count, e. When a node in the IDLE state senses an environmental event it transitions into the SEND stand and informs the next e neighbors it encounters before reverting back to the IDLE state.
Protocol 6.5
Code designed by Matt Duckham. Additional coding by Alan Both and Hai Ruo Xie.
Copyright 2011, 2012 Matt Duckham
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License http://www.gnu.org/licenses/ for more details.
The formal specification procedure used for all the protocols on this site is based on the standard distributed systems approach of Nicola Santoro (see Santoro, N. Design and Analysis of Distributed Algorithms. Wiley, Hoboken, NJ. 2007.) For more details on the protocol specification style, please refer to the book accompanying book for this website, Decentralized Spatial Computing: Foundations of Geosensor Networks.
;; Copyright 2011, 2012 Matt Duckham ;; ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <http://www.gnu.org/licenses/>. __includes["../gsn.nls" "../env.nls"] ;; Last time that a region is changed, Last time that motes locations are changed globals [region_timestamp motes_timestamp] ;; Define a new breed of turtle called motes breed [motes mote] ;; Each mote can store the local variables s which is the sensed value and ee which is the infection count. motes-own [s ee] ;; System setup and initialization to initialize make-single-region RegionSize ;; Create the region if NetworkStructure = "UDG" [create-udg] ;; Create UDG network if NetworkStructure = "GG" [create-udg create-gg] ;; Create GG network if NetworkStructure = "RNG" [create-udg create-rng] ;; Create RNG network ask motes [ update-reading ;; Update locally sensed data become "IDLE" ;; Set all motes to state IDLE set ee infection# ;; Set the maximum number of neighbors that can receive the message set color white rt random-float 360 ;; Let the mote face a random direction ] set region_timestamp 0 ;; Reset the timestamp of the creation of new region set motes_timestamp 0 ;; Reset the timestamp of the creation of new mote locations and communication graph end ;; Generate sensed data to update-reading ifelse [region] of patch-here = ["A"] [set s 1] ;; When region detected, s equals 1 [set s 0] ;; When region not detected, s equals 0 end ;; Runs the epidemic diffusion algorithm to go ask motes [step] mote_labels ;; Changes the labels of the motes based on the MoteLabel dropdown list tick ;; Update the locations of motes and communication graph when interval elapsed if (ticks - motes_timestamp) >= MoteMoveInterval [ ask motes [ move-mote CorrelatedRandomWalk LevyFlight ;; Next movement of mote ] clear-links ;; Delete all existing links between motes if NetworkStructure = "UDG" [create-udg] ;; Create UDG network if NetworkStructure = "GG" [create-udg create-gg] ;; Create GG network if NetworkStructure = "RNG" [create-udg create-rng] ;; Create RNG network set motes_timestamp ticks ;; Update the timestamp of mote location change ask motes [update-reading] ;; Update sensed values of the motes ] ;; Alter region when the RegionChangeInterval value has elapsed if (ticks - region_timestamp) >= RegionChangeInterval [ ;; Interval has elapsed if RegionMovement != "Static" [ ;; Do nothing to the region if it is static if RegionMovement = "Uncorrelated" [ ask patches [ ;; Clear patches set pcolor white set region [] ] make-single-region RegionSize ;; Create a new region that is unrelated to the existing region ] if RegionMovement = "Evolving" [ evolve-region ["A"] RegionSize ;; Incrementally change the existing region ] set region_timestamp ticks ;; Update the region change timestamp ask motes [ ;; When region changes, reset motes and update sensed values update-reading become "IDLE" ;; Set state to IDLE set messages [] ;; Clear messages set ee infection# ;; Reset infection count set color white ] ] ] end ;; ;; Mote protocols ;; ;; Step through the current state to step if state = "IDLE" [ step_IDLE stop ] if state = "SEND" [ step_SEND stop ] end ;; When a mote detects an environmental event, it transitions into the SEND state. If it ;; receives a message, it changes its color to mid-blue. to step_IDLE if s = 1 [ ;; Check for presence of sensed variable become "SEND" ] if has-message "MSGE" [ ;; Receiving message let msg received "MSGE" set color 95 ;; Become mid-blue when message is received stop ] end ;; Motes in the SEND state will send ee messages where ee is the infection count before ;; reverting to the IDLE state. ;; Motes receiving the MSGE message will change their color to mid-blue. to step_SEND let c_nbr count link-neighbors if c_nbr > 0 [ ;; Check for presence of sensed variable ifelse ee >= c_nbr ;; If the infection count is larger the amount of neighbors [ broadcast (list "MSGE") ;; Broadcast MSGE to neighbors set ee (ee - c_nbr) ;; Reduce the infection count by the amount of neighbors ] [ ;; If the amount of neighbors is larger than the infection count send (list "MSGE") n-of (ee) link-neighbors ;; Send MSGE to ee arbitrarily chosen neighbors set ee 0 become "SEND" ] if ee = 0 [ ;; If infected sufficient neighbors set ee infection# ;; Infection count reset become "IDLE" ;; Revert to IDLE state ] ] if has-message "MSGE" [ ;; Receiving message let msg received "MSGE" set color 95 ;; Become mid-blue when message is received stop ] end ;; Changing the labels of the motes based on the MoteLabel dropdown list to mote_labels ask motes [ if MoteLabel = "none" [set label ""] ;; Hide the label if MoteLabel = "mote id" [set label who] ;; Show mote id if MoteLabel = "sensed value" [set label s] ;; Show sensed value if MoteLabel = "infection count" [set label ee] ;; Show epidemic infect count ] end
The NetLogo procedures for this applet can be downloaded directly as: Protocol6.5.nlogo
All the NetLogo simulation models for this book depend on two library files: gsn.nls and env.nls
These files should be placed in the parent directory of the .nlogo file (and are common to all the .nlogo models on this website).