## 3 Optimization Function  
### Fitness Function  
Since the main objective of the EMS is to smooth the MG power profile by managing the energy balance between renewable energy sources, electric loads, energy storage systems, and the main electrical grid, a set of six quality criteria, which quantify the effectiveness of energy management, is defined according to [20; 21; 25; 26; 40; 41; 42], as follows:  
\[P_{G,MAX}=\text{max}(P_{GRID}) \tag{5}\]  
\[P_{G,MIN}=\text{min}(P_{GRID}) \tag{6}\]  
\[MPD=\text{max}\Big{(}\Big{|}\dot{P}_{GRID}\Big{|}\Big{)} \tag{7}\]  
\[APD=\frac{1}{M}\sum_{n=1}^{M}\Big{|}\dot{P}_{GRID}(t)\Big{|} \tag{8}\]  
\[\dot{P}_{GRID}(t)=\left[P_{GRID}(t)-P_{GRID}(t-1)\right]/T_{S} \tag{9}\]  
\[PVR=\frac{P_{G,MAX}-P_{G,MIN}}{P_{LG,MAX}-P_{LG,MIN}} \tag{10}\]  
\[PPV=\sqrt{\sum_{f=f_{i}}^{f_{f}}\left(P_{GRID,f}\right)^{2}}\Bigg{/}P_{DC} \tag{11}\]  
where \(P_{G,MAX}\) and \(P_{G,MIN}\) are the maximum and minimum power of the grid power profile (\(P_{GRID}\)); \(MPD\) (maximum power derivative) is the maximum grid power profile ramp-rate (\(\dot{P}_{GRID}\)) in one year; \(APD\) (average power derivative) is the average of the grid power profile ramp-rates in one year, with \(M\) being the number of samples in one year; \(PVR\) (power variation range) is the grid power profile variation concerning the MG net power; and \(PPV\) (power profile variability) gives an idea of the quality of the grid power profile where \(P_{GRIDf}\) is the grid power harmonic at \(f\) frequency, and \(f_{i}=1.65\times 10^{-6}\) Hz and \(f_{f}=5.55\times 10^{-4}\) Hz are the initial and final frequencies defined to evaluate variation periods of above one week or less [20; 21; 25; 26].  
Figure 4: Fuzzy controller membership functions (MF): (**a**) Power forecast error, (**b**) battery state-of-charge (SOC), and (**c**) fuzzy logic control (FLC) output [45]. ©2016 IEEE, Reprinted, with permission, from [PERSON], [PERSON], [PERSON] [PERSON], [PERSON] [PERSON], [PERSON] [PERSON], [PERSON] Energy management strategy for a grid-tied residential microgrid based on Fuzzy Logic and power forecasting. IECON 2016—42 nd Annu. Conf. IEEE Ind. Electron. Soc., Florence, Italy: IEEE; 2016, pp. 4103-4108.  
On the other hand, since the FLC tuning procedure can be considered as an optimization process [29], it will require the definition of an optimization (cost) function involving all energy management quality criteria to coherently represent the designer's preferences between objectives in terms of a weighted sum function [46]. This function is defined according to [40], and it is normalized in terms of the reference energy management quality criteria obtained from a previous study where a heuristic-based optimization procedure is applied [43]. From this perspective, the optimization function is defined as follows:  
\[fitness=w\cdot F_{1}+(w-1)\cdot F_{2} \tag{12}\]  
\[F_{1}=\left(\frac{P_{G,MAX}}{P_{G,MAX}^{REF}}+\frac{P_{G,MIN}}{P_{G,MIN}^{REF} }+\frac{MPD}{MPD_{REF}}\right) \tag{13}\]  
\[F_{2}=\left(\frac{APD}{APD_{REF}}+\frac{PVR}{PVR_{REF}}+\frac{PPV}{PPV_{REF}}\right) \tag{14}\]  
where \(w\geq 1\) is a fixed real number that balances the designer's preference between \(F_{1}\) and \(F_{2}\), prioritizing one of them during the iterative optimization process [40].