## 3 Modeling Approach
### Multi-Energy System
#### 3.2.3 Optimization  
The objective function is the minimum total Net Present Cost (NPC) of the energy system, computed in Equation (15).  
\[\mathit{ObjectiveFunction}=\min(\mathit{NPC}) \tag{14}\]  
\[\mathit{NPC}=\mathit{Inv}+\sum_{n=1}^{N}\frac{\mathit{YCC}}{(1+e)^{n}}+ \mathit{Cost}_{rep} \tag{15}\]  
where \(\mathit{Inv}\) is the total investment cost, \(\mathit{YCC}\) is the yearly constant cost of the project, \(N\) is the project lifetime, \(e\) is the discount rate factor, and \(\mathit{Cost}_{rep}\) is the cost of components replacement (in this case defined for batteries only).  
The total investment cost is calculated as the summation of the specific investment costs multiplied by the total installed capacity of each component. The specific costs are provided in Table S1 in the Supplementary Information and are considered as the total installed cost, including hardware costs (component, cabling costs), and installation costs (connection costs including inverters cost if required), per unit of capacity.  
The total investment is evaluated by summing the capital costs of all the installed components, computed based on their specific costs (expressed in USD/kW for generation technologies and USD/kWh for storage). Equation (16) reports the detailed calculation of the investment cost, in which \(\mathit{fun}\) represents the percentage of the investment that is financed by a bank (or any another entity).  
\[Inv= \Bigg{[}N_{PV}C_{PV}U_{PV}+C_{bat}U_{bat}+C_{gen}U_{gen}\] \[+ \sum_{k=1}^{n}(N_{SC}(k)U_{SC}C_{SC}+U_{Tank}C_{SOCtank}(k) \tag{16}\] \[+ U_{Boiler}C_{Boiler}(k)+U_{Res}C_{Res}(k))\Bigg{]}\cdot(1-fun)\]  
\(YCC\) is calculated as shown by Equation (17), where \(Cost_{O\&M}\) is the cost of operation and maintenance of the system and \(Cost_{finum}\) is the fixed-rate loan payment, while the other variables represent costs associated with the use of fossil fuels and the cost of losing the unmet load (\(LL_{cost}\)).  
\[YCC=Cost_{O\&M}+Cost_{finum}+\sum_{t=1}^{T}Cost_{Dised}(t)+\sum_{t=1}^{T}Cost_{ gas}(t)+LL_{cost}(t) \tag{17}\]  
\(Cost_{finum}\) in Equation (18) is computed as per Equation (18), where \(i\) is the number of years in which the loan has to be paid back and \(r\) is the interest rate.  
\[Cost_{finum}=\frac{Inv\times fun\times r}{1-\left(1+r\right)^{-i}} \tag{18}\]  
The cost of components replacement is finally computed as per Equation (19), where \(y\) is the number of years after which a battery is replaced.  
\[Cost_{rep}=\frac{C_{bat}\times U_{bat}}{\left(1+e\right)^{y}} \tag{19}\]  
\[Cost_{rep}=\frac{C_{bat}\times U_{bat}}{\left(1+e\right)^{y}} \tag{20}\]  
Based on the NPC, the model also evaluates the Levelized Cost of Energy (LCOE) as in Equation (20),  
\[LCOE=\frac{NPC}{\sum_{n=1}^{N}\frac{E_{domum}}{\left(1+e\right)^{n}}} \tag{21}\]  
where \(E_{demand}\) is the total energy demand (electric and thermal) of the system.  
An overall system efficiency is also computed as per Equation (21),  
\[\eta_{overall}=\frac{E_{demand,net}}{\sum_{j}E_{supply,j}} \tag{22}\]  
where \(E_{demand,net}\) is the net (i.e., after subtracting the lost load) total energy demand, and \(E_{supply,j}\) is the total energy supplied by each \(j\)-\(th\) energy supply technology (such as diesel generators, PV panels, LPG boilers, and solar thermal collectors).