## 3 Mathematical Formulation
### Second Stage: Joint Restoration Scheme
#### 3.2.5 Power Flow Constraints  
The nodal active power balance is modeled using Constraint (48) [18]. Since \(p^{FV}_{f,\ell,s}\) in (48) is the product of \(p^{FV}_{f,\ell,s}\) and \(\alpha_{f,\ell,s}\), Constraints (49)-(51) are used to linearize the equation. Constraints (52) and (53) define the decision variables for switchable loads. Constraint (54) defines a decision variable to represent load shedding at each node in each scenario.  
\[\sum_{i\in\mathrm{N}1(j)}(p_{ij,t}-l_{ij,t}r_{ij})-\sum_{k\in\mathrm{N}2(j)}p _{jk,t}+\sum_{m\in S_{M}}\left[\sum_{g\in S_{G}}p^{DG}_{g,t}+\sum_{f\in S_{FV} }p^{FV}_{f,\ell,s}-p^{d}_{j,t}\right]=0 \tag{48}\]  
\[p^{FV}_{f,\ell,s}\leq p^{EVCS,max}_{e},\ \forall f,t,s \tag{49}\]  
\[p^{FV}_{f,\ell,s,t}\leq P^{FV}_{f,\ell,s,t},\ \forall f,t,s \tag{50}\]  
\[p^{FV}_{f,\ell,s}\geq p^{FV}_{f,\ell,s}-p^{EVCS,max}_{e},\ \forall f,t,s \tag{51}\]  
\[p^{d}_{j,t}=Ar_{j,s}\times D^{\mathrm{P}}_{j,t},\ \forall j,t,s \tag{52}\]  
\[q^{d}_{j,t}=Ar_{j,s}\times D^{\mathrm{Q}}_{j,t},\ \forall j,t,s \tag{53}\]  
\[s^{d}_{j,t}=D^{\mathrm{P}}_{j,t}-p^{d}_{j,t},\ \forall j,t,s \tag{54}\]  
Similarly, the nodal reactive power balance is modeled using Constraint (55), which is linearized by (56)-(58).  
\[\sum_{i\in\mathrm{N}1(j)}(q_{ij,t}-l_{ij,t}x_{ij})-\sum_{k\in\mathrm{N}2(j)}q _{jk,t}+\sum_{m\in S_{M}}\left[\sum_{g\in S_{G}}Q^{DG}_{g,t}+\sum_{f\in S_{FV} }q^{FV}_{f,\ell,s,t}-q^{d}_{j,t}\right]=0 \tag{55}\]  
\[q^{FV}_{f,\ell,s,t}\leq Q^{EVCS,max}_{e},\ \forall f,t,s \tag{56}\]  
\[q^{FV}_{f,\ell,s,t}\leq Q^{FV,dch}_{f,\ell,s,t},\ \forall f,t,s \tag{57}\]\[q_{f,c,t,s}^{FV}\geq Q_{f,c,t,s}^{FV,dch}-Q_{\epsilon}^{EVCS,max},\ \forall f,t,s \tag{58}\]  
The upper and lower limits for nodal voltages of active nodes are modeled using (59). The voltages of the master DGs are set using Constraint (60). The nodal voltage drop constraints bound via the Big-M method are modeled using (61). The relation between power flow, current, and voltage is defined using (62). Constraint (63) is used to model the limits of branch current flow in the distribution network. Constraints (64) and (65) model the active and reactive power flow through the closed branches of the distribution network.  
\[A_{i,m,s}\times(V_{(i,min)})^{2}\leq u_{i,t}\leq A_{i,m,s}\times(V_{(i,max)})^{ 2},\ \forall i,t,s \tag{59}\]  
\[u_{i,t}=A_{i,m,s}\times(V_{m}^{DG,set})^{2},\ \forall i\in S_{l_{DG}},\forall i,t,s \tag{60}\]  
\[-M\times(1-O_{l,s})\leq u_{i,t,s}-u_{j,t,s}-2(r_{ij}p_{ij,t}+x_{ij}q_{ij,t})+( (r_{ij})^{2}+(x_{ij})^{2})l_{ij,t}\leq\]  
\[M\times(1-O_{l,s}),\ \forall l,t,s \tag{61}\]  
\[\left\|2p_{ij,t}\ \ 2q_{ij,t}\ \ (l_{ij,t}-u_{i,t})\right\|\leq(l_{ij,t}+u_{i,t}) \tag{62}\]  
\[0\leq l_{l,s}\leq O_{l,s}\times(I^{Max})^{2},\ \forall l,t,s \tag{63}\]  
\[-O_{l,s}\times(p_{ij}^{Max})\leq p_{ij,t,s}\leq O_{l,s}\times(p_{ij}^{Max}), \ \forall i,t,s \tag{64}\]  
\[-O_{l,s}\times(q_{ij}^{Max})\leq q_{ij,t,s}\leq O_{l,s}\times(q_{ij}^{Max}), \ \forall i,t,s \tag{65}\]  
The model of BESS used in [19] was used to represent the behavior of BESS during grid service restoration.  
Objective function (1) constrained by (2) and (3) forms the stage 1 model of the two-stage stochastic model. Stochastic objective function (4) constrained by (5)-(65) forms the MISOCP stage 2 of the two-stage stochastic problem. Combined objective functions of both the above-mentioned stages constrained by their respective constraints form the two-stage stochastic optimization approach with a MISOCP model. In a two-stage stochastic model, the first stage makes decisions before the realization of uncertainty, creating a framework for optimal decision making, while the second stage adapts these decisions post-realization, ensuring a robust and flexible response to various possible scenarios.