# 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 Genetic Algorithm in Cloud Environment  
In this subsection, we extensively explain the proposed genetic algorithm (GA) that is utilised to execute our proposed model. The significant chromosomes' size, mutation, and crossover prospects are producing new offspring that assists in obtaining novel solutions. Suppose that there are F (GA) chromosomes population (Virtual_Ms) = 1000 and a set of iteration = 100. Each Virtual_Ms in the cloud environment is represented as a chromosome which considers a possibility solution (Virtual_Ms) that can be assigned for implementing the stakeholder's requests. Calculate cost function (optimally chosen of Virtual_Ms) by using CPU Utilisation (U), Turnaround Time (TT), and Waiting Time (WT). If the stakeholder's request is concluded, find the optimal implementation request time and optimally chosen Virtual_Ms, otherwise, execute selection, crossover, mutation, process, and produce new chromosomes, as shown below in Algorithm 1. The selection process assists in holding the best chromosomes (Virtual_Ms) and electing a proper pair from each chromosome (Virtual_Ms). It relies on the division of the 2 chromosomes (two Virtual_Ms on the cloud environment) randomly and compares between them to select the best one. So, execute the 2-points crossover process between two chromosomes (two Virtual_Ms) and obtain two different offspring. The crossover process is computed by using two Equations (3) and (4) as follows:  
\[\text{Offspring A}=\text{H}\times\text{P1}+(\text{1}-\text{H})\times\text{P2} \tag{3}\]  
\[\text{Offspring B}=(\text{1}-\text{H})\times\text{P1}+\text{H}\times\text{P2} \tag{4}\]  
where:  
H = random number (elected before each crossover process)  
P = parent (Virtual_Ms)  
The purpose of the mutation process is to hold small changes in chromosomes. So, it utilises a flip bit mutation method for that purpose. In chromosomes (Virtual_Ms), the mutation process changes one or more gene values from its initial state. Mutation = 0.5. Algorithm 1 shows scientific steps to apply GA on the cloud environment, as follows. \begin{table}
\begin{tabular}{c c c c} \hline \hline
**Number** & **Factors** & **Formula** \\ \hline
1 & CPU Utilisation (U) & U = 100\% \(-\) (100\% time spent in the idle task) & (a) \\
2 & Waiting Time (WT) & WT = TT \(-\) Burst Time (BT) & (b) \\
3 & Turnaround Time (TT) & TT = Completion Time (CT) \(-\) Arrival Time (AT) & (c) \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Factors of optimal selection of Virtual Machines. * \(\mathbf{\alpha}\) = population,
* \(\beta\) = rate of Elitism,
* \(\mathbf{Y}\) = rate of Mutation,
* \(\sigma\) = number of Iterations  
```
1 Input: Size \(\mathbf{\alpha}\) of population,
2 Rate \(\beta\) of Elitism,
3 Rate \(\mathbf{Y}\) of Mutation,
4 Number \(\mathbf{\sigma}\) of Iterations
5 Output: H \(\leftarrow\) (Optimal Chromosomes (Virtual_Ms), Optimal Exec Time)
6 Stakeholders Tasks = \(\mathbf{ST}\)
7 Count I = 0
8P\({}_{\text{k}}\) = Produce random \(\mathbf{\sigma}\) solutions
9 Calculate fitness function (i) for each I \(\varepsilon\text{P}_{\text{k}}\)
10 While (\(\mathbf{ST}\
eq 0\))
11 For I = 0 to \(\mathbf{\sigma}\)do
12 Select chromosomes (Virtual_Ms) for tournament
13 Find chromosomes (Virtual_Ms) with the lowest fitness
14 Remove chromosomes (Virtual_Ms) with the lowest fitness
15 Two-points crossover process (create new chromosomes)
16 Evaluate new chromosomes (Virtual_Ms)
17 Endfor
18 BitFlip Mutation
19 Evaluate (mutated chromosomes (Virtual_Ms))
20 Calculate fitness function (i) for each I \(\varepsilon\text{P}_{\text{k}}\)
21 Endwhile
22H = fittest values from P\({}_{\text{k}}\)
23 Return H
```  
**Algorithm 1**Genetic Algorithm (GA) Steps for Selecting Virtual_Ms on Cloud Environment. Initially, the system contains many chromosomes (Virtual_Ms).