A Bilevel Optimization Model Based on Edge Computing for Microgrid

With the continuous progress of renewable energy technology and the large-scale construction of microgrids, the architecture of power systems is becoming increasingly complex and huge. In order to achieve efficient and low-delay data processing and meet the needs of smart grid users, emerging smart energy systems are often deployed at the edge of the power grid, and edge computing modules are integrated into the microgrids system, so as to realize the cost-optimal control decision of the microgrids under the condition of load balancing. Therefore, this paper presents a bilevel optimization control model, which is divided into an upper-level optimal control module and a lower-level optimal control module. The purpose of the two-layer optimization modules is to optimize the cost of the power distribution of microgrids. The function of the upper-level optimal control module is to set decision variables for the lower-level module, while the function of the lower-level module is to find the optimal solution by mathematical methods on the basis of the upper-level and then feed back the optimal solution to the upper-layer. The upper-level and lower-level modules affect system decisions together. Finally, the feasibility of the bilevel optimization model is demonstrated by experiments.


Introduction
With the vigorous development of renewable energy, the power system structure is becoming increasingly complex and huge, the number of distributed power resources in the distribution network is increasing, and the terminals on the microgrid user side are also various [1][2][3]. The traditional power purchase mode of distribution users in the main network is not adequate for the current power requirements [4][5][6]. In order to adapt to the new situation of continuous development and change, an intelligent microgrid consisting of photovoltaic power generation, a combined cooling heating and power system, an energy storage system and a response load is suggested in the literature [7]. In the microgrid, electrical energy is transmitted in both directions. That is, the electrical energy, according to the actual situation and demand, is able to be effectively transferred to the transmission network; it is not just a one-way transmission [8].
A common smart microgrid is an independent system composed of small-scale power generation and distribution systems, as shown in Figure 1, where the distribution system is composed of a distributed generation unit, energy storage, energy converter, related loads, Nowadays, with the access to a large number of terminals and the emergence of more users on the demand side, the data flow between electrical equipment terminals and monitoring and control centers, enterprises and power users as well as mobile terminals is growing rapidly [9][10][11][12]. Faced with these new power services and massive data, traditional relational databases have been unable to meet the requirements of efficient data processing. How to improve the efficiency of data processing and power distribution while ensuring the safe and stable operation of the entire power system has been widely valued in the industry [13][14][15][16].
In the deployment process of data processing, computing resources can be deployed simultaneously in the cloud and at the edge of the network, while edge computing is a new computing system and technology that sinks its computing power from the former to the latter to achieve real-time business, efficient data processing, application intelligence, security and privacy protection [17][18][19].
Edge computing has the advantages of a low latency, real-time and efficient data processing capacity [20], data security and privacy protection, personalized configuration and localized processing. It also meets the different application needs of power grid intelligence. Therefore, this paper proposes a bilevel optimization model for microgrid users based on edge computing, which is divided into an upper-level module and a lowerlevel module. The purpose of the bilevel optimization model is to optimize the power distribution of the microgrid. The decision variables of the microgrid are set in the upperlevel module while the optimal solution of the upper-level module is calculated through mathematical methods in the lower-level module. The optimal solution is also fed back to the upper-level module and influences the decision variables. The upper-level and the lower-level affect each other. The combined modules determine the cost-optimal control decision of the microgrid under the load balance condition.
The contributions of this paper are summarized as follows:

1.
We put forward a bilevel optimization model, aiming to realize the cost-optimal control decision under the condition of load balancing for microgrid users. The model consists of an upper-level module and a lower-level module.

2.
We introduce the modeling process of both the upper-level module and the lower-level module and the model solution procedure in detail. The purpose on the two-layer optimization modules is to optimize the cost of power distribution of microgrids.

3.
Extensive simulations are conducted to demonstrate the proposed bilevel optimization model. The results indicate that the proposed model is feasible for the control decision of power distribution of microgrid users.
The remainder of the paper is organized as follows. Section 2 describes the background knowledge of the Dijkstra algorithm. Section 3 illustrates the presented bilevel optimization model in detail. Section 4 introduces the model solution procedure. The experimental results obtained from simulation are given in Section 5. Finally, the paper is concluded in Section 6.

Dijkstra Algorithm
Inspired by the idea of the greedy algorithm, the Dijkstra algorithm is widely used to obtain the optimal solution of the shortest route problem [21]. The Dijkstra algorithm needs to calculate the shortest distance between all user nodes. The details are as follows.

1.
First, the parameters are initialized: start node i = 1, 2, 3...n, destination node j = 1, 2, 3...n, intermediate variable d i,j = l i,j , where d i,j represents the intermediate value of the shortest distance solution process and l i,j denotes the distance between adjacent nodes i and j. If the two nodes are nonadjacent, set l i,j = +∞. Initialize m i,j = +∞, where i = j and m i,j is the shortest distance from node i to node j. This shortest distance includes the distances passing through intermediate nodes.

2.
Second, compare all distances between adjacent nodes i and j ( i = j) and let m i,j = min{d i,j }, where j = 1, 2, 3...n. For all j = 1, 2, 3...n, if d i,j = m i,j = +∞, set N i,j = j, where N i,j is an intermediate variable. N i,j = j indicates that the node j has been compared with node i. For all j = 1, 2, 3...n, if N i,j = j, let d i,j = min{m i,k + l k,i , d i,j }, where intermediate node k = 1, 2, 3...n, m i,k is the shortest distance from node i to node k and l k,i denotes the distance from intermediate node k to the adjacent node i.

3.
Next, judge whether all N i,j = j, where j = 1, 2, 3...n. If not, recompare all new distances l i,j except the distance of node N i,j . Otherwise, check whether i is more than or equal to n. If so, the algorithm ends; if not, let i = i + 1 and reinitialize the parameters: d i,j = l i,j , m i,j = +∞, where j = 1, 2, 3...n and i = j. Then, continue to execute the algorithm.

Bilevel Optimization Model
To realize cost-optimal microgrid control decisions under load balance, a bilevel optimization model for a microgrid is put forward in this paper, as shown in Figure 2. The upper-level module mainly establishes the electricity consumption behavior model of microgrid users according to the users' behavior parameters such as electricity consumption, electricity sale, electricity transmission, electricity consumption time and so on. It considers the comprehensive cost in the process of power grid planning, and then the selection of microgrid nodes is analyzed from the perspective of economic indicators. The lower-level module is mainly to find the optimal solution for the path selection in the network [22,23].  In the bilevel optimization model, the upper-level and lower-level modules are interconnected through intermediate variables, and each module has its own objective function and constraints. The two-layer optimization modules are modeled as follows: where F(·) is the upper-level objective function, α inv and s are the decision variables of the upper-level module, with the caveat that s is affected by the lower-level module, and G(·) and H(·) represent the inequalities and constraints of the upper-level module, respectively. The lower-level module is modeled as follows: where s(·) represents the lower-level objective function, α inv and α nd are the decision variables of the lower-level module, with the caveat that α inv is affected by the upperlevel module, and g(·) and h(·) denote the inequalities and constraints of the lower-level module, respectively. The overall objective function is shown in Equation (3): where λ 1 , λ 2 , · · · , λ n are weight ratios from 0 to 1 and λ 1 + λ 2 + · · · + λ n = 1. The value of λ 1 , λ 2 , · · · , λ n is changed by decision-makers according to the emphasis of different objectives. The purpose of the two-level optimization modules is to optimize the power distribution of the microgrid users. The upper-level module sets the decision variables for the lower-level module. The upper-level module needs to calculate the weight ratio between the attribute values of the microgrid users so that the optimal solution is able to be found in the lower-level optimization module. After the optimal solution is fed back to the upperlevel module, it also affects the decision variables simultaneously. The upper-level and lower-level modules influence each other.

Upper-Level Module
The upper-level module is based on the optimization of the comprehensive cost of power distribution at the user node of the microgrid as the objective function, involving parameters of the cost of purchasing electricity, the cost of selling electricity and the cost of electricity transmission. Taking into account the attributes of each user node graph in the microgrid [24] and the economic benefits of the operation of the distribution network [25], the upper-level objective function is represented in Equation (4): where F total is the comprehensive cost of the distribution network, C SA is the electricity purchasing cost between consumers, C ST is the electricity selling cost and C TR is the electricity transmission cost. The details are as follows. 1.
The electricity purchasing cost for consumers is represented in Equation (5): where E pr t is the electricity price at time t and P τ is the exchange power between different microgrids in the τ(τ = 1, 2, 3, 4) season.

2.
The electricity selling cost is defined in Equation (6): where E pr t is the electricity price at time t, P pv t is the photovoltaic power generation at time t and ∆P pv t is the deviation value of photovoltaic power generation at time t.

3.
The transmission cost is demonstrated in Equation (7): where W sre is the value of the meter on the input side, W f re is the value of the meter on the output side and γ is the normalization factor.
In addition, the two-level optimization model in the distribution network should also meet the following series of equations and constraints.

1.
The line power constraint is defined in Equation (8): where P K is the line power and P MAX is the maximum allowable line power, which is a fixed value determined when the transmission line is constructed.

2.
The electric power constraint of the microgrid is shown in Equation (9): where P E is the electrical power output of the microgrid, P M_A is the purchased power of the consumers, P CH is the amount of electricity converted by the photovoltaic inverter, P REG_sel f is the self-consumption of microgrid distributed renewable energy and P CT is power consumption.

3.
The microgrid price constraint is presented in Equation (10): where E The microgrid cost constraint is defined in Equation (11).
We see that if the electricity price is less than E prt_med , the electricity price is inversely proportional to the transmission cost, and the higher the electricity price, the lower the transmission cost. If the electricity price is greater than E prt_med , the electricity price is directly proportional to the transmission cost, and the higher the electricity price, the higher the transmission cost.

Lower-Level Module
The main consideration in the upper-level optimal control module was the comprehensive cost. It mainly analyzed the selection of microgrid nodes from the economic indicators. While in the lower-level module, the main goal is to calculate the optimal solution of the path selection through the graph-based path-search algorithm.

1.
After the modeling and operation of the upper-level module, we obtain the weight values between the microgrid user nodes. Then, these weight values are combined into a digraph matrix. The lower-level objective function is defined in Equation (12).
The corresponding lower-level constraints are as follow (14): where "0/1" represents whether the edge of the node of the directed graph exists, which constitutes a constraint graph.

Model Solution
First, according to the original data of microgrid users, the electricity purchasing cost, electricity selling cost, electricity transmission cost and other parameter values are calculated, and then they are normalized. Second, the optimal solution of the upper model and the weight proportion of each power price parameter is calculated. Next, the optimal solution is obtained through Dijkstra's algorithm [21,26,27], and finally the optimal distribution scheme is given.
The normalization equation is defined as (15). (15) where C x is the current cost value (such as C SA , C ST and C TR ), C max is the maximum of current cost and C min is the minimum of current cost. Thus, we obtain the comprehensive cost of the distribution network (i.e., solution of the upper-level objective function): where C SA − x , C ST − x and C TR − x are all calculated according to Formula (15).
Then, the weight ratios (λ 1 , λ 2 , · · · , λ n ) are obtained via Equations (17)- (19): If we set the start node as A and select the adjacent node as B on any branch of the destination node, the weighted objective function value J F total _x (i.e., the overall objective function) from A to B is obtained via Equation (20): (20) where C A·SA_x is the electricity purchasing cost of node A, C B·ST_x is the electricity selling cost of node B and C AB·TR_x is the electricity transmission cost between node A and node B.
After we calculate the weighted objective function value J F total between all adjacent nodes, we obtain the digraph matrix Γ.
Last, the best solution is found through Dijkstra's algorithm, introduced in Section 2.1.

Simulated Results
To verify the feasibility of the bilevel optimization model for the microgrid proposed in this paper, we designed the following simulation experiment.
Then, according to the weight ratio Equations (17)- (19), we obtained the optimal weight ratios as λ C SA_X = 0.368, λ C ST_X = 0.407 and λ C TR_X = 0.223. The weight ratios corresponding to different C SA , C ST and C TR are demonstrated in Table 2.  In addition, we calculate the weighted objective function value of microgrid users with Equation (20), as shown in Table 3. Where "inf" means that there is no direct connection between the two nodes, i.e., the two nodes are in an unreachable state. In this case, the weight ratio between the parameters is 1:1:1.
If setting Bridget as the start node and Doug as the destination node, from Table 3 and Figure 3, we find that there are five paths from Bridget to Doug, i.e., five schemes in total as presented in Table 4. Then, from Tables 3 and 4, we get the total weighted objective function value on the five paths, as shown in Figure 6.  Figure 6, we see that the weighted comprehensive cost of scheme 1 corresponding to parameter group 7 is minimal. Thus, it is the optimal solution from Bridget to Doug, that is, when C SA = 0.28, C ST = 0.31 and C TR = 0.17, the comprehensive cost is optimal from Equation (4). In addition, from Figure 6, for the scheme recommendations with fixed parameters, scheme 2 is the optimal option for the second group of parameters, and scheme 3 is the optimal option for the fifth group of parameters. 15

Conclusions
To realize the cost-optimal control decision of microgrids under the condition of load balance, this paper proposed a bilevel optimization model for microgrid users based on edge computing. The modeling process of both the upper-level module and the lower-level module was introduced in detail. The model solution was also provided. Finally, the experimental results indicated that the presented bilevel optimization model was feasible for the control decision of power distribution of microgrid users.
In the follow-up work, we will further optimize the bilevel model, for instance, considering more complex microgrid structures, more user nodes and more parameters. In addition, we think that it is meaningful to analyze the impact of different attributes of each user on the performance of the bilevel model.

Data Availability Statement:
The data used to support the findings of this study are included within the article.