## 3 Methodology
### Modeling Frequency Deviations  
As explained above, one of the requirements of the isolated microgrid is the need to maintain the frequency in the required range. The frequency deviations depend on the grid inertia (i.e., the number of connected rotating machines) among other factors. One possible solution to ensure the frequency requirements is to connect the maximum number of rotating machines (diesel generators) providing large amount of inertia. However, these machines usually have a minimum active power generation. (The industry has reported that during low load condition diesel engines suffer from the \"slobbering\" effect. This effect is related to the low heat in the cylinder, allowing unburned fuel and oil to leak through the slip joints. This eventually leads to power losses, accelerated ageing and high maintenance costs). Thus, this strategy leads to a costly (fuel cost) and pollutant (CO\({}_{2}\) emissions) solution. Accordingly, the optimal solution is to connect the minimum number of rotating machines that ensures that, after a maximum power imbalance, the grid frequency will be kept in the required range. Thus, the approach of this paper is to obtain an empirical linear equation determining the minimum frequency reached after a maximum power imbalance. This expression is then used in the optimization algorithm. To obtain this expression, the worst case was first defined. The load and PV production of a real microgrid were monitored with 1 s resolution during six days and with 30 s resolution during one year. Using load data, a maximum load variation of 1.5 MW in 1 s was identified. This severe variation could have been produced due to the disconnection of a big load. For the case of PV data, it registered a maximum power variation of 1 MW in 1 s. According to the available recorded data, these changes will not occur simultaneously. Thus, the worst case considered is that the maximum power imbalance will occur after a sudden load variation of 1.5 MW, representing the situation when the maximum frequency deviation will occur. Then, a simulation model of the microgrid was created. The model of the diesel generators are described in [23] while simplified PV and battery models are described in [25]. Using the simulation model, a bundle of scenarios varying \(D_{con}\) from \(N_{d}\) to \(N_{dmin}\) (being \(N_{dmin}\) the minimum number of diesel units connected to supply the maximum power imbalance), varying the \(P^{pv}\) from the rated PV power to 0 and varying the \(P^{bat}\) from \(P^{mxB}\) (maximum battery power) to \(P^{mmB}\) (minimum battery power) were simulated. In these simulations, the worst case (maximum load variation) was tested and the frequency response was analyzed, storing the minimum frequency reached for each simulation. From the analysis, a relation between the EMS output variables and the minimum frequency was performed (this analysis is explained below). To keep the optimizationproblem solvable using mixed integer linear programming (MILP), a linear regression is proposed for that purpose as Equation (1):  
\[f^{mn}=\theta_{ind}+\theta_{d}\cdot D_{con}+\theta_{pv}\cdot P_{PV}+\theta_{bat} \cdot P_{bat} \tag{1}\]  
where \(\theta_{x}\) are the coefficients of linear regression. The minimum frequency reached after the maximum power variation is represented in Figure 4 as a box plot against the \(ON^{dies}\), \(P^{bat}\) and \(P^{PV^{*}_{max}}\). For each of the decision variables, it is possible to observe the tendency of the minimum frequency reached. The lower is the \(P^{bat}\) and \(P^{PV^{*}_{max}}\), the higher (in absolute values) is the maximum frequency deviation reached. On the other hand, the lower is the \(ON^{dies}\), the lower is maximum frequency deviation reached. Figure 5 shows the summary of performing a linear regression; it can be observed that the coefficients for \(P^{PV^{*}_{max}}\) and \(P^{bat}\) are negative and the coefficient for \(ON^{dies}\) is positive.