# SmartFog: Training the Fog for the Energy-Saving Analytics of Smart-Meter Data
## 5 The Proposed Adaptive Elitist GA
For this purpose, the size \(S_{CHA}\) of the list of the crossed over-plus-mutated chromosomes is reduced by the factor \(r\) (see line #17 of Algorithm 1), while the size \(S_{ELIT}\) of the list of the elite chromosomes is increased as reported in line #18 of Algorithm 1;
5. finally, when the relative energy gap falls into the inter-threshold interval \([TH_{LOW},\,TH_{UPP}]\), \(S_{ELIT}\) and \(S_{CHA}\) remain unchanged. **Input:**\(S_{POP}\): integer-valued population size;  
\(TH_{LOW}\): positive-valued lower threshold;  
\(TH_{UPP}\): positive-valued upper threshold, with \(TH_{LOW}\geq TH_{UPP}\);  
\(I_{GEN}\): number of performed iterations;  
\(r\): reducing factor, with \(0<r<1\). **Output:**\(\mathcal{E}_{BEST}\): energy consumed by the globally best generated chromosome. **Local variables:**\(\mathcal{E}_{CUR}\): energy consumed by the best chromosome of the current population;  
\(\mathcal{E}_{PRE}\): energy consumed by the best chromosome of the previous population;  
\(S_{ELIT}\): integer-valued size of the current set of elite chromosomes;  
\(S_{CHA}\): integer-valued size of the current set of crossed over-plus-mutated chromosomes, with \(S_{CHA}+S_{ELIT}=S_{POP}\);  
\(\mathcal{L}\): full list (of size \(S_{POP}\)) of the currently generated chromosomes. **-- Initialization phase --**  
```
1:Randomly generate a list \(\mathcal{L}\) of \(S_{POP}\) chromosomes of size \(L+1\);
2:Compute the energy of the generated chromosomes through Equation (4);
3:Sort the chromosomes into ascending order of their consumed energy values and return the sorted list \(\mathcal{L}\);
4:Store into \(\mathcal{E}_{PRE}\) the energy of the first (i.e., the best) element of the sorted list\(\mathcal{L}\);
5:Initialize the size \(S_{ELIT}\) of the set of the elite chromosomes, with \(1\leq S_{ELIT}\leq S_{POP}\);
6:Initialize the size \(S_{CHA}\) of the set of the crossed over-plus-mutated chromosomes at \(S_{CHA}=S_{POP}-S_{ELIT}\);
7:for\(i=1:I_{GEN}\)do
8: Perform the crossover and mutation of the last \(S_{CHA}\) chromosomes of the current population and return the updated population list \(\mathcal{L}\);
9: Evaluate the energy of the \(S_{POP}\) chromosomes of the returned list \(\mathcal{L}\);
10: Sort the chromosomes into ascending order of their consumed energy values and return the sorted list \(\mathcal{L}\);
11: Store the energy of the first chromosome of the sorted list \(\mathcal{L}\) into \(\mathcal{E}_{CUR}\);
12:if\((\left|\mathcal{E}_{CUR}-\mathcal{E}_{PRE}\right|/\mathcal{E}_{CUR})<TH_{LOW}\)then\(\triangleright\) Increase the exploration capability of the AEGA
13:\(S_{ELIT}=\) round \((rS_{ELIT})\);
14:\(S_{CHA}=S_{POP}-S_{ELIT}\);
15:endif
16:if\((\left|\mathcal{E}_{CUR}-\mathcal{E}_{PRE}\right|/\mathcal{E}_{CUR})>TH_{UPP}\)then\(\triangleright\) Increase the exploitation capability of the AEGA
17:\(S_{CHA}=\) round \((rS_{CHA})\);
18:\(S_{ELIT}=S_{POP}-S_{CHA}\);
19:endif
20: Update: \(\mathcal{E}_{PRE}=\mathcal{E}_{CUR}\);
21:endfor -- End of the iterative phase --
22:\(\mathcal{E}_{BEST}=\mathcal{E}_{CUR}\); \(\triangleright\) Store the energy of the globally best generated chromosome
23:return\(\mathcal{E}_{BEST}\). ```  
**Algorithm 1** Adaptive Elitist GA (AEGA). Due to the elitist nature of the proposed AEGA, the energy \(\mathcal{E}_{CUR}\) returned at the end of the last iteration (i.e., at \(i\equiv I_{GEN}\); see line #7 of Algorithm 1) is also the minimum energy obtained over the overall set of carried out iterations (see line #22 of Algorithm 1). Hence, it constitutes the final output of the AEGA (see line #23 of Algorithm 1). Before proceeding, three main remarks about the expected impact on the performance of the AEGA of the setting of the input parameters \(TH_{LOW}\), \(TH_{UPP}\) and \(r\) of Algorithm 1 are in order.