Hour-Ahead Energy Trading Management with Demand Forecasting in Microgrid Considering Power Flow Constraints

: Multiple small-scale low-voltage distribution networks with distributed generators can be connected in a radial pattern to form a multi-bus medium voltage microgrid. Additionally, each bus has an independent operator that can manage its power supply and demand. Since the microgrid operates in the market-oriented mode, the bus operators aim to maximize their own beneﬁts and expect to protect their privacy. Accordingly, in this paper, a distributed hour-ahead energy trading management is proposed. First, the beneﬁt optimization problem of the microgrid is solved, which is decomposed into the local beneﬁt optimization sub problems of buses. Then, the local sub problems can be solved by the negotiation of operators with their neighbors. Additionally, the reference demand before negotiation is forecasted by the neural network rather than given in advance. Furthermore, the power ﬂow constraints are considered to guarantee the operational stability. Meanwhile, the power loss minimization is considered in the objective function. Finally, the demonstration and simulation cases are given to validate the e ﬀ ectiveness of the proposed hour-ahead energy trading management.


Introduction
With resource exhaustion and environment deterioration, more and more renewable energy generation is being incorporated into the power grid [1][2][3]. However, renewable energy generation, such as wind and solar energy, has the inherent characteristics of randomness and intermittence [4][5][6]. The direct integration of distributed renewable energy into the grid will cause the mismatch of power and finally result in instability. This motivates the development of the microgrid. Actually, the microgrid [7][8][9][10] is a small-scale power distribution system, which is composed of distributed power sources and neighbor loads. When compared with the traditional power grid, the microgrid has several advantages. First, the microgrid can be virtually self-sufficient, which will reduce the long-distance transmission loss. Second, these distributed renewable energy generations can be well used and managed in microgrid. However, in the traditional centralized scheduling of power grid, the renewable energies cannot be fully utilized. Thus, the study of microgrid operation is necessary.
In the microgrid, there are operations for different time periods, namely, the real-time, short-term, mid-term, and long-term [11]. Especially, the hour-ahead operation, which belongs to the short-term operation, may affect the unit commitment [12,13], economic dispatch [14], demand side management [15], spinning reserve scheduling [16], and so on. In the microgrid hour-ahead operation, the demand forecasting plays an important role. Actually, there are various demand forecasting approaches [17], including the multiple regression, fuzzy logic, expert systems, artificial neural networks (ANNs), and so on. Among these demand forecasting methods, the ANN [18][19][20] The ANN method is used to forecast the demand of LV distribution networks. The hourly forecast results participate in the energy trading as the desired reference demand. This ensures that the final trading decision will not deviate too far from the forecasted demand; • The power loss minimization is added to the objective function. Additionally, the power flow constraints are also added to the optimization problem. Therefore, in the iteration of optimization, the microgrid operation is guaranteed to be within the allowable range; • The energy trading optimization problem is solved by decomposing it into local benefit optimization sub problems of the supplier and buses. The local sub problems can be solved by negotiation of operators only with their neighbors. The privacy of market participants is protected.
The paper is organized as follows. In Section 2, the microgrid system framework is introduced. Additionally, the power flow, demand forecasting, and optimization problems of the micro-grid are formulated. Section 3 applies the PCPM algorithm to solving the distributed energy trading management. Numerical examples to complement the theoretical analysis are provided in Section 4. Finally, the conclusion is stated in Section 5.

Proposed Microgrid System
In an islanded electricity supply network, multiple small-scale low voltage (LV) distribution networks can be connected in a radial pattern to form a multi-bus medium voltage microgrid, which is shown in Figure 1. Each bus has an independent operator that can manage its power supply and demand. The operators are equipped with an advanced metering infrastructure that enables bidirectional communication among buses. In this radial microgrid, the fuel/gas generator is the main supplier. The renewable generators, such as wind power generators and solar power generators, can only supply local demand. The operators of buses take the responsibility of purchasing electricity from upstream suppliers and selling electricity to local users or downstream buses. These operators can be called retailers in microgrid. negotiation of operators only with their neighbors. The privacy of market participants is protected.
The paper is organized as follows. In Section 2, the microgrid system framework is introduced. Additionally, the power flow, demand forecasting, and optimization problems of the micro-grid are formulated. Section 3 applies the PCPM algorithm to solving the distributed energy trading management. Numerical examples to complement the theoretical analysis are provided in Section 4. Finally, the conclusion is stated in Section 5.

Proposed Microgrid System
In an islanded electricity supply network, multiple small-scale low voltage (LV) distribution networks can be connected in a radial pattern to form a multi-bus medium voltage microgrid, which is shown in Figure 1. Each bus has an independent operator that can manage its power supply and demand. The operators are equipped with an advanced metering infrastructure that enables bidirectional communication among buses. In this radial microgrid, the fuel/gas generator is the main supplier. The renewable generators, such as wind power generators and solar power generators, can only supply local demand. The operators of buses take the responsibility of purchasing electricity from upstream suppliers and selling electricity to local users or downstream buses. These operators can be called retailers in microgrid.

Power Flow Constraints
If only active power is considered in the scheduling of the microgrid, and other power flow parameters, such as reactive power, voltage, current, and so on, are ignored, the schedule results may violate the stable operation conditions of the microgrid. Therefore, power flow constraints play an important role in scheduling of the microgrid.
The radial distribution network of the microgrid is modeled as a directed tree graph ∶= ( , ). The buses in set are indexed by = 0,1, … , . Additionally, the distribution line, which connects bus i and bus j, is denoted as ( , ) ∈ . The main supplier, the fuel/gas generator, is indexed as bus 0. It is the slack bus, which means its voltage is fixed as and it will supply active and reactive power ( , ) to balance the electricity demand. For each bus ∈ \{0}, is its complex voltage and = + is its complex power injection. If the bus has renewable generators, is the demand minus generation. For each line, ( , ) ∈ , is the complex current from bus i to bus j.
= + is the

Power Flow Constraints
If only active power is considered in the scheduling of the microgrid, and other power flow parameters, such as reactive power, voltage, current, and so on, are ignored, the schedule results may violate the stable operation conditions of the microgrid. Therefore, power flow constraints play an important role in scheduling of the microgrid.
The radial distribution network of the microgrid is modeled as a directed tree graph T := (N, E). The buses in set N are indexed by i = 0, 1, . . . , n. Additionally, the distribution line, which connects bus i and bus j, is denoted as (i, j) ∈ E. The main supplier, the fuel/gas generator, is indexed as bus 0. It is the slack bus, which means its voltage is fixed as V 0 and it will supply active and reactive power (p 0 , q 0 ) to balance the electricity demand. For each bus i ∈ N\{0}, V i is its complex voltage and s i = p i + q i is its complex power injection. If the bus has renewable generators, s i is the demand minus generation. For each line, (i, j) ∈ E, I ij is the complex current from bus i to bus j. z ij = r ij + ix ij is the impedance, and S ij = P ij + iQ ij v is the complex power that flows on the distribution line (i, j). These notations are illustrated in Figure 2. Given a radial distribution microgrid, the branch flow model [28,29] is as follows: In order to simplify the notations, = | | , = | | . = − * / * can be derived from Equations (2) and (3). If it is squared, then we can get the branch flow model without phase angle of voltage and current Reference [28] verifies that if ( , , , ) is given, the unique phase angle of the radial network can be determined.

Demand Forecasting Using Artificial Neural Network Method
In the energy trading, the accurate forecast of the demand can decrease the waste and maintain stable operation of the power grid. Compared with conventional methods, artificial neural network (ANN) can forecast the demand with higher accuracy. In this paper, the ANN structure is shown in Figure 3. It is a single hidden layer network. In the hidden layer, there are 20 neurons and the activation function is a tansig function. In the output layer, the activation function is a linear function. The training method is Levenberg-Marquardt algorithm. The ANN is trained and tested on a publicly available set of real electricity demand data from the ISO-NE [32]. We extract historical hourly electricity demand data of three zones from 1 January 2016 to 31 December 2018. The hourly weather data of these zones can also be acquired from the ISO-NE. After the preparation of data, the inputs of the training include: • The dry bulb and dew point temperature;

•
The hour and the day; • The label of holiday/weekend; • The average demand of previous day; • The demand from the same hour the previous day; • The load from the same hour and same day from the previous week. Given a radial distribution microgrid, the branch flow model [28,29] is as follows: In order to simplify the notations, (2) and (3). If it is squared, then we can get the branch flow model without phase angle of voltage and current Reference [28] verifies that if (P, Q, l, v) is given, the unique phase angle of the radial network can be determined.

Demand Forecasting Using Artificial Neural Network Method
In the energy trading, the accurate forecast of the demand can decrease the waste and maintain stable operation of the power grid. Compared with conventional methods, artificial neural network (ANN) can forecast the demand with higher accuracy. In this paper, the ANN structure is shown in Figure 3. It is a single hidden layer network. In the hidden layer, there are 20 neurons and the activation function is a tansig function. In the output layer, the activation function is a linear function. The training method is Levenberg-Marquardt algorithm. The ANN is trained and tested on a publicly available set of real electricity demand data from the ISO-NE [32]. We extract historical hourly electricity demand data of three zones from 1 January 2016 to 31 December 2018. The hourly weather data of these zones can also be acquired from the ISO-NE. After the preparation of data, the inputs of the training include: • The dry bulb and dew point temperature;

•
The hour and the day; • The label of holiday/weekend; • The average demand of previous day; • The demand from the same hour the previous day; • The load from the same hour and same day from the previous week. The data set of years 2016 and 2017 is used to train the ANN. The training set is used for building the model (estimating its parameters). Once the neural network model is built, we can use it to forecast the next hour demand with the eight inputs. The forecasted output result can be compared with the real data from 2018. Then, we can test the performance of the model on out-of-sample data. The performance will be shown in the simulation part. The final hour-ahead forecast output is used as the reference demand of bus i, ̂ .

Social Utility Maximization
The social utility of the MV microgrid is defined as the profit of LV distribution networks minus the cost of generation. The objective of the microgrid is to maximize the social utility, which is shown in Equation (8). In (8), the power flow constraints are also considered. Therefore, minimization of the power loss of transmission lines can be added to the objective.
In the Equation (8), is the retail electricity price of bus i. Even if consumers of buses own controllable applications, α is penalty coefficient of the difference between reference demand ̂ and final supply . The initial reference demand ̂ can be obtained by the ANN method. C( ) is the cost function of the fuel/gas generator. It is indicated by a quadratic function [33] C( ) = + + , where > 0, , ≥ 0 are varying fuel/gas coefficients. The parameter is used to represent the fixed hourly cost of renewable generators at bus j. The coefficient can adjust the weight of the power loss term.
(9) can be converted to a second-order cone constraint as follows: The data set of years 2016 and 2017 is used to train the ANN. The training set is used for building the model (estimating its parameters). Once the neural network model is built, we can use it to forecast the next hour demand with the eight inputs. The forecasted output result can be compared with the real data from 2018. Then, we can test the performance of the model on out-of-sample data. The performance will be shown in the simulation part. The final hour-ahead forecast output is used as the reference demand of bus i,p i .

Social Utility Maximization
The social utility of the MV microgrid is defined as the profit of LV distribution networks minus the cost of generation. The objective of the microgrid is to maximize the social utility, which is shown in Equation (8). In (8), the power flow constraints are also considered. Therefore, minimization of the power loss of transmission lines can be added to the objective.
In the Equation (8), λ i is the retail electricity price of bus i. Even if consumers of buses own controllable applications, α is penalty coefficient of the difference between reference demandp i and final supply p i . The initial reference demandp i can be obtained by the ANN method. C(p 0 ) is the cost function of the fuel/gas generator. It is indicated by a quadratic function [33] ≥ 0 are varying fuel/gas coefficients. The parameter C jr is used to represent the fixed hourly cost of renewable generators at bus j. The coefficient ρ can adjust the weight of the power loss term.
The quadratic Equation (7) is a constraint in (8). Because it is non-affine, (8) is not convex. Reference [28] relaxes it into an inequality constraint, which can convex the power flow constraints.
(9) can be converted to a second-order cone constraint as follows: Then, the convex optimization function of microgrid utility maximization is function (8) with substitutional constraint (9).
The validity conditions for the relaxation is proposed in [28]. In the paper, it is easy to satisfy the conditions considering the structure of the microgrid.
After the second-order cone relaxation, the objective function becomes convex, which can be solved centrally. However, a control center is needed to take the responsibility of global control; it requires detailed information of the microgrid, which causes privacy issues. With market-oriented reform, operators of buses aim to maximize their own benefits and expect to protect their privacy during trading. Therefore, the microgrid social utility maximization problem needs to be solved using distributed mechanisms.

Introduction of Predictor Corrector Proximal Multiplier Method
Predictor corrector proximal multiplier (PCPM) [30,31] is a method to solve convex minimization problems in the decomposition approach. Considering a convex problem in the generic form The Lagrangian of this problem is where y is the Lagrangian multiplier.
The distributed algorithm can be written as where λ k is a positive scalar. In this algorithm, p k+1 is the predictor step, y k+1 is the corrector step, and x k+1 , z k+1 are separable proximal steps. After iterations, the PCPM method will converge to a global optimal solution.

Distributed Solution Method
The variables in the function (8) with substitutional constraint (9) can be decoupled and computed separately from each other using the PCPM method. Lagrange multipliers µ i are associated with the active power equation constraints. They can be used to decompose the objective function of microgrid to sub problems that can be solved locally. Lagrange multiplier µ i can be treated as a price guidance signal. It is not the real electricity price, because of the power loss term in the objective function. The sub problems solved by supplier and buses are defined in the following section.

Solving Supplier Cost Minimization
As a supplier of the microgrid, the supplier sells electricity to its users. According to the cost of generation and the demand of its users, the supplier will design an appropriate price to maximize its own utility. The objective function of the supplier is presented as function (10).v i is the estimation of children node voltages. The coefficient ω i is the Lagrange multiplier associated with the voltage estimation. x * is the optimization of the last iteration.

Solving Buses Utility Maximization
Buses except the slack bus will buy electricity from its upstream supplier. If it has child nodes, it will sell electricity to downstream buses. Therefore, buses are separated into two kinds. One is the leaf nodes, which have no child node. The other is the nodes that have child nodes. The utility maximization problems of these two kinds of nodes are as follows: • Bus i ∈ N\{0}, such that (i, j) ∈ E, j ∈ N\{0} solves the following problem: • Bus i ∈ N\{0}, such that (i, j) E, for all j ∈ N\{0}, solves the following problem:

Algorithm Design and Implementation
According to the PCPM method, buses will solve their utility maximization locally. The distributed energy trading algorithm is presented in Algorithm 1.

1.
The slack bus 0 chooses initial values for variable set x and Lagrange multipliers λ i for its child nodes such that (0, i) ∈ E. Each bus i ∈ N\{0} such that (i, j) ∈ E, j ∈ N\{0}, chooses initial values for variable set y and Lagrange multipliers λ j for its child nodes such that (i, j) ∈ E. Each bus i ∈ N\{0} such that (i, j) E, for all j ∈ N\{0}, chooses initial values for variable set z.

3.
Each bus j ∈ N\{0} transmits its demand p j and voltage v j to its parent node i ∈ N, (i, j) ∈ E. The parent node i will update the Lagrange multipliers as follows: Each parent node sends the updated Lagrange multipliers to its child nodes.

5.
Each bus j ∈ N\{0} transmits its demand p j and voltage v j to its parent node i ∈ N. The parent node i will update the Lagrange multipliers as follows: 6. k ← k + 1 , return to step 2.

Evaluation
Most of microgrids are carried out by simulation, which is difficult to perform in a real situation. Considering the fact, in this section, numerical examples are provided to complement the analysis. In order to make the demonstration and simulation more reliable, the work is verified by simulation based on the real data. The simulation is implemented to a medium-voltage microgrid distribution network, as shown in Figure 4. There are four buses. Bus 0 is the slack bus that connects to a fuel/gas generator. The voltage of it is 4.16 kV, which refers to the IEEE 13 Node Test Feeder system. The cost function of the generator is C(p 0 ) = 0.8p 2 0 + 10p 0 . Its generation limit is p 0 ∈ [2MW, 7MW]. The other three buses provide electricity to LV distribution networks respectively. And a wind turbine is connected to bus 2. The hourly wind power generation data is retrieved from independent electricity system operator (IESO) [34]. The fixed cost is assumed to be $1 for one hour. The distribution line parameters are listed in Table 1. In order to better explain the detailed process of evaluation, a block diagram is presented in Figure 5.

Demand Forecasting Results
The demands of LV distribution networks announced by operators are forecasted by ANN method using real historical electricity data and weather information. The ANN is trained in MATLAB using the neural network toolbox. Figure 6a, b shows the comparison of the actual demand and the forecasted demand. Figure 6a shows the results from a whole year while Figure 6b shows the results from 2 weeks. The error distribution is presented in Figure 6c, d. The mean absolute error (MAE) is 30.67 kWh, and mean absolute percent error (MAPE) is 2.3%. The hour-ahead forecasted demand ̂ of 3 LV distribution networks is accurate enough to be used as the reference demand in trading.

Demand Forecasting Results
The demands of LV distribution networks announced by operators are forecasted by ANN method using real historical electricity data and weather information. The ANN is trained in MATLAB using the neural network toolbox. Figure 6a, b shows the comparison of the actual demand and the forecasted demand. Figure 6a shows the results from a whole year while Figure 6b shows the results from 2 weeks. The error distribution is presented in Figure 6c, d. The mean absolute error (MAE) is 30.67 kWh, and mean absolute percent error (MAPE) is 2.3%. The hour-ahead forecasted demand ̂ of 3 LV distribution networks is accurate enough to be used as the reference demand in trading.

Demand Forecasting Results
The demands of LV distribution networks announced by operators are forecasted by ANN method using real historical electricity data and weather information. The ANN is trained in MATLAB using the neural network toolbox. Figure 6a,b shows the comparison of the actual demand and the forecasted demand. Figure 6a shows the results from a whole year while Figure 6b shows the results from 2 weeks. The error distribution is presented in Figure 6c

Energy Trading Results
Each LV distribution network uses ANN to forecast its demandp i for the next hour. The original system data withp i is shown in Tables 2 and 3. The retail prices of LV distribution networks are 21, 22, and 23, respectively. The power flow information is calculated by the MATPOWER [35]. Then, we tested the distributed algorithm mentioned above in MATLAB using the CVX toolbox. The penalty coefficient of the difference between initial demandp i and final supply p i , α i , was 10, 20 and 50, respectively, for each bus. The Lagrange multipliers for the active power equality constraints are depicted in Figure 7a. Because there is power loss term in the objective function, the Lagrange multipliers are not the real electricity price. They are called the shadow prices, and can be used as signals to coordinate the trade. Figure 7b is the real power demand and supply on each bus. The iterations of reactive power on lines are shown in Figure 7c. Figure 7d is the convergence of the social utility and power loss. The optimized system data are shown in Tables 4 and 5. Table 6 compares the cost and utility of the original system and the optimized system. It is clear that, after the optimization, the social utility is more and the power loss is less. Additionally, the distributed algorithm can achieve the optimization solution as the central algorithm.

Energy Trading Results
Each LV distribution network uses ANN to forecast its demand ̂ for the next hour. The original system data with ̂ is shown in Tables 2 and 3. The retail prices of LV distribution networks are 21, 22, and 23, respectively. The power flow information is calculated by the MATPOWER [35]. 0.3310 0.1909 Then, we tested the distributed algorithm mentioned above in MATLAB using the CVX toolbox. The penalty coefficient of the difference between initial demand ̂ and final supply , α , was 10, 20 and 50, respectively, for each bus. The Lagrange multipliers for the active power equality constraints are depicted in Figure 7a. Because there is power loss term in the objective function, the Lagrange multipliers are not the real electricity price. They are called the shadow prices, and can be used as signals to coordinate the trade. Figure 7b is the real power demand and supply on each bus. The iterations of reactive power on lines are shown in Figure 7c. Figure 7d is the convergence of the social utility and power loss. The optimized system data are shown in Tables 4 and 5. Table 6 compares the cost and utility of the original system and the optimized system. It is clear that, after the optimization, the social utility is more and the power loss is less. Additionally, the distributed algorithm can achieve the optimization solution as the central algorithm.  The optimized energy trading is compared with the original trading in 24 h, as depicted in Figure  8. We can see that the wind power generation has a great influence on the system utility. The more that wind generation is injected to the grid, the greater the social utility that is achieved. Moreover, the trading mechanism encourages trading during the low valley of electricity consumption and represses trading during the peak period. The peak cutting and valley filling performance of the proposed trading mechanism is beneficial for the microgrid.  The optimized energy trading is compared with the original trading in 24 h, as depicted in Figure 8. We can see that the wind power generation has a great influence on the system utility. The more that wind generation is injected to the grid, the greater the social utility that is achieved. Moreover, the trading mechanism encourages trading during the low valley of electricity consumption and represses trading during the peak period. The peak cutting and valley filling performance of the proposed trading mechanism is beneficial for the microgrid.

Conclusions
In this paper, a distributed energy trading management has been proposed to optimize the utility of a microgrid. When compared with existing publications, the demand of each LV distribution network is forecasted by the ANN method rather than given in advance. Additionally, in the optimization of energy trading, the power flow constraints and power loss minimization are included, rather than only the optimizing active power. The distributed PCPM algorithm guarantees that the operators in microgrid only need to negotiate with neighbors instead of sharing information to all. Finally, the simulation of a four-bus microgrid with practical data demonstrates the effectiveness of the proposed scheme.
It should be noted that the reactive power compensation is not considered in the energy trading management. Additionally, the trading in the LV distribution network of each bus is not included. In the future, the study of hierarchically distributed energy trading management with reactive power compensation can be continued.

Author Contributions:
The work presented in this paper is the output of the research projects undertaken by C.L. Specifically, K.F. and C.L. developed the topic. K.F. carried out the calculation and simulation, analyzed the results, and wrote the paper. Z.S. gave some suggestions on the calculation process.

Conclusions
In this paper, a distributed energy trading management has been proposed to optimize the utility of a microgrid. When compared with existing publications, the demand of each LV distribution network is forecasted by the ANN method rather than given in advance. Additionally, in the optimization of energy trading, the power flow constraints and power loss minimization are included, rather than only the optimizing active power. The distributed PCPM algorithm guarantees that the operators in microgrid only need to negotiate with neighbors instead of sharing information to all. Finally, the simulation of a four-bus microgrid with practical data demonstrates the effectiveness of the proposed scheme.
It should be noted that the reactive power compensation is not considered in the energy trading management. Additionally, the trading in the LV distribution network of each bus is not included. In the future, the study of hierarchically distributed energy trading management with reactive power compensation can be continued.