# Energy Efficient Management of Pipelines in Buildings Using Linear Wireless Sensor Networks
## 3 Proposed Solution
### Lion Optimization Algorithm
#### 3.2.2 Node Deployment Algorithm  
The pipeline setup can be considered as a tuple of following fields: (a) Location of base station (BS). (b) Communication range of sensor node R. (c) The starting coordinate of the channel in X direction. (d) The end coordinate of the channel in the X direction. (e) The starting coordinate of the channel in the Y direction. (f) The end coordinate of the channel in the Y direction.  
Pipeline setup (BS,R, xMin, xMax, yMin, yMax)  
The proposed algorithm setups a pipeline with number of sensor nodes with transmitting range R and a Base Station (BS). The algorithm decides the position of each sensor node and the BS. This pipeline is to be setup with area (\(xMax-xMin\))*(\(yMax-yMin\))  
The systematic algorithm is presented below:  
(1) Calculate number of nodes in the network where: \[L=\sqrt{\left(xMax-xMin\right)^{2}+\left(yMax-yMin\right)^{2}}\]
2. Initialize the Network \[\text{P}_{nodes}(:,1)=\text{rand}(n,1)^{*}(xMax-xMin)+xMin\] \[\text{P}_{nodes}(:,2)=\text{rand}(n,1)^{*}(yMax-yMin)+yMin\] Here, \(\text{rand}(n,1)\) gives n random numbers ranging from [0,1] \[P^{\prime}_{nodes}=P_{nodes}\] (4) Initialize the position of the base station \[P_{BS}=\sum\frac{p_{nodes}}{n}\]
5. Transfer the data from nodes to BS and calculate dist, delay and drop_ratio as: \[dist=\sum dist_{i}\] \[dist_{i}=\sqrt{\left(BS(1,1)-P^{\prime}_{nodes}(i,1)\right)^{2}+\left(BS(1,2)- P^{\prime}_{nodes}(i,2)\right)^{2}}\] delay = \(Timeof\,packetarrival-Timeof\,packetgeneration\) \[drop_{ratio}=1-\frac{nos.o\,fPktGenerated}{Nos.ofPktreceivedatBS}\]
6. Calculate \[F=\frac{\alpha_{1}}{dist}+\alpha_{2}*delay+\alpha_{3}*drop\_ratio\]
7. Transmit a one-hop hello signal from the BS then: \[\text{no\_of\_leader}=\text{number of acknowledgement Received.}\]
8. If (no_of_leader > 1) \[\text{i}\hskip 14.226378 pt{P_{nodes}}^{\prime}=\left\{\begin{array}{l}rand*(2* p_{BS}-P_{nodes})+p_{BS}if(2*p_{BS}-P_{nodes})<p_{BS}\\ rand*p_{BS}+(2*p_{BS}-P_{nodes})if(2*p_{BS}-P_{nodes})>p_{BS}\end{array}\right.\] \[\text{ii}\hskip 14.226378 pt{p_{BS}}^{\prime}=p_{BS}+rand*percentage_{i}*(p_{BS}-P_{nodes})\] Else: \[\text{i}\hskip 14.226378 ptp^{node}_{i}=\left\{\begin{array}{l}p^{ node}_{i}ifrand>pr_{i}\\ randelse\end{array}\right.\] Here, \(pr_{i}=0.1+min\Big{(}0.5\),\(\frac{p_{i}-Best_{pi}}{Best_{p}}\Big{)}\) \[\text{ii}\hskip 14.226378 pt{P_{nodes}}^{\prime}=\coprod P^{node}_{i}\] \[{p_{BS}}^{\prime}=p_{BS}+rand*percentage_{i}*(p_{BS}-P_{nodes})\] end if
9. Transfer the data from nodes to BS and calculate dist, delay and drop_ratio as: \[dist=\sum dist_{i}\]\[dist_{i}=\sqrt{\left(BS(1,1)-P^{\prime}_{nodes}(i,1)\right)^{2}+\left(BS(1,2)-P^{ \prime}_{nodes}(i,2)\right)^{2}}\]  
Delay = \(Timeofpacketarrival-timeofpacketgeneration\)  
\[drop_{ratio}=1-\frac{nos.ofPacketGenerated}{Nos.ofPacketreceivedatBS}\]  
10. Calculate: \[Ft=\frac{\alpha_{1}}{dist}+\alpha_{2}*delay+\alpha_{3}*drop_{ratio}\]
11. If(F\({}^{\prime}<F\)) Then: \[P_{BS}=p_{BS}{}^{\prime}\] and \[P_{nodes}=P^{\prime}_{nodes}\] end if
12. If (\(|F-F^{\prime}|<0.01\)) Then exit Else go to step 3  
The above algorithm first estimates the number of nodes in the network based on the length of the pipeline. Initially, the position of nodes is generated randomly on the pipeline. After that, the Lion Optimization meta-heuristic is used to get the optimized position of the nodes. The mathematical details have been discussed in the previous subsection. While optimizing the position of nodes the drop ratio and delay are considered, i.e., the position having optimized delay and drop ratio is selected.