# Dynamic UAV Inspection Boosted by Vehicle Collaboration Under Harsh Conditions in the IoT Realm
## 4 Algorithm
### Static Planning and Scheduling Algorithm
#### 4.1.3 UAV Allocation Routes  
After dividing multiple UAV flight routes within a single docking anchor point, the next step involves assigning these routes to individual UAVs. To enhance the efficiency of the multi-UAV-vehicle collaborative patrolling system, the solution requires a more balanced distribution. Each UAV should execute tasks in parallel to minimize the execution time for tasks at a single anchor point.  
```
0: Anchor point location \(a_{j}\), customer set corresponding to the anchor point \(E_{i}\);
0: UAV flight route set routes;
1: Initialize the route set \(routes\leftarrow\emptyset\)
2:for\(i=1\) to \(max\_iter\)do
3: temporary task point set \(Q\gets E_{i}\),\(route\leftarrow\emptyset\)
4:while\(Q\
eq\emptyset\)do
5:if\(route=\emptyset\)then
6: Randomly select a customer point \(p_{i}\) from \(Q\), current location \(location=p_{i}\)
7: Add \(p_{i}\) to \(route\), and remove it from \(Q\)
8:endif
9: Find the task point \(p_{j}\) in \(Q\) that is closest to \(location\) and add it to \(route\)
10: Calculate the distance \(d\) from the anchor point \(a_{i}\) passing through all points in the route and returning to the anchor point \(a_{i}\)
11:if\(d\leq d_{\text{max}}\)then
12: Remove \(p_{j}\) from \(Q\), \(location=p_{j}\)
13:else
14: Remove customer point \(p_{j}\) from \(route\)
15: Add the route \(route\) to the route set \(routes\),\(route\leftarrow\emptyset\)
16:endif
17:endif
18:if\(route=\emptyset\)then
19: Add the route \(route\) to the set of routes \(routes\)
20:endif
21:endfor
22: Return \(routes\);
```  
**Algorithm 2** Algorithm for Partitioning Routes within Anchor Points  
The pseudocode for the UAV route assignment algorithm is shown in Algorithm 3. Initially, the status of all UAVs and the length of each route are iterated through. If there is a route \(l_{r_{i}}\) with a length not exceeding the remaining flight range \(x_{u_{k}}\) of a certain UAV \(u_{k}\) (i.e., the distance from the current UAV position to the anchor point via all customers on  
Figure 3: Illustration of the Route within the Anchor Point.  
the route), then this route \(r_{i}\) is assigned to that UAV \(u_{k}\) and removed from the set of UAV flight routes _routes_. Through this step, all UAVs will return to the anchor point, and the flag is set to True. At this point, the UAV's position is updated to the anchor point, and the remaining flight range is reset to full battery status. The remaining UAV flight routes in the set are sorted in descending order by flight length (the distance from the anchor point to all task points in _routes_ and back to the anchor point). During each iteration through the flight route set, if there is a route that makes the total length of the routes currently assigned to a UAV the shortest, then this route is added to the solution set of that UAV. The above steps are repeated in a loop until all UAV routes are fully assigned.  
```
0: Anchor point position \(a_{i}\),UAV flight route set routes,Set of UAVs \(U\);
0: The solution within a single anchor point \(S_{part}\);
1:for\(u_{k}\in U\)do
2:for\(route\in routes\)do
3:if\(l_{r_{i}}<x_{u_{i}}\)then
4: Add this route to the solution set of the corresponding UAV and remove it from the route set
5:else
6: Set the UAV's return-to-position flag to _True_, indicating that the UAV will fly directly back to the anchor point.
7:endif
8:endfor
9:endfor
10: Update the position of each UAV to the anchor point position \(a_{i}x_{u_{i}}=d_{max}\)
11: Sort the remaining routes in the route set in descending order by flight length.
12:for\(route\in routes\)do
13: Select the UAV with the shortest total length of routes already scheduled.
14: Add the route to the solution set of that UAV.
15:endfor
16: Return \(S_{part}\);
```  
**Algorithm 3** UAV Route Assignment Algorithm