# A Hierarchical Resource Allocation Scheme Based on Nash Bargaining Game in VANET
## 2 Hierarchical Resource Allocation Scheme Based on Nash Bargaining Game
### The Formulation of Hierarchical Resource Allocation Scheme in VANET
#### 2.2.2 Resources Allocation for VUEs in the Second Layer
\begin{array}{ll}(1)&\partial L(p,\theta)/\partial p_{i,j}=0,\\ (2)&\theta_{i}(\sum\limits_{j=1}^{C^{k}}p_{i,j}-P^{max})=0\\ (3)&\theta_{i}\geq 0.\end{array} \right. \tag{18}\]  
Then, we can obtain the optimal transmission power \(p_{i,j}^{*}\) for VUE \(i\) on subchannel \(j\), which is given as  
\[p_{i,j}^{*}=\left[\frac{\alpha_{i}^{k}}{C^{k}}\left(\sum\limits_{j=1}^{C^{k}} \frac{1}{\eta\cdot h_{i,j}}+P^{max}\right)-\frac{1}{\eta\cdot h_{i,j}}\right]^ {+} \tag{19}\]  
where \(x^{+}=max(0,x)\). According to the value of the optimal transmission power \(p_{i,j}^{*}\), we can get the optimal transmission rate  
\[r_{i}^{*}=\alpha_{i}^{k}\sum\limits_{j=1}^{C_{k}}\omega_{k}^{0}\text{log}_{2 }(1+\eta\cdot p_{i,j}^{*}h_{i,j}) \tag{20}\]  
Then, the sub-problems of optimal time allocation can be formulated as  
\[ \begin{array}{ll}\max\limits_{\tau_{i}^{k}}&\prod\limits_{i=1}^{N_{k}}\left( \tau_{i}^{k}\cdot\alpha_{i}^{k}\sum\limits_{j=1}^{C^{k}}\omega_{k}^{0}\text{ log}_{2}(1+\eta\cdot p_{i,j}^{*}h_{i,j})-r_{i}^{min}\right)\\ s.t.&C15:\sum\limits_{i=1}^{N_{k}}\tau_{i}\leq 1\end{array}  \tag{21}\]  
The Lagrange function is formulated as  
\[L(\mathbf{\tau},\
u)=\sum\limits_{i=1}^{N_{k}}\text{ln}\left(\tau_{i}\cdot\alpha_{ i}^{k}\sum\limits_{j=1}^{C^{k}}\omega_{k}^{0}\text{log}_{2}(1+\eta\cdot p_{i,j}^{* }h_{i,j})-r_{i}^{\text{min}}\right)-\
u(\sum\limits_{i=1}^{N_{k}}\tau_{i}-1) \tag{22}\]  
\(\mathbf{\tau}=(\tau_{1}^{k},\tau_{2}^{k},...,\tau_{N_{k}}^{k})\) is the time vector allocated to VUEs. \(\
u\) is the lagrangian multiplier. According to KKT conditions, the following conditions must be satisfied  
\[\left\{ \begin{array}{ll}(1)&\partial L(\tau,\
u)/\partial\tau_{i}^{k}=0\\ (2)&\
u(\sum\limits_{i=1}^{N_{k}}\tau_{i}^{k}-1)=0\\ (3)&\
u\geq 0\end{array} \right. \tag{23}\]  
and then, the optimal transmission time allocation for the \(i\)th VUE in the \(k\)th RSU is obtained  
\[\tau_{i,k}^{*}=\frac{1}{N_{k}}\left(1-\sum\limits_{i=1}^{N_{k}}\frac{r_{i}^{ min}}{r_{i}^{*}}\right)+\frac{r_{i}^{\text{min}}}{r_{i}^{*}} \tag{24}\]  
Thus, we present the algorithm in Algorithm 1. In Algorithm 1, we firstly calculate the spectrum resources obtained by the \(k\)th RSU. Then, we obtain the power resource and time slot resource of the VUE \(i\) in the \(k\)th RSU. Therefore, the time complexity of Algorithm 1 is \(O(N^{2})\). ```
0: total spectrum resources \(B^{sum}\), the parameters of RSU \(\bar{\eta}_{k}\), \(\bar{P}_{k}\), \(\bar{G}_{k}\), \(R_{k}^{min}\), subchannel bandwidth \(\omega_{k}^{0}\), VUE's minimum transmission rate requirement \(r_{i}^{min}\). 0:\(b_{k}^{*}\), \(p_{i,j}^{*}\), \(\tau_{i,k}^{*}\). 1:for\(k\in K\)do
2: Calculated \(b_{k}^{*}\), which is the optimal spectrum resources allocated for the \(k\)th RSU based on Equation (9). 3:for\(i\in N\)do
4: Calculated \(\alpha_{i}^{k}\), which is the matching degree between the \(i\)th VUE and the \(k\)th RSU. 5: According to the allocated spectrum resources \(b_{k}^{*}\), calculated \(C^{k}\) based on Equation (10), which is the number of subchannel allocated to the \(k\)th RSU. 6: Calculated \(p_{i,j}^{*}\) based on Equation (19), which is the optimal transmission power for VUE \(i\) on the subchannel \(j\). 7: Calculated \(\tau_{i,k}^{*}\) based on Equation (23), which is the optimal transmission time allocation for the \(i\)th VUE in the \(k\)th RSU. 8:endfor
9:endfor
10:return\(b_{k}^{*}\), \(p_{i,j}^{*}\), \(\tau_{i,k}^{*}\)
```  
**Algorithm 1** Hierarchical Resource allocation based on Nash bargaining game