# Pilot Sequence Allocation Schemes in Massive MIMO Systems Using Heuristic Approaches
## 4 Proposed Solutions
### Binary Particle Swarm Optimization  
The BPSO was first described by [PERSON] and [PERSON] [23] and was an adaptation of the original (continuous) PSO. This algorithm works based on the behaviour of birds in search of foods, and the each candidate solution is presented as a bird in a flock flying through the search space (optimization problem domain), and the found represents the optimal solution. At each algorithm iteration, the velocity of each particle is updated through the equation:  
\[\mathbf{v}_{i}[t+1]=\omega\,\mathbf{v}_{i}[t]+c_{1}\,r_{1}\left(\mathbf{x}_{ i}[t]-\mathbf{p}_{i}\right)+c_{2}\,r_{2}\left(\mathbf{x}_{i}[t]-\mathbf{p}_{g}\right) \tag{16}\]  
where \(\omega\) is the inertia weight, \(\mathbf{v}_{i}\) is the candidate \(i\) velocity, \(\mathbf{x}_{i}\) is the particle position in the search space, \(\mathbf{p}_{i}\) is the best position candidate \(i\) has ever been to in terms of fitness function, and \(\mathbf{p}_{g}\) is the best position overall the whole population, i.e., the first keeps an individual best position record and the latter, a global best position record. The coefficients \(c_{1}\) and \(c_{2}\) are the cognitive and social acceleration constants, respectively, whilst \(r_{1}\) and \(r_{2}\) are uniformly distributed random numbers in the interval \([0,1]\). In a classical PSO algorithm, the next step would be updating each candidate position using its velocity. However, to implement a binary version, the change in each candidate dimensions must also be either zero or one. Therefore, a sigmoid function is applied to each velocity component, and it is equivalent to the probability of changing each bit. In this paper, we use the following sigmoid function in each dimension \(\mathbf{v}_{i}\):  
\[\mathcal{S}(v_{i}[t])=\frac{1}{1+e^{-v_{i}[t]}} \tag{17}\]  
The sigmoid function value is then compared to a random value generated to each dimension of the candidate \(\mathbf{x}_{i}\) such that:  
\[x_{i}[t+1]=\left\{ \begin{array}{ll}1&\text{if }r<\mathcal{S}(v_{i}[t])\\ 0&\text{otherwise}\end{array} \right. \tag{18}\]  
where \(r\sim\mathcal{U}(0,1)\), i.e., \(r\) is a random variable with uniform distribution over the interval \((0,1)\). Although the position possibilities are constrained to \(\{0,1\}\), particle velocity may grow indefinitely. Hence, a maximum velocity constraint may be applied to each dimension, i.e.,  
\[v_{i}[t+1]=\left\{ \begin{array}{ll}v_{\max}&\text{if }v_{i}[t+1]>v_{\max}\\ -v_{\max}&\text{if }v_{i}[t+1]<-v_{\max}\end{array} \right. \tag{19}\]  
Furthermore, since OP1 in (9) is a constrained optimization problem, we present two alternatives to treat the unfeasible solution candidates. The first is simply discarding the unfeasible candidates and replacing them with a random feasible one; the second is using a new fitness function defined as:  
\[\mathcal{\hat{J}}_{1}(\mathbf{\Phi})=\left\{ \begin{array}{ll}\mathcal{J}_{1 }(\mathbf{\Phi})&\text{if feasible}\\ \mathcal{J}_{\min}-\mathcal{P}&\text{if unfeasible}\end{array} \right. \tag{20}\]  
where \(\mathcal{J}_{\min}\) is the worst feasible solution in the PSO population, and \(\mathcal{P}\) is the sum of the constraints in Equations (10) and (11), i.e.,:  
\[\mathcal{P} = \sum_{\ell=1}^{L}\sum_{k=1}^{K_{\ell}}\left(\sum_{q=1}^{T_{p}} \phi_{k,q,\ell}-1\right)+ \tag{21}\] \[\sum_{\ell=1}^{L}\sum_{q=1}^{T_{p}}\left(\sum_{k=1}^{K_{\ell}} \phi_{k,q,\ell}-1\right)\]  
Finally, a pseudocode of the BPSO algorithm is presented in Algorithm 1. ```
input :Channel gain Hipermatrix--\(\mathbf{\beta}\)  Population Size--\(N\)  Max.