# Optimal Sizing of Battery Energy Storage System for Implicit Flexibility in Multi-Energy Microgrids
## 2 Methodology
### Bess
\begin{array}{c}p_{t}^{\text{POD}_{\textit{chain}_{\textit{inj}}}}=0,\text{ if }p_{t}^{\text{BESS}_{\textit{data}}C}\times p^{\text{BESS}_{\textit{num}}}\leq p _{t}^{\text{POD}_{\textit{fund}}}\\ p_{t}^{\text{POD}_{\textit{chain}_{\textit{inj}}}}=p_{t}^{\text{BESS}_{ \textit{data}}C}\times p^{\text{BESS}_{\textit{num}}}-p_{t}^{\text{POD}_{ \textit{fund}}},\text{ otherwise.}\end{array} \]  
To ensure that \(p_{t}^{\text{POD}_{\textit{chain}_{\textit{inj}}}}\) represents only the portion of charging power withdrawn from the grid and intended for future grid injection, a constraint is imposed such that the total sum of \(p_{t}^{\text{POD}_{\textit{chain}_{\textit{inj}}}}\) over the optimization horizon must be less than or equal to the total sum of \(p_{t}^{\text{POD}_{\textit{chain}_{\textit{inj}}}}\). This ensures that only the portion of grid-supplied charging power that is actually reinjected can be valued as NIE. The full framework is implemented in HOMES using a set of mixed-integer linear constraints reported below. Equation (32) shows the decomposition of the actual BESS charging power into two components: one that can be classified as NIE and a residual (fictitious) component representing the remaining portion of charging power. Equation (33) ensures that the portion of the charging power that is classified as negative injection complies with the criteria described above, based on the comparison with internally generated power. Similarly, Equations (34) and (35) apply the same logic to the discharging power. Finally, Equation (36) ensures that the variable \(p_{t}^{\text{POD}_{\textit{chain}_{\textit{inj}}}}\) represents only the charging power withdrawn from the grid that has been subsequently re-injected into the grid. \[p_{t}^{\text{BESS}_{\textit{data}}C}\times p^{\text{BESS}_{\textit{num}}}=p_{ t}^{\text{POD}_{\textit{chain}_{\textit{inj}}}}+p_{t}^{\text{POD}_{\textit{chain}_{ \textit{grad}}}}, \tag{32}\]  
\[p_{t}^{\text{POD}_{\textit{chain}_{\textit{pred}}}}\geq p_{t}^{\text{BESS}_{ \textit{data}}C}\times\left(1-y_{t}^{\text{POD}_{\textit{chain}_{\textit{inj}}}} \right)+p_{t}^{\text{POD}_{\textit{{chain}_{\textit{inj}}}}}\leq y_{t}^{\text{ POD}_{\textit{chain}_{\textit{inj}}}}, \tag{33}\]\[p_{t}^{BESS_{disi,AC}}\times p^{BESS_{nom}}=p_{t}^{POD_{disinj}}+p_{t}^{POD_{ discons}}\,, \tag{34}\] \[p_{t}^{POD_{discons}}\geq p_{t}^{BESS_{disAC}}\times\left(1-y_{t}^{POD_{ disinj}}\right)+p_{t}^{POD_{load}}\times y_{t}^{POD_{disinj}}\,,\] (35) \[\sum_{t=1}^{T}\biggl{(}p_{t}^{POD_{disinj}}\times\Delta t\biggr{)} \leq\ \sum_{t=1}^{T}\biggl{(}p_{t}^{POD_{disinj}}\times\Delta t\biggr{)}. \tag{36}\]  
Subsequently, it is necessary to define a set of constraints to model the cost components of the electricity bill in accordance with the Italian tariff regulatory framework. Specifically, the bill is divided into three main components:  
* An energy-based component expressed in EUR/kWh. * A power-based component related to the monthly peak power, expressed in EUR/kW,
* A fixed component expressed in EUR/POD. The variable tariffs in EUR/kWh include energy consumption charges, variable system charges, and capacity market charges, as detailed in Equation (37). Equation (38) shows that the energy withdrawn from the grid (including associated losses) is subject to a time-of-use (ToU) tariff structure. Conversely, negative injection (NIE) is valued at the zonal DAM price. Equation (39) models the application of EUR/kWh tariffs to the net withdrawn energy (i.e., grid imports net of negative injection) for dispatching costs, network charges, and metering services. Finally, Equation (40) accounts for the capacity market charges, which are applied based on a tariff set every three months by Terna. This peak shaving tariff distinguishes between system peak and off-peak hours, with significantly different rates.