# A Task Allocation Strategy of the UAV Swarm Based on Multi-Discrete Wolf Pack Algorithm
## 3 The Wolf Pack Algorithm
### Proposed Algorithm
#### 3.2.1 Individual Coding and Initialization  
In the improved algorithm, a hybrid coding method based on task assignment and path planning is adopted for mixed variables. The position vectors of individuals contain discrete variables representing the results of task assignment. In order to generate a feasible task allocation plan more effectively, according to the characteristics of UAV task allocation problem, the algorithm adopts a mixed variable coding method based on task allocation and path planning and designs an appropriate constraint processing method to initialize the position vector of wolf individuals according to the coding method. At the same time, new individuals are generated by a recombination method based on structure learning to further improve the quality of the population. In addition, in the process of population renewal, in order to obtain more excellent individuals, the improved algorithm adopts the mechanism of coevolution, that is, a coevolutionary population and the original population compete to generate new individuals.  
At present, the existing coding methods can only describe the final assignment scheme but cannot represent the executing sequence of tasks, that is, the path planning result of the task performed by UAV. Therefore, in order to represent both the result of task assignment and the result of UAV's path planning during task execution, a hybrid variable coding method based on task assignment and path planning is proposed in this paper. This method codes according to the specific situation of the UAV in the execution of the task. The code of each individual contains two parts, that is, \(P=~{}(MN,~{}UN)\), where the first part \(MN\) is a discrete variable, recording the task number, and the second part \(UN\) is a discrete variable, which records the number of UAVs performing corresponding tasks.  
Figure 1 shows the code of an individual corresponding to the model of Section 2. It contains 6 targets, there are 3 UAVs, numbered 1-3. The two lines of the position vector of the individual wolf are used to represent the task assignment result. For example, the targets T1, T4 and T6 are assigned to the UAV \(U_{1}\) for execution. At this time, this is the corresponding task assignment plan vector: \(X_{1}^{k}=1~{}(~{}k~{}\in~{}\{~{}1\,6~{}\}~{})\).  
In addition, in order to show the results of the UAV's path planning, the order in which the task numbers appear in the position vector represents the order in which the UAV performs tasks. The blue curve in Figure 1 indicates that UAV \(U_{1}\) performs tasks in sequence \(T_{1},T_{6}\). The orange curve indicates that the execution tasks of the UAV \(U_{2}\) are \(T_{2}\), \(T_{3}\). The green curve indicates that the execution tasks of the UAV \(U_{3}\) are \(T_{4}\) and \(T_{5}\), in turn. Because the coding method uses a hybrid variable coding method based on task allocation and path planning, this variable can not only efficiently convert the position vector of the individual wolf pack into a task allocation plan of the model, but can also fully consider the path uncertainty during the execution of the UAV task and use the order of tasks in the position vector to explicitly show the order in which UAVs perform tasks. This coding method can generate a definite task allocation plan and the path planning results of the UAV when the individual is initialized.  
In the actual initialization operation in the UAV task allocation, we first initialize the task number in the first row. In order to provide a global orientation to the algorithm, randomly scramble \([0,1,\ldots,W]\) and assign it to the first row (W is the last mission number), and then the UAV number in the second line is initialized by random assignment.  
Figure 1: The hybrid coding method.