# Performance Analysis of IoT-Based Health and Environment WSN Deployment
## 3 Health and Environment Sensor Network Deployment
### PSO-Based Sensor Network Deployment  
In a PSO algorithm, the deployment problem of the sensor network is simulated as swarm particles, which move around the search space and are improved by their own best position and swarm's best position together through generations to find the optimum solution [68; 69]. Figure 5 shows the PSO steps for MST-based network deployment algorithm to maximize coverage and lifetime. The algorithm is explained step by step below.  
Step 1: Generate an initial random population with \(p\) number of particles representing sensor networks. This step is completely equivalent to that of BA. In this algorithm, the position of the resources is considered as the position of each particle.  
Step 2: Generate MST graph similar to step 2 of BA.  
Step 3: Set \(t=0\). The following steps are done until t less than the number of generations (\(t<N_{iteration}\)).  
Step 3.1: Calculate fitness functions according to Equation (13).  
Step 3.2: Determine the best particle in the swarm as global best (gbest) that have a higher fitness value and also determine the best position of each particle (pbest). For the first iteration, the initial pbest is considered as the position of the particle.  
Step 3.3: Update the velocity vector for all particles. The velocity of each particle is defined as 2n \(\times\) 1 vector. In this vector, odd and even elements represent respectively the x and y velocities of  
Figure 5: Particle Swarm Optimization (PSO) for MST-based network deployment.  
the network vertices. To calculate velocity, first distance matrix \(D\) is defined by an \(n\times n^{\prime}\) matrix as follows:  
\[D=\left[\begin{array}{cccc}d_{11}&d_{12}&\ldots&d_{1n^{\prime}}\\ d_{21}&d_{22}&\ldots&d_{2n^{\prime}}\\ \vdots&\vdots&\ddots&\vdots\\ d_{n1}&d_{n2}&\ldots&d_{nn^{\prime}}\end{array}\right]\rightarrow\ D=\left[ \begin{array}{c}\Delta x_{1}\\ \Delta y_{1}\\ \vdots\\ \Delta x_{n}\\ \Delta y_{n}\end{array}\right] \tag{16}\]  
where {1, 2, \(\ldots\), \(n\)} are the sensor node numbers of each particle and {1, 2, \(\ldots\), \(n^{\prime}\)} are the sensor node numbers of the gbest particle (or pbest). Second, the smallest element is computed in each matrix row, which represents the minimum distance. Third, the \(x\) and \(y\) differences between each vertex and selected vertex of pest (or gbest) particles are calculated. The velocity vector is calculated to pbest and gbest particles separately. Finally, the total velocity is calculated by Equation (17).  
\[\vec{v_{i}}=w\vec{v_{i}}+c_{1}\ \vec{\varphi_{i1}}\ \vec{\varphi_{i1}}\ \vec{\varphi_{i 0}}+c_{2}\vec{\varphi_{i2}}\ \vec{\varphi_{i}}\ \vec{\varphi_{i 0}} \tag{17}\]  
where \(w\) is the inertia weight, \(c_{1}\) and \(c_{2}\) are acceleration coefficient and constant parameter, \(\varphi_{1}\) and \(\varphi_{2}\) are randomly parameters which are selected for the particles in each step. If the velocity of each particle is obtained at a distance of more than 200 m, it is multiplied by 0.1. It should be noted the initial velocity is considered zero.  
Step 3.4: Update the position vector for all particles. The position vector of each particle is updated using its velocity vector as below.  
\[\left[\begin{array}{c}x_{1}\\ y_{1}\\ \vdots\\ x_{n}\\ y_{n}\end{array}\right]=\left[\begin{array}{c}x_{1}\\ y_{1}\\ \vdots\\ x_{n}\\ y_{n}\end{array}\right]+\vec{v_{i}} \tag{18}\]  
Step 3.5: \(t=t+1\).  
Step 4: Find the best global bee (WSN).