# SmartFog: Training the Fog for the Energy-Saving Analytics of Smart-Meter Data
## 5 The Proposed Adaptive Elitist GA  
A main advantage of the (previously mentioned) elitist mechanism is that it guarantees that, by design, the \"best\" chromosome delivered at the current iteration is also _globally_ the best chromosome generated up to the current iteration [22]. This implies that, in our framework, the sequence of the energy returned by the Elitist GA is guaranteed to exhibit a non-increasing behavior. However, this pro is typically counterbalanced by one major disadvantage. In fact, elitism is, by design, a conservative strategy that tends to enhance the exploitation capability of the GA by reducing the corresponding exploration capability [22]. This means, in turn, that elitist GAs tend to be trapped by the local minima of the underlying objective functions and, then, they are slow to converge [22]. Motivated by these considerations, we propose a suitable _Adaptive_ version of the standard Elitist GA (namely the AEGA), whose ultimate goal is to attain an improved trade-off between the two contrasting requirements of high exploitation and exploration capabilities. Algorithm 1 reports a pseudo-code of the proposed AEGA, together with a description of its input, output and local variables. Roughly speaking, the following main design principles are on the basis of the proposed AEGA:  
1. the size \(S_{\text{POP}}\) of the full population to be generated at each iteration is specified as an input parameter and it is held constant (see the list of the input parameters of Algorithm 1). However, the sizes \(S_{ELIT}\) and \(S_{CHA}\) of the sub-lists of the elite chromosomes and the crossed over-plus-mutated chromosomes are _adaptively_ updated at each iteration. The goal is to adaptively balance the exploitation-vs.-exploration capabilities of the resulting AEGA (see the \"for\" statement at line #7 of Algorithm 1), while guaranteeing that the summation: \(S_{ELIT}+S_{CHA}\) remains equal to \(S_{POP}\) (see lines #14 and #18 of Algorithm 1);
2. at each iteration, the relative (absolute) gap: \(\left|\mathcal{E}_{CUR}-\mathcal{E}_{PRE}\right|/\mathcal{E}_{CUR}\) between the energy \(\mathcal{E}_{CUR}\) and \(\mathcal{E}_{PRE}\) returned by the AEGA at the current iteration and the previous one is used for indicating if the algorithm is trapped by the attraction basin of an _already_ explored local minimum or is just entering the still unexplored attraction basin of the _new_ local minimum (see the two \"if\" statements at lines #12 and #16 of Algorithm 1);
3. when the relative energy gap is below a (user defined) lower threshold \(TH_{LOW}\) (see line #12 of Algorithm 1), it is reasonable to expect that the algorithm is currently trapped by the attraction basin of an _already explored_ local minimum. Hence, in order to quickly escape it, the exploration capability of the AEGA should be increased. For this purpose, the size \(S_{ELIT}\) of the list of the elite chromosomes is reduced by a (user defined) factor \(r\), with \(0<r<1\) (see line #13 of Algorithm 1), while the corresponding size \(S_{CHA}\) of the list of the crossed over-plus-mutated chromosomes is increased as reported in line #14 of Algorithm 1. Such updated values of \(S_{ELIT}\) and \(S_{CHA}\) will be used for performing the next iteration (see the \"for\" statement at line #7 of Algorithm 1);
4. when the relative energy gap is larger than a (user defined) upper threshold \(TH_{UPP}\) (see line #16 of Algorithm 1), it is reasonable to expect that the AEGA is _just_ entering the _still unexplored_ attraction basin of a new local/global minimum. Hence, in order to finely examine this new region of the solution landscape, the exploitation capability of the AEGA should be increased.