# Joint Power Allocation and Link Selection for Multi-Carrier Buffer Aided Relay Network
## 3 Proposed Solution  
The optimization problem formulated in previous section can easily be called a mixed integer optimization problem, and it is difficult to solve. For tractability of solution, we chose a decomposition approach to maximize the average throughput at \(MU\) in \(T\) time slots. At first, we found different link selection strategies for the given power allocation. Let, \(P_{i,t}^{BS*}\) and \(P_{i,t}^{R_{b}*}\) represent optimal powers at source and relay nodes for the corresponding maximum rates \(R_{i,t}^{1*}\) and \(R_{i,t}^{2*}\), respectively. Thus, our problem was reduced to selecting the link such that maximum throughput was obtained, which was:\[\max_{a_{t}} \lim_{T\to\infty}\frac{1}{T}\sum_{t=1}^{T}\sum_{i=1}^{N}(1-\alpha_{t })R_{i,t}^{2*}\] (10) s.t. \[\lim_{T\to\infty}\frac{1}{T}\sum_{t=1}^{T}\sum_{i=1}^{N}(\alpha_{t })R_{i,t}^{1*}\geq\] \[\lim_{T\to\infty}\frac{1}{T}\sum_{t=1}^{T}\sum_{i=1}^{N}(1-\alpha _{t})R_{i,t}^{2*}\] \[\alpha_{t}(1-\alpha_{t})=0.\]  
For \(\overline{A}\) to be the amount of data present in the queue of the buffer before the start of communication between \(BS\) and \(MU\), the following two cases can be considered in order to solve the problem. _Case_ 1: (\(\sum_{i=1}^{N}\sum_{t=1}^{T}R_{i,t}^{2*}\leq\overline{A}\)):  
The solution to the problem (10) becomes;  
\[\alpha_{t}=0,\qquad\forall t,\]  
and from (4) we get,  
\[P_{i,t}^{BS*}= 0,\] \[P_{i,t}^{R_{b}*}= \arg\quad\max_{P_{i,t}^{R_{b}}}\ \sum_{t=1}^{T}\sum_{i=1}^{N}(1-\alpha_{t })R_{i,t}^{2}\] (11) s.t. \[\sum_{i=1}^{N}P_{i,t}^{R_{b}}\leq P_{T}^{R_{b}},\quad\forall t.\]  
The necessary and sufficient conditions associated with problem (11) are given by:  
\[\frac{\partial L(P_{i,t}^{R_{b}*},\lambda_{t})}{\partial P_{i,t}^{ R_{b}*}}=0, \tag{12}\] \[\lambda_{t}\left(P_{T}^{R_{b}}-\sum_{i=1}^{N}P_{i,t}^{R_{b}*} \right)=0,\quad\forall t,\] \[\lim_{T\to\infty}\frac{1}{T}\sum_{t=1}^{T}\sum_{i=1}^{N}(\alpha_{t })R_{i,t}^{1*}\geq\]0  
when \(P_{i,t}^{R_{b}*}\) is the optimal value that maximizes the objective function in (11), and \(L(P_{i,t}^{R_{b}*},\lambda_{t})\) is the Lagrangian of the problem, written as:  
\[\lim_{T\to\infty}\frac{1}{T}\sum_{t=1}^{T}\sum_{i=1}^{N}(\alpha_{t })R_{i,t}^{1*}\geq\]1  
here \(\lambda_{t}\) is called the Lagrangian multiplier of the problem. Applying the necessary and sufficient conditions given in (12) the optimal value of \(P_{i,t}^{R_{b}*}\) can be expressed as:  
\[\lim_{T\to\infty}\frac{1}{T}\sum_{t=1}^{T}\sum_{i=1}^{N}(\alpha_{t })R_{i,t}^{1*}\geq\]2the structure of (13) is similar to the water filling solution [29], with, \(\frac{1}{\lambda_{t}}\) as the maximum power stream or water level. In our work, the water level was optimized using the sub-gradient method, where, in each iteration the value of \(\lambda_{t}\) was updated by:  
\[\lim_{T\to\infty}\frac{1}{T}\sum_{t=1}^{T}\sum_{i=1}^{N}(\alpha_{t })R_{i,t}^{1*}\geq\]3  
where, \(itr\) and \(\psi\) represent the iteration number and step size, respectively. _Case 2_: (\(\sum_{i=1}^{N}\sum_{t=1}^{T}R_{i,t}^{2*}>\overline{A}\)):  
The solution required to put some \(\alpha_{t}=1\) (or \([1-\alpha_{t}]=0\)). To keep \(R_{i,t}^{2*}\) at maximum possible level, the link between \(BS\) and \(R_{b}\) was selected for the time slots \(t^{*}\) such that the difference between the rates of first and second hops at that slot, denoted as \(\sum_{i=1}^{N}R_{i,t}^{3}\) is also maximum. After each selection, the sum rate \(\sum_{i=1}^{N}\sum_{t=1}^{T}R_{i,t}^{1*}\) will start to increase and in contrast, \(\sum_{i=1}^{N}\sum_{t=1}^{T}R_{i,t}^{2*}\) will gradually decrease. This process will continue to repeat until \(\sum_{i=1}^{N}\sum_{t=1}^{T}R_{i,t}^{2*}\approx\sum_{i=1}^{N}\sum_{t=1}^{T}R_{ i,t}^{1*}+\overline{A}\). Step wise description of our designed algorithm is elaborated in Algorithm 1. ```
1:Initialize \(\overline{A}\). 2:Let \(\sum_{i=1}^{N}R_{i,t}^{3}=\sum_{i=1}^{N}R_{i,t}^{1*}-\sum_{i=1}^{N}R_{i,t}^{2*}\quad \forall t\). 3:Select \(t^{*}=\arg\max_{i=1}^{N}R_{i,t}^{3}\).