## 3 Mathematical Formulation
### Second Stage: Joint Restoration Scheme
#### 3.2.1 Network Reconfiguration and Radiality Constraints  
Network reconfiguration constraints define the switching action that segregates the nodes, ensuring the radiality of the microgrids. The binary variable \(A_{i,m,s}\) will be one if the \(i\)-th node belongs to the microgrid \(m\in S_{M}\) in the scenario \(s\in S_{S}\). Here, \(S_{M}\) represents the set of all microgrids and \(S_{S}\) is the set of all scenarios considered in the second stage.  
\[Ar_{i,s}=\sum_{m=1}^{S_{M}}A_{i,m,s}\leq 1,\ \forall i,m,s \tag{5}\]  
The node \(i\) can be connected to microgrid \(m\) in scenario \(s\) if the \(m\)-th member of \(S_{I_{DG}}\) is selected as the root bus.  
\[A_{i,m,s}\leq A_{j,m,s},\ j\in S_{I_{DG}}\forall i,m,s \tag{6}\]  
The binary variable \(O_{l,s}\) is set to zero if two nodes of a distribution line do not belong to the same microgrid. Meanwhile, \(i^{\prime}\) represents the index for the terminal bus of line \(l\). Equation (7) is linearized by applying linear methods to Equations (8)-(10). Equation (11) defines a binary variable \(O_{l,s}\) that is 1 when the branch is active as part of any microgrid in scenario \(s\).  
\[O_{l,s}\leq A_{i,m,s}\times A_{i^{\prime},m,s},\ \forall i,i^{\prime},m,s \tag{7}\]  
\[O_{l,m,s}\leq\sum_{i}A_{i,m,s},\ i\in S_{IB},\ \forall l,m,s \tag{8}\]  
\[O_{l,m,s}\leq\sum_{i^{\prime}}A_{i^{\prime},m,s},\ i^{\prime}\in S_{TB},\ \forall l,m,s \tag{9}\]  
\[O_{l,m,s}\geq\sum_{i}A_{i,m,s}+\sum_{i^{\prime}}A_{i^{\prime},m,s}-1,i\in S_{ IB},i^{\prime}\in S_{TB}\ \forall l,m,s \tag{10}\]  
\[O_{l,s}=\sum_{m\in S_{M}}O_{l,m,s},\ \forall l,s \tag{11}\]  
Constraints (12)-(14) represent the status of a line and a bus while considering damaged lines during a scenario using the binary variable \(F_{l,s}\) and hardening in the first stage controlled by the binary variable \(R_{l}\). Equation (12) controls the effect of hardening on line damage. Equations (13) and (14) ensure that the health status of the line and bus generated during the line damage scenario is applied to the model.  
\[O_{l,s}\leq 1-(1-F_{l,s})\times(1-R_{l}),\ \forall l,s \tag{12}\]  
\[O_{l,m,s}\leq LH_{l,s},\forall l,m,s \tag{13}\]  
\[A_{i,m,s}\leq BH_{i,s},\ \forall i,m,s \tag{14}\]  
The radiality of each distribution network is ensured by utilizing a necessary and sufficient condition from [18]. The necessary condition requires the number of buses minus the number of branches to be equal to one, which is ensured using Constraints (15)-(17). The sufficient condition is to ensure connectivity of each microgrid, which is included in the model employing Constraints (18)-(21). The binary variable \(\zeta_{m,s}\) is one if microgrid \(m\) is selected. Meanwhile, \(\beta_{i,i^{\prime},l,m,s}\) represents the fictional flow on line \(l\) with nodes \(i\) & \(i^{\prime}\). Finally, \(\beta_{i^{\prime},m,s}^{(2)}\) represents the fictional supply of master DG \(m\).  
\[\sum_{i}A_{i,m,s}\leq M\times\xi_{m,s},\ \forall l,s \tag{15}\]  
\[\xi_{m,s}\leq M\times\sum_{i}A_{i,m,s},\ \forall l,s \tag{16}\]  
\[\sum_{l}O_{l,m,s}=\sum_{i}A_{i,m,s}-\xi_{m,s},\ \forall l,s \tag{17}\]  
\[\sum_{i\in S_{TB}}\sum_{l}\beta_{i,i^{\prime},l,m,s}^{(1)}-\sum_{i\in S_{IB}} \sum_{l}\beta_{i,i^{\prime},l,m,s}^{(1)}=A_{i^{\prime},m,s}\,i^{\prime}\
eq S_{l_{DC}}\forall m,s \tag{18}\]  
\[\sum_{i\in S_{TB}}\sum_{l}\beta_{i,i^{\prime},l,m,s}^{(1)}-\sum_{i\in S_{IB}} \sum_{l}\beta_{i,i^{\prime},l,m,s}^{(1)}-\beta_{i^{\prime},m,s}^{(2)}\,i^{ \prime}=S_{l_{DC}}\forall m,s \tag{19}\]  
\[-O_{l,m,s}\times M\leq\beta_{i,i^{\prime},l,m,s}^{(1)}\leq O_{l,m,s}\times M, \ i\in S_{TB},i^{\prime}\in S_{IB}\forall l,m,s \tag{20}\]  
\[A_{i^{\prime},m,s}\leq\beta_{i^{\prime},m,s}^{(2)}\leq M\times A_{i^{\prime},m,s},i^{\prime}\in S_{l_{DC}}\forall m,s \tag{21}\]