## 2 Optimisation Methods and Modelling
### Modified 'CHP Switch' Algorithm  
This algorithm offers a new way to control the 'CHP switch', however, the result is the state of CHP may be changed very frequently in a short time period. However, as mentioned in the introduction, the state of CHP cannot be changed too frequently due to operational restrictions such as ramp up time. Therefore, a modified 'CHP switch' algorithm is proposed in this paper to reduce the switching frequency of CHP. This algorithm ideally requires the load to be recorded for at least a year a beforehand. If this data is not available then the daily load can be approximated using heating degree days and total aggregated energy bills, or the load simulators such as those used in [34]. There are two ways to reduce switching frequency of CHP. The first one is to keep CHP on when it should be off, defined in this paper as 'Fill Gap', and the second way is to keep CHP off when it should be on, defined in this paper as 'Remove Glitch'. The 'Fill Gap' method is normally used when the CHP is switched off in a short time period and the energy price is relatively high. On the contrary, 'Remove Glitch' is normally used when the CHP is switched on for a very short time period and the energy price is relatively low. By using both 'Fill Gap' and 'Remove Glitch', the switching frequency can be reduced, which mitigates the cycling stress on the CHP unit and allows it to reach a steady state with maximum operating efficiency. However, for short periods, the CHP will generate surplus energy in the 'Fill Gap' and fail to meet load in the 'Remove Glitch' mode. This will decrease the efficiency slightly, but can be mitigated with energy storage, and supplemented by the grid if necessary. When using 'Fill Gap' or 'Remove Glitch' to reduce CHP switching frequency, it is necessary to have knowledge of the states of CHP in next few following minutes. To obtain states of the CHP in the next few more minutes, 'probability of CHP switch on' at each minute in a day is calculated based on historical data. To get the 'probability of CHP switch on' in a day, four steps are required. First, select all the relevant recorded daily energy consumption data from last year as sampling data i.e., data from the corresponding month of the previous year(s). Second, data that covers unusual events need to be removed from the sampling data (for example, days in which the occupants were absent or there was increased occupancy). When combined with occupancy data, for example from occupancy sensors, this process can be easily automated. If this leaves insufficient data to analyse, more data can be acquired from the year before last year or the load can be estimated as mentioned before through simulation and historical weather data. The third step is to record the states of CHP switch in every minute for all sampling data. This is obtained using the previous year's recorded demand and calculated using the basic control described in Section 2.2. The last step is to calculate the 'probability of CHP switch on' in each minute in a day using the following equation:  
\[P_{on}^{i}\ =\ \frac{N_{on}^{i}}{N} \tag{10}\]  
In Equation (10), \(P_{on}^{i}\) is the 'probability of CHP switch on' in the \(i\)th minute, \(N_{on}^{i}\) is the number of days that CHP is switched on in the \(i\)th minute and \(N\) is total days in the sampling data. After getting the 'probability of CHP switch on' in each minute in a day, CHPS algorithm can be modified as:  
* Step 1: Using Equations (6) and (7) to predict the next minute's electricity demand and gas demand;* Step 2: Comparing the benefit and cost of CHP in the next minute. If the benefit is greater than the cost, the state of CHP is set as 'possible on' and if the benefit is less than the cost, the state of CHP is set as 'possible off'. * Step 3: If the switch is 'on' at present and the state of CHP in next minute is predicted as 'possible on', the CHP is kept 'on' in the next minute.