## 3 Problem Formulation  
An optimization problem is formulated for minimizing the end-to-end latency in making the final prediction through distributed inference within a resource-constrained UAV swarm. Based on an optimization discussed in [25], this new optimization problem considers the UAVs availability and both the U2G and U2U links. The proposed optimization problem depends on three decision variables \(\delta_{t,r,i,j}\), \(\psi_{t,i,j,q}\), and \(o_{t,i}\), which are defined as follows:  
\[\delta_{t,r,i,j}= \begin{cases}1,&\text{if UAV $i$ executes layer $j$ of request $r$ at time $t$}\\ 0,&\text{otherwise},\end{cases}  \tag{8}\]  
\[\psi_{t,i,q}= \begin{cases}1,&\text{if UAV $i$ exists at cell $q$ at time $t$}\\ 0,&\text{otherwise},\end{cases}  \tag{9}\]  
\[o_{t,i}= \begin{cases}1,&\text{if UAV $i$ is operable at time $t$}\\ 0,&\text{if UAV $i$ is inoperative at time $t$}.\end{cases}  \tag{10}\]  
The proposed optimization problem can be an integer linear programming (ILP) optimization, and it is formulated as  
\[\min_{\psi_{t,i,q},\psi_{t,i,j}}\quad\sum_{t=1}^{T}\sum_{r=1}^{RQ_{t}}\sum_{i=1 }^{N}\sum_{ \begin{subarray}{c}k=1\\ k\
eq i\end{subarray} }^{N}\sum_{j=1}^{L-1}\delta_{t,r,i,j}\cdot o_{t,k}\cdot \delta_{t,r,k,j+1}\cdot\frac{K_{r,j}}{\rho_{i,k}}+\sum_{i=1}^{N}o_{t,i}\cdot t _{i}^{(p)}+t_{l}, \tag{11}\]  
Constraints:  
\[\sum_{r=1}^{RQ_{t}}\sum_{j=1}^{L}\delta_{t,r,i,j}\cdot m_{j}\leq m_{i}^{\max}, \tag{11a}\] \[\sum_{r=1}^{RQ_{t}}\sum_{j=1}^{L}\delta_{t,r,i,j}\cdot c_{j}\leq c_{i}^{\max},\] (11b) \[\sum_{i=1}^{N}\delta_{t,r,i,j}= \begin{cases}1,&\text{if $j\leq L$}\\ 0,&\text{otherwise},\end{cases} \] (11c) \[\sum_{q=1}^{C}\psi_{t,i,q}=1, \tag{11d}\]\[\sum_{i=1}^{N}\psi_{t,i,q}\leq 1, \tag{11e}\] \[\delta_{t,r,i,j}\leq o_{t,j},\] (11f) and where \[t_{l}=\sum_{i=1}^{N}o_{t,i}\cdot\delta_{t,r,i,L}\cdot\frac{K_{r,L}}{\rho_{i,G}},\] (12) \[t_{i}^{(p)}=\sum_{t=1}^{T}\sum_{r=1}^{RQ_{i}}\sum_{j=1}^{L}\delta_{t,r,i,j} \cdot\frac{c_{j}}{c_{i}^{\max}}. \tag{13}\]  
The proposed optimization problem is divided into three parts to systematically address the latency components associated with distributed CNN inference in a UAV swarm. The first part focuses on inter-UAV transmission latency for transmitting intermediate data between layers, which is crucial for efficient distributed processing. The second part addresses the latency of transmitting the final output to the ground station. Lastly, the third part addresses the computational latency required to process the layers assigned to each UAV. 1. Inter-UAV transmission latency: the time required to transmit the intermediate data of layer \(j\) assigned to UAV \(i\) to UAV \(k\) can be represented in \[\frac{K_{r,j}}{\rho_{i,k}},\] (14) where \(K_{r,j}\) denotes the intermediate data generated from layer \(j\) of request \(r\), and \(\rho_{i,k}\) denotes the transmission data rate between the UAV \(i\) and the UAV \(k\). 2. Final output transmission latency to ground devices: in Equation (12), \(t_{l}\) is the time required to transmit the output of the last layer to the ground device \(G\), and \(K_{r,L}\) is the size of the final output for classification tasks. 3. Computational latency of individual UAVs: In Equation (13), \(t_{i}^{(p)}\) is the total time required to compute all processing tasks assigned to UAV \(i\). This time is defined as the ratio of the computational requirement \(c_{j}\) of the layer \(j\) to the computational capacity \(c_{i}^{max}\) of the UAV \(i\). The constraint in Equations (11a) and (11b) ensures that each UAV \(i\) does not exceed its memory usage and computational capacity while processing its assigned CNN layer, respectively. The constraint in Equation (11c) guarantees that each layer is assigned to only one UAV. To prevent collisions, the constraint in Equation (11d) ensures that only one UAV visits each cell at each time step. The constraint in Equation (11e) restricts each UAV to visiting only one cell at any given time t. Lastly, the constraint in Equation (11f) ensures that no layers are assigned to inoperable UAVs.