# Distributed Task Allocation for Multiple UAVs Based on Swarm Benefit Optimization
## 3 Method
### The Entire Procedure  
As can be seen from the above, after any UAV \(i\) in the swarm constructs its task plan \(\mathbf{a}_{i}\) based on the above task selection method, it has realized the optimization of swarm overall efficiency (Formula (1)) under constraints (Formulas (2)-(4) and (6)). However, for the conflict-free constraint (Formula (5)), the aforementioned process is still inadequate for resolving potential task selection conflicts between UAVs. Hence, an additional task conflict resolution mechanism must be introduced for further coordination.  
Since this paper focuses on the optimization of UAV swarm benefits, the method outlined in reference [38] is adopted for task conflict resolution. The brief process is described as follows. UAVs exchange information regarding the swarm benefit variation of all tasks \(j\) from their respective perspectives \(\mathbf{B}_{j}^{i}\), accompanied by the UAV identifiers and timestamps corresponding to these variations. Conflicts are then resolved using the conflict resolution rules established in reference [38]. When the timeliness of information can be ascertained, UAVs with different swarm benefit variations for the same task \(j\) will be unified to the scheme with the highest swarm benefit variation from a personal perspective. In cases where timeliness cannot be determined, timestamps are used to facilitate the decision-making process. Thus, the conflict-free constraint (Formula (5)) is satisfied, and the optimization (Formula (1)) under all constraints (Formulas (2)-(6)) is achieved through the iterative process of task selection and conflict resolution, continuing until the individual task plans of all UAVs remain unchanged.  
The entire optimization process is outlined in Algorithm 2. Initially, all UAVs within the swarm set their task plans \(\mathbf{a}_{i}\) to empty set (line 1). Subsequently, the iterative process proceeds as long as there is a change in any UAV's plan \(\mathbf{a}_{i}\) within the swarm (lines 2-9). The task selection process follows the procedure detailed in Algorithm 1 (line 3), while the conflict resolution process is described in lines 4-7 of Algorithm 2. The conflict resolution process involves identifying conflicting tasks (line 5), and determining the ownership of these tasks based on the rules established in reference [38] to reach \(\mathbf{B}_{j}^{i}=\mathbf{B}_{j}\) (\(\mathbf{B}_{j}\) is the consistent swarm benefit variation in the UAV swarm) (line 6), and ultimately, UAVs remove conflicting tasks that are not assigned to them along with any subsequent tasks (line 7), updating the planned time and benefit variation of the remaining tasks in their task plans (line 8).  
```
1:UAV \(i\in\mathcal{I}\) initializes its individual task plans \(\mathbf{a}_{i}=\{\}\).
2:while\(IsChanged(\mathbf{a}_{i})\)do
3: Task selection as shown in Algorithm 1.
4: UAVs exchange their information regarding \(\mathbf{B}_{j}^{i}\) for all tasks \(j\).
5: UAV \(i\) find all conflicting tasks \(j=\mathbf{a}_{i}\cap\mathbf{a}_{k}\) with other UAV \(k\).
6: Determines the ownership of these conflicting tasks to reach \(\mathbf{B}_{j}^{i}=\mathbf{B}_{j}\).
7: Removes these conflicting tasks \(j\) with \(\mathbf{B}_{j}^{i}\
eq\kappa_{ij}^{-}\) and their subsequent tasks from \(\mathbf{a}_{i}\).
8: Updates the planned time and benefit variation of the remaining tasks in \(\mathbf{a}_{i}\).
9:endwhile
```  
**Algorithm 2** The entire optimization procedure