The Comparison Study of Short-Term Prediction Methods to Enhance the Model Predictive Controller Applied to Microgrid Energy Management

Electricity load forecasting, optimal power system operation and energy management play key roles that can bring significant operational advantages to microgrids. This paper studies how methods based on time series and neural networks can be used to predict energy demand and production, allowing them to be combined with model predictive control. Comparisons of different prediction methods and different optimum energy distribution scenarios are provided, permitting us to determine when short-term energy prediction models should be used. The proposed prediction models in addition to the model predictive control strategy appear as a promising solution to energy management in microgrids. The controller has the task of performing the management of electricity purchase and sale to the power grid, maximizing the use of renewable energy sources and managing the use of the energy storage system. Simulations were performed with different weather conditions of solar irradiation. The obtained results are encouraging for future practical implementation.


Introduction
Microgrids (MG) are integrated energy systems composed of distributed energy resources and multiple electrical loads operating as an autonomous grid; these can be either parallel to or islanded from the existing power grid.A microgrid can be considered a small-scale version of the traditional power grid, its small scale leading to far fewer line losses and lower demand on the transmission infrastructure.All of these advantages are motivating an increased demand for microgrids in a variety of application areas such as campus environments, military operations, community/utility systems, as well as commercial and industrial markets [1].An MG can provide optimal electricity distribution to consumers by implementing control strategies.Nowadays, the MG concept focuses primarily on the integration of distributed renewable energy sources, stationary storage batteries and methodologies for management and control, as is shown in [2][3][4][5][6].
In the literature, there are several MG methods and applications.In [7], the basic structure of an MG is presented, and a detailed discussion about MG control techniques is included.In [8], the authors review the latest documents related to the use of hybrid energy storage systems (HESS), which facilitate the introduction of renewable energy sources (RES) to MGs.A centralized and decentralized control architecture for microgrids and their possible applicability to serve the particular needs in microgrids are discussed in [9].In [10], a summary of the available approaches is presented (system configuration, unit size and control and energy management) along with those currently being investigated for the optimal design of RES hybrid systems.A decentralized energy management system based on multi-agent systems theory employing fuzzy cognitive maps for its implementation is proposed in [11].In [12], a framework for microgrid energy management, where each agent is seeking an optimal goal-directed action planning under power consumption, production and price uncertainties, is proposed, and the optimal scheduling strategy is achieved by using a robust optimization approach.A multi-objective optimization in order to minimize the energy cost and greenhouse gas emissions in a hybrid system including photovoltaic (PV), wind, battery storage and a micro gas turbine is proposed and implemented in [13]; furthermore, in [14], an optimal energy management of a standalone microgrid under different operational modes is studied; the system is tested under two different operational policies where microgrid power generation sources work with and without the battery storage system.Moreover, in [15], a control strategy for the integration of distributed storage systems in a photovoltaic and micro-current network is developed, which also includes varying loads.The proposed control allows the maximum use of photovoltaic energy under different MG operating conditions and provides a smooth transfer between network connection and isolation.In [16], a strategy based on model predictive control (MPC) is presented, where the optimization problem has been formulated as a mixed integer linear problem (MILP), the control algorithm for which has been validated in an MG located at the Center for Renewable Energy Sources and Saving, in Pikermi-Athens, Greece.On the other hand, in [17], an MPC algorithm in which the optimization problem has been formulated as a mixed-integer quadratic optimization (MIQP) has been applied to a microgrid located at the University of Seville, Spain.In [18], the authors compared the MPC techniques and the hysteresis band (HB) method in energy dispatch within a microgrid.The main difference between MPC and HB is that MPC guarantees optimality, while HB does not.The authors conclude that there is a dramatic reduction in the cost of operation using MPC techniques.
MG operating requirements are usually satisfied by a hierarchical control structure [19], where several authors have shared the idea of considering three levels associated with different time scales [20,21].The primary level operates at a fast time scale, maintaining voltage and frequency stability during changes in the generation or load, or after switching to the island mode.The secondary level is responsible for ensuring that the voltage and frequency deviations are adjusted to zero after a load or generation change is produced within the microgrid.This tertiary control is used to control the power flow between the microgrid and the main grid and for optimal operation over large time scales [22].
The MG's control loop performance can be improved when disturbance information is available.This can be done using a feedforward controller based on disturbance estimations, mainly of the demand and the available renewable energy.There are many methods for estimating energy demand, and these can be characterized by the prediction horizon length and the selected methodology.The prediction horizon may vary depending on the application and can be considered as a short-term forecast for predictions up to 60 min [23,24] or a long-term forecast for hourly, daily and monthly prediction values [25,26].On the other hand, disturbances are usually represented as time-series structures mainly due to their stochastic behavior.Time-series models are one of the ways to estimate future energy demand values.These models are obtained using past data and are used to estimate future behavior along a prediction horizon.Time series models are based on the assumption that modeled data are autocorrelated and characterized by trends and seasonal variations.Thus, well-known autocorrelated models like autoregressive moving average (ARMA), autoregressive integrated moving average (ARIMA), autoregressive moving average with exogenous inputs (ARMAX) and autoregressive integrated moving average with exogenous inputs (ARIMAX) [27] can be used.Artificial neural networks (ANN) are a different approach for disturbance estimation when the design is training-based and no statistical conditions are assumed for the source data.Neural networks (NN) are widely accepted as a technology for predicting time series, offering an alternative way to solve complex problems [28].Neural networks and ARIMA models are often compared in terms of forecasting capacity.As a tool for nonlinear system identification, the nonlinear autoregressive with exogenous inputs (NARX) network has been successfully applied to a number of real-world input/output modeling problems, such as biomedical time series modeling [29], communication network traffic prediction [30] and energy demand [31].
This paper studies the effect of using different prediction strategies in a closed-loop control framework for energy management in a real case study.Methods based on time series and neural network models are used for the photovoltaic panel energy production and the energy demand of the load systems (building and greenhouse).The models are identified using real data collected at a sampling time of 1 min during the years 2014 and 2015.The microgrid optimal energy management problem is formulated including binary variables in the constraints and solved as mixed integer quadratic programming (MIQP).In this way, the prediction models are utilized to provide a feedforward framework, and the usability of the predictions over different prediction horizons is discussed.It is important to emphasize that feedforward action effectiveness is directly connected to the predictions' quality.Significant improvement is obtained for closed-loop system behavior compared to the case of constant future predictions.Moreover, controller performance is compared to an ideal case with perfect future predictions, and a discussion is carried out to evaluate the prediction methods.
The rest of the paper is organized as follows: in Section 2, the microgrid subsystems, the methods and the performance criteria used to model energy demand and electrical energy production are briefly shown, and the energy hub's methodology is also presented; in Section 3, the results and discussions are shown, and finally, in Section 4, the conclusions are outlined.

Materials and Methods
The MG is composed of a photovoltaic system, an electric vehicle whose batteries can be used as an energy storage system (the use of the electric vehicle is not considered in this paper) and two load subsystems (a building and a greenhouse).Figure 1 shows the microgrid.Additionally, the microgrid is connected to the main grid, allowing the purchase and sale of energy when necessary.

The Greenhouse
The greenhouse studied in this paper is a multispan 'parral type' greenhouse (see Figure 2), with a surface area of 877 m 2 , oriented in a N-S direction.The facilities are situated at the Cajamar Foundation experimental station,'Las Palmerillas', in the El Ejido municipality, Almería, southeastern Spain [32].The greenhouse has lateral and zenithal ventilation powered by independent AC motors, an aero-thermo heating system from hot water pipes fed with biomass, a CO 2 enrichment system created from burning biomass, shade nets, as well as water and nutrient feeding systems.It is equipped with measurement equipment for 52 variables and is designed to develop identification tests and to implement climate control, fertigation and electric power strategies.Furthermore, the greenhouse has energy demand sensors (SINEAX M 561) programmable with an RS-232 interface run on a computer with the appropriate software.In Table 1, the variables measured and the model of the sensors used are detailed [33,34].The CIESOL ('Centro de Investigación en Energía SOLar') building is a solar energy research center, which is located inside the Campus of the University of Almería, in southeastern Spain (see Figure 3).It is distributed over two floors with a total surface area of 1071.92 m 2 , comprising: six offices, all with an easterly orientation and located on the ground floor (with the exception of the main office, situated on the upper floor); eight laboratories facing north (four located on the ground floor devoted to 'solar chemistry'; and the other four located on the upper floor: two for the 'Modeling and Automatic Control unit' and the other two for the 'Evaluation of Solar Resources unit'); a plant where a high efficiency boiler and an absorption machine are located; and finally, the center's employee rooms, such as the kitchen and toilets.

PV System
The PV system is made up of various sets located on-site at the University of Almería.One of these (see Figure 4) is located on the sloping roof of the CIESOL building and has the following characteristics: a total number of 4 modules linked in 3 sets of 14 panels/series, each with a unit capacity of 222 Wp/panel where the electrical energy produced is in the form of direct current at low voltage, then converted to alternating current through an inverter at a voltage of 230 V, forming a photovoltaic field of 9.324 kWp.Table 2 shows the summary and the main electrical characteristics of each module.The total set at the University of Almería that comprises the PV system considered in this paper forms a photovoltaic field that can reach 110 kWp.The bank of 6 batteries in the electric vehicle (Figure 5) that have been used in this MG is the Green Saver model with lead-acid silicone technology.Table 3 shows the summary for one battery.The MG uses a centralized controller [35] unit, which is responsible for correct process operation.The objective of this controller is to attend to the demand of the greenhouse and the CIESOL building, buying as little energy as possible from the main grid.The controller uses car batteries as energy storage units to optimize energy use during the day.

Hub Methodology
The methodology used in this paper to model the process has been presented in [36,37].An energy hub is defined as the interface between energy production, consumers and the transmission line.From a system standpoint, a hub can be identified as a unit that provides the following features: (1) power input and output; (2) energy conversion; and (3) energy storage.Some of the main features of the hub are:

•
Within energy hubs, losses occur only in the converter and storage elements.

•
If not explicitly mentioned, unidirectional power flow from the inputs to the outputs of the converters is assumed.

•
Power flow through converter devices is characterized by power and energy efficiency only; no other quantities are used.
The methodology is summarized as follows: a single converter converts, at time instant k, a generic r input flow u L r (k) of a generic hub in a p output flow y p (k), where superscript L is associated with converter input flows.The input-output conversion is defined by the so-called coupling factor γ L p,r , which correspond to a converter steady-state conversion efficiency between the input and output flows: If we have several converters, it can be written as follows: where Γ L i is the converter coupling matrix.From a discrete-time point of view, the internal storage state x i,s at sampling time k + 1 depends on the state at the previous sample k and on the total exchanged flow ǔE i,s (k) during the period ∆T ranging from k to k + 1 sampling, where the values of steady state input-output flow are described by the relationship: where e i,s (k) is the efficiency of the i, s interface charging/discharging hub, which describes the energy exchange between the system and the storage.This factor depends on the direction of flow exchanged as follows: where e + i,s and e − i,s are the charging and discharging efficiency, respectively [38].Assuming ǔE i,s (k) remains constant during ∆T: If we consider several storage systems: then, a single hub can be represented by the following condensed form:

Performance Criterion
When a certain method is used to estimate process variables, the differences between the estimated and real values can be employed to evaluate the method.Different statistical indexes can be utilized to compare the results of the forecasting models [25,39,40].In this work, the mean square error (MSE), the root mean square error (RMSE), the mean absolute percentage error (MAPE) and the coefficient of determination R 2 will be used.The MSE is determined by: where n is the forecasting horizon, y k is the real signal at time k and ŷ is the estimated signal at time k.When a zero value is obtained for MSE, it means that the estimator ŷk predicts parameter observations y k with perfect accuracy.RMSE is given by the square root of MSE: MAPE is defined as follows: The coefficient of determination R 2 provides a measurement of how well future outcomes are likely to be predicted by the forecasting method.It is calculated as follows: where ȳ is the arithmetic mean value of the measured signal.

System Modeling and Control Algorithm
This section describes the modeling of the plant and the controller to be used.An MPC controller with linear constraints, whose formulation is detailed in [35], has been utilized in the MG control unit.To attempt the objectives described in Section 2.1.5,the following variable selection was defined.

Manipulated Variables
The MG input vector is defined according to: where P GridPurch and P GridSale are the purchase and sale of energy to the external network and P BAT CH and P BAT DISCH are the charging and discharging power of the batteries.

Disturbance Vector
The external disturbance to the MG is solar irradiation (measured in Wm −2 ) on the microgrid solar panels and directly affects the MG energy balance.

Controlled Variables
The controlled variables vector (system output vector) is defined as: where P CIE is the energy demand of the CIESOL building (kW) and P gh is the greenhouse energy demand (kW).

Microgrid Model
The evolution of the microgrid state variable (the state of the batteries' charge SOC BAT ) is described by the linear model: where η BAT CH and η BAT DISCH are the charging and discharging efficiency of the battery, respectively.T s is the sample time, and C BAT is the battery capacity.
Net power balance (P rem (k)) within MG is considered.P pv = η solar Irrad(k) and P solar = P pv .P pv , η solar and Irrad(k) are, respectively, the energy production of the PV panels, the solar energy conversion efficiency and the solar irradiation that acts as a disturbance.Figure 6 shows the control diagram.Therefore, the MG can be modeled as a single hub in a condensed form as: where:

Controller
The controller is designed to perform the energy management of the microgrid under energy changes during the generation or loads and managing the use of energy storage system.The MPC cost function is given by: ỹ(k + l) = P CIE (k) + P gh (k) where l = 0, . . ., N p − 1, Q u and Q x are positive definite weighting matrices, f is a linear function and N p is the prediction horizon.Regarding the notation " ã" over variables, this is used to denote variables over the prediction horizon; a and a denote the minimum and maximum allowed values, respectively.The first term of the objective function (20) has been used for the management of renewable sources and the purchase/sale of energy from the grid.The weights Q u and f are tuned to minimize the use of the network and the storage system.In the second term, Q x is tuned to maintain the storage load around 50% allowing deviations from this value when there is a need to store more energy and use the stored energy; the minimum charge state allowed in the batteries is 30%.An initial state in the batteries of 80% has been considered.
To ensure the proper use of the renewable energy sources, to manage the purchase and sale of electricity to the external network and to use the storage to minimize oscillations between production and demand, binary variables are introduced to the formula as constraints in the following way: The state space formulation of the hub has been transformed into the mixed logical dynamic (MLD) formulation considering concepts of propositional calculus and integer linear programming, as shown in [41].This formulation makes it possible to include binary variables introduced in a discrete-time dynamic system in order to describe the evolution of the system's continuous and logic signals in a unified model.
The conditions P j (k) > 0 in Equations ( 24), ( 25) and ( 27) and condition P BAT DISCH < 0 in Equation ( 28) can be associated with a binary variable δ j for j = {GridPurch, GridSale, BAT CH } and δ BAT DISCH , respectively, such that: Equation ( 30) can be expressed by the inequalities: where and is a small tolerance (typically the machine precision).
In Equation (24), P GridPurch (k) > 0 gives δ GridPurch (k) = 1, which means that the energy is purchased from the grid and therefore the weight is used on the purchase value, in (25); on the other hand P GridSale (k) > 0 results in δ GridSale (k) = 1, which means that the energy is sold to the grid, and therefore, the weight is used on the sale value.Analogous analysis is performed for Equations ( 27) and (28).Furthermore, Equations ( 26) and ( 29) are associated with the exclusive sum (exclusive or), such that: This means that only one action can be performed once, buying or selling energy and charging or discharging battery energy; moreover, doing neither is not possible.

Simulation Results and Discussion
This section presents the results obtained from applying the control and prediction methods.As already mentioned, the analysis mainly focuses on load prediction, which has been executed with forecasting steps given minute by minute.The energy demand and production were previously filtered using the Savitzky-Golay filter [42] in order to preserve initial distribution characteristics such as the relative maximum and minimum, as well as the width of the peaks.Data from 2014 have been used to identify the models and during different days of the year 2015 have been used for validation (see Figure 7).Different scenarios are presented using the proposed controller in order to realize optimal energy distribution and to observe the contribution made by the prediction models on two different significant days.

CIESOL Building and PV System
Two models for each system were proposed.Firstly, we compared several combinations of the autoregressive moving average (ARMA) models using the final prediction error (FPE) [43]; these models were based on historical energy demand and energy production data.The data used to identify these models were chosen from data collected over the year 2014.The ARMA model for a single-output time series is given by the following equation: where y(k) is the system output and e(k) is the model error.The ARMA structure reduces to the autoregressive (AR) structure for C(z −1 ) = 1 as is mentioned in [43].
The discrete-time polynomials obtained for the CIESOL building energy demand (A1) and for the energy production of the PV system (A2) are detailed in Appendix A.
Additionally, for the same periods and minimizing the MSE, we evaluated several combinations of the NAR neural network multilayer perceptron using the Levenberg-Marquardt algorithm.These combinations included networks with different numbers of hidden layers, different numbers of units in each layer and different types of transfer functions.The chosen configuration consisted of one hidden layer with 11 and 10 neurons for CIESOL and the PV system, respectively, and a hyperbolic tangent sigmoid transfer function within this layer, defined by the equation: where n is the weighted input of the hidden layer and f (n) is the output of the hidden layer.For the output layer, a log-sigmoid transfer function was selected (36), and eight and six neurons for CIESOL and the PV system were used, respectively.
In order to evaluate prediction accuracy, these models were evaluated for predictions with 5, 10 and 15 horizon samples.Figure 8 and Table 4 show the obtained results.For the CIESOL building, one can observe that both models (ARMA and NN) produced good performance; however, it can also be observed that the NN model better approximated the peak demand and showed better results for all sample horizons.One can see that the neural networks method is able to capture sudden changes, whereas the ARMA method only follows the trend.The lower MSE, RMSE and MAPE values of the NN model for all horizons show that it is better than the ARMA model; furthermore, the R 2 is the square of the sample correlation coefficient between the real samples, and their predicted values-values close to one are desired.The resulting R 2 values for this analysis are satisfactory, with the NN model presenting higher values than the ARMA model.However, for a 15-sample prediction horizon, one can observe that a substantial change exists for that of the 10-sample prediction horizon in both models; that is, both models are able to follow the trend, but the energy demand peaks have not been captured.Conversely, for the photovoltaic system, the best results derived from the neural network model for all sample horizons.Moreover, one can see that the two models produce a small predicted signal delay when clouds are passing.Nevertheless, the neural network model provides the best performance according to Table 4 with smaller differences compared to the ARMA model, in which the absolute percentage error measurement shows that the best forecasting accuracy is provided by the NN model (this does not exceed 13.5% for the 15-sample horizon).One can also observe that, when there is a substantial change in radiation, both 15-sample prediction horizon models take longer to follow the process dynamics.In contrast, there is no great change in the 10-sample prediction horizon.

The Greenhouse
The energy demand has been considered as a MISO (multi-input single-output) system, where inside temperature, v 1 (k), outside temperature, v 2 (k), inside relative humidity, v 3 (k), global radiation, v 4 (k), blower, u 1 (k), pump heating, u 2 (k), zenithal ventilation, u 3 (k), and lateral ventilation, u 4 (k), were the input variables, and energy demand, y(k), was the output variable.All greenhouse variables were measured with a sampling period of 1 min.In order to calculate future predictions, the future inputs were considered as known; however, these inputs can be estimated by other prediction models.A model based on Bayesian networks was presented in [34] considering these variables, where the energy demand was classified into four classes.One of the main problems when considering energy demand classes is that information is lost about the real demand values.
In this paper, the real value of the energy demanded is represented; meaning energy information is not lost when defining it within classes.It has been observed that energy demand behavior in the greenhouse was that of low energy demand during the spring-summer and high energy demand during the autumn-winter.This is because during the spring-summer, there is no crop, and the cultivation period occurs during the autumn-winter, when a controlled temperature inside the greenhouse has to be maintained using different heating systems due to the low overnight temperatures.Accordingly, four models were proposed, an autoregressive with external input (ARX) model and one based on neural networks for the autumn-winter season, as well as an ARX model and an NN model for the spring-summer season.To identify the spring-summer models, we considered data from 22 February 2014-21 September 2014.For the autumn-winter season, data from 22 September 2014-21 February 2015 were chosen.
Several ARX models were performed.An ARX model was observed as follows: Using Akaike's Information Criterion (AIC) [44], better dynamic behavior adjustment was presented to the real system, where α 1 = 4 and α 2 = 5 for the autumn-winter model and β 1 = 6 and β 2 = 10 for the spring-summer model were used, respectively.The discrete-time polynomials obtained for the autumn-winter season (A3) and for the spring-summer season (A4) are shown in Appendix A.
On the other hand, to find the optimal network architecture, several combinations of NARX neural network multilayer perceptron were evaluated using the Levenberg-Marquardt algorithm minimizing the MSE.These combinations included networks with different numbers of hidden layers, different numbers of units in each layer and different types of transfer functions.
A configuration was chosen consisting of a hidden layer with 11 and 12 neurons for the autumn-winter season and spring-summer season, respectively, along with a hyperbolic tangent sigmoid transfer function in this layer, defined by (35).For the output layer, a linear transfer function was selected with eight neurons for the autumn-winter season and eight neurons for the spring-summer season.
Figure 9 shows the one-day forecasting results during the autumn-winter and the spring-summer season of 2015 using a prediction horizon of 5, 10 and 15 samples.The results are summarized in Table 5.The changes in energy demand during the autumn-winter season were more abrupt than in the spring-summer season, meaning the models obtained for the autumn-winter season had a greater prediction error compared to the spring-summer season models.The resulting values of R 2 for this analysis are satisfactory for both models with a 5-and 10-sample prediction horizon; however, one can see that for a 15-sample prediction horizon, the coefficient R 2 is below 0.7 for the spring-summer season.For the autumn-winter season, the ARX model values are 0.990, 0.919 and 0.767, compared to the NN model values of 0.986, 0.907 and 0.745 for the 5-, 10-and 15-sample prediction horizons, respectively.Furthermore, for the spring-summer season, the ARX model values are 0.985, 0.890 and 0.663 against the NN model values of 0.985, 0.867 and 0.473 for the 5-, 10-and 15-sample prediction horizons, respectively.Consequently, the ARX models give better results than the NN models for both seasons.

An Optimal Distribution Using the Proposed Controller
The predictive controller previously presented in Section 3 has been applied to the MG.The results presented in this section were obtained considering the following conditions:

•
The simulation used real data collected for a sunny day and a day with passing clouds.

•
Three similar sets of batteries that can reach a total capacity of C = 20 kWh and a charging η BAT CH = 0.8 and discharging η BAT DISCH = 0.7 efficiency, respectively, and 10 similar greenhouses, such as those presented in the materials section, were considered.

•
The cost involved in the degradation of the batteries has been considered constant.In addition, the maintenance cost of the photovoltaic system has not been considered.

•
It is considered to maintain the state of charge of batteries at 50% throughout the day.

•
Figure 10 shows the energy demand profiles for both types of day.

•
The cost function weights (20) were adjusted using simulations.

•
The proposed controller was applied to the microgrid.The aim of the controller is to perform the energy management of the microgrid during changes in generation or loads.The controller was implemented in MATLAB [45] using the YALMIP [46] toolbox and the CPLEX [47] solver.

•
The simulations were performed using a control horizon of N c = 5 samples and a prediction horizon, which varied from 6 to 15, (N p = 6, 7, . . ., 15).In order to verify the contributions of the models presented in Sections 4.1 and 4.2 to the predictive control techniques, three different scenarios have been considered in this paper: (i) Perfect information: Scenario 1 is performed assuming that the real data of demand (P CIE and P gh ) and energy production (P pv ) are known.(ii) Imperfect information: Scenario 2 is performed using the best forecasting models of demand (the NN model for P CIE and the ARX model P gh ) and energy production (the NN model for P pv ).(iii) No Information: Scenario 3 is performed assuming that future values are not known and predictive models for demand (P CIE and P gh ) and energy production (P pv ) are not used.This means that the predictions are considered constant along the prediction horizon.
Figures 11 and 12 show the behavior simulations for the electrical energy distribution and the SOC in Scenario 2 on a sunny day and a day with passing clouds for a prediction horizon of 6, 10 and 15 samples, respectively.One can see that, as the prediction horizon grows, there are larger fluctuations in the variables P Grid Purch , P Grid Sale , P BAT CH and P BAT DISCH , causing greater effort from the batteries and resulting in more energy being bought and less energy being sold.Figures 11d-f and 12d-f show how the SOC of the batteries tries to stay around its reference for a sunny day and for the day with passing clouds, respectively.Furthermore, one can observe that the lower prediction horizon has a greater variation range during the day.As can be seen, the three scenarios for both days have been realized trying to maintain the same level (50%) of the SOC throughout the day and considering the design of the controller; this has been done with the aim of observing the contribution of prediction models.However, depending on the controller design, the results may vary.In the design of the controller, it could be required that at the end of the day, the SOC tries to maintain a different reference level.In addition, small differences can be observed by considering the total sum of each manipulated variable during the day (see Tables A1 and A2 in Appendix B and Figure 13), where the trend of the variables is shown; these trends indicate in a generalized way that as the prediction horizon increases, more energy is bought and less energy sold, while there is less energy charging and less energy being discharged into the batteries.
Furthermore, it can be observed that on the sunny day, Scenario 2 generated better results than Scenario 3 for a horizon prediction of 6-11; while for a prediction horizon of 12 and above, it is evident that Scenario 3 is closer to Scenario 1. Conversely, on the day with passing clouds, with a prediction horizon of 6-13, Scenario 2 presents better results than Scenario 3.  To observe the differences in Scenario 2 and Scenario 3 compared to Scenario 1, the average absolute error ∆ was used.This index is given by: for k = {GridPurch, GridSale, BAT CH , BAT DISCH }.
For the optimal distribution of energy, it is a priority to have less energy purchased (P Grid Purch ), more energy sold (P Grid Sale ) and to have greater use of the batteries; that is to say, in terms of charging (P BAT CH ) and discharging (P BAT DISCH ), but with less fluctuations.Consequently, a prediction horizon of eight and six yields the best results on the sunny day and the day with passing clouds, respectively, using Scenario 2; this is shown in Figure 13 and Table 6, where ∆ 1,2 and ∆ 1,3 show the performance of Scenario 2 compared to Scenario 1, and Scenario 3 compared to Scenario 1, respectively.As shown in Figure 13 and Table 6, for the sunny day up to horizon 11, Scenario 2 gives better results, whereas starting from horizon 12, the best choice is Scenario 3. The same analysis can be carried out for the cloudy day, where the changing point is horizon 14.Regarding the energy exchanged with the main grid, it is possible to conclude that, for Scenario 2 with small prediction horizons, the controller decided to sell more energy than it did with longer horizons, when compared to Scenario 3.This is due to the fact that predictions are better with smaller horizons and are degraded as the horizon increases.It is important to point out that, in this particular case, the amount of energy sold to the main grid is low due to the small amount of excess power from the solar panels; this can be raised by increasing the PV panels' nominal power.This MG change can provide a more profitable economical operating point.

Conclusions and Future Works
This work presents the use of different time series forecast and neural network methods to obtain energy demand and energy production estimations.In addition, a controller has been proposed to optimize the use of renewable energies in a microgrid; this controller has also been proposed to regulate battery use, where charging and discharging of the battery system is allowed to oscillate around a desired load value.Furthermore, the contribution of short-term model prediction has been verified for optimal energy distribution (based on MPC) in an MG.As can be observed, although the differences are minimal, the use of short-term prediction models provides an improvement on the optimal distribution of energy for prediction horizons of less than 12 min on the sunny day and less than 14 min on the day with passing clouds.
In future work, the use of the electric vehicle will be considered as a vehicle connected to the grid (V2G).Furthermore, prediction models will be recalibrated to improve horizon predictions over 15 min; moreover, uncertainties will be considered of the PV system and load demand using the probability density function (PDF) of solar radiation and the normal distribution function for prediction purposes.We will propose a secondary level controller over a slow time scale (1 h).The aim is to carry out an economic optimization where the purchase and sale prices (e/kWh) of energy are considered; these prices vary hourly according to the daily market.Another important topic is to deal with the stochastic nature of prediction errors using probabilistic constraints.

Figure 2 .
Figure 2. Greenhouse and acquisition data system.

Figure 9 .
Figure 9. Results for one day during the autumn-winter season from the ARX model and the neural network model with a (a) 5-, (b) 10-and (c) 15-sample prediction horizon; and for one day during the spring-summer with a (d) 5-, (e) 10-and (f) 15-sample prediction horizon for the greenhouse.( ) Measured, ( ) ARX model, ( ) NN model.

Figure 10 .
Figure 10.Total energy demand for a ( ) sunny day and a ( ) day with passing clouds.

Figure 13 .
Figure 13.Total energy (kW) used on a sunny day (a,c,e,g) and a day with passing clouds (b,d,f,h) where ( ) is Scenario 2 and ( ) is Scenario 3.

Table 1 .
Sensory system installed in the greenhouse.

Table 2 .
Summary for the PV module.

Table 3 .
Main battery features.

Table 4 .
Performance indexes for the prediction model of the CIESOL building and the PV system with 5-, 10-and 15-sample prediction horizons.

Table 5 .
Performance indexes for the greenhouse prediction model with 5-, 10-and 15-sample prediction horizons.

Table 6 .
Index ∆ of the performance for the differences between Scenarios 2 and 3 on a sunny day and a day with passing clouds.