Protocol 5.7: Determining the (inner) boundary nodes and cycle for a region

PROTOCOL

Determining the (inner) boundary nodes and cycle for a region (cf. Protocol 4.14)

SUMMARY

Similar to Protocol 4.14, this algorithm finds motes making up the inner boundary of a region by determining if the mote is in the region but has one or more neighbors outside of the region.

The cyc function is then used to find the first neighbor inside the region in an anticlockwise direction from a neighbor outside the region. This neighbor will be the next mote in the boundary cycle and its id will be set as the wind value.

OPERATION

Click the Setup button to generate a network based on communication distance and network size.

Click the Go! button to run the algorithm.

NOTICE

The region is green in color, once the algorithm runs, BNDY motes should appear in mid-blue around the edges.

Use the MoteLabel list to change the labels to the mote id, sensed value or wind value.

TRY

Try selecting GG or RNG from the NetworkStructure drop-down box to change the network shape to a Gabriel Graph or Relative Neighborhood Graph. Does the algorithm run any differently for planar and non-planar graphs?

Try running the algorithm slowly to get a better idea of how the algorithm runs. Change this by adjusting the speed slider.

LINK TO BOOK

Protocol 5.7

CREDITS

Code designed by Matt Duckham. Additional coding by Alan Both.

LICENSE

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"]
;; Define a new breed of turtle called motesbreed [motes mote]
;; Each mote can store the local variables s which is the sensed value of the region,;; D which is the table containing the sensed values and id's of neighbors and wind ;; which is the id of the next mote in the boundary cycle.motes-own [s D wind]
;; System setup and initializationto initialize
make-single-region "medium";; Create the regionif NetworkStructure ="UDG" [create-udg] ;; Create UDG networkif NetworkStructure ="GG" [create-udg create-gg] ;; Create GG networkif NetworkStructure ="RNG" [create-udg create-rng] ;; Create RNG networkask motes [
ifelse [region] ofpatch-here= ["A"]
[set s 1] ;; When region detected, s equals 1
[set s 0] ;; When region not detected, s equals 0set D []
set wind "NULL"
become "INIT";; Set all motes to state INIT
]
while [any? motes with [s =1andcountlink-neighborswith [s =1] <2]] [ ;; Ensuring that motes inside the region are at least 2-connectedask motes with [s =1andcountlink-neighborswith [s =1] <2] [die]
]
end;; Runs the boundary cycle algorithmto go
ask motes [ step ]
mote_labels ;; Changes the labels of the motes based on the MoteLabel dropdown listtickend;;;; Mote protocols;;;; Step through the current stateto step
if state ="INIT" [ step_INIT stop ]
if state ="IDLE" [ step_IDLE stop ]
if state ="BNDY" [ step_BNDY stop ]
end;; All motes broadcast their sensed value and id to their neighbors and transition into;; the IDLE stateto step_INIT
broadcast (list"PING"who s) ;; Broadcast sensed value and identifier
become "IDLE"end;; Motes in the IDLE state store the sensed values and ids of their neighbors and then;; determine if they are boundary motes. If so they set their wind value to the id of;; the next mote in the boundary cycle and transition into the BNDY state.to step_IDLE
if has-message "PING" [ ;; Receiving PING messagelet msg received "PING"let i. item1 msg
let d. item2 msg
set D fput (list i. d.) D ;; Store neighbor identifier and sensed valueiflength D =countlink-neighbors [ ;; Check whether PING received from all neighborslet I [] ;; Creating the I functionforeach D [
let i' item0 ?
let d' item1 ?
set I fput d' I ;; The I function is populated with d values from the D table
]
if s =1andmember?0 I andmember?1 I [ ;; Check for node inside region with neighbor outsidelet tmp.i 0let tmp.d 0foreach D [
let i' item0 ?
let d' item1 ?
if d' =0 [
set tmp.i i'
]
]
while [tmp.d =0] [ ;; Finding the first neighbor that has a sensed value ofset tmp.i cyc tmp.i ;; 1, in an anticlockwise direction from a neighbor withforeach D [ ;; a sensed value of 0let i' item0 ?
let d' item1 ?
if i' = tmp.i [
set tmp.d d'
]
]
]
set wind tmp.i ;; Setting this neighbor as the wind value
become "BNDY"
]
]
stop
]
endto step_BNDY
end;; Changing the labels of the motes based on the MoteLabel dropdown listto mote_labels
ask motes [
setlabel"";; Hide the labelif MoteLabel ="mote id" [setlabelwho] ;; Show mote idif MoteLabel ="wind"and wind !="NULL" [setlabel wind] ;; Show wind valueif MoteLabel ="s" [setlabel s] ;; Show s value
]
end

The NetLogo procedures for this applet can be downloaded directly as: Protocol5.7.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).