## 4 Proposed Algorithm for Reliability Computing of Chain Routing Protocols in WSN
### Proposed Reliability Calculation  
This section explains the calculation of the RBD for the various proposed models that are illustrated previously in Section 4.4. The reliability of these models, based on stationary or mobile CHs, is calculated as follows:  
* SD-Chain: in this configuration, the chain members are connected to each other serially and the reliability calculation relies on the series reliability that is explained in Section 4.2. Moreover, the reliability calculation depends on the CH energy; while the CH or the network is alive, continue the reliability calculation, as illustrated in Algorithm 1. * SQ-Chain: in this model, the CH could be anywhere through the chain, since it is selected based on Q. The chain may divide into two serial chains, where each chain ends at the CH. While the chain member does not reach the alive CH, calculate the reliability for both chains serially. Both chains are parallel, so calculate the parallel reliability, then the series with the CH, as shown in Algorithm 2. * MD-Chain-SH: the SD-Chain is divided into multiple serial chains, and the nodes of each chain are arranged serially with their CH. Each chain calculates the series reliability with the CH, then calculates the parallel reliability for all chains that are parallel to each other, as clarified in Algorithm 3. * MQ-Chain-SH: the MQ-Chain has the same node arrangement as the SQ-Chain discussed above, but for multi-chains instead of a single chain. However, calculating the reliability for MQ-Chain-SH has the same steps as calculating the reliability of SQ-Chain, in addition to one more step that calculates the parallel reliability for all multi-chains, as explained in Algorithm 4. * MD-Chain-MH: this model has multiple D-Chains, while each chain has one CH that collects the data from its chain members, the whole chain has one LN that collects the data from the CHs. Algorithm 5 clarifies the reliability calculation for MD-Chain-MH. Each chain calculates the reliability serially for the chain nodes and then calculates the series reliability for the chain with the CH, if the CH is not the LN. Calculate the parallel reliability for all chains, then calculate the reliability serially with LN. * MQ-Chain-MH: in this configuration, each chain has a CH, and the whole network has an LN. This model has multiple Q-Chains, where the reliability for each chain is calculated in series and then parallel until it arrives at the CH. If the CH is not the LN, then calculate the reliability of the chain serially with the CH. Finally, calculate the parallel reliability of whole chains and then series reliability with the LN, as described in Algorithm 6. Figure 15: MQ-Chain-MH formation. ```
1:Input: chain head (\(CH\)), nodes (\(N\)), initial energy (\(Eo\)), node energy (\(E_{N}\)), chain head energy (\(E_{CH}\)) and no. of alive nodes (\(Alive\)). 2:Output: reliability. 3:\(R=1\)
4:\(i\) = \(Alive\)
5:while\(N_{i}\)\(\ast\)\(CH\)do
6:\(R=R\times E_{N}(i)/Eo\)
7:\(i=i-1\)
8:endwhile
9:\(reliability=R\times E_{CH}/Eo\)
10:returnreliability
```  
**Algorithm 1** Calculate reliability of SD-Chain. ```
1:Input: chain head (\(CH\)), nodes (\(N\)), initial energy (\(Eo\)), node energy (\(E_{N}\)), chain head energy (\(E_{CH}\)) and no. of alive nodes (\(Alive\)). 2:Output: reliability. 3:\(R_{1}=1\)
4:\(R_{2}=1\)
5:\(i_{1}=1\)
6:\(i_{2}=Alive\)
7:while\(N_{i_{1}}\)\(\ast\)\(CH\)do
8:\(R_{1}=R_{1}\times E_{N}(i)/Eo\)
9:\(i_{1}=i_{1}+1\)
10:endwhile
11:while\(N_{i_{2}}\)\(\ast\)\(CH\)do
12:\(R_{2}=R_{2}\times E_{N}(i)/Eo\)
13:\(i_{2}=i_{2}-1\)
14:endwhile
15:\(R=1-\left((1-R_{1})\times(1-R_{2})\right)\)
16:\(reliability=R\times E_{CH}/Eo\)
17:returnreliability
```  
**Algorithm 2** Calculate reliability of SQ-Chain. ```
1:Input: chain head (\(CH\)), nodes (\(N\)), initial energy (\(Eo\)), node energy (\(E_{N}\)), chain head energy (\(E_{CH}\)), no. of alive nodes (\(Alive\)) and no. of chains (\(c_{j}\)). 2:Output reliability.