## 4 Methodology
### Metric  
To evaluate the performance of optimization algorithms, we measured the energy consumed by the central heating (CH) installation adjusted with outside temperature. For normalization, a _degree days metric_--the integral of a function of time that varies with outdoor temperature [40]--can be used (more specifically, heating degree day (HDD), which is designed to quantify the demand for energy required to heat a building [41]). In this study, we use more fine-grained metrics that make use of outdoor temperature measured every hour instead of a daily average. All temperature measurements were made by TCR/07 outdoor temperature sensors. Central heating energy consumption was measured by QFR022 energy meter. Having these values meant we were able to make a measurement and verification (M&V) report [42]. The main advantage of M&V is that it isolates the energy effect after modernization, which is often disturbed by other processes occurring in the facility. We used the following equation to quantify CH energy consumption:  
\[E_{1}(\{t_{i}\}_{i=1}^{n})=\frac{\sum_{i=1}^{n}Q(t_{i})}{\sum_{i=1}^{n}T(t_{i})} \tag{1}\]  
where \(\{t_{i}\}_{i=1}^{n}\) denotes sequence of length \(n\) when the measurements took place. In other words, every element of this sequence is the time of measurement. \(Q(t)\) is heating power used by CH installation at time \(t\). \(T(t)\) is defined as follows, similarly to definitions in [40,41]:  
\[T(t)= \begin{cases}0&\text{for temperature $x$ in ${}^{\circ}$C at time $t$ such as $x>18\,^{\circ}$C$}\\ 18-x&\text{for temperature $x$ in ${}^{\circ}$C at time $t$ such as $x\ \leq 18\,^{\circ}$C$}\end{cases} \]  
The metric defined by (1) quantifies the ratio of total energy consumption during a specific period to the difference between the temperature outside and \(18\,^{\circ}\)C (for all hours when the temperature was lower than \(18\,^{\circ}\)C), summed over the same time period. A lower value of the metric means more effective usage of the thermal energy. The reference temperature of \(18\,^{\circ}\)C is the base temperature for European countries [43, 44, 45]. As a secondary metric, we used the following equation to quantify thermal discomfort related to underheating:  
\[E_{2}(\{t_{i}\}_{i=1}^{n})=\frac{1}{n}\sum_{i=1}^{n}D(t_{i}) \tag{2}\]  
Figure 7: A two-layer algorithm for heating energy control inside a residential building. The arrows mark the direction of information flow. The local control layer has bi-directional communication with valves, pumps, and other sensors and actuators, so it can read present values and send commands to achieve desired set points. The optimization layer has access to information from indoor temperature sensors and the weather forecast service. It can adjust set points of the local control layer to a certain degree in order to minimize energy consumption. where \(\{t_{i}\}_{i=1}^{n}\) denotes sequence of length \(n\) when the measurements took place. In other words, every element of this sequence is the time of measurement. \(D(t)\) is thermal discomfort at time \(t\). \(D(t)\) is defined as follows, similarly to the definition in [29]:  
\[D(t)= \begin{cases}0&\text{for temperature $x$ in ${}^{\circ}$C at time $t$ such as $x>21\,{}^{\circ}$C}\\ (21-x)^{2}&\text{for temperature $x$ in ${}^{\circ}$C at time $t$ such as $x\leq 21\,{}^{\circ}$C}\end{cases} \]  
The reference temperature of 21 \({}^{\circ}\)C is the recommended indoor temperature in living spaces of a residential building [40]. As a tertiary metric, we used the following equation to quantify overheating:  
\[E_{3}(\{t_{i}\}_{i=1}^{n})=\frac{1}{n}\sum_{i=1}^{n}O(t_{i}) \tag{3}\]  
where \(\{t_{i}\}_{i=1}^{n}\) denotes sequence of length \(n\) when the measurements took place, providing that on the day of the measurement the outdoor temperature was less than 21 \({}^{\circ}\)C. In other words, every element of this sequence is the time of measurement. \(O(t)\) is overheating at time \(t\). \(O(t)\) is defined as follows:  
\[O(t)=