Microgrid Energy Management System With Embedded Deep Learning Forecaster and Combined Optimizer

This paper presents an energy management system for the microgrid present at Wroclaw University of Science and Technology. It has three components: a forecasting system, an optimizer and an optimized electrical vehicle charging station as a separate load for the system. The forecasting system is based on a deep learning model utilizing a Long Short-Term Memory (LSTM) – Autoencoder based architecture. The study provides a statistical analysis of its performance over several runs and addresses reliability and running time issues thereby building a case for its adoption. A MIDACO – MATPOWER combined optimization algorithm has been used as the optimization algorithm for energy management which intends to harness the speed of MATPOWER and the search capabilities of Mixed Integer Distributed Ant Colony Optimization (MIDACO) in finding an appropriate global minimum solution. The objective of the system is to minimize the import of power from the main grid resulting in improved self-sufficiency. Finally, an optimized electrical vehicle charging station model to maximize the renewable energy utilization within the facility is incorporated into the same.


I. INTRODUCTION
In the current political and societal scenario there has been substantial mobilization towards mitigation of climate change. This is evident from the Paris Agreement [1] which aims to mitigate climate change by limiting global warming to 2 o C above the pre-industrial levels with efforts to keep it below 1.5 o C. Similarly, the Sustainable development goal 7 (SDG7) on clean and affordable energy [2] and the European Green Deal on the EU becoming climate neutral by 2050 [3] aim to increase the share of renewable energy sources within the energy mix along with sustainable transportation solutions.
The associate editor coordinating the review of this manuscript and approving it for publication was Derek Abbott .
In order to achieve the goals mentioned above and face the challenges they pose, one of the solutions proposed is microgrids. They can be defined as a decentralized power network consisting of numerous distributed energy sources, located close to the end-users and provide the flexibility of being operated either in grid connected mode or in isolation [4]- [8]. They have a defined boundary and are considered as a single entity by the distribution and transmission system operators. This promotes renewable energy integration into the existing network, provides independence from the main grid (isolated mode) and it can be tailored to meet the demands at the local level. While there are numerous benefits to microgrids, there are several challenges as well, including high variability of the renewable energy sources, uncertainties of the same, matching of supply and demand and VOLUME 8, 2020 This work is licensed under a Creative Commons Attribution 4.0 License. For more information, see https://creativecommons.org/licenses/by/4.0/ scalability of the microgrid [6]- [8]. Further challenges include high capital costs involved with the setup, unavailability of adequate regulatory and protection standards, privacy protection and control issues [10]. These reasons have led to focused research into energy management systems (EMS) for microgrids [8], [9]. Microgrids can be both AC and DC, even though the current power grid in most places is AC, numerous loads such as battery chargers, computers and lighting systems are DC in nature. Also, renewable energy sources such as solar photovoltaic systems, energy storage systems and a few others produce DC voltages. The advantages and disadvantages of both types of systems and research into the same is elaborated in [7]. The EMS along with performing energy balance within the microgrids also usually tries to fulfil other objectives. These could be minimization of operational costs [13], [14], minimization of emissions [12] and minimization of losses [15], [16] amongst many other objectives that depend on the motivation behind building such systems. Many such management systems also employ a combination of these objectives in a multi-objective manner [17]. The aim of this study is to develop an EMS for the microgrid at Wroclaw University of Science and Technology that is based on a forecasting system constructed from deep learning models and a combined optimizer which is a combination of MIDACO (an ant colony extension) and MATPOWER with the objective function of minimizing power imported from the main grid. The contributions of the study foremost include the EMS itself tailored for the microgrid at the university which is to be implemented, followed by the sliding window algorithm enabling efficient training of deep learning networks on large data, reliability studies of the forecasting system and a combined optimization approach leveraging both speed and quality of the final solutions obtained which is also the novel approach explored in this work.
Deep learning approaches for forecasting were adopted due to the following reasons. Compared to traditional machine learning algorithms the deep learning models do not flatten early in terms of performance. This means that with greater availability of data and increased computational power the relationship ascertained by the deep learning networks improve and do not saturate unlike the traditional algorithms which after a certain threshold cannot improve their performance irrespective of the amount of data and computational power available. A comprehensive comparison of the performances of traditional machine learning algorithms like linear regression, logistic regression and smaller neural networks against the deep learning models can be found in [18]. Moreover, another reason is their ability to extract features from raw data called feature learning which enables it to learn unknown representations present in the input data [19]. Also, numerous review papers have shown the advantages of using neural networks for solar power output forecasting especially in microgrid energy management applications [10]. They elaborate on the numerous challenges encountered when dealing with uncertain and unpredictable renewable sources of energy and how to tackle the same using neural network-based methods and others.
While numerous studies have shown the ability of metaheuristic optimization algorithms to find improved solutions to the optimal power flow question [17], [18] and to work with multi-objective functions [22] their application is still limited. Recent advances in computational power has significantly reduced their run times but the amount of time taken for one run to be completed (convergence to a global minimum solution) takes from anywhere between 17.15 seconds to 594.08 seconds depending upon the optimization algorithm used. This time has been calculated for operational cost minimization in the IEEE 30 bus system and can be found in [23]. A high run time for the optimization part creates operational issues, depending upon the need of the energy management system it may have to be run several times a day or even in an hour and in such cases a faster optimization process is preferred. Hence, this study uses a combined approach involving MIDACO (Mixed integer distributed ant colony optimization) and Matpower leveraging the advantages of both approaches to optimization.
Electrical Vehicles (EV) are seen as a sustainable mode of transport and also are considered a cost-effective alternative to internal combustion engines. However, there are significant hurdles in their large-scale adoption [24]. They require a substantial amount of investment in terms of charging stations installation to the existing power network. The randomness involved in EV arrival and charging times also adds significant uncertainty to the amount of power demand at any given time which could cause stability concerns involving voltage fluctuations and harmonics [25]. Hence, it would be beneficial to deploy coordinated charging of vehicles in charging stations. This study uses 'fmincon' based on the Interior point algorithm in MATLAB to co-ordinate and optimize charging in the Electrical Vehicle Charging Station (EVCS).
In the literature several studies can be found which have proposed EMSs based on the combination of different forecasting and optimization algorithms. Here are a few of such algorithms. In [12] a deep recurrent neural network with long short-term memory (DRNN-LSTM) has been used for the purposes of forecasting both the hour-ahead solar panel output and the load. Their model used both historical data and meteorological data to make the forecasts which is then followed by energy balancing performed by the Particle Swarm Optimization (PSO) algorithm. The objective function used in this case is the minimization of cost between the main grid and the microgrid, the cost of depreciation involving electrical vehicles and energy storage systems (ESS) and the cost of treatment of pollution. The study had considered 3 scenarios in order to study the effects of both the presence of the ESS and coordinated charging of EVs. Scenario 1 considering neither coordinated charging nor ESS, scenario 2 with only ESS connected and scenario 3 considering both coordinated charging of EVs and ESS. In this manner it was proved that solar energy utilization can be improved and daily costs can 202226 VOLUME 8, 2020 be reduced by as much as 8.97% for the study pertaining to their data.
In order to deal with the uncertainty around wind power generation, increase its utilization and also promote the use of big data analytics in microgrid operation and optimization, [6] proposes the integration of the Apache Spark streaming with the optimization model. The benefits of using Apache spark are that it needs no pre-processing of data, it is capable of analyzing dynamic behavior and it is capable of handling and processing data in real time. Unlike the traditional way of forecasting utilizing historical data and updating them over pre-selected time periods this study utilizes the real-time data available and improves the forecasts continuously. The objective function used for the purpose of optimization in this study was the minimization of operational and maintenance costs of the microgrid.
Another such project combining forecasting and optimization can be seen in [26] where they have used LSTM (long short-term memory) RNNs (recurrent neural networks) for the purpose of load demand and solar irradiance forecasts. This study uses a forecasting horizon of 1 day and has used a large dataset for the purpose of training their neural networks (12 years of data). Furthermore, a comparison is made between the performance of the LSTM-RNN network with a simple Feed Forward Neural Network (FFNN) and it is shown that the LSTM-RNN has more accurate results. The pre-processing of data in this study is significant where apart from data cleaning such as removal of missing data and normalization, one-hot encoding and partitioning of data using k-means clustering is performed. The models are implemented using MATLAB's deep learning toolbox. For optimization the study has used MDSTool which is described as a decision support tool for planning and analysis for hybrid energy systems and microgrids. The tool is able to perform energy balance, energy analysis and evaluate financial feasibility of the microgrid operation.
A multi-agent-based approach to energy management of microgrids with solar PV, wind turbines, storage systems and conventional generators is described in [27]. The objective function in this case is minimization of energy loss and operational cost of agents. For the purposes of forecasting the power output of renewable energy generators, a deep learning model using a combination of gated recurrent unit and convolutional neural networks is used. In order to perform the energy management and find the optimal point of operation, the alternating direction method of multipliers (ADMM) is used. The ADMM used in this study is enhanced by means of over-relaxation. Finally, the performance of this approach is evaluated on a modified CIGRE low-voltage network. A neural-network based approach for forecasting renewable generation in a residential microgrid along with energy management with an objective to alleviate the peak to average ratio and mitigate electricity cost is presented in [28]. A comprehensive model for scheduling and energy management is obtained using mixed integer linear programming (MILP). The microgrid consists of energy storage systems, wind turbines and solar PV panels. Validation of the proposed model is evaluated by running several simulations in MATLAB.
While a few examples are provided above, a comprehensive review of the numerous forecasting methods (conventional and neural network based) followed by optimization can be found in [29] whereas an analysis of the approaches by which weather forecasts are obtained and implemented in EMSs along with recommendations for appropriate use of such data can be found in [30].
While many studies cover the use of LSTMs for the purpose of forecasting, seldom there are studies which focus on the LSTM -autoencoder model. Furthermore, very few studies comment upon the reliability of such deep learning models used by providing associated statistical analysis of the model run over several times using different training and test data sets. This study describes the use of LSTMautoencoders for forecasting and then comments on its ability to remain consistent in its performance. Moreover, with regard to optimization, numerous intelligent algorithms have been explored but the unique combination of MIDACO and Matpower is yet to be seen in EMSs for microgrids. The rest of this paper is arranged in the following manner, section 2 describes the forecasting model used, the associated data processing, evaluation metrics and the statistical analysis of results, section 3 describes the microgrid layout and the optimized Electrical Vehicle Charging Station (EVCS) model, section 4 describes the mathematical foundation, the combined optimization algorithm, the energy management procedure and a comparison of it's performance against a few other optimization algorithms while section 5 provides the results and discussions. This is then followed by conclusions.

II. FORECASTING MODEL, DATA PRE-PROCESSING, EVALUATION METRICS AND STATISTICAL ANALYSIS A. FORECASTING MODEL LSTM -AUTOENCODERS
An LSTM is a specialized Recurrent Neural Network (RNN), the RNN in recent times has shown significant performance in the handling of sequential data and forecasting [31], [32]. This is due to the fact that in comparison to a feedforward neural network (FFNN) the RNN possesses a memory cell. It is said to have a memory cell because unlike the FFNN where the connections move in only one direction (from input to output layers) in the RNN the connections also point backwards which enables it to store information in one given time step and propagate it forward. This can be visualized and explained with the help of a single RNN neuron as shown in Fig. 1.
On the left of Fig. 1, the neuron with an activation function (A) takes in an input X and gives an output Y . Moreover, it feeds the output back to itself so that this output can be used along with the input in the next step. This way it is ensured that the experiences learned from the previous time steps do no vanish and can be used during training in the current and future steps. On the right of Fig. 1 this process is explained by unrolling the behavior of this neuron as it moves from an earlier time step to the present time step and it can be seen how the output Y(t-1) is used along with input X (t) to produce the output Y (t) by the activation function. Several neurons such as this can be arranged together in a layer called an RNN layer where each of the neurons will receive a vector of inputs, a vector of outputs from the previous step and return a vector of outputs.
While the RNN, due to its structure is able to work with sequential data efficiently it has a few drawbacks which are long training times and the fact that in case of an RNN, the inputs at the earliest time steps fade and is forgotten which means that at every time step information of some inputs is lost and this can lead to inaccurate forecasts [31], [32].
To solve these problems the basic memory cell of the RNN was improved and many models were considered one of which is the LSTM. The LSTM is faster and can identify long-term dependencies in data [31]. The structure of the memory cell in an LSTM is significantly different. Fig. 2 depicts the cell structure for both the regular RNN and the LSTM where, tanh and Sig (sigmoid) represent activation functions, h(t) represents the short-term state, c(t) the long-term state, X(t) input vector at t, Y(t) the output vector at t, X(t-1) the input vector at t-1, Y(t-1) the output vector are t-1, f(t) controller of the forget gate, g(t) and i(t) controllers of the input gate and o(t) controller of the output gate.
It can be noticed immediately that compared to the regular RNN memory cell which only has one output which is also propagated to the next step, the LSTM cell has two state vectors which are the short-term state vector h(t) and the long-term state vector c(t). Traversing from left to right, it can be seen that the long-term memory state c(t-1) from the previous time step is obtained which is then passed through a forget gate wherein certain memories are dropped and then new memories are added via the input gate. This new long-term memory state is c(t) and is then passed onto the next time step without further modifications. Once the new memories are added c(t) is copied and is sent through the tanh function and into the output gate where results are filtered along with the output from o(t) wherein the input is sent through a sigmoid function. The resultant from this output gate is short-term state vector h(t).
The description of each gate and manipulation of memories is as follows, firstly the input x(t) and the short term state h(t-1) are given as inputs to all the fully connected layers, i.e. f(t), g(t), i(t) and o(t), with i(t) using the sigmoid function and the others using the tanh for activation. It can be seen that in the simple RNN cell there is only one such layer with tanh activation and the information is then sent as an output and repeated to the next step. This function is performed by g(t) in the LSTM cell where it analyses the input signal x(t) and the short-term state h(t − 1).
The other layers (f(t), g(t) and o(t)) are in fact called as gate controllers due to the fact that they use the sigmoid/logistic activation function and the output is maintained within 0 and 1. The output from each and every one of them is sent to an element wise multiplication gate and depending on whether the value is 0 or 1 they close or open the gate.
The forget gate controlled by f(t) decides which memories are removed from the long-term state c(t-1). The input gate controlled by i(t) determines what memories from the output of g(t) is added to the long-term state c(t). Output gate

controlled by o(t) determines which parts of the long-term state c(t) should be output as Y(t) and h(t-1) at this time step.
This elaborate structure enables the LSTM cell to read inputs, store them over both long-term and short term, solving the problem of vanishing experiences and enables them to work efficiently with time series and sequential data. The entire process is described as: where The LSTMs used for the purpose of machine learning have numerous models based on the arrangement of LSTM layers, based on encoding and decoding of data and based on their combinations with other deep learning models such as the CNN-LSTM. This study has decided to use the LSTM-Autoencoder model for the following reason. This model in essence has 2 parts, an encoder and decoder. The purpose of the encoder is to create an internally learned representation vector from the input vector. This means that based on the configuration of the encoder it creates a new encoded vector from the input. This vector contains the complex dynamics that are that are present within the temporal ordering of the input vector. This vector is then decoded by the decoder and the model's performance depends on the ability of the decoder to recreate the input vector [33], [34]. The encoding process usually results in a compression where the dimensionality of the input is reduced and the encoded vector can now also be used with other machine learning algorithms as a feature vector. Hence, the auto-encoder architecture provides a flexibility and dimensionality reduction which other LSTM based architectures do not.
The equations concerned with encoding and decoding are shown here: where W 1 and W 2 are weights of the encoding and decoding layers respectively and b 1 and b 2 their respective bias; σ represents the activation input whereas y is the internal representation (encoded vector), x is the input vector and x is the input after decoding.
The LSTM auto-encoder model used in this study can be seen in Fig. 3. The encoder of the LSTM as described earlier consists of 2 layers in the model, the input layer and the LSTM layer, whereas the decoder of the model consists of an LSTM layer and a feed forward neural network (Time Distributed(Dense)). The RepeatVector from the diagram is a data manipulfation layer which enables the LSTM at the decoder layer to read the encoded vector. It is not possible to connect the encoder and decoder without it.
The input layer is designed to receive inputs in the form of [samples, steps, features], as it can be seen from the figure the designation for the samples remains none because the input layer is capable of judging the number of samples by just looking at the input fed to it. The steps in this case is 1 and the features are 6 which are irradiation (W/m 2 ), module temperature ( o C), output power (W) from the previous two time-steps. The LSTM layer in the encoder takes this input and creates an encoded vector with 1 feature. This is repeated 15 times since the LSTM layer in this study has 15 cells. In order for the LSTM layer in the decoder to decode the encoded vector it has to have a 3-dimensional shape hence the RepeatVector reshapes the encoded vector. The LSTM decoded vector attempts to recreate the input sequence by approximating the relationship between the input and the output and is then followed by a simple feed forward neural (FFN) network to print the output.

B. DATA PRE-PROCESSING
The features used in this study differ from one another with regard to their units of measurement, distribution of data and scale of the data. When neural networks are trained on such data with different characteristics it can lead to large weight values and such models can be poor in learning and also VOLUME 8, 2020 tend to be sensitive to changes in the input data [35]. Hence, to avoid this obstacle the data is normalized in the range [0,1] using a min-max scaling algorithm described as This study uses a sliding window algorithm to feed data to the input layer. While this method of feeding data to this forecasting model is not absolutely necessary, it has been essential during the investigation of other models such as the CNN-LSTM and other CNN based forecasting models. The results of those models can be accessed in [36]. Nevertheless, even in this study the sliding window algorithm helps in re arranging the input data without much effort in-order to decide the optimal past time steps needed to make the forecast and helps in faster model training [36]. The algorithm is shown below.

Sliding window algorithm
Procedure Variables (X, V, t) i = 0, n = 0; # number of windows = n K = []; # K is the set of windows extracted While i + V ≤ length (X) #V is the length of the sliding window The results from forecasting were analyzed using the following criteria. These criteria were chosen based on the recommendations of review studies and reports in the solar forecasting field [37], [38]. The Root Mean Square Error (RMSE), the Mean Absolute Error (MAE) and the MBE (Mean Bias Error) were used. The RMSE is quite suitable to evaluate forecast results since it has the ability to punish larger errors with greater effect. The MAE calculates the average absolute error of the forecasts and the MBE calculates the average error of the forecasts. The purpose of bias is to decide if the forecasting algorithm chosen has a tendency to under or over predict. The criteria are defined from (10)- (13) where, the forecasted and actual observations are represented by yi(forecasted) and yi(actual) respectively. e i is the error, i = 1, . . . . . . ., N represents all the time steps of the data.

D. STATISTICAL ANALYSIS
The forecasting models for this study were all modelled in PYTHON using Jupyter Notebooks. The deep learning environment used was TensorFlow and the models were constructed using KERAS. Additionally, other PYTHON libraries were used for data processing and manipulation. The computations such as fitting the models and evaluation of the results were made in a computer with an Intel core i7 9th generation processor having a 16 GB RAM and running a Windows 10 operating system. The data for this study comes from the PV panels installed in Wroclaw University of Science and Technology. While there is a total of 3 different modules, polycrystalline, monocrystalline and CIGS consisting of 27, 21 and 56 panels respectively. This study mainly focuses on the forecasting for polycrystalline solar module but there is no reason to believe that this forecasting model cannot be extended to other modules. The peak power capacity for the monocrystalline module is 5 kW and the measured variables include irradiation (W/m 2 ), wind speed (m/s), ambient temperature ( • C), and PV module temperature ( • C). As mentioned during the explanation of the LSTM architecture the variables used in the study will be the irradiation (W/m 2 ), module temperature ( • C) and output power (W) from the past two time -steps. The variables were chosen according the recommendations of [37], [38]. All the variables are measured in time steps of 10 mins. The total time spread of the data is for one year. The data was always split into a 9:1 ratio for the purposes of training and validation.
The forecasting model described in 2.1 was run 1000 times and in each of the runs the model was trained and validated on different data sets. This was achieved by randomly sampling the data for validation from the entire length of the input vector and keeping the rest for training. This is done in order to ensure that the model remains consistent and that it is reliable over several runs and that a good forecasting model is not achieved by chance or luck.
The mean RMSE and MAE values for 1000 runs are 0.224 kW and 0.089 kW respectively, these are 4.48% and 1.78% of the nominal power of the panel. Moreover, from Figs. 4(a) and (b) it can be seen that the frequency distribution curves of both these metrics are near Gaussian/normal which enables the calculations of confidence parameters. The standard deviations for both curves are 0.053 kW and 0.021 kW which are 1.06% and 0.42% of the nominal power implying that the spread of the error values over the runs performed is not significant hence, the results are consistent. The 95% confidence intervals for both the RMSE and MAE values are [0.113, 0.33] kW and [0.047, 0.131] kW respectively. From this, it can be said with 95% confidence that whenever a model is fit, the best models would have an RMSE value of 2.26% of nominal power and a less accurate model would have an RMSE value of 6.6% of nominal power. In general, it can also be noticed that the RMSE values are higher than the MAE values which was expected due to the tendency of the RMSE to punish bigger errors more highly than the MAE which treats errors of all magnitudes equally.
For comparison with a well-known forecasting model, the same underlying data was fit with an ARIMA model and it was run 1000 times with changing test and validation data sets. The parameters of the model are (2,1,1) where 2 is the Autoregressive (AR) coefficient, 1 represents the fact that the time series was differenced once in order to obtain stationarity and 1 is the Moving Average (MA) coefficient. The entire procedure of selecting an appropriate ARIMA model, especially for this particular data can be found in [36] which also includes other deep learning models that were earlier explored for forecasting related to the same system.
The mean RMSE and MAE values are 0.374 kW and 0.181 kW respectively, these are 7.48% and 3.6 % of the nominal power of the panel which is higher than the corresponding values of the LSTM -autoencoder model. The standard deviations for the same are 0.22 kW and 0.105 kW at 4.4% and 2.1 % implying that the spread of the error values is also higher than that of the LSTM -autoencoder model. The 95% confidence intervals for the RMSE and the MAE are [0.36, 0.38] kW and [0.16, 0.20] kW which are higher than the intervals for the LSTM -autoencoder model but with a lesser spread.
The BIAS of both models was also calculated over all the runs and the values were 0.99 and 0.6 respectively. The only observation from this indicator is that the value is positive hence, the models have a tendency to over-predict than underpredict when compared to the actual value.
Figs. 5(a) and (b) present the forecasts made for two randomly sampled days from the set kept for validation. Fig. 5(a) represents a day from the spring/summer time indicated by the higher output throughout the day whereas the Fig. 5(b) is typical of a winter day. It can be noticed that both algorithms on both figures work quite similarly throughout the day except around peaks where the forecasting made by the ARIMA model is less accurate when compared to the LSTM autoencoder model. In general, it can be said that both models are inaccurate at the peaks.

III. MICROGRID LAYOUT AND ELECTRICAL VEHICLE CHARGING STATION A. MICROGRID LAYOUT
The microgrid layout is presented in Fig. 6. The layout consists of 3 PV modules similar to the layout at the university but since the EVCS represents a significant new load that would be added to the system, the power output from the modules VOLUME 8, 2020 is multiplied by a suitable factor for this study in order to take into account the scale of the microgrid that is necessary. Similarly, the load curve is only available for load 1, and the other loads are obtained by multiplying the curve by a suitable constant.
G1 represents the main grid which is connected to the microgrid and it is the only source of reactive power for the microgrid since all other sources in the microgrid are renewable energy sources. The storage device is represented by G7/L5 due to its dynamic nature to act as a source during discharging and load during charging. The peak output power for the PV modules 1, 2 and 3 are 9 kW, 4 kW and 7 kW respectively. The maximum demand observed during the day for loads 1, 2, 3, and 4 are 10.5 kW, 6 kW, 11.5 kW and 5.5 kW respectively. The battery storage device has a capacity of 6 kWh and is modelled according to the dynamics described in [39].
While the microgrid layout contains numerous resources close to the installation present within the university a few other sources are modelled in-order to represent the complexity of the modern microgrid.
A micro hydro power plant with Pelton turbines is placed at node 4 with a maximum power capacity of 6.2 kW. They are modelled according to the equation (14) [40].
where, P h (t) is the power output, A h is the plant coefficient which varies from 6 -8 for hydro plants of small sizes, in this study it is 6. q(t) is the flow rate of discharge in m 3 /s and the minimum value for which these turbines produce power is 0.014. This results in minimum output power of 4.2 kW. H is the head of the hydro power plant which is 50m. It is assumed in this study that the at least minimum discharge rate of water is maintained throughout the year. A Hyundai 5.2 kW/ 6.5 kVA diesel generator is also installed at node 2. The generator has a 16 litre fuel tank and the most important consideration for the diesel generator is that the minimum output power should be maintained at all times when it is running [41]. The minimum output power in this study is maintained at 30% of the rated power which is 1.56 kW.
The impedances of the lines between nodes represented by Z have the parameters as shown in Table 1. They are aluminum cables with XLPE insulation and PVC outer sheath having 1 core with 120mm 2 cross-section.

B. ELECTRICAL VEHICLE CHARGING STATION
The EVCS shown in this study can be seen in node 5 of Fig. 6. It consists of 5 Tesla level 2 chargers that are capable of delivering power anywhere between 3.7 and 17.2 kW per hour. Since the arrival of EV's during anytime of the day is random, their arrival is determined by choosing the time of arrival from a normal distribution using the Randi function in MATLAB. Moreover, the state of charge (SOC) of the incoming cars is also highly variable and so is the desired SOC and maximum waiting time that would be given as an input by every EV. This randomness is achieved by randomly sampling incoming SOCs from a normally distributed curve with a mean of 0.2 SOC and a standard deviation of 0.2 SOC. The desired SOCs and maximum waiting time are also randomly sampled from a normally distributed curve with a mean of 0.7 SOC and a standard deviation of 0.3 SOC and with a mean of 6 hours and a standard deviation of 2 hours. Also, the capacities of the incoming cars are variable. For the city of Wroclaw, the most popular EV is the Nissan Leaf with a battery capacity of 42 kWh hence the capacities of the cars are drawn from a normal distribution with a mean of 42 kWh and a standard deviation of 10 kWh.
The EVCS in this study is optimized by way of controlling the rate of charging of the EVs. The objective function in this case is synonymous with the objective of the energy management system wherein the idea is to minimize the import of power from the external grid and maximize the utilization of local renewable energy production as follows: min (P G ) = P d + P l − P mg (15) where, P G represents the power imported from the main grid which is written as a sum of the total load demand P d within the microgrid and its associated line losses P l from which the total power generated withing the microgrid P mg is subtracted.
It can be seen that the equation (15) is the same as equation (22), this is because the coordinated charging feature is based on the availability of excess power in the microgrid compared to the demand.
The constraints and mathematical model of the problem are as follows: (21) where N EV and N c represent the number of electrical vehicles connected and the total number of chargers respectively. Equation (16) implies that at every time step t, the total number of EVs connected is less than or equal to the total number of chargers available. In (17) P c is the charging power and at every time step t it is constrained within the minimum P cmin and maximum P cmax charging power of the chargers. Equation (18) ensures that the SOC of each EV remains within the limits of its initial value of arrival and the desired SOC level. (19) describes the charging time for every vehicle i which is T c and it is constrained within the maximum waiting time T max input by every user. In (20) t represents length of each time step, in this case 10 min, and P ct is the optimal charging power at time t. Together they determine the energy added to every EV, i, which is add SOC i . The new SOC after charging, of every EV i is calculated as a sum of the SOC of the EV at the previous time step and add SOC i as shown in (21).

IV. ENERGY MANAGEMENT USING A COMBINED MIDACO-MATPOWER ALGORITHM A. MATHEMATICAL FOUNDATION OF ENERGY MANAGEMENT
The EMS used in this study has an objective function as shown in (22). The equation describes minimization of the import of power from the main grid to the microgrid. This in principle can also be seen as promoting self-sufficiency of the microgrid as it maximizes the utilization of energy produced within the microgrid. min (P G ) = P d + P l − P mg (22) P mg = P sg + P dg + P hg + P s (23) P d = P sd + P evcs + P cd (24) where, P G is represents the power imported from the main grid which is written as a sum of the total load demand P d within the microgrid and its associated line losses P l from which the total power generated within the microgrid P mg is subtracted. P mg is written as the sum of the power output of all generators in the microgrid which includes the power from the solar panels (P sg ), power from the diesel generator (P dg ), power from the hydro turbines (P hg ) and the power output of the storage (P s ). P d is written as a sum of the power demand from the storage device (P sd ), from the EVCS (P evcs ) and the consumer demand (P cd ). The minimization of (22) is subject to equality and inequality constraints necessary to maintain the stability and power quality within the microgrid. They are described as follows: Equations (25) and (26) represent the equality constraints necessary to carry out power balancing within the microgrid. In (25), |V i | n k=1 |V k | |Y ik | cos(θ ik + δ k − δ i ) represents the active power losses in the microgrid and in (26), represents the reactive power losses Equations (27)-(30) keep parameters such as voltage magnitude (V i ), voltage angle (δ i ), active power (P i ) and reactive power (Q i ) within desired operational limits. Here, V i and V k represent the voltages at nodes i and k respectively; Y ik and θ ik are the admittance and admittance angle between buses i and k; P gi , P di , Q gi and Q di are the active power and reactive power supply and demand at nodes i; δ i and δ k are the voltage angles at buses i and k. Hence, (27) represents the fact that the active power output of each generator in every node is constrained within their minimum and maximum output. (28) ensures that the reactive power output for all generators stays within their limits at every node and (29) and (30) ensure that the voltage magnitude and voltage angle stay within their limits at every node.
Crucial to solving these set of equations is the identification of state and control variables of the system. In fact, this holds true for any power system and solving the optimal power flow problem [42]. In this study the control (independent) variables chosen are the active power outputs of the generators (including storage discharge) in the microgrid, voltage magnitudes and the load demand from the EVCS and the storage system. The state (dependent) variables would be the reactive power outputs and slack bus power (power from the main grid). MIDACO (mixed integer distributed ant colony optimization) algorithm [43] is used to solve for the control variables and based on its results the state variables are obtained using Matpower [44]. A description of how MIDACO works and how the combined algorithm looks for the global minimum value will be shown in the next section.

B. COMBINED MIDACO AND MATPOWER OPTIMIZATION ALGORITHM
MIDACO is an extension of the Ant Colony Optimization (ACO). It has several improvements over the traditional ACO algorithm and it is capable of handling both continuous and VOLUME 8, 2020 integer variables [43]. The algorithm can be visualized as follows. It tends to mimic the foraging behavior of ants wherein the ants are initially scattered about their colony with each looking for a potential food source. Once such a location is decided, the food is brought back to the colony and while doing so a pheromone trail is laid down by the ants. This pheromone trail evaporates over time and its strength depends on how many times it is frequented by the ants. Hence, the food source that is located closest to the ant colony is visited the most and the associated pheromone trail remains the strongest. These food sources can be equated to potential solutions whereas the best food sources (best solutions) would be decided based on the strength of its pheromone trail [43].
Mathematically, the above explained concept is modelled as a graph known as a construction graph G C (V, E), where V are the vertices of the graph (food sources/potential solutions) and the edges E which are the trail utilized by the ants which determine the quality of the solution obtained [43]. While the construction graph enables searching for a global minimum, the local optimization problem is solved by means of daemon actions which can be seen as certain constraints that have to be fulfilled while the solutions are obtained. MIDACO uses a mixed integer sequential quadratic programming (MISQP) solver for the local optimization problem.
The constraint handling in MIDACO is done through a robust oracle penalty method [43]. Simple penalty methods such as death or static are easy to implement but have performance issues. Sophisticated methods such as adaptive and annealing have better performance but are associated with high computational burden. The oracle penalty method is proposed as an approach that is computationally not intensive but has high performance [43]. It is based on one parameter alone and is robust since its performance isn't affected if the initial solution selected is good or bad. A comprehensive explanation of the method is beyond the scope of this article but can be found in [43].
MIDACO presents a significant advantage when it comes to parameter selection. The only parameter selected in the study is that of the stopping criteria which is the maximum number of iterations. In this case 500 iterations. MIDACO is able to handle other parameters in an ''autopilot'' mode which enables it to escape from local solutions if it is entrapped and continue to search for the global solution. It repeatedly restarts in order to do so and requires no user interference [45].
One of the issues encountered while using MIDACO for energy management was the high computational time with an increase in size of the power network. While this is to be expected for any optimization algorithm, a solution to this problem was to integrate Matpower into MIDACO where the global minimum would be decided by MIDACO and the load flow problem will be solved by Matpower. Matpower is a well-known open source power system analysis tool [44].
The algorithm is shown in Fig. 7. The process begins with the declaration of all variables associated with the problem. These include the network parameters such as the number and capacities of generators, loads, distribution lines resistances and reactances, shunt compensators used, and so on. This is followed by declaration of the parameters of MIDACO such as the number of Ants, stopping criteria (100 iterations), kernel size used etc. Next the objective function and the equality and inequality constraints are defined. Following this, a random solution vector is created and the best solutions evaluated, during this evaluation every solution is associated with a load flow simulation by Matpower which solves for the dependent/state variables. This process is repeated until the stopping criteria is achieved following which the optimized parameters are stored.  Table 2. On the contrary the NOPF and the EDOPF are able to find a solution in a very short amount of time (nearly instantly) which makes them suitable for ED problems but their final minimized solution is worse than that of the combined optimizer.
Hence, the optimizer represents a fine balance between the computation time and quality of the final solution obtained which is the reason for its adoption for this study.

D. ENERGY MANAGEMENT PROCEDURE
The process of energy management is shown in Fig. 8. It begins with the declaration of all elements within the microgrid along with their characteristics and limits. This includes the solar PV panels, the storage device, the diesel generator and the micro hydro power plant. It also includes the main grid through the PCC. The loads within the microgrid and the EVCS.
The storage device and the EVCS function with regard to two different conditions. Condition 1: when the renewable power generation within the microgrid is greater than the load within the microgrid and condition 2: when the renewable power generation is less than or equal to the load in the microgrid.
Under condition 1, first the storage device's SOC is checked and if it isn't at a 100% it is charged using the excess supply of power available.
For the EVCS a check is made if the available excess energy minus the energy consumed by the storage device is greater than the load demand of the ECVS when all connected chargers charge at minimum capacity. If it is greater, the EVCS consumes the excess power while constraining this consumption within the sum of the total demand if all chargers were charging at maximum charging power. If it is lesser, the EVCS would charge all the chargers at their minimum charging powers. This additional load due to the EVCS and the storage is added to the overall load of the microgrid at their corresponding nodes.
Under condition 2, again, first the SOC of the storage device is checked, if it is greater than 5% the storage device starts discharging.
The EVCS in this condition would charge all connected EVs using the chargers' minimum charging power.
The corresponding load due to the EVCS and the amount of power generated by the storage device are added to the overall load and generation mix of the microgrid respectively at the appropriate nodes.
Once all the loads and the generators are defined, the MIDACO -MATPOWER combined optimizer does resource allocation with the objective of satisfying all the loads while minimizing the power imported from the main grid. This is done keeping all parameters such as the voltage magnitude, active power, reactive power and voltage angles within their respective defined limits. Fig. 9 presents an analysis of the import/export of power into the microgrid from the main grid. It can be readily seen that during periods of high renewable energy generation, the export of power to the grid when supply exceeds demand is high. It can also be seen that when the renewable energy output begins to fall the import of power from the main grid begins to increase, the reason for this is the load demand within the microgrid exceeding the renewable power generated within the same. Fig. 10 describes the influence of controlled/uncontrolled charging on the load demand of the microgrid. Unlike the previous figure this characteristic is shown only for 24 hours due to erratic nature of the curves. It can be seen that in case of uncontrolled charging, the demand is higher than in case of controlled charging. Moreover, it can also be seen that this demand is almost fully met by importing power from the main grid defeating the objective of establishing self-reliance and minimizing the use of power from the main grid. It has to be mentioned that even though in case of uncontrolled charging the load demand is high and very erratic it leads to more cars being charged over the day which is the reason for the frequent fall and rise of load demand. Fig. 11 depicts the charging and discharging of the storage device shown as G7/L5 in the microgrid layout. It can be said that charging and discharging of the storage depends upon the excess generation or demand in the microgrid which can be ascertained by the Import/Export of power from/to the main grid. It can be seen that even during night times there are moments when power is exported to the main grid due to operation of the DG and the micro hydro power plant which    charges the storage device and discharging is observed when power is imported from the main grid.

V. RESULTS
The SOC of each individual EV connected to the chargers can be obtained at any given time. Fig. 12 shows such an example where the SOCs of incoming EVs are tracked for charger 1 and 2 during a day.
It can be seen that the final SOC levels of different cars of different capacities are different, this is due to the different desired SOCs and departure times input by the users. Once an EV is charged up to the desired level or the departure time is reached, the curve falls to zero and then begins tracking the SOC of the next incoming EV. In this figure, two EVs one on each charger (C1 -EV -1 and C2 -EV -1) achieved their desired SOC level or departure time and the next 2 EVs on both chargers (C1 -EV -2 and C2 -EV -2) are on their way to achieving them.

VI. CONCLUSION
This article has described the implementation of a deep learning-based forecasting algorithm, a meta-heuristic based combined optimization algorithm for energy management and an EVCS with a controlled charging capability. The forecasting model architecture is based on LSTM-autoencoders which use a sliding window algorithm to enable quick learning of the input data. The forecasts mainly focused in this study are the 10 min ahead forecasts. The forecasting algorithm based on RMSE, MAE and BIAS has shown sufficient accuracy as required by the facility at Wroclaw University of Science and Technology moreover, its reliability has been established by running the algorithm for 1,000 runs and evaluating the errors with the training and validation data changing at every run. The optimization algorithm used was a MIDACO -MATPOWER based combined algorithm which attempts to harness the speed of MATPOWER to solve the power flow problem and MIDACOs capabilities to effectively search for a global optimization solution. The objective function of the EMS was to minimize the import of power from the main electrical grid which the results have shown to be true especially during days of high renewable energy generation within the microgrid. It is expected that these savings would promote self-sufficiency and energy savings.
The article also further elaborates on the effects of controlled and uncontrolled charging on the microgrid which has shown the erratic behavior that tends to appear when EVs are charged at maximum charging capacity. With respect to the future work ahead, it involves exploring a few more forecasting algorithms mainly by way of data processing in-order to further improve the accuracy. Exploring other objective functions such as minimization of cost, minimization of emissions and multi-objective approaches to optimization amongst others. Converting the deterministic optimization approach used in this study to a stochastic one considering uncertainties. The EVCS also has to be modified so that it can be used in a bi-directional manner and not only serve as a load which has been proven useful in many studies. This study amongst others would form the basis of proposals to installing an EVCS and a modern EMS within the campus. VOLUME 8, 2020