# Balancer Genetic Algorithm--A Novel Task Scheduling Optimization Approach in Cloud Computing
#### 3.2.6 Bancer Operator  
After the generation of an entire population, for the next generation the balancer operation is performed. The goal of the balancer operation is to balance the workload among VMs. Tasks from overloaded VMs are migrated to underloaded and vice versa. The decision of over- and under-loaded VMs relies on the percentage of share used by any VM, just like one computed in the fitness function. Algorithm 6 shows the details of the balancer operator. ```
1:\(Population[Parent_{1}],Population[Parent_{2}],flag,p\)
2:\(Population[x_{i}],Population[x_{i+1}]\)
3:procedureCrossoverAlgorithm
4:\(SizeChromosome\gets size(Population[x_{i}])\)
5:\(CutPoint_{1}\gets random(SizeChromosome)\)
6:\(CutPoint_{2}\gets random(SizeChromosome)\)
7:if\(flag==1\)then
8:for\(j\gets 1\) to \(Cutpoint_{1}\)do
9:\(Child_{1}[x_{j}]\gets Population[Parent_{1}]\)
10:\(Child_{2}[x_{j}]\gets Population[Parent_{2}]\)
11:endfor
12:for\(j\gets CutPoint_{1}+1\) to \(SizeChromosome\)do
13:\(Child_{1}[x_{j}]\gets Population[Parent_{2}]\)
14:\(Child_{2}[x_{j}]\gets Population[Parent_{1}]\)
15:endfor
16:else
17:for\(j\gets 1\) to \(Cutpoint_{1}\)do
18:\(Child_{1}[x_{j}]\gets Population[Parent_{1}]\)
19:\(Child_{2}[x_{j}]\gets Population[Parent_{2}]\)
20:endfor
21:for\(j\gets CutPoint_{1}+1\) to \(CutPoint_{2}\)do
22:\(Child_{1}[x_{j}]\gets Population[Parent_{2}]\)
23:\(Child_{2}[x_{j}]\gets Population[Parent_{1}]\)
24:endfor
25:for\(j\gets CutPoint_{2}+1\) to \(SizeChromosome\)do
26:\(Child_{1}[x_{j}]\gets Population[Parent_{1}]\)
27:\(Child_{2}[x_{j}]\gets Population[Parent_{2}]\)
28:endfor
29:endfor
30:\(Population[p]\gets Child_{1}[\)
31:\(Population[p]\gets Child_{2}[\)
32:\(p\gets p+1\)
33:\(Population[p-2]\), \(Population[p-1]\)
34:endprocedure```
1:\(Population[x_{i}]\)
2:\(Population[x_{i}]\)
3:\(Population[x_{i}]\)
4:procedureMutationAlgorithm
5 Mutation. 2:\(SizeChromosome\gets size(Population[x_{i}])\)
5:for\(i\gets 1\) to SizeChromosomedo
6:\(r\gets random(1)\)
7:if\(r<=probability\)then
8:\(r\gets random(SizeChromosome)\)
9:\(Gene[x_{i}]\gets r\)
10:endif
11:endif
12:endfor
13:return
14:endprocedure
```  
**Algorithm 6**Balancer. ```
1:\(Population[x_{i}]\)
2:\(Population[x_{i}]\)
3:\(Population[x_{i}]\)
4:\(Population[x_{i}]\gets r\)
5:\(Population[x_{i}]\gets r\)
6:\(Population[x_{i}]\gets r\)
7:\(Population[x_{i}]\gets r\)
8:\(Population[x_{i}]\gets r\)
9:endfor
10:return
11:endprocedure
```  
**Algorithm 7**Ballancer. ```
1:\(Population[x_{i}]\)
2:\(Population[x_{i}]\)
3:\(Population[x_{i}]\)
4:\(Population[x_{i}]\gets r\)
5:\(Population[x_{i}]\gets r\)
6:\(Population[x_{i}]\gets r\)
7:\(Population[



The balancer operation is performed on each chromosome of the population, except for the elite chromosomes. The major advantage of this balancer operator, as compared to other techniques, is that it does not totally change the chromosome. Other techniques modify a significant number of genes, which may not be as helpful because the chromosome loses its actual characteristics. Other techniques also do not check the VM share information to recognize the over- and under-loaded VMs. The chromosome becomes an input of the balancer operator, and genes of the chromosome are traversed. The total VM share of each VM is already computed before fitness is computed, and it is also utilized in the balancer operator. As the value of a gene represents a VM number corresponding to a task, the VM share is checked against each gene of the chromosome. Initially, the share of every VM is at maximum according to their VM share. While traversing the genes of the chromosome, the size of the task is subtracted from the respective VM. If the VM share is greater than 0, it means that the task can be assigned to the VM, and the size of the task is subtracted on assignment. Otherwise, if the VM share is less than or equal to 0, it means that VM is over-loaded and there is no need to assign any other task to that VM. In such cases, the task being assigned is added to a pool of tasks known as \(cloudlet_{pool}\).