# Task Assignment of UAV Swarm Based on Wolf Pack Algorithm
## 3 The Wolf Pack Algorithm
### The Basics of the Wolf Pack Algorithm
However, the task assignment problem is a discrete problem in which the variable in each dimension is an integer belonging to a set. As such, based on the rules of the WPA, it is necessary to improve the WPA to match the integer discrete character of the task assignment. In addition, in order to improve the convergence speed and solution accuracy, PSO and a GA are introduced into WPA. The details of the PSO-GA-DWPA are as follows and the algorithm is shown in Algorithm 2. #### 3.2.1 Integer Matrix Coding

Integer matrix coding is adopted to express the assignment schema

\[X_{i}=\left[ \begin{array}{cccccc}x_{i1}&x_{i2}&\cdots&x_{ij}&\cdots&x_{iN_{T }}\\ y_{i1}&y_{i2}&\cdots&y_{ij}&\cdots&y_{iN_{T}}\end{array} \right], \tag{12}\]

where \(X_{i}\) is the position of the wolf \(i\in N\), \(N\) is the population number of wolves, the dimensions of variable is \(N_{T}\) because there are more targets than UAVs and each target can only be attacked once. The 1 st row of Equation (12) is the index of the UAVs which perform attacking tasks where \(x_{ij}\in V\), and elements in this row can be repeated because a UAV can attack multiple targets. The 2 ed row of Equation (12) is the index of targets, where \(y_{ij}\in T\). For the same UAV, the order in which the target number appears is the attack order. For example, if there are 5 UAVs attacking 8 targetsand the coding matrix is shown as \(X_{i}=\left[ \begin{array}{cccccccc}1&3&2&2&1&1&3&3\\ 3&5&1&4&2&8&7&6\end{array} \right]\), then the task assignment scheme is as follows: \(\mathit{plan}_{1}=\left\{(3,L_{1}^{(1)}),(2,L_{2}^{(1)}),(8,L_{2}^{(1)})\right\}\), \(\mathit{plan}_{2}=\left\{(1,L_{1}^{(2)}),(4,L_{2}^{(2)})\right\}\), and \(\mathit{plan}_{3}=\left\{(5,L_{1}^{(3)}),(7,L_{2}^{(3)}),(6,L_{2}^{(3)})\right\}\). #### 3.2.2 Improvement on Walking Behavior

The walking behavior of wolves is essentially an active exploration of the unknown environment. This process determines the extent of the current best solution approaches to the global optimal solution. In the WPA, each exploring wolf scouts the prey from h directions divided equally by 360 degrees as Equation (8), and adjusts the coverage of the scout by changing the size of \(h\). The bigger \(h\) is, the larger the coverage of the scout will be, but the speed of the scout will be relatively slower. To scout the prey more effectively, PSO is introduced in this paper to make the walking process completed from as few directions as possible, under the guidance of the global extremum and the individual extremum. Each exploring wolf is represented as one particle in the PSO. The implementation of PSO is divided into three steps [20]: tracking individual extremum, tracking global extremum and individual variation. 1. Tracking individual extremum This part of the formula is expressed in the discrete domain as Equation (13). This represents a copy operation with probability \(c_{1}\). \(X_{i}^{k}\) represents the position of wolf \(i\in S\) in iteration \(k\). \(P_{i}^{k}\) is the optimal solution of wolf \(i\in S\) according to the current scouted directions, representing the individual extremum of wolf \(i\in S\) in iteration \(k\). Note that \(\varphi_{i}^{k}\) is a temporary variable. \[\varphi_{i}^{k}=c_{1}\otimes F_{1}(X_{i}^{k},P_{i}^{k})= \begin{cases}F_{1}(X_{ i}^{k},P_{i}^{k}),&\varepsilon=\mathit{rand}()<c_{1}\\ X_{i}^{k},&\text{otherwise}\end{cases} . \tag{13}\]

During the operation in Figure 2, a random number \(\varepsilon\in[0,1]\) is generated firstly. If \(\varepsilon<c_{1}\), where \(c_{1}\) is the threshold to determine crossover, two random integers \(a,b\in[1,N_{T}]\) are generated. The columns between the index range \([a,b]\) of \(X_{i}^{k}\) will be exchanged with the counterpart in the individual extremum \(P_{i}^{k}\). The result of this operation is \(\varphi_{i}^{k}\). On the other hand, if \(\varepsilon\geq c_{1}\), \(\varphi_{i}^{k}=X_{i}^{k}\). 2. Tracking global extremum Equation (14) represents a copy operation with probability \(c_{2}\).