## 2 Methodology and Materials
### Optimization Method
#### 2.7.2 Data Optimization  
Data processed by the abovementioned LSTM model is employed to design the optimization model. In this research, the classical optimization method is implemented using CPLEX solver to achieve a global solution from the designed optimization model, using Equations (17) to (18). The time step is specified ten second over one year. The approached mixed-integer nonlinear programming optimization method is presented in Figure 6. This results to minimize cost and carbon emission values using Equations (1) to (16) considering decision variables grid power consumption and carbon emission of the present year; and associated parameters load power, initial grid cost, operational cost, grid tariff, feed-in-tariff, fuel consumption, emission factor and so others. Accordingly, the optimal cost savings and carbon emission are obtained. The optimization formula is presented in Algorithm 1. Additionally, the accuracy of the results is determined using mean absolute percentage error (MAPE) metric using Equation (19),  
\[min\left\{\begin{aligned} &\sum\limits_{i=1}^{t}\left(C_{grid}(i) \times P_{grid}(i)\right)-\sum\limits_{i=1}^{t}\left(C_{FiT}(i)\times P_{export} (i)\right)\\ &\sum\limits_{i=1}^{n}\frac{C_{base}(i)-C_{cur}(i)}{C_{base}(i)} \times 100\%\\ \end{aligned}\right. \tag{17}\]  
\[s.t.\left\{\begin{aligned} & P_{PV}(t)+P_{bat}(t)+P_{grid}(t)-P_{load}(t)=0\\ & S_{cost}(t)=\sum\limits_{i=1}^{t}\left(C_{int}(i)-C_{\text{opt} }(i)\right.\\ &\left.C(t)=\sum\limits_{i=1}^{n}F_{i}\times EF_{i}\right.\\ \end{aligned}\right. \tag{18}\]  
\[Accuracy=\left\{\begin{aligned} & 100\%-MAPE;\\ & MAPE=\frac{1}{n}\sum\
olimits_{i=1}^{n}\left|\frac{A_{i}-P_{i}}{A _{i}}\right|\\ \end{aligned}\right. \tag{19}\]  
Here, \(n\) is number of iterations, \(A_{i}\) and \(P_{i}\) are actual and predicted values of the datasets respectively.  
Figure 5: Schematic diagram of LSTM layer and the operation block.  
```
Input: Merredin WA Power Grid information Output: Cost savings optimal results and carbon emission reduction Begin optimization method:  Start analysis and checking parameters  Analyze performance Data Processing  LSTM model: \(f_{t}=\sigma\Big{(}w_{fx}x_{t}+w_{fh}h_{t-1}+b_{f}\Big{)}\) \(i_{t}=\sigma(w_{ix}x_{t}+w_{ih}h_{t-1}+b_{l})\) \(g_{t}=\tau\Big{(}w_{gx}x_{t}+w_{gh}h_{t-1}+b_{g}\Big{)}\) \(c_{t}=c_{t-1}\odot f_{t}+g_{t}\odot i_{t}\) \(h_{t}=\tau(c_{t})\odot o_{t}\) Optimization Model Fitness function: \(\min\Bigg{\{}\sum_{i=1}^{t}\Big{(}C_{grid}(i)\times P_{grid}(i)\Big{)}-\sum_{i= 1}^{t}\big{(}C_{FiT}(i)\times P_{export}(i)\big{)}\) \(\sum_{i=1}^{n}\frac{C_{\text{data}}(i)-C_{\text{cur}}(i)}{C_{\text{data}}(i)} \times 100\%\) Constraints: \(s.t.\Bigg{\{}P_{PV}(t)+P_{bat}(t)+P_{grid}(t)-P_{load}(t)=0\) \(S_{cost}(t)=\sum_{i=1}^{t}(C_{int}(i)-C_{\text{opt}}(i)\) \(C(t)=\sum_{i=1}^{n}F_{i}\times EF_{i}\) Optimization complete if Constraints are satisfied then  Update parameters from the optimization models  Calculate \(C_{opt}(t)\) and \(E_{Carbon}(\%)\) if constraints suit the optimization problem then return\(C_{opt}(t)\) and \(E_{Carbon}(\%)\) endif endif
```  
**Algorithm 1**Optimization Formula