# Cross-Cycled Uplink Resource Allocation over NB-IoT
## 3 Cross-NP Uplink Resource Allocation
### Algorithm Description
\(\sigma\) is used to indicate the currently allocated subframe from NPUSCH start subframe \(t_{f}^{c^{\prime}}\). Variable \(\phi\), initialized as 0, indicates that the number of subframes is allocated. Variable \(h\), initialized to 0, is the resource assignment index (i.e., \(I_{d^{\prime}}^{h}\) for UE \(d^{\prime}\)). In Lines 3-14, as long as the requirement \(\psi_{d^{\prime}}\) of UE \(d^{\prime}\) has not been met, this function will try to allocate subframes continuously one by one (i.e., \(\sigma=\sigma+1\) in Line 4) until the maximum resource units are allocated for the UE (i.e., \(h<H\)). In Lines 5-6, if the current subframe position exceeds the NPUSCH start subframe comprising the first DCI with the minimum scheduling delay in the next NP (i.e., \(L+R_{max}/R+\min(k_{0}^{i})+1\)), it means that no more subframes can be allocated in this NP, and we break the while loop. In Lines 7-8, if all the subcarriers of the subframe are occupied by NPRACHs (i.e., \(r_{P}^{t_{f}^{c^{\prime}}+\sigma}\geq F\)), we skip this subframe. In Lines 9-10, if the unused subcarriers are sufficient for UE \(d^{\prime}\) using resource \(u^{\prime}\), the number of currently allocated subframes \(\phi\) for the UE is increased by 1. Then, in Lines 11-12, we check whether the number of allocated subframes meets the number of data repetitions required for UE \(d^{\prime}\) using unit type \(u^{\prime}\) and modulation \(m^{\prime}\). If it is satisfied, the index \(h\) of the resource assignment is incremented by 1, and we record the last subframe position \(\tau_{d^{\prime}}\) of UE \(d^{\prime}\). \(\tau_{d^{\prime}}\) will be used for the NSF-Adjustment() function to increase the subframe utilization by adjusting the allocated \(I_{d^{\prime}}^{h}\) units of UE \(d^{\prime}\). If this subframe does not have sufficient subcarriers for the UE, this function breaks the while loop (Lines 13-14). ```
1 FunctionSubframe-Allocation(\(t_{i^{\prime}}^{c^{\prime}}\), \(d^{\prime}\), \(u^{\prime}\), \(m^{\prime}\)):\(\sigma=-1\), \(\phi=0\), and \(h=0\)while\(\eta(I_{d^{\prime}}^{h},m^{\prime})<\psi_{d^{\prime}}\) and \(h<H\)do
2\(\sigma=\sigma+1\)if\(t_{i^{\prime}}^{c^{\prime}}+\sigma>L+R_{max}/R+\min(k_{0}^{i})+1\)then
3 break the **while** loop
4 elseif\(t_{i^{\prime}}^{c^{\prime}}+\sigma>\Gamma\)then
5 continue
6 if\(S_{P}^{c^{\prime}+\sigma}+\tau_{P}^{c^{\prime}+\sigma}+f_{u^{\prime}}^{c^{ \prime}}\leq F\)then
7\(\phi=\phi+1\)if\(\phi=I^{(h+1)}\cdot t_{u^{\prime}}\cdot N_{d^{\prime}}^{u^{\prime},m^{ \prime}}\)then
8\(h=h+1\) and \(\tau_{d^{\prime}}=\phi\)
9 else
10 break the **while** loop
11 return\(I_{d^{\prime}}^{h}\), \(\tau_{d^{\prime}}\)
```  
**Algorithm 3**Subframe-Allocation  
The NSF-Adjustment() function Algorithm 4 determines whether freeing up an occupied NPUSCH start subframe of UE \(d^{\prime}\) by subtracting one resource unit to release more usable subframes to serve other UEs. In Line 2, \(\xi\), initialized as 0, is the number of subframes that NPRACHs fully occupy. In Line 3, if the last subframe \(\tau_{d^{\prime}}\) allocated to UE \(d^{\prime}\) exactly is an NPUSCH start subframe and index \(h\) of the resource assignment for UE \(d^{\prime}\) is larger than 1, we calculate the number of usable subframes when the NPUSCH start subframe is vacated in Lines 4-11. Because this paper considers cross-NP resource allocation, \(\tau_{End}\) is the last allocable subframe of this NP, which can cross over the length \(L\) of this NP (Line 4). In Lines 5-11, we view each subframe to count the number of usable subframes from NPUSCH start subframe \(\tau_{d^{\prime}}\) to the last allocable subframe. For each subframe \(x\), if NPRACHs fully occupy the subframe, \(\xi\) is increased by 1, and we go to check the next subframe (Lines 6-8). If the available subcarriers of the subframe are all allocated to UEs or the subframe is another NPUSCH start subframe, the last allocable subframe is updated as the current subframe \(x\), and we break the for loop (Lines 9-11).