# Optimal Siting and Sizing of FACTS in Distribution Networks Using the Black Widow Algorithm
## 3 Solution Methodology
### Slave Stage: Successive Approximation Power Flow Method  
As observed in the BWO algorithm depicted in Figure 1, the evolution of the initial population through the solution space, as well as the application of the cannibalism and mutation stages, requires the evaluation of the potential solutions by the slave stage [36]. In this optimization model (1)-(8), the slave stage is used to evaluate each potential FACTS location and size in the power balance constraints (4) and (5). To solve these equations, a numerical method must be used in order to find a solution with adequate convergence [39].  
This research adopts the SAPF method to solve the power flow problem in electrical distribution networks due to its easy implementation and efficient convergence [40]. The general SAPF formula is defined in Equation (13).  
\[\mathbb{V}_{dh}^{m+1}=-\mathbf{Y}_{dd}^{-1}\Big{(}\mathbf{diag}^{-1}\big{(} \mathbb{V}_{dh}^{m,\star}\big{)}\Big{(}\mathbb{S}_{dh}^{\star}-\mathbb{S}_{ \text{comp}}^{\star}\Big{)}+\mathbf{Y}_{dg}\mathbb{V}_{gh}\Big{)},\{\forall h \in\mathcal{H}\} \tag{13}\]  
where \(m\) is the iteration counter; \(\mathbb{V}_{dh}\) is a complex vector containing the voltage variables in all the demand nodes per period; \(\mathbb{V}_{gh}\) corresponds to a vector that contains the voltage values in the slack source; \(\mathbf{Y}_{dd}\) is a square matrix associated with the admittance relations between demand nodes; \(\mathbf{Y}_{dg}\) is a rectangular matrix that contains the complex relations between the demand and slack nodes; \(\mathbb{S}_{dh}\) is a vector containing the set of constant demand power loads per node and period; and \(\mathbb{S}_{\text{comp}}\) corresponds to the vector of complex power injections at the nodes where the FACTS must be placed. Note that \(\mathbb{X}^{\star}\) denotes the application of the conjugate operator to the complex vector \(\mathbb{X}\).  
**Remark 6**: _Note that the vector \(\mathbb{S}_{\text{comp}}\) contains the variables that relate the master stage to the slave stage, as the former defines the set of nodes and FACTS sizes. This is fixed in the slave stage to solve the power flow problem with the recursive Formula (13)._The convergence criterion applied to the power flow formula in (13), as recommended by the authors of [40], is the error between two consecutive voltage iterations, i.e.,  
\[\max_{h\in\mathcal{H}}\Bigl{\{}\left|\|\mathbb{V}_{dh}^{m+1}\right|-\left|\mathbb{ V}_{dh}^{m}\right|\Bigr{\|}\Bigr{\}}\leq\varepsilon, \tag{14}\]  
where \(\mathbb{V}_{dh}^{0}\) corresponds to the vector with the initial voltage values, which are set as equal to the voltage at the substation bus (i.e., \(\mathbb{V}_{gh}\)). In addition, \(\varepsilon\) is the maximum tolerance error, set as \(1\times 10^{-10}\)[40].  
Once power flow Formula (13) has reached the desired convergence in (14), the expected grid power losses can be calculated:  
\[z_{1}=C_{kWh}T\sum_{h\in\mathcal{H}}\mathbb{V}_{h}^{\top}(\mathbf{Y}^{\star} \mathbb{V}_{h})\Delta_{h}, \tag{15}\]  
where \(\mathbb{V}_{h}\) is the vector containing the voltage profiles in the distribution network, including the slack source per period, i.e., \(\mathbb{V}_{h}=\left[\mathbb{V}_{gh}\,\mathbb{V}_{dh}\right]^{\top}\), and \(\mathbf{Y}\) is the nodal admittance matrix of the distribution network under analysis.