## 2 Materials and Methods
### Application of the Control Strategies to the WWTP
#### 2.3.2 Particular Characteristics of the Controllers Implementation  
The first issue to address when implementing the proposed controllers to the BSM1 plant is the equivalence between the plant variables and the reduced model variables, and the model mismatch. It is assumed that the organic matter concentration, ammonium concentration, nitrates and nitrites concentration, and dissolved oxygen concentration in the second anoxic reactor and the fifth reactor, as well as the heterotrophic and autotrophic biomass concentration, are measurable variables. Then, these measurements are used to initially build the state vector for the reduced model, making the following equivalence:  
* Second anoxic reactor measures -> ammonium concentration (\(S_{\text{NH1}}\)), readily biodegradable substrate concentration (\(S_{\text{S1}}\)), nitrates and nitrites concentration (\(S_{\text{NO1}}\)), and dissolved oxygen concentration (\(S_{\text{O1}}\)).
* Fifth aerobic reactor measures -> ammonium concentration (\(S_{\text{NH2}}\)), organic matter concentration (\(S_{\text{S2}}\)), nitrates and nitrites concentration (\(S_{\text{NO2}}\)), and dissolved oxygen concentration (\(S_{\text{O2}}\)).  
The current values of the heterotrophic and autotrophic biomass concentration are used as constant parameters in the model. The set points for the reduced model are \(S_{\text{NO1}\_SP}=1\) mg/L and \(S_{\text{O2}\_SP}=2\) mg/L in the reduced model.  
In order to deal with the plant-model mismatch problem (see Figures 11-13), the difference between the BSM1 plant measurements and the reduced model outputs (denoted \(\text{e}_{\text{i}}\)) is computed at each sampling time, and it is used for bias correction of the set points and constraints limits in the optimization problem described above (Equations (2)-(2c)). For instance, see the following constraint (13) modification, where the bound has been decreased by the difference between the plant measurement and the model output: \(S_{\text{NH5}}(t)\leq 6-e_{\text{NH2}}\left[\frac{\text{grCOD}}{\text{m}^{3}} \right]\forall t\in\ [0,\ \tau_{N})\).  
Regarding the pure-EMPC implementation, performing an optimization of economic objectives to obtain the manipulated variables might lead the operation to the limits of the constraints in long time horizon, producing performance deterioration. In order to guarantee feasible solutions in the whole operating period, a first attempt of the optimization of the economic function is carried out, and if infeasibilities arise, a second optimization is executed using an HEMPC cost function (with a tracking term introduced to recover feasibility). This is a particular characteristic of the proposed pure EMPC,but all the controllers implemented in this paper use the manipulated variables values obtained in the previous sampling time when no feasible solutions are found in the current controller execution.  
Regarding the HEMPC's implementation, it is clear that this controller formulation has to deal with competing economics and control objectives, whose importance in the hybrid cost function is given by the weights \(w_{E}\) and \(w_{\mathrm{C}}\) (Equation (2) with \(w_{E}\
eq 0\), \(w_{\mathrm{C}}\
eq 0\)). In order to maintain the controlled variables at the desired reference value, it is necessary to consume energy, which increases the operating costs. Then, the minimization of the pumping energy (\(PE\)) and aeration energy (\(AE\)) produce a deviation respect to the desired set points, since not enough freedom degrees are available to meet both requirements at the same time. This deviation is tolerated while the constraints required for the effluent quality are fulfilled.