# A Parallel Particle Swarm Optimisation for Selecting Optimal Virtual Machine on Cloud Environment
## 4 The Proposed Genetic Algorithm and Parallel Particle Swarm Optimisation in the Cloud
### The Proposed Parallel Particle Swarm Optimisation in Cloud Environment
The barrier synchronisation aims to stop the algorithm from the move to the next step until the cost function (the best chosen of Virtual_Ms) has been notified, which is necessary to preserve algorithmic coherence. Assume that all the particles' (Virtual_Ms) fitness estimations have been accomplished and results notified before the velocity and position computations can be implemented. Update particle velocity, according to Equation (7):  
\[ \begin{array}{c}\text{VI},\text{j}\) (t) = \(\text{W}\,\text{VI},\text{j}\) (t - 1) +\\ \text{C1}\ \text{R1}\ (\text{Pi},\text{j}\) (t - 1)-\(\text{Xi},\text{j}\) (t - 1)) +\\ \text{C2}\ \text{R2}\ (\text{PS},\text{j}\) (t - 1)-\(\text{Xi},\text{j}\) (t - 1)) +\\ \text{C3}\ \text{R3}\ (\text{Pg},\text{j}\) (t - 1)-\(\text{Xi},\text{j}\) (t - 1)) \\ \end{array}  \tag{7}\]  
where:  
\(\text{Xi},\text{j}\) = the position of ith particle in jth swarm,  
\(\text{VI},\text{j}\) = the velocity of ith particle in jth swarm,  
\(\text{Pi},\text{j}\) = the pbest of ith particle in jth swarm,  
\(\text{PS},\text{j}\) = the swarm best of jth swarm,  
\(\text{Pg},\text{j}\) = the global best among all the sub swarms,\(\text{W}=\text{inertia weight}\),  
C1, C2, C3 = acceleration parameters,  
R1, R2, R3 = the random variables. Update particle position according to Equation (8):  
\[\text{Xi},\text{j}\left(\text{t}\right)=\text{Xi},\text{j}\left(\text{t}-1 \right)+\text{VI},\text{j}\left(\text{t}\right) \tag{8}\]  
where:  
\(\text{Xi},\text{j}\left(\text{t}\right)=\text{the current position of ith particle in jth swarm}\),  
\(\text{Xi},\text{j}\left(\text{t}-1\right)=\text{the new position of ith particle in jth swarm}\),  
\(\text{VI},\text{j}\left(\text{t}\right)=\text{the current velocity of ith particle in jth swarm}\). ```
1 Input: Size \(\alpha\) of population,
2 Set \(\beta\) of \(\text{P}_{\beta\text{-best}}\),
3 Set \(\sigma\) of \(\text{P}_{\beta\text{-best}}\),
4 Number Y of Iterations
5 Output: \(\text{P}_{\beta\text{-best}}\leftarrow\text{(Optimal Particles (Virtual\_Ms): Optimal }_{\text{Exec Time}})\)
6 Stakeholders Tasks = X
7 Count I = 0
8 For I = 0 to \(\alpha\)do
9 \(\text{P}_{\text{velocity}}\leftarrow\text{Random velocity 0}\)
10 \(\text{P}_{\text{position}}\leftarrow\text{Random position (\alpha)}\)
11 \(\sigma\leftarrow\text{P}_{\text{position}}\)
12 If (cost(\(\sigma\)) <= cost(\(\beta\)))
13 \(\beta=\sigma\)
14 End if
15 End for
16 While (X # 0)
17 For I = 0 to Ydo
18 Calculate fitness function
19 Update velocity (\(\text{P}_{\text{velocity}}\), \(\beta\), \(\sigma\))
20 Update position (\(\text{P}_{\text{velocity}}\), \(\text{P}_{\text{position}}\))
21 \(\text{P}_{\text{velocity}}\leftarrow\text{Update velocity}\)
22 \(\text{P}_{\text{position}}\leftarrow\text{Update position}\)
23 If (cost (\(\text{P}_{position}\)) <= cost(\(\sigma\)))
24 \(\sigma\) = \(\text{P}_{\text{position}}\)
25 If (cost(\(\sigma\)) <= cost (\(\beta\)))
26 \(\beta\) = \(\sigma\)
27 If (X is finished = true)
28 X = X - 1
29 Save \(\beta\)
30 Else
31 Calculate fitness function for each particle (Virtual\_Ms)
32 End if
33 End if
34 End if
35 I = I + 1
36 End for
37 End while
38 Return \(\beta\)
```  
**Algorithm 2** PSO Steps for Selecting Virtual_Ms on Cloud Environment  
Figure 3: The proposed parallel particle swarm optimisation algorithm for cloud computing.