# Optimization of Heat Pump Systems in Buildings by Minimizing Costs and CO\({}_{2}\) Emissions
## 2 Methodology  
The paper examined the selection of the optimal heat production and supply system for different types of buildings. The main objective of the analysis was to select a heat production and supply system in such way that the total costs of the system and its operation are minimized over the period analyzed while also meeting the requirements of reducing CO2 emissions. The model could cover various types of buildings, such as renovated and unrenovated buildings, apartment buildings, public buildings, supermarkets, etc. The optimization is performed taking into account various technical, economic, environmental, and social factors. In order to construct a mathematical optimization model, various types of heat pumps, electric heaters, and their combinations in a heat production and supply system had to be analyzed. The optimization model included constraints to ensure that the capacity of the heating system selected for each building was sufficient to meet the actual monthly and the peak hourly heat demand. The monthly variable operating modes of the selected technologies were taken into account depending on the heat demand of the analyzed buildings and the maximum capacity of the heating system in different months. Variables reflecting the operating modes of the analyzed technologies each month show the time span across which the analyzed technology has to operate in order to meet the total monthly heat demand. The model also considered the degradation of heating technologies and their decreasing efficiency in the long term. The problem of selecting the optimal heating system was solved using MINLP [33] and multi-objective optimization methods. The solutions for the optimization problem include the optimal number of HPs and EHs as well as the optimal operating modes of these technologies for each month during the analyzed period. The solutions were obtained using the branch and reduce algorithm. The MINLP problem was solved using the Python programming language, the Pyomo library, and the BARON solver [34], which is a popular optimization software known for finding globally optimal solutions for complex nonlinear problems. The formulation of the optimization problem and the solution process are presented in Figure 1.  
The methodology framework for the optimization problem, illustrated in Figure 1, was divided into four main parts: data, assumptions, optimization, and results. The workflow begins by collecting and analyzing data on the building's specific characteristics and heat consumption as well as forecasting heat demand for a mid-term period. Assumptions are then made about prices for electricity, natural gas, and CO\({}_{2}\) emissions, and the main parameters for HPs and EHs are calculated. A MINLP multi-objective optimization problem is then formulated [35; 36; 37] and solved for the selected buildings. The results are further analyzed through post-optimization analysis by presenting the performance of various technical and financial indicators. The objectives of the analysis were to minimize the total heating costs (Equation (1)) and GHG emissions of the installed heating system (Equation (2)). The total heating costs consist of the price of HPs and EHs as well as their installation, the maintenance costs of the selected technologies, the price of the electricity needed for the operation of HPs and EHs, and the price of the natural gas consumed during the operation of hybrid HPs. The mathematical optimization model was constructed taking into account these two objectives and various constraints:  
\[\min f(x,y)=\sum_{i=1}^{n}\sum_{j=1}^{t}\sum_{k=1}^{m}c_{ijk}y_{ijk}x_{i}+\sum _{i=1}^{n}\bigl{(}\widetilde{c}_{i}+\hat{c}_{i}+m\hat{c}_{i}\bigr{)}x_{i}, \tag{1}\]  
\[\min(x,y)=\sum_{i=1}^{n}\sum_{j=1}^{t}\sum_{k=1}^{m}\widetilde{c}_{ijk}y_{ijk} x_{i}, \tag{2}\]  
subject to  
\[\sum_{i=1}^{n}q_{ijk}y_{ijk}x_{i}\geq Q_{jk}, \tag{3}\]  
\[\sum_{i=1}^{n}x_{i}q_{ij1}\geq Q_{max_{j}}, \tag{4}\]  
Figure 1: The scheme of the methodology framework for the optimization problem.