# An Optimal Online Resource Allocation Algorithm for Energy Harvesting Body Area Networks
## 4 Resource Allocation Algorithm
### Sub-Problem Solution  
\(D_{V}(t)\) is relevant to the set of variables \(Y(t)=(c(t),\,h(t),\,p(t))\), so we divide \(D_{V}(t)\) into three parts according to the \(Y(t)=(c(t),\,h(t),\,p(t))\). Each part is a sub-problem that needs to be optimized. These sub-problems are battery management, collecting rate control and transmission power allocation. The sub-problem of battery management optimizes the energy harvesting rate \(h_{n}(t)\), which requires information on the energy queue occupancy \(I_{n}(t)\) and energy supply rate \(e_{n}(t)\). The sub-problem of collecting rate control optimizes the collecting rate \(c_{n}(t)\), which requires information on the energy queue occupancy \(J_{n}(t)\) and data queue occupancy \(I_{n}(t)\). The sub-problem of transmission power allocation optimizes transmission power \(p_{n}(t)\), which requires information on the energy queue occupancy \(J_{n}(t)\), data queue occupancy \(I_{n}(t)\), and transmission rate \(r_{n}(t)\). In the following, we will solve the sub-problems separately. * Battery Management The sensor should harvest energy as much as possible for data collection and data transmission. The system is stable only if the energy in the system is sufficient enough. In this sub-problem, we need to optimize energy harvesting rate \(h_{n}(t)\). To keep the BAN system running, we should try to charge the battery of sensor \(n\) carried by patient as much as possible. For each sensor \(n\in N\), combining the first term of \(D_{V}(t)\) with the constraint Equation (9), we have the optimization problem of \(h_{n}(t)\) as follows: \[\min_{h_{n}(t)}-\widehat{J}_{n}(t)h_{n}(t),\] s.t. \[ \begin{cases}h_{n}(t)\leq e_{n}(t),\\ J_{n}(t)+h_{n}(t)\leq\Omega.\end{cases} \] The problem is linear of \(h_{n}(t)\). In time slot \(t\), we can get the value of energy queue occupancy \(J_{n}(t)\). Thus, minimize the optimization problem just to maximize the \(h_{n}(t)\) with the constraints. If the battery of sensor \(n\) carried by patient is full, \(\widehat{J}_{n}(t)\) equals 0, and we do not need to harvest energy, \(h_{n}(t)=0\). If the battery is not full, \(J_{n}(t)\leq\Omega\) and \(\widehat{J}_{n}(t)\geq 0\), we need to harvest energy as much as possible, \(h_{n}(t)=\min(\Omega-J_{n}(t),e_{n}(t))\). According to the above, we can get \[ \begin{cases}h_{n}(t)=\min(\Omega-J_{n}(t),e_{n}(t)),\ if\ \widehat{J}_{n}(t)\geq 0,\\ h_{n}(t)=0,\ else.\end{cases} \]
* Collecting Rate Control In this sub-problem, we consider data scheduling of sensor \(n\) carried by patient in BAN. We optimize the second part of \(D_{V}(t)\) while ensuring the constraint Equation (1). We have the optimization problem of \(c_{n}(t)\) as follows: \[\min_{c_{n}(t)}a\widehat{J}_{n}(t)c_{n}(t)+I_{n}(t)c_{n}(t)-VU(c_{n }(t)),\] s.t., \(0\leq c_{n}(t)\leq c^{max}\). In time slot \(t\), we can get the values of energy queue occupancy \(J_{n}(t)\) and data queue occupancy \(I_{n}(t)\). \(\alpha\) and \(V\) are constants. Thus, minimize the optimal problem just need to optimize the collection rate \(c_{n}(t)\). According to Section 3.1, we can get that the utility function \(U(c_{n}(t))\) is a concave function; thus, the problem is convex. According to the convex optimization, let the collecting rate \(c_{n}^{*}(t)\) be the unique optimal solution, and we can get: \[c_{n}^{*}(t)=[U^{\prime-1}(\frac{\widehat{J}_{n}(t)\alpha+I_{n}(t)}{V})]_{0}^{ \max}.\] (14)
* Transmission Power Allocation In this sub problem, we consider transmission power allocation of sensor \(n\) carried by the patient. We optimize the third part of \(D_{V}(t)\) to get the optimal transmission power. Combining the third term of \(D_{V}(t)\) with the constraint Equation (2), we have the optimization problem of \(p_{n}(t)\) as follows: \[\min_{p_{n}(t)}\widehat{J}_{n}(t)z_{n}(t)p_{n}(t)-I_{n}(t)z_{n}(t )r_{n}(t),\] s.t. \[ \begin{cases}0\leq p_{n}(t)\leq p^{max},\\ z_{n}(t)=1,if\ I_{n}(t)>L,\end{cases} \]where \(r_{n}(t)=\log(K\beta_{n}(t))\), \(\beta_{n}(t)=\frac{p_{n}(t)}{\sum_{i=1,i\
eq n}p_{i}(t)}\).