# A Method to Construct an Indoor Air Pollution Monitoring System Based on a Wireless Sensor Network
## 2 WSN Coverage Optimization Based on PSO
### Network Coverage Optimization Based on PSO  
The PSO is inscribed in the family of evolutionary algorithms and is one of the most popular meta-heuristic optimization algorithms inspired by nature. This technique is used for any problem to explore a search in space to find the set parameters that maximize/minimize a particular goal [25]. The population in the PSO algorithm is called the swarm, and each individual in the group is called the particle. The displacement of any particle (as indicated above) is governed by very specific rules and conditions and is influenced by the movement of other particles in the neighborhood. The algorithm is guided by personal experience (Pbest), overall experience (Gbest), and the present movement of the particles to decide their next positions in the search space. In D dimensional search space, we have M particles at certain speed flight. To find the optimal solution, PSO algorithm initializes a group of random particles through the iterative. With the speeds of each generation of particles, the location updates the objective function as follows [26],  
\[v_{ij}(n+1)=w\times\ v_{ij}(n)+c_{1}\times rand_{1}\times\big{(}pbest_{ij}-x_{ ij}\big{)}+c_{2}\times rand_{2}\times\big{(}gbest-x_{ij}\big{)} \tag{9}\]\(j\): Refers to the dimension of the question searched by particles
* \(i\) : Refers to the number of particles
* \(n\) : Refers to iterations
* \(c_{1}\) _and_\(c_{2}\) : The accelerating constants in the algorithm
* \(rand_{1},\ rand_{2}\) : Are two independent uniformly distributed random variables between (0,1)
* \(v_{ij}\): Is usually valued in a certain range
* \(w\): Is the inertia coefficient where: \[w=wmax-\frac{n}{\max\textit{number}}\ \times(wmax-wmin)\] (10)  
The appreciation of the quality of its position is stopped by the value of the \"objective\" function at this point. It is essential that this particle can memorize the better position by which it has already passed, formulated as follows:  
\[\textit{Pbest}_{ij}=(\ \textit{pbest}_{i1},\ \textit{pbest}_{i2},\ \ldots,\ \textit{pbest}_{iD})\]  
The best position reached by the particles of the swarm is formulated as follows:  
\[\textit{Gbest}=(\textit{gbest}_{1},\ \textit{gbest}_{2},\ \ldots,\ \textit{gbest}_{D})\]  
The notion of _Gbest_ (global best), is modeled on the PSO Global version (PSOG) where all the particles of the swarm are derived from the particle \(i\). At the beginning of the algorithm, the particles of the swarm are initialized randomly/regularly in the search space. Subsequently at each iteration, the particles move, merging the three components:  
* \(v_{ij}(n)\): Is the speed of the particle in last iterative;
* \(c_{1}\times rand_{1}\times(\textit{pbest}_{ij}-x_{ij})\): The \"cognitive\" part which is the distance between the current position with best position of the particle, which indicates that particles can learn on itself;
* \(c_{2}\times rand_{2}\times(\textit{gbest}-x_{ij})\): The \"social\" part which is the distance between the current position with the global the best position, that represents the collaboration between the particles. At the end of the displacement of the particles in a given iteration, the new positions are evaluated and the two vectors _Pbesti_ and _Gbest_ are reindexed. According to Equation (11) in the case of a minimization of an objective function then Equation (12) in the PSOG can be achieved:  
\[\textit{Pbest}_{i}(t+1)=\left\{ \begin{array}{c}\textit{Pbest}_{i}(t),\ \textit{si}\ f(x_{i}(t+1))\geq\textit{Pbest}_{i}(t)\\ x_{i}(t+1),\ \ \ \ \ \ \ \textit{otherwise}\end{array} \right. \tag{11}\]  
\[\textit{Gbest}(t+1)=\text{argmin}_{\textit{Pbesti}}f(\textit{Pbest}_{i}(t+1)), \ 1\leq i\leq N \tag{12}\]  
This procedure is represented in the PSO algorithm, for \(N\) represents the number of particles of the swarm:  
Step 1: Randomly initialize N particles: Position and speed. Step 2: Evaluate particle positions.