## 2 Mathematical Formulation
### Model Constraints
#### 2.2.2 Operational Limits  
**Active and reactive power limits for conventional generation:**  
The constraints in (5) define the limits of active and reactive power generation by conventional generators each hour based on their nominal capacities within the grid.  
\[P_{i}^{cg,\min}\leq P_{i,h}^{cg}\leq P_{i}^{cg,\max},\quad Q_{i}^{cg,\min}\leq Q _{i,h}^{cg}\leq Q_{i}^{cg,\max}, \tag{5}\]  
\[\{\forall i\in\Omega_{cg},\forall h\in\Omega_{H}\}\]  
where \(P_{i}^{cg,\min}\) is the minimum active power to be injected by the conventional generator at node \(i\), and \(P_{i}^{cg,\max}\) is the maximum active power to be injected by the generator at node \(i\). Similarly, \(Q_{i}^{cg,\min}\) is the minimum active power to be injected by the conventional generator at node \(i\), and \(Q_{i}^{cg,\max}\) is the maximum active power to be injected by the generator at node \(i\).  
**Active power constraints for distributed generation:**  
In the same way, Equation (6) sets a limit for the power supplied by the DG at node \(i\) during hour \(h\).  
\[P_{i}^{dg,\min}\leq P_{i,h}^{dg}\leq P_{i}^{dg,\max}G_{h}^{dg}, \tag{6}\]  
\[\{\forall i\in\Omega_{B},\forall h\in\Omega_{H}\}\]  
Here, \(P_{i}^{dg,\min}\) is the maximum active power to be injected by the distributed generator at node \(i\), and \(P_{i}^{dg,\max}\) is the minimum active power to be injected. This constraint considers the PV generation curve in p.u., determined by the technology used and radiation conditions in the study region, which vary each hour and are represented by \(G_{h}^{dg}\).  
**BESS operating limits:**  
On the other hand, Equation (7) defines the charging and discharging power limits of the BESS in the microgrid. It ensures that the power exchanged by the battery at node \(i\) and hour \(h\) stays within the allowable range.  
\[P_{B,i}^{charge\_max}\leq P_{i,h}^{B}\leq P_{B,i}^{disch\_max}, \tag{7}\]  
\[\{\forall i\in\Omega_{N},\forall h\in\Omega_{H}\}\]  
In this case, \(P_{i,h}^{B}\) is the power absorbed or supplied by the battery, \(P_{B,i}^{\text{charge\_max}}\) is the maximum charging power, and \(P_{B,i}^{\text{disch\_max}}\) is the maximum discharging power.  
For the calculation of BESS power limits, the equations in (8) define the maximum charging and discharging powers as a function of the battery capacity \(C_{i}^{B}\), and the charging (\(tc_{i}^{B}\)) and discharging (\(td_{i}^{B}\)) time intervals at node \(i\):  
\[P_{B,i}^{dischmax}=\frac{C_{i}^{B}}{td_{i}^{B}},\quad P_{B,i}^{charge\_max}=- \frac{C_{i}^{B}}{tc_{i}^{B}}, \tag{8}\]  
\[\{\forall i\in\Omega_{B}\}\]  
With this in mind, charging power is assumed to be negative, while discharging power is positive.  
In this sense, the state of charge (SoC) of each battery over time is updated by Equation (9), considering the charge/discharge coefficient \(\phi_{i}^{B}\), power \(p_{i,h}^{B}\), and time step \(\Delta t\):  
\[SoC_{i,h}^{B}=SoC_{i,h-1}^{B}-\phi_{i}^{B}p_{i,h}^{B}\Delta t, \tag{9}\]  
\[\{\forall i\in\Omega_{B},\forall h\in\Omega_{H}\}\]The coefficient \(\phi_{i}^{B}\) defined in Equation (10) depends on the battery's charging/ discharging times and power limits:  
\[\phi_{i}^{B}=\frac{1}{td_{i}^{B}P_{B,i}^{dischmax}}=\frac{1}{tc_{i}^{B}P_{B,i}^{ chargmax}}, \tag{10}\]  
\[\{\forall i\in\Omega_{B},\forall h\in\Omega_{H}\}\]  
To calculate the state of charge at any given time, it is necessary to know the initial state of charge of the battery:  
\[SoC_{i,h=0}^{B}=SoC_{i}^{0}, \tag{11}\]  
\[\{\forall i\in\Omega_{B}\}\]  
If a final SoC is required at the end of the day, it is set by (12)  
\[SoC_{i,h=24}^{B}=SoC_{i}^{f}, \tag{12}\]  
\[\{\forall i\in\Omega_{B}\}\]  
Finally, the SoC must remain within the operational bounds, as stated in Equation (13):  
\[SoC_{i}^{B,min}\leq SoC_{i,h}^{B}\leq SoC_{i}^{B,max}, \tag{13}\]  
\[\{\forall i\in\Omega_{B},\forall h\in\Omega_{H}\}\]  
where \(SoC_{i}^{B,\min}\) and \(SoC_{i}^{B,\max}\) represent the minimum and maximum state of charge limits of the battery, respectively.