# Mean-Field Stackelberg Game-Based Security Defense and Resource Optimization in Edge Computing
## 4 Mean-Field Games Equilibrium and Optimal Strategies
### Mean-Field Game Equilibrium Algorithm  
This subsection shows the implementation of the mean-field game equilibrium algorithm for the proposed model, which is given in Algorithm 1. The equilibrium algorithm can be divided into the defense section and the attack section. Specifically, we calculate the optimal strategies and the corresponding state trajectories for defenders and attackers separately from the mean-field game model. Since the objective functions are quadratic, the solutions can be given based on the Stackelberg game theory, and the complexity of the mean-field equilibrium algorithm is \(O(1/\sqrt{n})\). The algorithm process can be described in Algorithm 1 and Figure 2.  
``` Input: the number of defenders \(N\) and the initial state \(x_{0}\), \(x_{i0}\). Output: the optimal strategies \(u_{i}^{*}\) and \(u_{0}^{*}\). 1. Set up the parameters \(\alpha_{i}\), \(\beta_{i}\), \(\lambda_{i}\), \(a_{i}\), \(b_{i}\), \(c_{i}\), \(a_{0}\), \(b_{0}\), \(u_{0}\), and \(c\). 2. The defenders detect attack behavior. 3. Start the mean-field game for defenders. 4. For t = 1 to T
5. Calculate optimal strategies for the defenders based on Equations (11)-(15). 6. Set up the objective function \(J_{i}^{*}\) and the state trajectory \(x_{i}^{*}\). 7. Calculate the optimal strategy for the attacker based on Equations (33)-(37). 8. Set up the objective function \(J_{0}^{*}\) and the state trajectory \(x_{0}^{*}\). 9. End. 10. Return the optimal strategies \(u_{i}^{*}\) and \(u_{0}^{*}\). ## 5 Numerical Simulation

This section provides the simulation results to illustrate the dynamic evolution of the defense strategy of the defenders and the trajectory of the attackers based on the proposed mean-field Stackelberg game model. We first consider all the defenders as heterogeneous followers who share the same parameters and then discuss the heterogeneous case with \(N=10,000\). Each defender tries to obtain the optimal defense strategy to minimize the cost given in Equation (3). In Section 4.1, we obtained the optimal defense strategy for edge device \(i\) (5), \(1\leq i\leq N\), and in Section 4.3, we obtained the optimal attack strategy (33). We assume that the coefficients are within the range of 0 to 1. We presume that the simulation time is T = 10 min. The rest of the related simulation parameters are given in Table 1.

The evolution of the optimal defense strategies for any three defenders is shown in Figure 3. At the beginning of the attack, the defense level gradually increases as the defense mechanism responds and then stabilizes. The result indicates that the defenders respond to defense mechanisms to improve their defense when detecting attacks. Related to the defense strategy, the resource consumption for the defenders is given in Figure 4. It shows that the value of \(x_{i}(t)\) gradually rises and then declines during the start of the attack, and finally, the value eventually reaches a stable range. When the defense mechanism is activated, it requires more resources for the edge devices. As a result, the node reduces the additional overhead of the computational task. When the level of offensive defense decreases, the resource consumption level starts to decrease and fluctuates within a certain range to maintain the computational requirements of the task. \begin{table}
\begin{tabular}{|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|} \hline \(a\) & \(A\) & \(a_{0}\) & \(b\) & \(b_{0}\) & \(c\) & \(c_{0}\) & \(\alpha\) & \(\beta\) & \(a_{0}\) & \(\beta_{0}\) & \(\gamma\) & \(\lambda\) \\ \hline
0.38 & 0.73 & 0.26 & 0.3 & 0.12 & 0.07 & 0.51 & 0.4 & 0.5 & 0.93 & 0.24 & 0.62 & 0.52 \\ \hline
0.4 & & 0.3 & & 0.22 & & 0.3 & 0.96 & & & 0.68 & 0.23 & \\ \hline

To ensure maximum security, each edge device will adopt its optimal defense level. In this framework, the number of attackers gradually decreases over time, which is shown in Figure 5. Figure 6 shows the evolution of the level of attack.