## 3 Numerical Model
### Optimization Process and Number of Iterations  
In full-load mode, at each one of the 48 time steps, the turbine can be either on (SP = 100) or off (SP = 0). Thus, there are \(2^{48}\) possible operating profiles. The number is even higher when partial-load is considered, since \(7+1\) different operating points are possible (see Table 1). Exploring the complete space of possible solutions would require a huge amount of computational resources. Nevertheless, a large amount of solutions either do not fulfill the demand (too many SP = 0) or exceeded the amount of hot water that can be either consumed or saved in the tank. For this reason, \"sampling\" a smaller space of candidate solutions is sufficient to have an idea of the optimal operating profile. This procedure is explained in this section. First of all, random solutions must be constrained within specific bounds. In order to have an equal probability of having the system operating or not, the SP values are searched within the bounds [\(-\)60, 100]. In fact, only SP values higher than or equal to 20 make it operate. Candidate solutions are pre-filtered such that, when SP \(<\) 20 are generated, they are automatically set to 0. However, it was noted that, by applying the SP pre-filtering in the interval [\(-\)60, 100], very expensive solutions were found. These solutions fulfill the  
Figure 6: Flowchart of the developed optimization algorithm for the MGT-CHP system. Each randomly generated operative profile is tested. The energy demands are assigned as the input, based on environmental parameters and building occupancy and size. Battery and thermal storage sizes are assigned by the user, and their charge is updated for every time step. If the system fulfills the demand, the operative profile cost is computed; if not, it is discarded and the next one is analyzed. energy demands, but do not minimize the costs. In fact, less expensive solutions could be found if the random search were influenced to look within more \"low-power\" bounds. A satisfactory interval was found to be \([-60,\,40]\) for the full-load mode: if \(\text{SP}<20\), \(\text{SP}\) is set to zero and the system is off, as usual. If \(20<\text{SP}<40\), however, \(\text{SP}\) is set to \(100\). In so doing, the solver is conditioned to look in a space where the system has a \(80\%\) probability to be off and \(20\%\) to be on. This conditioning also produced candidate solutions that fulfilled the demand, but with a final cost definitely lower. For the partial-load, a similar approach was taken. Three different intervals were tested: \([-60,\,100]\), \([-60,\,70]\), and \([-60,\,40]\). The first interval considers all the possible operating points; the second and the third consider only SP up to \(70\) and \(40\), respectively. Figure 7 shows how the operative cost is influenced by the number of candidate solutions considered. Simulations were performed with \(n=1\)k, \(2\)k, \(3\) k, \(5\)k, \(10\)k, \(50\)k, and \(100\)k solutions. Results for full-load and partial-load operations are reported in Figure 7a,b, respectively. Both configurations show an asymptotic decreasing trend, since more candidates allow a higher chance to find a better solution. However, it can be seen that the curves flatten remarkably between \(50\)k and \(100\)k. Between these two points, there is a \(0.11\%\) variation (\(0.010\) EUR) and \(0.30\%\) variation (\(0.031\) EUR) for full-load and part-load mode, respectively. Hence, exploring a subset of \(n=100\)k candidate solutions, instead of \(2^{48}\) or \(8^{48}\), provides a satisfactory accuracy with much less computational cost. Future analyses could consider switching to a more efficient solver strategy instead of random search, for example a particle-swarm search, if similar accuracy were obtained with less computational time. In Figure 7, it can be seen that the solutions generated within the \([-60,\,40]\) interval have small room for variation and provide very similar costs.