# Optimal Energy Consumption Tasks Scheduling Strategy for Multi-Radio WSNs
## 4 Optimization Energy-Consumption Task Scheduling Strategy
### Design of the Strategy  
In PSO, each solution is regarded as a particle which consists of a position and velocity. The velocity of each particle calculates iteratively according to its own experience and the global particles. Moreover, the particle updates its position based on the current velocity. The above process continues iteratively until it achieves an optimal (or near-optimal) solution or reaches the maximum number of iterations.  
In our designed strategy, the number of particles is assumed to be equal to the number of tasks to be scheduled, and the search space is assumed to be D-dimensional. Thus, for the \(i\)-th particle, the position and the velocity can be, respectively, denoted \(X_{i}=(X_{i1},X_{i2},\ldots,X_{iD})\) as \(V_{i}=(V_{i1},V_{i2},\ldots,V_{iD})\). The iterative process of the position and velocity can be expressed as follows.  
\[V_{id}^{t+1}=\omega\times V_{id}^{t}+c_{1}\times rand()\times\left(P_{id,best} ^{t}-X_{id}^{t}\right)+c_{2}\times rand()\times\left(G_{id,best}^{t}-X_{id}^{ t}\right) \tag{11}\]  
\[X_{id}^{t+1}=X_{id}^{t}+V_{id}^{t+1} \tag{12}\]  
where \(\omega\) is called the inertia factor and \(\omega\geq 0\). \(V_{id}^{t}\) and \(V_{id}^{t+1}\) are the velocity of the \(i\)-th particle at the \(t\)-th (current velocity) and \((t+1)\)-th, respectively. Similarly, the \(X_{id}^{t}\) and \(X_{id}^{t+1}\) are the position of the \(i\)-th particle at the \(t\)-th (current position) and \(t+1\)-th, respectively. \(c_{1}\) and \(c_{2}\) are the learning factors, normally fixed \(c_{1}=c_{2}=2\). rand() is used to generate a random within \([0,1]\). \(P_{id,best}^{t}\) and \(G_{id,best}^{t}\) represent the current local optimal position of the \(i\)-th particle and the global optimal position of the particles.  
The steps of the PSO used for the proposed optimization energy consumption task scheduling strategy are as follows.  
**Step 1:** Randomly initialize every particle, including the velocity and position;  
**Step 2:** Evaluate the objective function value for each particle and find the current local best position \(P_{id,best}^{t}\). Then determine the global optimal position of the particles \(G_{id,best}^{t}\);  
**Step 3:** Update the velocity and position of each particle according to Equations (11) and (12), separately. Then update the current local best position \(P_{id,best}^{t}\) and the global optimal position of the particles \(G_{id,best}^{t}\);  
**Step 4:** Return to Step 2 and continue the above process until the desired number of iterations is met.  
The corresponding pseudo-code of the PSO which is applied to achieve the optimization energy efficient task scheduling strategy is provided by Algorithm 1.  
```
Require: Randomly generate the population of initial solutions. The number of particles (equal to the number of tasks to be scheduled. The search space \(D\). The maximum iteration number \(T\); Ensure: for each particle \(i\)do  Initialize velocity \(V_{id}^{t}\) and position \(X_{id}^{t}\) for \(i\)-th particle, and obtain the local best solution \(P_{id,best}^{t}\) and global best solution \(G_{id,best}^{t}\);  end for\(G_{id,best}^{t}=\min\left\{P_{id,best}^{t}\right\}\); while\(t<T\)do for\(i=1\) to \(N\)do  Update the velocity \(V_{id}^{t+1}\) and position \(X_{id}^{t+1}\) for \(i\)-th particle, according to Equations (11) and (12), respectively;  Evaluate the \(i\)-th particle if(fitness(\(X_{id}^{t+1}\))\(<\)fitness(\(P_{id,best}^{t}\))) then \(P_{id,best}^{t}=X_{id}^{t+1}\)  end if if(fitness(\(P_{id}^{t+1}\))\(<\)fitness(\(G_{id,best}^{t}\))) then \(G_{id,best}^{t}=P_{id}^{t+1}\)  end if  end for  end while
```  
**Algorithm 1**The pseudo-code of the PSO used for MR-WSNs.