# Simulated Annealing for Resource Allocation in Downlink NOMA Systems in 5G Networks
## 3 Simulated Annealing Based Resource Allocation
### SA for User Pairing  
The SA algorithm performed the user pairing scheme when the system mode \(\mu=1\). In this system, the SA algorithm started with two different configurations, such as hot and cold configurations, based on the channel's gain difference. This considers that subchannels are accessible by all users. This assumption addresses the impact of the channel gain difference on the user pairing scheme and the throughput performance [16]. Furthermore, the user pairing scheme exploits the channel gain difference for the multiplexed users, which should be investigated to guarantee the minimum target data rate for the user with the weakest channel gain. The hot configuration started the initial design by randomly multiplexing the user with high channel gain with the user with low channel gain on the same subchannel as the current best solution. The cold configuration established the initial design by matching the users randomly based on descending order of channel gain on the same subchannel as a current best solution [16]. The users and subchannels matching scheme are performed in the cold configuration, enabling the search to start based on both users' good channel gain conditions [16]. The average channel gain for each subchannel is employed in the cold configuration as calculated in (12):  
\[G_{Av}=\frac{\sum_{i=1}^{U}G_{i,n}}{U} \tag{12}\]where \(U\) is the total number of users accessing the particular subchannel and \(G_{i,n}\) is the channel gain corresponding to the users. 1. Set the number of iterations \(j\in\{1,2,\ldots,J_{Max}\}\), the initial temperature T = 100:
2. Initialize the users set and subchannel set. 3. Estimate the channel gain \(G\in\left\|\hat{g}_{Max}\right\|_{U\times N}\). 4. Initialize the \(U_{Unsaligned}\) and \(N_{Unsaligned}\) in the system. 5. Pair two users on the same subchannel according to **Hot Config** as current Best Solution \(C_{B}\) Pair two users on the same subchannel according to **Cold Config** as current Best Solution \(C_{B}\). 6. _Calculate_ Throughput function of the Initial design \(f_{C_{B}}\) :
7. System Mode \(f\
eq h=1\). 8. **Choose** two random subchannels \(1:N_{c}\) while fixing the initial values of \(a_{n}\) and \(\delta_{n}\). 9. **Exchange** the users with high channel gain for both selected subchannels. 10. **Check if** the Second selected subchannel is still giving high channel gain to the shifted user. 11. _If yes_; exchange the two users with high channel gain. 12. _If no_; check the user with low channel gain to exchange. 13. Check the low channel gain user \(Unsaligned_{n}<G_{Av}\); then exchange the users. 14. _If no_; check a different subchannel. 15. When Users and Subchannels are matched, denote the new configuration \(C_{A}\). 16. **Calculate** the Throughput function after \(f_{C_{A}}\) :
17. **If \(f_{C_{A}}<f_{C_{B}}\)**; accept the configuration. 18. **Else \(f_{C_{A}}>f_{C_{B}}\)**; Calculate: \(\Delta f=f_{b}-f_{a}\); Generate random number of \(\epsilon\in(0,1)\)
19. **If \(\epsilon<e^{-\frac{A}{2}}\)**; then accept the new solution Throughput function \(f_{C_{A}}\). 20. **Reduce** the temperature (\(T_{j}=T_{j-1}-\alpha\bar{T}_{j-1}\)). 21. Accept the solution. 22. End the Algorithm. The SA started the search with the initial configuration, where the user pairing condition is used to guarantee the SIC optimality. Each configuration is practically tested for random power allocation and equal power allocation. The scenarios are adopted to ensure the practicality of the channel's gain difference in improving the system's throughput. The users and subchannel matching scheme is performed according to the two configurations where the channel gain threshold is set for the cold configuration and the channel gain condition for the hot configuration. The initial design started with a random user pairing according to the proposed initial configurations as the current best solution for the objective function, then two random channels are chosen to exchange the users according to the channel gain condition.