## 3 DRL-Based Joint User Selection and Blocklength Allocation Design
### Problem Formulation  
For a network composed of \(K\) UEs and one MEC server, we will decide which packets will be transmitted, and the blocklength to be used for each packet in each frame to minimize long-term average task AuD. Considering that the data packets on each UE are cached in a FIFO queue, we assume each UE can transmit at most one packet within a frame. Therefore, we can use a set to represent the selection of UEs and blocklength allocation in frame \(t\):  
\[\mathcal{N}_{t}=\big{\{}n_{1,t},n_{2,t},\cdots,n_{k,t}\big{\}},n_{k,t}\in\mathbb{N} \tag{13}\]  
where \(n_{k,t}\) is the blocklength assigned to UE \(k\) in frame \(t\). \(n_{k,t}=0\) means that the UE does not transmit packets in this frame. From (13), the optimization problem of task offloading can be formulated as follows:  
\[\min_{\mathcal{N}_{t},t\in T} \overline{\Delta_{d}}\] (14a) s.t. \[\sum_{k=1}^{K}n_{k,t}=n_{c},\forall i\in\mathcal{T}\,n_{k,t}\in\mathbb{N} \tag{14b}\] \[\varepsilon_{k,t}\leq\varepsilon_{max},\forall k\in\mathcal{U},t \in\mathcal{T} \tag{14c}\]  
\(\overline{\Delta_{d}}\) is the optimization objective, defined as minimizing the average AuD in Equation (12). The constraint (14b) guarantees that the total blocklength equals the available blocklength for the transmission phase in a frame. The constraint (14c) ensures that the error probability for each transmitted packet does not exceed the error probability constraint \(\varepsilon_{max}\).  
From (7) and (8), it is evident that the error probability monotonically decreases as the blocklength increases. Thus, for a given error probability constraint \(\varepsilon_{max}\), with the known SNR \(\gamma_{k,t}\) and data packet size \(m_{k,t}\), we can determine the optimal blocklength \(n_{o,k,t}\) for transmission such that the packets are transmitted exactly meeting the error probability constraint.  
Therefore, when we select a UE, the transmitted blocklength is determined uniquely. By using the binary decision variables, we can transform the joint problem of UE selection and blocklength allocation into a UE selection problem. At frame \(t\), the set of binary decision variables used to determine whether the UE transmits is:  
\[\mathcal{X}_{t}=\{x_{1,t},x_{2,t},\cdots,x_{K,t}\},x_{K,t}\in\{0,1\} \tag{15}\]  
Then, we can transform the optimization problem into:\[\min_{\mathcal{X}_{t},t\in\mathcal{T}} \overline{\Delta_{d}}\] (16a) s.t. \[\sum_{k=1}^{K}n_{o,k,t}\leq n_{c},\forall t\in\mathcal{T} \tag{16b}\] \[\mathcal{X}_{t}=\{x_{1,t},x_{2,t},\cdots,x_{K,t}\},x_{K,t}\in\{0,1\} \tag{16c}\]  
Constraint (16b) is the total blocklength constraint for a frame. Constraint (16c) is the set of binary decision variables, where \(x_{K,t}\) represents the binary decision for each UE \(K\) at frame \(t\), taking a value of either 0 or 1. \(x_{K,t}=1\) means UE \(K\) transmits its data packet using the optimal blocklength that precisely meets the error probability constraint in frame \(t\), whereas \(x_{K,t}=0\) means that the UE \(K\) will not transmit a data packet in that frame. Given that the selected packets for transmission are transmitted in such a way to exactly meet the error rate constraint, the total blocklength may not exactly equal the blocklength available for transmission in one frame. In real-world scenarios, we allocate the remaining blocklength to the packets to achieve lower transmission error probability.