Implementation of Optimal Two-Stage Scheduling of Energy Storage System Based on Big-Data-Driven Forecasting — An Actual Case Study in a Campus Microgrid

Optimal operation scheduling of energy storage systems (ESSs) has been considered as an effective way to cope with uncertainties arising in modern grid operation such as the inherent intermittency of the renewable energy sources (RESs) and load variations. This paper proposes a scheduling algorithm where ESS power inputs are optimally determined to minimize the microgrid (MG) operation cost. The proposed algorithm consists of two stages. In the first stage, hourly schedules during a day are optimized one day in advance with the objective of minimizing the operating cost. In the second stage, the optimal schedule obtained from the first stage is repeatedly updated every 5 min during the day of operation to compensate for the uncertainties in load demand and RES output power. The ESS model is developed considering operating efficiencies and then incorporated in mixed integer linear programming (MILP). Penalty functions are also considered to acquire feasible optimal solutions even under large forecasting errors in RES generation and load variation. The proposed algorithm is verified in a campus MG, implemented using ESSs and photovoltaic (PV) arrays. The field test results are obtained using open-source software and then compared with those acquired using commercial software.


Introduction
The concept of microgrids (MGs) and corresponding applications have drawn considerable attention from researchers over the last decades, given that it is now possible to reliably and efficiently integrate distributed energy resources (DERs) into today's power systems [1,2].They can integrate distributed renewable energy generation and storage capacity to meet the electrical needs of customers.They greatly enhance local power supply reliability [3].However, many challenging issues are associated with MGs operation, the most common of which is the reliable integration of renewable energy sources (RESs), such as photovoltaic (PV) and wind turbine (WT), given their inherent variability and uncertainty in terms of power generation [4][5][6][7].Sharp fluctuations in load demands on a MG constitute additional unpredictable variables [8,9].However, the impact of these uncertainties can be compensated with the aid of the energy storage system (ESS) [10,11].Optimal energy scheduling using an ESS is crucial to cope with the uncertainties of RESs and loads, and to ensure the reliable and economical operation of the MG.The MG can operate in the grid-connected and islanded modes [12,13].
Energies 2019, 12, 1124 2 of 20 MG energy management system (MEMS) successfully provides the reference signals in real time and scheduling time horizons, so that the MG operates in both modes reliably.
Single-stage approaches have been popular because they are easy to implement [14][15][16][17][18][19][20][21].In reference [14], online optimal control strategies for ESSs was developed.The optimization problem was formulated as a robust mixed integer linear programming (MILP) problem to handle uncertainty in the forecast load demands and RESs power generation.In reference [15], a two-layer optimal dispatch model with ESSs and supercapacitors was formulated.An upper layer minimized the total operational costs, and a lower layer then mitigated load fluctuations and RES forecast errors.It demonstrated that two types of energy storage could be utilized in a hierarchical dispatch model.An execution monitoring and replanning approach for optimal 24-h dispatch considering the uncertainties in weather conditions and load profiles were developed in [16].A multi-objective function was devised to minimize energy losses, fuel costs, and carbon dioxide emissions.However, the single-stage approaches in [14][15][16] were modeled only using numerical software.
Some studies have focused on actual-to-laboratory-scale MGs [17][18][19][20][21].An energy management system (EMS) was proposed to minimize the overall operations costs in [17].It considered a complete non-linear optimal power flow problem, which determined the active and reactive power injections at all network buses.It compared the solution that derived using a linearized optimal power flow problem.Optimal operation of an isolated system using a virtual power producer was proposed to minimize the generation costs and optimize battery charging/discharging in [18].Reference [19] proposed the use of offline scheduling to minimize operating costs by using day-ahead forecast data.It focused on modeling a MG and design of an EMS.An EMS maximizing total MG profit considering the total capacities of the RESs and storage systems in terms of future expansion was developed in [20].Reference [21] proposed the use of an EMS based on unit commitment with a rolling horizon to reduce the uncertainties of forecasting.The goal of their proposed optimization was to minimize the operational costs of the MG.
However, the day-ahead single-stage approach is vulnerable to forecasting errors and unpredictable variations in renewable power generation and load demands.Thus, the optimal operating schedule obtained using a single-stage approach may not guarantee optimal operation of an actual MG.Such issues focus attention on two-stage scheduling approaches, which are robust under forecasting errors and unpredicted changes in operation conditions [22].Most literature on the two-stage scheduling approach has focused on simulation-level demonstrations [23][24][25][26][27][28][29].Reference [23] addressed energy resources scheduling for the day-ahead and in real time to minimize the total operation cost of a grid-connected MG.It considered the case where all types of loads were imposed in a demand response program.In references [24,25], day-ahead scheduling determined the hourly generation schedules to minimize MG operation costs.Real-time scheduling at a time scale of 5 min allowed the MG to follow the day-ahead scheduled power exchange with the main grid.Two different time scales were applied; 1 h for cooling energy and 5 min for electrical energy.In reference [26], each stage of the two-stage scheduling was two-level.The lower level of the day-ahead scheduling module was to maximize the expected profit, and the upper level was to minimize the total cost of MG operation during the day.The second stage featured hour-ahead scheduling at 15-min intervals.The aim of the lower level of the second stage was to maximize the use of RESs when following the day-ahead schedule.The upper level of the second stage was the same as the upper level of the first stage.A two-stage robust optimization method to plan ESS charging/discharging, and direct load control (DLC) was developed to maximize the total profit of the MG in [27].In the first stage, ESS charging/discharging power was scheduled to decrease energy purchases from the main grid, and DLC scheduling was then set 15 min earlier to complement ESS operation.In reference [28], hourly scheduling of the day-ahead optimal economic dispatch was performed to minimize the daily MG operational costs, followed by intra-hour adjustment using two layers to smooth fluctuations and follow day-ahead scheduling.In the second stage, two different dispatch time intervals were set, one for virtual energy storage system and the other for the vehicle-to-building system.In reference [29], a two-stage scheduling framework optimization problem was formulated to optimize the real-time operation of a battery and an ultracapacitor.Hour-ahead scheduling was first performed to minimize the operation cost of the MG, followed by real-time scheduling to eliminate power imbalances caused by the uncertainties in the RESs and loads.
Only a few studies have validated the two-stage optimization problem using real MGs [30,31].A heuristic optimal operation was proposed to minimize the MG operating cost in [30].The proposed strategy featured both day-ahead and real time scheduling and performance of three different heuristic algorithms was compared.Reference [31] assessed peak load shifting, onsite PV performance and grid support by formulating an MILP optimal dispatch problem, featuring both month-ahead and day-ahead scheduling.The first stage determines DERs scheduling to minimize total operating costs (on a monthly basis), and the second stage then considers the same optimization problem but over a day-long time horizon.Table 1 presents a summary of previous studies on the optimal scheduling optimization problem types, and the validation methods used.This paper proposes a two-stage scheduling, which consists of the day-ahead scheduling and the hour-ahead scheduling with consideration of the ESS.It is implanted in a MEMS in a campus MG and then validated both in actual case and in simulation to show the effectiveness of the proposed method.The main contributions of this paper are as follows:

•
This paper proposes two-stage scheduling-day-ahead and hour-ahead scheduling-to mitigate uncertainty and forecasting errors.The first stage is performed one day in advance to minimize the operation cost, while the second stage is performed every 5 min to minimize the difference between the input power from the main grid before the day and that during the day.

•
Unlike previous papers [23][24][25][26][27][28][29], we engage in practical implementation of the proposed two-stage scheduling system.An Internet-of-Things (IoT)-based campus MG, composed of PV and ESS, is used as a case study to evaluate the proposed method.The method is developed using not only the forecast data on load demand and required PV generation but also actual data on electricity prices and device parameters.

•
The proposed scheduling optimization problem is modelled in PuLP (i.e., a modeling environment in Python) using an open-source solver coin-or branch and cut (CBC).The optimization module in the implemented MEMS is completely open-source based.

•
Additional case studies are performed to deal with limitations of the implementation in the campus MG.We verify that completely open-source software can be used to develop the small-scale MG and that the algorithm is applicable at various PV and battery capacities.
The remaining manuscript of this paper outlines as follows: Section 2 describes an overview of the implemented campus MG; Section 3 formulates our proposed two-stage scheduling; Section 4 describes the results of not only implementation but also simulation case studies; and Section 5 concludes the paper.Note that this paper focuses especially on optimization.

•
Additional case studies are performed to deal with limitations of the implementation in the campus MG.We verify that completely open-source software can be used to develop the smallscale MG and that the algorithm is applicable at various PV and battery capacities.
The remaining manuscript of this paper outlines as follows: Section 2 describes an overview of the implemented campus MG; Section 3 formulates our proposed two-stage scheduling; Section 4 describes the results of not only implementation but also simulation case studies; and Section 5 concludes the paper.Note that this paper focuses especially on optimization.Moreover, two types of IoT sensors are installed throughout the library.One is a power sensor (P-type) and the other is a high-speed sensor (H-type).Table 2 lists the features of the two types of sensor.The reliability of sensors is important since inaccurate sensing and data measurement can cause various malfunctions in the EMS and consequently unstable operation of the MG [32].Note that the average and maximum error rates of two sensors were measured in the field demonstration experiments.54 P-type sensors have been installed in the electric distribution panels where lighting and plug-in loads are connected.In addition, 23 H-type sensors have been installed in the distribution panels for heating, ventilation, and air conditioning (HVAC) systems (e.g., air cleaners, thermoshydrostats, package air conditioners, and pumps).The H-type sensors will be more extensively exploited particularly for the analysis of dynamic operation and control of the campus MG, which is considered a next research topic.Moreover, two types of IoT sensors are installed throughout the library.One is a power sensor (P-type) and the other is a high-speed sensor (H-type).Table 2 lists the features of the two types of sensor.The reliability of sensors is important since inaccurate sensing and data measurement can cause various malfunctions in the EMS and consequently unstable operation of the MG [32].Note that the average and maximum error rates of two sensors were measured in the field demonstration experiments.54 P-type sensors have been installed in the electric distribution panels where lighting and plug-in loads are connected.In addition, 23 H-type sensors have been installed in the distribution panels for heating, ventilation, and air conditioning (HVAC) systems (e.g., air cleaners, thermos-hydrostats, package air conditioners, and pumps).The H-type sensors will be more extensively exploited particularly for the analysis of dynamic operation and control of the campus MG, which is considered a next research topic.

Configuration of an Implemented MG
Figure 2 illustrates the configuration of the campus MG.Existing loads are classified into two types: general loads (e.g., lighting, air conditioners, and heaters) and critical loads (e.g., central computer, super computer, and big-data server).Both types of loads are supplied with power when the MG is in the grid-connected mode.However, in case of failure of the main grid, the general loads may not receive enough power because the critical loads have priority over the general loads.

The Proposed Two-Stage Scheduling Algorithm
In practice, variations between forecast data and real-time data are inevitable due to variations and uncertainties in load demands and PV generation.However, it is possible to obtain more accurate forecasts as real-time operation becomes more imminent [26,27].Thus, it is not possible to use only day-ahead scheduling at 1-hour intervals to reflect variability well [29].Thus, the two-stage scheduling is proposed to mitigate forecast errors and improve the accuracy of scheduling.IoT sensors are installed on the sides of the general and critical loads and generate huge amounts of data.All information (e.g., general load power P L_gen and critical load power P L_crit parameters) received by the IoT sensors is transmitted to a cloud-based IoT platform over a communication link [33].An efficient data communication system is required for continuous, fast, reliable, and accurate transfer of information among sensors.Thus, no disturbance and disconnection is acceptable when sharing information [34].The P-type sensors use the Ethernet for information transfer, and the H-type sensors communicate via Wi-Fi.The information in the cloud-based IoT platform is sent to a big-data server designed to store and analyze huge amounts of data and to provide a monitoring system.The database (DB) in the MEMS retrieves the required information (e.g., P L_gen and P L_crit ) from the big-data server Energies 2019, 12, 1124 6 of 20 over the communication link.The MG bus, the PV and the battery are equipped with measuring units.The utility and PV-side units measure voltage, current, active power (i.e., utility power P u , PV power P PV ).An additional state-of-charge (SOC) is measured at the battery side measuring units.All of these data pass through a supervisory control and data acquisition (SCADA) system and are then forwarded to the MEMS; the DB then acquires the data.
The MEMS consists of four modules: forecasting, optimization, data analysis, and human-machine interface (HMI) [35].The forecasting module operates at different time scales: day-ahead and 2 hours-ahead.It provides forecasts of PV generation power and load demands and delivers the forecasts to the optimization module.The optimization module makes decisions scheduled utility power P u s and battery power P b s using data from the forecasting module and DB.Note that the campus MG is implemented using two-stage scheduling, which is described specifically in Section 3. The battery power reference signal P b ref is transferred to the battery controllers through the SCADA, which compensates for any mismatch between the scheduled power and the actual MG power [19].
A bit flag (0/1) is also delivered to the SCADA to decide whether the scheduled results are performed or not in practice.It is zero only when the parameters input by the MEMS operator exceed bounds or when required data (e.g., the forecast load demands and PV generation power, market information, and measurements) are not delivered to the optimization module.The MEMS collects vast amounts of data such as forecasts, measurements, market information, DER parameters, and the result of scheduling.These data must be analyzed properly to provide insights on how to improve the performance of the forecasting and optimization modules [36].A MEMS should also provide real-time monitoring and control of a MG.This is performed by the HMI, and keeps operators aware of current MG status and delivers accessible information [36].Turning briefly to communication, no standard form of communication for MEMS operations has yet been defined [37].However, as the numbers of DERs in MGs increase, a new type of communication system is needed to improve the quality and stability of the system.For example, IEC 61850 deals with real-time supervision and control of electrical systems and is widely used to exchange real-time information [38].

The Proposed Two-Stage Scheduling Algorithm
In practice, variations between forecast data and real-time data are inevitable due to variations and uncertainties in load demands and PV generation.However, it is possible to obtain more accurate forecasts as real-time operation becomes more imminent [26,27].Thus, it is not possible to use only day-ahead scheduling at 1-hour intervals to reflect variability well [29].Thus, the two-stage scheduling is proposed to mitigate forecast errors and improve the accuracy of scheduling.Figure 3 presents the time framework of our proposed scheduling for the campus MG, which includes day-ahead scheduling and hour-ahead scheduling, especially at a typical time t = N (hour) for ∆t where N ∈ {0, 1, • • • , 23}.Also, both stages are formulated as MILP problems, the objective functions of which include penalty terms.

1.
Day-ahead scheduling stage: This stage is performed only once before the day to determine the optimal scheduling for the next day.The time window (TW) is 24 h, and the time interval (∆t) is 1 h.The scheduled profiles do not change with ∆t.

2.
Hour-ahead scheduling stage: This is performed every 5 min during the day for peak saving.
Note that hour-ahead scheduling is not conducted at the beginning of every 5-min interval, but rather follows the day-ahead scheduled profile.In other worlds, the second stage runs not 12 times but rather 11 times per ∆t.The time window is TW − k∆t where k ∈ {1, • • • , 11}, and the time interval ∆t is 5 min.Only the first interval of each run set serves as a final decision and the rest of the intervals are for reference only.

Day-Ahead Scheduling Stage
In the first stage, the objective function contains the two terms, shown in Equations ( 1) and ( 2).The first term is to minimize the total daily operation cost of the campus MG, and the second is a penalty function that takes into account the situation when the scheduled utility power exceeds the contracted power.Note that it is taken into consideration the case of the MG exporting the surplus PV output power to the main grid, where the scheduled utility power can become negative.
where ct is the hourly electricity price of the main grid.Moreover, Pu,t s,d is the scheduled utility power imported from the main grid at tth period.Furthermore, Pcont is the contracted power and M2,t is an additional decision variable, which is the larger of the 0 and (Pu,t s,d − Pcont) at time t.In (1), θ1 is a penalty factor and T is the set of hourly periods (i.e., T = [0, 1, •••, 23]).However, the second term needs to be linearized when formulating a MILP problem.It is based on Appendix A and can be achieved using Equations (3)- (5).
where M1,t is a continuous decision variable at time t.Moreover, r0, r1, and r2 are parameters.Furthermore, W1,t is a binary decision variable at time t.All facilitate the piecewise linearization of the penalty function M2,t.Moreover, the power balance between total power production and consumption at any time t must be guaranteed.The linearized DistFlow formulation for the power flow equations is adopted.It has been largely used in both distribution grids and MGs [39,40].In this paper, we use active power, neglecting power losses on the lines, which can be formulated as Equation (6).
where Pj,i,t s,d and Pi,k,t s,d is the day-ahead scheduled active power that flows from jth bus to ith and from ith bus to kth, respectively, at time t.Moreover, PLi,t f,d is the day-ahead forecast load demand

Day-Ahead Scheduling Stage
In the first stage, the objective function contains the two terms, shown in Equations ( 1) and ( 2).The first term is to minimize the total daily operation cost of the campus MG, and the second is a penalty function that takes into account the situation when the scheduled utility power exceeds the contracted power.Note that it is taken into consideration the case of the MG exporting the surplus PV output power to the main grid, where the scheduled utility power can become negative.min{ ∑ (c t P s,d where c t is the hourly electricity price of the main grid.Moreover, P u,t s,d is the scheduled utility power imported from the main grid at tth period.Furthermore, P cont is the contracted power and M 2,t is an additional decision variable, which is the larger of the 0 and (P u,t s,d − P cont ) at time t.In (1), θ 1 is a penalty factor and T is the set of hourly periods (i.e., T = [0, 1, • • • , 23]).However, the second term needs to be linearized when formulating a MILP problem.It is based on Appendix A and can be achieved using Equations (3)- (5).
where M 1,t is a continuous decision variable at time t.Moreover, r 0 , r 1 , and r 2 are parameters.Furthermore, W 1,t is a binary decision variable at time t.All facilitate the piecewise linearization of the penalty function M 2,t .Moreover, the power balance between total power production and consumption at any time t must be guaranteed.The linearized DistFlow formulation for the power flow equations is adopted.It has been largely used in both distribution grids and MGs [39,40].In this paper, we use active power, neglecting power losses on the lines, which can be formulated as Equation (6).
where P j,i,t s,d and P i,k,t s,d is the day-ahead scheduled active power that flows from jth bus to ith and from ith bus to kth, respectively, at time t.Moreover, P Li,t f,d is the day-ahead forecast load demand power at ith bus at time t, and P PV,t f,d is the forecast PV generation power at time t.In addition, P ch,t s,d and P dch,t s,d are the day-ahead scheduled battery charge and discharge powers at time t.Furthermore, B is the set of buses and L is the set of lines in the implemented MG.Furthermore, B is the set of buses and L is the set of lines in the implemented MG.
The SOC and power output constraints are important battery issues.Equation (7) shows that the energy stored in the battery at time t is affected by not only its previous value but also the charge and discharge power at the present moment.To prevent the battery from becoming overcharged or overdischarged, the SOC limit must be satisfied, which is described in Equation ( 8).

SOC
where SOC t s,d is the state of charge describing how much energy is stored in the battery at time t.
Furthermore, SOC min and SOC max are the minimum and maximum amounts of energy that can be stored in the battery, respectively.Moreover, η ch and η dch are the charge and discharge efficiency of the battery, respectively.In addition, EC max is the capacity of the battery.Inequality constraints dealing with the charging and discharging power capacity limits of the battery can be derived from Equations ( 9) and (10).The battery has three operating states: standby, charging, and discharging.The three cannot be in play at the same time t.This can be achieved by introducing a new variable u t , (i.e., charging/standby (1) and discharging/standby (0)).When the scheduled battery powers P ch,t s,d and P dch,t s,d are zero, standby is in play.
where P ch max and P dch max are the maximum charge and discharge powers of the battery, respectively.
In addition, u t is a binary variable preventing simultaneous battery charging and discharging.Another limitation should be satisfied during the operation of the proposed scheduling to meet the scheduling requirements of the next dispatch day and safe operation of the battery [41].Equation (11) means that the energy stored at the last time of scheduling should be set to its initial value.
where SOC 23 s,d is the scheduled battery SOC at 23:00 p.m.; SOC init is the initial value of the SOC.

Hour-Ahead Scheduling Stage
The objective function is to minimize the discrepancies between the day-ahead scheduled utility power profiles and the hour-ahead scheduled utility powers, expressed as the first term of Equation (12).Due to natural discharge of the SOC, the actual SOC value could exceed the upper or lower limit.Thus, the second and third terms are added to prevent this situation.
where P u,t s,h is the scheduled utility power at time t to be determined in the second stage.Moreover, SOC t s,h represents the scheduled SOC at time t; M 3,t is an additional decision variable, which is the smaller of the 0 and (SOC t s,h − SOC min ) at time t.Furthermore, M 5,t is another decision variable, which Because the three terms of the objective function are all nonlinear, they must be linearized for the MILP problem.The first term includes an absolute value, which can be changed to a linear form by adding auxiliary variables covering positive and negative deviations.Both the second and third term can be linearized using Equations ( 15)-( 18) in a manner similar to that shown in the first stage, which is also based on Appendix A.
where M 4,t is a continuous variable at time t.Moreover W 2,t and W 3,t are binary decision variables at time t.In addition, r 3 , r 4 , r 5 and r 6 are additional parameters.All decision variables are required for piecewise linearization of the penalty functions M 3,t and M 5,t .
The constraints are similar to those imposed on the day-ahead scheduling, except that the SOC limit constraint is considered in the objective function.Note that Equation ( 23) is appropriate for continuous operations, as is Equation (11), which means that the energy stores of the last frame (running at the final time step) should be equal to the initial values.
SOC s,h t = SOC s,h t−1 + ((η ch P s,h ch,t − P s,h dch,t /η dch )∆t)/EC max ∀t ∈ T , (20) SOC s,h 23_55min = SOC init (23) where P j,i,t s,h and P i,k,t s,h is the hour-ahead scheduled active power that flows from jth bus to ith and from ith bus to k th , respectively, at time t.Moreover, P Li,t f,h is the hour-ahead forecast load demand power at ith bus at time t, and P PV,t f,h is the forecast PV generation power at time t.In addition, P ch,t s,h and P dch,t s,h are the hour-ahead scheduled battery charge and discharge powers at time t.In ( 23),

SOC 23_55min
s,h is the scheduled battery SOC at 23:55 p.m.
A surcharging system is considered for the case where the maximum demand power of the 15-min average exceeds the contracted power to stabilize the supply.A constraint in Equation (24) represents this.

Flowchart of the Proposed Two-Stage Scheduling
Figure 4 summarizes the proposed two-stage scheduling for 1 day.This section presents a detailed flowchart.
Step (1) Initialize the time windows TW and TW as 24 h and 1 h, respectively, and the time intervals ∆t and ∆t as 1 h and 5 min, respectively.Then, set the current time t = N + k = 0.
Step (2) Obtain input information on the P Li,t uses an open-source MILP solver, CBC [42]; an open-source modeling tool PuLP ver.1.4.6 [43] in the Python environment.Additionally, scheduling was performed using actual data from the forecasting module and the DB in the appropriate time frame.Table 3 lists the technical parameters of the ESS used.The minimum and maximum SOC values are divided into two types: hard limits SOC h_lim and soft limits SOC s_lim .The values of SOC s_lim are applied to define the SOC limits of the first stage and the SOC penalty functions of the second stage, considering additional reserve in the battery energy capacity.Moreover, the values SOC h_lim are the upper and lower bounds of the second-stage SOC values.The safe, reliable operation of the campus MG is of utmost importance, which could be successfully achieved with the reserve margins of the ESS.SOC have a significant influence on the reserve power of the ESSs [44].Thus, an additional 5% reserve margin was taken into account in the first stage scheduling, considering that the maximum and minimum SOC levels were set to be 20% and 80%, respectively.In other words, the SOC level could vary between 25% and 75%.The charge and discharge efficiencies of the battery were set to 80%.Table 4 lists the TOU rates for three periods: off-peak (23:00 p.m. ~09:00 a.m.), mid-peak (09:00 a.m.~10:00 a.m., 12:00 p.m. ~13:00 p.m., 17:00 p.m. ~23:00 p.m.), and on-peak (10:00 a.m.~12:00 p.m., 13:00 p.m. ~17:00 p.m.).The contracted power was assumed to be 2000 kW.It is also assumed that the selling price for the exported power is assumed to be equal to the buying price for the imported power.

Day-Ahead Scheduling
Day-ahead scheduling is performed before the day.The scheduling results in terms of utility power from the main grid and battery charge/discharge powers are shown in Figure 6a, in which the red line indicates the scheduled battery power, the green line the utility power, and the purple line the net load (the difference between the load demand and the PV generation power).The scheduling results of each time step are maintained for 1 h.More utility power is imported when the TOU is low and less when the TOU is high.Also, the ESS is charged when utility power is inexpensive and discharged when it is expensive, to minimize operation costs.The maximum utility power is imported from 08:00 to 09:00 (28.25 kWh per 15 min).The utility power remains within the contracted power because the objective function imposes a large deviation penalty for exceeding the contracted power.However, battery charge/discharge was minimal because the efficiency was assumed to be 80% and a 5% SOC safety margin was applied.The computation time required for a solution was 27.97 s, and the electricity cost was $97.59 during the day.

Hour-Ahead Scheduling
Hour-ahead scheduling makes decision the utility and battery powers every 5 min to minimize deviations between the day-ahead and hour-ahead scheduled utility powers.The results are shown in Figure 6b, in which the colors have the same meanings as in Figure 6a.The total objective value of hour-ahead scheduling is zero, which means that the scheduled utility power of hour-ahead scheduling and that of day-ahead scheduling overlap perfectly.Compared to the day-ahead ESS scheduling, where the ESS is on standby most of the time, the battery is not on standby in the second scheduling stage.The ESS is used to compensate for forecast errors caused by uncertainty and variations in load demand and PV generation.The battery power changes frequently to ensure that the utility power is equal to that of the day before.The first time interval of hour-ahead scheduling is 6.69 s on average.

Day-Ahead Scheduling
Day-ahead scheduling is performed before the day.The scheduling results in terms of utility power from the main grid and battery charge/discharge powers are shown in Figure 6a, in which the red line indicates the scheduled battery power, the green line the utility power, and the purple line the net load (the difference between the load demand and the PV generation power).The scheduling results of each time step are maintained for 1 h.More utility power is imported when the TOU is low and less when the TOU is high.Also, the ESS is charged when utility power is inexpensive and discharged when it is expensive, to minimize operation costs.The maximum utility power is imported from 08:00 to 09:00 (28.25 kWh per 15 min).The utility power remains within the contracted power because the objective function imposes a large deviation penalty for exceeding the contracted power.However, battery charge/discharge was minimal because the efficiency was assumed to be 80% and a 5% SOC safety margin was applied.The computation time required for a solution was 27.97 s, and the electricity cost was $97.59 during the day.

Hour-Ahead Scheduling
Hour-ahead scheduling makes decision the utility and battery powers every 5 min to minimize deviations between the day-ahead and hour-ahead scheduled utility powers.The results are shown in Figure 6b, in which the colors have the same meanings as in Figure 6a.The total objective value of hour-ahead scheduling is zero, which means that the scheduled utility power of hour-ahead scheduling and that of day-ahead scheduling overlap perfectly.Compared to the day-ahead ESS scheduling, where the ESS is on standby most of the time, the battery is not on standby in the second scheduling stage.The ESS is used to compensate for forecast errors caused by uncertainty and variations in load demand and PV generation.The battery power changes frequently to ensure that the utility power is equal to that of the day before.The first time interval of hour-ahead scheduling is 6.69 s on average.

Performance Analysis
In this section, we analyze the performances of open-source solvers and DER capacities at the simulation level.The battery charge and discharge efficiency were both set to 85 %.The other values were unchanged.All simulations were performed using an AMD Ryzen 7 model 1700 eight-core 3-GHz processor with 32.0 GB of memory.

Open-Source Solver Performance
CPLEX is widely used to solve MILP problems.However, the optimization module of our campus MG module is completely open-source.To analyze the performance of the open-source solver, we compared CPLEX and CBC.Both are established in Python.We assumed that the forecast error range between day-ahead and 2-h-ahead would be ±5 %, thus relatively small.Table 5 compares the optimal values and required computation times of two-stage scheduling.The computation times required by the two solvers for day-ahead scheduling were 11.06 s and 0.29 s, respectively.We also compared the average computation times required for the first-time interval of hour-ahead scheduling, because it takes the longest time in the second stage.The times were 3.25s and 0.16 s, respectively.In other words, CBC requires far more computation time than CPLEX for both stages.Figure 7 presents the scheduling imported utility power, battery power, and SOC profiles calculated by the two MILP solvers.This shows that the campus MG worked safely with the reserve margin.The optimal value derived by CBC is exactly that derived by CPLEX for both day-ahead and hour-ahead scheduling.The simulation results thus show that CBC is acceptable for practical implementation in small-scale MGs even though CPLEX affords better performance in terms of computation time.

Performance Analysis
In this section, we analyze the performances of open-source solvers and DER capacities at the simulation level.The battery charge and discharge efficiency were both set to 85 %.The other values were unchanged.All simulations were performed using an AMD Ryzen 7 model 1700 eight-core 3-GHz processor with 32.0 GB of memory.

Open-Source Solver Performance
CPLEX is widely used to solve MILP problems.However, the optimization module of our campus MG module is completely open-source.To analyze the performance of the open-source solver, we compared CPLEX and CBC.Both are established in Python.We assumed that the forecast error range between day-ahead and 2-h-ahead would be ±5%, thus relatively small.Table 5 compares the optimal values and required computation times of two-stage scheduling.The computation times required by the two solvers for day-ahead scheduling were 11.06 s and 0.29 s, respectively.We also compared the average computation times required for the first-time interval of hour-ahead scheduling, because it takes the longest time in the second stage.The times were 3.25s and 0.16 s, respectively.In other words, CBC requires far more computation time than CPLEX for both stages.Figure 7 presents the scheduling imported utility power, battery power, and SOC profiles calculated by the two MILP solvers.This shows that the campus MG worked safely with the reserve margin.The optimal value derived by CBC is exactly that derived by CPLEX for both day-ahead and hour-ahead scheduling.The simulation results thus show that CBC is acceptable for practical implementation in small-scale MGs even though CPLEX affords better performance in terms of computation time.

DER Capacity Performance
In Section 4.2.2, we compared the operation costs of the first stage as the PV and battery capacities changed.Battery capacity was changed over the range of 100-400 kWh.The PV capacity varied from 0-300 W. Figure 8 presents the MG operating costs within this range.It is assumed that

DER Capacity Performance
In Section 4.2.2, we compared the operation costs of the first stage as the PV and battery capacities changed.Battery capacity was changed over the range of 100-400 kWh.The PV capacity varied from 0-300 W. Figure 8 presents the MG operating costs within this range.It is assumed that the extent of PV generation at each time is proportional to the PV capacity.The operation costs decreased from about $117.80 to about $49.82 as the PV and battery capacities increased.In other words, the operation costs of the MG are inversely proportional to the PV and battery capacities.However, the PV system affects operating costs more than the battery does.Our findings also demonstrate that our proposed two-stage scheduling algorithm can handle various PV and battery capacities.words, the operation costs of the MG are inversely proportional to the PV and battery capacities.However, the PV system affects operating costs more than the battery does.Our findings also demonstrate that our proposed two-stage scheduling algorithm can handle various PV and battery capacities.

Conclusions
In this paper, we proposed optimal two-stage scheduling of a MG, considering forecasting errors.It consists of two stages: day-ahead and hour-ahead scheduling.The first stage is performed before the day to minimize operation costs.The second minimizes deviations from the utility powers scheduled by the first stage.The proposed optimal operation system was formulated as an MILP problem and solved by CBC.The application of the proposed method to a real case (a campus MG) proved that our system effectively compensated for forecasting errors and was applicable in practice.Simulations revealed that our proposed scheduling method is also valid during implementations in which the battery is inactivated because of safety concerns.The simulation case studies show that an open-source solver can be used to control small-scale MGs even though the performance is lower than that of a commercial solver; our proposed algorithm is applicable over a wide range of PV and battery capacities.
Further work is required to increase the efficiency of our proposed two-stage scheduling for the campus MG.The error rate of the forecasting module should be decreased, because the economic savings imparted by scheduling improve as the accuracy of forecast data improves.Additionally, our proposed two-stage scheduling algorithm should be implemented using various open-source solvers (e.g., GNU linear programming kit (GLPK), Solving constraint integer programs (SCIP)) or other open-source modeling environments such as Pyomo of Python or JuMP of Julia.We will also measure the required computation times and derive optimal values for larger scale operations in case the campus MG is extended in future.

Conclusions
In this paper, we proposed optimal two-stage scheduling of a MG, considering forecasting errors.It consists of two stages: day-ahead and hour-ahead scheduling.The first stage is performed before the day to minimize operation costs.The second minimizes deviations from the utility powers scheduled by the first stage.The proposed optimal operation system was formulated as an MILP problem and solved by CBC.The application of the proposed method to a real case (a campus MG) proved that our system effectively compensated for forecasting errors and was applicable in practice.Simulations revealed that our proposed scheduling method is also valid during implementations in which the battery is inactivated because of safety concerns.The simulation case studies show that an open-source solver can be used to control small-scale MGs even though the performance is lower than that of a commercial solver; our proposed algorithm is applicable over a wide range of PV and battery capacities.
Further work is required to increase the efficiency of our proposed two-stage scheduling for the campus MG.The error rate of the forecasting module should be decreased, because the economic savings imparted by scheduling improve as the accuracy of forecast data improves.Additionally, our proposed two-stage scheduling algorithm should be implemented using various open-source solvers (e.g., GNU linear programming kit (GLPK), Solving constraint integer programs (SCIP)) or other open-source modeling environments such as Pyomo of Python or JuMP of Julia.We will also measure the required computation times and derive optimal values for larger scale operations in case the campus MG is extended in future.
Figure 1 presents the architecture of the campus MG.The MG ensures uninterrupted operation of critical loads in the library (S-01).As shown in the figure, the MG is grid-connected and includes PV and ESS.The rated PV power of the panels (300 modules) is 100 kW and the panels are installed on the roof of the outdoor parking lot.A total of 250 kWh of lithium-ion batteries (four racks) and a MEMS operating center are situated on the first floor of the library.

Figure 1
Figure 1 presents the architecture of the campus MG.The MG ensures uninterrupted operation of critical loads in the library (S-01).As shown in the figure, the MG is grid-connected and includes PV and ESS.The rated PV power of the panels (300 modules) is 100 kW and the panels are installed on the roof of the outdoor parking lot.A total of 250 kWh of lithium-ion batteries (four racks) and a MEMS operating center are situated on the first floor of the library.

Figure 1 .
Figure 1.Architecture of the implemented IoT-based campus MG.

Figure 1 .
Figure 1.Architecture of the implemented IoT-based campus MG.

Figure 2 .
Figure 2. Configuration of the implemented campus MG.
Figure 3 presents the time framework of our proposed scheduling for the campus MG, which includes dayahead scheduling and hour-ahead scheduling, especially at a typical time t = N (hour) for Δt where N ∈ {0, 1, •••, 23}.Also, both stages are formulated as MILP problems, the objective functions of which include penalty terms.1. Day-ahead scheduling stage: This stage is performed only once before the day to determine the optimal scheduling for the next day.The time window (TW) is 24 h, and the time interval (Δt) is 1 h.The scheduled profiles do not change with Δt.

Figure 2 .
Figure 2. Configuration of the implemented campus MG.

Figure 3 .
Figure 3.Time framework for the proposed two-stage scheduling.

Figure 3 .
Figure 3.Time framework for the proposed two-stage scheduling.
of the 0 and (SOC t s,h − SOC max ) at time t.In addition, θ 2 and θ 3 are penalty factors and T is the time set of the second stage (i.e., T = [5, 10, • • • , 1435] for the unit time interval of 5 min).

Figure 5 presents
Figure 5 presents HMI screens showing the forecasted and actual loads and the PV generation profiles on the day before and during a typical winter day.The black line represents the day-ahead data for the first stage, the blue line the 2-h-ago data for second stage scheduling, the red line the actual values, and the green histogram the difference between the 2-h-ahead forecast and the actual values.All profiles of Section 4.1 are shown in the HMI at 15-min intervals (kWh).Note that the zero values of the red line at about 17.50 and the blue line at about 19.25 do not indicate faults, rather simply that no data are yet available.

Figure 5 .
Figure 5. HMI screens of the forecasted and actual profiles before and during a typical winter day (a) load; (b) PV generation.

Figure 5 .
Figure 5. HMI screens of the forecasted and actual profiles before and during a typical winter day (a) load; (b) PV generation.

Figure 6 .
Figure 6.HMI screens showing the scheduled battery power, utility power, and net load of (a) dayahead scheduling; (b) hour-ahead scheduling.

Figure 6 .
Figure 6.HMI screens showing the scheduled battery power, utility power, and net load of (a) day-ahead scheduling; (b) hour-ahead scheduling.

1Figure 7 .
Figure 7.The two-stage scheduling profiles created by the CPLEX and CBC MILP solvers.(a) Imported utility power; (b) battery power; (c) SOC.

Figure 7 .
Figure 7.The two-stage scheduling profiles created by the CPLEX and CBC MILP solvers.(a) Imported utility power; (b) battery power; (c) SOC.

Figure 8 .
Figure 8. MG operating costs by changes in PV and battery capacities.

Figure 8 .
Figure 8. MG operating costs by changes in PV and battery capacities.

Table 1 .
Summary of previous studies on the optimal scheduling using ESS in MG.

Table 2 .
Features of P-type and H-type IoT sensors.

Table 5 .
Comparison results of CBC and CPLEX.
1First time interval of the hour-ahead scheduling.

Table 5 .
Comparison results of CBC and CPLEX.

Table A1 .
Parameter values for the piecewise linearization of the penalty functions.