# Switched Auto-Regressive Neural Control (S-ANC) for Energy Management of Hybrid Microgrids
## 3 Switched Auto-Regressive Neural Control (S-ANC)
### Formal Definition  
Initially, the system state, control, and output vectors are defined for the hybrid MG system in the S-MPC:  
The system-state vector of the MG is as follows:  
\[x(k)=[SOAcc^{l}(k)] \tag{7}\]  
where \(l\in\{BAT,FT,WT\}\). \(SOAcc^{BAT}(k)\), \(SOAcc^{FT}(k)\), and \(SOAcc^{WT}(k)\) are the state of the accumulators for the battery, hydrogen tank, and water tank, respectively. The system-control (input) vector of the MG is defined as follows:  
\[u(k)=[P_{3}(k);P_{4}(k);\ldots P_{11}(k)] \tag{8}\]  
The system-output vector of the MG is defined as follows:  
\[y(k)=[P_{1}(k);P_{2}(k)] \tag{9}\]  
Consider the discrete-time linear state-space system:  
\[\mathbf{X}(k+1)=\mathbf{A}_{x}x(k)+\mathbf{B}_{u}u(k) \tag{10}\]  
where \(k=0,1,2,\ldots,N_{P}-1\) symbolizes the discrete-time instant. Figure 4: Block diagram showing the introduction of S-ANC. By defining the following matrices:  
\[\mathbf{A}_{x}= \begin{bmatrix}I\\ A\\ A^{2}\\ \vdots\\ A^{Np_{p}}\end{bmatrix} \mathbf{B}_{u}= \begin{bmatrix}0&0&\cdots&0\\ B&0&\cdots&0\\ AB&B&\cdots&\vdots\\ \vdots&\vdots&\ddots&0\\ A^{Np-1}B&A^{Np-2}B&\cdots&B\end{bmatrix}  \tag{11}\]  
where  
\[A= \begin{bmatrix}1&0&0\\ 0&1&0\\ 0&0&1\end{bmatrix} \quad B^{T}= \begin{bmatrix}0&0&0\\ 0&0&0\\ \eta_{ch}&0&0\\ -\eta_{dis}&0&0\\ \eta_{ch}&0&0\\ -\eta_{dis}&0&0\\ 0&\eta_{ch,H_{2}}&0\\ 0&-\eta_{dis\prime H_{2}}&0\\ 0&0&\eta_{ch\prime H_{2}O}\\ 0&0&-\eta_{dis\prime H_{2}O}\end{bmatrix}  \tag{12}\]  
The linear state-space equation can be stated depending on the battery, fuel tank, and water tank equations as follows [75]:  
\[SOAcc^{l}(k+1)=SOAcc^{l}(k)+\frac{P^{j}_{a\to b}(k)-P^{j}_{b\to a}(k)}{C_{l}} \tag{13}\]  
where \(j\) is the energy flows, so \(j\in\{\textit{Power},\textit{Hydrogen},\textit{Water}\}\). \(a\to b\) represents the energy flows between accumulators and converters; for example, \(P_{4}\) is the power from the PV to the battery. Define the constraints for the hybrid MG: Energy flows from the PV, GR, BAT, FT, EL, FC, and WT are positive and subject to maximum values. \[ \begin{split} 0\leq P_{1}(k)=P_{LD}(k)-y_{a}(k)\leq P^{max}_{1}\\ 0\leq P^{j}_{m}(k)\leq P^{j^{max}}_{m}\end{split}  \tag{14}\]  
where \(P^{j^{max}}_{m}\) (\(m=1,2,\ldots,11\)) imply the maximum values of energy/matter flows. The sum of PV energy supplied directly for the load (\(P_{2}(k)\)) and the battery for the charging (\(P_{4}(k)\)) should be smaller than the energy flow from the PV array, (\(P_{PV}(k)\)). \[P_{2}(k)+P_{4}(k)\leq P_{PV}(k) \tag{15}\]  
The \(SOAcc^{l}\) is restricted between the minimum and maximum values [16]. \[SOAcc^{l^{min}}\leq SOAcc^{l}\leq SOAcc^{l^{max}} \tag{16}\]  
Define the reference matrix (\(\mathbf{R}\)) for the hybrid MG system:  
\[\mathbf{R}(k)=[w_{xx}(P_{LD}(k);P_{PV}(k);0);\ldots;P_{LD}(k+N_{p}-1);P_{PV}(k +N_{p}-1);0)] \tag{17}\]Design and control the multiple models (converting MPC to S-MPC) depending on several parameters as follows:  
\[\text{if}\quad P_{a\to b}^{j}<0;\quad SOAcc^{l}>SOAcc^{min}\quad\text{and} \quad SOAcc^{l}<SOAcc^{max} \tag{18}\]  
\[\text{if}\quad P_{a\to b}^{j}>0;\quad SOAcc^{l}>SOAcc^{max}\quad\text{and} \quad SOAcc^{l}<SOAcc^{min} \tag{19}\]  
where \(i=1,2,\,\ldots,\,11\). Regarding the AR-LSTM formulation, if Equations (2) and (4) are merged, the new state vector will be as follows:  
\[ \begin{split}\mathbf{X}(k)=c+\varphi(1)t\alpha x(W_{xx}x(k-1)+W_{ xx}u(k))+\varphi(2)t\alpha x(W_{xx}x(k-2)\\ +W_{ux}u(k-1))+\cdots+\varphi(q)t\alpha x(W_{xx}x(k-N_{P})+W_{ux}u( k-N_{P}+1))+\epsilon(k)\end{split}  \tag{20}\]  
The objective function of the hybrid MG system using S-ANC (the combination of Equations (1) and (6)):  
\[ \begin{split} J(k)=\sum_{k=0}^{N_{P}}W_{xx}(k)(\mathbf{R}(k)+ \mathbf{X}(k))^{2}+\sum_{k=0}^{N_{P}}W_{ux}(k)\Delta u(k)^{2}\\ +\sum_{k=0}^{N_{P}}W_{yy}(k)y(k)^{2}+p^{2}+\sum_{k=0}^{N_{P}} \hat{y}(k),y(k)\end{split}  \tag{21}\]  
\[ \begin{split} 0=F(\mathbf{X}(k),y(k),u(k),\hat{y}(k),\mathbf{R}(k),p) \\ 0\leq H(\mathbf{X}(k),y(k),u(k),\hat{y}(k),\mathbf{R}(k),p)\end{split}