Real Time Energy Storage Sharing With Load Scheduling: A Lyapunov-Based Approach

This paper studies energy storage sharing in a grid-connected residential microgrid, where a group of households with controllable loads and renewable generations cooperatively shares an energy storage. By exploiting delay tolerance of elastic loads, we develop a joint real time storage sharing and load management system that takes into consideration the operational constraints of the shared energy storage coupled with the time-varying load demands and stochastic renewable generations of all households, with the aim of minimizing the long term time-averaged energy costs of the households without reducing energy consumption. A Lyapunov-based online battery sharing control algorithm is designed to jointly optimize energy consumption, load scheduling and energy charging/discharging actions of individual households only based on current system states. The proposed online sharing algorithm enables the households to optimally utilize the shared battery and reschedule their delay tolerant loads in a distributed but coordinated fashion, while satisfying the time-varying energy consumption preference of each household. Numerical simulation results demonstrate that the low-complexity joint storage sharing and load scheduling algorithm serves the load demands of each household with a lower delay at a relatively low cost while facilitating a fair utilization of the shared energy among the households in terms of their energy contributions.


I. INTRODUCTION
The fast-growing electricity demand coupled with environmental concerns about traditional fossil-fuel based electricity generation has motivated the integration of renewable energy systems, e.g., solar photovoltaics (PVs). However, incorporation of such inherently intermittent and stochastic renewable energy resources poses significant challenges in managing a stable and efficient energy supply. Energy storage is seen as an effective solution [1] to increasing dynamics in power systems due to growing electricity demand and renewable integration. Energy storage, as an energy buffer, offers great flexibility in managing and optimally utilizing the intermittent renewable energy by decoupling the time of renewable generation and consumption. Integration of energy storage has multi-faceted benefits for different players. On the power grid operator side, energy storage improves stability, sustainability, and reliability of renewable energy sources [2] and power systems [3]. On the user side, reduced electricity The associate editor coordinating the review of this manuscript and approving it for publication was Mahdi Pourakbari Kasmaei . cost and lessened interruptions can be achieved by storing excess renewable energy and cheaper energy for later use in times of renewable generation shortage and higher electricity price.
An extensive effort has been made towards the understanding of the potential of energy storage for residential energy management [4] in reducing the impact of intermittent renewable generation and lowering the electricity cost. Storage management combined with load management would improve energy utilization efficiency. Residential load management usually aims to balance electric power supply and reduce electricity expenditures through reducing consumption and/or shifting consumption. In contrast the former, the latter takes advantage of the variation of electricity prices to schedule flexible loads across time without causing any load curtailment. From the user's perspective, energy storage enables load shifting to optimizes energy costs without compromising customers' comfort. Energy management in microgrids with renewable integration has been studied from the perspective of load shifting combined with energy storage. Various demand response approaches have been proposed to schedule the electricity loads in response to the variation of renewable energy generations and/or electricity prices [5]- [10]. Most studies assume that one entity owns an energy storage system (ESS) and uses it solely.
The concept of sharing an ESS among users has received increasing attention recently. In such an energy storage sharing system, users with non-overlapping power consumption patterns benefit from pooling their excess renewable energy and/or cheaper energy together. Nevertheless, given the complicated dynamics of the sharing system, sharing an ESS creates challenges in demand response and energy storage control. There have been previous works developing various mechanisms and approaches to provide cost savings through an ESS shared among multiple customers in a community or between customers and a system operator [11]- [27]. Assuming that the load demands and renewable energy generations are known ahead of time, most of these studies focus on the day-ahead energy storage allocation to accommodate the energy loads and renewable generations without considering load management or only considering energy consumption reduction. In practice, with random and arbitrary changes in load demands and renewable energy generations, adaptive response to the unknown dynamics of the system inputs in real-time is required for such a time-varying system. Lyapunov optimization theory [28] has been recently adopted to develop online energy management algorithms involving demand side management mechanisms for microgrids with renewable energy resources combined with ESSs, without requiring any a priori statistical knowledge of the underlying stochastic processes [29]- [33]. Most of the studies primarily consider the scenario where an ESS is owned and controlled solely by one entity, and focus on power balancing of a power grid through coordinating a group of distributed ESSs, or electricity cost minimizing through charging/discharging as well as energy trading between the users and a power grid or among users.
In our previous work [34], a Lyapunov-based real-time battery sharing control algorithm was proposed to optimally coordinate the utilization of a shared battery among multiple households to reduce their energy consumption costs. Small portions of elastic loads are shed in response to energy supply conditions to save costs taking into consideration the user conform levels. The proposed optimal control algorithm allows households to balance cost saving with the discomfort caused by load shedding. In this paper, we extend the previous work to incorporate load rescheduling by exploiting time flexibility or delay tolerance of elastic loads. Elastic loads are delay-tolerant in the sense that they can be postponed and severed with some delay. The delayable loads combined with energy storage give more opportunities to reduce the energy cost. Nevertheless, developing an effective joint energy storage sharing, energy consumption management and load rescheduling solution faces challenges. First, storage control decisions are coupled over time due to the finite capacity of the battery. Second, load rescheduling decisions affect the energy consumption and storage decisions and vice versa. Given that load management and storage control decisions from multiple households are correlated over time and with each other, dynamically coordinating energy storage combined with load rescheduling among a group of households is especially challenging.
There have been attempts, such as [5]- [7], employing the Lyapunov optimization techniques in studying joint optimization of storage control and load shifting, where all load demands or all elastic load demands are considered to be scheduled. Different from these works, in this paper, considering discomfort caused by energy consumption deviation, only a portion of elastic loads is rescheduled and the amount of the rescheduled loads, which varies over time depending on energy consumption preferences of the households and dynamics of the system, is to be determined along with charging/discharging and energy consumption decisions on a real time basis. This makes the joint storage sharing and load scheduling optimization problem more complicated.
In this paper, we study the specific problem of multiple households with delay-tolerate loads sharing an ESS and design an online control algorithm for such an ESS sharing system. Based on an extension of the battery sharing framework presented in our previous work [34], the design of such an energy management system aims to save energy cost by managing and rescheduling energy consumption, instead of reducing energy consumption. The main contributions of this paper are as follows: • An online control strategy is developed for the ESS sharing system in the presence of delay-tolerate loads to tackle the unknown dynamics of the system inputs.
Based on an extension of the battery sharing framework presented in our previous work [34], a Lyapunov-based ESS sharing management system is designed to save energy cost by integrating energy consumption management, load scheduling and energy storage sharing, without requiring any statistical knowledge of the load demands and renewable generations of individual households.
• Taking into consideration the charging/discharging requests and energy contributions to the shared ESS from individual households, a distributed implementation of the proposed online sharing control strategy, in which each household determines its optimal energy charging/discharging and load management decisions locally, is proposed to coordinate the utilization of the ESS among the households in a distributed and fair manner.
The rest of the paper is organized as follows: The related works are briefly discussed in Section II. A joint load management and ESS sharing system model is presented in Section III. The joint load management and energy storage optimization problem in this ESS sharing system is formulated in Section IV. In Section V, based on the Lyapunov optimization theory, a distributed online sharing control algorithm is designed to approximately solve the optimization VOLUME 9, 2021 problem and its performance is analyzed. Section VI presents simulation evaluations. Finally, concluding remarks are provided in Section VII.

II. LITERATURE REVIEW AND BACKGROUND
Energy storage sharing mechanisms and approaches that have been proposed for residential energy management mainly consider two scenarios: (a) distributed ESSs scenario, where multiple users own individual ESSs and share their stored energy with each other; (b) a shared ESS scenario, where a group of users operate a common ESS together. Existing studies with distributed ESSs generally focus on optimal coordination among distributed storage resources belonging to individual users. For instance, a decentralized control scheme was proposed in [35] to allow households with solar systems in an off-grid community to pool power together to fulfill communal load demands. The proposed modified I-V droop method controls power contributions from individual households such that each household contributes according to the capacity and the state of charge of its battery. To effectively coordinate distributed storage resources, many recent studies have adopted the concept of peer-to-peer (P2P) trading to develop optimization models to determine optimal schedules of ESSs and trading decisions, such as [36]- [38]. The authors in [38] investigated the optimal ESS operation and sizing problem in a P2P energy trading network under two different ESS ownership structures: user owned structure and a third party energy sharing provider (ESP) owned structure. The comparison of economic benefit between the two structures shows that the ESP owned model achieves a smaller energy cost saving owing to the fact that the benefits are split between the users and the ESP, but requires less investment on a smaller ESS, compared to the user owned ESS structure.
Relevant to this paper, studies with a shared ESS mainly focus on optimal allocation of the shared ESS among multiple users. Many studies model the interactions among multiple users sharing an ESS as a non-cooperative game and develop pricing-based decision-making strategies to determine day-ahead optimal ESS capacity allocation and charging/discharging schedule. The authors proposed an ESS sharing control strategy combining ESS capacity trading and decentralized ESS controlling for multiple users in [23]. ESS capacity trading and operation is modeled as a noncooperative static game, where each user decides its capacity trading and charging/discharging scheduling a day ahead to minimize energy operation cost, based on its own energy demand, the total energy demand of others and the total ESS capacity used by other. The authors in [24] studied an energy sharing problem, where consumers within an apartment building share a distributed energy resource (DER) consisting of a renewable generator and an ESS, and developed a Stackelberg game-based discriminatory auction model for energy pricing and allocation. In the bi-level auction based allocation method, the DER owner first determines the energy prices based on consumers demand curves, the consumers then decide accordingly their energy consumption. An energy trading based ESS sharing approach for load management of a Neighborhood Area Network (NAN) was proposed in [25], where energy users with PV panels trade their surplus PV energy with a community storage system (CES) and the main grid. Adopting a dynamic non-cooperative repeated game, the decentralized ESS sharing approach allows energy users individually decide their optimal energy trading bids along with storage schedules for the next day based on their load demand and PV power generation forecasts. The authors in [26] studied an energy-sharing network and introduced an energy-sharing provider (ESP) with an ESS to facilitate energy sharing among PV prosumers. A centralized day-head energy sharing approach was proposed, where the ESP first decides the schedule of the shared ESS for the next day via stochastic programming based on individual prosumers' load demand and PV generation forecasts, then sets real-time prices for the prosumers to decide their energy consumption accordingly via a Stackelberg game-based model. A storage virtualization concept is introduced in [22], where a central storage unit owned by an aggregator is virtualized into separable virtual capacities which are sold to users. The authors proposed a virtual storage sharing framework, in which the aggregator determines the storage size and virtual capacity pricing decision for the whole investment period, and each user decides its virtual capacity and storage schedule based on the day-head prediction of its load and renewable generation in each operational period.
There have been several studies developing ESS sharing control strategies to allocate the shared storage resource taking energy contributions from individual users into consideration. In [21], the authors proposed a centralized reputation-based energy management system (EMS) that runs a day-ahead optimization problem, to schedule appliance power consumption of individual households and allocate the available energy in the shared battery based on the renewable energy that individual households have shared. The dayahead optimization problem requires the EMS to know all the households' energy information including information about appliances to be scheduled and PV generation. In [27], assuming load demands and renewable energy generations of individual consumers are known, a credit-based energy management strategy was proposed to schedule an shared ESS in a NAN, where multiple consumers share an ESS owned by a load service entity (LSE) through energy trading in a dynamic pricing system. In the proposed method, energy credits are provided to each consumer for the excess renewable energy it provides to the NAN and the grid. A credit limit for each customer is predefined based on its distributed generation capacity. These credits are then used during predefined peak periods with higher energy prices, which is equivalent to a virtual shift of the excess renewable energy to the predefined peak periods.
The primary assumptions in most of these prior studies is that load demands and renewable energy generations are perfectly predicted or known ahead of time. Different from the prior works, this study investigates the real-time ESS sharing problem and proposes an online ESS sharing control strategy that is able to adaptively respond to dynamic changes of the system. Moreover, storage sharing management and load scheduling are jointly considered to further explore the potential of the shared ESS in cost saving.

III. SYSTEM MODEL
In this study, we consider a smart community of a group of households I = {1, 2, . . . , I } sharing an energy storage battery via an online energy storage sharing management (OESSM) system, which operates in slotted time t ∈ {0, 1, . . . , T − 1}. As in our previous study [34], the households operate the shared battery via a central coordinator, which manages the shared battery to ensure its operational constraints are satisfied. Each household has an on-site solar PV generator and can store energy harvested from its solar generator or purchased from the main grid (MG) into the shared battery. The time-varying load demands of the households can be supplied by their individual solar generators, the MG and/or the shared battery.

A. HOUSEHOLD ENERGY SUPPLY AND DEMAND
The loads of each household consist of the following two categories: 1. inelastic loads, which cannot be shed or shifted over time; 2. elastic loads, which are flexible in a sense that they can be flexibly scheduled or curtailed over time, since the operation times and the amounts of energy usage of such elastic loads can be adjusted. There is great potential to exploit the inherent flexibility of elastic loads in cost saving. In this work, we consider a load management mechanism, where elastic loads that tolerate delay can be rescheduled and served later in response to supply conditions so as to reduce electricity costs while maintaining customer comfort. Note that, all power quantities are in the unit of energy per time slot in this paper.
For household i, denote the amount of energy used to serve the current load in time slot t by d 1,i (t), which is bounded by: where D i (t) is the most preferred load demand of household i in time slot t, including inelastic and elastic load demand requests, and D i (t) is the inelastic load demand in time slot t that must be satisfied. Note that both D i (t) and D i (t) are decided by household i based on its physical constraints and willingness to control its elastic loads in time slot t.
To control the quality-of-service (QoS) [32], [39], the longterm time-averaged load rescheduling ratio, for the households, as in [31], the ratio of the rescheduled or delayed elastic loads to the elastic loads is upper bounded, which is expressed by where is the elastic load demand that can be potentially rescheduled in time slot t, and β i ∈ (0, 1] is a QoS control threshold reflecting the tolerance of household i to the energy consumption rescheduling: the smaller the value of β i , the tighter the QoS control. Load rescheduling used for cost saving may cause discomfort to the households. In time slot t, when the energy consumption d 1,i (t) deviates from the preferred load demand D i (t), the discomfort experienced by household i is represented by the following discomfort cost function: where the weighted coefficient α i (t) indicates the sensitivity of household i towards the energy consumption deviation indicates that household i is more sensitive towards the energy consumption deviation. Hence, α i (t) could vary over time in a stochastic manner. Note that both β i and α i (t) are decided by household i based on its energy consumption preference. As in [5], the load request that is not satisfied in time slot t, D i (t) − d 1,i (t), is buffered in a queue Q f ,i and served later. Let d 2,i (t) denote the amount of energy used to serve the delayed elastic loads in time slot t. Then the queue backlog Q f ,i evolves as follows: The service of the rescheduled loads cannot be delayed for an arbitrarily long time. In other words, the average delay of the rescheduled loads in the queue should be finite. This can be expressed as follows: For the convenience of expression, we let D i (t) denote the serving energy of household i in time slot t and In each time slot, the households can purchase energy from the MG at the unit price p(t), p min ≤ p(t) ≤ p max , which is time-varying, to supply its load or/and store into the shared battery to take advantage of price variations. Let g l,i (t) denote the amount of energy purchased by household i in time slot t to supply D i (t) and g s,i (t) denote the amount of energy purchased by household i in time slot t to store into the shared battery, respectively. Thus, the energy cost incurred in time slot t is given by Denote the amount of energy charged and discharged by household i in time slot t by g ch,i (t) and g dis,i (t), respectively, and the time-varying PV energy generation of household i in time slot t by g pv,i (t). We assume a priority of using the PV energy generation g pv,i (t) to directly supply D i (t). Then the excess PV energy, if any, will be stored into the shared battery. When D i (t) ≤ g pv,i (t), i.e., energy surplus, the energy VOLUME 9, 2021 that household i stores into the shared battery in time slot t is given by Note that, due to the finite storage capacity, a portion of the excess PV energy will be curtailed if there is not enough storage space. When D i (t) > g pv,i (t), i.e., energy deficit, the residual, D i (t)−g pv,i (t), can be served with the energy purchased from the MG, g l,i (t) and/or the energy discharged from the shared battery, g dis,i (t). A balance between purchasing energy from the MG and discharging energy from the battery must be struck under the following feasibility condition: Note that, g dis,i (t) = 0 in case of energy surplus while g ch,i (t) = 0 in case of energy deficit.

B. SHARED ENERGY STORAGE
In practice, energy conversion losses occur during the charging and discharging processes. Denote s(t) as the energy state of the battery, i.e., state of charge (SOC), at the beginning of time slot t, which evolves as follows: where η ch ∈ (0, 1] and η dis ∈ [1, ∞) are the charging and discharging efficiency coefficient, respectively, and b i (t) is the effective charging and discharging amount in time slot t. Due to limitation imposed by the charging and discharging circuits, the amount of energy that can be charged/discharged into/from the shred battery is upper bounded. The maximum charging and discharging rate of the battery are denoted by R ch and R dis , respectively. We have Charging a battery near its capacity or discharging it close to zero will significantly reduce battery lifetime [40]. Thus, the SOC of the shared battery in time slot t is bounded by where S min and S max are the preferred energy lower and upper bounds respectively.

IV. ONLINE BATTERY SHARING ALGORITHM A. PROBLEM STATEMENT AND FORMULATION
The objective of the OESSM system is to minimize the longterm time-averaged energy consumption costs of all households while maintaining the discomfort experienced by each household within an acceptable level in real-time, subject to the time varying PV energy generations and load demand requests of the households along with the operational constraints of the shared battery, by jointly managing energy consumption, load rescheduling, energy purchasing and energy charging/discharging actions of all households. For the sake of ease of reading, the system state X(t) and the control vector Y(t) in time slot t are defined, respectively, by: where ∀i is the load demand request vector and g pv (t) [g pv,i (t)] ∀i is the PV generation vector; and ∀i are the energy purchasing vectors for battery charging and load serving respectively, g ch (t) [g ch,i (t)] ∀i and g dis (t) [g dis,i (t)] ∀i are the battery charging and discharging vectors respectively, d 1 ∀i are the serving energy vectors for current loads and rescheduled loads respectively.
In each time slot, given the current system state X(t), Y(t) is chosen to minimize the energy costs of the households, which are comprised of the costs of energy purchases and the discomfort costs of load rescheduling, over a long-term Tslot period, while guaranteeing the QoS demanded by each household and finite average delays for the delay tolerant loads. Therefore, the energy management problem can be formulated as the following stochastic control optimization problem, called P1, P1 : min (1)(2)(5)(7)(8)(11)(10), where C ToT (t) = i∈I C MG,i (t) + i∈I C COM ,i (t) and E{·} is taken with respect to X(t). Taking into account the system dynamics, the stochastic optimization problem P1 seeks control decisions for the whole process. However, control actions Y(t) that are correlated over time make P1 a particularly challenging problem to solve.

B. PROBLEM REFORMULATION BASED ON LYAPUNOV OPTIMIZATION
The time-coupling optimization problem P1 can be solved using approaches based on Dynamic Programming [41], provided that the statistical information of the random variables of X(t) are known for forecasting future information, which might be complex in practice. In this study, we take an alternate approach based on the Lyapunov optimization theory [28], which employs the concept of one-slot lookahead queue stability to handle the time-coupling constraints through successive problem relaxation and transformation and determine the control vector Y(t) in each time slot based only on the current system state X(t), without requiring any statistical knowledge of the PV energy generations and load demand requests. In general, for complex dynamic systems, time-averaged constraints are transformed into queue stability constraints and simple real-time algorithms can be constructed based on the virtual queues to achieve system optimization using the Lyapunov optimization theory. However, the standard Lyapunov optimization techniques cannot be applied to solve P1 directly due to the hard constraint on the per time slot charging and discharging decisions imposed by the timecoupling dynamics of s(t) over time in (9) combined with the battery capacity constraint in (11). To avoid such timecoupling, the constraint (11) can be relaxed to the following soft constraint: Instead of bounding the energy state, s(t), in each time slot, (15) maintains the stability of the mean rate of the effective charging and discharging amounts, b i (t), in the whole process. The derivation of (15) follows the framework of Lyapunov optimization [28] and is given in our previous work [34]. Accordingly, P1 is relaxed to the following problem: The relaxation transformation removes the dependency of per time slot charging/discharging decisions on the battery state, so that the standard Lyapunov optimization techniques can be applied to tackle the relaxed problem P2. This relaxation technique was first introduced in [6] and then widely adopted in recent studies on energy storage management to accommodate time-coupling constraints. However, since the timecoupling constraint (11) is replaced with the time-average constraint (15), the solution to P2 might not be feasible to P1.
In the next section, we present an online control algorithm to solve P2 while guaranteeing all constraints of P1 are satisfied. It will be shown in Section IV-D that, under the proposed online algorithm, the solution to P2 meets the constraint (11). Thus, the optimal solution to P2 is also feasible to P1.

C. LYAPUNOV-BASED ONLINE BATTERY SHARING CONTROL ALGORITHM
In this section, virtual queues are defined to transform the time-averaged constraints in P2 into constraints with queue stability. A Lyapunov-based online battery sharing control algorithm (LOBSC) is then presented to approximately solve P2 and a real-time solution is provided only based on the current system state for each time slot.

1) VIRTUAL QUEUE DESIGN
• Battery Queue K b (t) = s(t) − θ accumulates the charging and discharging amounts, where θ is a perturbation parameter that can be designed to ensure the energy state constraint in (11) is satisfied. The dynamics of K b (t) is given by In a decision making algorithm minimizing a quadratic Lyapunov function of K b (t), keeping the quadratic Lyapunov function small pushes the value of s(t) towards θ. Hence, carefully choosing the value of the perturbation parameter will ensure the battery queue always lies in the feasible region. It will be shown in Section IV-D that, the boundedness of s(t) will be guaranteed through the design of θ and V max in (27) and (28).
• Delay-Aware Queue R f ,i (t) provides the worst-case delay guarantee on the rescheduled delay tolerant loads in Q f ,i (t), using the technique of persistent queue [5], [6]. The dynamics of R f ,i (t) is given by where i is a positive control parameter, and > 0 or 0 otherwise. According to (18), while the service process of the delay-aware queue R f ,i (t) is the same as that of the backlog queue Q f ,i (t), i is added whenever the backlog queue is nonempty in the arrival process. In other words, R f ,i (t) continuously grows when there are delayed loads in Q f ,i (t) that have not been served. In a decision making algorithm minimizing a quadratic Lyapunov function of Q f ,i (t) and R f ,i (t), the size of Q f ,i (t) is pushed small when R f ,i (t) grows due to the nonempty Q f ,i (t). It can be ensured that all delayed energy loads are served with a worst-case delay, which will be specified later in Section IV-D.
• QoS-Aware Queue H l,i (t) accumulates the ratio of rescheduled loads and evolves as follows: According to (19), where the arrival rate is the load rescheduling ratio while the departure rate is β i in each time slot, to make sure the queue H l,i (t) is stable, the time-averaged load rescheduling ratio must be less than or equal to β i . Thus, maintaining the stability of H l,i (t) ensures that the constraint (2) is satisfied [28]. Replacing the time-coupling constraint (11), the timeaveraged inequality constraints (2) and (5) in P2 with the mean rate stability constraints (17), (18) and (19), respectively, P2 is transformed to P3, which is suitable for the Lyapunov optimization framework, as follows: ∀i ∈ I. We then define the following Lyapunov function as a scalar measure of the queueing delays of all virtual queues: 2 ]. (21) Note that the Lyapunov function only relies on the current system inputs [g pv (t), D(t), s(t)]. Define the conditional oneslot Lyapunov drift as follows: where the expectation is taken over all the random processes associated with the system inputs, given the current virtual queue states of K b (t), H l,i (t), Q f ,i (t) and R f ,i (t).
To incorporate the time-averaged energy consumption cost, we include a weighted version of the time-averaged energy consumption cost into the Lyapunov drift, and obtain the following drift-plus-penalty expression: where the Lyapunov drift in the first term represents the stability of the queues, and V in the second item serves as a weight controlling the performance tradeoff between queueing delay and energy consumption cost, i.e., how much one emphasizes on the energy consumption cost minimization. Adjusting the parameter V allows a trade-off between the cost of energy consumption and the sizes of the queue backlogs. Based on the drift-plus-penalty minimization method [28], the online battery sharing algorithm is designed to minimize the upper bound on the drift-plus-penalty expression, which is given in Proposition 1, to jointly stabilize the virtual queues and minimize the time-averaged energy consumption cost.

Proposition 1: For any possible control decision, the driftplus-penalty expression for all t is upper bounded by
where B is given by where f max Proof: See Appendix A Hence, the LOBSC algorithm can be described as follows: in each time slot t, observing the current virtual queue states (t) and system state X(t), the LOBSC algorithm determines the control decision Y(t) by solving the following optimization problem P4: (1) (7)(8)(10)(17)(18)(19).
Transforming the stochastic control optimization problem P1 into a linear programming problem P4, in which the timeaveraged constraints and energy consumption cost minimization are jointly considered in the new objective function, significantly reduces the calculation complexity. Although no knowledge of the statistics of the system state X(t) is required to solve the real time optimization problem P4, the queue states (t) carries sufficient statistical information to determine the control decision Y(t) in each time slot [28]. It will be shown that, an appropriate design of the perturbation parameter θ and the control parameter V in the real-time optimization problem P4 will ensure the boundedness of the SOC in (11) is guaranteed, which in turn ensures that the control decisions Y(t) derived from P4 are feasible to P1.

D. PERFORMANCE ANALYSIS
In this section, the performance of the LOBSC algorithm P4 is analyzed with respect to the original problem P1. Proposition 2: Setting the perturbation parameter θ as where then, under the LOBSC algorithm, we have 1) The worst-case delay of any rescheduled load is bounded by 46632 VOLUME 9, 2021 where R min 2) In each time slot t, i.e., the control decision Y(t) derived from P4 is feasible to P1.
3) The resulting time-averaged cost under the LOBSC algorithm by solving P4, C * P4 , is within bound B/V of the optimal cost of P1, C * P1 , i.e., where B is given in (25). Proof: The proof of Proposition 2 is an extension of the results in our previous work [34] to the case where portions of the delay-tolerant loads are rescheduled. For brevity, a sketch of the proof is provided in Appendix B.
Proposition 2.1 characterizes the boundaries on the worstcase delay of the rescheduled energy loads while indicating that the worst-case delay is affected by the delay-aware queue R f ,i (t), whose evolution depends on the control parameter i and the initial state of delay-aware queue R f ,i (t).
Furthermore, while Proposition 2.2 indicates that the control decisions Y(t) derived under the LOBSC algorithm are a feasible set of P1, Proposition 2.3 characterizes the gap between the expected time-averaged cost achieved by P4 and the optimal cost of P1, which implies that, setting the control parameter V as V max p max −p min minimizes this performance gap. In summary, by transforming the original problem P1 into the linear programming problem P4, which is relatively simple to be implemented and significantly reduces the calculation complexity, the LOBSC algorithm provides a low-complexity alternative, which achieves sub-optimal performance, without requiring any statistical information of the system. It can easily cope with arbitrary number of households with different levels of demand.

V. DISTRIBUTED IMPLEMENTATION
The optimization problem P4 can be solved in a centralized way, provided that the detailed information on the load demands and solar generations of all households are known to a central agent. This means each household has to report its demand preference and renewable generation, which are private information, to the central agent in each time slot. In this section, with the consideration of privacy preservation, we propose a distributed approach to implement the LOBSC algorithm in a distributed manner.
In each time slot, the households can be divided into two groups: energy surplus group, I a , where g gv,i (t) ≥ D i (t) ∀i ∈ I a , and energy deficit group, I b , where g gv,i (t) < D i (t) ∀i ∈ I b . Since K b (t) in P4 is determined by the charging and discharging amounts in the previous time slot t −1, we assume it is known to all households in each time slot. Therefore, P4 can be further split into I sub-problems for individual households, which are given by and where C i (t) = C MG,i (t) + C COM ,i (t), ξ ch,i (t) and ξ dis,i (t) denote the percentages of the maximum charging rate and discharging rate, R ch and R dis , taken by household i, respectively. It is noticed that, in each time slot, providing that i∈I a ξ ch,i (t) ≤ 1 and i∈I b ξ dis,i (t) ≤ 1, the constraint (10) in P4 is satisfied. In other words, once R ch and R dis are appropriately divided among households, the solutions to the sub-problems of P4-a and P4-b are feasible to P4.
We now present a division scheme in which R ch and R dis are divided among the energy surplus and energy deficit group, respectively, in a way that avoids the households who contribute less energy free ride on the energy contribution of others who contribute more while encouraging cooperation among the households. At the beginning of each time slot t, assuming ξ ch,i (t) = 1 and ξ dis,i (t) = 1 ∀i ∈ I, each household with energy surplus/deficit independently determines its optimal control vector, [d 1,i (t), d 2,i (t), g l,i (t), g s,i (t), g ch,i (t), g dis,i (t)], by solving P4-a/P4-b based only on its load demand request d i (t) and solar energy generation g pv,i (t).
When the sum of charging requests obtained, i∈I a g ch,i (t)+g s,i (t), exceeds R ch , R ch is divided proportionally within the energy surplus group based on the charging requests of the households, i.e., ξ ch,i (t) = g ch,i (t)+g s,i (t) i∈Ia g ch,i (t)+g s,i (t) . Similarly, when the sum of discharging requests obtained, i∈I b g dis,i (t), exceeds R dis , R dis is proportionally divided within the energy deficit group based on the energy contributions of the households, i.e., ξ dis,i (t) = is the energy contribution of household i, which is defined as the accumulated amount of energy that household VOLUME 9, 2021 i has charged and discharged: Then, each household in the energy surplus/deficit group redetermines its optimal control vector using the adjusted value of ξ ch,i (t)/ξ dis,i (t), which in turn ensures that i∈I a ξ ch,i (t) ≤ 1 and i∈I b ξ dis,i (t) ≤ 1. If household i discharges more than its energy contribution in time slot t, which results in EC i (t) < 0, it can only charge energy into the shared battery until it has a positive contribution.
With all information that can be obtained locally or through simple communication, each household independently solve the sub-problems P4-a/P4-b avoiding disclosure of private information, which is more implementable in practice. Furthermore, the distributed implementing approach considers a fair battery utilization by jointly considering the charging/discharging requests and energy contributions of individual households.

VI. NUMERICAL SIMULATION A. SIMULATION SETUP
In order to evaluate the effectiveness of the proposed LOBSC algorithm, a residential microgrid consisting of 10 households, each equipped with a solar system, is simulated. The households share a battery with charging and discharging efficiencies of η ch = 0.8 and η dis = 1.25, respectively. For simplicity's sake, we assume that S min = 0.1S max and R ch = R ch = 0.15S max , and set the initial battery energy level as S min . The simulation is performed for a duration of 90 days with T = 2160 and the Time-of-Use tariff of Johannesburg city power, as listed in Table 1, is used in the simulation.
The households are classified into 3 types: Type I with low electricity consumption, Type II with medium electricity consumption and Type III with high electricity consumption. The solar systems of the households in the same type generate a similar amount of renewable energy every day, which is selected from a uniform distribution with the mean value of 5kWh, 8kWh and 15kWh and a slight variance of 0.05kWh for Type I, Type II and Type III households, respectively. The daily solar energy generation of each household is then converted into hourly solar energy generations using a beta distribution with the mean value of 0.6kWh and the standard deviation of 0.03kWh, as shown in Fig.1(a).
Different types of households have very different load demand profiles resulting from the operation of various household appliances, as shown in Fig.1(b). In order to synthesize a real-time load profile reflecting variations in load demand at different times of day, the time-varying energy consumption of household appliances is simulated using the appliance demand profile generator (ADPG) developed in [34]. For each household, the total load demand generated by the ADPG in each time slot is used as the most preferred load request D i (t), while the inelastic load D i (t) is randomly set from [0.3D i (t), 0.9D i (t)]. The QoS related parameters β i and α i (t) are randomly selected from [0.3, 0.8] and [1.5, 3.5], respectively. Note that the values of the parameters α i (t) are chosen to ensure the weighted discomfort cost is comparable to the energy cost in the objective function of the optimization (14), so that both energy and discomfort cost are active factors in the optimization.
We randomly generate 10 households: 4 Type I households with 29.39kWh of average household load demand per day and 4.75kWh of average household solar generation per day, 3 Type II households with 35.55kWh of average household load demand per day and 8.21kWh of average household solar generation per day, and 3 Type III households with 43.50kWh of average household load demand per day and 16.36kWh of average household solar generation per day. For the sake of easy comparison, the average monthly solar generations and load demands of individual households are listed in Table 2. In addition, the corresponding average monthly costs without an ESS and a demand management (DM) mechanism are listed Table 2 as lower benchmarks. The real-time optimization problems P4-a and P4-b are solved using the CVX toolbox [42] for Matlab.

B. SIMULATION RESULTS AND ANALYSIS
Note that the performance of the proposed LOBSC algorithm depends on the battery capacity, the control parameter i and the initial state of the delay-aware queue R f ,i (0). We will study the impact of these factors on the performance of the battery sharing system in terms of cost saving and delay.
Besides surplus solar energy generations, the LOBSC algorithm allows the households to actively charge cheaper energy into the shared battery for later use. By varying the battery capacity while fixing other parameters , we investigate the impact of the battery capacity on cost saving under the LOBSC algorithm. As can be observed in Fig.2(a), the average cost per kWh decreases as S max increases from 40kWh to 70kWh. This is because that, with more storage capacity available for excess solar energy, the solar generation curtailment rate drops with an increase in S max , as shown in Fig.2(b). However, once the solar generation curtailment rate reaches zero, a larger S max that allows the households to store more cheaper electricity from the MG results in a higher energy cost as shown in Fig.2(a).
We now investigate the impact of the parameters of the delay-aware queue R f ,i (t) on the delay performance of the LOBSC algorithm in a battery sharing system with the 10 households sharing a 70kWh battery. We first evaluate the impact of the parameter i with R f ,i (0) = 0. As expected, a larger i pushes the delay-aware queue to grow faster, which results in a smaller delay since the buffered energy loads are more likely to be served quickly as shown in Fig.3(a) and Fig.3(b). However, the reduced delay comes with an increase in the energy cost as illustrated in Fig.3(c). It is also noticed that when i > 0.25, only a slight reduction in delay is obtained when increasing i . This is explained as follows: Since E{d 2,i (t)} < E{β i (D i (t) − D i (t))}, when i > E{β i (D i (t) − D i (t))}, the delay-aware queue R f ,i (t) will keep growing and quickly reaches the point Q f ,i (t) + R f ,i (t) > Vp max , where new buffered energy loads will be served immediately.
We then evaluate the impact of the initial state of the delayaware queue R f ,i (0) with i = 0.25. As can be observed,  setting R f ,i (0) as zero results in the worst delay performance with a mean delay of 2.67 hours (in Fig.4(a)) and a maximum delay of 54 hour (in Fig.4(b)). A smaller delay can be achieved with a larger R f ,i (0), since the buffered energy loads will be served as long as Q f ,i (t) + R f ,i (t) > Vp(t). Especially, when R f ,i (0) > Vp min , all delays are maintained under 7 hours. However, reducing delay means the buffered energy loads are less likely to be served during periods of lower electricity prices, which in turn increases the energy cost as shown in Fig.4(c). Obviously, a proper mechanism that trades off delay and energy cost optimally is needed in setting the parameters of the delay-aware queue. Nevertheless, in this work, we primarily focus on how to optimally share the battery among the households to save energy consumption costs of the households, given the dynamic behavior of the system, and the problem of optimal parameter selection is not considered in this paper.
In what follows, we further evaluate the performance improvement of the LOBSC algorithm with i = 0.25 and R f ,i (0) = 45. Firstly, to evaluate the performance of the LOBSC algorithm in terms of cost saving, the LOBSC algorithm is compared with a distributed load-shedding battery sharing algorithm, where a portion of load demands in each time slot is shed while satisfying the comfort levels of the households. For a fair comparison, under the distributed load-shedding battery sharing algorithm, the shared battery  is operated with a similar Lyapunov-based battery sharing control scheme where a portion of elastic loads is shed instead of being shifted. We assume that households take the same β i and α i (t) as those of the LOBSC algorithm, even though households could be more sensitive towards the load shedding, which in turn leads to higher energy costs. Fig.5 provides a comparison of the accumulated served load and corresponding cost over time between the two algorithms. It is illustrated that, the load shedding algorithm (with the shed demand rate being 12.27%) serves less loads with a lower energy cost. As shown in Table 2, compared with the lower benchmark case, the LOBSC algorithm with 13.09% load demand being rescheduled reduces the system average monthly cost by 13.74% with an average cost of 0.93R/kWh, while the load shedding algorithm with 12.27% load demands being shed achieves 26.90% cost reduction with a similar average cost (0.90R/kWh).
Secondly, to evaluate the performance improvement in terms of fairness, the LOBSC algorithm that takes into account the energy contribution of each individual household is compared with a centralized battery sharing algorithm, in which the real-time optimization problem P4 is solved by CVX directly. As shown in Table 2, the centralized battery sharing algorithm allocates the available energy/space of the shared battery among households mainly based on the amounts of their charging/discharging requests. Unfortunately, this leads to a situation in which Type I and Type II households, who contribute less energy, free ride on the energy contributed by Type III households, even though the centralized battery sharing algorithm reduces the average monthly cost of the whole system by 13.32%.
In contrast, the LOBSC algorithm limits the shared energy utilization of each household by its energy contribution while encouraging households to share their surplus energy. As can be observed in Table 2, under the LOBSC algorithm, while each household contributes slightly less energy compared to those of the centralized battery sharing algorithm, the shared energy that each household consumes is limited by what it shared. According to Table 2, under the LOBSC algorithm, Type I, II and III households achieve 7.57%, 11.28% and 21.48% lower average monthly costs, respectively, which coincide with their average ratios of solar generation to load demand (16.16%, 23.21% and 37.61%). Similarly, compared to the centralized algorithm, Type III households under the LOBSC algorithm achieve a lower mean delay since their shifted loads are more likely to be severed with the shared energy. Both algorithms maintain the maximum delay under 11 hours.

VII. CONCLUSION
This work studies the real time energy management problem for a residential energy storage sharing system and presents an OESSM system that integrates energy consumption management, load scheduling and energy storage sharing, aiming to minimize the long-term time-averaged costs of all households while maintaining customer comfort. Based on the Lyapunov theory, we propose an online battery sharing control algorithm, under which the households are coordinated to jointly optimize their energy charging and discharging decisions along with energy consumption and load scheduling decisions in a distributed manner without requiring any statistical knowledge of their load demands and renewable generations. The performance gap of the proposed low-complexity LOBSC algorithm and load scheduling delay boundaries are characterized. Numerical evaluations provide a better understanding on the influence of some contral parameters in the performance of the LOBSC algorithm in terms of cost saving and load scheduling delay. It is shown that, under the LOBSC algorithm, the load demands of each household are served with lower delays at a cost per kWh similar to that of the Lyapunov-based load shedding algorithm and the households utilize the shared energy in a fair manner.
and g s * (t) [g * s,i (t)] ∀i ∈ I be the optimal solution to (40). Since D * (t) does not directly affect the battery queue K b (t), it is treated as a given load. We further split P5 into two sub-problems for the energy surplus and energy deficit group, respectively, as follows: • Energy Surplus: when g gv,i (t) ≥ D * i (t), we have g * l,i (t) = 0. Then, the optimization problem for the energy surplus group can be written as follows: • Energy Deficit: when g gv,i (t) < D * i (t), according to (8), we have g * ch,i (t) = 0 and g * l,i (t) = d * 1,i (t) + d * 2,i (t) − g * dis,i (t) − g pv,i (t). Then, the optimization problem for the energy deficit group can be written as follows:  The optimal solution to P5 has the following properties: • In the case of energy surplus, since the partial derivative of the objective function in (41) with respect to d 2,i (t) is negative, the maximum possible value for d 2,i (t) is Q f ,i (t − 1), i.e., d * 2,i (t) ≤ Q f ,i (t − 1); • In the case of energy deficit, the optimal decision on d 2,i (t) is given by Suppose a flexible load D i (t) − d 1,i (t) at any time slot t is served on time t + δ WC i , which means the load is not served by t + δ WC i − 1. Then, according to the properties mentioned above, it only happens in the case of energy deficit. Specifically, it must be case that Q f ,i (τ )+R f ,i (τ ) < Vp(τ ) for all time slots τ ∈ {t +1, t +2, · · · , t +δ WC i −1}. This implies that d 2,i (τ ) = 0 and 1 {Q f ,i (τ −1)>0} = 1. Thus, we have Accordingly, which can be rearranged as follows: , which can be rearranged as follows: where f max i max t∈{0,1,..T } {D i (t) − D i (t)}. Hence, we get Now we look at a special case where t = 1 and Q f ,i (0) = 0. In the worst-case scenario, according to (44), the worst-case delay for the delayed load D i (1) − d 1,i Especially, when R f ,i (0) = 0, we have δ WC i (1) > Vp min f max i + i . This indicates that, given a certain i , a smaller R f ,i (0) leads to a larger worst-case delay for the delayed load D i (1)−d 1,i (1), which could in turn affect the following evolution of the delay-aware queue R f ,i (t) and the delays of the following buffered loads.
Proof of Proposition 2.2: The real time optimization problem P4 includes all constraints of the original problem P1 except for the energy state constraint. Therefore, the optimal solution of P4 is feasible to P1, provided that the energy state s(t) is bounded within [S min , S max ]. The boundary of s(t) can be proved using induction. The proof is similar to that of our previous work and hence omitted for brevity. Interested readers may refer to [34] for details.

Proof of Proposition 2.3:
The proof of the performance boundary follows the performance result derivation in the Lyapunov optimization framework and is similar to that of our previous work. Interested readers may refer to [34] for details.