Cloud-Fog Computing-Based Distributed Event-Triggered Consensus Predictive Compensation for Optimal Energy Management in Microgrid under DoS Attack

. A cloud-fog computing-based event-triggered distributed energy optimization management method based on predictive attack compensation is proposed to address the problem of denial of service (DoS) attack, the complexity of computation, and the bandwidth constraint on the communication network in microgrids. Firstly, in order to optimize the energy supply of microgrid and maximize the proﬁt, the minimum cost function of maintaining the balance of supply and demand is given considering the power loss of microgrid. Secondly, considering the problem of bandwidth-constrained communication, a distributed event-triggered consensus algorithm is proposed based on fog computing. Thirdly, a model predictive compensation algorithm based on cloud computing is proposed, which uses the mismatched power between supply and demand at the historical time before the attack to predict and compensate the missing data of the agent power at the current time and many times after attack. Finally, the eﬀectiveness of the proposed method is veriﬁed by simulation results.

weakness of CPS, which means that the microgrid is also vulnerable to malicious network attacks. For now, the field of network attacks on the power system mainly consists of three branches, which are the Denial of Service (DoS) attack, replay attack, and False Data Injection (FDI) attack [12]. Among them, the DoS attack as a highly destructive attacking method brings about huge adverse impact on the security and stability of the microgrids. e study in [13] proposes a self-triggered consensus algorithm under the DoS attack. e proposed method can achieve the recovery of microgrid voltage and the equal distribution of reactive power, but the research is restricted to the perspective of energy.
e study in [14] proposes a rule-based fallback control strategy using the SoC (state of charge) of the distributed managed energy storage system to enhance the recovery capability when microgrids are under the DoS attack. However, the distributed structure results in the lack of communication among subsystems. From the perspective of attack and defense, [15,16] lucubrate the optimal attack and dynamic attack energy distribution of the system. However, the proposed method lacks optimal management of the system's energy. Based on the event-triggered communication method, [17,18] enhance the capacity of energy management of microgrids and at the same time alleviate the problem of bandwidth constraint on the communication network.
It is worth noting that the above literatures do not consider the problem of the system's computing capability. e smart grid always distributes a large number of sensors. is results in the generation of large-scale data from grid systems, while traditional hardware systems have difficulty in providing large-capacity data storage and computing capacity [19]. Since cloud computing can solve the above problems, it is welcomed by many researchers. However, most cloud computing models use centralized management methods to transmit and deal with data, which makes them unable to meet the requirements of the system boundary area for the minimum delay in real-time and semi-real-time applications and the model is limited by the bandwidth of communication. Besides, these methods also have the problems of large energy consumption and insufficient use of computing capability. e characteristics of the fog computing model for calculation analysis in the boundary network, such as low latency and high efficiency and scalability, complement the disadvantages of cloud computing. erefore, the combination of fog computing and cloud computing can effectively improve the stability of the smart grid [20].
To address the microgrid's energy optimization management problem in the case of DoS attack, this paper proposes a cloud-fog computing based distributed eventtriggered consensus energy optimization management method based on predictive attack compensation. e main work is as follows: (1) is paper proposes a distributed event-triggered consensus predictive compensation algorithm. e communication bandwidth of the system is reduced by the event-triggered method, and the missing data of microgrid is predicted by the prediction algorithm. We convert the missing communication data in microgrid into the power loss of the grid unit, which receives this data so that the power at the next moment can be predicted by tracking the history power data of unbalance between supply and demand before the attacking moment, and then the missing data caused by the attack can be obtained. By doing so, the consistency of each unit in the smart grid can be achieved. (2) is paper proposes a three-layered cloud-fog-object smart grid data processing architecture, which uses the cloud computing model to calculate the prediction data of the smart grid and the fog computing model to calculate the consistency of the smart grid to obtain the energy supply-demand balance of the smart grid as well as the minimum cost of optimization.
. . , ϖ n represents the degree matrix of G and ϖ i � L ii .

Energy Optimization Management.
In this paper, we try to solve the energy optimization management problem from the perspective of economy. By regarding each part of the microgrid as an agent i in multiagent framework, consistency between agents can be achieved. en, we translate the energy management problem into an optimization problem and solve it. Specifically, we try to find the solution of the following objective function, which can maximize the total gain of the microgrid.
where N G , N S , N R , and N L are the sets of generator, energy storage system, renewable energy, and load, respectively; W i 1 , W i 2 , W i 3 , and W i 4 are the welfare function of generator, energy storage system, renewable energy, and load, respectively; P i 1 , P i 2 , P i 3 , and P i 4 are the power consumption of generator, energy storage system, renewable energy, and load, respectively; P m i j and P M i j represent the minimum boundary and maximum boundary of power, respectively. Note that during the power transmission there exists power loss caused by many factors, for example, the reactance of a transmission line. We define the transmission efficiency of generator, energy storage system, renewable energy, and load as follows:

Mathematical Problems in Engineering
Since renewable energy is stochastic and intermittent, and as a kind of energy that is renewable, it is reasonable to assume that the price of it is stable. Considering these reasons, in this paper, we regard renewable energy as nondispatchable energy and consider its welfare as constant. Besides, the electrovalence of load in a power grid does not change correspondingly with power consumption. As a result, in this paper, we take the load as nondispatchable energy as well and its welfare is also set to constant. In this paper, we only consider the energy dispatch optimization problem of generator and energy storage system. e welfare function of a generator is where ρ 1 (t) is the power-on time of a generator and C i 1 (P i 1 ) is the generator's manufacturing cost, which can be expanded into where a i 1 , b i 1 , and c i 1 are positive parameters of the manufacturing cost of a generator. e welfare function of energy storage system is where ρ 2 (t) is the power-on time of the energy storage power and C i 2 (P i 2 ) is the charge-discharge energy consumption and degradation cost of the energy storage power, which can be expanded into where a i 2 and b i 2 are the cost coefficients of charge-discharge energy consumption of the energy storage power; ρ c is the degradation cost of the energy storage power. Substituting equations (3) and (5) into equations (1a)-(1c), we can transform the final objection from maximizing the welfare of the microgrid system into minimizing the cost of the generator and energy storage system. e objective function then turns into where N � (N G , N S ) is the element set of the generator and energy storage system; 4 is the power difference between renewable energy and load, which is a constant. With Karush-Kuhn-Tucker (KKT) conditions, the incremental Lagrange objective function of equations (7a) and (7b) can be written as where τ is the KKT multiplier.
By differentiating equation (8), we can know that equations (7a) and (7b) must have a constant solution τ * that satisfies where ∇C i (·) is the derivative of C i (·).

DoS Attack.
Considering the problem of bandwidth constraint in communication between agents in microgrid, in this paper, we reduce the quantity of information to be transferred with an event-triggered manner. As a result, the communication between agents is discretized. DoS attack as a simple and efficient attacking method has drawn massive attention. In real-world scenario, in view of attackers trying to remain hidden and the energy being used for attack is limited, DoS attack is set to a random sequential form. Here, we use θ i (t), which is a white noise random variable sequence that follows the Bernoulli distribution to represent whether the communication channel is under DoS attack. Without losing generality, we define θ i (t) � 1, which means that the system has not been attacked, while θ i (t) � 0 means the opposite. e mathematical probability of it satisfies where β i ∈ [0, 1] is a known constant, and all θ i (t) are independent from each other.

Distributed Event-Triggered Predictive Compensation
Control Scheme Designment. To solve the data-missing problem of communication between agents caused by DoS attack, in this paper, we try to mitigate the impact on agents caused by data missing from another perspective. e failure of receiving data from agent j will lead to the inability of agent i to calculate its control parameter τ i , which will further break the balance of power supply and demand of agent i. To avoid the coupling problem between agents caused by directly predicting the data of agent j, in this paper, we use the history data of agent i instead. To be specific, the history data being used here is the last moment's power data P i and unbalance parameter of supply and demand P i . In this paper, we use a cloud computing based predictive compensation algorithm to predict the power of agent i and then obtain its control parameter τ i . erefore, the problem of balance between power supply and demand of agent i and the problem of the transmission of control parameter τ i can be simultaneously solved. As for the smallscale data computing in the microgrid, we use fog computing to replace cloud computing to reduce the system's power consumption and delay. As shown in Figure 2, the proposed distributed eventtriggered predictive compensation control scheme is mainly made up of three parts, which are the power solving (fog computing), control parameter solving (fog computing), and model predictive control compensation (cloud computing), where the model predictive control compensation is made up of controller, predictor, and compensator. e control parameter obtains trigger parameter with event-triggered detector and the power solving chooses its control parameter τ Ai according to whether the DoS attack happens.

Fog Computing-Based Distributed Event-Triggered Predictive Compensation Control Scheme Algorithm.
To address the problems in microgrids such as (1) the bandwidth constraint on communication between agents, (2) privacy information of subsystems being hard to obtain, and (3) communication between agents being easy to be attacked by DoS attack, in this paper, we propose an event-triggered distributed consensus energy management optimizing algorithm based on attack compensation.
where Λ i is the projection operator and τ i is the KKT multiplier that represents the price parameter of each unit in microgrids; , represents the latest updated event-triggered signal of each agent i; t i k |k � 1, 2, . . . represents the event-triggered time when agent i passes status information to its neighbours.
where τ ci is the control parameter obtained by the predictive compensation control algorithm when agent i is under attack. When τ j which is data transferring from agent j to agent i is under attack, the proposed algorithm will convert the goal from predicting τ j to predicting agent i's power P Ai to ensure the balance between supply and demand of agent i and obtain the control input τ Ai according to the predictive model. It is worth noting that, in this paper, all θ i (k) are synchronous.
To mitigate the bandwidth constraint of the system's communication, we design the event-triggered function as follows: where ϖ i is the degree of agent i.
When trigger function f i (t) ≥ 0, agent i obtains information τ j from its neighbour agent j and then updates information i∈N w ij (τ i − τ j ). At the same time, agent i broadcasts its status information to its neighbours. e proposed distributed algorithm only needs to pass τ i between agents. e quantity of information to be transmitted is much fewer, which can reduce the cost of communication and improve the communication efficiency of the system.

Cloud Computing-Based Model Predictive Algorithm.
To obtain the missing data caused by the attack, we propose a cloud computing based predictive compensation control algorithm.
e proposed predictive cloud control mainly consists of predictive controller and compensator. e Mathematical Problems in Engineering predictive controller can predict r control sequences after the present moment k * and then the compensator chooses the latest predictive control sequence as the missing control input data at moment k. By reason of agent i being event-triggered, we predict the missing data discretely. Setting τ ci as u i (k), P i as x i (k), and P i as y di (k), the multiagent model can be represented as Supposing that the latest updated moment received by the present controller is k * , the agent can successfully output and the corresponding output is updated from y i (k) to y i (k * ). e predictive output of y i (k * ) is y i (k|k * ), where k � k * + l > k * and l � 1, 2, . . . , r. Supposing that all the agents are observable, to predict the information of agents on moment k, the system predicts the information from moment k * + 1 to moment k as To make output y i (k|k * ) track y di (k), here, we introduce a set of dynamic variables: e cloud computing based predictive control can be represented as where M i and L i are gain matrices with corresponding dimension. e predicted control input is As a result, the predicted control input of the system τ i (t) is obtained. Agent i can track the difference value of supply and demand balance mismatching P i with the proposed predictive compensation control algorithm and then obtain its actual power P comi . e corresponding input τ ci (t) can be further obtained and the communication between agents is successfully achieved. From equation (11a), we know that if the target power P i is constant, τ i (t) is also constant, which ensures the status of agent i not affected by attacks.

Convergence Analysis.
To prove the convergence of the proposed cloud-fog computing based event-triggered distributed consensus predictive compensation algorithm in the section titled "Fog Computing Based Distributed Event-Triggered Predictive Compensation Control Scheme Algorithm," we rewrite equations (11a)-(11c) as a compact set.
where Λ � Λ 1 × · · · × Λ n , τ, τ ⌢ A , z, η, P A , and ∇C(P) are the stacked volume vectors of is the equilibrium point of the proposed algorithm. Because the communication graph is connected, by premultiplying both sides of (19a) with (1 T n ⊗ I ι ), we can have the following equation: With respect to differential projection, we can know from equation (19a) that which means that the equilibrium point of algorithm (18a)-(18c) is equivalent to the optimization in (7a) and (7b). According to the differential projection, we have , π i (P Ai ) ≥ 0, and π i (P * Ai ) ≥ 0. Converting the equilibrium point of equations (19a)-(19c) to the original point, we have where Γ � [r, R] is an orthogonal matrix; with r T R � 0, R T R � I n− 1 , RR T � I n − rr T , r � 1/ � n √ , 1 n ∈ R, and R ∈ R n×(n− 1) , we have 6 Mathematical Problems in Engineering To prove the convergence of equations (24a)-(24e), here, we define a Lyapunov function as follows: where h > 0. Differentiating equation (25) and combining it with equations (24a)-(24e), we have en, by using Young's inequality, we have and, because τ because w ij � w ji , we have and, because the random variable τ Mathematical Problems in Engineering and then As a result, when Σ ≥ 0 and f i (t) ≤ 0, we can know that _ V < 0, which means that the algorithm converges to the optimum of optimization problem 7, and the proposition has been proved.

Simulation and Analysis
In this paper, we perform experiments on the IEEE-14 bus system to verify the effectiveness of the proposed cloud-fog computing based event-triggered distributed consensus predictive compensation algorithm. e microgrid is a kind of island mode grid, and its communication network topology is shown in Figure 3. e simulation of the microgrid is composed of two Distributed Generators (DG) and three Energy Storage Systems (ESS). e parameters of each component are shown in Table 1. e cost of batteries is ρ c � 0.058 $/kW.
To study the effectiveness of the compensation when the microgrid is under DoS attack, in this paper, we compare the corresponding condition of the system when the attack happens with or without compensation. e experimental results are as follows.

Without Compensation under DoS
Attack. When the system is under DoS attack, the power generation will decline sharply. In this paper, we set a random attacking moment between the 2 nd and the 5 th seconds. As shown in Figure 4, great fluctuation can be observed during the period of attacking, which makes the microgrid system unstable.
As shown in Figure 4, the average local power generation of the microgrid system drops to 20 kW. Besides, when the load power increases, the generated power of the microgrid stays at a low level. erefore, the energy supply ability of the system becomes insufficient. In Figure 5, we can see that the marginal cost of agents also decreases to about 30. Figure 6 shows that the balance between supply and demand is broken under DoS attack. e final supplied power is only 150 kW, which is far lower than the load's demand, which is 275 kW. Such phenomena may result in the imbalance of supply and demand of the microgrid system and then can lead to instability and low power level of the whole grid. As shown in Figure 7, with the help of the proposed eventtriggered sampling method, the sampling rate of the system decreases with a great margin, thus solving the problem of bandwidth constraint in the system.

With Predictive Compensation under DoS Attack.
To address the instability and performance degradation of the microgrid caused by DoS attack, in this paper, we use the proposed cloud-fog computing based predictive compensation algorithm to take data compensation for the agent that has been attacked. As shown in Figure 8, the power of each unit in the grid increases to 50 kW. Compared with power without predictive compensation, the proposed algorithm boosts the system's efficiency of the power supply. Figure 9 shows that the marginal cost increases from 31 in Figure 5 to 58 when it reaches consensus. Such a phenomenon proves that the proposed method can improve the economic benefit of the microgrid system. From Figure 10, we can see that the balance between supply and demand of the microgrid system is achieved. Besides, when the load power changes, the system can track the change in real time.
In a word, the proposed compensation algorithm can not only mitigate the economic impact caused by the attack but also keep the balance between supply and demand of the attacked system and moreover keep the energy optimization performance.
As shown in Figures 11 and 12, we conduct tracking prediction of generator 1's power data with the proposed cloud computing based predictive compensation algorithm.     From the result, we can see that the actual power of generator 1 can well track its unbalance power (reference power). Compared with fog computing, the tracking response of cloud computing is faster and the marginal cost is better.
Based on the above experimental results, the cloud-fog computing based distributed event-triggered predictive compensation energy optimization management of microgrid under DoS attack is achieved.

Conclusion
In this paper, a cloud-fog computing based distributed event-triggered predictive compensation energy optimization management algorithm is proposed. Considering the loss of power transmission of microgrid, the profit can be maximized by optimizing the power supply of microgrid. As for the problem of bandwidth constraint and the inconsistent problem of the microgrid, we take advantage of the properties of fog computing such as low latency and high efficiency and propose a distributed event-triggered consensus predictive compensation algorithm. Besides, we also utilize a cloud computing based predictive model compensation algorithm to enhance the computational efficiency of the prediction of the parameters in the grid. e proposed algorithm can track the history power data of the unbalance between supply and demand before the attacking moment and use it to predict and compensate the power missing data of the agent on the current moment and subsequent moments. Experimental results show that the proposed cloudfog computing based distributed event-triggered consensus predictive compensation microgrid energy management algorithm can efficiently solve the performance degradation, mismatch of supply and demand, weak computing capacity, and transmission delay caused by DoS attack.

Data Availability
e microgrid data used to support the findings of this study are available from the corresponding author upon request.

Conflicts of Interest
e authors declare that they have no conflicts of interest.    Control input