## 4 Proposed Distributed Trajectory Planner Based on PSO and Bresenham Algorithm
### Particle Swarm Optimization  
Particle Swarm Optimization (PSO), a relatively new family of algorithms that may be used to find optimal or near-to-optimal solutions. It is an optimization technique that provides an evolutionary-based search result on numerical and qualitative problems. It optimizes a problem by iteratively trying to improve a candidate solution. It is inspired by group behaviors in wildlife, for example, bird flocks, honeybees, ant colonies, and fish schooling.  
In PSO, all particles are randomly initialized with velocity and position, and each particle keeps finding a candidate solution. Then, in each iteration, the velocity and position of each particle are renewed based on information about the previous velocity, the best position ever occupied by the particle, which is known as a personal influence, and the best position ever occupied by any particle in the swarm, known as a social swarm or global swarm. The mathematical formulations are as follows.  
Let, assume the number of the particle is P, D denoting the dimensionality of a particle, and N stands for the iteration number. For any \(i\)th particle, position and velocity vector can be represented as \(x_{i}\) and \(v_{i}\), respectively. For standard PSO algorithm, there are two kinds of cost values, i.e., \(p_{i,\,best}\) for the individual best value of one particle, and global best value \(g_{best}\) of all particles, which can be written as Equations (25) and (26):  
\[p_{i,best}=\ p_{i1,best},p_{i2,best},p_{i3,best},\ldots,p_{iN,best} \tag{25}\]  
\[g_{best}=\ g_{1,best},g_{2,best},g_{3,best},\ldots,g_{N,best} \tag{26}\]  
After determining the two cost values, the velocity and position of each particle in each dimension are renovated by using Equation (27) [1]:  
\[\begin{array}{c}v_{ij}(k+1)=wv_{ij}(k)+n_{1}r_{1}\big{(}p_{i,best}-x_{ij}(k) \big{)}+n_{2}r_{2}\big{(}g_{best}-x_{ij}(k)\big{)}\\ x_{ij}(k+1)=x_{ij}(k)+v_{ij}(k+1).\end{array} \tag{27}\]  
In Equation (27), \(r_{1}\) and \(r_{2}\) denoting the random values between 0 and 1, \(w\) is the inertia coefficient which reflects the influence of the velocity in the previous iteration on the current iteration. \(n_{1}\) and \(n_{2}\) are self-cognitive and social cognitive values, which indicate the inheriting abilities from the particle itself and the whole swarm. Pseudocode for dynamic fitness function using PSO can be shown in Algorithm 1.  
```
1. Initialize cell SAI values;
2. while (CAC is not satisfied)
3. {
4. set monitoring UAV number \(=N_{add}\);
5. for \(j=1:N_{add}\);
6. for \(j=1:N_{add}\);
7. set iteration number \(=N_{add}\);
8. set particle number \(=N_{add}\);
9. for \(k=1:N_{add}\);
10. {
11. for \(t=1:N_{part}\)
12. {
13. randomly initialize \(x_{i}\) and \(v_{i}\);
14. initialize \(P_{out}=x_{i},S_{out}=x_{part}\);
15. Update \(x_{i}\) and \(v_{i}\) using (26);
16. Compute the fitness value of \(x_{i}\) using (3) to (23);
17. \(\text{I}(fitness(x_{i})>fitness(P_{best}))\)
18. \(\text{I}(fitness(P_{best})>fitness(g_{best}))\)
19. \(\text{I}(fitness(P_{best})>fitness(g_{best}))\)
20. {
21. \(\text{S}_{best}=P_{best}\);
22. \(\text{dynamic\_fitness}=fitness(g_{best})\);
23. }
24. }
25. }
26. update SAI value using Bresenham algorithm;
27. }
28. evaluate collisions among multiple UAVs.
```  
**Algorithm 1**Pseudocode for Dynamic Fitness Function using PSO.