## 4 SOMS Framework
### The Second Stage  
The objective function of the first stage is defined as Equation (5):  
\[ \begin{array}{c}Min\left\{a_{1}\times\sum\limits_{b}^{N_{h}}\sum\limits_{t} ^{N_{t}}((1-q(b,t))\times P_{d}(b,t)\times Pen(b))+a_{2}\\ \times\sum\limits_{m}^{N_{m}}\sum\limits_{t}^{N_{t}}H_{m}\times f(m,t)\times T (t)+a_{3}\times\sum\limits_{i}^{N_{t}}\sum\limits_{t}^{N_{t}}v(i)\times P_{DG} (i,t)+a_{4}\\ \times\sum\limits_{L}^{N_{L}}\sum\limits_{b}^{N_{h}}\sum\limits_{t}^{P}{}_{DR }(L,b,t)\times C_{DR}(L)\right\}\end{array}  \tag{5}\]  
In Equation (5), the first section is defined to consider the cost of load shedding and system outage. In this regard, the parameter \(Pen(b)\) is defined to show the difference between various buses. The second section is provided to decrease the RRC time. Moreover, the third term is considered to minimize the DG cost in crisis times, and the final section of the objective function is presented to minimize the demand response cost. In Equation (5) \(a_{1}\), \(a_{2}\), \(a_{3}\) and \(a_{4}\) are defined as coefficient parameters for the objective function. One of the important constraints in the power system is the balance of generations and loads, which is defined in Equation (6):  
\[ \begin{array}{c}\sum\limits_{i}^{N_{t}}P_{DG}(i,t)+\sum\limits_{b}^{N_{b}} Sus(b,bp)\times(\delta(b,t)-\delta(bp,t))\\ =q(b,t)\times P_{d}(b,t)-\sum\limits_{L}^{N_{t}}P_{DR}(L,b,t)\end{array}  \tag{6}\]  
\(Sus(b,bp)\) indicates the susceptance between bus \(b\) and \(bp\). Additionally, \(\delta(b,t)\) shows the angle of the bus \(b\) in time \(t\). Equation (6) shows that the sum of the DG output power and transmission power should be equal to the demand in each time interval. The capacity of the distribution lines is limited to \(P_{Line}^{max}\). Therefore, Equation (7) is introduced as:  
\[u(m,t)\times P_{Line}^{max}\leq\sum\limits_{b}^{N_{b}}Sus(b,bp)\times(\delta( b,t)-\delta(bp,t))\leq u(m,t)\times P_{Line}^{max} \tag{7}\]  
where the variable \(Z(m,t)\) is defined as the status of the damaged component after the crews visit and fix the damaged component. The status of the damaged component at each time is lower than or equal to \(Z(m,t)\), which is introduced in Equation (8):  
\[u(m,t)\leq Z(m,t) \tag{8}\]  
In Equation (9), the power of each DG is forced to be lower than or equal to \(P_{DG}^{max}\). \[0\leq P_{DG}(i,t)\leq P_{DG}^{max} \tag{9}\]If a load is energized, it should be remain energized, which is enforced by Equation (10):  
\[q(b,t)\geq q(b,t+1) \tag{10}\]  
Equation (11) shows that if a crew \(c\)th visiting an outage leaves it after finishing the repair, then [8]:  
\[\sum_{\forall n\in N_{\alpha}\backslash\{m\}}x(m,n,c,\sigma)-\sum_{\forall n\in N _{\alpha}\backslash\{m\}}x(n,m,c,\sigma)=0 \tag{11}\]  
Equations (12) and (13) force all crews to start from the depot and, after the finishing task, return to the depot [8]. \[\sum_{\forall m\in N_{\alpha}\backslash\{0\}}x(0,m,c,\sigma)-\sum_{\forall m \in N_{\alpha}\backslash\{0\}}x(m,0,c,\sigma)=1 \tag{12}\]  
\[\sum_{\forall m\in N_{\alpha}\backslash\{dp\},c\in RC_{\sigma}}x(m,dp,c, \sigma)=nc(\sigma) \tag{13}\]  
Equation (14) guarantees that an outage is repaired by only one crew, to ensure that no crew visits a fixed component [22]. \[\sum_{\forall c\in RC_{\sigma}}y(m,c,\sigma)=1 \tag{14}\]  
If the \(c\)th crew is moved from a damaged component \(m\) to \(n\), then \(y(m,c,\sigma)=1\). Equation (15) relates the binary variables \(y(m,c,\sigma)\) and \(x(m,n,c,\sigma)\):  
\[y(m,c,\sigma)=\sum_{\forall n\in N_{\alpha}\backslash\{0,m\}}x(m,n,c,\sigma) \tag{15}\]  
Crews have different abilities and specialties for repairing the damaged components. Regarding the expertise, crews that cannot fix the damaged component should not visit that component.