# Real-Time Station Grouping under Dynamic Traffic for IEEE 802.11 ah
## 4 Real-Time RAW Parameter Optimization
### RAW Slot Assignment  
The second main step of TAROA determines the set of RAW slots \(\mathcal{R}^{b}\) to initialize in the next beacon interval \(b\), as well as for each of the RAW slots their duration \(t^{r}\), and the assigned stations \(\mathcal{S}^{r}\). These RAW parameters are selected based on the previously determined estimation of the transmission interval \(t^{s}_{int}\) and next transmission time \(t^{s}_{next}\). As shown in Algorithm 2, this is a two-step process: (i) select a subset of stations with pending packets to be assigned to a RAW slot during the upcoming beacon interval (lines 2-8); and (ii) partition the selected stations among the available number of RAW slots and determine the slot duration (lines 9-14).  
In the first part (lines 2-8), the algorithm iterates over all stations \(s\), according to ascending last successful transmission time \(t^{s}_{succ}\left[0\right]\) (i.e., \(\mathcal{S}_{queue}\)) until the next station has a next estimated transmission time greater than the current time (i.e., \(t^{s}_{next}>t_{c}\)) or the maximum allowed number of packet transmissions has been reached (i.e., \(\pi^{b}\geq\pi^{b}_{max}\)) (line 2). The station is first added to the set of stations allowed to transmit during the beacon interval \(\mathcal{S}^{b}\) (line 3). Then, if the station is estimated to transmit more than one packet per beacon interval (i.e., \(t^{s}_{int}<1\)) and its estimated number of transmissions will exceed the maximum packet transmissions in \(b\) (line 4), then it is allowed to transmit part of its packets and its estimated transmission interval is updated accordingly (line 5). Otherwise, the station is expected to be able to transmit all of its packets and \(\pi^{b}\) is increased with the number of packets \(s\) is estimated to transmit in the beacon interval (line 8).  
At this point, it should be noted that all slots within a RAW group have the same duration and only stations with sequential AID can be assigned to the same group. Moreover, the optimal duration of a slot depends on the number of stations assigned to it, as well as their data rates, number of queued packets, and packet payload sizes. As such, for simplicity, we assume throughout the remainder of this paper that each RAW group has exactly one slot, allowing all slots to have a different size. Overcoming this problem is possible by selecting a worst-case slot duration (suboptimal) or performing dynamic AID reassignment. The latter is expected to increase optimality, but falls outside the scope of this paper.  
In the second part (lines 9-14), stations are assigned to RAW slots \(r\in\mathcal{R}^{b}\) according to increasing AID (as only sequential AID can be assigned to the same group) until the number of stations assigned to the slot are greater or equal to the optimal number of assigned stations (i.e., \(|\mathcal{S}^{r}|>\sigma^{r}_{opt}\)) (line 10). How to calculate this optimum is explained in more detail in Section 5. The number of packets to be transmitted by \(s\) is added to the expected number of packet transmissions in \(r\) (line 13). Finally, the optimal duration \(t^{r}\) of the slot is determined based on the number of expected packet transmission \(\pi^{r}\) (line 14).