## 2 Methods
### Design of the Optimal EMS  
This section presents the design of the optimal EMS (first part of this contribution). The optimal EMS is an MPC controller. At each sampling time \(k\), the optimal EMS performs the following steps:  
1. Acquires process state information (demands, TES state of charge (SOC), prices, etc.). 2. Acquires a prediction of the energy demand profiles for a given time horizon. 3. Calculates the sequence of control action values that minimize the operating cost of the micro-CHP system within the prediction horizon. 4. Applies the values of instant \(k\) and returns to step 1. For the calculation in step 3, the optimal EMS solves a MILP type optimization problem. The objective function (operating cost) is evaluated within a given time window, namely, from the current instant \(k\) to the future instant \(k+HP\). The constant \(HP\) is the prediction horizon. The predictions of energy demands are assumed to be perfect. This is the best case for the optimal EMS. Next, the MILP optimization problem is formulated. This formulation follows closely the one developed by [PERSON] et al. (1998) and later also used by [PERSON] (2000). The optimization problem consists of minimizing the objective function \(\mathbf{f}^{\mathbf{T}}\mathbf{x}\), Equation (2), subject to the constraints defined in Equations (3)-(5). \[\min_{\mathbf{x}}\mathbf{f}^{\mathbf{T}}\mathbf{x} \tag{2}\]  
\[\mathbf{A}\mathbf{x}\leq\mathbf{b} \tag{3}\]  
\[\mathbf{A}_{\mathbf{eq}}\mathbf{x}=\mathbf{b}_{\mathbf{eq}} \tag{4}\]  
\[\mathbf{l}\mathbf{b}\leq\mathbf{x}\leq\mathbf{ub} \tag{5}\]  
The vector \(\mathbf{x}\) in (2) is the vector of decision variables. There is a distinction between _decision variables_ and _control actions_. For a given instant \(k\), there are 16 decision variables (Nomenclature section) but only 4 control actions: \(Pe_{SYref_k}\), \(PhH_{ABref_k}\), \(Phl_{Dref_k}\), and \(ON/OFF_{k}\) (Figure 1). \(Pe_{SYref_k}\) is the sum of the piecewise electrical outputs, Equation (6), and \(ON/OFF_{k}=Y_{T0_{k}}\). \[Pe_{SYref_k}=Pe_{T0_{k}}+Pe_{T1_{k}}+Pe_{T2_{k}}+Pe_{T3_{k}}+Pe_{T4_{k}} \tag{6}\]  
The objective function \(\mathbf{f}^{\mathbf{T}}\mathbf{x}\) is the operating cost of the micro-CHP system, Equation (7), whose coefficients are given by Equations (8)-(12). \[ \begin{split} F(\mathbf{x})=\sum_{i=0}^{HP-1}\left(\sum_{n=0}^{4 }c_{Pe_{Tn}}Pe_{Tn_{k+i}}+c_{PhH_{AB}}Ph_{ABref_{k+i}}+c_{Phl_{D}}Ph_{Dref_{k+ i}}+\right.\\ \left.+c_{Pe_{hup}}Pe_{hup_{k+i}}+c_{Pe_{cell}}Pe_{sell_{k+i}}+S_ {st_{k+i}}+S_{off_{k+i}}\right)\end{split}  \tag{7}\]  
\[c_{Pe_{Tn}}=\frac{T_{s}Pr_{ng}K_{ng_{n}}}{60\,re_{SY_{N}}(1-D)}\qquad\forall n \in\{0,\ldots,4\} \tag{8}\]  
\[c_{Ph_{AB}}=\frac{T_{s}Pr_{ng}}{60\,rth_{AB}} \tag{9}\]  
\[c_{Phl_{D}}=\frac{T_{s}Pr_{el}K_{cool}}{60} \tag{10}\]  
\[c_{Pe_{hup}}=\frac{T_{s}Pr_{el}}{60} \tag{11}\]  
\[c_{Pe_{cell}}=-\frac{T_{s}Pr_{FiT}}{60} \tag{12}\]  
The following describes the constraint Equations (3)-(5) that the solutions of Equation (2) must satisfy. The SOC of the TES must be kept within minimum and maximum limits:  
\[SOC_{min}\leq SOC_{k+i}\leq SOC_{max}\qquad\forall i\in\{1,\ldots,HP\} \tag{13}\]  
The micro-CHP system model includes equations that model the electrical and thermal performances of the system, see [PERSON] et al. (1998), Equations (1) and (2), and Figure 2. These equations are nonlinear. In order to apply the MILP methodology, the model must be linear. It is therefore necessary, as a preliminary step, to linearize these equations. The piecewise linearization of the electrical performance curve is described in Appendix A. This piecewise linearization entails nine additional constraints, Equations (14)-(18). These constraints force the dispatch order to be T0, T1,..., T4 [19]. The micro-CHP system startup time (\(t_{d}\)) is incorporated into the formulation as in [29].