## 3 Resource Allocation Problem
### PSO for Power Allocation  
PSO is an algorithm based on natural organisms that are seeking habitats with sufficient food, such as birds and fish. PSO is known as an agent-based algorithm because it uses multiple agents or particles [18; 19]. The implementation of PSO is considerably simpler than those of the genetic algorithm (GA) and the ant colony algorithm (ACO), which share some similarities with PSO's optimisation techniques. PSO works on the basis of the real-number randomness and global communication between swarm particles rather than the mutations, crossover operators or pheromones used in GA and ACO. In the current work, the PSO algorithm is proposed to obtain the optimal power solution in a NOMA system based on the objective function (8).  
In particular, the velocity and position of each particle are adjusted in accordance with the group information. In PSO, the number of particles (\(Q_{P}\)) is predefined. \(X_{i}\) is the position and \(V_{i}\) is the velocity of each particle. The dimension \(D_{S}\) is the search space for potential solutions to the optimisation problem. The quality of the solution is evaluated iteratively for each particle through an objective function. The personal best of a particle is \(P_{best\ i}\) for the obtained objective function value, which is compared with the global best value as \(G_{best}\).  
Consequently, the position and velocity of each particle are modified along each dimension. The position and velocity are coupled dynamics of a PSO particle. The velocity dynamics are influenced by inertia and cognitive and social components, and these, in turn, influence the position dynamic of PSO. Position and velocity dynamics are mathematically described as follows:  
\[V^{i}(t)=w(t)V^{i}(t-1)+r_{1}c_{1}(t)\Big{(}X^{i}_{pbest}(t)-X^{i}(t-1)\Big{)} +r_{2}c_{2}(t)\Big{(}X_{gbest}(t)-X^{i}(t-1)\Big{)}, \tag{27}\]  
\[X^{i}(t)=X^{i}(t-1)+V^{i}(t), \tag{28}\]  
The optimisation problem is non-convex with respect to variables \(\delta\) and \(P\) for the NOMA system. Therefore, PSO is utilised to obtain the optimal solution as a global optimisation scheme. Let \(X^{i}(t)\) be the position vector of a PSO particle \(i\) in iteration \(t\), where \(X^{i}(t)\) contains the optimisation variables, as shown below.  
\[X^{i}(t)=\bigg{[}\begin{array}{c}\delta^{i}(t)\\ P^{i}(t)\end{array}\bigg{]}. \tag{32}\]  
The algorithm generates initial variable particles \(X^{i}(0)=\left[\delta^{i}(0)^{T}\ P^{i}(0)^{T}\right]^{T}\), where the subchannel power is \(P\) and \(\delta\) is the power ratio. The PSO parameters are set as follows: \(w_{max}\), \(w_{min}\), \(V_{max}\), \(c_{t,0}\), \(c_{t,t}\), and \(t_{max}\). Then, the objective function is evaluated for each particle as \(f\big{(}X^{i}(t)\big{)}\), \(where\ i=1,\ldots,N_{Particle}\). The possible solution is represented as the position of each particle. Each particle updates the best position \(X^{i}_{\textit{{pbest}}}(t)\) and then updates the best position amongst all particles \(X_{\textit{{gbest}}}(t)\). Subsequently, the inertia weight \(w(t)\) and the two acceleration factors \(c_{1}\) and \(c_{2}\) are updated. Consequently, the velocity and position of a particle are updated until the maximum iterations or the global best \(X^{i}_{\textit{{gbest}}}(t)\) is returned. This iterative algorithm continues until the optimal power allocation solution is found.