## 4 The Model of Packet Size Adaptation Using Bounded Multi-Armed Bandits
### Packet Size Adaptation  
The nature of the wireless channel is time-varying. It is very inefficient when a fixed frame size is used. As previously discussed, a variable frame size minimizes the error caused by the frame rate of a large data packet transmission through a bad channel quality. If the channel quality is better, a large packet size is sent. The variable frame size reduces the number of retransmissions, increases the goodput of the system and saves energy. The paper finds the optimal size by MAB according to the different channel quality. The frame size is a local optimum, because the number of users and channel quality change, making the network environment change too [41; 42; 43; 44]. In order to make use of multi-armed bandits to find the optimal frame size according to the channel quality, we need to develop exploration and exploitation. Our goal is to maximize the goodput of the networks. The channel goodput considered for developing exploration and exploitation which depends on the packet size, collision rate, and data rate, the delay of the protocol and the quality of the channel. The following equation gives the relationship between throughput and the frame size [3]:  
\[\rho=\frac{IR}{(\!(L\!+\!H_{\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\! T: average backoff time slots under a certain channel  
D: Distributed Inter-frame Spacing(DIFS)  
Perror: bit error probability in the case of known channel quality  
OACK: the overhead of the acknowledgment  
Oprotocol: the MAC and PHY protocol process delay overhead  
Firstly, from the PU behavior indicated in Equation (19), we find that the probability that the packet can successfully transmit is decreased as the packet size increases. The energy is wasted when the packet collides with PU packets. Secondly, if the packet size is reduced, the ratio of energy consumption in the data transmission slots of Figure 2 to the energy consumption in the access control slot is reduced, which also reduces the energy efficiency. There is a trade-off between the two conditions, and there may be exist an optimal packet size which leads to the best energy efficiency. Sensors could transmit as many packets as possible to improve energy efficiency during their lifetime. In this paper, the metric energy-per-bit(EPB) is used as denoting the ratio of the total energy consumption to the amount of data successfully transmitted. As introduced before, the protocol designed is to minimize the EPB for the network, not only based on an individual condition [45]:  
\[ \begin{split} P_{j}^{success}&=P(\text{idle for next L slots}\mid\text{idle in the initialslot})\\ &=(\text{l}-\text{p}_{j})^{L}\end{split}  \tag{19}\]  
Every frame needs to consider the adaptation of the packet size because both the PU behavior and sensor activity are time-varying. A CM is awakened and transmits an accessing request message when data needs to be sent. The CH begins to determine the packet size of the data transmission of the current frame according to the sensor activity and the PU behavior when it receives the access request from the CMs. The total energy consumption in the network includes:  
* The energy consumed by the access control slot, which includes transmitted access request packets and the broadcast of access reply packets received. * The energy consumed of the data transmission slots. In this work, the star topology is used between each CM and the CH which has an equal distance d. The size of the access request packet is K1 bits. The size of the access reply packet is K2 bits. In the access control slot, the energy consumption of the whole network is as follows:  
\[E^{control}=(E_{cur}+\varepsilon d^{2})\times K_{1}+E_{cur}\times K_{2} \tag{20}\]  
Data packet transmission refers to the frame structure in Figure 6. A complete data transmission occupies L slots. Eg: the CM i tries to transmit a packet whose length is L slots using channel j. The energy consumption is \(E^{cur}(\text{L})\). Let P\({}_{j}(\text{l})\) denote the transmission probability of the collision between the CM and PU.