# Improving Route Selections in ZigBee Wireless Sensor Networks
## 6 Proposed Link Cost Estimation and Modified Route Selection Procedure
### Link Cost Estimation Procedure  
We propose that the cost of a link still be computed as in the ZigBee specification; i.e., the cost \(c_{z_{1},z_{2}}\) between nodes \(z_{1}\) and \(z_{2}\) is still computed using the probability of successful packet transmission \(p_{z_{1},z_{2}}\) in (2); however, we propose that \(p_{z_{1},z_{2}}\) be estimated not only from LS packets, but also from any unicast packet transmissions from \(z_{1}\) to \(z_{2}\). The rationale is to increase the number of measurements and reduce the estimator variance. To define the estimator that we propose, we first describe the ideal estimator. At each time \(t\), let \(N_{z_{1},z_{2}}^{(u),tx}(t)\) be the number of unicast packets sent by node \(z_{1}\) to node \(z_{2}\) in the last \(T_{avg}\) seconds; let \(N_{z_{1},z_{2}}^{(u),rx}(t)\) be the number of these packets that were received by \(z_{2}\); define  
\[\hat{p}_{z_{1},z_{2}}^{(u)}(t):=\frac{N_{z_{1},z_{2}}^{(u),rx}(t)}{N_{z_{1},z_ {2}}^{(u),tx}(t)}; \tag{8}\]recall from (3) that \(\hat{p}_{z_{1},z_{2}}^{(LS)}(t)\) represents the ratio of LS packets transmitted by \(z_{1}\); and use these definitions to obtain the minimum variance unbiased linear estimator [53]:  
\[\hat{p}_{z_{1},z_{2}}^{(ideal)}(t)=\frac{\sigma_{u}^{2}(t)}{\sigma_{u}^{2}(t)+ \sigma_{LS}^{2}(t)}\hat{p}_{z_{1},z_{2}}^{(LS)}(t)+\frac{\sigma_{LS}^{2}(t)}{ \sigma_{u}^{2}(t)+\sigma_{LS}^{2}(t)}\hat{p}_{z_{1},z_{2}}^{(u)}(t), \tag{9}\]  
where \(\sigma_{LS}^{2}(t)\) and \(\sigma_{u}^{2}(t)\) are respectively, the variance of the estimators \(\hat{p}_{z_{1},z_{2}}^{(LS)}(t)\) and \(\hat{p}_{z_{1},z_{2}}^{(u)}(t)\) at time \(t\). Considering that the unicast and LS packets have the same size, which is a reasonable approximation when sensors operate in the same manner and the size of data packets is small, the probability of successful transmission of a unicast packet (\(p_{z_{1},z_{2}}\)) is the same as the probability of successful transmission of a LS packet; and since both \(N_{z_{1},z_{2}}^{(u),rx}(t)\) and \(N_{z_{1},z_{2}}^{(LS),rx}(t)\) are binomial random variables, \(\sigma_{u}^{2}(t)=p_{z_{1},z_{2}}[1-p_{z_{1},z_{2}}]/N_{z_{1},z_{2}}^{(u),tx}(t)\) and \(\sigma_{LS}^{2}(t)=p_{z_{1},z_{2}}[1-p_{z_{1},z_{2}}]/N_{z_{1}}^{(LS),tx}(t)\). Using these expressions in (9) and simplifying, we obtain  
\[\hat{p}_{z_{1},z_{2}}^{(ideal)}(t)=\frac{N_{z_{1},z_{2}}^{(u),rx}(t)+N_{z_{1}, z_{2}}^{(LS),rx}(t)}{N_{z_{1},z_{2}}^{(u),tx}(t)+N_{z_{1}}^{(LS),tx}(t)}. \tag{10}\]  
We call the estimator of (10) ideal because the information needed to compute \(\hat{p}_{ideal}(z_{1},z_{2})\) is spread between \(z_{1}\) and \(z_{2}\): \(N_{z_{1},z_{2}}^{(u),rx}(t)\) is known by \(z_{1}\) but not \(z_{2}\); and \(N_{z_{1},z_{2}}^{(u),rx}(t)\) and \(N_{z_{1},z_{2}}^{(LS),rx}(t)\) are known by \(z_{2}\) but not \(z_{1}\). Node \(z_{2}\) provides feedback to \(z_{1}\): it sends a MAC ACK to every unicast packet sent by node \(z_{1}\); and \(z_{2}\) broadcasts \(\hat{c}_{z_{1},z_{2}}^{(LS)}(t)\) whenever it sends its LS packet. This feedback is, however, imperfect. Regarding MAC ACK packets sent by \(z_{2}\), \(z_{1}\) could consider \(N_{z_{1},z_{2}}^{(u),rx}(t)\) as the number of MAC ACK packets received; however, the unicast transmission may have been received by \(z_{2}\) with the MAC ACK being lost at \(z_{1}\); and \(z_{1}\) would consider that the unicast transmission was lost, underestimating \(N_{z_{1},z_{2}}^{(u),rx}(t)\). Regarding \(z_{2}\)'s LS packet, it may also be lost at \(z_{1}\); however, more importantly, \(z_{2}\)'s LS packet only provides indirect and incomplete information about \(N_{z_{1},z_{2}}^{(LS),rx}(t)\). As explained in Section 3.2, \(z_{2}\) computes \(\hat{p}_{z_{1},z_{2}}^{(LS)}(t)\) and uses Equation (2) to compute the 3-bit cost estimate \(\hat{c}_{z_{1},z_{2}}^{(LS)}(t)\). From the quantized \(\hat{c}_{z_{1},z_{2}}^{(LS)}(t)\), node \(z_{1}\) is only able to recover a range for \(\hat{p}_{z_{1},z_{2}}^{(LS)}(t)\).