## 4 Beetle Swarm Optimization (BSO) Method
### Realization of the Proposed BSO  
Based on the analysis above, the detailed realization of the proposed BSO method can be described as follows: The flowchart is provided in Figure 6. From this figure, we can see that there are four steps, which are the scene construction, algorithm initialization, determination of beetle sizes, updates of the beetles' positions, and global optimum positions. The illustrations for every step can be found, and the pseudocode is provided in Figure 7.  
**Scene Construction**/  
Give the starting point \(S\) and destination point \(D\). Generate \(M\) beetles with the dimension \(N\). Initial position of a beetle \(i\) is randomly given as \(x_{i}\). **Algorithm Initialization**/  
The number of all beetle moves is set as \(T\). Set the beetle move counter \(k\)=0. Calculate initial path cost using equation (7). Save the position \(x_{i}\) with least cost as current global best. **Main Loop**/  
Beetle move counter \(k\)=\(k\)+1. **While** termination condition \(T\) is not satisfied **do**  
Determine adaptive step size of beetle \(i\) in \(k\)th move _Step_,\(i\) and random proportionality coefficient \(R_{i}^{k}\) with equation (10) and (11) respectively. Generate \(d_{0}^{(k)}=Step_{i}^{k}/R_{i}^{k}\) for beetle \(i\) in \(k\)th move. Obtain right and left antennae coordinates \(x_{k}\)\({}^{i,k}\) and \(x_{1}\)\({}^{i,k}\) of beetle \(i\) in \(k\)th move with equation (13). Calculate costs of right and left antennae with equation (7) as \(f(x_{k}^{k,-})\) and \(f(x_{1}\)\({}^{i,k})\). Update current positions of beetle \(i\) and global best cost using equation (12) and (7). **End while**  
**Output**/ The beetle positions with the least cost combining with the current global best cost \(G_{C}\) in the last move is the global best solution for the waypoint. Figure 6: Flowchart of proposed BSO. Figure 7: Pseudocode of proposed algorithm. Step 1: Scene construction. The coordinates of the starting and destination points for UAVs to operate are given first as \(S\) and \(D\). The positions of \(S\) and \(D\) should be in the scope, which is covered by the ground risk map, as shown in Figure 1. After that, a beetle swarm would be generated with the determined number of beetles \(M\). All the beetles' dimensions are set as the same as \(N\). The positions of all the beetles are the possible waypoint sets for UAVs. \(N\) is also the number of the waypoints between the starting point \(S\) and the destination point \(D\); namely, the size of each waypoint set is \(N\). Step 2: Algorithm initialization. In the proposed BSO method, the total number of all the beetles' moves in a given swarm is initialized as \(T\). In this way, there are \(T\) iterations to evolve for the optimization process. The move counter \(k\) starts from zero. The initial path cost is calculated by using Equation (7) based on all the beetles' initial positions by incorporating the three main constraint conditions, including the ground risk, the turning angle, and the path length. The beetle with the lowest path cost would be saved and then selected as the current global best solution from the beginning to the current iteration. Step 3: Determination of beetle size. First, set the beetle move counter \(k=k+1\). After that, for any beetle \(i\) in the current move \(k\), the proposed adaptive step size \(Step_{i}^{\,k}\) and random proportionality coefficient \(R_{i}^{\,k}\) can be determined by using the two previously provided Equations (10) and (11), respectively. Once these two key parameters for the proposed BSO method are determined, the required distance \(d_{0}^{\,i,k}\) between the beetle \(i\)'s right and left antennas in the current \(k\)th move can be calculated with the equation \(d_{0}^{\,i,k}=Step_{ik}/R_{i}^{\,k}\). In this way, the size of the current beetle \(i\) can be obtained finally. Step 4: Update the beetles' positions and global best.