# Optimal Sizing of Battery Energy Storage System for Implicit Flexibility in Multi-Energy Microgrids
## 2 Methodology
### Generation Units
#### 2.2.1 Ctp  
First, we assume that the electrical and thermal efficiency curves could be approximated using piecewise linearization for each CHP unit \(u\). Given the slope and intercept of each linear segment, Equation (1) and Equation (2) describe how the electrical and thermal outputs are related to the natural gas input, respectively:  
\[p_{u,t}^{EL_{CHP}}=\sum_{i=1}^{N_{pixelsCHP_{u}}}\Big{[}\Big{(}\Phi_{u,i}^{EL_{ CHP}}\times p_{u,t}^{FUEL_{CHP}}+\Omega_{u,i}^{EL_{CHP}}\times y_{u,t}^{iSOn_{CHP}} \Big{)}\times y_{u,t,i}^{eff_{CHP}}\Big{]}, \tag{1}\]  
\[p_{u,t}^{TH_{CHP}}=\sum_{i=1}^{N_{pixelsCHP_{u}}}\Big{[}\Big{(}\Phi_{u,i}^{TH_{ CHP}}\times p_{u,t}^{FUEL_{CHP}}+\Omega_{u,i}^{TH_{CHP}}\times y_{u,t}^{iSOn_{CHP}} \Big{)}\times y_{u,t,i}^{eff_{CHP}}\Big{]}. \tag{2}\]  
The selection of the specific linear segment of the CHP efficiency curves for each unit \(u\) at each time step \(t\) is governed by the set of binary variables \(y_{u,t,i}^{eff_{CHP}}\), which are included in the following constraints to ensure modeling consistency:  
\[\sum_{i=1}^{N_{pixelsCHP_{u}}}y_{u,t,i}^{eff_{CHP}}=1, \tag{3}\]  
\[p_{u,t}^{FUEL_{CHP}}\geq\Theta_{u,i}^{LB_{H}fuel_{CHP}}-bigM\times\Big{(}1-y_{u,t,i}^{eff_{CHP}}\Big{)}, \tag{4}\]  
\[p_{u,t}^{FUEL_{CHP}}\leq\Theta_{u,i}^{UB_{H}fuel_{CHP}}+bigM\times\Big{(}1-y_{u,t,i}^{eff_{CHP}}\Big{)}. \tag{5}\]  
Additional constraints are imposed to ensure CHP units operate within their minimum and maximum allowable load limits:  
\[p_{u}^{MINel_{CHP}}\times y_{u,t}^{iSOn_{CHP}}\leq p_{u,t}^{EL_{CHP}}\leq p_{ u}^{MAXel_{CHP}}\times y_{u,t}^{iSOn_{CHP}}. \tag{6}\]  
Furthermore, a CHP unit may be subject to operational constraints such as a minimum uptime--once switched on, it must remain operational for a certain period--and a minimum downtime--once switched off, it cannot be restarted immediately. To account for this behavior, two parameters have been introduced: \(\Delta t_{u}^{minTimeOn_{CHP}}\) and \(\Delta t_{u}^{minTimeOff_{CHP}}\). These are incorporated into the following constraints, which affect the binary variable indicating whether the CHP unit is shutting down or turning up during the time interval \(t\):  
\[y_{u,t}^{iSShuttingDown_{CHP}}\leq\frac{\sum_{t=(t-\Delta t_{u}^{minTimeOn_{ CHP}})}^{t}\big{[}y_{u,t}^{iSOn_{CHP}}\big{]}}{\Delta t_{u}^{minTimeOn_{CHP}}}, \tag{7}\]  
\[y_{u,t}^{iSStartingUp_{CHP}}\leq 1-\frac{\sum_{t=(t-\Delta t_{u}^{minTimeOff_{CHP}} )}^{t}\big{[}y_{u,t}^{iSOn_{CHP}}\big{]}}{\Delta t_{u}^{minTimeOff_{CHP}}}. \tag{8}\]It is also necessary to define a constraint that links the different binary variables used to model the CHP unit's operational status, specifically its ON/OFF state, start-up, and shut-down phases:  
\[y_{u,t}^{isStartingUP_{CHP}}-y_{u,t}^{isShuttingDown}{}_{CHP}=y_{u,t}^{iSOn_{CHP} }-y_{u,t-1}^{iSOn_{CHP}}, \tag{9}\]  
\[y_{u,t}^{isStartingUP_{CHP}}+y_{u,t}^{isShuttingDown}{}_{CHP}\leq 1. \tag{10}\]  
It is important to note that Equations (9) and (10) assume that the unit's start-up and shut-down times are significantly shorter than are the model's time resolution. In other terms, CHP power output variations are treated as instantaneous, allowing the unit to ramp its power output from minimum to maximum, or vice versa, within a single time step. This assumption is consistent with the operational behavior of internal combustion engines (ICEs) commonly used in CHP systems, which are characterized by fast response times and high operational flexibility.