## 3 Monitoring System and Optimized Building Operation
### Optimization  
For optimization purposes, it was decided to apply GA for several reasons. One is that they are, e.g., compared to PSO (particle swarm optimization), more suited for global search. Their suitability is also underlined by the fact that many studies with the aim to optimize HVAC systems rely on evolutionary and in specific on genetic algorithms [30].  
In addition, compared to rule-based approaches, GA optimization is easier to be adapted for other use cases (flexible electricity tariffs, power markets, other system combinations) and not very sensitive to all events that are not covered within the rule-based approach, making it more adaptive and robust.  
Within this work, for optimization purposes, a communication and control interface between the model in INSEL and Python--in particular the DEAP (Distributed Evolutionary Algorithms in Python, [43]) framework--was established. Using 24 h forecasts of ambient temperature and global radiation, optimized schedules for the following day's heat pumps operation are created, addressing various optimization goals such as the highest self-consumption and lowest electricity costs in a flexible tariff model. Varying set point temperatures and switching on/off schedules of the heat pump were tested to charge buffer storages and also to increase the room temperature utilizing the building's thermal mass to store energy. Optimization time steps are 5 minutes, taking into account the  
\begin{table}
\begin{tabular}{c c c} \hline \hline
**Machine Learning Application** & **MAPE [\%]** & **MAE [kWh]** \\ \hline kNN Hourly & 108.67 & 0.27 \\ kNN Daily & 62.46 & 0.12 \\ DTR Hourly & 130.05 & 0.32 \\ DTR Daily & 80.51 & 0.16 \\ \hline \hline \end{tabular}
\end{table}
Table 3: Evaluation results of kNN and DTR modeling. MAPE: mean absolute percentage error, MAE: percentage mean deviation.  
Figure 22: DTR: Daily demand and prediction over approximately 25 days.  
minimum operation times of heat pumps [44] and also allowing small steps of demand increase to find a better optimum. Model settling time and rebound effects are also assessed and reduced by a model parametrization using real values and a certain running time span before and after the 24 h optimization period. Regarding flexible electricity tariffs, a special methodology was applied according to [45] to generate ToU (Time of Use) tariffs that create more incentives for the end users.  
In [46], it has been shown that varying the mutation and probability can reduce the amount of computational time by up to 50%. In [47], for a similar optimization goal, it was determined that a reduced number of simulation runs can be sufficient to find a nearby optimum since the forecast inaccuracy always brings an uncertainty, and therefore, an absolute optimum that applies to the reality cannot be found. Thus, a comprehensive iteration on the values of the algorithm operators (crossover probability, mutation probability) and its parameters (number of populations, number of generations) was carried out.  
The algorithm's target function e.g., for the optimization of self-consumption and/or a flexible electricity tariff, is the cumulated electricity cost and earnings over the prediction/optimization period described in the following equation.  
\[M_{total}=Q_{el,pre\_grid}*m_{PV}-Q_{el,h_{grid}}*m_{h\_tariff}-Q_{el,HP\_grid}*m _{HP\_tariff} \tag{7}\]  
with \(M_{total}\)[\(\xi\)] as the building's daily monetary balance, \(m_{PV}\)[\(\xi\)/kWh] as the PV feed in the tariff, \(m_{h\_tariff}\)[\(\xi\)/kWh] as the household electricity tariff, \(m_{HP\_tariff}\)[\(\xi\)/kWh] as the heat pump electricity tariff, \(Q_{el,pre\_grid}\)[kWh] as the daily amount of PV electricity to the grid, \(Q_{el,h\_grid}\)[kWh] as the daily amount of household electricity from the grid, and \(Q_{el,HP\_grid}\)[kWh] as the daily amount of heat pump electricity demand from the grid.