# Optimal Data Collection Time in LoRa Networks--A Time-Slotted Approach
## 5 The Optimal Data Scheduling Problem
The end of the frame occurs at time \(j+\tau+T_{f}\) because the last transmission starts at \(j+\tau\) and lasts for \(T_{f}\) amount of time. To determine which slot is the last one used, we need to multiply \(j+\tau+T_{f}\) with the sum over all variables \(y^{i}_{t^{f}_{j}}\). Indeed, there can be only one node using a slot, so this sum is either 0 (the slot is not used) or 1 (the slot is used by one node). Thus, the result of \(\max_{f\in F,\ t^{f}_{j}\in\mathcal{T}_{f}}(j+\tau+T_{f})\sum_{i}y^{i}_{t^{f}_{ j}}\) gives the time \((j+\tau+T_{f})\) of the longest frame. To get a linear equation removing the maximum function, we add the following set of constraints:  
\[(j+\tau+T_{f})\sum_{i}y^{i}_{t^{f}_{j}}\leq\zeta,\ \forall f\in F,t^{f}_{j} \in\mathcal{T}_{f}, \tag{11}\]  
where \(\zeta\) is a continuous variable whose purpose is to keep track of the maximum frame length, which is what we want to minimise in our problem. Summarising, Equation (7) verifies that at most one node can use a slot. Equation (8) forbids a node to use non-permitted SFs. Equation (9) ensures that all nodes get to send their total amount of data. Finally, Equation (10) verifies the duty cycle restrictions using sets \(\chi_{t^{f}_{j}}\) defined above. This last constraint can be eliminated in the case of LoRa operating in the 2.4 GHz ISM band where no radio duty cycle restrictions exist [35]. The hardness of the model stems from the fact that a very large range of slots for all 6 SFs (or 8 for 2.4 GHz LoRa) is evaluated for each possible transmission. This results in a very long sequence of possible iterations. The problem can be alleviated by setting a maximum frame length \(\Gamma\) per SF which is translated to a maximum number of slots to be evaluated. However, we need to define how this value is chosen. For example, allowing too many slots in each frame increases dramatically the number of binary variables of our model (recall that there is a single \(y\) variable per node and per slot). On the contrary,if we do not reserve enough slots for each SF, especially for SF7 which is the most utilised spreading factor, the linear program can still find a solution with the given slots. In this case, the schedule will be optimal only for the given settings but not globally optimal. Since most of the transmissions are accommodated in the SF7 frame, the value of \(\Gamma\) is selected through a trial and error method so that the frame of SF7 is large enough to find the optimal schedule. Nevertheless, the linear program still requires to test a high number of variables per transmission, upper-bounded by \(N\Gamma|F|\), which may limit the practicality of the computational solution to low node numbers only. For deployments with many nodes, time-efficient heuristics such as the _Light_ and _Global_ heuristics presented in [11] can be used. The two heuristics differ in the way they handle transmissions and how they divide the schedule into frames. The first algorithm, _Light_, schedules only the first transmission for each node and repeats that in subsequent frames. The second approach, _Global_, computes the schedule for all transmissions and, as a consequence, produces a sequence of frames that may differ to each other. As a result, _Global_ can compute more efficient schedules than _Light_ in terms of data collection time, however, this comes at the expense of a higher computation cost, a larger schedule size, and a higher implementation complexity.