• Protocol 5.9: Electing a leader for the boundary cycle

    PROTOCOL

    Electing a leader for the boundary cycle (see Protocol 5.8 and Protocol 4.12)

    SUMMARY

    This algorithm is an extension of Protocol 5.8 which uses the routing of a message around the boundary to elect a leader, similar to Protocol 4.12. To do this, boundary motes receiving a message determine if the id of the message originator is lower than their m value which is initially set to their own id. If it is lower, the message is passed on and the m value is set to the id of the message originator.
    This means that any boundary mote receiving a message originating from themselves will have the lowest id and therefore be elected as the leader.

    OPERATION

    • Click the Setup button to generate a network based on communication distance and network size.
    • Click the Go! button to run the algorithm.
    • Toggle the “check2conn” switch to additionally check if subgraph formed by the region is 2-connected (two paths between any pair of nodes). Note: this check may slow the simulation down considerably for larger network sizes.

    NOTICE

    • The region is green in color, once the algorithm runs, BNDY motes should appear in mid-blue around the edges.
    • The leading mote should be the purple in color.
    • Use the MoteLabel list to change the labels to the mote id, sensed value, wind value or m value. Only motes in the boundary cycle will show their m 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.9

    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.

    Protocol 5.9

    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 motes
    breed [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, wind which
    ;; is the id of the next mote in the boundary cycle, m which is the smallest
    ;; identifier and Def which is the defer value.
    motes-own [s D wind m Def]
    
    ;; System setup and initialization
    to initialize
      make-single-region "medium" ;; 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 [
        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
        set D []
        set wind "NULL"
        set m who
        become "INIT" ;; Set all motes to state INIT
      ]
      while [any? motes with [s = 1 and count link-neighbors with [s = 1] < 2]] [ ;; Ensuring that motes inside the region are at least 2-connected
        ask motes with [s = 1 and count link-neighbors with [s = 1] < 2] [die]
      ]
    end
    
    ;; Runs the leader election for a boundary cycle algorithm
    to go
      ask motes [ step ]
      mote_labels ;; Changes the labels of the motes based on the MoteLabel dropdown list
      tick
    end
    
    ;;
    ;; Mote protocols
    ;;
    
    ;; Step through the current state
    to step
      if state = "INIT" [ step_INIT stop ]
      if state = "IDLE" [ step_IDLE stop ]
      if state = "BNDY" [ step_BNDY stop ]
      if state = "LEAD" [ step_LEAD stop ]
    
    end
    
    ;; All motes broadcast their sensed value and id to their neighbors and transition into
    ;; the IDLE state
    to 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, send off a MSGE and transition into the BNDY
    ;; state.
    ;; Any motes in the IDLE state receiving the MSGE will forward it to the next neighbor
    ;; in the boundary cycle using the cyc function and the id of the previous mote.
    to step_IDLE
      if has-message "PING" [ ;; Receiving PING message
        let msg received "PING"
        let i. item 1 msg
        let d. item 2 msg
        set D fput (list i. d.) D ;; Store neighbor identifier and sensed value
    
        if length D = count link-neighbors [ ;; Check whether PING received from all neighbors
          let I [] ;; Creating the I function
          foreach D [
            let i' item 0 ?
            let d' item 1 ?
            set I fput d' I ;; The I function is populated with d values from the D table
          ]
    
          ifelse s = 1 and member? 0 I [ ;; Check for node inside region with neighbor outside
            let tmp.i 0
            let tmp.d 0
            foreach D [
              let i' item 0 ?
              let d' item 1 ?
              if d' = 0 [
                set tmp.i i'
              ]
            ]
    
            while [tmp.d = 0] [   ;; Finding the first neighbor that has a sensed value of
              set tmp.i cyc tmp.i ;; 1, in an anticlockwise direction from a neighbor with
              foreach D [         ;; a sensed value of 0
                let i' item 0 ?
                let d' item 1 ?
                if i' = tmp.i [
                  set tmp.d d'
                ]
              ]
            ]
            set wind tmp.i ;; Setting this neighbor as the wind value
            send (list "MSGE" who who) (mote wind) ;; Initiate message to first boundary neighbor
            become "BNDY"
          ]
          [
            set Def 1
          ]
        ]
        stop
      ]
    
      if has-message "MSGE" and Def = 1 [ ;; Receiving MSGE message
        let msg received "MSGE"
        let i item 1 msg
        let i' item 2 msg
        send (list "MSGE" i who) (mote cyc i') ;; Forward message to next boundary cycle neighbor
        stop
      ]
    end
    
    ;; Motes in the BNDY state will either forward messages to the next boundary neighbor
    ;; if the i value is lower than the m value, not forward the message if it is higher or
    ;; transition into the LEAD state if the i value is the same as their id.
    to step_BNDY
      if has-message "MSGE" [ ;; Receiving MSGE message
        let msg received "MSGE"
        let i item 1 msg
        let i' item 2 msg
    
        ifelse i = who [ ;; Check whether message returned to sender
          become "LEAD"
        ]
        [
          if i < m [
            set m i
            send (list "MSGE" i who) (mote wind) ;; Forward message to next boundary neighbor
          ]
        ]
        stop
      ]
    end
    
    to step_LEAD
    end
    
    ;; Changing the labels of the motes based on the MoteLabel dropdown list
    to mote_labels
      ask motes [
        set label "" ;; Hide the label
        if MoteLabel = "mote id" [set label who] ;; Show mote id
        if MoteLabel = "wind" and wind != "NULL" [set label wind] ;; Show wind value
        if MoteLabel = "s" [set label s] ;; Show s value
        if MoteLabel = "m" and (state = "BNDY" or state = "LEAD") [set label m] ;; Show m value for motes within the boundary cycle
      ]
    end
    

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

Leave a Reply

Your email address will not be published. Required fields are marked *

*

* Copy this password:

* Type or paste password here:

8,290 Spam Comments Blocked so far by Spam Free Wordpress

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>