## 2 Materials and Methods
### Optimization Model
#### 2.3.3 Mathematical Formulation  
The mixed-integer linear programming model that minimizes energy and investment costs, and ensures that the demand is met, is given by (5)-(27).  
\[\min\ \sum_{j\in T}cWT(j)\cdot y(j)+\sum_{\ell\in B}cb(\ell)\cdot v(\ell)+ \sum_{t=1}^{pb}\sum_{i\in P}\sum_{j\in T}\big{(}x(i,j)\cdot c(i,j)\cdot(1+rr) ^{t-1}\big{)} \tag{5}\]  
\[\text{s.t.}\ \ \sum_{j\in T}w(j)=1 \tag{6}\]  
\[\sum_{j\in WT}y(j)\leq 1 \tag{7}\]  
\begin{table}
\begin{tabular}{c c c} \hline \hline
**Data** & \multicolumn{2}{c}{**Battery Set, \(B\)**} \\  & **1** & **2** \\ \hline Name & LG Resu13 & BYD LVS 8.0 \\ \(cb\) & 5679 EUR & 3815 EUR \\ \(kb\) & 12.4 kWh & 8.0 kWh \\ \hline \hline \end{tabular}
\end{table}
Table 4: Description of battery set: designation, unit cost, and capacity.  
\begin{table}
\begin{tabular}{c c c} \hline \hline
**Data** & \multicolumn{2}{c}{**Wind Turbine Set, \(WT\)**} \\  & **1** & **2** \\ \hline Name & Aeolos-V 10 kW & Aeolos-H 20 kW \\ \(cWT\) & 18,364.15 EUR & 26,589.08 EUR \\ \hline \hline \end{tabular}
\end{table}
Table 3: Description of wind turbine set: designation and unit cost.  
\[\sum_{j\in B}bb(j)\leq 1 \tag{8}\]  
The objective function (5) represents the total cost of investment in wind turbines and batteries along with the value of energy purchased from the grid for the adopted period. Constraint (6) forces the choice of a tariff for the purchase of energy for the building. Constraints (7) and (8) prevent the choice of more than one type of turbine or battery.  
\[s(i)\leq\sum_{j\in B}kb(j)\cdot v(j),\ i\in P \tag{9}\]  
\[db(i)\leq s(i),\ i\in P \tag{10}\]  
\[ab(i)\leq\sum_{j\in B}kb(j)\cdot v(j),\ i\in P \tag{11}\]  
\[s(i+1)=s(i)+ab(i)-db(i),\ i\in 1\ldots np-1 \tag{12}\]  
The constraints (9)-(12) check the conditions for charging, discharging, and stocking the batteries, so that the operation of the energy storage system works correctly.  
\[db(i)+\sum_{j\in T}x(i,j)+\sum_{\ell\in WT}pw(i,\ell)\cdot y(\ell)=d(i)+ab(i), \ i\in P \tag{13}\]  
Constraints (13) ensure that, for all periods, the energy demand is met and the power surplus is stored. It provides that all the energy used from the batteries with the energy purchased from the power grid and the energy produced by the wind turbines is equal to the demand plus the energy stored in the batteries.  
\[db(i)\leq Mb\cdot z(i),\ i\in P \tag{14}\]  
\[z(i)\leq db(i),\ i\in P \tag{15}\]  
\[ab(i)\leq Mb\cdot zz(i),\ i\in P \tag{16}\]  
\[zz(i)\leq ab(i),\ i\in P \tag{17}\]  
\[z(i)+zz(i)\leq 1,\ i\in P \tag{18}\]  
Regarding the binary variables of charge/discharge of the ESS, constraints (14)-(18) prevent a charge and discharge from happening simultaneously. According to constraints (14) and (15), if there is a discharge from a battery in a period \(i\in P\), \(z(i)\) assumes value \(1\); otherwise, it assumes a value of \(0\). If there is a charge, \(zz(i)\) assumes the value \(1\), according to the constraints (16) and (17). Constraint (18) prevents that the binary variables of charge and discharge having values of \(1\) at the same period \(i\in P\).  
\[\sum_{i\in P}x(i,j)\leq M\cdot w(j),\ j\in T \tag{19}\]  
\[w(j)\leq\sum_{i\in P}x(i,j),\ j\in T \tag{20}\]  
\[v(j)\leq Mv\cdot bb(j),\ j\in B \tag{21}\]\[bb(j)\leq v(j),\ j\in B \tag{22}\]  
Constraints (19) and (20) prevent more than one tariff \(j\in T\) from being used, whereas constraints (21) and (22) restrain the use of more than one type of ESS, \(j\in B\), in the model.  
\[\sum_{i\in P}zz(i)\cdot pb\leq cycles \tag{23}\]  
Constraint (23) ensures that the charge and discharge cycles of the batteries that limit the battery's life, in this case, \(cycles=6000\), are not exceeded.  
\[x(i,j)\geq 0,\ \ i\in P,j\in T \tag{24}\]  
\[v(i)\in Z,\ \ i\in B \tag{25}\]  
\[ab(i),\ db(i),\ s(i)\geq 0,\ \ i\in P \tag{26}\]  
\[z(i),\ zz(i),\ w(j),\ y(i),\ bb(\ell)\in\{0,1\},\ \ j\in T,i\in WT,\ell\in B \tag{27}\]  
Constraints (24)-(27) establish the domain of the variables.