Uncertainty-Aware Model Predictive Control for Residential Buildings Participating in Intraday Markets

Buildings with generation and storage assets have the opportunity to trade in electricity markets. Residential buildings, however, have load patterns that are more difficult to predict and less flexible – introducing uncertainties to their operation. In addition, local intermittent renewable energy sources further increase these uncertainties. In this regard, an uncertainty-aware model predictive control (UA-MPC) is proposed in this paper. The proposed UA-MPC allows residential building energy management systems to trade in intraday markets without violating the operational constraints of their batteries despite the uncertainties in load consumption and solar irradiation. Moreover, the proposed UA-MPC only needs prediction intervals instead of detailed probability distribution functions to describe the uncertainties. Furthermore, in the proposed UA-MPC, the optimization is formulated as a shortest path problem. Thus, the optimization can be solved in polynomial time, which is desirable in intraday settings. Numerical simulations for two active residential buildings in grid-connected and isolated-neighborhood scenarios have been used to evaluate the proposed UA-MPC. Furthermore, the performance of the proposed UA-MPC was compared with the performance of a deterministic model predictive control (MPC) and a robust MPC. The results show that the proposed UA-MPC eliminates constraint violations that would otherwise occur in using deterministic MPC while providing lower costs than those using robust MPC. The results also show that the proposed UA-MPC can generate bidding curves in a few seconds, demonstrating its applicability in intraday market settings.


I. INTRODUCTION
There has been a steady increase in renewable energy resources (RES) in buildings in recent years. For example, solar photovoltaic (PV) systems in homes, commercial buildings, and industry experienced exponential growth in the last decade [1], [2]. Several business models have also been established and proposed in the literature to integrate these buildings as prosumers in intraday energy markets [3], [4].
One of the challenges in integrating residential buildings into energy markets is the high volatility and variance of their The associate editor coordinating the review of this manuscript and approving it for publication was Behnam Mohammadi-Ivatloo . loads [5], [6], making it difficult for established forecasting methods to provide an accurate forecast [7]. Moreover, residential loads are not as flexible as commercial and industrial loads. Some reasons for this are that residents do not follow specific and regular schedules. Nevertheless, several measures to control or influence residents' behavior can be implemented, for example, using time-based price signals. However, consumption patterns are hard to break, and the limited cognition, lack of knowledge, and lack of awareness further aggravate this problem [8]. With low forecast accuracy, optimization methods may produce decisions that could violate the operational constraints of the batteries used in residential buildings. These violations may lead to battery health decline, failure in satisfying market commitments, or forced load curtailments.
In this paper, an uncertainty-aware model predictive control (UA-MPC) for building energy management systems (BEMS) is proposed. The prosed approach allows buildings to trade locally generated and stored energy while considering the uncertainties in load and PV generation forecasts. By considering the uncertainties, a building will be able to participate in different business models in intraday markets while avoiding violations of operational constraints.
As shown in Fig. 1, the proposed approach is expected to be used in buildings with PV systems, battery storage, and optionally, backup diesel generators. The BEMS must also have forecasting capabilities that can produce prediction intervals.
In dealing with forecast uncertainties, typical model predictive control (MPC) approaches use an optimization horizon and a shorter application horizon. With a typical MPC, the BEMS optimizes the operation over an optimization horizon but implements the control decision only for the next application horizon. Then, the MPC repeats this process every application horizon. This way, the MPC takes advantage of new forecasts and updated values of optimization parameters.
The proposed UA-MPC inherits all properties of a typical MPC. However, it also adds several features that are beneficial to residential buildings. First, the UA-MPC not only optimizes based on point forecasts but also considers the prediction interval that will contain future values of random variables with a certain probability. Second, the optimization problem in the proposed UA-MPC is formulated as a shortest path problem (SPP) -allowing buildings to optimize in polynomial-time and filter solutions that are not feasible under the worst-case realizations of load consumption and solar irradiation.
Buildings can use the output of the proposed UA-MPC to react to market price signals. Buildings can also use the outputs to produce bids if the buildings are active participants in determining the energy price and volume it wants to trade in an intraday market setting.
In addition, the proposed approach can be used in a scenario where the main grid is available. It can also be used in a scenario where the grid is unavailable, but the building can trade power within an isolated neighborhood. Only the graph used for the SPP is different between the two scenarios.

II. RELATED WORK A. MODEL PREDICTIVE CONTROL APPROACHES IN BUILDINGS
To determine the expected optimal operation cost, the BEMS has to optimize over a time horizon using the forecasted values of load demand and solar irradiation. To this end, plenty of research papers have investigated the use and potential of model predictive control (MPC) to carry out the optimization and management of building energy systems, albeit primarily for non-residential buildings [9]. Compared to non-residential buildings, residential buildings receive less attention because they individually have smaller loads, fewer controllable loads, and less predictable consumption patterns. However, the expansion of distributed generation and local energy communities is increasing the need for more sophisticated control in residential buildings.
A review of residential energy systems in [10] has shown that MPC is the most typical approach to handle uncertainty for residential systems. The MPC approaches in the literature can be classified based on the optimization approach that they use: deterministic MPC, stochastic MPC, distributionallyrobust MPC, and robust MPC.
In deterministic MPC, the optimization uses the latest available point forecasts and building states to mitigate the errors due to uncertainties. Deterministic MPC does not consider the uncertainties in the forecasts. Examples of deterministic MPC for load management in residential buildings are presented in [11] and [12]. In these examples, however, there are no guarantees that the operational constraints of different appliances will be respected across the different possible realizations of load consumption or solar irradiation. Another example of deterministic MPC is presented in [13], in which the scheduling problem of appliances and energy storage is considered an NP-hard optimization problem. In this example, the optimization is performed using heuristic and local search. However, with heuristic search approaches, there is no guarantee that the global optimum solution will be found in polynomial time, resulting in the possible use of a suboptimal solution. In [14], the scheduling problem uses the concept of L1 regularization to handle the mixed integer programming problem in a convex programming framework. This approach relies on the convex formulation of the operation characteristics and constraints of the appliances. However, [14] did not elaborate if the assumptions of convexity will hold under the different possible realizations of the forecasted quantities. In [15], a two-horizon algorithm is proposed to reduce uncertainties by increasing the optimization resolution, i.e., using finer time steps. Still, the uncertainties in the forecasts are not addressed. In [16], a self-learning scheme is proposed to improve the performance of the energy management system over time as it learns and gains more experience in real-time operations. However, the uncertainty was not quantified nor considered in the optimization in the paper. By neglecting the uncertainties in residential buildings, in which the load has high volatility and variance, deterministic MPC may lead to constraint violations in the VOLUME 10, 2022 battery constraints, further leading to battery safety and health degradation or unplanned load curtailment to maintain market commitments.
One way to handle uncertainties in the forecasts is to use stochastic MPC, which employs stochastic optimization approaches. In stochastic optimization, the randomness can be modeled using a probability distribution function or scenario trees [10], [17]. Stochastic optimization is typically used in multi-stage problems focused on the coordination of multiple BEMS. An example application is provided in [18], where the online stochastic optimization helps achieve better privacy protection for the participants. It is also possible to define risks for each scenario and optimize based on these risks. In such cases, the stochastic MPC becomes a riskaverse MPC, as in [17]. In the context of building energy systems in an intraday market, stochastic optimization may not guarantee convergence to the global optimum solution in a reasonable time, which may lead to using sub-optimal solutions. Also, depending on the implementation, stochastic MPC may require considerable computational time, e.g., using Monte-Carlo methods, which may render it infeasible for an intraday market setting. Moreover, the probability distribution function required in defining scenario trees may not be available.
Stochastic MPC assumes that the probability distribution functions of the forecasted quantities are known and exact. This assumption can be relaxed using a distributionally robust MPC. In distributionally robust MPC, ambiguity sets are used to define possible deviations from a given probability distribution functions [19]. A case study for using distributionally robust MPC for thermal control in buildings is presented in [20]. However, implementing such optimization need more advanced statistical approaches to determine the required ambiguity sets from historical data. Also, similar to stochastic MPC, convergence to the optimum solution is not guaranteed unless several approximations are assumed.
Another way to consider uncertainties from forecasted values is to use robust MPC. In contrast to stochastic MPC, robust MPC handles uncertainties by using robust optimization, in which optimization is performed under worst-case conditions [21]. By optimizing under worst-case conditions, robust MPC ensures that constraints will not be violated even if the worst-case realizations happen. Examples of robust MPC proposed in the literature can be found in [22]- [25]. Robust optimization has gained popularity due to its tractable formulations for certain types of uncertainty sets [26], which describes the range of possible values which the forecasted quantities can take. However, robust optimization is considered pessimistic because it optimizes using worst-case conditions and may lead to higher costs in the most probable cases.
The proposed UA-MPC in this paper differs from robust MPC because UA-MPC does not optimize under the worstcase conditions. Similar to deterministic MPC, the UA-MPC still evaluates the objective function based on the expected values of random variables. The UA-MPC, however, can avoid violations of operational constraints (e.g., battery SoC limits, diesel generator outputs) when the worst-case scenario happens. This feature is achieved by discretizing the solution space and eliminating candidate solutions that would lead to violations under worst-case realizations. Table 1 summarizes the main characteristics of the methods discussed above concerning their application in residential buildings.

B. UNCERTAINTY MODELING
Uncertainties in the future values of random variables are quantified using probabilistic forecasting methods, which produces quantiles, prediction intervals, or probability density functions [27]. Prediction intervals are not to be confused with confidence intervals. A prediction interval (PI) is an interval is a range of values that the forecasted variable could take with a certain probability, while confidence intervals are associated with a parameter or parameter functions describing the data [28]. With the use of prediction intervals, an energy management system can provide a statistical guarantee in its performance without the need for the random variables' exact probability distribution function.
There are various forecasting methods for producing prediction intervals. Some of the classical ones use a pivotal quantity, maximum likelihood estimators, or normal approximations [28]. There are also methods of producing prediction intervals based on neural networks [29]. In this paper, we use the prediction intervals accompanying forecasted values to quantify the forecast uncertainty. By considering, the proposed UA-MPC ensures that constraints will not be violated as long as the forecasted quantities fall within these prediction intervals.
Some examples of prediction intervals from load consumption forecasts are shown in Fig. 2. Fig. 2-a shows the prediction intervals that cover 68% of future values, while Fig. 2-b shows the prediction intervals that cover 95% of future values. As expected, the prediction intervals covering 95% of possible future values are wider than those covering only 68%. Moreover, the prediction intervals are smaller in the hours after midnight, indicating lower forecast uncertainties at these hours compared to other periods of the day.

C. SHORTEST-PATH PROBLEM WITH UNCERTAIN EDGE COSTS
One particular class of optimization problems that have been extensively studied considering uncertainty is the SPP. SPP has been used in the fields of computer science, telecommunications, and transportation [30]. The SPP is defined in the context of a graph containing nodes connected by edges with associated costs. When the edges are associated with a direction of travel, the graph is called a directed graph. To illustrate, Fig. 3 shows an example directed graph with six nodes and eight edges.
The objective of SPP is to find the path from the initial node to the final node that will give the least cost or the shortest distance. Several methods are available to solve the SPP in cases where the edge costs come with uncertainties. The most notable of these methods are as follows [30]: • Expected Value Model -which is concerned with finding the path with the lowest expected costs under uncertainties -this is the most typical way of dealing with random edge costs unless the users are concerned with the variance of total costs; • Most Reliable Path -which is concerned with finding the path with the highest probability to arrive at the destination at a certain cost threshold, and; • α-Reliable Path -which gives the least-cost path with a certain level of confidence. In the proposed UA-MPC, the optimization is formulated as an SPP with uncertain costs, and the Expected Value model is used to find the optimum solution. This formulation makes the optimization problem in the MPC solvable in polynomial time using shortest-path algorithms such as Bellman-Ford or Floyd-Warshall [31]. This guarantee makes it desirable for intraday settings. It also produces the least-cost solution given the most likely realizations of the random variables. Eq. (2) provides the objective function for the expected value model of SPP with the constraints in provided in (2) and (3). If desired, the costs in this equation may also be adjusted to consider potential risks.
where: c ij is the expected cost of directed edge from node i to node j; x ij is the decision variable associated with the use of edge i, j; x ij is 1 if edge i, j is in the shortest path, and 0 if not; E is the set of all edges; O(n) is the set of nodes with outgoing edges; I (n) is the set of nodes with incoming edges. Another approach for the SPP when dealing with the uncertainties in edge cost is the robust SPP. Similar to robust optimization, robust SPP optimizes under worst-case conditions and does not require probability distribution functions to describe uncertainties [32]. Instead, robust SPP uses uncertainty sets to describe the range of possible edge costs. In the robust SPP, the goal is to find the least cost at the worst-case conditions. Robust SPP is pessimistic, but it avoids constraint violations under worst-case conditions.
Although the robust SPP is not used in the proposed UA-MPC because it is pessimistic, the idea of graph reduction that is typically used in robust SPP [32], [33] is used in the UA-MPC. In graph reduction, the edges in the graph that would result in violations of the constraints under worst-case conditions are removed. In the proposed UA-MPC, the worstcase conditions, i.e., the maximum load and the minimum solar irradiation, are defined using the boundaries of the  prediction interval. This definition ensures that the optimal solution will not violate the battery constraints as long as the values of random variables fall within the prediction interval.

III. SUMMARY OF CONTRIBUTIONS
Currently, there is a lack of methodology to optimize the operation of residential buildings that hedge against uncertainties in load consumption and solar irradiation while providing a formulation that can be solved in polynomial time. In this paper, this gap is addressed by the proposed UA-MPC, in which the optimization is formulated as an SPP. This formulation makes the problem solvable in polynomial time, which is desirable in MPC settings because it allows buildings to use the optimization outputs to participate in intraday markets. Moreover, graph reduction is used to ensure that the building operation will not violate the operational constraints when the realization of load consumption and solar irradiation falls within prediction intervals that cover a percentage of possible realizations of these random variables.
The proposed approach is described in further detail in section IV.

IV. UNCERTAINTY-AWARE MODEL PREDICTIVE CONTROL A. OVERVIEW
An overview of the UA-MPC is shown in Fig. 4. Also highlighted in Fig. 4 are the blocks of graph creation, benchmark optimization, and candidate evaluation, which are the important developments in the UA-MPC.

B. TIMELINE
With respect to time, the proposed approach is executed in the context of an intraday market as shown in Fig. 5.
The market takes buying and selling offers for a trading horizon, denoted by h i . Each trading horizon has a duration of T x (e.g., 15 minutes). The buildings fulfill their commitments to sell or buy energy at a specific power level during a trading horizon. Also, during a trading horizon, the buildings provide bids for the next trading horizon. The bids are based on the benchmark optimization and candidate optimization shown in Fig. 4. The optimization horizons of each building may differ in length and may contain several consecutive trading horizons. After receiving the bids, the market settles the bids before the next trading horizon. In the next trading horizon, the buildings again fulfill their commitments in selling or buying energy at a specific power level. The buildings' commitments allow markets to dispatch buildings as loads or generators.

C. SYSTEM MONITORING AND LOAD FORECASTING
One cycle of the UA-MPC starts with metering and monitoring that updates the BEMS with the actual battery SoC and historical load consumption of the building. Then, the BEMS performs forecasting to produce both 1) the expected values and 2) prediction intervals of future load consumption and solar irradiation.

D. GRAPH CREATION
After forecasting the load, the BEMS creates the graph that will be used in the optimization process. Two types of graphs may be created depending on the scenario: gridconnected scenario or isolated-neighborhood scenario. In the grid-connected scenario, the building is connected to the grid, possibly buying energy from the grid, injecting energy at the feed-in-tariff (FIT), or trading in a local energy market. In the isolated-neighborhood scenario, the grid is not available, and the building is allowed to buy or sell energy only within its neighborhood.
Concerning the graph creation, the main difference between the grid-connected and isolated-neighborhood scenarios is that diesel generation is only used and modeled in the isolated-neighborhood scenario. Fig. 6 shows G C , which is the graph used for the grid-connected scenario. Each node in the graph is defined by a battery SoC and a point in time. Each edge in the graph defines a transition between two nodes. Step 1: The graph creation starts at the initial node α at time t α , which is the beginning of the next trading horizon. Node α is defined by the anticipated SoC at t α . This anticipated SoC is calculated using the current SoC and the expected load consumption and PV generation between t 0 and t α .

1) GRID-CONNECTED SCENARIO
Step 2: The next set of nodes are defined at time t α + T X , which is one trading horizon after t α . Each node contains a different battery SoC that is between the minimum SoC, SoC min , and the maximum SoC, SoC max . The number of nodes defined for this time instant N t , is given by Eq. (4).
where SoC is the difference between two consecutive SoCs. A smaller SoC creates a more accurate graph, but it takes more memory due to a higher number of nodes and edges. It can also lead to a longer time for finding the shortest path within the graph later in the process. A guideline for selecting SoC is provided in the candidate generation section.
Step 3: Step 2 is repeated for every time instant at the end of a trading horizon within the optimization period, i.e., for time instants t α + 2 * T X , t α + 3 * T X , and so on. For example, if the optimization period is 12 hours, and a trading horizon lasts for 15 minutes, then Step 2 is repeated 96 times.
Step 4: The final node, ω, is created and is connected to all the nodes at the end of the optimization horizon. The cost of the edges going to ω is set to zero. This means that the battery SoC at the end of the optimization horizon is not essential to the optimization.
Step 5: A directed edge is created from each node of one time instant to every node in the next time instant.
Step 6: Except for edges connected to the α and ω, the cost of each edge is calculated by first using Eq. (5) to determine the battery output for the transition; then using Eq. (6) to determine the expected power imported from the grid; then Eq. (7) to calculate the expected cost per kWh on buying or VOLUME 10, 2022 selling from the grid; then Eq. (9) to determine the expected cost of the edge.
where: c ij is the expected cost of directed edge from node i to node j. σ is an indicator if the transition from i to j would violate a constraint.
SoC i is the battery SoC of node i. SoC j is the battery SoC of node j.
Step 7: In this step, graph reduction is performed. Here, the procedure checks whether the battery SoC limits can be violated in case the building commits to the trade under worstcase conditions. That is, graph reduction is performed using Eqs. (10) - (14) and then checking the value of Q E . If Q E is true, then the edge is removed from the graph.
Q E = SoC wc,min < SoC min ∨ SoC wc,max > SoC max (14) Step 8: In this step, the edges that occur when no trades are executed are added to the graph. This step is performed using Eqs. (15) - (16).
If SoC j − SoC i is equal to SoC,n , then c ij is set to zero.
Also, if SoC i + SoC,n is greater then SoC max , then c ij is also set to zero. This step is performed to handle cases where the solar PV would charge the battery beyond the maximum SoC.
At this point, the graph should look like the graph shown in Fig. 6, except for the green edges that represent trades in the next time horizon. These edges are added later during the candidate evaluation step. Furthermore, the edge connected to node α is denoted as α, n.

2) ISOLATED-NEIGHBORHOOD SCENARIO
In the isolated-neighborhood scenario, the diesel generator operation has to be modeled. For this scenario, the process for graph creation is described as follows: Steps 1 to 5 are the same as those for the grid-connected scenario.
Step 6 is the same as that for the grid-connected scenario. However, the power balance equation in Eq. (6), the condition in Eq. (8), and the cost equation in Eq. (9) are respectfully replaced by Eqs. (17), (18), and (19).
where, P D,ij is the output power of the diesel generator defined by the transition from node i to node j.
Steps 7 and 8 are the same as those for the grid-connected scenario. The set of edges that were added in Step 8 is denoted as E z,on . Also, the resulting graph after Step 8 is denoted as G on . An illustration of this graph is the Diesel-On plane in Fig. 7, except that the final node from G on is not yet removed.
Step 9: The set of all edges in G on is denoted as E on . Then, a copy of G on is created. The copy is referred to as G off . Naturally, the edges within E on have their copies in G off . The set of these edge copies is denoted as E off . Also, the copies of the edges in E z,on in G off is denoted as E z,off .
Step 10: All the edges in G off that are not in E z,off are removed. The resulting graph is shown as the Diese-off plane in Fig. 7.
Step 11: The final node in the diesel-on plane is removed. This does nothing physically, but it gives the SPP a single final point.
Step 12: In this step, the edges connecting the diesel-on and diesel-off planes are added based on the following rules: • For each node in G on , add an edge from this node to its copy in G off . This represents the fact that the generator can turn off at any time.
• For each node in G off with the minimum SoC, add an edge from this node its copy on G on . This represents the diesel turning on when the minimum is reached. • For each node in G off , calculate SoC a using Eq. (20) and Eq. (21). If SoC a is less than the minimum SoC, add an edge from the node to its copy in G on . This represents the diesel turning on when the minimum SoC is reached in the middle of a trading horizon. The resulting graph should be the one in Fig. 7.
The cost of each edge added in this step is zero. These edges added in this step represent the diesel generator turning on or off. Also, the process of graph creation for the isolated-neighborhood scenario ends here at Step 12.

E. BENCHMARK OPTIMIZATION
Benchmark optimization is achieved by finding the shortest path from node α to node ω in the graph. The total cost of this path is denoted as c 0 .
In the isolated-neighborhood scenario, however, there are two possible initial nodes. Between these two, the BEMS the initial node in G on if the generator is currently on. Otherwise, it selects the initial node in G off .

F. CANDIDATE GENERATION
An initial set of candidate trades, P R , is defined based on the charging and discharging limits of the building, i.e., P ch,max and P dch,max . Each candidate, P r ∈ P R , is defined using predefined resolution r . For example, if P ch,max and P dch,max are both 20 kW, and r is 1 kW, then the initial list is [20 kW, 19 kW, 18 kW, . . . , −18 kW, −19 kW, −20 kW]. In this list, the positive values represent buying power while the negative values represent selling power.
A candidate will be removed from the initial list of candidate trades by using Eqs. (22) - (26), and then checking the value of Q E . P B,max = −P r + P L,1,max − P S,1,min * η P B,min = −P r + P L,1,min − P S,1,max * η (23) If Q E is true, then the candidate is excluded from the list of trades.
Also, the SoC of the graph should not exceed the value in Eq. (27). Otherwise, the difference between the prices for two consecutive candidates may not be captured in the next step.
The process for candidate trade determination in the isolated-neighborhood scenario is the same as the process in the grid-connected scenario with the following exception: the edge representing the trade is added to the G off . This reflects that diesel generator is off when trading to avoid selling energy from non-renewable sources.

G. CANDIDATE EVALUATION
A candidate trade is evaluated by forcing the optimization to execute the trade with zero payments and then comparing the resulting cost with c 0 , which is the cost at the benchmark. This process is similar to the process of Vickrey pricing in SPP as introduced in [34].
The process is performed by first removing all edges connected to node α. Then, an edge from node α corresponding to the trade is added with an edge cost of zero. An example of this added edge is shown as a green edge in Fig. 6. Afterward, the shortest path from node α to node ω is determined, and the path cost is denoted as c r . In the isolated-neighborhood scenario, the node α considered is the one in the Diesel-Off Plane since the diesel generator is assumed to be off when trading. VOLUME 10, 2022 If the candidate represents buying power, then the willingness to buy is given by Eq. (28). Otherwise, if the candidate represents selling power, then the negative of the willingness to sell is given by Eq. (29).
The collection of φ r from all candidates constitutes the Vickrey-price curve. This curve is then sent to the intraday market platform, which decides how much the building will buy or sell in the next trading horizon.

H. REMARKS ON RISKS AND FLEXIBILITY
During graph creation, the expected costs can also be adjusted to capture and manage risks. For example, for edges that have low battery SoC, the expected costs can be increased to model the building's urgency of buying to keep the SoC within limits. Moreover, it is also possible to set the battery SoC limits to 0 and 1. In this case, the costs of edges where the battery is close to the limits can be increased to model the increased risks of market commitment failure, battery health degradation, or forced curtailments in load or generation. Alternatively, edges that are considered too risky can be removed from the graph.
Moreover, this paper focuses on trading energy from self-generation and battery storage in residential buildings. Therefore, the model presented in this section does not capture flexibilities in load consumption patterns, such as in heating, ventilation, and air conditioning (HVAC) or electric vehicle (EV) charging. Nevertheless, the model can be adjusted to capture these flexibilities. For example, for modeling EV charging flexibility, additional planes can be added to the graph representation. The additional planes would contain the SoCs of the EVs' batteries. The nodes in the additional planes may be further restricted to capture target SoCs at specific time instances.
Furthermore, modeling load consumption flexibility can also be captured using additional planes -similar to how the diesel generator operation was modeled in this paper. For example, one SoC plane can be used for the states in which air conditioning is off, and an additional plane can be used to represent states in which the air conditioning is on. The constraints in the operation of the air conditioning use can be modeled in the edges that connect the two planes.

V. CASE STUDY
A case study with numerical simulations was performed on a local energy neighborhood to assess the performance of the proposed UA-MPC. The neighborhood is composed of two active residential buildings as illustrated in Fig. 8.
Each building in the neighborhood is capable of energy trading and participating in an intraday energy market. Moreover, the neighborhood is typically connected to the grid. However, during power interruptions due to the failures in the grid, the neighborhood operates in islanded mode, in which the buildings are able to trade with each other. Furthermore, there is no centralized controller in the neighborhood to manage the energy system, and each building has its own BEMS.
A. BUILDINGS Fig. 9 shows a schematic diagram of the active residential buildings that were considered in the case study. Further specifications about the building resources and loads are provided in Table 2. Each building in the neighborhood can generate energy through a solar PV system and a backup generator. Also, each building has its own battery for energy storage. Moreover, each building has its own BEMS that performs the following functions: • Measure the load demand and PV generation output. • Determine whether the generator is on or off and how much power it should produce.
• Communicate with the BEMS of the other building for energy trading. For the case study, the load profile of each building was generated by adding the load profiles of its individual households. The appliances and load profile for each household were generated using the CREST Demand Electricity Model [35]. This model produces household load profiles using a bottom-up activity-based structure based on the number of residents, either having weekdays or weekends, the month of the year, and random allocation of household appliances. Furthermore, the CREST Demand Electricity Model uses stochastic programming techniques to represent dwelling diversity.
The irradiation profile for the solar PV was generated using the PVWatts Calculator [36]. It was assumed in the case study that the buildings are located in the same neighborhood and have the same solar irradiation profiles.
Load and solar irradiation profiles with lengths of twenty-one days are generated in the months of July and January. The months were selected to simulate high and low irradiation settings, respectively. The last seven days of the profiles were used for the numerical simulations, while the first 14 days were used to train and validate black-box forecasting models needed by the MPC of the BEMS. The forecasting models were developed using the Regression Learner of MATLAB R , because it provides the option to choose the most appropriate model among various algorithms.  Moreover, the models produced by the Regression Learner do provide not only the expected values of the predicted variables but also the prediction intervals needed in the proposed UA-MPC. Such models developed in MATLAB were enough to illustrate the features of the UA-MPC. In real-world applications, however, the modeler can use more advanced forecasting models that are developed for a specific buildingprovided that these models can provide prediction intervals to quantify uncertainties in the forecast.
In the case study, the battery's operational O&M costs are neglected. This follows from the findings of [37], where it is found that the battery's operational O&M costs are too small to make an impact in determining prices.
Furthermore, for the grid-connected scenario, a surcharge of 0.0037 Euros per kWh is considered when selling (i.e., C IC in eq. (29)); whereas for the isolated-neighborhood scenario, a surcharge of 0.0046 Euros per kWh is considered.

B. SCENARIOS
The performance of the proposed UA-MPC is tested in the main scenarios and sub-scenarios listed below: • Main Scenarios: --Grid-Connected Scenario --Isolated-Neighborhood Scenario Two settings were also used to evaluate the performance of the UA-MPC and compare it with the performance of other MPC approaches. These settings are 1) the high-irradiation setting, when there is high solar irradiation and the buildings have relatively high self-generation; and 2) the lowirradiation setting, when there is low solar irradiation and buildings have relatively low self-generation. For the highirradiation setting, the summer month of July was selected. For the low-irradiation setting, the winter month of January was selected. Moreover, two kinds of simulations were performed for each setting: First, a week-long simulation using the actual profiles of the buildings; Second, Monte-Carlo simulations using 100 randomly generated 1-day load profiles and solar irradiation profiles. The profiles for the Monte-Carlo simulations are based on the prediction intervals at the start of the day. The Monte-Carlo simulations allow the evaluation of the UA-MPC performance across different realizations of solar irradiation and load consumption. Furthermore, for each month, the first two weeks were used to develop forecasting models. The third week was used for the simulations. Also, one day of the third week in each month was used for the Monte-Carlo simulation.

C. PERFORMANCE INDICATORS
The performance of the proposed UA-MPC was tested under each scenario using three performance indicators.
The first performance indicator is the cost index, C T , as calculated in Eq. (30). It is the sum of the buying costs and fuel costs from diesel generation and is reduced by the earnings from selling energy.
where: T i , T e , T D are the respective sets of all time instances where the building is importing, exporting, or running the diesel generator; VOLUME 10, 2022 p i,t and p e,t are the respective import and export costs at time t; P D,t is the diesel generator output at time t; and f P D,t is the cost function of the diesel generator.
The second performance indicator for the case study is the violation-area index, A , which indicates the severity of violations of SoC limits. A quantifies the area that exists between the SoC profile and the SoC limits at times when the SoC limits are violated, as in Eq. (31). where: T min is the set of all time instances where the minimum SoC is violated; and T max is the set of all time instances where the maximum SoC is violated.
In cases where the maximum SoC is 1.0, and the minimum SoC is 0, then A cannot be defined. However, in such cases, the building is forced to abandon its market commitment or curtail its internal load.
Another performance indicator that is used to evaluate the proposed UA-MPC is the curve preparation time, T CP . This is the total time spent preparing the Vickrey-price curve from the latest measurements received by the BEMS. That is, the curve preparation time is the total execution time of the load and PV forecasting, graph creation, benchmark optimization, candidate generation, candidate evaluation, Vickrey-price curve generation. For the proposed UA-MPC to be usable, the curve preparation time must be reasonably less than the trading horizon of the intraday market.

VI. RESULTS
The results of the numerical simulations for the case study are presented in this section as follows: 1) Some example forecasts, prediction intervals, shortest paths, and Vickrey curves are provided to give the readers an impression of the quantities used in the proposed UA-MPC.
2) The performance of the UA-MPC was tested in the high-irradiation and low-irradiation settings, and the results are presented using the performance indicators defined in the previous section.
3) The results regarding the execution times are provided to check if the UA-MPC can be used in an intraday setting.

A. EXAMPLES OF INTERNAL QUANTITIES AND OPERATIONAL PROFILE 1) FORECASTS AND PREDICTION INTERVALS
Forecasting models were developed to forecast the load consumption of each building and its solar irradiation. For this purpose, the Regression Learner Application of MATLAB R was used to build and compare different forecasting models (e.g., linear regression models, non-linear regression models, regression trees, etc.). Among the various forecasting models, the GPR model [38] were chosen as forecasting models due to their ability to provide relatively accurate forecasts with smaller uncertainties. As a remark, the GPR models were developed specifically for the buildings in the case study. In practice, the BEMS may use other models for a building depending on the available data and building models.
The accuracies of the forecasting models are provided in Table 3 for reference. However, it is not easy to interpret and imagine the accuracy of the forecasting models without showing the forecasted values with the actual values. Therefore, Fig. 10 is provided, which shows not only the point forecasts but also the 95-% prediction intervals quantifying the forecast uncertainties. Fig. 10-a and Fig. 10-b shows example forecasts for load consumption. These forecasts were created at 12:01 a.m., and they provide the expected values and prediction intervals for the next 24 hours. Each of the prediction intervals shown contains 95 % of future load values. In the simulations, the upper bound of the prediction interval is treated as the maximum possible load, and the lower bound as the minimum possible load. For both buildings, less uncertainty in load consumption is observed from 1 a.m. to 6 a.m. when the residents are most likely sleeping. For the rest of the day, however, the uncertainty on the load consumption is considerable, as indicated by the wide prediction intervals.
A forecasting model was also developed for solar irradiation for the next 24 hours. Similar to the case of load consumption, the lower and upper bounds of the prediction intervals were treated as the minimum and maximum PV generation for the UA-MPC. Furthermore, because exogenous data (e.g., weather forecasts) are not provided in the case study, only historical solar irradiation data were used in developing the forecasting model. This limitation resulted in forecasts with higher uncertainties than what could be available in practice. To compensate, a model that forecasts solar irradiation for the next 30 minutes was also developed. Example forecasts using the 24-hour and 30-minute models are shown in Fig. 10-c and Fig. 10-d respectively. These examples were taken at 12:01 a.m. and 7:01 a.m., respectively.

2) EXAMPLES OF SHORTEST PATHS
In the simulation section, a r of 1 kW was used for generating candidate trades, and Eq. (27) was used to determine the SoC for each building. The resulting graphs used in the simulation consisted of approximately 2800 nodes for the grid-connected scenario and 5600 nodes for the isolated-neighborhood scenario. These graphs are too big to be shown in this paper, and therefore, only example shortest paths from the graph are shown in Fig. 11. Fig. 11-a shows two optimum paths. One path is the result of benchmark optimization, in which no trade in the next trading horizon happens. The second path is the result of candidate evaluation, in which the option of selling 2 kW in the market for the next trading horizon is evaluated. In this case, the difference between the lengths of the shortest paths quantifies the building's minimum selling price when selling 2 kW in the next trading horizon.
Similarly, 11-b shows the shortest path for the benchmark optimization and the shortest path for the candidate in which FIGURE 11. Shortest Paths representing the SoCs for the optimal operation of Building 1 as determined for 12:30 a.m. onwards (a) as compared to the optimal operation when 2 kW is sold to the grid in the next trading horizon; and (b) is 10 kW is bought from the grid in the next trading horizon.
10 kW is bought from the market. In this case, the difference between the lengths of the shortest paths quantifies the building's maximum buying price when buying 10 kW in the next trading horizon.
Note that, as described in the previous chapter, the cost of the trade was kept at zero when evaluating the cost of the shortest path during candidate evaluation.

3) EXAMPLES OF VICKREY-PRICE CURVES
The prices for candidate each candidate trade are determined for the next trading horizon. Then, the prices are collected and used to determine the Vickrey-price curve.
Examples of Vickrey-price curves for Building 2 are shown in Fig. 12. These curves highlight the difference between the curves produced from the deterministic MPC and the UA-MPC. Note that the curves Fig. 12-a were produced assuming the same battery SoC. The same applies to the curves in Fig. 12-b. As expected, the UA-MPC results in more conservative trading than the deterministic MPC. For example, it can be observed in Fig. 12-a that if deterministic MPC is used, Building 2 offers to inject up to 15 kW into the grid -as indicated by the negative buying offer from 12:31 a.m. to 12:45 a.m. Meanwhile, if the UA-MPC is used, the curve only allows to inject up to 13 kW of power for the same trading horizon. Another example can be observed in Fig. 12-b for trading between 9:01 a.m. to 9:15 a.m. Here, when deterministic MPC is used, Building 2 offers to sell energy by injecting between 1 kW to 8 kW. In contrast, when UA-MPC is used, Building 2 offers not to inject power into the grid but instead offers to draw between 2 kW to 15 kW from the grid.

4) OPERATIONAL PROFILE
The Vickrey-price curves from the two buildings are compared before the beginning of each trading horizon. The Vickrey-price curves, FIT, and electricity prices are then used to determine how the building will commit in the next time horizon. In the grid-connected scenario, there are four possibilities: 1) trade with each other in a peer-to-peer setup; 2) sell energy from the grid using the FIT at a specific power level; 3) buy energy from the grid using the grid price at a specific power level; or 4) do nothing. In the isolated-neighborhood scenario, only options (1) and (4) are possible. Note that in options (1), (2), and (3), a building acts as a committed or dispatchable market player. Fig. 13 provides an example of the buildings' activity as market players under the case study. Shown in Fig. 13 is the resulting profile of using the UA-MPC in the two buildings over one week in July (i.e., high-irradiation setting) under the grid-connected scenario. It can be observed from Fig. 13 that the buildings mostly buy energy from the grid to cover their energy needs as opposed to trading with each other. There are instances, however, where Building 2 is able to sell energy to Building 1: as in the case of July 18 and July 19, 2021 in Fig. 13. Note that shown week happens in the high-irradiation setting. In other seasons, it is expected that the buildings are less active in selling energy due to the lower solar irradiation.

B. VIOLATIONS AND COSTS 1) HIGH-IRRADIATION SETTING a: WEEK-LONG SIMULATIONS
The results of a week-long simulation for the high irradiation settings can be found on Fig. 14, Table 4, and Table 5.   Fig. 14 shows that SoC limits were properly respected. However, using the perfect-forecast MPC is impossible in practice. Therefore, the profile produced by the perfect-forecast MPC is only provided here as an ideal benchmark. For the deterministic MPC, the SoC profile relatively follows the ideal benchmark. However, the deterministic MPC led to violations of the SoC limits in both buildings. These violations may be detrimental to the battery's health. If the SoC reaches zero, the violations may lead to the violations of the buildings' market commitment or forced load curtailment inside the building. For the robust MPC, Fig. 14 shows that SoC limits were respected, as supported by the values of the SoC-violation index in Table 4. However, the resulting profile from the robust MPC is far from the ideal benchmark. Moreover, the robust MPC resulted in less utilization of the battery capacity, limiting the operation to SoCs above 0.6 while the minimum limit is 0.2. This further reduction in the utilized range led to higher operational costs, as shown in Table 5. In contrast, the proposed UA-MPC avoided the violations of the SoC violations while utilizing   With more battery utilization, the UA-MPC produced lower costs compared to those of robust MPC, as shown in Table 5. As a remark, it can be observed in Table 4   However, there are still outliers in which the UA-MPC and robust approaches were not able to eliminate the violations. These outliers resulted from realizations of load consumption or solar irradiation that are outside the prediction intervals used in the UA-MPC. Note that the prediction intervals used here only contain 95% of the future values. If a random value of the solar irradiation or load consumption in the simulation falls outside the prediction interval used in the UA-MPC, then violations of the SoC limits may occur. Fig. 16 shows the distribution of the cost index from the Monte-Carlo simulations. The results show that both UA-MPC and robust MPC resulted in operating costs that are higher than the deterministic MPC. Nevertheless, for the grid-connected scenario, it is clear that the UA-MPC resulted in costs that are significantly lower compared to those of robust MPC -highlighting the benefits of using UA-MPC over the robust MPC. For the isolated neighborhood case, however, the figures for both buildings show a significant overlap between the costs of robust MPC and UA-MPC. In some instances, robust MPC resulted in costs that were even lower than the deterministic MPC. These instances are due to the additional income that a building receives from the pessimistic operation of the other building. For example, there are instances in which Building 1 is willing to pay a higher price to buy energy from building 2 because Building 1 is anticipating worst-case conditions -resulting in higher income for building 2.
2) LOW-IRRADIATION SETTING a: WEEK-LONG SIMULATIONS Figure 17 shows the SoC profile for the batteries of the two buildings for one week in January, in which there low VOLUME 10, 2022   irradiation. From the profiles, it can be observed that the deterministic MPC resulted in violations of the SoC limits in Building 1. In contrast, both robust MPC and the proposed UA-MPC were able to respect the SoC limits. The violation indices listed in Table 6 confirm this observation, highlighting the advantage of the proposed UA-MPC over deterministic MPC.
Furthermore, Figure 17 shows that profiles of the different MPC approaches did not deviate from each other as much as in the case of the high-irradiation setting. It is therefore not surprising that the operational costs in Table 6 for this scenario are closer to each other than in the high-irradiation setting.

b: MONTE-CARLO SIMULATIONS
For the low-irradiation setting, the results of the Monte-Carlo simulation regarding the SoC violations and costs are shown in Fig. 18 and Fig. 19 respectively. Figure 18 shows that the robust and UA-MPC indeed eliminated the SoC violations that would have occurred if the deterministic MPC was used. Nevertheless, if Fig. 15 and Fig. 18 are compared, there are less SoC violations in the low-irradiation setting than in the high-irradiation setting. This reduction in violations can be attributed to the fewer trades in the low-irradiation setting due to limited self-generation.
Moreover, Fig. 19 shows the distribution of costs from the Monte-Carlo simulation. For the grid-connected case, the deterministic MPC, robust MPC, and UA-MPC resulted in a similar cost for Building 1. For Building 2, the robust MPC resulted in relatively higher costs. For the isolatedneighborhood case, the three MPC approaches resulted in similar costs, with the robust MPC having a higher median than the other two.

3) SUMMARY
In summary, the results from the one-week and Monte-Carlo simulations show that the proposed UA-MPC avoids the violations of the SoC limits without significantly increasing the costs. These SoC limits were violated if the deterministic MPC was used, highlighting the benefits of using the proposed UA-MPC. The violations can also be avoided using the robust MPC. However, the robust MPC led to lower battery utilization and generally higher costs.
In the high-irradiation setting, the advantage of the UA-MPC is more pronounced. One reason is that there is more self-generation to manage during high-irradiation settings and the buildings are more active in selling energy.

C. RUNTIME
Lastly, the performance of the UA-MPC was evaluated using the curve preparation time. As defined in the previous section, the curve preparation time must be less than the trading horizon (e.g., 15 minutes) for the proposed UA-MPC to be applicable in an intraday market setting.    which is much shorter than the trading horizon and allows a big margin for the time needed for communication and for the market operator's decision making.
Meanwhile, Fig. 20-b shows the spread of the curve preparation times with different values of SoC . As expected, the results show that the curve preparation time decreases as the SoC increases. This observation is also aligned with the expectations because a lower SoC produces a graph with more nodes and edges. Fig. 20-b indicates a tradeoff between the optimization accuracy and the curve preparation time. As the SoC is reduced, the discretization of the battery SoC becomes finer, and the results of the optimization become more accurate. However, the increase in accuracy comes with a higher curve preparation time.
For the case study, the preparation of the Vickrey curves requires a SoC that is not higher than 0.01 for Building 1 and not higher than 0.007 for Building 2. These numbers are calculated using from Eq. (27) for a Vickrey-price curve with a resolution of 1 kW and a trading horizon of 15 minutes. Fig. 20-b indicates that for the SoC of in both buildings, the curve preparation time is not more than 4 seconds, which is significantly lower than the trading horizon.

VII. CONCLUSION
In this paper, the UA-MPC is proposed. The UA-MPC allows a BEMS to consider the uncertainties in the forecasts when optimizing the operation of a residential building with solar PV and battery, and at the same time, allowing the building to participate in intraday energy markets. The optimization inside the MPC is formulated as an expected-value SPP that can be solved in polynomial time using well-established algorithms. In creating the graph for the SPP, the graph reduction technique is applied to eliminate edges that may lead to violations of constraints under worst-case conditions. The case study results have shown that disregarding uncertainties in the optimization, as in the case of deterministic MPC, will violate battery SoC limits when a building commits to buying or selling at a particular power level in an intraday market. In contrast, the proposed UA-MPC, which considers the uncertainties quantified through prediction intervals, prevents these violations without significantly affecting the costs. Moreover, robust MPC can also be used to prevent the violation of battery SoC limits. However, robust MPC led to higher costs than the UA-MPC due to the robust MPC's pessimistic nature. This observation has been made for both grid-connected and isolated-neighborhood scenarios.
Furthermore, it has been observed that the advantages of using UA-MPC are more pronounced during high-irradiation settings and grid-connected scenarios, in which the building is more active in selling energy, and there is more generation from the solar PV to manage. The results have also shown that the UA-MPC can prepare bidding curves within a few seconds using a personal computer, showing that the UA-MPC is fast enough for intraday-market settings.
Aside from the technical aspects, another motivation for the study is to help increase the participation of active residential buildings with PV-Battery systems in intraday energy markets. With its technical benefits, UA-MPC could help fulfill this motivation by building the confidence of aggregators and market operators in the ability of active residential buildings in energy trading and executing market commitments. Moreover, the proposed UA-MPC does not also require the building's residents to change their consumption patterns. On the one hand, this could be helpful in terms of public acceptance. On the other hand, the independence from load consumption patterns means that load flexibility is not the focus of this paper and has not been investigated deeply. Remarks have been provided regarding how the model can be extended to model load consumption flexibility. However, future work is still suggested to investigate the model's applications to residential buildings with numerous flexible loads (e.g., parking lots and charging points for EVs or large HVAC loads).
Furthermore, the proposed UA-MPC and its applications can be further investigated in future research to capture the 1) uncertainties in the market prices and 2) the role of the electrical network's limitations and electrical losses in local energy trading.