# Energy-Efficient UAVs Deployment for QoS-Guaranteed VoWiFi Service
## 6 Solving a Dynamic Scenario
### Periodical Search Algorithm: PSO  
Particle Swarm Optimization (PSO) is a heuristic search method inspired by bird flocking or fish schooling's social behaviour. In PSO, each candidate solution is represented as a particle that moves around in the search-space towards better solutions. Initially, a collection of particles with random positions in the search-space is created. Each particle is represented by its position (i.e., collection of characteristics, similar to individuals in GA), and a velocity. On each iteration, each particle updates its position based on its velocity, its best known position, and the global best location.  
Figure 5: Dynamic scenario.  
```
Input:\(\mathcal{D}\), \(\mathcal{L}_{old}\) (old location), \(\mathcal{P}\), \(\mathcal{U}\), \(\{\boldsymbol{w}_{k}\}\), \(D_{\max}\), \(C_{\min}\), \(R_{\min}\) Output:\(\mathcal{L}^{*}\) (new location), \(f^{*}_{\text{obj}}\) (obj. value) Initialization:\(\mathcal{L}^{*}=\mathcal{L}_{old}\), \(f^{*}_{\text{obj}}=\text{Inf}\) /* Create the initial swarm */ \(\mathcal{W}=\text{PSO\_InitSwarm}\left(\mathcal{L}_{old}\right)\); // Initialize best-known locations \(\mathcal{B}=\mathcal{W}\); // Initialize best-known obj. function values \(\mathcal{F}(i)=\text{Inf}\;\;\forall i\); // Initialize best-known obj. function values while!(exit criteria met)do forparticle \(i=1\)to\(|\mathcal{W}|\)do /* Update the \(i\)-th particle */ \(\mathcal{W}(i)=\text{PSO\_UpdateParticle}\left(\mathcal{W}(i)\right)\); /* Evaluate the \(i\)-th particle */ \(\left[f_{\text{obj}},\;C,\;R\right]=\text{Check}\left(D,\mathcal{W}(i),\, \mathcal{U},\,\{\boldsymbol{w}_{k}\}\right)\); /* Record results */ if\(\left(f_{\text{obj}}<\mathcal{F}(i)\;\text{and}\;C\geq C_{\min}\;\text{and}\;R \geq R_{\min}\right)\)then \(\mathcal{B}(i)=\mathcal{W}(i)\); // Update best-known particle's location \(\mathcal{F}(i)=f_{\text{obj}}\); // Update best-known particle's obj. function value if\(f_{\text{obj}}<f^{*}_{\text{obj}}\)then \(\mathcal{L}^{*}=\mathcal{W}(i)\); // Store best-known global position \(f^{*}_{\text{obj}}=f_{\text{obj}}\);  end if  end for  end for  end for
```  
**Algorithm 3**PSO-based search pseudocode.  
Algorithm 3 shows the pseudocode for our PSO-based search algorithm. The input of the algorithm is the previous positioning (\(\mathcal{D}\) and \(\mathcal{L}_{old}\)), the set of ground users (\(\mathcal{U}\)) and their location (\(\{\boldsymbol{w}_{k}\}\)), the set of edges (\(\mathcal{P}\)), coverage (\(C_{\min}\)) and quality (\(R_{\min}\)) constraints, and the maximum number of drones (\(D_{\max}\)). The algorithm assumes that the number of deployed drones (\(D\)) does not change between two consecutive executions, and relocates them. To do so, it initializes the swarm of particles (\(\mathcal{W}\)) with the function \(PSO\_InitSwarm\) around the previous positioning (\(\mathcal{L}_{old}\)). Then, each particle is updated through the function \(PSO\_UpdateParticle\), which receives as input the best known position for that particle. Then, the candidate position (\(\mathcal{X}\)) is evaluated through the function _Check_ from Section 5. Finally, if the particle improves its result, we store the new position as \(\mathcal{W}(i)\) and, if the best solution is improved, we record it at \(\mathcal{L}^{*}\), which is the output of the algorithm. This procedure is repeated until the exit criteria is met. PSO implementation and its functions (\(PSO\_InitSwarm\) and \(PSO\_UpdateParticle\)) is discussed in Appendix C.