## 2 System Model and Problem Formulation  
### System Model  
In this paper, a single-cell cellular network-assisted D2D communication is considered, where an IRS is employed to elevate the link quality when a D2D user uses the cellular spectrum in an underlay manner. Please note that the IRS is not needed for direct D2D communication, which is of short range and the IRS is also not needed for communication between cellular users, as it happens through the BS. As shown in Figure 1, the basic system consists of one base station (BS), one IRS (more IRS units will be added as needed at locations that will provide best coverage to every user), a number of CUs, and a number of D2D pairs. The BS, CUs, and D2D pairs are equipped with a single antenna, while the IRS has \(N\) (\(N>1\)) reflecting elements. A controller is attached to the IRS to control the reflection coefficients of each element. Note that we assume each reflecting element acts as an independent unit; therefore, one IRS can handle \(N\) user pairs. In this system, \(K\) CUs coexist with \(M\) D2D pairs, and the D2D pairs share the downlink stream of the cellular network. Orthogonal frequency division multiple access (OFDMA) is used for the multiple access technique for both the CUs and D2D pairs, where resource blocks are employed for the spectrum allocation. In order to tackle the interference, it is assumed that the spectrum of a CU can be shared by at most one D2D pair, and a D2D pair can share at most one CU's resource. Let \(\mathcal{K}\) be the set for CUs, where \(\mathcal{K}=\{1,2,\ldots,K\}\), \(\mathcal{M}\) is the set for D2D pairs, and where \(\mathcal{M}=\{1,2,\ldots,M\}\) and \(\mathcal{N}\) are the set for IRS reflecting elements, where \(\mathcal{N}=\{1,2,\ldots,N\}\). We denote the \(k^{th}\) CU in the system by \(C_{k}\), where \(k\ \in\ \mathcal{K}\), and the \(m^{th}\) D2D pair by \(D_{m}\), where \(m\ \in\ \mathcal{M}\). The transmitter and the receiver of the D2D pair \(D_{m}\) are represented by \(D_{m}^{t}\) and \(D_{m}^{r}\), respectively. The channel model for all links in this system is considered quasi-static flat-fading. Let \(g_{b,i}\in\mathbb{C}^{N\times 1}\) be the channel gain of the cellular link from the BS to the IRS, \(g_{i,c}\in\mathbb{C}^{1\times N}\) be the channel gain from the IRS to CU \(C_{k}\), and \(g_{b,c}\in\mathbb{C}\) be the channel gain from the BS to CU \(C_{k}\). On the other hand, the channel gain of the D2D link from D2D transmitter \(D_{m}^{t}\) to the IRS is denoted as \(\mathbf{h}_{t,i}\in\mathbb{C}^{N\times 1}\), the channel gain from the IRS to D2D receiver \(D_{m}^{r}\) is denoted as \(\mathbf{h}_{r,i}\in\mathbb{C}^{1\times N}\), and the channel gain from D2D transmitter \(D_{m}^{t}\) to D2D receiver \(D_{m}^{r}\) is denoted as \(h_{t,r}\in\mathbb{C}\). Let \(u_{t,c}\in\mathbb{C}\) be the interference link from D2D transmitter \(D_{m}^{t}\) to CU \(C_{k}\) and \(v_{b,r}\in\mathbb{C}\) be the interference link from the BS to D2D receiver \(D_{m}^{r}\). Let \(\mathbf{\Phi}\triangleq\text{diag }[\Phi_{1},\Phi_{2},\ldots,\Phi_{N}]\in \mathbb{C}^{N\times N}\) be the reflection coefficient matrix at the IRS, where \(\Phi_{n}=\alpha_{n}e^{\beta_{n}}\) represents an amplitude coefficient \(\alpha_{n}\in(0,1]\) and a phase shift  
Figure 1: An IRS-assisted D2D underlay communication network. coefficient \(\theta_{n}\in(0,2\pi]\). Here, \(\alpha_{n}=1,\forall n\in\mathcal{N}\) is considered to achieve a maximum signal reflection.