1.

Initialization: Randomly distribute CUEs and D2D pairs in a cell and calculate their distances to the center of the BS. Determine the value of r
_{0} between 0 and the radius of the cell

2.

Divide users into four groups according to r
_{0}, A_{CUE}, A_{D2D}, B_{CUE}, and B_{D2D}

3.

In area A or B, users randomly constitute clusters (the clustering in area B must satisfy the distance criterion), and each cluster consists of two CUE users and two D2D pairs

4.

For each RB

5.

Randomly choose a cluster in the cell and determine whether it is in area A or B

6.

Calculate the largescale loss in this cluster

7.

Case user to BS: 128.1 + 37.6 * log
_{10}(d[km])

8.

Case user to user: 148 + 40 * log
_{10}(d[km])

9.

Set the initial transmit power according to area A or B: P
_{
C1}, P
_{
C2}, P
_{
D1}, P
_{
D2}

10.

Do

11.

For each subcarrier (SC)

12.

Generate smallscale loss H: multiplex Gaussian with zero mean unit variance

13.

If cluster in area A

14.

Interference Alignment  Equations (20)(26), (42)(47)

15.

Else cluster in area B

16.

Multiplex Scheme  Equations (1)(16)

17.

End if

18.

End SC

19.

Calculate SINR in this RB: Equations (27) to (30) for IA

20.

Equations (17) and (18)for Multiplex;

21.

While SINR does not meet the target, Power Control, then jump 10

22.

End each RB

23.

Calculate sum throughput
