A Predictive Control Strategy for Energy Management in Micro-Grid Systems

: The integration of renewable energy sources (RES) was ampliﬁed, during the past decades, in order to tackle the challenges related to energy demands and CO 2 increases. Recently, many initiatives have been taken by promoting the deployment and the usage of micro-grids (MG) in buildings, as decentralized systems, for energy production. However, the variable nature of RESs and the limited size of energy storage systems require the deployment of adaptive control strategies for efﬁcient energy balance. In this paper, a generalized predictive control (GPC) strategy is introduced for energy management (EM) in MG systems. Its main objective is to efﬁciently connect the electricity generators and consumers in order to predict the most suitable actions for energy ﬂow management. In fact, based on energy production and consumption proﬁles as well as the availability of energy storage systems, the proposed EM will be able to select the best suitable energy source for supplying the building’s loads. It will efﬁciently manage the usage of energy storage and the utility grid while maximizing RESs power generation. Simulations have been conducted, using real-sitting scenarios, and results are presented to validate the proposed predictive control approach by showing its effectiveness for MG systems control.


Introduction
In the past decades, energy management (EM) systems have been proposed for improving the global performance of buildings while maintaining a suitable occupants' comfort. Recent studies showed that energy consumption in buildings could be efficiently reduced by deploying micro-grid (MG) systems [1]. The aim is to minimize the electrical bill's cost while extending the lifetime of the system's components (e.g., converters, batteries, and fuel cells). Generally, an EM system incorporates control approaches and functions, which maximize the MG system's efficiency and minimize energy consumption. In some cases, control approaches use single-objective function procedures (e.g., maximizing the quality of services). Without considering different operating constraints, these procedures are easier to implement and to deploy in real-sitting scenarios. Moreover, an EM control strategy, which takes into consideration only the energy availability within MG components (e.g., energy sources, storage devices, utility grid), could be implemented by simple algorithms. These algorithms implement procedures that switch, at each time, from RES to storage devices or to the traditional electrical grid (TEG). For instance, actual commercial inverters are able to manage the interconnection between renewable energy sources (RESs), energy storage systems, and the utility grid by incorporating a single-objective function. In particular, the MG system's EM takes into consideration only the availability of the electricity for being supplied to buildings loads. For instance, the inverter can use either batteries or the utility grid without taking into account other parameters, such as the actual electricity cost as well as batteries charge/discharge cycles. However, high battery charge/discharge cycles, in a limited time, could decrease their performance, which impact on the system's profitability [2]. In other cases, controllers can interact, in real-time, with energy sources generators (e.g., solar, wind) in order to limit the power generation (limited power point tracking). The aim is to ensure the quality of electrical services (e.g., frequency, voltage), and consequently minimizing the profitability of MG system's components. Despite their advantages, they could have, however, negative impacts on the batteries' lifecycle and system's profitability. Therefore, context-awareness principles and predictive analytics could be exploited for developing context-driven and predictive control approaches, such as generalized predictive control (GPC) [3]. It is worth noting that GPC approaches are not new and have been applied in grid and EM control applications. However, due to recent development of information and communication technologies (ICT), these approaches could be deployed in real-sitting scenarios by using machine learning algorithms and recent artificial intelligence techniques. The latter are mainly used to forecast/predict control input parameters, such as power production and consumption. Furthermore, the improvement of microcontrollers and microprocessors offers more advantages for the predictive control deployment in embedded devices, such as in power converters [3,4].
The work presented in this paper introduces a predictive control approach for EM in MG systems. In fact, due to the development of information and communication technologies (e.g., machine learning, IoT/big-data, smart metering) with its integration to the energy management component, the predictive control can have a new revolution using machine learning algorithms to forecast the input control parameters. In addition, the improvement of microcontrollers and microprocessors offers more advantages for the predictive control deployment. The proposed control approach is capable to manage energy flows in MG systems using data prediction and forecasting algorithms. Mainly, collected data (e.g., power production, power consumption, batteries' state of charge) can be used to train machine-learning algorithms in order to generate the control input parameters. The main objective is to improve the performance of existing predictive control methods by using recent Internet of things (IoT) and big-data technologies [4][5][6]. In fact, unlike the above-mentioned approaches, the proposed control approach considers multiple objective functions, which take into consideration batteries charge/discharge cycles as well as the electricity price forecasting. Its main aim is to ensure, in an optimal way, the continuous electricity supply, from different installed sources (e.g., RESs, batteries, TEG), to building's services. The proposed approach is based on the GPC model, which is able, based on forecasted inputs values, to generate a sequence of future control actions over a prediction horizon. This requires an advanced metering infrastructure, which allows measuring and predicting all inputs values. Therefore, an MG was deployed together with an IoT/big-data platform in order to conduct experiments and validate developed models. As depicted in Figure 1, the MG system contains RESs and battery storage systems, which are connected together with the utility grid in order to supply the electrical energy to building's loads (e.g., lighting, ventilation). The IoT/big-data platform was developed and deployed in order to allow measuring and forecasting RESs power generation, loads consumption, and batteries state of charge (SoC) [7,8]. An embedded system was also developed and contains mainly a microcontroller, which is connected to several sensors (e.g., current, voltage) and actuators for performing selected and generated actions by the GPC-based controller. This later, based on forecasted values, allows switching between different energy sources, batteries, and the utility grid. The GPC is deployed for conducting experiments and compared against a model predictive control (MPC) strategy, as already developed in our previous work [3]. The remainder of this paper is organized as follows. Section 2 presents a brief state of the art of predictive control deployment for EM and power converter control. Materials and methods are presented in Section 3, by putting more emphasize on system modeling for the GPC algorithm deployment together with its optimization functions and constraints. The results and interpretations are discussed in Section 4, by deploying the investigated GPC model and control strategy. Conclusions and perspectives are outlined in Section 5.

Related Work
Appropriate EM systems, incorporating control strategies, are required for reliable and robust operation of MG systems. These control strategies must take into consideration the nature of installed RES, storage systems, and their interconnection to the electrical networks. Figure 2 presents the future architecture of MG systems together with the required control strategies, which could be adopted at each system's level. It highlights the role of participating entities in this new smart electricity network (e.g., manufacturers, electricity operators, consumers). However, the most significant challenge of this new MG system's architecture is the development and the deployment of suitable control strategies. These strategies are required for efficient energy balance while ensuring a high level of power quality and favoring the active integration of prosumers in its related emerging electricity market. In addition, within this new MG system architecture, control strategies must take into consideration the multiple disturbance variables and constraints, which are present at different time scales.
Recently, numerous approaches have been proposed and could be classified according to the MG system's layers, as depicted in Figure 2, including primary, secondary and tertiary controls. At the primary control level, the power converter is connected to RESs and interacts directly with the EM system. This later is responsible for improving the frequency and the voltage stability by preventing circulating the current among converters. Generally, frequency-and voltage-power droop controls are deployed as the primary controller [9]. The droop control method is often used at this level in order to emulate physical behaviors that make the system stable and more damped [10]. In fact, the load changes in the MG cause direct current (DC) link voltage variation and the droop controller can change the output power of the converter by interacting on the voltage variation. It includes a virtual impedance control loop to emulate physical output impedance. Moreover, in this hierarchical layer, the control signals are sent in milliseconds [11] in order to stabilize the internal MG buses, to address some power quality issues, and to track the maximum power generated by RESs. Due to communication time, which should be minimal or negligible, the generated control signals are based only on local measurements (e.g., voltage, current). At the secondary control layer, the controller ensures, after system load variation, that the power levels (e.g., frequency, voltage, current) into the MG systems are within the required standards values. The standardization is considered by the converters' manufacturers in order to ensure a seamless MG connection or disconnection to or from the utility grid. It can include a synchronization control loop in order to avoid voltage and current violations by sending modified power references to the distributed energy sources. In addition, this control layer is considered as a mediator between the third and the primary layers. In fact, the second layer corrects the frequency and voltage deviations between the optimization upper reference signals and real MG's measurements, which have not been solved by the primary control. In this context, this control level can be formulated as a redundant optimization problem in order to achieve more accurate outputs [12]. As shown in Figure 3, this control level is considered as a lower controller layer. It can be designed to reach the optimal power references toward the primary control layer, which is responsible for generating the commands (e.g., turn-on, switch-off) to each commendable unites in the converter to reach the desired set point. At this layer, the EM system takes its decisions based on dedicated inputs, mainly RES power generation, power consumption, battery SoC, weather forecast, and the energy price estimation [13,14]. Generally, the control strategy is designed as an optimization problem taking into account both discrete (e.g., RESs disconnection decisions, the operation state) and continuous variables (e.g., bus voltage, active and reactive power). This optimization is most often solved using integer linear programming techniques [15][16][17]. Unlike primary and secondary control layers, the tertiary control manages the power flow between the MG and the electrical grid on the one hand and between the MG and eventually neighboring MG on the other hand. This control, throughout the EM, allows the optimal operation and planning of the MG system taking into consideration the second layer control outputs [9]. The main objective functions of this control layer are to minimize the daily operating costs, to maximize the profitability of the installed RES system, and to improve the self-consumption of the RESs. These functions are formulated as optimization problems by including the energy cost function and environmental/operational system's constraints, as shown in Figure 3. By considering those constraints, the optimization problem could be solved using convex optimization techniques (COT), which compute the appropriate MG system's operations and daily cost. The commands and actions in this layer are updated every second, minute, hour, or even daily, depending on deployed control strategies. In addition, the power generation and consumption together with batteries' SoC have to be measured and processed in order to generate new reference values to the controller. Recently, predictive approaches have been proposed for advanced systems' control according to defined constraints. Their aim was to develop predictive controllers for efficient energy flow in MG systems. These controllers could forecast future actions and decisions, but they require forecasted inputs' values (e.g., power consumption/production). With recent progress in IoT and big-data technologies together with machine learning and artificial intelligence techniques, it is now possible to deploy sensors for gathering contextual data [13]. These data could be processed and used for predicting n-step-ahead values. Therefore, the forecasted values are the main inputs that are used by predictive control approaches for generating the most suitable and future actions [5].
MPC and GPC are the well-known approaches having the capabilities of predicting future events and forecasting right control decisions accordingly. In fact, they have the ability to incorporate optimization mechanisms, which allows integrating system's constraints and disturbances in forecasted control decisions. For instance, the GPC is widely used in advanced control applications, such as in EM and buildings' automation systems [6,[18][19][20]. For example, the work presented in [21] introduced a home EM system for battery storage and PV systems. The proposed planning, for the optimal operation strategy, is expressed as a stochastic mixed-integer nonlinear programming. The power generated by the PV system is considered as an uncertain parameter and modeled by a probability distribution function. The battery storage system is used to store energy during off-peak/low-cost hours and discharge energy during on-peak/high-cost hours. However, the main limitation of this EM strategy is the passive reaction of the system with the cost and the peak demand variability. It is programmed by a fixed time interval, which represents the predefined periods of on-peak and high-cost. In addition, it is not defined by an active function for the interactive variability of the cost and the electricity demand. Moreover, authors in [20] proposed an adaptive and dynamic optimization technique based on the stochastic MPC approach. The proposed EM approach is applied for distributed energy resources scheduling problem for a set of smart homes with different sources of energy. Its aim is to address the uncertainty and variability issues of the PV power generation. This study is designed for large-scale smart houses by taking into consideration their cooperation with their surrounding neighbors. Another interesting work is presented in [22], in which the authors proposed an EM system using the MPC where a simple state-space model is used for the performance modeling of a MG system. This work considered the RESs power production and the consumption as measured disturbances parameters for the EM system. Therefore, the storage systems and the cost are modeled as constraints for the MG system, which are solved by the state-space equations. In addition, other works are presented in literature, which refer to optimal control of RES in MG systems, considering hybrid storage systems, as detailed in [23]. In [24], the authors used the MPC for optimal control of distributed energy resources with a battery storage system. In other works, the MPC is used for EM of MG systems that are connected to the charging station for electrical vehicles [25][26][27]. Generic MPC models are introduced in [28,29] for economic optimization in MG systems. Another interesting work is presented in [30], where authors proposed a MPC methodology to manage the power quality of MG system. The power converters are regulated in order to achieve the requirement by applying the algorithm to a four-wire three-phase voltage source inverter, which works as master of a microgrid with unbalanced and non-linear loads and generators connected.
It is worth noting that the MPC family was proposed for electronic power, and especially for power converter control. The GPC is one of the continuous control set MPC (CCS-MPC) methods that calculate a continuous control command in order to generate the desired output of the power converter. The CCS-MPC models have a lower computational cost than other existing methods, such as the finite control set (FCS-MPC), optimal switching vector (OSV-MPC), and optimal switching sequence (OSS-MPC) [31]. It can be used for a long predictive horizon by calculating the control actions beforehand and then limiting the online computation burden. Mainly, the calculation time is the main factor for the deployment of MPC control families. In past decades, the development of computing units and the integration of ICTs and machine-learning algorithms for power electronic applications encourage the use of predictive control for power converters. For instance, in [32,33], a FCS-MPC is used for current control of three-phase inverter. It is studied in [34] for a multiphase inverter, in [35,36] for a multilevel inverter, and in [37,38] for a matrix converter. For more details, we refer readers to recent interesting reviews, which are related to predictive control applications in power electronics [39][40][41][42]. The work presented in [43] investigated decentralized MPC based hierarchical control scheme with both primary and secondary level for an islanded alternative current (AC) MG system. The aim was to address power quality and unequal power sharing problems. The control scheme consists of an inner control loop, primary and secondary control. The FCS-MPC is incorporated in the inner loop to track the reference voltage and fix the capacitor voltage in each distributed generator unit. Primary control comprises of virtual impedance loop and droop control to manage the power flow and power sharing among distributed generator systems. Moreover, state space predictor based secondary control is proposed for regulating frequency of the MG and node voltage to their nominal values in islanded operation. In [40], authors reviewed the system components, modeling, and control of MG for future smart buildings. An overview of MG control and optimization is given in terms of optimization methods, constraints, and objectives. Mainly, depending on the scale of the controlled system, several works are presented. In fact, for some research works, the control constraints and the objective functions are investigated for large scale MG systems. For example, authors in [44] presented a good control strategy based on an economic MPC approach for community-based MG systems. The control strategy is applied to design the central controller of a large number of MG systems. It mainly showed the capability to efficiently deal with multivariable dynamic constrained systems and to predict properly its actions in order to achieve the optimal performance according to user defined cost functions. Authors realized a comparative analysis of both heuristic and MPC approaches. Reported results showed that the MPC approach has a strong impact on the overall cost of the system. It is able to guarantee a 20-year lifetime of the battery avoiding then its replacement while satisfying the other required criteria.
In this work, a hierarchical approach is proposed to control the energy flow in single MG systems. Unlike the works that investigated the control approaches for multiple MG systems, this work focuses on the EM of a single MG system with the perspective to develop a smart inverter, which can execute predictive control approaches. More precisely, an EM system is deployed based on GPC model in order to manage the operation of such MG and in particular its interaction with the main utility grid. A power converter is then modeled and controlled by a GPC model for ensuring the interaction with the grid. An optimization function with dedicated constraints is modeled for both secondary and tertiary layers. For the second layer, the charge/discharge cycle of the battery and the maximum power extracted from RESs are designed as the main constraint to be optimized by the GPC model, while for the tertiary layer the electricity price is integrated as an input parameter for the controller.

Materials and Methods
The MG system is connected together with the utility grid and storage systems in order to supply the power to the building's load. Furthermore, the MG system could operate in either connected or standalone modes while ensuring frequency and voltage quality. This section provides more details of the MG system modeling for the GPC integration. The GPC model is presented by focusing on its key elements, which we have considered in the present study.

Control Strategy Design and GPC Integration
The GPC is a predictive approach that allows computing and predicting the suitable actions for being performed according to forecasted and contextual information/constraints of MG systems. It can be classified with advanced process control families with less variation in process variables. Its main concept, as depicted in Figure 4a, is described as follows. Based on a predefined model of the MG system, optimal future actions (controls/commands) are computed to reach the desired set point according to the defined constraints and optimization functions. These functions consider future errors, constraints, and control parameters (Figure 4b). An interesting work is presented in [45] about model predictive control for buildings. The work provides a unified framework for model predictive building control technology with a focus on the real-world applications. As described in Figure 4a, the predictor generally calculates, for each instant t, the predictions of the dynamic evolution of the process [y(t + 1), . . . , y(t + N)] T throughout the defined horizon, N − steps ahead. This prediction is based on the dynamic parameters, which are measured at t, as well as the future control system's regulation [u(t), u(t + 1), . . . , u(t + N)] T , along the prediction horizon N. The future control actions are then generated in order to optimize the desired cost function by resolving, at each defined time step, the predefined constraints. The designed cost function keeps the system's output at (t + k) as close as possible to the defined setpoint. This setpoint dictates the output evolution accordingly by considering the evolution of the constraints position ( Figure 4b). As is explained in Figure 4b, the system should be controlled to reach the set point by calculating the minimum trajectory from the actual measurements respecting the cost function to be minimized and avoiding the obstacles (constraints) at the same time. Generally, the cost function takes the form of a quadratic function of the errors between the predicted output and the set point [46].
For GPC integration within the MG system, we focus only on secondary and tertiary control. The former control considers that the EM supervises the MG system by gathering the required data from its entities, mainly RES, batteries, and loads. It mainly manages the energy for both grid-connected and islanded modes with reliable and secure operation. Accordingly, the controllable units of the studied MG system, in both modes, are modeled by a state-space equation, described in Equation (1), where x(t) is the system state, u(t) is the vector of manipulated variables, y(t) is the output vector, and A, B, C are respectively the system matrix, the control matrix, and output matrix.
In the secondary layer, we have incorporated the GPC within the EM in order to generate suitable control actions for efficient power Demand/Response balance. More precisely, the batteries SoC is controlled by the GPC strategy according to the variability of predicted power production, power consumption, and electricity cost. In fact, the power generated by the RESs and the power consumption are considered as disturbances sources for the MG system during its operation. Mainly, the storage system is the main unit used to smooth power fluctuations in MG systems and the main parameter considered for studies in the literature is the SoC variability [47]. For that, the control strategy is designed based on the SoC variability in a MG system, which is used to smooth the power generation on the one hand, and to minimize the electricity price for another hand. Therefore, batteries' SoC could be modeled by a state-space equation while the variability of these controllable parameters is considered because of the disturbances variation, which is described as follows: where P bat is the power generated or extracted from the battery, P RES is the power generated by RES, P load is the load demand, SoC min is the minimum batteries SoC (to avoid a deep discharge), and SoC max is the SoC when the batteries are fully-charged. Generally, the controller cannot manipulate the disturbances of the system. Hence, in our GPC model, the RES power generation and the load consumption are represented as measured system's disturbances. These disturbances can be computed using actual measured power production/consumption, which are in turn affected by external disturbances (e.g., weather conditions, occupant's activities). The deployed IoT/big-data platform, as stated above, could handle this task by forecasting these disturbance parameters (i.e., RES, load power), and consequently, minimizing the GPC prediction errors [4,5]. In fact, if the disturbances can be measured or predicted, their influence on the system's output can be included in the GPC model. This allows anticipating their effect on the control command. Like any predictive control model, the GPC can reject disturbances according to the feedback mechanism. In this way, the GPC can inherently include a feed-forward effect. Therefore, the d(t) disturbances' effect is added to the state-space formulation (Equation (1)) and the equivalent dynamic model is then written in Equation (3), where B d is the matrix, which quantifies the effect of the disturbances on the system states, and d(t) = P RES − P load combines the disturbances into one variable.
As stated above, the main aim of the GPC is to control the battery charging/discharging power. In fact, the GPC regulates the battery state in order to reach the operating goal (i.e., demand/response balance) and to make the right decision: charge, discharge, or battery-at-rest. At a first step, these decisions are made depending on the conditions, which are mentioned in Equation (2). It is worth noting that for modeling the SoC dynamics, the disturbances could be indirectly integrated in the control variables. More precisely, the future values SoC(t + 1) can be calculated by accumulating the actual SoC(t) and the battery charge/discharge current, as described in Equation (4), where I bat = I RES − I load is the batteries' charge/discharge current, I RES and I load are respectively the PV and load current, C is the nominal capacity of the battery, and ∆t is the operating period.
By considering the SoC(t) as the system state, Equation (4) can be rewritten by Equation (5), where x(t) is the system state, A = 1, and the I bat (t) = B is the system input.
By interpolation, Equation (4) to n-step-ahead, the above-mentioned form (Equation (5)) could be rewritten in a matrix form as follows: . . .
Mainly, for the input vectors, we consider the following change: The input vectors u(k) could be similarly rewritten as follows: . . .
It is equivalent to: We can then obtain the following predictive model by replacing Equation (9) in Equation (6): The main constraint, we have considered in the secondary control layer, is related to the batteries' charge/discharge (i.e., the SoC stays at its maximum as much as possible). Therefore, the aim is to minimize the given objective function E N (Equation (12)) within a prediction horizon N. It should be noted that the prediction horizon N has a length strictly superior to the control horizon n. However, for some scenarios, when a machine-learning algorithm is used to generate the control input parameters, the prediction horizon can be minimized and the optimization function can generate its optimal behavior based on the forecasted values [3]. However, in order to get the control sequence ∆U, the criterion that will be optimized is described by Equation (13). It is composed of the quadratic error and the command level.
Alike the secondary control, which manages the energy for both grid-connected and islanded modes with reliable and secure operation, the tertiary control tackles all issues related to the interconnection between the MG system and the utility grid. It mainly adjusts the power set point in order to efficiently manage the power flows by having the possibility to interconnect multiple MG systems. This control layer is mainly considered at the same time as a part of the main grid and the MG system. Under this control, several constraints could be included as a cost function for the efficient management of MG systems. Examples are the electricity price (i.e., the cost for purchasing electricity from the utility grid), the system's profitability (i.e., daily operation costs of the battery storage system and RESs), and the revenue related to the excess energy, which is injected to the utility grid (i.e., selling energy to the neighboring MG systems).
In this work, the electricity price is considered as a fundamental constraint, which is shared between the secondary and the tertiary control layers. In fact, by interpolating this constraint in both layers, the control actions must be generated according to the electricity price variability. The cost function variability used in our work follows the energy price, as presented by the European foundation [48]. In fact, the following control strategy is adopted. When the electricity price is inexpensive, the control strategy could charge the batteries from the main grid for being used during the morning peak consumption, otherwise, the batteries and RESs could be used to supply the power to building's loads while the surplus can be injected into the utility grid. Mainly, when the price is less than a defined threshold value, a simple conditional control strategy could be deployed to balance the power flow by providing the priority to RESs and the utility grid than batteries, otherwise, the batteries and the RESs have the priority to supply the building's loads, as shown in Figure 5. In all cases, the battery can be charged from either RESs or the utility grid according to the daily electricity price variation. In order to include the above-mentioned constraints into the GPC, we use an incremental model by considering ∆u(t) = u(t) − u(t − 1) as the control decision variable, and, therefore, the state-space equation could be represented as in Equation (14), where the new state vector is z(t) = [x(t).u(t − 1)] T and the matrices M, N, and Q are obtained by comparing Equation (3) and Equation (14). It is worth noting that the basic theory of GPC is to compute a sequence of future control actions in order to minimize a multi-stage cost function, which is defined over a prediction horizon. The criterion to be optimized is the expectation of quadratic function that measures the distance between the system's outputs prediction and the reference sequence over a prediction horizon. In the presented state-space equation (Equation (14)), the prediction includes the estimated disturbances (i.e., RESs production, load consumption). The GPC original algorithm is extended to include the cases of measurable disturbances and to change in the predictor. In fact, by considering a system that operates around a practical set point, the single-input single-output of the system plant can be described by Equation (15), after linearization, as follows: This model is known as a CARIMA (controller auto-regressive integrated movingaverage), where ∆ = 1 − z −1 , e(t) is a zero mean white noise, d is the dead time of the system, and the polynomials A, B, and C, in the backward shift operator z −1 , are presented by: The most transfer function model, used by the GPC method, is the commonly used model, called CARIMA model. This form of plant model is formulated in a way that the uncertainty is added into a good representation, so that slow variation of disturbances could have non-zero steady-state. We then synthetize from the CARIMA model a one-step-ahead prediction equation that represents a set of simultaneous prediction equations. The unified GPC algorithm based on CARIMA model can be implemented using model parameters without the need of solving Diophantine equations. The procedure of unified GPC starts by estimating the model parameters and choosing the appropriate values of the maximum and the minimum costing horizon. The model calculates the j-th step response parameter and predicts the plant output assuming future controls equal u(t − 1) [49]. Therefore, the main objective of predictive control is to predict the future control actions u(t), u(t + 1), and u(t + i) in such a way that the future system's output is driven to reach the set point. At the end, the unified GPC calculates the future control increment, extract the first element ∆u(t), and computes the u(t). This step is inspired from the model presented in [49]. Basically, the GPC model consists of applying a sequence of control actions in order to minimize a defined multi-objective cost function. It is worth noting that this vector is generated by a machine-learning algorithm, which is mainly used to forecast the RESs power generation and load consumption [13,50,51]. Consequently, the GPC predictor can reject the effect of these disturbances, along the horizon N, by providing a feed-forward effect. Within this context, the prediction is generated by considering only the cost function, which is modeled by the electricity price as well as the cost associated to the energy mainly used to keep the batteries' SoC at its maximum. Therefore, the constraint defined for the tertiary level control can be written as follows: The first term of Equation (17) represents the cost related to the energy supplied, by RESs and storage devices, to the building's load.ŷ(t) is the reference, w(t) is the plant prediction, Nu is the control horizon, λ(j) is the control weighting, and N 1 is the minimum costing horizon and it is equal to one if the delay is unknown and equal to delay if this last is known, N 2 represents the maximum costing horizon. The matrix Q 1 is generally diagonal and its values depend on the defined priority, which is set-up to control energy sources, as stated above ( Figure 5). The second term is responsible for set point tracking; at each moment the main aim is to regulate the equality I bat = I RES − I load by regulating the battery current while respecting, as much as possible, the constraint described by Equation (12). The third term considers the variability of the electricity price along the prediction horizon N. It mainly represents the cost optimization function for the GPC. However, keeping the SoC at its maximum is highly desirable in order to avoid high cycles of charge/discharge, which could have a direct impact on batteries' state-of-health. At the same time, overcharging of batteries must also be avoided, as is presented in Equation (2), to keep a good state of the health for battery storage. This constraint is, however, not mandatory for the MG system's operations. Therefore, the elements of the matrix R will be smaller than other matrix elements. Accordingly, the optimal solution of Equation (17) could be obtained by solving a quadratic programming problem, as presented in [52]. Moreover, the best prediction ofŷ(t + j) can be expressed by Equation (18) based on the model developed in [52]: where, G j z −1 = E j z −1 B j z −1 , E j and F j are uniquely defined with degrees j − 1 and na respectively. The set of control signals u(t), u(t + 1), . . . , u(t + n), are obtained in order to solve the GPC problem by optimizing the constraint in Equation (17). By considering that the system has a dead time of d sampling period, the output of the system is influenced by the signal output u(t) after sampling period d + 1. The minimum costing horizon, the maximum costing horizon, and the control horizon can be defined respectively by: N 1 = d + 1, N 2 = d + n, and N u = n. However, the GPC law can be calculated using the Diophantine equation. To obtain the control law, it is necessary to know the free response f , which depends on the past and it is calculated recursively by: where A z −1 = ∆A z −1 , f 0 = y(t), and ∆u(t + j) = 0 for j ≥ 0. Equation (17) can be expressed as follow: where the matrix G is composed of the plant step response coefficients, so that the elements of the first column of this matrix are the first n coefficients and the output sequence [ŷ(t + 1),ŷ(t + 2), . . . ,ŷ(t + n)] T is equal to the first column of the matrix G, and w = [w(t + d + 1) w(t + d + 2) . . . w(t + d + n)] T . The minimum of J can be calculated by considering the gradient of J equal to zero and assuming there are no constraints on the control signal, which leads to: The control signal sent to the process is the first element of the vector u expressed by ∆u(t) = K(w − f ), where K represents the first row of the matrix G T G + λI −1 G T .
It is worth noting that the control strategy decisions are generated for a DC MG bus, but the main grid is an AC power system. Thus, a voltage source inverter is required to convert the DC voltage into AC voltage. This will allow generating efficiently the control actions by the above-mentioned GPC model. The next section focuses on the MG synchronization issue by providing a single-phase power converter model.

Single-Phase Modeling for MG Synchronization
The simulated MG system is connected to the utility grid by a bidirectional interface. The aim is to have a complete scenario in order to study the usefulness of the GPCbased control strategy. However, the converter is one of the power electronic devices, which requires time's latency of tens to hundreds of microseconds in order to operate efficiently [53]. This technical constraint could be avoided using the GPC for predictive control. In fact, in order to compute the predictive output parameters (e.g., voltage, current), a state-space equation is required to generate equivalent duty cycle impulse. As depicted in Figure 6, the simulated model is, therefore, represented by a closed-loop configuration of a single-phase MG system. The system is modeled by a DC voltage source and other electronics components, which act as an interface between RESs and the AC utility grid. Usually, an insulated gate bipolar transistor (IGBT) is used as a voltage source inverter due to its fast-switching speed, which is represented by V sw = τ(s)V dc , where V dc meant for the deployed DC voltage sources, and τ(s) is the duty ratio, which is controlled by the GPC model. For the PID testing system, it is used for current regulation of the single-phase systems. In single-phase systems, the common approach is to create a set of imaginary quantities orthogonal to those of the single-phase system so as to obtain DC quantities by means of a stationary-to-rotating frame (αβ to dq) transformation. The orthogonal imaginary-current component is usually obtained by phase shifting the measured real signals by a quarter of the fundamental period. The measured and the shifted current components are then employed in an αβ − dq transformation, and a conventional dq current controller with decoupling strategy is used. The output quantities of the controller are back-transformed to the αβ frame to obtain the AC control signals. Usually, the α component of the control signal is employed and fed into the PWM modulator, while the β component is discarded. This approach is relatively simple and straightforward; however, the introduction of such delay in the system tends to deteriorate the dynamic response, which becomes slower and oscillatory. The main idea is to create an alternative current-regulation in which the β component of the control signal, along with that of the grid voltage, is adopted. The aim is to create the imaginary current orthogonal to the converter current. The main objective of this system's model is to convert the DC power generated by RESs to AC power while controlling the active and reactive power in order to have an equal power of both DC and AC sides. In fact, the voltage through the inductor of the single-phase MG is described by V L = L dI L dt (see Figure 6). By considering V sw as the switching voltage, the equation can be written as follows: where, V g is the voltage through the capacitor, which acts as a MG voltage, and I L is the current across the inductor. By deploying the Laplace Transform, we obtain: Moreover, the grid voltage of the single-phase is written as: C dV g dt = I c , where I c is the current across the capacitor. Therefore, we obtain the following equation: The system state-space equation for a linear time invariant is: From Equation (22) and Equation (24), we obtain respectively the system state matrix, the input variable, and the disturbances matrix: x = I L V g , u = [V sw ], and d = I g . The duplication of this presentation with Equation (25), we obtain Equation (26) as follows, where, y = [V g ] = [01] I L V g represents the output of the system. d dt Generally, the GPC-based controller computes, for each sampling time, a sequence of actions that minimize the defined cost function. Only the first action is applied to the controllable system by solving the open-loop optimal control problem. This process is repeated, at every sampling time horizon, for remaining actions. In our case, the GPC strategy is applied to the current's control of a power converter, as described in the block diagram of Figure 6. For instance, when the predictive time horizon is 1, the optimal control action S(t k ), calculated at t k−1 , is applied to the converter. The measured current i k and voltage V dc re f are used by the reference design model in order to generate the reference current i * k+1 and voltage V * k+1 . The predictive model allows then computing the predicted current i * k+1 and voltage ∼ V * k+1 . Furthermore, the defined references and the predicted current and voltage values are used to improve the cost function, and consequently generating the optimal control action S(t k+1 ) for being applied at t k+1 . However, the main problem, which could face this predictive approach, is its deployment in actual inverters for real-time control. This is due mainly to the considerable processing time delay, which is required to generate predictive values. This delay must be considered in the design of the power controller, and consequently, the delay compensation is a practical method that is used to solve such problem [54]. Within this context, we consider a single-phase system, which is interfaced with the utility grid, as depicted in Figure 6. Therefore, for a voltage-source converter with regulated input currents, the dynamics of the AC-side of the MG system can be represented by Equation (27), where L and R are respectively the inductance and the resistance of the voltage-source converter filter.
The predicted current vector i * k+1 is calculated, during a sampling time T s , by a discretetime model, which is a function of the measured currents i k , the inverter voltage V gk , and the electromotive force ∼ e(k). This current vector is described as follows: According to the model of Equation (28), the cost function for the power converter is defined as the error between the reference and the predicted current values. It is described by Equation (29), where i * α is the real part and i * β is the imaginary part of the reference current vector i * k , and i p α and i p β are respectively the real and imaginary parts of the predicted current vector i * k+1 .
Moreover, as stated in [54,55], the three-phase is presented by seven different voltage vectors. To simplify the presentation, the system is represented by three values of β in order to have only three possible trajectories for i β , in particular for a single-phase system. Figure 7 highlights the problem related to the processing delay, especially for ideal and practical cases. In Figure 7, the red curve represents the predicted current, as mentioned in Equation (28), the green curve is the actual current, which is obtained by minimizing the cost function of Equation (29), and the black line is the considered current reference. Depending on the processing speed and the sampling frequency, the time is significant between the parameters' measurement and the application time (including the time for prediction) of the new control action. For an ideal case, the processing time, spent by the microcontroller, is insignificant and the predictive control model operates as shown in Figure 7a. In fact, at the present time t k , the current is measured and the optimal action is immediately calculated, consequently, the control action, which minimizes the error at the time t k+1 , is generated and applied at time t k . For that, the output reaches the reference current correctly at time t k+1 . Practically, the calculation time is significant compared to a given sampling time of the model. As a result, a delay is created between the measurement time and the application of the predicted control action. Figure 7b shows that during the time T s (between t k and t k+1 ) the previous state continues to control the system, accordingly, the voltage vector, which is selected at time t k , continues to be applied after t k+1 . In this way, the next action is selected considering the measurement in t k+1 and it will be applied near to t k+2 ,. This makes the current oscillate around the reference, which then increases the "current ripple".
As a solution to this problem, the delay compensation method for the predictive control is proposed in order to take into account the calculation time. In fact, the calculated control action, at time t k , is applied at the sampling time t k+2 , as shown in Figure 8. The measured current at t k is used as the starting point for the next switching state and the predicted current for the delay compensation is calculated by Equation (30), where i * k+1 is the previous prediction of the current, and V g(k+1) presents the actuation to be evaluated. Accordingly, the cost function uses the predicted current i * k+2 in order to calculate, at the next sampling time, the switching state.
This single-phase modeling is simulated in order to synchronize the MG system with the electrical grid, while the surplus of RESs power generation is injected through a power converter controlled by the GPC model. The obtained results are reported in the next section.

Results and Performance Evaluation
The MG system is composed of RESs and batteries in order to supply clean energy to the building's load. It is also connected to the utility grid and could operate in either connected or standalone modes. More precisely, two renewable energy sources have been considered, solar and wind. In fact, PV panels and a wind turbine are deployed to generate a maximum power of 1 KW and 1.5 KW respectively. These RESs generators are connected to battery storage system in order to supply the building's load with continuous power. A variable behavior of power demand is used to simulate the load consumption presenting two peak-demand periods. Furthermore, the MG system couples both DC and AC buses. In fact, the power generated from RESs is converted to DC power due to their robustness face to the power quality problems (e.g., reactive power, harmonics). Our proposed EM system is deployed using the GPC model in order to generate control actions accordingly ( Figure 5) while minimizing the predefined cost function. The GPC-based predictive control model is also used to control the power converter in order to ensure the quality of power while converting DC to AC power before being injected into the utility grid. For the performance evaluation of the deployed EM, four main scenarios have been considered by conducting a sensitivity analysis of the GPC-based control strategy according to different situations. MATLAB/SIMULINK (2018.a version with MPC tools) combined with programs are used as a platform for computing and implementing the controllable MG system. The simulations have been performed during a time period for about 24 h using same parameters and conditions. The controllers' parameters are computed taking into consideration the settling time, the predictive horizon, the control horizon, and the rise time, which are chosen by a suitable tuning technique as illustrated in Table 1. Table 1. GPC algorithms' input parameters.

Input Parameters Control Horizon (N u ) Prediction Horizon (N p ) Sampling Time (T s ) Weighting Control (λ)
Value 4 10 10 s 0.6 The first scenario is dedicated to investigating the operational capability of the MG system when coupling different RES and batteries with the developed EM system. In this scenario, we have considered that initially batteries are fully charged, while in the second scenario, batteries are initially discharged and the threshold value of the electricity price is already fixed. The third scenario augments the second scenario by a further constraint regarding the electricity price. In this case, we have used a dynamic threshold value according to the peak-demand periods. The fourth scenario simulates the complete behavior of the MG system and the GPC-based control according to the electricity price by favoring the usage of RESs and storage devices while minimizing the usage of the electrical grid. In addition, batteries could be charged from the electric grid, especially when the electricity price is lower. Table 2 summarizes the characteristics of the MG system's entities and initial conditions. It is worth noting that in all scenarios, the battery discharging (resp. charging), as well as the extracted (resp. injected) power from (resp. to) the utility grid, have positive (resp. negative) sign in all experimental results, presented in the rest of this section.

EM Scenarios Using GPC Control
In the first scenario, a GPC model is integrated to regulate the battery charge/discharge according to the constraints, which are presented by Equation (2) and Equation (13) (i.e., the batteries are initially fully charged). In this scenario, the controller manages the power production/consumption by interacting with the batteries and by performing the actions presented in Figure 5. In this case, batteries are first used to supply the building's load, especially when the RESs could not satisfy the demand.
The operational behavior of the MG system is depicted in Figure 9. As shown, around 07:00 A.M., the PV panels start to generate the power (green curve), which is accumulated with the batteries' power (blue curve) in order to ensure the power to the load. Around 08:30 A.M., the wind turbine starts to generate the power (yellow curve) together with the PV and batteries. At 10:00 A.M., the RESs (i.e., PV and wind turbine) generation is becoming higher than the power demand, and the surplus is used to charge the batteries. It is also shown that the GPC-based model took into consideration the objective function (Equation (12)) by keeping, as much as possible, the batteries SoC at its maximum. From 10:00 A.M. to 05:00 P.M., batteries power is again accumulated with the power generated from RESs in order to supply the building's load, while around 05:00 P.M., the power generated from RESs is almost negligible and, therefore, batteries are the most powerful supplier.
In summary, during this scenario, the MG system is tested in order to show its capability to operate within the variable RESs generation while respecting the abovementioned constraints, which are incorporated within the GPC-base control model. As demonstrated, without considering the electricity price, the MG system is operated in the autonomous mode and the GPC controller managed efficiently the variable production of RESs by interacting with the storage system. In fact, the proposed GPC model could ensure the island mode detection by managing the power dispatching tasks, which are handled by the secondary layer.
As stated above, the second scenario is mainly dedicated to evaluate the MG system's behavior when batteries are initially discharged. Since RESs, generations and load demand are considered as measurable disturbances, and only the electricity price is the uncontrollable parameter, the operational behavior MG needs to be adapted, by the GPC-based control, in order to supply the power to building's load. In this scenario, we consider that the same RESs and loads behaviors are used, but by having the possibility to extract or inject the electricity from or to the utility grid. The GPC controller is designed to manage the switching between batteries and the utility grid without controlling the power, which is generated by RESs. As shown in Figure 10, we consider that RESs are generating the maximum power using the MPPT of the first control layer (green curve for PV generation and yellow curve for wind turbine generation). Under this scenario, the electricity price is taken into account as the main constraint for the tertiary control layer (Equation (17)) for managing the interconnection between the MG system and the utility grid. As defined in Equation (17), the Q 1 matrix elements represent the priority between the RESs, the batteries, and the utility grid for supplying the power to the building's load while minimizing the cost function, which represents the electricity price variability.  As depicted in Figure 10, the consumption (orange curve) is the set point willing to reach by the GPC model. The aim is to accumulate the RESs power generation, batteries, and the utility grid while minimizing the cost function, which is embedded into the GPC-based control.
At the starting time, the batteries are discharged and the RESs generation is null, therefore the controller uses the utility grid for power supply to the building's load. As clearly mentioned in Figure 10, from 06:30 A.M. to 10:00 A.M., the RESs generation (green curve) is less than the power demand, consequently, and according to the control diagram of Figure 5, the power generated by RES is only used to charge the batteries. Therefore, the building's load is completely supplied by the utility grid (black curve). It is worth noting that the operational behavior needs to be avoided in MG systems, as also indicated in Figure 5. More precisely, during this period, the electricity price is higher than the defined threshold value, but the RESs generation is less than the load demand while the batteries are not at the maximum. However, the GPC model could not operate efficiently, since it needs to first satisfy the constraint defined for the secondary control layer while using the RESs power generation in order to charge the batteries, keeping their the SoC at a maximum level.
At 10:00 A.M., the RESs generation is higher than the power demand. In this case, the energy excess is managed according to the electricity price variation. In fact, during the following periods, 10:00 A.M.-11:00 A.M., 02:00 P.M.-03:00 P.M., and 04:00 P.M.-05:00 P.M., the electricity price (pink curve) is higher than the threshold value (red curve). Therefore, the surplus is injected into the utility grid in order to increase the prosumers' profitability by selling the energy at a high price. From 11:00 A.M. to around 01:00 P.M., the electricity price is less than the threshold value; in this case, instead to inject the surplus into the utility grid, it is used to charge the batteries. Therefore, the batteries are charged and could supply the building's load, as shown during the period from 03:00 P.M. to around 04:00 P.M.. They are also used for supplying the load even after 05:00 P.M. despite that their SoC is not at the minimum. To summarize, in this second scenario, a fixed threshold value (red curve in Figure 10) of the electricity price is integrated as a cost function for being minimized by the GPC-based control. In fact, the GPC manages the power between the RESs, the batteries, and the utility grid according to the defined priority as well as the constraints for the secondary and the tertiary layers.
Unlike the second scenario, in the third scenario, a dynamic threshold value is used for the electricity price by considering the peak-demand periods. In fact, the electricity price is an interesting exogenous for both prosumers and the utility grid operators. For instance, it could be used by the grid operators as penalties for the consumers, avoiding then the peak-demand. In fact, the consumers can efficiently manage their consumption by using, for example, programmable machines, which could be controlled by integrating "Internet of things" technologies, or by the deployment of intelligent and predictive control strategies. Moreover, in MG systems, the proposed GPC model can locally manage RESs generation and storage devices. For the studied scenario, the electrical grid is used only during some periods, mainly when the electricity price is inexpensive. The batteries' SoC is kept at its maximum for being used during periods with high electricity price, and consequently, the electricity bill could be minimized. Furthermore, the high electricity demand from the utility grid is minimized avoiding then the generation of peak-demands. As shown in Figure 11, at the starting time, the RESs start charging the batteries and the grid generates the power for supplying the building's load. From 06:00 A.M. to 08:00 A.M., the MG system operates like in the second scenario. However, during the morning peak-demand period (from 08:00 A.M. to 10:00 A.M.), the electricity price (pink curve) increases to reach the maximum, although the batteries start to generate the electricity to the load in order to avoid using the utility grid, having the highest price. During the periods (from 10:00 A.M. to around 02:00 P.M.), which show the lowest electricity price, the RESs (green curve) supply the power to the load while the surplus is managed in a similar manner as the previous scenario. In the afternoon (from 02:00 P.M. to 04:00 P.M.), there is a peak-demand, as shown by the orange curve ( Figure 11). In this period, the surplus generated by RESs is injected into the utility grid while the batteries are used to supply the building's load (especially when RES generation is low), respecting then, the electricity price variation and the battery SoC constraints. In summary, from the results, depicted in Figure 11, the deployed GPC model manages the energy flow according to the defined constraints, which are related to the secondary layer (Equation (13)). Moreover, it efficiently handles the cost function related to the tertiary layer (Equation (17)).
The fourth scenario is mainly included to investigate the MG system behavior taking into consideration all constraints defined in Equation (17). The aim is to maximize supplying the building's load from RESs and batteries, especially when the electricity price is expensive. This priority is selected depending on the elements of the diagonal matrix Q 1 , which are presented in Equation (17). In addition, the action selected by the GPC model, during a given prediction horizon N, considers the variability of electricity price, which is represented by the second term of the Equation (17). Thus, the sources selected to generate the electricity to the loads should be capable to generate the equivalent energy in order to reach the selected set point, presented in the third term of the Equation (17), while the set point is represented by the electricity consumption variability.
In this scenario, the GPC model for EM is deployed during 24 h with the main aim is to show the utility of this model in minimizing the electricity bill. Two cases are considered in order to make a comparative study regarding the electricity cost. For the first case (Case 1), as described in Figure 12a, we have considered a dynamic threshold value for the electricity price, in a similar way as the third scenario. In the second case (Case 2), as depicted in Figure 12b, we consider that the EM system can use the utility grid to charge the batteries, mainly when the electricity price is inexpensive. As already known, batteries are used during the night when the RESs power is unavailable, especially for the PV panels. As shown in Figure 12a, around 05:00 P.M. the RESs generation becomes insignificant (green curve for PV power and yellow curve for the wind power). Consequently, the batteries start generating the power (blue curve) to the loads (orange curve). When the batteries are used, their energy is accumulated with the wind turbine in order to satisfy the requested power. However, at 08:00 P.M., the batteries' SoC reached the minimum threshold value (to avoid a deep-discharging) and the wind turbine cannot satisfy alone the energy demand. In this case, the utility grid is used to supply the electricity to the building's loads, while the power, which is generated by the wind turbine, charges the batteries, from 08:00 P.M. to around 02:00 A.M.. During the rest of the night, the batteries are not fully charged, and, therefore, the load is supplied by the utility grid while the batteries remain at rest. In the morning, starting from 06:00 A.M. to 12:00 A.M., the RESs generation is less than the load's demand. In this period, as shown in Figure 12a, the power generated by the RESs is entirely stored in the batteries, while the building's load is supplied by the utility grid. However, from 12:00 A.M. to 04:00 P.M., the RESs generation is higher than the building's load demand. During this period, and because the electricity price is low, the surplus is then used to charge the batteries. From 04:00 P.M. to 05:00 P.M., the surplus is, however, injected into the utility grid. The aim is to profit from the high electricity price by selling it, and then reducing the electricity bill for consumers. Regarding the second case, as presented in Figure 12b, we consider that the batteries can be charged at night from the utility grid, especially when the electricity price is lower. The system operates like in Case 2. Though, at 02:00 A.M., the utility grid charges the batteries because the electricity price is low and the batteries SoC should be kept at its maximum for being used during the morning in order to avoid the peak-demand. Unlike the first case, the building's load is supplied, during this peak-demand, only by both the batteries and RESs, without using the utility grid. The main control constraints that are considered in this work is the electricity cost and the battery charge/discharge cycle. In fact, in the presented scenarios, the controller considered the electricity price before switching to the batteries. In this way, at some moments the EM should switch to the batteries because the RESs generation cannot satisfy the demand, but by considering the constraint related to the electricity price and battery charge/discharge cycle minimization, the control strategy uses the utility grid to supply the power to the building's loads. This decision keeps the batteries fully charged and profits from the low cost of electricity at those moments. As explained above, batteries, as storage devices, are a solution for energy supply only when the constraint of electricity price is not satisfied. In addition, batteries are kept at rest during the night (Figure 12b) to avoid discharging (demi-cycle is minimized) profiting from the low cost of electricity during this period (from 02:00 A.M. to 06:00 A.M.).
To summarize, the above mentioned scenarios focused on the performance evaluation of the GPC-based control for EM in MG systems. We put more emphasis on the operation behavior of the considered MG system following a cost function and the system's constraints. The next sub-section will focus on the benefit of the GPC-based control on the electricity price.

The Benefit of GPC Model on the Electricity Price
In this section, the profit of electricity price is computed for the fourth scenario and in both cases (1 and 2, Figure 12), since they represent the entire system's operations. In this study, the kilowatt-hour is calculated for the power, which is extracted or injected into the utility grid, as well as the power used to charge or discharge the batteries. It is worth noting that the RESs generate the maximum power at each moment without limiting the power by the LPPT (limited power point tracking) algorithms. In the studied scenarios, the possibility to charge the battery from the utility grid was integrated as an important element in the proposed EM strategy for MG systems. However, a high cycle of the batteries' charge/discharge could play a major role in decreasing the batteries' state-of-health. The GPC-based control manages the power flow in order to keep, as much as possible, the battery SoC at its maximum (Equation (11)). This avoids a high cycle of charge/discharge and a deep-discharge of batteries, which cause the degradation of their state-of-health.
Regarding Case 1, batteries can only be charged from RESs production. They are mainly used to compensate the power generated for supplying the building's load according to the constraints, which are set in the deployed GPC-based model. As presented in Tables 3 and 4, the cost average, the battery power average, and the grid power average are calculated for each hour during the system's operation period. In fact, the negative average power represents the equivalent power, which is used to charge the batteries, while the positive value is the equivalent power, which is generated from the batteries in order to supply the electricity to the building's loads.  By comparing this factor in both cases, the batteries have a total battery power-average equal to "−5.71 KWh" and "−0.0042 KWh" respectively for Cases 1 and 2. For Case 1, this is due to the high usage of the utility grid, and consequently, the batteries receive the maximum power from the RESs without considering the electricity price variation, especially during the day. However, in Case 2, the batteries can be charged from the utility grid, mainly when the electricity price is inexpensive. In fact, the negative average of the power grid represents the equivalent power, which is injected to the grid from RESs, while the positive average is equivalent to the power, which is extracted from the grid in order to satisfy the load demand. As depicted in Table 3, in Case 1, "15.36 KWh" of energy is used from the utility grid, representing an equivalent of "8.97 €" for 24 h, while in Case 2, only "11.42 KWh" of energy is extracted from the grid, which is equivalent to "5.85 €" for the same period.
Therefore, different factors are considered in order to manage the energy flow in the MG system. In order to maximize its profitability, for all studied scenarios, the RESs generate, at each moment, the maximum power. When RESs cannot satisfy the demand, the grid and the batteries' power are efficiently managed in order to avoid the degradation of batteries state-of-health, while minimizing the electricity bill. In summary, the above-mentioned results show the usefulness of the GPC-based control in minimizing the electricity bill by integrating the electricity price as a main important factor for EM in MG systems. However, the power quality as well as the timely decision, which is provided by the GPC-base control, has to be assessed. The next sub-section focuses on evaluating and assessing these two important factors.
For the real deployment and testing of the proposed control strategy, a real platform is ongoing development. The proposed platform uses the new information and communication technologies to improve the performance of the GPC controller. The deployed platform contains RESs and battery storage systems, which are connected together with the TEG in order to supply the electrical energy to the building's loads (e.g., lighting, ventilation) as is mentioned in Figure 13. The IoT/big data platform was developed and deployed in order to allow measuring and forecasting RESs power generation, loads consumption, and batteries SoC. Sensing/actuating components with a control card are installed in order to monitor and manage the whole MG system offering the possibility to test the developed control techniques in the real context. The deployed sensors are used to collect the control input parameters (e.g., power demand, power production, SoC), which is sent by a microcomputer (Raspberry-pi) to a deployed cluster that present a preferment calculation node. Due to the limited calculation performances of the actual inverters, it is planned to propose an IoT architecture that integrate the inverter as a device in the MG system that can communicate with the whole other devices (consumers, producers). The measurements will be sent to a cluster to execute the control algorithm and to calculate the optimal control actions that will be resubmitted to the local inverter for execution. In addition, machine-learning algorithms can be deployed to forecast the control input parameters and the disturbances events that can influence the control decision in the MG. The actual inverters have the possibility to be connected to the internet to store the data, for that the idea is use to use this data to increase the performances of the inverter by integrating more sophisticated control algorithms with variable constraints, cost function, and optimization methods.

State of the Art Synthesis and Our Contribution
Control strategies, generally, use single-objective function procedures (e.g., maximizing the quality of the services). Without considering different operating constraints, these procedures are easier to implement and to deploy in real-sitting scenarios. Moreover, control strategies, which take into consideration only the energy availability within MG components (e.g., energy sources, storage devices, traditional electric grid), could be implemented by simple algorithms. These algorithms implement procedures that switch, at each time, from RES to either storage devices or to the TEG. For instance, actual commercial inverters are able to manage efficiently the interconnection between RESs, energy storage systems, and the utility grid by incorporating a single-objective function. In particular, the MG system's EM takes into consideration only the availability of the electricity for being supplied to buildings loads. The inverter can use once either batteries or the utility grid without taking into account other parameters, such as the actual electricity cost as well as batteries' charge/discharge cycles. However, high batteries' charge/discharge cycles, in a limited time, could decrease their performances, which impact the profitability of the system. In other cases, controllers can interact, in real-time, with energy sources generators (e.g., solar, wind) in order to limit the power generation (limited power point tracking). The aim is to ensure the quality of the electrical services (e.g., frequency, voltage), and consequently minimizing the profitability of the MG system's components. Despite their advantages, they could have, however, negative impacts on the batteries' lifecycle and system's profitability. Therefore, context-awareness principles and predictive analytics could be exploited for developing context-driven control approaches.
This work contribution to the current state of knowledge aims to develop contextdriven control approaches for EM of MG systems in the context of smart buildings. Unlike the control approaches from literature, the proposed strategy considers multiple objectives functions, which take into consideration batteries charge/discharge cycles as well as the electricity price forecasting. The main aim is to ensure, in an optimal way, the continuous electricity supply from different installed sources (e.g., RESs, batteries, TEG) to the building's services. The proposed approach is based on predictive control models, which are able to generate a sequence of future control actions over a prediction horizon based on the MAPCASTE (measure, analyze, plan, forecast, and execute) approach ( Figure 14). The obtained results show the usefulness of the proposed control strategy to minimize the electricity price for the consumer. However, in order to carry out the control approach, several forecasted inputs values are required, mainly the power production/consumption and batteries SoC. This requires an advanced metering infrastructure, which allows measuring and predicting all input values in order to enhance the GPC performances.

GPC Controller for Power Quality Regulation
Computing and data processing, for providing timely decisions and actions, are of most importance, especially in systems requiring real-time predictive control. For instance, as stated above, a delay is created between the measurement time and the application of the predicted control action. In fact, between two moments (t k and t k+1 ), the previous state continues to control the system, and consequently, the voltage vector, selected at time t k , continues to be applied after t k+1 . This makes the power oscillates around the reference, and then the "current ripple" increases. Therefore, by using the GPC controller for the tertiary control layer, the predictor calculates, for each instant t k , the predictions of the dynamic evolution of the process [y(t + 1), . . . , y(t + N)] T , throughout the prediction horizon N. This prediction is based on dynamic parameters, which are measured at this moment, as well as on future control regulations [u(t), u(t + 1), . . . , u(t + N)] T , along the prediction horizon N. As depicted in Figure 15, the orange curve represents the output power, which is generated by the inverter according to the GPC-based control, while the blue curve represents the power, which is generated by the inverter according to a PID (proportional-integral-derivative) controller. As shown in Figure 15, unlike the PID controller, which takes a few moments to reach the set point regulation (1000 W of load consumption), the GPC controller generates the future control actions by keeping the system's output as close as possible to the set point. In fact, the GPC controller shows more system's stability during the switching moments. For the PID, a simple setting is realized with the main focus is the development of a predictive controller, which is based on data prediction and forecast to generate suitable action for EM [3]. In this comparison scenario, the controller is used in a closed-loop unity feedback system. The tracking error e is sent to the PID controller and the generated control signal u(t) from the controller to the inverter is equal to the proportional gain (K p ) times the magnitude of the error plus the integral gain (K i ) times the integral of the error plus the derivative gain (K d ) times the derivative of the error.
Based on the control action (Equation (31)) generated from the controller PID, the K p regulation decreases the rise time, the K i eliminates the steady-state error, and the K d reduces the overshot and settling time. The PID can operate with high performance for real-time data processing using the system "feedback" as the main element for the model stability. However, the predictive control uses the system "feedforward" that can interact with the system's output before the command execution. Unlike the PID, the predictive control/command offers the possibility to integrate multiple objective functions and control constraints. For obtaining accurate values of K p , K i , and K d , the Sisotool in MATLAB/SIMULINK can be used. In this simple study, the PID is tuned for K p = 2.75, K i = 0.984, and K d = 1.73. Since the voltage loop and current loop are decoupled, each PID controller can be designed separately. Therefore, for Figure 15, the presented peak for the PID control, at the switching moments, can be adjusted by regulating the PID coefficients and it is enlarged to show this existing issue with the PID controller compared to the GPC controller. For the PID, the DC link capacitor output voltage presented an overshoot (generating an overshoot of power) and the GPC controller gives less overshoot. It is also observed from the result that the inductor current achieves its steady state value faster with the GPC controller.
Moreover, the control strategy decision by the GPC-based control is mainly generated for the secondary and tertiary control layer. In fact, the GPC manages the system for the secondary control layer by taking the right action on batteries charge/discharge according to the detected mode, autonomous grid-connected. As shown in Figure 16, the PID controller takes more time to converge to the desired references, especially during switching moments. Since the PID is based on a feedback control mechanism (i.e., cannot generate future actions) and the studied constraints cannot be modeled for real-time control, we present only the result when the PID is applied for the grid-connected mode with a static set point. Unlike PID, the GPC controller is based on a feed-forward control mechanism, which allows it to generate future actions according to a predefined cost function and constraints. As depicted in Figure 16a, the regulation of batteries charge/discharge decision is more stable at the switching moments and without a significant "current ripple". Similarly, high switching performance are presented for the interconnection with the electrical grid ( Figure 16b). This is due to the delay compensation method, which is used by the GPCbased control.
Furthermore, the GPC model gives an exact solution to an approximated optimization problem by calculating the voltage reference to the inverter. However, this voltage is generated by a PWM (pulse width modulation) or SVM (space vector modulation) technique. As presented in Figure 6, the power circuit of a grid-connected converter is represented by a smoothing inductor. The main objective of the GPC model is to calculate, for the inverter, the reference of the output voltage for each connected source and load or injection of power to the grid. For the controller, the main variables are the DC voltage/current, the grid voltage/current, and the load voltage/current. The inverter should be able to regulate the output depending on the parameter variation of the DC bus. The output of the system is modeled by Equation (30), in which the output voltage and current are regulated following the references that are generated by the GPC-based control. Figure 17 presents the obtained regulation of voltage and current for the deployed power converter depending on the DC voltage variation. Figure 17a-c show respectively the DC voltage, the DC current, and the current across the LC filter capacitor.  The active power filter consists essentially of a voltage source inverter and a DC bus, which is connected to a capacitor, while the AC bus is connected to the main grid through an LC filter. Mainly, for each load connected to the AC bus, the converter should be capable to generate the suitable current and voltage. For the studied scenarios, the voltage and frequency of the grid are set as 240 V and 50 Hz, respectively. Depending on the deployed loads used for our scenarios, Figure 18a presents the current variation and Figure 18b presents the voltage, which are measured at the output of the inverter. The frequency spectrum is presented for the AC bus voltage and current and for the load voltage as shown in Figure 19. Depending on the Equation (25) dynamics, the voltagesource-inverter output is chosen as the control signal and the final switching sequence is generated through a PWM technique. The performance is analyzed for an RLC load, which is deployed for simulation purposes. Thus, the converter must ensure the stability of the energy injected into the utility grid, according to the rules established by the operators [56].
It is worth noting that, in power electronics, the state feedback regulators do not guarantee a good performance in terms of rapid recovery and low harmonic distortion of the output, especially when the system is affected by disturbances and variations in parameters. However, the use of a feed-forward technique improves the transient response and minimizes, even remove harmonic disturbances. Better performance of this type of controllers is achieved, as shown in Figure 19. The output tracks the reference voltage and current with good behavior by ensuring the stability of the system's frequency at 50 Hz for harmonic loads. Furthermore, the GPC provides an explicit solution for unconstrained predictive control. It is also able to handle the problem of mismatch between the model and the deployed load.

Conclusions and Perspectives
In this paper, an energy management system, based on a generalized predictive control approach, was introduced for being deployed in the secondary and the tertiary control layers. In fact, the secondary layer focused on power regulation and energy demand/response balance. An optimization function was defined, for this level, by considering a GPC strategy. State-space equations are presented for the controllable micro-grid system's entities depending on the constraint, which is defined in the tertiary control layer. Therefore, the tertiary control focused only on power dispatch and economic aspects. Within this context, the electricity cost is used as a constraint to control the batteries charge/discharge. Indeed, the electricity price is integrated as a cost function to be minimized while respecting the constraint defined by the GPC model. The controller manages the power between the RESs, the batteries, and the utility grid depending on the operational constraints of the EM strategy deployed using the GPC model. The powerful of the GPC model for the EM system was shown by minimizing the electricity bill. For a given scenario, the deployed control strategy manages the energy flow in the deployed MG system depending on the electricity price variability during the day. The main objective is to ensure the power to the consumer with a minimum price by integrating predictive control methods that considers multiple objective function and constraint. While the battery charge/discharge current is controlled depending on the defined constraint with the possibility to charge the battery storage system from the utility grid when the electricity price is minimal. It is worth noting that actual controllers of the power converter manage the energy flow based on real-time measurement (e.g., current, voltage, power), however, it is possible to control the power exchange using predictive control offering the possibility to integrate multi-objective functions and constraints. Today, it is possible to connect actual inverters with the Internet in order to store, process, and analyze measured data. These latter could be used to train machine learning algorithms and to generate the control input parameters offering more accuracy for the predictive control. In future works, a power converter will be deployed based on the GPC controller for energy management in our actual MG system.