## 3 Beam Allocation Algorithm Based on MAPPO and Stackelberg Game
### Beam Allocation Algorithm Based on MAPPO
The joint power allocation of I2V and V2V has a high degree of coupling, so we propose a method based on Stackelberg game to transform the joint power allocation problem into two suboptimal power allocation problems, thereby simplifying the solution of the original problem. In this section, we consider the I2V link as the leader in the game and the V2V link as the follower. For simplicity, this section assumes perfect channel state information is available. The leader aims to maximize the total achievable rate of I2V, while the follower aims to maximize the total energy efficiency and sensing rate of V2V, establishing a competitive relationship between them. The power allocation problem for the leader can be written as

\[\underset{p_{m,n},\forall m\in M}{\text{maximize}} R_{n}^{R}-\sum_{n}\sum_{k}p_{m,n}h_{R,k}\psi_{m,k}\] (18) s.t. \[p_{m,n}\leq p_{\max}^{R},\forall m\in M, \tag{18a}\]

where \(h_{R,k}\) represents the channel gain from the RSU to vehicle \(k\). Although a larger \(p_{m,n}\) increases \(R_{n}^{R}\), it also causes more severe interference to V2V. Therefore, the first part of the objective function represents the total achievable rate of IZV, i.e., the utility function; the second part of the objective function represents the interference level of IZV to V2V, i.e., the cost function. By observing, it can be found that the objective function is concave with respect to \(p_{m,n}\). Therefore, its partial derivative can be set to zero to obtain \(p_{m,n}^{*}\):

\[p_{m,n}^{*}=\max\biggl{\{}0,\min\biggl{\{}\frac{\mathcal{A}-\mathcal{B}}{ \mathcal{A}\mathcal{B}},p_{\max}^{R}\biggr{\}}\biggr{\}}, \tag{19}\]

where \(\mathcal{A}=\frac{h_{K,n}}{\sigma_{k}^{2}+\sum\limits_{k^{\prime}}h_{k,m}p_{ k^{\prime},n}\hat{\psi}_{k,n}}\), \(B=\sum\limits_{k}h_{k,k}\hat{\psi}_{m,k}\); \(h_{K,m},h_{k,m}\) represent the channel gains from the RSU and vehicle \(k\) to vehicle \(m\), respectively. Since the joint power optimization is performed in two stages, the follower's power, i.e., the V2V transmit power, can be considered constant when solving the leader's power allocation problem. Similarly, when solving the follower's power allocation problem, the leader's power, i.e., the IZV transmit power, can be considered constant. The power allocation problem for the follower can be written as

\[\underset{p_{k^{\prime},n^{\prime}}}{\text{maximize}} \sum_{k}\Big{(}E_{k,n}+R_{k,n}^{r}\Big{)}-\sum\limits_{m}\sum\limits_ {k}\sum\limits_{k^{\prime}}p_{k^{\prime},n}h_{k,m}\hat{\psi}_{k,m}\] (20) s.t. \[r_{n}=\sum_{k=1}^{K}\left(w_{c}E_{k,n}+w_{r}R_{k,n}^{r}\right)+w_{R}R_{n}^{R}, \tag{14}\]0 \[r_{n}=\sum_{k=1}^{K}\left(w_{c}E_{k,n}+w_{r}R_{k,n}^{r}\right)+w_{R}R_{n}^{R}, \tag{14}\]1

The first part of the objective function represents the total energy efficiency and sensing rate of V2V, i.e., the utility function; the second part of the objective function represents the interference level of V2V to IZV, i.e., the cost function. Due to the total power constraint, we cannot simply use partial derivatives to obtain the optimal power. Therefore, we can use the CVX toolbox to solve this problem. However, the objective function in the problem is not concave with respect to \(p_{k^{\prime},n}\). Additionally, energy efficiency is a fractional optimization problem, so we need to transform it into a more convenient form for solving. Firstly, the Dinkelbach algorithm is employed to transform the fractional form of energy efficiency into a linear form of numerator minus \(\lambda\) times the denominator. Then, an iterative method is used to solve the problem. The algorithm begins with an initial value \(\lambda_{k^{\prime}}(0)\), and in each iteration, the optimal solution \(p_{k^{\prime},n}^{*}(j)\) is obtained, which is then used to update \(\lambda_{k^{\prime}}(j)=R_{k^{\prime},n}^{c}/p_{k^{\prime},n}^{*}(j)\).