# Quantum PSO-Based Optimization of Secured IRS-Assisted Wireless-Powered IoT Networks
## 3 Proposed Solution Based on Alternating Optimization
```
1:Set the initial values: \(\tau_{\min}=0\), \(\tau_{\max}=1\), \(\xi\), \(\delta\), and QPSO parameters (\(N_{p}\), \(\gamma\), \(I_{\max}\))
2:Initialize iteration index \(i=0\)
3:Main loop:
4:repeat
5: Set \(t_{0}^{(n)}=\frac{\tau_{\min}+\tau_{\max}}{2}\) and \(t_{k}^{(n)}=\frac{1-t_{0}^{(n)}}{K}\)
6:\(n\gets n+1\)
7:Optimize phase shifts (\(\mathbf{\Phi}_{0}\), \(\mathbf{\Phi}_{1}\))
8: Use QPSO to solve sub-problem P1.1 (12)
9: Initialize population of particles for \(\mathbf{\Phi}_{0}\) and \(\mathbf{\Phi}_{1}\)
10: Set the contraction-expansion coefficient (\(\gamma\)) and maximum iterations (\(I_{\max}\))
11:AO loop 1: (QPSO iteration)
12: Initialize iteration index \(i=0\)
13:repeat
14: Evaluate fitness for each particle based on secrecy throughput in (12a)
15: Update individual best position (\(pbest_{j}\)) and global best position (\(gbest\)) using (13) and (15)
16: Update attractors (\(attract_{j}\)) using (16) and update particle position (\(X_{j}\)) using (15) and (19)
17:\(i\gets i+1\)
18:until\(i=I_{\max}\) or convergence is achieved
19: Assign optimized \(\mathbf{\Phi}_{0}^{*}\), \(\mathbf{\Phi}_{1}^{*}\) from QPSO output
20:Optimize time allocation (\(t_{0}\), \(\{t_{k}\}\))
21:AO loop 2: (Bisection method for \(t_{0}\))
22: Initialize iteration index \(n=0\)
23:repeat
24: Set midpoint for \(t_{0}\): \(t_{0}=\frac{\tau_{\min}+\tau_{\max}}{2}\)
25: Set \(t_{k}=\frac{1-t_{0}}{K}\) for all users
26:evaluate secrecy throughput with fixed \(\mathbf{\Phi}_{0}^{*}\), \(\mathbf{\Phi}_{1}^{*}\)
27:if throughput constraint (10b) is met then
28:\(\tau_{\min}=t_{0}\)
29:else
30:\(\tau_{\max}=t_{0}\)
31:endif
32:\(n=n+1\)
33:until\(\tau_{\max}-\tau_{\min}<\delta\)
34:Check convergence:
35:if\(\tau_{\max}-\tau_{\min}<\delta\)then
36: Convergence achieved, exit loop
37:else
38: Update \(\tau_{\max}\) or \(\tau_{\min}\) based on the current value of \(t_{0}^{(n)}\)
39: Proceed to the next iteration
40:endif
41:until\(\tau_{\max}-\tau_{\min}<\delta\)
42:Output: Optimized values for \(\mathbf{\Phi}_{0}^{*}\), \(\mathbf{\Phi}_{1}^{*}\), \(t_{k}^{*}\), \(\{t_{k}^{*}\}\)
```  
**Algorithm 1** Finding the solution to \(\mathcal{P}1\). Optimizing \(\{t_{0},\{t_{k}\}\}\) with a Fixed \(\{\mathbf{\Phi}_{0},\mathbf{\Phi}_{1}\}\)  
We fix IRS phase-shift matrices \(\mathbf{\Phi}_{0}\), \(\mathbf{\Phi}_{1}\) to optimize downlink and uplink time allocations \(t_{0}\), \(\{t_{k}\}\). We rewrite (11b) as follows:P1.2 \[\max_{t_{0},\{t_{k}\}} \sum_{k=1}^{K}[R_{k}-R_{E}]^{+}\] (20a) subject to \[[R_{k}-R_{E}]^{+}\geq\bar{R} k=1,2,\ldots,K\] (20b) \[\sum_{j=0}^{K+1}t_{j}\geq 1\] (20c) \[0\leq t_{j}\leq 1, j=0,1,\ldots,K+1\] (20d)  
Bisection Search Method-Based Solution  
In this sub-problem, we focus on the optimized time, \(\tau=\{t_{0},t_{1},t_{2},\ldots,t_{k}\}\), for downlink and uplink while keeping phase-shift matrices \(\mathbf{\Phi}_{0}\) and \(\mathbf{\Phi}_{1}\) fixed. We employ a two-step approach, utilizing the bisection method to determine the optimal time allocation for downlink and uplink. First, we optimize the time allocation for downlink \(t_{0}\) by applying the bisection method, which is well-suited for convex problems like P1.2. The bisection method iteratively narrows the range of feasible solutions for \(t_{0}\) until the optimal solution is obtained, ensuring the overall rate constraint is satisfied. Once the optimal \(t_{0}\) is determined, the remaining time is divided equally among the users for the uplink time allocation. This is achieved by setting \(t_{k}=\frac{1-t_{0}}{K}\), where \(K\) represents the number of users. Similar techniques have been employed in optimizing wireless resource allocations, where the bisection method is commonly used due to its simplicity and convergence guarantees. This approach efficiently optimizes time resources, ensuring fairness among the users while meeting the required rate conditions.