## 3 Solution Methodology
### Slave Stage: Generalized Backward/Forward Method  
The sweeping method is a numerical method based on graph theory that uses the incidence matrix as a means to solve the power flow problem [23]. The incidence matrix is a representation of the relationship between the nodes and branches of the distribution system [24]. To create an incidence matrix (node-branch), the following structure is employed:  
\[A_{i,j}=\left\{\begin{matrix}+1&\qquad\text{If the current leaves node i}\\ -1&\qquad\text{If the current reaches node i}\\ 0&\qquad\text{If the branch j is not connected to node i}\end{matrix}\right\}\]  
To develop the problem, this matrix is divided into two submatrices representing generation (slack node) and demand.  
\[A=\left[A_{s}\ A_{d}\right] \tag{9}\]  
With the above matrices, it is possible to obtain the relationship between the voltage drops in branches \(E\) and the voltages at the nodes, as follows:  
\[E=A_{s}V_{s}+A_{d}V_{d} \tag{10}\]where \(V_{s}\) is the voltage at the slack node, and \(V_{d}\) is the vector comprising the voltages at the nodes where there is demand. This is thus formulated because the power flow problem revolves around finding the variable \(V_{d}\).  
Now, [PERSON]'s law is applied in order to relate the branch current \(J\) to voltages \(E\):  
\[E=ZJ \tag{11}\]  
with \(Z\) being the matrix that contains all the primitive impedances of the lines.  
Now the net injected currents \(I\) can be separated as follows as a function of the slack node current \(I_{s}\) and the current at the demand nodes \(I_{d}\):  
\[I=[I_{s}\;I_{d}]^{\top} \tag{12}\]  
Now, [PERSON]'s current law is applied in order to find the relationship between the net injected currents at the system nodes \(I\) and the branch currents \(J\), with which the following structure is obtained in matrix form:  
\[I_{s} =A_{s}^{\top}J \tag{13}\] \[I_{d} =A_{d}^{\top}J \tag{14}\]  
Note that, by considering Equation (14) and substituting Equations (10) and (11), a general expression for the demanded current is obtained:  
\[I_{d}=A_{d}^{\top}YA_{s}V_{s}+A_{d}^{\top}YA_{d}V_{d} \tag{15}\]  
with \(Y\) being the primitive admittances matrix, i.e., \(Y=Z^{-1}\).  
On the other hand, it is known that the relationship between the demanded currents and the voltages has a nonlinear hyperbolic form [25], which is defined below.  
\[I_{d}=-diag^{-1}(V_{d}^{*})(S_{d}^{*}), \tag{16}\]  
Now, by equalizing Equations (15) and (16), a general equation is obtained which relates the demand node voltages between each other in a nonlinear way.  
\[V_{d}=-[A_{d}^{\top}YA_{d}]^{-1}\Big{[}diag^{-1}(V_{d}^{*})(S_{d}^{*})+A_{d}^ {\top}YA_{s}V_{s}\Big{]}, \tag{17}\]  
finally, Equation (17) is adjusted in order to make it iterative and achieve that the expected voltage value is reached with the predefined convergence error via loop programming logic. The iterative sweeping formula is presented below.  
\[V_{d}^{t+1}=-[A_{d}^{\top}YA_{d}]^{-1}\Big{[}diag^{-1}(V_{d}^{t*})(S_{d}^{*})+ A_{d}^{\top}YA_{s}V_{s}\Big{]}, \tag{18}\]  
Note that the convergence error is defined as \(\varepsilon=1\times 10^{-10}\) and the iterative process starts with \(t=0\) and \(V_{d}^{0}=1\angle 0^{\circ}\), which ends if and only if \(\max\Big{\{}||V_{d}^{t+1}|-|V_{d}^{t}||\Big{\}}\leq\varepsilon\).