## 3 Proposed Energy-Water Management System
### Water Management System  
The WMS is based on the MPC approach and considers a prediction horizon of \(N_{y}=28\) days and a sampling time of one day. This WMS optimization gives the irrigation volumes that maximize the benefits expected from all \(N_{c}\) crops for the \(N_{ag}\) farmers over the prediction horizon of \(N_{y}\), with \(N_{c}=\sum_{g=1}^{N_{ag}}N_{c,g}\):  
\[\max_{\hat{V}_{r,c}} \sum_{c=1}^{N_{c}}B_{c}\cdot Y_{r,c}(k+N_{y})- \tag{15a}\] \[\sum_{c=1}^{N_{c}}C_{\omega_{c}}\cdot g(Y_{r,c}(k),\omega_{c}),\] (15b) s.t. \[Y_{r,c}(k+N_{y})=Y_{r,c}(k-1)\cdot\prod_{i=k}^{k+N_{y}}\left[1-K _{y,c}(i)\cdot(1-K_{s,c}(i))\right]^{\frac{1}{M_{c}}},\] (15c) \[Y_{r,c}(k)=1\] (15d) \[K_{s,c}(k)= \begin{cases}\frac{TAW(k)-D_{r}(k)}{TAW(k)-RAW(k)}& \text{if }RAW(k)<D_{r}(k),\\ 1&\text{otherwise},\end{cases} \] (15e) \[D_{r}(k)=D_{r}(k-1)-P(k)+RO(k)-1,000\cdot\frac{\hat{V}_{r,c}(k)}{A _{c}}-CR(k)+DP(k)+ET_{p}(k),\] (15f) \[D_{r}(0)=1.000\cdot(\theta_{FC}-\theta_{0})\cdot Z_{r}(0),\] (15g) \[g(Y_{r,c}(k),\omega_{c})=\max\left\{0,(\omega_{c}-Y_{r,c}(k)) \right\}, \tag{15h}\]  
where the first term of the objective function in Equation (15a) corresponds to the maximization of the relative benefits due to the relative yields \(Y_{r,c}(k+N_{y})\) of the crops under a horizon of \(N_{y}\). The coefficient \(B_{c}\) is the relative benefit, which includes the benefits of cultivation in the community and is equivalent to [20]:  
\[B_{c}=Y_{p,c}P_{c}A_{c}, \tag{16}\]  
where \(Y_{p,c}\) is the optimum yield of crop \(c\) in kg/ha, \(P_{c}\) is the expected price of crop \(c\) in \(\$/\)kg, and \(A_{c}\) is the cultivated area in ha. These data are obtained from the Office of Agrarian Studies and Policies [27] and from reports of the _Food and Agriculture Organization of the United Nations_[34; 37]. The second term of the objective function in Equation (15b) is the penalty for not meeting a minimum expected relative return of \(\omega_{c}\) on the crop, where \(C_{\omega_{c}}\) is a high relative cost and \(g(Y_{r,c}(k),\omega_{c})\) is a function that determines the gap needed to reach the minimum expected return \(\omega_{c}\). The following terms correspond to the restrictions of the WMS formulation. Equation (15c) is the expected relative return at the end of the horizon \(N_{y}\), where \(Y_{r,c}(k-1)\) is the relative yield at time \(k-1\), \(K_{y,c}(k)\) is the sensitivity of crop \(c\) to the lack of water, \(K_{s,c}(k)=\frac{ET_{g,c}(k)}{ET_{p,c}(k)}\) is the ratio between the actual and potential evapotranspiration for crop \(c\), and \(M_{i,c}\) is the duration in days of the corresponding growth stage of crop \(c\). The initial condition of the crop yield in Equation (15d) is equal to 1 (maximum value); Equation (15e) gives the ratio between the actual and potential evapotranspiration; Equations (15f) and (15g) calculate the root zone depletion and its initial condition, respectively; and Equation (15h) defines the penalty function \(g(Y_{r,c}(k),\omega_{c})\). Associated with these formulations is the constraint on the extraction of water for all \(c\) crops from the aquifer, which must be less than its recharge volume \(R\):  
\[\sum_{c=1}^{N_{c}}\bar{V}_{r,c}(k)\leq R. \tag{17}\]  
The optimization problem defined by the objective function in Equations (15a) and (15b) and the constraints in Equations (15c)-(15h), (16) and (17) provides the control action given by the required irrigation volumes at each sampling time (i.e., each day). In the next time step, a new optimal control action is determined (rolling horizon). The 28-days-ahead predictions for temperature, radiation, wind speed, and precipitation based on auto-regressive models are used for the WMS based on MPC. To solve the WMS optimization problem we apply a genetic algorithm to the optimization variables, where each gene on the chromosome represents a daily irrigation volume for a culture \(\bar{V}_{r,c}(k)\dots\bar{V}_{r,c}(k+N_{y}-1)\) over a prediction horizon of \(N_{y}\) days.