# Peak Age of Information Optimization in Cell-Free Massive Random Access Networks
## 4 Optimization of Average Peak Age of Information  
### Global PSO Algorithm Based on Full Topology Information  
The PSO algorithm is a stochastic optimization method inspired by swarm intelligence [20]. In PSO, each particle represents a potential solution to the optimization problem, and the particle continuously adjusts its position in the search space to find the optimal solution [21]. The global PSO algorithm optimizes the channel access probability through global search to minimize the global average PAoI. The detailed implementation of PSO algorithm is described in Algorithm 1. ```
0: Network parameters \(n^{g},g=\{1,2,\ldots G\}\), \(\lambda\); algorithm setting parameters \(K\), \(c_{1}\), \(c_{2},v_{min}\), \(\mathbf{v}_{max}\), \(\mathbf{q}_{min}\), \(\mathbf{q}_{max}\), \(\omega_{min}\), \(\omega_{max}\), \(I_{max}\). 0: Optimal channel access probability \(\mathbf{d}^{(l_{max})}=\)\(\left[q^{(1)},q^{(2)},\ldots,q^{(G)}\right]\) and minimum global PAoI \(A_{d}^{(l_{max})}\)
1:for each particle \(k=1\) to \(K\)do
2: Initialize position \(\mathbf{q}_{k}^{(1)}\) and velocity \(\mathbf{v}_{k}^{(1)}\)
3:\(\mathbf{b}_{k}^{(1)}=\mathbf{q}_{k}^{(1)}\)
4: Calculate the PAoI \(A_{k}^{(1)}\) according to (10)
5:endfor
6: Initialize \(\mathbf{d}^{(1)}\) and \(A_{d}^{(1)}\) according to (13) and (10)
7: Set the initial iteration value \(i=1\)
8:for each iteration round \(i<I_{max}\)do
9:for each particle \(k=1\) to \(K\)do
10: Update velocity \(\mathbf{v}_{k}^{(i+1)}\) according to (12) and (14)
11: Constrain the velocity \(\mathbf{v}_{k}^{(i+1)}\) within the range \([\mathbf{v}_{min},\mathbf{v}_{max}]\)
12: Update position \(\mathbf{q}_{k}^{(i+1)}=\mathbf{v}_{k}^{(i+1)}+\mathbf{q}_{k}^{(i)}\)
13: Constrain the position \(\mathbf{q}_{k}^{(i+1)}\) within the range \([\mathbf{q}_{min},\mathbf{q}_{max}]\)
14: Calculate the PAoI according to (10)
15: Update \(\mathbf{b}_{k}^{(i+1)}\)and \(A_{k}^{(i+1)}\) according to (13) and (10)
16:endfor
17: Update \(\mathbf{d}^{(i+1)}\) and \(A_{d}^{(i+1)}\) according to (13) and (10)
18:\(i=i+1\)
19:endfor
```  
**Algorithm 1** PAoI Optimization Algorithm Based on Global PSO  
Given the number of MTDs, \(n^{g}\), and packet arrival rates, \(\lambda\), for each logical group, assuming there are \(K\) particles in the network, \(k=\{1,2,\ldots,K\}\), and each particle \(k\) has a position vector \(\mathbf{q}_{k}\) and a velocity vector \(\mathbf{v}_{k}\). \(\mathbf{q}_{k}\) represents the channel access probability vector, whose elements correspond to the channel access probabilities of different groups, and \(\mathbf{v}_{k}\) controls its search direction and step size. During each iteration, \(\mathbf{v}_{k}\) will perform a small amplitude random update on the elements of \(\mathbf{q}_{k}\), and the updated position needs to be within the legal range. Particles compute PAoI based on \(\mathbf{q}_{k}\) to identify optimal positions. The update rules are as follows [22]:  
\[\left\{ \begin{array}{l}\mathbf{v}_{k}^{(i+1)}=\mathbf{\omega}^{(i)}\cdot\mathbf{v}_{k}^{ (i)}+c_{1}r_{1,k}^{(i)}\cdot(\mathbf{b}_{k}^{(i)}-\mathbf{q}_{k}^{(i)})+c_{2}r_{2,k}^{ (i)}\cdot(\mathbf{d}^{(i)}-\mathbf{q}_{k}^{(i)}),\\ \mathbf{q}_{k}^{(i+1)}=\mathbf{v}_{k}^{(i)}+\mathbf{q}_{k}^{(i)},\end{array} \right. \tag{12}\]where \(c_{1}\) and \(c_{2}\) are the learning weight, \(r^{(i)}_{1,k}\) and \(r^{(i)}_{2,k}\) are the random value generated from the range \([0,1]\), \(\mathbf{b}^{(i)}_{k}\) represents the best-experience position of the particle itself, \(\mathbf{d}^{(i)}\) represents the best-experience position among all particles, and they are determined by the following formulas:  
\[\left\{ \begin{array}{l}\mathbf{b}^{(i)}_{k}=\underset{\mathbf{d}^{(1)}_{k},\mathbf{d}^{(2 )}_{k},\ldots,\mathbf{d}^{(i)}_{k}}{\text{argmin}A}\\ \mathbf{d}^{(i)}=\underset{\mathbf{b}^{(i)}_{1},\mathbf{b}^{(i)}_{2},\ldots,\mathbf{b}^{(i)}_{ K}}{\text{argmin}A}\end{array} ,\right.