## 3 Proposed Target Channel Visiting Order Design Algorithm
### Proposed PSO Based Algorithm for Target Channel Visiting Order Design  
The first step to use PSO for solving problem (3) is to map the particle to a possible solution. As the position of a particle contains binary bits while the visiting order takes decimal values, we need to convert these binary bits to decimal integers or the way around. Figure 2a shows the mapping process. We need \(B=\left\lceil\log_{2}M\right\rceil\) bits to represent a value in \([\![,M]\!]\), where \(\left\lceil a\right\rceil\) denotes the closest integer which is greater than \(a\). In consequence, the number of bits in a particle position is \(MB=M\left\lceil\log_{2}M\right\rceil\). Consecutive \(B\) bits in the position represent a channel index. For instance, 000 represents channel \(c_{1}\), 001 represents channel \(c_{2}\), and so on. Figure 2b illustrates an example.  
The initial swarm is generated randomly to maintain a uniform distribution of these particles on the search space. Mapping a randomly generated position to a specific \(\boldsymbol{v}\) may result in a solution which contains repeated channels. As a same target channel will not be visited twice or more in spectrum handoff, we propose the following procedure to ensure that a solution is valid. For position \(\boldsymbol{x}_{i}^{k}=[\boldsymbol{x}_{i1}^{k},\boldsymbol{x}_{i2}^{k},..., \boldsymbol{x}_{iD}^{k}]\), we convert it to decimal integers and denote the resulting vector as \(\boldsymbol{z}_{i}^{k}=[\boldsymbol{z}_{i1}^{k},\boldsymbol{z}_{i2}^{k},..., \boldsymbol{z}_{iM}^{k}]\). Update \(\boldsymbol{z}_{i}^{k}\) by computing \(\boldsymbol{z}_{i}^{k}=[\boldsymbol{z}_{i1}^{k}\bmod M,\boldsymbol{z}_{i2}^{k }\bmod M,...,\boldsymbol{z}_{iM}^{k}\bmod M]\), where \(a\bmod M\) computes the reminder obtained after \(a\) is divided by \(M\). Store all distinct values in \(\boldsymbol{z}_{i}^{k}\) on a set \(\Omega\). Denote \(\Box=[0,1,2,...,M-1]\). If the number of elements in \(\Omega\) is smaller than \(M\), we repeat the following two steps to make \(\boldsymbol{z}_{i}^{k}\) valid: (a) For any two elements in \(\boldsymbol{z}_{i}^{k}\) which are identical, randomly choose one of them and replace it with a value (denoted by \(\lambda\) ) randomly chosen from the set \(\Theta=\Box-\Omega\) ; (b) update \(\Omega\) by adding \(\lambda\) into the set. The above procedure is repeated when all elements in \(\boldsymbol{z}_{i}^{k}\) are distinct. After the above procedure, \(\boldsymbol{z}_{i}^{k}\) is converted back to binary string and \(\boldsymbol{x}_{i}^{k}=[\boldsymbol{x}_{i1}^{k},\boldsymbol{x}_{i2}^{k},..., \boldsymbol{x}_{iD}^{k}]\) is replaced by this string. For simplicity, we refer to this procedure as \"position correction\" in the rest of the paper. Fig.3 shows an example of \"position correction\".  
Figure 3: An example of “position correction” where \(M=6\).  
Figure 2: Mapping the position to the solution. (**a**) General representation. (**b**) An example where \(M=6\) and \(B=\left\lceil\log_{2}M\right\rceil=3\).  
After initialization, the fitness of each particle is evaluated. We use the opposite of handoff delay (2) for fitness function. After fitness evaluation, the velocity and the position are updated by (6) and (8) and a new swarm of particle is obtained. Note that we also need to use the procedure of \"position correction\" discussed previously to make all positions valid. The iteration continues until the maximum number of iterations is reached. The proposed algorithm is shown in Table 2.