An Economic Dispatch for a Shared Energy Storage System Using MILP Optimization: A Case Study of a Moroccan Microgrid

: Energy storage systems are an effective solution to manage the intermittency of renewable energies, balance supply, and demand. Numerous studies recommend adopting a shared energy storage system (ESS) as opposed to multiple single ESSs because of their high prices and inefficiency. Thus, this study examines a shared storage system in a grid ‐ connected microgrid. By modifying the power outputs of the energy resources, this work intends to implement an economic dispatch of a shared ESS in order to satisfy the power balance and lower the overall cost of electricity. In this context, an optimization problem was formulated and developed using a mixed ‐ integer linear programming (MILP) model. Furthermore, a pilot project (the Solar Decathlon Africa Village) in the Green & Smart Building Park (GSBP), Benguerir, Morocco, was employed to evaluate and verify the proposed approach. Some comparable scenarios were therefore run in a MATLAB environment. The collected findings demonstrate the efficacy of the developed algorithm in terms of optimizing energy cost reductions and enhancing the integration of renewable resources into the Moroccan energy mix.


Introduction
The significant incorporation of renewable energy sources (RES) into the energy mix is a result of the pressing need to reduce greenhouse gas emissions, which is the primary reason for global warming [1]. Utilizing these new resources has become a sustainable strategy for overcoming ecological changes and simultaneously satisfies the rising demand for energy [2].
However, the integration of renewable resources into the existing power grid poses challenges to grid operators. The most challenging issue regarding the penetration of these energy systems is grid instability. Because energy production that is based on renewable generators is heavily reliant on unpredictable weather conditions (solar radiation, wind speed), their power outputs are constantly varying, which may increase the degree of demand-supply imbalance and negatively impact grid stability and Commission defines specific tariffs for power projects under 100 kW [20]. Further, in Germany, the 2017 act relating to Renewable Energy Sources allows consumers to benefit from certain support schemes such as the market premium and the tenant electricity surcharge, depending on the installed capacities [21,22].
Morocco is one of the first MENA (Middle East/North Africa) countries to adopt renewable energy programs. Morocco has implemented an innovative energy strategy in order to promote the penetration of renewable resources. By 2030, the country aims to increase its renewable energy production to 52%. To fulfill this national energy transition, a profound legislative framework has been established to facilitate the insertion of renewable sources [23]. For example, law N°13-09, which is related to liberalizing the renewable energy market, encouraged public and private entities to use renewable energy as a source of energy production. In addition, law N°58-15, the new updated version of law N°13-09, authorized selling 20% of the excess annual production from renewable sources to grid operators. Moreover, law N°82-21 on self-production allows the generation of electricity for self-consumption, regardless of the voltage level and the installed capacity [24].
The Moroccan energy policy aims to create a competitive, resilient, and sustainable electricity market by authorizing private sector participation in the energy market and promoting self-production based on renewable sources. Through this significant reform, Morocco would be able to meet its ambitious 2030 goal and become a leader in the field of renewable energy [25].
However, the possibility of selling surplus power for installations connected to medium and low voltage is not applicable yet. This paper aims to evaluate the potential of exporting excess energy production in improving renewable resource deployment while minimizing electricity costs. Hence, the main contributions of this work are defined as follows:  The development of an economic dispatch for shared ESS using the MILP model.  Performing some comparative scenarios on MATLAB/Simulink to analyze their impact on energy cost savings.  Testing the performance of the developed algorithm on a pilot project (Solar Decathlon Africa Village) implemented on the Smart Campus-Green & Smart Building Park, Benguerir, Morocco.
Thus, this paper is organized as follows. Section 2 presents Solar Decathlon Africa and power system modeling, including the SDA general model. It also describes the methodology used in this study. Section 3 presents the problem formulation regarding the studied approach and the different parameters and components of the approach. Thus, it presents the MILP algorithm and its development regarding the available data and following the methodology. Finally, before the conclusion and recommendations, Section 4 elaborates and analyzes the simulation results of the Moroccan case study following three comparative scenarios.

Solar Decathlon Africa Village
Currently, there is growing interest in renewable energy resources because of climate change. People around the world have a greater conscience about environmental issues and energy supply constraints. Power generation systems based on renewable energy sources (RES) have several advantages such as easy implementation and scalability. These technologies have received much attention in recent years, and they are commonly present in buildings throughout microgrids around the world. Indeed, the recent growth in microgrids, which integrate renewable energy resources into conventional grids, has taken advantage of these generation characteristics.
Microgrids are defined as localized distribution networks with decentralized management that combine distributed energy resources [26]. A microgrid's design may contain energy storage, backup generators, uninterruptible power supplies (UPS), and controllable generation such as fuel cells and combined heat and power (CHP) fueled by natural gas. It may also incorporate non-controllable generation, such as photovoltaic generation. The microgrid management system balances load and generation. Through the points of common coupling, the microgrid communicates with either the local distribution network or the other microgrids connected to the power system [27].
The Solar Decathlon Africa (SDA) project consists of a variety of buildings implemented in the Green & Smart Building Park Platform of the Green Energy Park [28,29]. This project contains small living labs with their own energy production sources (mainly PV). Thus, some of these living labs will contribute as microgrids connected to the main power grid to support the test and validation of advanced microgrid control strategies and energy management systems (EMSs).
The proposed microgrid within SDA includes several technologies, which are listed below:  Advanced control strategies for energy management;  A shared energy storage system;  An intelligent outdoor lighting system;  Smart electric vehicle charging stations.
The services proposed for the microgrid cover demand, production, and flexible management to ensure the maximum energy consumption from renewable energy sources.

Power System Modeling
Power system modeling essentially entails creating a mathematical, coded, or schematic representation of the actual physical system. This tool can aid in analysis, testing, and the identification of power system specifications and faults. The ability to test new technologies, management systems, and controllers without interfering with the actual system will be made possible by having a complete model of the power system.
There are several tools for power system modeling:  Mathematical modeling: Usually, this is the heart of modeling, where all the components of the microgrid are modeled using a set of variables, equations, and functions that establish the relationship between the different components of the power system.  Software modeling: Software, which is now commonly used, can make it simple to model power systems using pre-existing blocks and units created by a company. A power system analysis, such as a short-circuit analysis, a power flow analysis, a system defect detection, etc., can also be provided by this method.  Coded modeling: This technique, which is relatively new to the field of power system modeling, entails developing an electrical system model utilizing codes and syntax based on predefined libraries. This tool makes it simple to introduce optimization and machine learning technologies.

SDA Model
In this study, MATLAB/Simulink software was used to develop the microgrid model. The units and tools needed are provided by this software in its Simscape Electrical library. The model contains:  An AC power source designed with the same specification of the local distribution network;  Distribution lines and transformers;  Photovoltaic power generation systems;  Shared Energy Storage system;  Five living labs (residential loads). An illustrated schematic of the whole microgrid model is shown in Figure 1. The main output of the model is the different measurements of power, voltage, and current in the various components and nodes of the microgrid. These measurements will help analyze the behavior of the microgrid generation and production regarding the energy management system.

Methodology
Data gathering was the initial phase of this research project because the major objective was to design an economic dispatch algorithm for a shared energy storage system within a studied microgrid in Morocco. Therefore, by using the smart meters included in the different living laboratories of the SDA, the necessary information including the various photovoltaic production profiles, information on energy consumption, and various energy costs (such as energy costs, penalties, bi-hourly energy charges, etc.) was gathered and used in the simulation process following the assessment process in Figure 2a. The parameters of the optimization problem were established following the data provided. The objective function, constraints, and equations for the optimization problem were all included in the problem description. To evaluate the optimization approach, the mathematical equations and the objective function were further transformed into a MATLAB-based code that was then loaded into a Simulink block for simulations.
Once all the parameters had been modified in the algorithm, the simulation began with a time step of 10 min for both energy consumption and PV production during a summer day. Additionally, the bi-hourly taxes for high-voltage A (HVA) in Morocco were used to comment on the relative costs of energy usage. As a result, the simulation encountered various important performance metrics, such as the amount of PV generated and injected into the main grid, the performance of the shared energy storage system, the PV curtailment, and the profile of load consumption. Once more, the energy cost reduction, which includes the cost both before and after the optimization, is the study's most significant finding. Therefore, the validation of the algorithm was later performed regarding the results of both costs.
This methodology was used in order to compare the algorithm's viability in light of the respective Moroccan energy frameworks. Additionally, the method was used to gather suggestions that could aid in the Moroccan energy transition without impacting the parties involved in the electricity market. The methodology's primary steps are displayed in Figure 2b.

Problem Description
Each household of our system contains loads and PV generators. Living labs' loads consume power (Pload) and PV generators generate power (PPV). If a mismatch between Pload and PPV occurs, there are four options to satisfy the power balance, as shown in Figure 3.


Main grid: supplying or consuming power mismatch. When Pload > PPV, the electricity should be supplied from the main grid. Similarly, when Pload < PPV, the exceeding electricity returns to the main grid.  Loads: positive and negative demand responses to make up for a power imbalance. By scheduling the operation time of the flexible loads, the consumption profile can be controlled corresponding to the PV power output.  PV generators: curtailment when PPV > Pload. The PV curtailment occurs when the PV generation is greater than the electricity demand.  Shared ESS: charging or discharging to compensate for power mismatch. The surplus energy is utilized to charge the ESS when the PV power output exceeds the load consumption. Likewise, the ESS discharges to supply the households' needs when the PV power cannot match the load demand.
By optimally determining the power outputs of each option, electricity cost minimization can be achieved.

Formulation of the Optimization Problem
The main objective of this study is to reduce electricity costs during the day. To achieve overall cost minimization, optimal values of exchanged powers should be required. In this context, an optimization problem is considered.

Objective Function
The power mismatch between Pload and PPV is defined as follows: As explained above, there are four options to compensate for the power mismatch. Thus, the power balance equation can be formulated as: The objective function to be minimized is the total cost of electricity. It is evaluated as the sum of the costs attributable to PV curtailment, positive and negative demand response, energy storage sharing, and main grid connection. It is presented below: ΔPmain can be expressed as follows: where ΔP + main and ΔP − main are the positive and the negative main grid output, respectively. Households pay for the consumed electricity (ΔP + main) with cmain. The power injected to the main grid (ΔP − main) is paid with cpenalty. Then, the objective function is modified as: To consider asynchronous charging and discharging efficiency, the ESS power ΔPESS has been separated using charging power ΔPchar and discharging power ΔPdis. Thus, ΔPESS can be represented by: Cost occurs only during discharge. Thus, the objective function is expressed as follows:

Constraints
There are several conditions and constraints that should be considered. For each option, the constraints that must be satisfied are presented below:  Shared ESS: -ESS cannot be charged and discharged simultaneously; if ESS is charging, the discharging output should be zero. If ESS is discharging, the charging output should be zero. Therefore, by using integer slack variables (bdis and bchar) as follows, ESS cannot be charged and discharged at the same time: bchar + bdis ≤ 1 -Note that if bdis (bchar) is zero, ΔPdis (ΔPchar) should be zero. Furthermore, ΔPchar and ΔPdis should be positive and not exceed the rated power of ESS. Thus, the following constraints should be satisfied: 0 ≤ ΔPdis ≤ bdis × PESS,max  Main Grid: -Supplying and consuming the power mismatch by the main grid cannot happen simultaneously. To express this constraint, we use integer slack variables (b + main and b − main) as the positive and negative main grid slack variables, respectively.
The power exchanged with the main grid (ΔP + main and ΔP − main) should be positive and limited by the rated power of the main grid transformer PTR. This constraint is expressed by Equations (12) and (13):  PV generator: -Maximum curtailment is equal to PPV.
where bPV is the PV slack variable.
-Curtailment is only allowable when ΔPmis (Equation (1)) is negative. The Big-M method is used to formulate logical expression as a mixed-integer linear program form.
 Loads: -It is assumed that positive and negative demand responses (DRs) are only allowable for ε% of individual loads. Thus, the number of positive and negative DRs is limited by the ε% of individual loads, as expressed in the following equations: -Positive and negative DRs cannot participate simultaneously. The positive and the negative DR integer slack variables (b + DR,i, b − DR,i) are used to express this constraint. Thus, positive and negative DRs can be expressed as follows:

MILP Algorithm Presentation
The mixed-integer linear programming (MILP) problems were presented, for the first time, by Nemhauser and Wolsey in 1988 [30]. MILP methods have been widely adopted for solving energy supply problems, such as sizing energy storage systems and distributed generators [31][32][33], minimizing energy costs and CO2 emissions [34,35], and the allocation of renewable sources in the distribution network [36].
Based on the branch and bound technique, the MILP model solves a specific class of optimization problems, which have [30]:


Linear objective functions;  Linear equality constraints and/or linear inequality constraints;  Integrality restrictions on some optimization variables (some optimization variables have integer values). Mathematically, a mixed-integer linear problem can be expressed by the following formulation: Minimize: F T .x Subject to: . .
F T .x represents the objective function to be optimized; F is a vector of constants; and x is an optimization variable vector.
The matrices (C and Ceq) and the corresponding vectors (d and deq) encode the linear inequalities and linear equalities, respectively.
Lb and Ub are the vectors of lower and upper boundaries, respectively.

Development of MILP Algorithm
The optimization problem is a mixed-integer linear problem (MILP), as shown in Figure 4. Thus, the MILP solver in MATLAB (e.g., intlinprog) was used [17] to obtain the optimal power values for minimizing costs. The main steps followed in the MILP algorithm are summarized in Figure 5.

Simulations and Results
In this section, the parameters and the model defined in the last section are transformed into a MATLAB environment in order to execute the simulations regarding the Moroccan data. Thus, to evaluate and verify the approach used in this study, the simulation horizon is one day divided into 144 sampling intervals with a time step of 10 min.
Furthermore, to be able to compare the results regarding the different case studies, we opted for three scenarios for simulation. The first one is the actual situation in Morocco, the second one introduces a simulation using the MILP optimization approach, and the last scenario provides a simulation using the energy management system (EMS) and involving the DR for all the five living labs. Table 1 provides an illustration of the researched system's parameters. However, the quantity of PV power placed in each living lab affects the various prices of DR. As a result, the price changes according to how much energy each household contributes to the demand response.

Parameter Definition Value ccurt
Cost of Curtailment 0.01 MAD/kWh c + DR, 1 Cost of DR 1 plus 0.0001 MAD/kWh c − DR, 1 Cost of DR 1 minus 0.1 MAD/kWh c + DR, 2 Cost of DR 2 plus 0.04 MAD/kWh c − DR, 2 Cost of DR 2 minus 0.03 MAD/kWh c + DR, 3 Cost of DR 3 plus 0.06 MAD/kWh c − DR, 3 Cost of DR 3 minus 0.01 MAD/kWh c + DR, 4 Cost of DR 4 plus 0.05 MAD/kWh c − DR, 4 Cost of DR 4 minus 0.02 MAD/kWh c + DR, 5 Cost of DR 5 plus 0.02 MAD/kWh c − DR, 5 Cost The total load profile of the living labs for the day 7 July 2022 is presented in Figure  6. As can be noticed, the load demand is low during the night and it starts increasing at 07:20 a.m. Moreover, the energy consumption peaks between 11:00 h and 13:00 h and in the evening, at 21:30 h.  Figure 7 shows the PV production profile of the studied system on 7 July 2022. As can be observed, the PV output has a typical production curve with a maximum value of 16.95 kW reached in the afternoon period.

Electricity Rate
In Morocco, the electricity rate is defined by the power system utility. The electricity prices are applied according to the voltage level (high, medium, low) and the used sector (industry, commerce, and residence).
For medium voltage, the applied electricity rate is defined as time-of-use (ToU) pricing, which consists of billing the consumed energy at different tariffs according to three hourly periods: on-peak, off-peak, and full hours. The ToU pricing by season is described in Table 2.

Scenario N°1: Simulation without EMS and without DR
In this instance, the simulation was run without taking the methodology employed in this study into account. This section, therefore, relates to the current state of Morocco's power grid. The meter used in the investigated microgrid collects data on the energy consumption in a unidirectional manner and retrieves billing information, in contrast to the Green & Smart Building Park, where the pricing of power is elaborated using meters installed in each facility. The meter, however, counts the energy surplus that is delivered to the grid as consumed. As a result, the cost of energy that is injected into the electrical system is the same as the one consumed. Figure 8 presents the findings when the simulation is finished for a day of data. Three key outputs were offered by the results: main grid power, power from shared energy storage, and power curtailment. Considering the PV and the load profiles presented in the preceding section, the energy provided to the microgrid was mainly imported from the grid. Therefore, the amount of energy absorbed/injected in the power system is considered as consumed.

Scenario N°2: Simulation with EMS and without DR
Without including demand response in our algorithm, the MILP technique was expanded in this scenario while adding the predefined functions and the other parameters discussed earlier. In terms of main grid power contribution and ESS generation, Figure 9 depicts the simulation's results, where the energy storage system anticipates charging and discharging scenarios throughout the afternoon. However, the energy storage is fully charged, and the surplus of energy is returned as a curtailment in accordance with the load profile between the hours 2:00 p.m. and 5:00 p.m., when the PV production is highest. It is also important to note that, in this instance, it is clear that no electricity has been injected into the power grid due to the non-intervention of DR strategies.

Scenario N°3: Simulation including EMS and DR
The MILP plan and the DR strategy are developed in the final scenario in accordance with the previously updated framework of law N°82-21, which permits a self-production of 20% of total energy from renewable resources. The findings, displayed in Figure 10, show a PV power injection of almost 3 kW into the power system, which is roughly equal to 20% of the PV capacity. It can also be seen that there is no curtailment in PV generation because the surplus energy could be exploited and injected into the main grid.
Regarding demand response strategy, it can be observed from Figure 11 that during the consumption peaks, almost all the households contribute to demand response when decreasing their energy demand in order to shave the peak load. Further, when the demand is lower than the PV production in the afternoon, a positive demand response occurred for household one by increasing its consumption. In fact, household one was more favorable to participate in a positive DR due to its low attributing cost (c + DR,1 = 0.0001 MAD/kWh). The costs of DR contribution were established in a different manner for the purpose of revealing the best DR contribution scenario.

Cost Reduction
This study's primary goal is to develop a generalized economic dispatch for a microgrid with a shared ESS. Thus, the study's goal is to introduce DR techniques while reducing the cost of energy. The MILP optimization approach determined the cost of energy for each of the many scenarios. It is clear from the chart below that the second and final scenarios would result in lower costs. The second scenario introduced an important cost decrease with a 31% cost reduction but did not permit the injection of extra power into the grid. However, the final scenario, which combines DR and a MILP optimization strategy, lowered the cost of energy by almost 51%, validating the goal of the study.

Discussion
According to the simulation results, the first scenario presents the actual Moroccan situation, without the implementation of the proposed approach or the demand response strategy. As can be observed in Figure 12, during the on-peak hours when the energy demand reached almost 22 KWh, the cost related to the amount of energy consumed during that period of time rose to approximately 32 MAD. However, in the second scenario, where the MILP optimization approach was implemented, the cost was reduced by approximately 31%.
Furthermore, the last scenario, where both the demand response strategy and the MILP optimization approach were integrated, presented a significant cost reduction of almost 52% of the energy cost.
Therefore, the approach established in this study has demonstrated a very significant cost reduction when employing the energy management system and including demand response strategies in all the residences of the SDA. However, the validity of the methodology depends not only on the outcome but also on how well it represents the Moroccan energy framework.
From another perspective, the study has demonstrated another crucial element that promotes the maximum use of renewable energies. This approach has proven to result in a significant decrease in the amount of power consumed from the grid, where in the first scenario, the microgrid was relying on the power system for almost 52% of its power demand during the day. However, in scenario two and scenario three, grid dependency

Scenario3
Scenario2 Scenario1 was reduced to 21.88% and 12.81%, respectively, which encourages the use of energy produced by renewable energies. Hence, the results demonstrate that the combination of a shared ESS installation and DR implementation is more beneficial in reducing utility bills, maximizing RES production among microgrids, and enhancing energy management systems. Additionally, the strategy has demonstrated that the previous law on auto-injection, N°13-09, has placed significant restrictions on supporting the integration of RES into the electrical system in Morocco. However, the last scenario, which is complied with the updated law (law N°58-15), has illustrated the validity of this energy policy regarding RES penetration into the power grid.

Conclusions and Recommendation
Shared energy storage systems have an essential role in improving the penetration of renewable energies into the existing power grid. In this paper, an economic dispatch for shared ESS was developed using the MILP model. The algorithm manages the power outputs of a shared ESS, PV generators, controllable loads, and the main grid in order to satisfy the power balance and reduce energy costs. The developed approach was demonstrated on a pilot project (SDA), and comparative scenarios were conducted in MATLAB/Simulink for a horizon of 24 h. The obtained findings reveal a significant energy cost reduction evaluated to be 52% when implementing the MILP technique and the demand response strategy.
This study highlights the importance of using a shared ESS and implementing a demand response mechanism in increasing RES systems' profitability. By combining shared storage systems and injecting surplus energy, users could reduce their grid dependence, avoid PV curtailment, and increase their cost savings.
This developed approach could take advantage of a large-scale proof of concept (POC) in order to study its feasibility and validity in a large-scale power system with high penetration of RES and greater ESS capacities. This would allow the parties involved to develop a pre-study of the proposed approach for further implementation. Consequently, this would encourage more large-and small-scale RES projects to be developed and would absolutely increase the share of renewable energies in the Moroccan energy mix.
However, regarding the self-production framework, the approach has proven its validity using various parameters and data including demand response costs, when they were applied in an arbitrary manner, which is considered a limitation to this study regarding the actual Moroccan power system. Therefore, the energy framework should include more details regarding the demand response costs, the different constraints related to the power system, the costs of penalties in terms of exceeding 20% of the energy production to the main grid, etc. The availability of these parameters would help consumers and industries to implement the approach in their facilities.
Finally, the method developed in this study was tested in a simulated environment. As a result, it has been decided that the next stage of the study will be implemented in a laboratory equipped with a real-time simulator, and the power hardware-in-the-loop simulation method will be used for simulation to introduce different grid parameters and constraints before applying the approach to the real microgrid.

Conflicts of Interest:
The authors declare no conflicts of interest.