# Switched Auto-Regressive Neural Control (S-ANC) for Energy Management of Hybrid Microgrids
## 3 Switched Auto-Regressive Neural Control (S-ANC)
### Formal Definition
 \tag{22}\]  
The main advantage of employing the formulation presented by Equations (21) and (22) is that it imposes short-term safety constraints, while allowing for continuous empirical experience-based learning. In addition, reducing the prediction horizon of the dynamic optimization problem significantly simplifies the resulting nonlinear program. Notably, both optimization functions from Equation (21) must be jointly merged, such that the state \(\mathbf{X}\) must be related to the expected optimization variables in \(k+1\). This results in lower overheads than optimizing with longer prediction horizons that must be discretized over time. Notably, domain knowledge is encoded in the controller model \(F\) for optimization and control vectors, providing the algorithm with understandability. Then, the constraints are implied for the hybrid MG system. The next step is to automatically convert the traditional MPC into S-MPC. The final steps in the S-MPC are to solve the cost function and obtain \"optimal decision variables\", as shown in Algorithm 1. After that, the hybrid AR-LSTM method is initiated by configuring the controller model \(F\). The current state \(\mathbf{X}\) is found using Equation (20), before training the \"optimal control decisions\". Finally, the control variable \(\mathbf{U}\) and \(\hat{y}\) are solved by utilizing updated reference \(\mathbf{R}\) and Equations (21) and (22). To begin, design a model of the MG system. The system reads some MG specifications, such as PV and load data, accumulator data, and the maximum values of power flows among the components of the hybrid MG. Following that, the MPC controller is implemented, which will state the optimization problem and solve it at each time step, to obtain the optimal control inputs for the next time step. However, the MPC is converted into the S-MPC before it is applied. The optimization problem should consider the objectives and constraints given in this paper's methodology section. Implement an AR-LSTM model and train it on past data to increase the accuracy of the predictive model utilized by the S-MPC controller. Based on the present and previous system conditions, the AR-LSTM should be able to anticipate future MG behavior. The prediction should be input into the S-MPC controller's optimization problem. Finally, as indicated in the methodology section of this paper, the S-MPC and AR-LSTM controllers in a closed-loop control system are combined. The proposed method can test the control strategy under various operating situations and evaluate its performance using the provided performance criteria (cost functions). ```
Identify:\(F(x(k),r(k),u(k),y(k),p)=0\) Imply:\(H(x(k),r(k),u(k),y(k),p)\geq 0\) Switching logic: Conversion MPC into S-MPC Solve: Objective function for S-MPC using Equation (1) Obtain: \"Optimal decision variables\" Configure:\(F(\mathbf{X}(k),y(k),u(k),\hat{y}(k),\mathbf{R}(k),p)=0\) whiletrue do \(\mathbf{X}(k)\leftarrow\) current state using Equation (13)--AR-LSTM Pretrain \"optimal decision variables\" using \(F\) U\((k)\leftarrow\) control (input) variable \(\mathbf{R}(k)\leftarrow\) estimate from measurements \(\hat{y}(k)\leftarrow\) Solve Equations (14) and (15) \(\mathbf{R}(k+1),\mathbf{U}(k+1)\leftarrow\) Apply \(\hat{y}(k)\) to \(F\)  end while
```  
**Algorithm 1**Switched Auto-regressive Neural Control (S-ANC)  
More specifically, to implement our proposed method in operation, initially, model the MG system and the S-MPC and AR-LSTM controllers, and then combine these models into a closed-loop control system. Here are the detailed steps that need to be followed, as illustrated in Figure 5:  
* Initiate the system specifications and operational conditions from the MG operator;
* Solve the systematic generation of the control problem, employing the MPC with the QP;
* Using switching logic, automatically convert the MPC into the S-MPC;
* The optimal control decisions are obtained;
* The optimal control decisions are employed as input data for the AR method;
* The data preparation is initiated.