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

Abdellatif Elmouatamid, Radouane Ouladsine, Mohamed Bakhouya, Najib El Kamoun, Khalid Zine-Dine

► To cite this version:

Abdellatif Elmouatamid, Radouane Ouladsine, Mohamed Bakhouya, Najib El Kamoun, Khalid Zine-Dine. A Predictive Control Strategy for Energy Management in Micro-Grid Systems. Electronics, 2021, 10 (14), pp.1666. 10.3390/electronics10141666. hal-04607722

HAL Id: hal-04607722

https://hal.science/hal-04607722

Submitted on 11 Jun 2024

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_1.png" /></figure>
Article

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

Abdellatif Elmouatamid<sup>1,2,*</sup>, Radouane Ouladsine<sup>1</sup>, Mohamed Bakhouya<sup>1</sup>, Najib El kamoun<sup>2</sup> and Khalid Zine-Dine<sup>3</sup>

<figure><img src="image_1.png" /></figure>

check for
updates

**Citation:** Elmouatamid, A.; Ouladsine, R.; Bakhouya, M.; El kamoun, N.; Zine-Dine, K. A Predictive Control Strategy for Energy Management in Micro-Grid Systems. *Electronics* **2021**, *10*, 1666. https://doi.org/10.3390/electronics10141666

Academic Editor: Carlos E. Ugalde-Loo

Received: 20 April 2021
Accepted: 20 May 2021
Published: 13 July 2021

**Publisher's Note:** MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations.

<figure><img src="image_2.png" /></figure>

**Copyright:** © 2021 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).

**Abstract:** The integration of renewable energy sources (RES) was amplified, during the past decades, in order to tackle the challenges related to energy demands and CO₂ 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 efficient 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 efficiently connect the electricity generators and consumers in order to predict the most suitable actions for energy flow management. In fact, based on energy production and consumption profiles 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 efficiently 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.

**Keywords:** control strategies; cost function; energy management; micro-grid systems; predictive control; operation constraints; renewable energy sources integration; simulation

## 1. 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

<footnote n="1"><sup>1</sup> LERMA Lab, College of Engineering and Architecture, International University of Rabat, El Jadida 11100, Morocco; radouane.ouladsine@uir.ac.ma (R.O.); Mohamed.bakhouya@uir.ac.ma (M.B.)</footnote>

<footnote n="2"><sup>2</sup> STIC Laboratory, Faculty of Sciences, Chouaïb Doukkali University, El Jadida 24000, Morocco; elkamoun.n@ucd.ac.ma</footnote>

<footnote n="3"><sup>3</sup> Faculty of Science, Mohammed V University, Rabat 10000, Morocco; khalid.zinedine@um5.ac.ma</footnote>

<footnote>* Correspondence: abdellatif.elmouatamid@uir.ac.ma; Tel.: +212-649-966-652</footnote>
Article

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

Abdellatif Elmouatamid<sup>1,2,*</sup>, Radouane Ouladsine<sup>1</sup>, Mohamed Bakhouya<sup>1</sup>, Najib El kamoun<sup>2</sup> and Khalid Zine-Dine<sup>3 ID</sup>

<figure><img src="image_2.png" /></figure>

check for
updates

**Citation:** Elmouatamid, A.; Ouladsine, R.; Bakhouya, M.; El kamoun, N.; Zine-Dine, K. A Predictive Control Strategy for Energy Management in Micro-Grid Systems. *Electronics* **2021**, *10*, 1666. https://doi.org/10.3390/electronics10141666

Academic Editor: Carlos E. Ugalde-Loo

Received: 20 April 2021
Accepted: 20 May 2021
Published: 13 July 2021

**Publisher's Note:** MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations.

<figure><img src="image_3.png" /></figure>

**Copyright:** © 2021 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).

**Abstract:** The integration of renewable energy sources (RES) was amplified, during the past decades, in order to tackle the challenges related to energy demands and CO₂ 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 efficient 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 efficiently connect the electricity generators and consumers in order to predict the most suitable actions for energy flow management. In fact, based on energy production and consumption profiles 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 efficiently 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.

**Keywords:** control strategies; cost function; energy management; micro-grid systems; predictive control; operation constraints; renewable energy sources integration; simulation

## 1. 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

<footnote n="1">1 LERMA Lab, College of Engineering and Architecture, International University of Rabat, El Jadida 11100, Morocco; radouane.ouladsine@uir.ac.ma (R.O.); Mohamed.bakhouya@uir.ac.ma (M.B.)</footnote>

<footnote n="2">2 STIC Laboratory, Faculty of Sciences, Chouaïb Doukkali University, El Jadida 24000, Morocco; elkamoun.n@ucd.ac.ma</footnote>

<footnote n="3">3 Faculty of Science, Mohammed V University, Rabat 10000, Morocco; khalid.zinedine@um5.ac.ma</footnote>

<footnote>* Correspondence: abdellatif.elmouatamid@uir.ac.ma; Tel.: +212-649-966-652</footnote>
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–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].
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–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].
<figure><img src="image_3.png" /><figcaption>**Figure 1.** Energy management schemes with GPC operation processes (Reprinted from ref. [3]).</figcaption></figure>

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.

## 2. 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
<figure><img src="image_4.png" /><figcaption>**Figure 1.** Energy management schemes with GPC operation processes (Reprinted from ref. [3]).</figcaption></figure>

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.

## 2. 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).

<figure><img src="image_4.png" /><figcaption>**Figure 2.** Micro-grid energy management levels.</figcaption></figure>

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–17].
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).

<figure><img src="image_5.png" /><figcaption>**Figure 2.** Micro-grid energy management levels.</figcaption></figure>

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–17].
<figure><img src="image_5.png" /><figcaption>**Figure 3.** Hierarchical control levels.</figcaption></figure>

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–20]. For example, the work presented in [21] introduced a home EM system for battery storage
<figure><img src="image_6.png" /><figcaption>Figure 3. Hierarchical control levels.</figcaption></figure>

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–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–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–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
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–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–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.

### 3. 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.

#### 3.1. *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.
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.

### 3. 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.

#### 3.1. *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.
<figure><img src="image_6.png" /><figcaption>Figure 4. A schematic view of GPC concept: (a) control actions on the horizon N, (b) predictive control mechanism.</figcaption></figure>

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.

$$ \begin{cases} x(t+1) = Ax(t) + Bu(t) \\ y(t) = Cx(t) \end{cases} \qquad (1) $$
<figure><img src="image_7.png" /><figcaption>Figure 4. A schematic view of GPC concept: (a) control actions on the horizon N, (b) predictive control mechanism.</figcaption></figure>

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.

$$ \left\{ \begin{array}{l} x(t+1) = Ax(t) + Bu(t) \\ y(t) = Cx(t) \end{array} \right. \qquad (1) $$
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:

$$P_{bat} = \begin{cases} P_{RES} - P_{load}; & \text{if } 0 \le P_{RES} \text{ and } SoC_{min} < SoC \le SoC_{max} \\ P_{load}; & \text{if } P_{RES} = 0 \text{ and } SoC_{min} < SoC \end{cases} \quad (2)$$

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.

$$\begin{cases} x(t+1) = Ax(t) + Bu(t) + B_d d(t) \\ y(t) = Cx(t) \end{cases} \quad (3)$$

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 $\Delta t$ is the operating period.

$$SoC(t+1) = SoC(t) + I_{bat}(t) \cdot \Delta t / C \quad (4)$$

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.

$$x(k+1) = Ax(k) + BU(k) \quad (5)$$
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:

$$P_{bat} = \begin{cases} P_{RES} - P_{load}; & \text{if } 0 \le P_{RES} \text{ and } SoC_{min} < SoC \le SoC_{max} \\ P_{load}; & \text{if } P_{RES} = 0 \text{ and } SoC_{min} < SoC \end{cases} \quad (2)$$

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.

$$\begin{cases} x(t + 1) = Ax(t) + Bu(t) + B_d d(t) \\ y(t) = Cx(t) \end{cases} \quad (3)$$

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 $\Delta t$ is the operating period.

$$SoC(t + 1) = SoC(t) + I_{bat}(t) \cdot \Delta t / C \quad (4)$$

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.

$$x(k + 1) = Ax(k) + BU(k) \quad (5)$$
By interpolation, Equation (4) to n-step-ahead, the above-mentioned form (Equation (5)) could be rewritten in a matrix form as follows:

$$ \begin{pmatrix} x(k+1) \\ \vdots \\ x(k+n) \end{pmatrix} = \begin{pmatrix} A \\ \vdots \\ A^n \end{pmatrix} x(k) + \begin{pmatrix} B & 0 & \cdots & 0 \\ AB & \ddots & \ddots & \vdots \\ \vdots & \ddots & B & 0 \\ A^{n-1}B & \cdots & AB & B \end{pmatrix} \begin{pmatrix} U(k) \\ \vdots \\ U(k+n) \end{pmatrix} \quad (6) $$

Mainly, for the input vectors, we consider the following change:

$$ \left\{ \begin{aligned} U(k) &= U(k-1) + \Delta U(k) \\ U(k+1) &= U(k) + \Delta U(k+1) = U(k-1) + \Delta U(k) + \Delta U(k+1) \\ \vdots & \\ U(k+n-1) &= U(k-1) + \Delta U(k) + \Delta U(k-1) + \dots + \Delta U(k+n-1) \end{aligned} \right. \quad (7) $$

The input vectors $u(k)$ could be similarly rewritten as follows:

$$ \begin{pmatrix} U(k) \\ U(k+1) \\ \vdots \\ U(k+n) \end{pmatrix} = \begin{pmatrix} 1 \\ \vdots \\ 1^n \end{pmatrix} U(k-1) + \begin{pmatrix} 1 & 0 & \cdots & 0 \\ 1 & \ddots & \ddots & \vdots \\ \vdots & \ddots & \ddots & 0 \\ 1 & \cdots & 1 & 1 \end{pmatrix} \begin{pmatrix} \Delta U(k) \\ \Delta U(k+1) \\ \vdots \\ \Delta U(k+n+1) \end{pmatrix} \quad (8) $$

It is equivalent to:

$$ \bar{U} = I_1 U(k-1) + I_2 \Delta \bar{U}(k) \quad (9) $$

We can then obtain the following predictive model by replacing Equation (9) in Equation (6):

$$ \left\{ \begin{aligned} \bar{X} &= \bar{A}x(k) + \bar{B}I_1U(k-1) + \bar{B}I_2\Delta\bar{U}(k) \\ \bar{Y} &= \bar{C}x(k) + \bar{D}I_1U(k-1) + \bar{D}I_2\Delta\bar{U}(k) \end{aligned} \right. \quad (10) $$

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 $\Delta U$, the criterion that will be optimized is described by Equation (13). It is composed of the quadratic error and the command level.

$$ Y_{ref} = [SoC_{max}(k+1), SoC_{max}(k+2), \dots, SoC_{max}(k+N)] \quad (11) $$

$$ E_N = SoC_{max} \begin{pmatrix} 1 \\ \vdots \\ 1^N \end{pmatrix} - SoC(t) \begin{pmatrix} SoC(t) \\ \vdots \\ SoC(t+N) \end{pmatrix} \quad (12) $$

$$ J = \frac{1}{2} (EQE^T + \Delta \bar{U} R \Delta \bar{U}^T) \quad (13) $$

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
By interpolation, Equation (4) to n-step-ahead, the above-mentioned form (Equation (5)) could be rewritten in a matrix form as follows:

$$ \begin{pmatrix} x(k+1) \\ \vdots \\ x(k+n) \end{pmatrix} = \begin{pmatrix} A \\ \vdots \\ A^n \end{pmatrix} x(k) + \begin{pmatrix} B & 0 & \cdots & 0 \\ AB & \ddots & \ddots & \vdots \\ \vdots & \ddots & B & 0 \\ A^{n-1}B & \cdots & AB & B \end{pmatrix} \begin{pmatrix} U(k) \\ \vdots \\ U(k+n) \end{pmatrix} \quad (6) $$

Mainly, for the input vectors, we consider the following change:

$$ \left\{ \begin{array}{l} U(k) = U(k-1) + \Delta U(k) \\ U(k+1) = U(k) + \Delta U(k+1) = U(k-1) + \Delta U(k) + \Delta U(k+1) \\ \vdots \\ U(k+n-1) = U(k-1) + \Delta U(k) + \Delta U(k-1) + \dots + \Delta U(k+n-1) \end{array} \right. \quad (7) $$

The input vectors $u(k)$ could be similarly rewritten as follows:

$$ \begin{pmatrix} U(k) \\ U(k+1) \\ \vdots \\ U(k+n) \end{pmatrix} = \begin{pmatrix} 1 \\ \vdots \\ 1^n \end{pmatrix} U(k-1) + \begin{pmatrix} 1 & 0 & \cdots & 0 \\ 1 & \ddots & \ddots & \vdots \\ \vdots & \ddots & \ddots & 0 \\ 1 & \cdots & 1 & 1 \end{pmatrix} \begin{pmatrix} \Delta U(k) \\ \Delta U(k+1) \\ \vdots \\ \Delta U(k+n+1) \end{pmatrix} \quad (8) $$

It is equivalent to:

$$ \bar{U} = I_1 U(k-1) + I_2 \Delta \bar{U}(k) \quad (9) $$

We can then obtain the following predictive model by replacing Equation (9) in Equation (6):

$$ \left\{ \begin{array}{l} \bar{X} = \bar{A}x(k) + \bar{B}I_1U(k-1) + \bar{B}I_2\Delta\bar{U}(k) \\ \bar{Y} = \bar{C}x(k) + \bar{D}I_1U(k-1) + \bar{D}I_2\Delta\bar{U}(k) \end{array} \right. \quad (10) $$

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 $\Delta U$, the criterion that will be optimized is described by Equation (13). It is composed of the quadratic error and the command level.

$$ Y_{ref} = [SoC_{max}(k+1), SoC_{max}(k+2), \dots, SoC_{max}(k+N)] \quad (11) $$

$$ E_N = SoC_{max} \begin{pmatrix} 1 \\ \vdots \\ 1^N \end{pmatrix} - SoC(t) \begin{pmatrix} SoC(t) \\ \vdots \\ SoC(t+N) \end{pmatrix} \quad (12) $$

$$ J = \frac{1}{2} (EQE^T + \Delta \bar{U} R \Delta \bar{U}^T) \quad (13) $$

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 $\Delta 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).

$$ \left\{ \begin{array}{l} z(t+1) = Mz(t) + N \Delta u(t) + N_d d(t) \\ y(t) = Qz(t) \end{array} \right. \qquad (14) $$

<figure><img src="image_7.png" /><figcaption>Figure 5. Energy management and control strategy.</figcaption></figure>
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 $\Delta 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).

$$ \left\{ \begin{aligned} z(t+1) &= Mz(t) + N \Delta u(t) + N_d d(t) \\ y(t) &= Qz(t) \end{aligned} \right. \qquad (14) $$

<figure><img src="image_8.png" /><figcaption>Figure 5. Energy management and control strategy.</figcaption></figure>
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:

$$A(z^{-1})y(t) = z^{-d}B(z^{-1})u(t-1) + C(z^{-1})\frac{e(t)}{\Delta} \quad (15)$$

This model is known as a CARIMA (controller auto-regressive integrated moving-average), where $\Delta = 1 - z^{-1}$, $e(t)$ is a zero mean white noise, $d$ is the dead time of the system, and the polynomials $A, B, \text{ and } C$, in the backward shift operator $z^{-1}$, are presented by:

$$ 
\begin{aligned}
A(z^{-1}) &= 1 + a_1z^{-1} + a_2z^{-2} + \dots + a_{na}z^{-na} \\
B(z^{-1}) &= b_0 + b_1z^{-1} + b_2z^{-2} + \dots + b_{nb}z^{-nb} \\
C(z^{-1}) &= 1 + c_1z^{-1} + c_2z^{-2} + \dots + c_{nc}z^{-nc}
\end{aligned}
\quad (16) $$

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 $\Delta 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:

$$J(N_1, N_2, N_u) = \sum_{j=N1}^{N2} |u(t+j-1)|_{Q_1}^2 + \sum_{j=N1}^{N2} |\hat{y}(t+j)|_R^2 + \sum_{j=1}^{Nu} \lambda(j) |\Delta u(t+j-1)|_{Q_2}^2 \quad (17)$$

The first term of Equation (17) represents the cost related to the energy supplied, by RESs and storage devices, to the building's load. $\hat{y}(t)$ is the reference, $w(t)$ is the plant prediction, $Nu$ is the control horizon, $\lambda(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
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:

$$A(z^{-1})y(t) = z^{-d}B(z^{-1})u(t-1) + C(z^{-1}) \cdot \frac{e(t)}{\Delta} \quad (15)$$

This model is known as a CARIMA (controller auto-regressive integrated moving-average), where $\Delta = 1 - z^{-1}$, $e(t)$ is a zero mean white noise, $d$ is the dead time of the system, and the polynomials $A, B, \text{ and } C$, in the backward shift operator $z^{-1}$, are presented by:

$$ \begin{aligned} A(z^{-1}) &= 1 + a_1z^{-1} + a_2z^{-2} + \dots + a_{na}z^{-na} \\ B(z^{-1}) &= b_0 + b_1z^{-1} + b_2z^{-2} + \dots + b_{nb}z^{-nb} \\ C(z^{-1}) &= 1 + c_1z^{-1} + c_2z^{-2} + \dots + c_{nc}z^{-nc} \end{aligned} \quad (16) $$

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 $\Delta 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:

$$J(N_1, N_2, N_u) = \sum_{j=N1}^{N2} |u(t+j-1)|_{Q_1}^2 + \sum_{j=N1}^{N2} |\hat{y}(t+j)|_R^2 + \sum_{j=1}^{Nu} \lambda(j) |\Delta u(t+j-1)|_{Q_2}^2 \quad (17)$$

The first term of Equation (17) represents the cost related to the energy supplied, by RESs and storage devices, to the building's load. $\hat{y}(t)$ is the reference, $w(t)$ is the plant prediction, $Nu$ is the control horizon, $\lambda(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]:

$$ ŷ(t + j)|t) = G_j(z^{-1})\Delta u(t + j - d - 1) + F_j(z^{-1})y(t) \quad (18) $$

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), \dots, 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:

$$ f_{j+1} = ŷ(1 - \tilde{A}(z^{-1}))f_j + B(z^{-1})\Delta u(t - d + j) \quad (19) $$

where $A(z^{-1}) = \Delta A(z^{-1})$, $f_0 = y(t)$, and $\Delta u(t + j) = 0$ for $j \ge 0$.

Equation (17) can be expressed as follows:

$$ J = (Gu + f - w)^T(Gu + f - w) + \lambda u^T u \quad (20) $$

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), \dots, ŷ(t+n)]^T$ is equal to the first column of the matrix G, and $w = [w(t+d+1) w(t+d+2) \dots 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:

$$ u = (G^T G + \lambda I)^{-1} G^T (w - f) \quad (21) $$

The control signal sent to the process is the first element of the vector u expressed by $\Delta u(t) = K(w - f)$, where K represents the first row of the matrix $(G^T G + \lambda 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.

### 3.2. 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 GPC-based control strategy. However, the converter is one of the power electronic devices,
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]:

$$ \hat{y}(t+j)|t) = G_j(z^{-1})\Delta u(t+j-d-1) + F_j(z^{-1})y(t) \quad (18) $$

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), \dots, 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:

$$ f_{j+1} = \hat{y}(1 - \tilde{A}(z^{-1}))f_j + B(z^{-1})\Delta u(t-d+j) \quad (19) $$

where $A(z^{-1}) = \Delta A(z^{-1})$, $f_0 = y(t)$, and $\Delta u(t+j) = 0$ for $j \ge 0$.

Equation (17) can be expressed as follows:

$$ J = (Gu + f - w)^T(Gu + f - w) + \lambda u^T u \quad (20) $$

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 $[\hat{y}(t+1), \hat{y}(t+2), \dots, \hat{y}(t+n)]^T$ is equal to the first column of the matrix G, and $w = [w(t+d+1) w(t+d+2) \dots 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:

$$ u = (G^T G + \lambda I)^{-1} G^T (w - f) \quad (21) $$

The control signal sent to the process is the first element of the vector u expressed by $\Delta u(t) = K(w - f)$, where K represents the first row of the matrix $(G^T G + \lambda 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.

## 3.2. 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 GPC-based 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} = \tau(s)V_{dc}$, where $V_{dc}$ means for the deployed DC voltage sources, and $\tau(s)$ is the duty ratio, which is controlled by the GPC model.

<figure><img src="image_8.png" /><figcaption>Figure 6. (a) Single-phase MG system, (b) the test system with one-line diagram.</figcaption></figure>

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 ($\alpha\beta$ to $dq$) transformation. The orthogonal imaginary-current component is usually obtained by phase shifting the measured real signals by a quarter
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} = \tau(s)V_{dc}$, where $V_{dc}$ means for the deployed DC voltage sources, and $\tau(s)$ is the duty ratio, which is controlled by the GPC model.

<figure><img src="image_9.png" /><figcaption>Figure 6. (a) Single-phase MG system, (b) the test system with one-line diagram.</figcaption></figure>

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 ($\alpha\beta$ 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 $\alpha\beta - dq$ transformation, and a conventional $dq$ current controller with decoupling strategy is used. The output quantities of the controller are back-transformed to the $\alpha\beta$ frame to obtain the AC control signals. Usually, the $\alpha$ component of the control signal is employed and fed into the PWM modulator, while the $\beta$ 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 $\beta$ 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 \frac{dI_L}{dt}$ (see Figure 6). By considering $V_{sw}$ as the switching voltage, the equation can be written as follows:

$$ \frac{dI_L}{dt} = \frac{V_L}{L} = \frac{V_{sw} - V_g}{L} \qquad (22) $$

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:

$$ I_L(s) = \frac{V_L(s)}{sL} = \frac{V_{sw}(s) - V_g(s)}{sL} \qquad (23) $$

Moreover, the grid voltage of the single-phase is written as: $C \frac{dV_g}{dt} = I_c$, where $I_c$ is the current across the capacitor. Therefore, we obtain the following equation:

$$ \frac{dV_g}{dt} = \frac{1}{C} I_c \qquad (24) $$

The system state-space equation for a linear time invariant is:

$$ \left\{ \begin{array}{l} \frac{dx(t)}{dt} = Ax(t) + Bu(t) \\ y(t) = Cx(t) + Du(t) \end{array} \right. \qquad (25) $$

From Equation (22) and Equation (24), we obtain respectively the system state matrix, the input variable, and the disturbances matrix: $x = \begin{bmatrix} I_L \\ V_g \end{bmatrix}$, $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] \begin{bmatrix} I_L \\ V_g \end{bmatrix}$ represents the output of the system.

$$ \frac{d}{dt} \begin{bmatrix} I_L \\ V_g \end{bmatrix} = \begin{bmatrix} 0 & -\frac{1}{L} \\ \frac{1}{C} & 0 \end{bmatrix} \begin{bmatrix} I_L \\ V_g \end{bmatrix} + \begin{bmatrix} I_L \\ 0 \end{bmatrix} [V_{sw}] + \begin{bmatrix} 0 \\ -\frac{1}{C} \end{bmatrix} [I_g] \qquad (26) $$

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 ref}$ 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
of the fundamental period. The measured and the shifted current components are then employed in an $\alpha\beta - dq$ transformation, and a conventional $dq$ current controller with decoupling strategy is used. The output quantities of the controller are back-transformed to the $\alpha\beta$ frame to obtain the AC control signals. Usually, the $\alpha$ component of the control signal is employed and fed into the PWM modulator, while the $\beta$ 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 $\beta$ 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 \frac{dI_L}{dt}$ (see Figure 6). By considering $V_{sw}$ as the switching voltage, the equation can be written as follows:

$$ \frac{dI_L}{dt} = \frac{V_L}{L} = \frac{V_{sw} - V_g}{L} \qquad (22) $$

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:

$$ I_L(s) = \frac{V_L(s)}{sL} = \frac{V_{sw}(s) - V_g(s)}{sL} \qquad (23) $$

Moreover, the grid voltage of the single-phase is written as: $C \frac{dV_g}{dt} = I_c$, where $I_c$ is the current across the capacitor. Therefore, we obtain the following equation:

$$ \frac{dV_g}{dt} = \frac{1}{C} I_c \qquad (24) $$

The system state-space equation for a linear time invariant is:

$$ \left\{ \begin{array}{l} \frac{dx(t)}{dt} = Ax(t) + Bu(t) \\ y(t) = Cx(t) + Du(t) \end{array} \right. \qquad (25) $$

From Equation (22) and Equation (24), we obtain respectively the system state matrix, the input variable, and the disturbances matrix: $x = \begin{bmatrix} I_L \\ V_g \end{bmatrix}$, $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] \begin{bmatrix} I_L \\ V_g \end{bmatrix}$ represents the output of the system.

$$ \frac{d}{dt} \begin{bmatrix} I_L \\ V_g \end{bmatrix} = \begin{bmatrix} 0 & -\frac{1}{L} \\ \frac{1}{C} & 0 \end{bmatrix} \begin{bmatrix} I_L \\ V_g \end{bmatrix} + \begin{bmatrix} I_L \\ 0 \end{bmatrix} [V_{sw}] + \begin{bmatrix} 0 \\ -\frac{1}{C} \end{bmatrix} [I_g] \qquad (26) $$

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 ref}$ 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.

$$V_{a,abc} = R i_{abc} + L \frac{di_{abc}}{dt} + V_{i, abc} \qquad (27)$$

The predicted current vector $i_{k+1}^*$ is calculated, during a sampling time $T_s$, by a discrete-time model, which is a function of the measured currents $i_k$, the inverter voltage $V_{gk}$, and the electromotive force $\tilde{e}(k)$. This current vector is described as follows:

$$i_{k+1}^* = \left(1 - \frac{RT_s}{L}\right) i_k + \frac{T_s}{L} \left(V_{gk} - \tilde{e}(k)\right) \qquad (28)$$

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_{\alpha}^*$ is the real part and $i_{\beta}^*$ is the imaginary part of the reference current vector $i_k^*$, and $i_{\alpha}^p$ and $i_{\beta}^p$ are respectively the real and imaginary parts of the predicted current vector $i_{k+1}^*$.

$$J = |i_{\alpha}^* - i_{\alpha}^p| + |i_{\beta}^* - i_{\beta}^p| \qquad (29)$$

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 $\beta$ in order to have only three possible trajectories for $i_{\beta}$, in particular for a single-phase system. Figure 7 highlights the problem related to the processing delay, especially for ideal and practical cases.

<figure><img src="image_9.png" /><figcaption>Figure 7. Predictive control operation, (a) ideal case: calculation time is negligible, (b) practical case: calculation time is significant.</figcaption></figure>
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.

$$V_{a,abc} = R i_{abc} + L \frac{di_{abc}}{dt} + V_{i, abc} \quad (27)$$

The predicted current vector $i_{k+1}^*$ is calculated, during a sampling time $T_s$, by a discrete-time model, which is a function of the measured currents $i_k$, the inverter voltage $V_{gk}$, and the electromotive force $\tilde{e}(k)$. This current vector is described as follows:

$$i_{k+1}^* = \left(1 - \frac{RT_s}{L}\right) i_k + \frac{T_s}{L} \left(V_{gk} - \tilde{e}(k)\right) \quad (28)$$

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_{\alpha}^*$ is the real part and $i_{\beta}^*$ is the imaginary part of the reference current vector $i_k^*$, and $i_{\alpha}^p$ and $i_{\beta}^p$ are respectively the real and imaginary parts of the predicted current vector $i_{k+1}^*$.

$$J = |i_{\alpha}^* - i_{\alpha}^p| + |i_{\beta}^* - i_{\beta}^p| \quad (29)$$

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 $\beta$ in order to have only three possible trajectories for $i_{\beta}$, in particular for a single-phase system. Figure 7 highlights the problem related to the processing delay, especially for ideal and practical cases.

<figure><img src="image_10.png" /><figcaption>Figure 7. Predictive control operation, (a) ideal case: calculation time is negligible, (b) practical case: calculation time is significant.</figcaption></figure>
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.

$$i_{k+2}^* = \left(1 - \frac{RT_s}{L}\right) i_{k+1}^* + \frac{T_s}{L} \left(V_{g(k+1)} - \tilde{e}(k+1)\right) \quad (30)$$

<figure><img src="image_10.png" /><figcaption>Figure 8. Predictive control with significant calculation time: operation of delay compensation method.</figcaption></figure>

Accordingly, the cost function uses the predicted current $i_{k+2}^*$ in order to calculate, at the next sampling time, the switching state.
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.

$$i_{k+2}^* = \left(1 - \frac{RT_s}{L}\right) i_{k+1}^* + \frac{T_s}{L} \left(V_{g(k+1)} - \tilde{e}(k+1)\right) \quad (30)$$

<figure><img src="image_11.png" /><figcaption>Figure 8. Predictive control with significant calculation time: operation of delay compensation method.</figcaption></figure>

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.

## 4. 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><caption>Table 1. GPC algorithms' input parameters.</caption><thead><tr><td>Input Parameters</td><td>Control Horizon (N<sub>u</sub>)</td><td>Prediction Horizon (N<sub>p</sub>)</td><td>Sampling Time (T<sub>s</sub>)</td><td>Weighting Control (λ)</td></tr></thead><tbody><tr><td>Value</td><td>4</td><td>10</td><td>10 s</td><td>0.6</td></tr></tbody></table>

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.
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.

## 4. 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><caption>**Table 1.** GPC algorithms' input parameters.</caption><thead><tr><td>Input Parameters</td><td>Control Horizon (N<sub>u</sub>)</td><td>Prediction Horizon (N<sub>p</sub>)</td><td>Sampling Time (T<sub>s</sub>)</td><td>Weighting Control (λ)</td></tr></thead><tbody><tr><td>Value</td><td>4</td><td>10</td><td>10 s</td><td>0.6</td></tr></tbody></table>

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.
<table><caption>**Table 2.** MG system parameters.</caption><thead><tr><td>Description</td><td>Value</td></tr></thead><tbody><tr><td>DC bus voltage</td><td>320 V</td></tr><tr><td>Grid Nominal voltage</td><td>240 V</td></tr><tr><td>System Nominal frequency</td><td>50 Hz</td></tr><tr><td>DC link capacitance</td><td>2.2 μF</td></tr><tr><td>LC Filter inductance</td><td>0.4 μH</td></tr><tr><td>LC Filter capacitance</td><td>6.85 μF</td></tr><tr><td>VSC rated power</td><td>3 KW</td></tr><tr><td>Load capacitance</td><td>100 mH</td></tr><tr><td>Load inductance</td><td>1 pF</td></tr><tr><td>PWM carrier frequency</td><td>10 KHz</td></tr><tr><td>Sampling frequency</td><td>5 KHz</td></tr><tr><td>Battery capacity</td><td>150 Ah</td></tr><tr><td>Maximum PV power</td><td>1 KW</td></tr><tr><td>Maximum wind power</td><td>1.5 KW</td></tr></tbody></table>

## 4.1. 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 above-mentioned constraints, which are incorporated within the GPC-based 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
<table><caption>**Table 2.** MG system parameters.</caption><thead><tr><td>Description</td><td>Value</td></tr></thead><tbody><tr><td>DC bus voltage</td><td>320 V</td></tr><tr><td>Grid Nominal voltage</td><td>240 V</td></tr><tr><td>System Nominal frequency</td><td>50 Hz</td></tr><tr><td>DC link capacitance</td><td>2.2 μF</td></tr><tr><td>LC Filter inductance</td><td>0.4 μH</td></tr><tr><td>LC Filter capacitance</td><td>6.85 μF</td></tr><tr><td>VSC rated power</td><td>3 KW</td></tr><tr><td>Load capacitance</td><td>100 mH</td></tr><tr><td>Load inductance</td><td>1 pF</td></tr><tr><td>PWM carrier frequency</td><td>10 KHz</td></tr><tr><td>Sampling frequency</td><td>5 KHz</td></tr><tr><td>Battery capacity</td><td>150 Ah</td></tr><tr><td>Maximum PV power</td><td>1 KW</td></tr><tr><td>Maximum wind power</td><td>1.5 KW</td></tr></tbody></table>

### 4.1. 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 above-mentioned constraints, which are incorporated within the GPC-based 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 uncontrolable 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₁ 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.

<figure><img src="image_11.png" /><figcaption>Figure 9. GPC control for autonomous operation mode.</figcaption></figure>

<figure><img src="image_12.png" /><figcaption>Figure 10. Energy management scenarios based on GPC model controller for the grid-connected mode and static set point.</figcaption></figure>
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₁ 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.

<figure><img src="image_12.png" /><figcaption>Figure 9. GPC control for autonomous operation mode.</figcaption></figure>

<figure><img src="image_13.png" /><figcaption>Figure 10. Energy management scenarios based on GPC model controller for the grid-connected mode and static set point.</figcaption></figure>
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
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.

<figure><img src="image_13.png" /><figcaption>**Figure 11.** GPC controller for the grid-connected mode and dynamic set point.</figcaption></figure>

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
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.

<figure><img src="image_14.png" /><figcaption>**Figure 11.** GPC controller for the grid-connected mode and dynamic set point.</figcaption></figure>

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.

<figure><img src="image_14.png" /><figcaption>**Figure 12.** Energy management scenarios based on GPC model, (a) Case 1: without battery-grid interaction, (b) Case 2: with battery-grid interaction.</figcaption></figure>
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.

<figure><img src="image_15.png" /><figcaption>**Figure 12.** Energy management scenarios based on GPC model, (a) Case 1: without battery-grid interaction, (b) Case 2: with battery-grid interaction.</figcaption></figure>
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.

## 4.2. *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.
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.

## 4.2. *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.

<table><caption>**Table 3.** Electricity price benefit for Case 1.</caption><thead><tr><th rowspan="2">Time *</th><th colspan="2">Battery</th><th colspan="2">Grid</th></tr><tr><th>Cost Average (€)</th><th>Power Average (KWh)</th><th>Power Average (KWh)</th><th>Equivalent Cost Exchange</th></tr></thead><tbody><tr><td>06 h-07 h</td><td>0.58</td><td>-0.02</td><td>0.41</td><td>0.24</td></tr><tr><td>07 h-08 h</td><td>0.56</td><td>-0.19</td><td>0.50</td><td>0.28</td></tr><tr><td>08 h-09 h</td><td>0.6</td><td>-0.44</td><td>0.98</td><td>0.59</td></tr><tr><td>09 h-10 h</td><td>0.72</td><td>-0.69</td><td>1.00</td><td>0.73</td></tr><tr><td>10 h-11 h</td><td>0.70</td><td>-1.05</td><td>1.48</td><td>1.05</td></tr><tr><td>11 h-12 h</td><td>0.57</td><td>-1.35</td><td>1.48</td><td>0.84</td></tr><tr><td>12 h-13 h</td><td>0.45</td><td>-1.13</td><td>0.54</td><td>0.25</td></tr><tr><td>13 h-14 h</td><td>0.33</td><td>-0.46</td><td>0</td><td>0</td></tr><tr><td>14 h-15 h</td><td>0.28</td><td>-0.67</td><td>0</td><td>0</td></tr><tr><td>15 h-16 h</td><td>0.43</td><td>-0.47</td><td>0</td><td>0</td></tr><tr><td>16 h-17 h</td><td>0.63</td><td>-0.04</td><td>-0.28</td><td>-0.18</td></tr><tr><td>17 h-18 h</td><td>0.66</td><td>-0.65</td><td>0</td><td>0</td></tr><tr><td>18 h-19 h</td><td>0.62</td><td>-1.42</td><td>0</td><td>0</td></tr><tr><td>19 h-20 h</td><td>0.59</td><td>-1.17</td><td>0</td><td>0</td></tr><tr><td>20 h-21 h</td><td>0.58</td><td>-0.49</td><td>1.48</td><td>0.85</td></tr><tr><td>21 h-22 h</td><td>0.58</td><td>-0.45</td><td>1.48</td><td>0.85</td></tr><tr><td>22 h-23 h</td><td>0.68</td><td>-0.47</td><td>1.22</td><td>0.83</td></tr><tr><td>23 h-00 h</td><td>0.74</td><td>-0.51</td><td>1.22</td><td>0.90</td></tr><tr><td>00 h-01 h</td><td>0.61</td><td>-0.35</td><td>0.99</td><td>0.59</td></tr><tr><td>01 h-02 h</td><td>0.49</td><td>-0.05</td><td>0.98</td><td>0.48</td></tr><tr><td>02 h-03 h</td><td>0.37</td><td>-0.02</td><td>0.47</td><td>0.17</td></tr><tr><td>03 h-04 h</td><td>0.27</td><td>-0.02</td><td>0.47</td><td>0.12</td></tr><tr><td>04 h-05 h</td><td>0.29</td><td>-0.02</td><td>0.47</td><td>0.13</td></tr><tr><td>05 h-06 h</td><td>0.48</td><td>-0.02</td><td>0.47</td><td>0.22</td></tr><tr><td>Total</td><td>-</td><td>-5.71 KWh</td><td>15.36 KWh</td><td>8.97 €</td></tr></tbody></table>

<footnote>* Simulation time without battery-grid interaction.</footnote>
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.

<table><caption>**Table 3.** Electricity price benefit for Case 1.</caption><thead><tr><th rowspan="2">Time *</th><th colspan="2">Battery</th><th colspan="2">Grid</th></tr><tr><th>Cost Average (€)</th><th>Power Average (KWh)</th><th>Power Average (KWh)</th><th>Equivalent Cost Exchange</th></tr></thead><tbody><tr><td>06 h-07 h</td><td>0.58</td><td>-0.02</td><td>0.41</td><td>0.24</td></tr><tr><td>07 h-08 h</td><td>0.56</td><td>-0.19</td><td>0.50</td><td>0.28</td></tr><tr><td>08 h-09 h</td><td>0.6</td><td>-0.44</td><td>0.98</td><td>0.59</td></tr><tr><td>09 h-10 h</td><td>0.72</td><td>-0.69</td><td>1.00</td><td>0.73</td></tr><tr><td>10 h-11 h</td><td>0.70</td><td>-1.05</td><td>1.48</td><td>1.05</td></tr><tr><td>11 h-12 h</td><td>0.57</td><td>-1.35</td><td>1.48</td><td>0.84</td></tr><tr><td>12 h-13 h</td><td>0.45</td><td>-1.13</td><td>0.54</td><td>0.25</td></tr><tr><td>13 h-14 h</td><td>0.33</td><td>-0.46</td><td>0</td><td>0</td></tr><tr><td>14 h-15 h</td><td>0.28</td><td>-0.67</td><td>0</td><td>0</td></tr><tr><td>15 h-16 h</td><td>0.43</td><td>-0.47</td><td>0</td><td>0</td></tr><tr><td>16 h-17 h</td><td>0.63</td><td>-0.04</td><td>-0.28</td><td>-0.18</td></tr><tr><td>17 h-18 h</td><td>0.66</td><td>-0.65</td><td>0</td><td>0</td></tr><tr><td>18 h-19 h</td><td>0.62</td><td>-1.42</td><td>0</td><td>0</td></tr><tr><td>19 h-20 h</td><td>0.59</td><td>-1.17</td><td>0</td><td>0</td></tr><tr><td>20 h-21 h</td><td>0.58</td><td>-0.49</td><td>1.48</td><td>0.85</td></tr><tr><td>21 h-22 h</td><td>0.58</td><td>-0.45</td><td>1.48</td><td>0.85</td></tr><tr><td>22 h-23 h</td><td>0.68</td><td>-0.47</td><td>1.22</td><td>0.83</td></tr><tr><td>23 h-00 h</td><td>0.74</td><td>-0.51</td><td>1.22</td><td>0.90</td></tr><tr><td>00 h-01 h</td><td>0.61</td><td>-0.35</td><td>0.99</td><td>0.59</td></tr><tr><td>01 h-02 h</td><td>0.49</td><td>-0.05</td><td>0.98</td><td>0.48</td></tr><tr><td>02 h-03 h</td><td>0.37</td><td>-0.02</td><td>0.47</td><td>0.17</td></tr><tr><td>03 h-04 h</td><td>0.27</td><td>-0.02</td><td>0.47</td><td>0.12</td></tr><tr><td>04 h-05 h</td><td>0.29</td><td>-0.02</td><td>0.47</td><td>0.13</td></tr><tr><td>05 h-06 h</td><td>0.48</td><td>-0.02</td><td>0.47</td><td>0.22</td></tr><tr><td>Total</td><td>-</td><td>-5.71 KWh</td><td>15.36 KWh</td><td>8.97 €</td></tr></tbody></table>

<footnote>* Simulation time without battery-grid interaction.</footnote>
<table><caption>**Table 4.** Electricity price benefit for Case 2.</caption><thead><tr><th rowspan="2">Time *</th><th colspan="2">Battery</th><th colspan="2">Grid</th></tr><tr><th>Cost Average (€)</th><th>Power Average (KWh)</th><th>Power Average (KWh)</th><th>Equivalent Cost Exchange</th></tr></thead><tbody><tr><td>06 h-07 h</td><td>0.58</td><td>0.45</td><td>0</td><td>0</td></tr><tr><td>07 h-08 h</td><td>0.56</td><td>0.38</td><td>0</td><td>0</td></tr><tr><td>08 h-09 h</td><td>0.6</td><td>0.60</td><td>0</td><td>0</td></tr><tr><td>09 h-10 h</td><td>0.72</td><td>0.41</td><td>0</td><td>0</td></tr><tr><td>10 h-11 h</td><td>0.70</td><td>0.50</td><td>0</td><td>0</td></tr><tr><td>11 h-12 h</td><td>0.57</td><td>0.25</td><td>0</td><td>0</td></tr><tr><td>12 h-13 h</td><td>0.45</td><td>-0.20</td><td>0</td><td>0</td></tr><tr><td>13 h-14 h</td><td>0.33</td><td>-0.36</td><td>0</td><td>0</td></tr><tr><td>14 h-15 h</td><td>0.28</td><td>-0.40</td><td>0</td><td>0</td></tr><tr><td>15 h-16 h</td><td>0.43</td><td>-0.37</td><td>0</td><td>0</td></tr><tr><td>16 h-17 h</td><td>0.63</td><td>-0.01</td><td>-0.26</td><td>-0.16</td></tr><tr><td>17 h-18 h</td><td>0.66</td><td>0.65</td><td>0</td><td>0</td></tr><tr><td>18 h-19 h</td><td>0.62</td><td>1.42</td><td>0</td><td>0</td></tr><tr><td>19 h-20 h</td><td>0.59</td><td>1.17</td><td>0</td><td>0</td></tr><tr><td>20 h-21 h</td><td>0.58</td><td>-0.49</td><td>1.51</td><td>0.87</td></tr><tr><td>21 h-22 h</td><td>0.58</td><td>-0.45</td><td>1.51</td><td>0.87</td></tr><tr><td>22 h-23 h</td><td>0.68</td><td>-0.48</td><td>1.25</td><td>0.85</td></tr><tr><td>23 h-00 h</td><td>0.74</td><td>-0.51</td><td>1.25</td><td>0.92</td></tr><tr><td>00 h-01 h</td><td>0.61</td><td>-0.35</td><td>1.01</td><td>0.61</td></tr><tr><td>01 h-02 h</td><td>0.49</td><td>-0.05</td><td>1.01</td><td>0.49</td></tr><tr><td>02 h-03 h</td><td>0.37</td><td>-1.04</td><td>1.54</td><td>0.57</td></tr><tr><td>03 h-04 h</td><td>0.27</td><td>-1.02</td><td>1.51</td><td>0.40</td></tr><tr><td>04 h-05 h</td><td>0.29</td><td>-0.10</td><td>0.59</td><td>0.17</td></tr><tr><td>05 h-06 h</td><td>0.48</td><td>-0.004</td><td>0.50</td><td>0.24</td></tr><tr><td>Total</td><td>-</td><td>-0.0042 KWh</td><td>11.42 KWh</td><td>5.85 €</td></tr></tbody></table>

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

<footnote>* Simulation time with battery-grid interaction.</footnote>
<table><caption>**Table 4.** Electricity price benefit for Case 2.</caption><thead><tr><th rowspan="2">Time *</th><th colspan="2">Battery</th><th colspan="2">Grid</th></tr><tr><th>Cost Average (€)</th><th>Power Average (KWh)</th><th>Power Average (KWh)</th><th>Equivalent Cost Exchange</th></tr></thead><tbody><tr><td>06 h-07 h</td><td>0.58</td><td>0.45</td><td>0</td><td>0</td></tr><tr><td>07 h-08 h</td><td>0.56</td><td>0.38</td><td>0</td><td>0</td></tr><tr><td>08 h-09 h</td><td>0.6</td><td>0.60</td><td>0</td><td>0</td></tr><tr><td>09 h-10 h</td><td>0.72</td><td>0.41</td><td>0</td><td>0</td></tr><tr><td>10 h-11 h</td><td>0.70</td><td>0.50</td><td>0</td><td>0</td></tr><tr><td>11 h-12 h</td><td>0.57</td><td>0.25</td><td>0</td><td>0</td></tr><tr><td>12 h-13 h</td><td>0.45</td><td>-0.20</td><td>0</td><td>0</td></tr><tr><td>13 h-14 h</td><td>0.33</td><td>-0.36</td><td>0</td><td>0</td></tr><tr><td>14 h-15 h</td><td>0.28</td><td>-0.40</td><td>0</td><td>0</td></tr><tr><td>15 h-16 h</td><td>0.43</td><td>-0.37</td><td>0</td><td>0</td></tr><tr><td>16 h-17 h</td><td>0.63</td><td>-0.01</td><td>-0.26</td><td>-0.16</td></tr><tr><td>17 h-18 h</td><td>0.66</td><td>0.65</td><td>0</td><td>0</td></tr><tr><td>18 h-19 h</td><td>0.62</td><td>1.42</td><td>0</td><td>0</td></tr><tr><td>19 h-20 h</td><td>0.59</td><td>1.17</td><td>0</td><td>0</td></tr><tr><td>20 h-21 h</td><td>0.58</td><td>-0.49</td><td>1.51</td><td>0.87</td></tr><tr><td>21 h-22 h</td><td>0.58</td><td>-0.45</td><td>1.51</td><td>0.87</td></tr><tr><td>22 h-23 h</td><td>0.68</td><td>-0.48</td><td>1.25</td><td>0.85</td></tr><tr><td>23 h-00 h</td><td>0.74</td><td>-0.51</td><td>1.25</td><td>0.92</td></tr><tr><td>00 h-01 h</td><td>0.61</td><td>-0.35</td><td>1.01</td><td>0.61</td></tr><tr><td>01 h-02 h</td><td>0.49</td><td>-0.05</td><td>1.01</td><td>0.49</td></tr><tr><td>02 h-03 h</td><td>0.37</td><td>-1.04</td><td>1.54</td><td>0.57</td></tr><tr><td>03 h-04 h</td><td>0.27</td><td>-1.02</td><td>1.51</td><td>0.40</td></tr><tr><td>04 h-05 h</td><td>0.29</td><td>-0.10</td><td>0.59</td><td>0.17</td></tr><tr><td>05 h-06 h</td><td>0.48</td><td>-0.004</td><td>0.50</td><td>0.24</td></tr><tr><td>Total</td><td>-</td><td>-0.0042 KWh</td><td>11.42 KWh</td><td>5.85 €</td></tr></tbody></table>

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

<footnote>* Simulation time with battery-grid interaction.</footnote>
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 micro-computer (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.

<figure><img src="image_15.png" /><figcaption>**Figure 13.** Data monitoring platform for energy management and GPC controller deployment.</figcaption></figure>
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 micro-computer (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.

<figure><img src="image_16.png" /><figcaption>**Figure 13.** Data monitoring platform for energy management and GPC controller deployment.</figcaption></figure>
4.3. *State of the Art Synthesis and Our Contribution*

Control strategies, generally, use single-objective function procedures (e.g., maximiz-
ing 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 imple-
mented 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 context-
driven 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 continu-
ous 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.

<figure><img src="image_16.png" /><figcaption>**Figure 14.** The proposed control approach schemes with operation process.</figcaption></figure>
4.3. *State of the Art Synthesis and Our Contribution*

Control strategies, generally, use single-objective function procedures (e.g., maximiz-
ing 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 imple-
mented 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 context-
driven 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 continu-
ous 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.

<figure><img src="image_17.png" /><figcaption>**Figure 14.** The proposed control approach schemes with operation process.</figcaption></figure>
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.

### 4.4. 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.

<figure><img src="image_17.png" /><figcaption>Figure 15. Power regulation for the GPC and PID controller.</figcaption></figure>
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.

### 4.4. 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.

<figure><img src="image_18.png" /><figcaption>Figure 15. Power regulation for the GPC and PID controller.</figcaption></figure>
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 (Kp) times the magnitude of the error plus the integral gain (Ki) times the integral of the error plus the derivative gain (Kd) times the derivative of the error.

$$u = K_p \cdot e + K_i \cdot \int e \cdot dt + K_d \cdot \frac{de}{dt} \qquad (31)$$

Based on the control action (Equation (31)) generated from the controller PID, the Kp regulation decreases the rise time, the Ki eliminates the steady-state error, and the Kd 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 Kp, Ki, and Kd, the Sisotool in MATLAB/SIMULINK can be used. In this simple study, the PID is tuned for Kp = 2.75, Ki = 0.984, and Kd = 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 GPC-based 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
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 (Kp) times the magnitude of the error plus the integral gain (Ki) times the integral of the error plus the derivative gain (Kd) times the derivative of the error.

$$u = K_p \cdot e + K_i \cdot \int e \cdot dt + K_d \cdot \frac{de}{dt} \qquad (31)$$

Based on the control action (Equation (31)) generated from the controller PID, the Kp regulation decreases the rise time, the Ki eliminates the steady-state error, and the Kd 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 Kp, Ki, and Kd, the Sisotool in MATLAB/SIMULINK can be used. In this simple study, the PID is tuned for Kp = 2.75, Ki = 0.984, and Kd = 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 GPC-based 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.

<figure><img src="image_18.png" /><figcaption>**Figure 16.** Power regulation for GPC and PID controller, (a) battery power regulation, (b) grid power exchange.</figcaption></figure>
voltage variation. Figure 17a-c show respectively the DC voltage, the DC current, and the
current across the LC filter capacitor.

<figure><img src="image_19.png" /><figcaption>**Figure 16.** Power regulation for GPC and PID controller, (a) battery power regulation, (b) grid power exchange.</figcaption></figure>
<figure><img src="image_19.png" /><figcaption>Figure 17. Current and voltage regulation, (a) DC bus voltage, (b) DC bus current, (c) the current across the filter capacitor.</figcaption></figure>

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.
<figure><img src="image_20.png" /><figcaption>**Figure 17.** Current and voltage regulation, (a) DC bus voltage, (b) DC bus current, (c) the current across the filter capacitor.</figcaption></figure>

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.
<figure><img src="image_20.png" /><figcaption>Figure 18. (a) Load current variation, (b) load voltage variation.</figcaption></figure>

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 voltage-source-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.

<figure><img src="image_21.png" /><figcaption>Figure 19. *Cont.*</figcaption></figure>
<figure><img src="image_21.png" /><figcaption>Figure 18. (a) Load current variation, (b) load voltage variation.</figcaption></figure>

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 voltage-source-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.

<figure><img src="image_22.png" /><figcaption>Figure 19. *Cont.*</figcaption></figure>
<figure><img src="image_22.png" /><figcaption>Figure 19. Frequency spectrum, (a) inverter output current, (b) inverter output voltage, (c) load voltage.</figcaption></figure>

## 5. 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