## 3 First-Stage Problem Formulation
### Constraints  
The constraints of the model are as follows:  
(1) MES pre-positioning constraints  
Due to the limited capacity of each node, Constraint (2) indicates that the number of pre-positioned MES devices for each node cannot exceed its maximum capacity. Constraint (3) ensures that each MES device is pre-positioned at only one node. \[\sum\limits_{m\in M}\alpha_{mp}\leq Np,\forall p\in I_{1} \tag{2}\]  
\[\sum\limits_{p\in I_{1}}\alpha_{mp}=1,\forall m\in M \tag{3}\]  
(2) MES re-allocation constraints  
Constraint (4) indicates that only if there is an MES device in the node at the first stage can the MES be dynamically re-allocated to the corresponding node in the second stage. Constraint (5) ensures that each MES device can only be re-sent from a pre-positioning node \(p\) to a re-allocation node \(k\). \[\sum\limits_{k\in I_{2}}\beta_{mpkn}\leq\alpha_{mp},\forall p\in I_{1},\forall m \in M,\forall n\in N \tag{4}\]  
\[\sum\limits_{p\in I_{1}}\sum\limits_{m\in M}\beta_{mpkn}\leq 1,\forall k\in I _{2},\forall n\in N \tag{5}\]  
(3) Topology reconfiguration constraintsThe variables \(pm_{kn}\) and \(pf_{kn}\) represent whether there is an MES device re-allocated to node \(k\) and whether node \(k\) is a generation node under scenario \(n\). The variable \(\theta_{ij}\) indicates whether node \(j\) is the parent node of node \(i\). Constraints (6) and (7) define a node as a power source node if it either receives power from an MES device or serves as a generation node. \(|DL_{n}|\) denotes the number of damaged lines. Constraint (8) ensures that the number of damaged lines is equal to the predetermined budget. Constraints (9)-(11) guarantee that the reconfigured power system maintains a radial topology [31]. Specifically, Constraint (9) derives that \(\theta_{ij}\) or \(\theta_{ji}\) equals one (indicating a parent-child relationship between nodes \(i\) and \(j\)) if the status of the boundary line switch is closed or the distribution line is not damaged. It is noted that we assume that the distribution line is closed in all other states except for being damaged, and the boundary lines are hardened and will not be damaged in the second stage. Constraints (10) and (11) indicate each node has one or less parent node other than the power source nodes. The power source nodes include the generation nodes and the nodes connected to MES. \[pm_{in}=\left\{ \begin{aligned} &\sum_{s\in S}\sum_{m\in M} \beta_{msin}&,i\in I_{2},\forall n\in N\\ & 0&,i\
otin I_{2},\forall n\in N\end{aligned} \right. \tag{6}\]  
\[pf_{in}=\left\{ \begin{aligned} & 1,i\in F,\forall n\in N\\ & 0,i\
otin F,\forall n\in N\end{aligned} \right. \tag{7}\]  
\[|DL_{n}|=BD,\forall n\in N \tag{8}\]  
\[\theta_{ijn}+\theta_{jin}=tl_{ijn}+bl_{ijn},\forall i,j\in I,\forall n\in N \tag{9}\]  
\[\sum_{j\in\psi(i)}\theta_{ijn}\leq 1-pm_{in},\forall i\
otin F,\forall n\in N \tag{10}\]  
\[\theta_{ijn}=0,\forall i\in F,j\in\psi(i),\forall n\in N \tag{11}\]  
(4) Power balance constraints  
Constraint (12) ensures that the inflow and outflow on node \(i\) are equal to achieve power balance. Constraint (13) determines the power flow according to the node phase angle and line state. If the line is not damaged, the value of \((bl_{ijn}+tl_{ijn})(1-al_{ijn})\) is 1; otherwise, it is 0. Note that this term is nonlinear, and a binary variable \(\lambda_{ijn}\) is introduced to replace the term. Therefore, Equation (13) can be equivalently transformed into Equations (19) and (20) by the big-M method. \"M\" represents a considerably large numerical value. Constraint (14) guarantees that the value of shed loads on the node is between 0 and the power demand of the node. Constraints (15) and (16) indicate that the actual power generation of MES and the generation node cannot exceed their maximum power generation, respectively. Specifically, the value of \(gm_{imm}\) is determined by two factors; one is whether the node \(i\) is powered by MES \(m\) under scenario \(n\) (\(\gamma_{imm}\)), and the other is the purchasing capacity of MES \(m\) (\(G_{m}\)).