## 2 Optimisation Methods and Modelling
### CHP Switch (CHPS) Algorithm  
As mentioned in the Introduction, energy prediction at building level has an average error of approximately 5% [24] whilst short-term prediction level has worse performance. This suggests that a more precise model should be proposed to control the power generation system (CHP system). Close study of household electrical demand has revealed that it usually changes rapidly and after changing will remain in the same state for several minutes or longer. However, the heating demand fluctuates more smoothly and on slower time scales. After careful study of these two time series, in [33] it was found that the electricity consumption and heat consumption in every minute can be effectively predicted with the following simple equations:  
\[P_{pele}(n\ +\ 1)=\ P_{ele}(n) \tag{6}\]  
\[P_{plant}(n\ +\ 1)\ =\ \sum_{i=n}^{i=n-9}\frac{P_{heat}(i)}{10} \tag{7}\]  
In Equations (6) and (7), \(P_{pele}(n\ +\ 1)\) and \(P_{plant}(n\ +\ 1)\) represent the predicted electricity demand and heat demand in \((n+1)\)th minute, respectively. \(P_{ele}(n)\) is the electricity consumption in the \(n\)th minute and \(P_{heat}(i)\) is the heat consumption in \(i\)th minute. In order to evaluate the accuracy of this load prediction approach, more than a hundred sets of daily load time series were tested. This data showed that on a minute by minute base 90.5% of the time the electrical demand is identical to the previous minute. Clearly there will be some errors between the predicted demands and actual demands by using Equations (6) and (7). This is shown in [33]. However, this has very small influence if heat and electricity generation are considered together. Moreover, the main novelty of [33] is that this paper treats the predicted demands as a reference input just to control the CHP binary switch, whereas other studies, using more sophisticated statistical methods to predict demand, must deal with the whole system's optimisation. Used specifically to control the switching of CHP, Equations (6) and (7) yield a very low error rate of 3% in terms of time dimension, and have vastly reduced computation times and complexity compared to statistical methods. After calculating the predicted demands, the benefit that CHP will give in the next minute can be expressed as:  
\[B_{dpp}\ =\ H_{dpp}\ \times\ \frac{H_{p}}{H_{d\!f}}\times 100\ +\ E_{dpp}\times E_{p} \tag{8}\]  
In Equation (8), \(B_{dpp}\) is the benefit, in monetary terms that CHP can generate at the next minute if it is switched 'on'. \(H_{dpp}\) and \(E_{dpp}\) are the effective value of heat and electrical power contribution due to CHP. \(H_{p}\) and \(E_{p}\) represent the gas and electricity prices. \(H_{d\!f}\) is gas to heat transfer efficiency. The cost to implement CHP in the next minute can be written as:  
\[C_{dpp}=\ R_{dpp}\times H_{p} \tag{9}\]  
where \(C_{dpp}\) is the energy cost of CHP working at the state of rated power and \(R_{dpp}\) represents the rated power (including heat power, electrical power and losses) of the CHP system. By comparing with the benefit that CHP can generate and the energy cost of CHP working at the state of rated power, the state of CHP can be decided. This algorithm significantly reduces the error introduced by energy prediction, because it uses the predicted heat demand and electricity demand together to control the 'CHP switch'. The heat output of CHP is normally much greater than the electricity output (two to four times higher), and the errors of heat prediction are relatively small. This will reduce the error of 'CHP switch' model to some extent. Additionally, when the capacity of CHP is carefully designed and considering the fact that the domestic electricity price is usually much higher than the domestic gas price, the state of CHP is influenced bythe benefit that CHP can yield. As long as the benefit of implementing CHP is greater than the energy cost of CHP working at the state of rated power, CHP will be switched on.