Randomized and Efficient Time Synchronization in Dynamic Wireless Sensor Networks: A Gossip-Consensus-Based Approach

This paper proposes novel randomized gossip-consensus-based sync (RGCS) algorithms to realize e ﬃ cient time calibration in dynamic wireless sensor networks (WSNs). First, the unreliable links are described by stochastic connections, re ﬂ ecting the characteristic of changing connectivity gleaned from dynamic WSNs. Secondly, based on the mutual drift estimation, each pair of activated nodes fully adjusts clock rate and o ﬀ set to achieve network-wide time synchronization by drawing upon the gossip consensus approach. The converge-to-max criterion is introduced to achieve a much faster convergence speed. The theoretical results on the probabilistic synchronization performance of the RGCS are presented. Thirdly, a Revised-RGCS is developed to counteract the negative impact of bounded delays, because the uncertain delays are always present in practice and would lead to a large deterioration of algorithm performances. Finally, extensive simulations are performed on the MATLAB and OMNeT++ platform for performance evaluation. Simulation results demonstrate that the proposed algorithms are not only e ﬃ cient for synchronization issues required for dynamic topology changes but also give a better performance in terms of converging speed, collision rate, and the robustness of resisting delay, and outperform other existing protocols.


Introduction
Ad hoc wireless sensor networks (WSNs) without preexisting infrastructures are composed of autonomous sensors [1], and the sensors are a variety of low cost, low power, sensing devices, which work cooperatively through ad hoc wireless communications. In WSNs, many kinds of missions [2,3], such as transmission scheduling, event sequencing, information fusion, and distributed filtering, rely heavily on a consistent notion of time to keep running orderly. For instance, Internet of Things' perception layer provides a ubiquitous access to the network, in which the multiple terminals collaborate closely with each other, and accurate synchronized clocks determine whether a multiterminal cooperation is accomplished or not. Therefore, timing protocols, which should concern with topologies, time delays, low power consumption, and so on, is the premise of dealing with services of ad hoc WSNs.
Two configurations of timing protocols are available: hierarchical and distributed. Cluster-based and tree-based protocols would both fall into the hierarchical configuration, because they perform a special operation; that is, some designated nodes are elected to be the reference (such as cluster head, root, and master). The typical hierarchical timing protocols include the one-way message dissemination schemes [4], two-way message exchange schemes [5], flooding schemes [6], pairwise broadcast synchronization (PBS) [7], and reference broadcast synchronization (RBS) [8]. Based on the message passing and filter methods, most of the works have built an estimation and tracking framework for the time synchronization problem, but these prototypes are not purely decentralized in nature. The hierarchy structure of a network consists in the logical master-slave relationship which is maintained by an actual infrastructure. The timing messages in this structure are delivered from top to bottom, while each node is labeled an equal identity tag in a distributed configuration. In the absence of a preexisting infrastructure, the distributed configuration is obviously more suitable to WSNs.
In dynamic WSNs, it is not possible to deterministically forecast the activating timeslot of sensors due to the uncertainties of nodes, such as uncontrollable mobility, sleep scheduling, heterogeneous nodes with various coverage levels, and so on. Radio signal fading caused by environmental turbulence can also severely corrupt the performance of wireless links. The nodes in the design of the consensus-based timing protocols sequentially update their own clocks whenever they receive a timing message from a geographical neighbor [11]. Because the logical rate represents the slope of the linear logical clock model, each node i is required to build a fixed link with the same neighboring node in order to collect timing messages and estimate the relative drift. In the MTS [12], the authors assume that a larger B is used to keep link i, j constant during a time interval kB, k + 1 B . Although it enables the MTS to behave robustly to work against topology changes, in highly dynamic topology this assumption will be unrealistic. This is because at a timeslot t 1 , node i can exchange timing messages with a neighbor only once to obtain clock reading. At the next timeslot t 2 , the link i, j will lose the connection. More generally, any pair of nodes "gossip" only once in one timeslot. Thus, the randomly changing connectivity between adjacent nodes renders efficient relative drift estimation challenging. This problem will directly affect the implementation of the logical clock rate and offset compensation, and become more paramount as the change of connected relation of WSNs gets faster. On this issue, the existing consensus-based timing protocols can be classified into two categories: (1) deterministic synchronization, which relies on a fixed link, such as [11][12][13][14][15][16][17][18]; and (2) randomized synchronization, such as [19][20][21]. Brown et al. [19] investigated the transient consensus behavior of the random pairwise consensus synchronization (RPCS) algorithm. It is a pity that the reciprocal delay model is supposed to be symmetric. Sun et al. [20] proposed a randomized method to deal with the random access problem. The method proposed therein combines a partial-update rule with a complete-update rule. However, the partialupdate rule is capable of compensating the offset in nondeterministic instants which results in incompletely compensating the clock rate. Bolognani et al. [21] proposed a randomized linear algorithm for the second-order consensus timing protocol. This algorithm is based on the average-value-based criterion, which have a slow speed of convergence.
(2) The speed of convergence may be relatively slow. A major concern is the lower convergence speed which increases the message complexity and consumes the limited power of the sensor nodes. However, many protocols [11,[13][14][15][16][19][20][21] are proposed based on the average-value-based criterion, which need more iterations to achieve acceptable synchronization error.
(3) The delay model is unrealistic. Several protocols suppose the uplink delay and the downlink delay among two nodes are symmetric [13,19] or obey a statistical delay model [12,14], such as normal distribution and Gaussian distribution. Worse still, the uncertainty regarding the delay is associated with the influence of the exterior environment.
(4) The common broadcast period would give rise to the timing message collision as pointed out in publications [11,18,20], but without being handled. The existing consensus-based timing protocols employ a deterministic communication protocol, in which each node is allowed to communicate with its neighboring nodes that are within its range in each deterministic timeslot. Due to the hidden node problem [22], the collisions become too serious to be further ignored since a exposed node receives multiple timing messages from hidden nodes with a common broadcast period during the same timeslot.
The critical fact that the real-world delays would change irregularly, and the more iterations and collisions would waste energy, has a negative effect on synchronization performances. Inspired by the rumor spreading of human groups and the way how epidemics spread, gossip algorithm [23,24] has been widely investigated in the information theory community for information dissemination. In the context of the multiagent networks, randomized gossip algorithm is attractive for solving the distributed and stochastic consensus problems [25][26][27] due to its randomized behavior and asynchronous processing. Faced with the dynamic topology issue, the gossip consensus provides less conservatism and higher efficiency than the existing consensus approach. So they are perceived as uniquely suited for the inherent dynamics of ad hoc WSNs whose topology is randomly connected. The gossip consensus approach contains two dimensions: gossip interaction and gossip update. The gossip interaction mode is particularly well suited for applications into wireless peer-to-peer and ad hoc sensor networks, where a random pair of nodes is active at each 2 Complexity iteration and that it out-syncs itself is a prior fact. In addition, randomized gossiping may allow communication asynchronously at random times to lower the probability of message collisions. The gossip update policy is that each node has to share its output with one of the neighboring nodes. That being said, privacy issues could easily apply to a node which participates in such updating. On the contrary, the existing consensus approach allows a node to share its output with multiple nodes, so privacy issues could discourage some nodes from participating in such updating. Therefore, under a more practical delay model, it is of great interest to study randomized gossip algorithm for achieving the generalized consensus timing protocol that has faster convergence speed and lower collision rate in dynamic WSNs. Motivated by these, this paper presents an innovative randomized and efficient timing protocol for dynamic WSNs, including the mutual drift estimation, clock rate and offset compensation. The key novelty of the contribution lies in a randomized algorithm for the extension of the generalized consensus-based timing protocol which implements probabilistic synchronization using randomized gossip-type interactions and updates. To achieve this goal, for the first time, we design the idea of the randomized activation of the synchronization links based on the preprogrammed Poisson process to activate a pair of nodes, and use the gossipconsensus-based approach with the converge-to-max criterion to fully adjust the clock rate and offset of random pairwise nodes. Moreover, by exploiting a least square-based low-pass filter, a revised version is improved to cope with the bounded delays.
The major contributions of this paper are summarized below: (i) We first ignore the time delays and propose a novel randomized gossip-consensus-based time synchronization (RGCS) protocol by incorporating the idea of randomized gossip algorithm into the consensus-based timing protocol. Compared to traditional mechanisms, the gossip consensus is achievable in a fully decentralized, randomized, and asynchronous fashion, even in highly dynamic WSNs. The converge-to-max criterion is introduced to achieve finite-time convergence, since the gossip consensus is a not fast convergence algorithm. Then, we prove that the expected logical clocks are synchronized with probability one (w.p.1), and provide a lower bound of fast finite-time convergence. In addition, we develop a Multi-RGCS protocol based on the principle of the edge-coloring (EC) technique to save finite-convergence time.
(ii) We consider the case where the delay obeys a realistic bounded model compared to the particular distribution communication delay model, and further propose a Revised-RGCS protocol to work against the uncertain bounded time delays. The filter proposed therein is competent to deal with practical delays which could be a basic constraint in the drift estimation issue over real-world WSNs.
(iii) We conduct performance evaluations of the proposed protocols through extensive simulation experiments using the MATLAB and OMNeT++. Simulation results demonstrate that RGCS fully adjusts logical rate and offset to achieve networkwide synchronization for randomly connected WSNs, and Revised-RGCS gives a better performance in terms of collision rate, converging speed, and the robustness of resisting delays compared to other existing protocols.
The rest of this paper is organized as follows. In Section 2, we review the related literatures and state the novelty with respect to the previous works. Section 3 formulates the time synchronization problem. Section 4 elaborates the proposed RGCS, Multi-RGCS, and Revised-RGCS. The simulation results are given in Section 5. Section 6 concludes the paper.

Related Work
In the absence of preexisting infrastructures, distributed configuration is a promising paradigm for distributed WSNs. Within this context, tremendous research efforts have already been devoted to distributed timing protocols. Based on belief propagation, a fully distributed timing protocol [28] developing from the two-way sender-receiver synchronization scheme was used for the joint estimation of rate and offset. Distributed asynchronous Clock Synchronization (DCS) [29] protocol was proposed for delay-tolerant networks. DCS can achieve global time synchronization among mobile nodes over intermittent connections with long delays, but the rate and offset are adjusted separately. Ahmed et al. [30] considered unreliable links to build an asynchronous framework, but it is the same as an RFA without rate compensation. An On-demand Time Synchronization Protocol (AOTSP) [31] was proposed with the advantages of weak spatial accumulative effect, low communication cost, and high scalability. However, AOTSP suffers from a temporal accumulative effect on account of exchanging timestamps.
In recent years, distributed consensus concept [9,10] has become a hot topic in the distributed time calibration research. Distributed timing protocol based on the idea of the consensus algorithm was originally achieved with the Average TimeSynch (ATS) [11] protocol which fully compensates clock rate and offset. To accelerate convergence speed, the Maximum Time Synchronization (MTS) [12] protocol was developed by which the system trajectories of rate and offset are updated to achieve the maximum-value under a normal distribution delay model, and Saiah et al. [14] proposed the Consensus-based Multi-hop Time Synchronization (CMTS) protocol under the Gaussian delay model. Panigrahi and Khilar [13] proposed a multiobjective evolutionary strategy-based topological optimization for the consensus timing protocol to deal with a trade-off between the minimizing of delays and the selection of sync initiating nodes, but the delays are assumed to be symmetric. The other improved protocols include the Robust-ATS (RoATS) [15] and Least Square estimation-based Time Synchronization (LSTS) [16] aiming at the delays. Recent works contributed 3 Complexity by Tian et al. [17] presented a very generalized model of the Consensus-based Time Synchronization (CBTS) algorithm without topological conditions. However, the RoATS, LSTS, and CBTS designed for distributed WSNs with delays are static scenarios and ignore the changing connectivity of dynamic WSNs. Brown et al. [19] investigated the transient consensus behavior of clock parameters in the Random Pairwise Consensus Synchronization (RPCS). Similar to DCS, RPCS adjusts rate and offset separately. He and Dong et al. investigated consensus timing protocol under message manipulation attacks [32] and sybil attacks [33], respectively. In order to address the topology change issue, the MTS protocol supposes that link i, j should be kept constant within a time width B; however, in a highly dynamic topology, this assumption is unrealistic. Sun et al. proposed the Random Broadcast-based Distributed time Synchronization (RBDS) [20] protocol based on the random access mechanism, which combines the partial-update rule with the complete-update rule. However, the partial-update rule is capable of compensating the offset in a nondeterministic timeslot which results in incompletely adjusting the drift. Based on the gossip consensus, we relax the basic condition of the MTS (that is, compared with the MTS, we do not need link i, j kept constant during a time interval kB, k + 1 B to collect the clock states more than once) and also enable completerate and complete-offset compensation.
There has been a surge of activity in ad hoc WSNs using the idea of gossip protocols. Specific to time synchronization, Marechal et al. [34] proposed a distributed gossip protocol for only adjusting natural clock drifts. Bolognani et al. proposed a Proportional Integral (PI) synchronization controller [35] with gossip communication mode for time synchronization. The PI controller proposed therein takes advantage of the asynchronism of pairwise-exchange communication.
Coupling-based internal Clock Synchronization (CCS) [36] which combines the gossip paradigm with a nature-inspired approach was proposed to cope with disturbance. The logical clock in the CCS is equal to the hardware clock plus an adjustment. This is a special case of our logical clock model which has both multiplicative and additive compensation. Joerg et al. [37] proposed a hybrid protocol for distributed microphones over a wireless network, which integrated the two-way message exchange mechanism with the gossiping technique. The idea of gossiping used therein mainly seeks a virtual master clock. Based on broadcast gossiping, Stankovic et al. [38] proposed two instrumental variabletype distributed recursions for estimating parameters of calibration functions with a general noise assumption. A concern regarding distributed recursion is their excessive use of communication, while the nodes of randomly connected networks can only communicate with its immediate neighbor in an opportunistic manner.
In summary, some of the above algorithms only compensate offset or rate [27,30,34], and other algorithms compensate offset and rate separately [4,19,29,37]. Several algorithms reconstruct clock parameters and perform reverse reconstruction to align absolute time, so they usually introduce more computational complexity [4,30,37]. The distributed nature of the consensus-based timing protocols is superior to other timing protocols, but the message collision rate is relatively high. In particular, node i announces a timing message when the hardware clock τ i or logical clock T i is such that there exists an integer Ψ satisfying τ i t = nΨ or T i t = nΨ + ϕ i , n = 1, 2, 3, … , N. There is a high probability of a timing message collision event in algorithmic mechanisms when the hardware parameters or bias ϕ are converging closely for at least two unidentified and hidden nodes [11,12,18,20,33]. In addition, many algorithms [11, 13-16, 18-21, 34] are still average-value-based algorithms, which have a slow speed of convergence. Worse still, under significant clock drifting, the average information will remove after a few iterations with a slow speed of convergence. Hence, taking the above reasons into consideration, energy-efficient time synchronization for dynamic WSNs may not be achieved by these consensus-based timing protocols. The major advantage of the gossip idea is that the iterative dynamics appear as a randomized and asynchronous evolution, so that it is quite convenient for asynchronous network and topological changes. Nevertheless, the main drawbacks of the aforesaid gossip-based protocols have been analyzed from the compensation quantity, the excessive use of communication, and so on.
So, taking a hybrid approach, we first proposed the RGCS algorithm without considering the delays, which combines the advantage of the randomized gossip algorithm and consensus-based TimeSync. The algorithm fully adjusts rate and offset, and also fits into the dynamic topology of randomly connected WSNs with lower collision. The converge-to-max criterion was introduced to choose the coefficients properly in order to enable fast convergence. A Revised-RGCS algorithm was developed by adopting the least square-based low-pass filter to counteract the impact of bounded delays. Summing up the works for comparison in this section, the features of representative distributed timing protocols are summarized in Table 1. Our time synchronization properties include: (i) Rate and offset synchronization. Each clock rate and offset should be fully adjusted to achieve a common virtual clock.
(ii) Compatible with dynamic topology changes. A time synchronization protocol has to explore the changing connectivity to design compensation rules.
(iii) Energy-efficient. The number of message collisions should be small. Synchronization should be finished within a limited time, since the gossip consensus is a not fast converging algorithm.
(iv) Robustness against bounded time delays. The bounded convergence should be guaranteed even when bounded uncertain delays are present.

Problem Formulation
Suppose N sensor nodes of a WSN indexed by i = 1, 2, … , N.
Owing to the node dormancy or death and random failure of links, a successful contact between a pair of nodes i and j 4 Complexity depends on the probability distribution of the setup of stochastic links. Thus, the topology of dynamic ad hoc WSNs is modeled as a time-varying graph G t = V , ℰ t . V is the set of vertices, and the existence of stochastic links ℰ t = e ij t | i, j ∈ V is determined independently. The set of node i's neighbors is denoted by N i = j ∈ V , e ij ∈ ℰ t . We use a notation ij to indicate e ij which means node i and j happen to link together, and the undirected random graph is bidirectional. Definition 1. A synchronization link ij or e ij means that an arbitrary random node i is coupled with its geographical neighbor j ∈ N i once to perform a synchronous operation. Specifically, triggering node i sends a beacon to choose the triggered neighbor j and confirm the ID of the synchronization link e ij ; then, they swap timing messages with each other. Due to the randomized activation of nodes, we need a neighbor discovery protocol for nodes to discover each other when they are neighbors.
Fortunately, a simple and useful neighbor discovery protocol can be used as in [39].
The oscillator generates the standard unit of frequency Ω. The clock provides its reading τ t of the elapsed absolute time t by accumulating the number of impulsive where κ is an oscillator frequency correction. The oscillation frequency is nearly invariable in a short time horizon, so the clock reading of the ith node possesses a linear dynamic behavior such as where a i and b i are the hardware clock rate and offset, respectively. a i determines the timing rate of the clock and b i represents the difference of the nodes' clock reading. The logical clock is a linear affine function of τ i t . α i t is a multiplicative compensation and β i t is an additive compensation, as follows: where α i t = a i α i t and β i t = α i t b i + β i t are called the logical rate and offset, respectively. So, we have available quantity τ i t , and two variables α i t , β i t to be designed. The objective is to design a randomized communication protocol and a gossip-consensus-based approach for coupled nodes i, j ∈ V announcing its timing messages and adjusting the logical rate and offset, such that the logical clocks T i i ∈ V is synchronized in the probability sense, as follows: Finally, notation Pr, o, O denote probability, infinitesimal of higher order, and infinitesimal of the same order, respectively.

RGCS, Multi-RGCS, and
Revised-RGCS Algorithms A randomly connected ad hoc WSN is specifically characterized in that the nodes are randomly activating and sleeping, and the RGCS algorithm is supposed to run independently in each individual node. Firstly, the Poisson process is configured to each node in order to generate the synchronization link (Sync-L) beacon which is sent to a node of its neighborhood by exploiting the broadcast nature of wireless communications. Thus, the randomized activation of e ij i, j ∈ V satisfies the Poisson process with the constant intensity λ ij such that Pr t ij l + σ − t ij σ = n = λ ij l n /n e λ ij l , n = 0, 1 … , for ∀l, σ ≥ 0. Some special circumstances are as follows: if λ ij = 0, it means link e ij is not activated forever, and if λ ij = ∞, it means link e ij is activated infinitely in a given time interval.
The Sync-L beacon between node i and j is confirmed, which is referred to the stochastic link activation event. Once the to node j. After that, the triggered node j pulls a multivariable message The overall procedure is illustrated in Figure 1.
Thus, accordingly, the set of activated synchronization links ∪ N i=1,j=1 e ij t are an identically and independently distributed (i.i.d.) Poisson distribution. Suppose that function ℱ N represents the amount of synchronization links of an underlying graph. When it is a complete graph, we can max- Each global gossip instantly corresponds to an updating event. We denote Δ l, ij as the intertime between consecutive gossip instants for the global Poisson process, and Δ l, ij l∈N, ij ∈E t is an i.i.d. process with moments The intensity λ increased, whereas Δ l, ij continuously decreased. The physical significance of λ ij represents the intermittent of activation events of link e ij , and the mathematical meaning of λ ij represents the mean value of the occurrence of the activation events per unit time. In many scenarios, environmental-temperature variations will be slow to change around nodes. Hence, we can do that by increasing intensity λ ij to enlarge the frequency of a link activation event in order to work against slowly changing drifts.
As shown in Figure 2, we illustrate how the proposed mechanism works under the hidden node problem. Node A is visible from node B, and node C is visible from node B too. However, node A and node B cannot sense with each other, because they are out of the communication zone of each other. In the deterministic communication protocol (such as ATS, MTS, RoATS, etc.), each node transmits its timing messages periodically with a common period based on its own clock on chip. If nodes A and B have a small difference in terms of the hardware rate and offset, they will announce timing messages to node C simultaneously. Thus, the collisions will occur endlessly. In our proposed mechanism, each node announces a timing message asynchronously based on its preprogrammed Poisson process, and random pairwise node delivery timing messages in the uplink and downlink successively. So node A randomly gossips, then a sync timeslot is established between nodes A and C with probability Pr t AC l . The sync timeslot between nodes B and C is established with probability Pr t BC l . The Poisson intervals δ AC and δ BC are independent of each other. If the transmission delay is negligible, the width of the sync timeslot can be narrow such that the probability of collisions will further down. Hence, with an appropriate λ, the probability of collisions is lower than that in the deterministic communication.
To defend against message manipulation attacks, secure consensus timing protocols should contain a detecting and excluding outlier mechanism for the logical clock checking and hardware clock checking. From the analysis of logical clock checking mechanism in the literature [32], we know that the bounded communication cycle which was determined by Ψ | τ i t = NΨ, N = 1, 2, … , Ψ > 0 is a pivotal parameter of the secure protocols. However, the authors suppose Ψ is invariable under malicious modification with the purpose of preventing the attack nodes using outdated receiving information to cheat, that is, it makes nodes to collect messages from neighboring nodes within a constant duration. The proposed gossip interaction mode which has less conservatism to topology changes can remove this Arbitrary i (triggering node) t Figure 1: The Sync-L beacon and timing message exchanges in a dynamic wireless sensor network.   . Each node consists of estimating the logical rate with respect to the virtual consensus rate, and local node j stores a new compensation α j . Then, by dividing α j at both sides of above equation, we have where ρ 1 ∈ 0, 1 The constant ρ 1 defines the degree of change of compensation α in gossip instant t ij l+1 . If ρ 1 is set to a small value, the average information will be removed in a few updates. Additionally, due to the discrete observations of the relative drift, we can increase ρ 1 to guarantee the stationarity of the estimated α. Based on the above analysis, the converge-to-max criterion is applied to t j k . The time, t j k , indicates the previous gossip instant of arbitrary edges which contain node j just before activated edge e ij 's lth gossip instant. Equation (5) counts the absolute time on two scales, that is, updating the usage round and communication round, to avoid confusion between the updating iteration and the gossiping communication. Scrupulously, t j k is given as follows: During all iterations, each node i's storage is O N i for all possible synchronization links. It implies that, even though the size of the network node increases, the storage complexities of the RGCS per node per iteration will not grow. This property ensures the scalability of the algorithm. Substituting (7) into (5) yields the update equation of compensating α j . Again, based on the converge-to-max criterion, we design the rate compensation iteration rule of random pairwise nodes. In this rule, the rate compensations of triggering node i, triggered node j, and silent nodes evolve as follows and try to adjust its offset β in order to reduce the difference. Once again, the gossip consensus approach and the converge-to-max criterion are applied to local node i, j, and silent nodes for attaining offset compensations, as follows . The flowchart of the RGCS algorithm is shown in Figure 3(a), and the basic procedures are described as follows: Step 1. Randomly initialize each local clock τ i .
Step 2. Judge whether arbitrary node i activates its neighbor or not, or whether it is activated by its neighbor or not.
Step 4. Judge whether to meet the sync accuracy or not. Otherwise, return to Step 2.

Convergence of RGCS. Substituting (2) into (3) yields an intuitive translation of the time synchronization issue:
Pr lim t→∞ a t = a v = 1, where a v and b v are the parameters of a consistent virtual clock. Equation (10) shows that whether the clocks achieve synchronization or not depends not only on the convergence of the logical rate and offset, but also on the convergence speed of the logical rate errors Pr α i t − α j t , because errors will tend to diverge if the convergence speed to zero of Pr α i t − α j t is slower than 1/t. Theorem 1. Consider the rate and offset update equations given by (6), (7), (8), and (9), and there exist two variables Δ > 0 and l > 0 such that the union graph G t ij l , Δ l, ij = ∪ ij ∪ l G t ij l for ∀e ij ∈ ℰ t is connected with probability one. Then, (10) holds true. Proof 1. Firstly, two functions V v t and V v t are introduced, where V v t is the set of nodes whose logical rate and offset are equal to a v and b v in instant t, and V v t is the cardinality of set V v t . Define a max = max a i , ∀i ∈ V , let node v be the node whose clock rate is equal to a max . According to the initial sets, there is at least one node in the network whose logic clock rate and offset are equal to a v and b v in the initial instant; that is, V v t ≠ ⊘, V v t ≥ 1. With the loss of generality, assume node j has a larger logical rate. If the link e ij is activated at gossip time t ij l , node i will update its logical clock such that a i α i = a j α j and α i b i + β i = α j b j + β j . Thus, the logical rate of each node is less than or equal to a max during the iteration of RGCS. For a pair of nodes i and j, i, j ∈ V v , there is a i α i = a max , α i b i + β i = β v , and a j α j = a max , α j b j + β i = β v . Thus, we can infer that a i α i or a j α j ≥ a k α k holds for ∀k ∈ V . Therefore, a pair of nodes i and j in V v will no longer update its logical clock and maintain its logical rate and offset during the latter iterations, which means that V v t is nondecreasing.
The complement of a set V v is defined as V − V v , which means that the set of nodes are not in V v . If node k is not in the set V v , then node k is in V − V v . Since all nodes' logical rate is less than or equal to a max during the iteration of RGCS, so we have a k α k < a v for ∀k ∈ V − V v . Thus, if node i ∈ V v is coupled with node k by Sync-L, then it follows from (8) and (9) that node k will update its logical clock such that  8 Complexity is jointly connected with probability one, there is at least one link e ik for i ∈ V v and k ∈ V − V v , which means that there has λ ik > 0. The probability of the event that link e ik is activated satisfies 1 − e −λ ik t′−t . Therefore, we have the probability of Thus, V v t will strictly increase with probability one when t → ∞. Hence, we have Pr lim t−∞ V v t = n = 1, which yields Pr lim t→∞ a i t = a c = 1, Pr lim t→∞ β i t = b c = 1, for ∀i ∈ V . Then, Pr a i α i t − a j α j t can approximate to zero when t → ∞. Clearly, The Theorem 1 is thus proved. In practice, considering the thrift energy to a bigger extent, the finite-time convergence of algorithms is very important in WSNs. Next, we will give the lower bound of the probability for the finite-time convergence of RGCS. For node i, j, let us assume W ij represents the time cost for a link activation event.
Then, u ij , U ij t 0 u ij s ds is the probability density function and probability distribution function of W ij , respectively.

Theorem 2. Suppose the union graph
for ∀e ij ∈ ℰ t is connected with probability one. Then, we have Pr Proof 2. From the proof of Theorem 1, we can conclude that node i in V − V v will become a node in V v after the link e vi is activated. When Theorem 2 is thus proved.

Multi-RGCS Algorithm.
Obviously, RGCS is obtained by the single-gossiping rule. Under this scenario, other silent nodes are situated in the wait state, while only one synchronization link is activated in a timeslot. We expect that more coupling nodes are able to exchange and update states in a timeslot, or more than a neighboring node can overhear a triggering node's messages (i.e., broadcast gossip manner).
Based on their positive effect on the performance of the convergence rate, the multigossiping version of RGCS (Multi-RGCS) is a topic which is worth exploring. In fact, we can assume that more than two nodes i, j, … wake up in t l simultaneously with probability P t l > 0. So the single-gossiping version corresponds to specific implementation of the above assumption in which if and only if two nodes i and j wake up. Different from the foregoing single-gossiping, Multi-RGCS requires an additional precondition that the synchronization links cannot have a public vertex in the same slot. In other words, we need to seek a multigossip sequence M n, t c = m t c n , where n is the color number, t c is the switching time. So, the synchronization links are dyed different colors, and those links that have the same color are categorized as the group m t c n . This problem could be investigated by the idea of the edge-coloring (EC) [40]. The EC aims at an assignment of one color to each synchronization link such that no two synchronization links on the same node are assigned the same color. Here, we give a straightforward EC algorithm to realize Multi-RGCS as in Figure 3(b). Thereunto, the key procedures of obtaining the multigossip sequence are summarized as follows. For t c , do the following: Step 1. Generate a spanning tree ℋ of graph G t c ; Step 2. Randomly pick a single edge in ℋ, find a nonadjacent edge to the former, and then find a nonstaining edge for coloring the third color until it cannot find any nonstaining edge. Step 3. The edges of different colors constitute the multigossip sequence M n, t c = m t c 1 , m t c 2 , … , m t c n . The probability characteristics of the set t l , l = 1, 2, … is similar to the set , and the physical meaning of t − i refers to the previous gossip instant of any synchronization link involving node i. In Multi-RGCS, several nodes are involved in multisynchronization links m t c n to increase the synchronization traffic and enhance the convergence speed.

Revised-RGCS Algorithm.
In RGCS, we suppose that the delays are negligible. However, by considering various disturbances, which act as an additive noise model (such as the delay), the actual timestamp is truly noisy, and the delay distribution is unknown. To deal with this issue, we proposed a least square estimation-based low-pass filter against bounded delays (Assumption 2). As shown in Figure 4, the time delay of the lth communication between node i and j is denoted by Due to the symmetry, the following process takes the case of d ij . Based on the definition of the relative drift and d ij , we have a longspan estimator α ij l for α ij l as followŝ where ξ l = d ij l − d ij 0 /∑ l δ ij and δ ij is the intertime between consecutive gossip instants for link e ij . Since d ij is bounded by D, we have ξˆl ≤ D/Σ l δ ij . Hence, we know that ξ l decays in a rate of O 1/δ . Let α * ij l be the optimal estimator for α ij l , and denote e l =â ij l τ i t ij l −â * ij l τ i t ij l . A least square principle as J = ∑ l l=1 e 2 l is employed. For calculating the recursion of α * ij l , we apply a partial derivative for α * ij l , namely which yields an optimal estimator as follows: where the weighting parameter γ * l = δ 2 1 + δ 2 2 + ⋯ + δ 2 l δ 2 1 + δ 2 1 + δ 2 2 + ⋯ + δ 2 1 + δ 2 2 + ⋯ + δ 2 l , 14 and α * ij 0 = 1. Substituting (11) into (13) yieldŝ where ξ * l = δ 1 + δ 1 + δ 2 + ⋯ + δ 1 + δ 2 + ⋯ + δ 1 d ij l − d ij 0 Then, bounded by d ij , we notice that the denominator of ξ * l is δ's quadratic term after accumulating, and the numerator of ξ * l is δ's first degree term. It implies that the decay rate of ξ * l is also O 1/δ . This decay rate ensures that the proposed least square estimation-based low-pass filter avoids the divergence condition of Pr α i t − α j t . Hence, we can utilize α * ij l / δ 1 + δ 1 + δ 2 + ⋯ + δ l 1/2 to replace α ij t l and modify the rate-updating rule of the triggering node i of (6); thus, there is The criterion for selecting the appropriate weighting parameter δ 1 + δ 1 + δ 2 + ⋯ + δ l − 1/2 is based on a piece-wise constant function, and it is chosen to be a decreasing factor, which contributes to restraining the negative effect of additive noise in stochastic approximation. Actually, the weighting parameter in this paper is a special case of the standard conditions in stochastic approximation methods: is an estimation of inverse relative drift a ij t ij l , the rate updating rule of triggered node j is Then, the clock offset compensations of local node i, j is updated as follows: The delays also have an impact on t i k . The issue is caused by the fact that node j would not instantly receive its gossiping neighbor's states due to uncertain delay, and if delay d ij satisfies the following two conditions: (i) delay d ij greater than intertime Δ; (ii) node j joins next gossip averaging; then t ik will change and needs to be modified. When d ij ≠ d ji , we call this asymmetric gossip, and this is a common case. 10 Complexity To clearly explain how delay influences the local updating equations, we might as well suppose link e ij is activating. After Δ, there are three possibilities of adjacent Sync-L: e ik , e jh , and e kh , ∀k, h ∈ V , if: Case 1. d ij ≥ Δ l, ik + nΔ l, kh , n = 0, 1, … , then (18) and (20)  Case 2. d ji ≥ Δ l, jh + nΔ l, kh , n = 0, 1, … , then (17) and (19) utilizeâ * jh l and t hj = max t jh s , t hj r | sr = 12 … The discriminant of Case 1 and Case 2 is easy to implement, because the comparison between the length of delay and the interval time of node activation depends on the local nodes themselves. The delays make Revised-RGCS slightly complex, but it will not damage the convergence. However, we should point out that the update of the logical rate is based on the long-span neighboring states τ j t ij l − τ j t ij 0 , so the nodes should set up a cached memory for forming a buffer queue of the timing messages. To summarize the above process, a flow diagram of the Revised-RGCS algorithm is described in Figure 5.

Simulation Studies
To verify the superiority of novel proposed algorithms, we carried out comparative simulations for RGCS and Multi-RGCS with a delay-free case in the Matlab R2010b. Then, using the OMNeT++ 5.1471 simulator, a more realistic simulator for WSNs, we verified the Revised-RGCS algorithm with delays. Table 1, DCS and RPCS are two appropriate reference algorithms, so we compared the performances of RGCS with them. All of them have been investigated numerically for emulating a randomly connected ad hoc WSN. The important parameter setting is described as follows. The local hardware rate is chosen from 0 999, 1 0001 , and the local offset is chosen from 0, 0 002 . α i 0 = 1 and β i 0 = 0. The number of nodes is 9, and the number of local nodes that can be accessed by the other nodes is 3. The initial synchronization period is 10 s. The threshold of successful Sync-L is characterized by a Poisson process with intensity λ, and the intensity reflects the connection strength between individual nodes. The average number of Sync-L per time interval is 10. It is feasible that the joint topologies of the simulation model of dynamic WSN are connected with probability one. The time unit is one second. The required accuracy is ±1 millisecond. Because  11 Complexity there are no reference nodes and random initial parameters, we employed a metric to evaluate the synchronization error of the algorithms: the maximum difference of the parameters between any two nodes in overall WSN [18][19][20], that is, Figure 6 shows the maximum error of logical rate α i t and offset β i t under RGCS and DCS. In our algorithm, the logical rate and offset synchronization can be achieved simultaneously. So, RGCS designed for randomly connected WSNs is an asynchronous and distributed configuration, and can make a complete compensation for the rate and offset. Due to the dense node density, DCS cannot achieve rate compensation and offset compensation simultaneously. Because DCS was devised for sparse node density to tolerate long delays, this leads to the synchronous mode for the update of the rate and offset. At the beginning of the compensation in RPCS, the rate of compensation is faster than that in RGCS, because RPCS employs a standard frequency estimation technique to obtain an estimate of the pairwise drift. However, the descending rate of the offset compensation is relative slow, and the logical clock T i t could not be synchronized without the backward jumps phenomenon. Figure 7 shows the maximum error of T i t of RGCS under λ = 1, 5, and 10, from which it can be observed that it takes less time with λ = 10 to reach synchronization. This is because a larger intensity of the Poisson process can decrease intertime Δ l, ij between consecutive gossip instants for any links. The results in Figure 6 validate the theoretical features of (3). So the descent velocity of the maximum error of logical clocks with λ = 10 becomes more remarkable. Figure 8 shows the comparative simulation results with regard to single RGCS and Multi-RGCS. The green line represents the convergence of logical clocks in Multi-RGCS. The falling speed of the green line is faster than that of the blue line (single RGCS), because more clocks exchange their states and come close to the maximum-value at each gossip instant. Then, Figure 9 shows the relationship between different coloring edge's numbers ranging from n = 5 to n = 12 and 95th percentile of synchronization errors. The performance degrades as more coloring numbers increase; however, it exhibits an approximate linear dependence; thus, it refers   12 Complexity to the amount of gossip as a function of the coloring number n. We can involve this feature to suppress drift for different synchronization accuracies. Based on the above simulation results and discussions, it can be seen that the paper has proposed an RGCS algorithm with superior performances compared to existing methods in terms of dynamic adaptability and faster convergence speed. A edge-coloring algorithm can be applied to constitute a spanning tree so that Multi-RGCS has a faster convergence speed than that in RGCS.

Bounded Delay
Case. OMNeT++ is an extensible, modular, component-based C++ simulation library and framework, primarily for building network simulators. Based on the MiXiM framework and Network Description (NED) files, we implement an ad hoc WSN on the OMNeT++ 5.1.1, and then run the Revised-RGCS algorithm on it. It has been simulated for WSNs of N = 9 clocks placed on a field with a size of 100 m × 100 m. Moving sensors are indexed by bidimensional coordinates X and Y, namely, node 11, node 12, node 13, node 21, node 22, node 23, node 31, node 32, and node 33. For those mobile nodes, we used the Random Walk module to locate the coordinate position of the node. In this module, each node was made to move to the next coordinate position at random. Note that the radios in a node could collect incident message sets with higher layer module operation decoupled by buffers, so a deferred message will be valid. Table 2 summarizes the key parameters.
The probability density distributions of time delays d ij and d ji are shown in Figure 10. We carried on the statistics from 10 times simulations and obtained their distribution. It can be seen that the maximum delay is bounded which confirms the realistic bounded model. In reality, d ij is often different from d ji because the uplink and downlink between the head and tail are independent from one another. Obviously, the Revised-RGCS is an asymmetric gossip. In RPCS, the authors assume reciprocal propagation delays d ij = d ji in each synchronization round. The delay assumption in this paper is more practical than that in the RPCS.
With the bounded delays, we compared the relative drift estimation method, which is based on a low-pass filter, used in the Revised-RGCS and that in RGCS. Figure 11 shows the results of the relative drift estimation error ξ * l of random pairwise nodes. It is observed that using (15), the relative drift α ij can be estimated accurately as α * ij l (the blue line) will converge to the ideal value. Oppositely, the average estimate error is diverging in RGCS (the green line) without the low-pass filter. We see that the relative rate estimation under the bound delay can be obtained with the Revised-RGCS, on which an effective timing protocol depends.

Complexity
The simulation results of the Revised-RGCS, DCS, and RPCS implementations are presented in Figure 12. It is observed from Figure 12 that the Revised-RGCS takes about 20 synchronization rounds to reach within 10 ticks while RPCS does not achieve the expected error before 20 rounds. It is clear that the Revised-RGCS can ensure that the sync error is bounded. In contrast, due to symmetric delay, the maximum synchronization error of the RPCS is ceaselessly growing. The results demonstrate that the Revised-RGCS converges asymptotically while RPCS is diverging. Although the DCS algorithm can reach time synchronization, its convergence rate is relatively slow under the randomly connected scene. This is because in DCS, the offset and rate compensation are initiated by the updated table information which is a weighted average of the neighborhoods. Most of the existing timing protocols employ a deterministic periodic synchronization scheme which results in message collisions, and they concentrate on those which merely exploit a packet in a collision timeslot or directly discard redundant packets. These techniques are passive to a certain extent. The reason for this is that WSNs require a nontrivial collision detection scheme and invalid packets waste energy. In RGCS, we assume that every gossiping of a pair of nodes costs the same amount of energy E eg and let E g be the total energy cost for gossiping to the expected accuracy, then, E s = E g = ∑ N l=1;e ij δ l, ij × E eg for ∀e ij ∈ E t . As discussed in Section 2, we know that in most of the distributed configuration protocols, similar hardware clock states are the main reason behind the message collisions of hidden nodes. Hence, the number of clocks is considered to be an evaluation indicator. Figure 13 shows the timing message collision rate versus the number of clocks. The timing collision rate of RPCS and DCS protocols achieve 23.4% and 19.2% when the network scale is 100. In simulations, due to an asynchronous pairwise policy and an appropriate λ, the collision rate of RGCS is null. In the Revised-RGCS, the collision rate is 2.1%, because the timing messages are delivered to the MAC layer of the nodes with long delays which collides with the Sync-L event at few instants.
Based on the above simulation results and discussions, the Revised-RGCS can guarantee time synchronization under the realistic bounded delay model with a low collision rate compared to the current algorithms in practice.

Conclusions
This paper presents a new randomized and energy-efficient time synchronization protocol called RGCS for dynamic WSNs with randomly changing connectivity. The protocol is based on distributed consensus TimeSync but incorporating the gossip algorithm. Therefore, it is superior to existing   14 Complexity protocols in a generalized randomization framework, and can be well adapted to the link variation of ad hoc WSNs dynamically. The new idea of randomized scheduling of the synchronization links is to lower the rate of collision, so the RGCS dramatically relieves the collision phenomenon. Based on the converge-to-max criterion, the method has been deduced to accelerate the convergence speed. By combining the idea of the EC, the Multi-RGCS has been proposed. Moreover, the Revised-RGCS has been developed to specially restrain the impact of uncertain bounded delays. Extensive simulations have demonstrated the better performances of the proposed protocols. The proposed EC method is rough, since the dynamic ad hoc WSNs need a global coordinator in order to produce a spanning tree at each changing moment of topology. It is worth investigating how to design a pure distributed EC algorithm for Multi-RGCS. This will enhance the adaptability for fast changing networks. However, pure distributed edge-coloring is to be NP-Complete. In future work, we will focus on developing a solution to find the maximum clique of the sync edges.

Data Availability
In this paper, the simulation on Matlab can be done by simply using the proposed algorithms given in Section 4 as well as the initial configuration given in Section 5, without any other data. The relevant data of the OMNeT++ simulation framework can be obtained by e-mail to the author.