## 3 Solution
### Slave Stage  
The slave stage in the problem of the optimal allocation and sizing of D-STATCOMs along distribution feeders can be considered to be the heart of this solution because this stage resolves the power balance equality constraints for each period \(h\), which is necessary for determining the operative states of the network, i.e., the daily grid losses defined in the term \(f_{1}\) of the objective function (1). To solve these equations, here we rewrite them using its complex domain equivalent [29].  
\[\mathbf{S}_{sh}^{\star}=\mathrm{diag}(\mathbf{V}_{sh}^{\star})[ \mathbb{Y}_{ss}\mathbf{V}_{sh}+\mathbb{Y}_{sd}\mathbf{V}_{dh}],\;\forall\{h \in\mathcal{H}\}, \tag{7}\] \[\mathbf{S}_{gh}^{\star}-\mathbf{S}_{dh}^{s,\star}=\mathrm{diag}( \mathbf{V}_{dh}^{\star})[\mathbb{Y}_{ds}\mathbf{V}_{sh}+\mathbb{Y}_{dd}\mathbf{ V}_{dh}],\;\forall\{h\in\mathcal{H}\}, \tag{8}\]  
where \(\mathbf{S}_{sh}\) is the complex vector that contains all the apparent power generation in the slack nodes at each period \(h\), \(\mathbf{V}_{sh}\) is the vector that contains all the voltage variables in complex form for all the slack nodes at each period of time \(t\), \(\mathbf{V}_{dh}\) is the vector that contains all the voltage variables in complex form for all the demand nodes at each period of time \(t\), \(\mathbb{Y}_{ss}\), \(\mathbb{Y}_{sd}\), \(\mathbb{Y}_{ds}\) and \(\mathbb{Y}_{dd}\) are submatrices obtained from the nodal admittance matrix that relates slack and demand nodes, respectively, \(\mathbf{S}_{dh}^{\star}\) is a complex vector that contains the variablesassociated with the reactive power generation in the D-STATCOMs, i.e., \(\mathbf{S}_{qh}^{\star}=jQ_{gh}\), \(\mathbf{S}_{dh}^{\star}\) is the vector that contains all the apparent power demands at each period \(h\). It is worth mentioning that \(x^{\star}\) corresponds to the conjugate value of the complex number \(x\), and \(\mathbf{diag}(x)\) represents the conversion of the vector \(x\) into a diagonal matrix. Please note that \(\mathbf{V}_{sh}\) are known variables since these correspond to the voltage values in all the slack nodes, while the \(\mathbf{V}_{dh}\) are unknown variables that must be determined for each period. In addition, if the reactive power injections in the D-STATCOMs are known (defined in the slave optimization stage), and the demand voltages can be iteratively obtained from (8) as follows:  
\[\mathbf{V}_{dh}^{k+1}=\mathbb{Y}_{\underline{d}d}^{-1}\Big{[} \text{diag}^{-1}\Big{(}\mathbf{V}_{dh}^{k,\star}\Big{)}\Big{[}\mathbf{S}_{qh}^{ \star}-\mathbf{S}_{dh}^{\star,\star}\Big{]}-\mathbb{Y}_{ds}\mathbf{V}_{sh}\Big{]},\] \[\forall\{h\in\mathcal{H}\}, \tag{9}\]  
where \(k\) is the iterative counter, such that for \(k=0\), plane-voltages are defined as \(\mathbf{V}_{dh}^{0}=\mathbf{1}\angle 0^{\circ}\) as the initial voltage condition using the per-unit representation. The recursive power flow formula defined by (9) is known as the successive approximation power flow method originally proposed in [29], where the iterations are made until the convergence criterion is met, which is defined as follows: \(\max\Big{\{}\Big{\|}\big{\|}\mathbf{V}_{dh}^{k+1}\Big{\|}-\Big{\|}\mathbf{V}_{ dh}^{k}\big{\|}\Big{\|}\Big{\}}\leq\epsilon\), where epsilon is defined as the maximum convergence error.  
**Remark 2**: _In the SAPF method defined by the recursive Formula (4) its convergence can be ensured by applying the Banach fixed-point theorem as demonstrated in [29], based on the properties of the demand admittance matrix \(\mathbb{Y}_{dd}\)._  
To determine the value of the objective function regarding the annual costs of the grid losses, the solution found by the SAPF method is used (suppose that the solution of the power flow is \(\mathbf{U}_{h}=\Big{[}\mathbf{V}_{sh}\ \mathbf{V}_{dh}^{k+1}\Big{]}^{T}\), which allows transforming the component \(f_{1}\) in the objective function (1) into  
\[f_{1}=C_{\text{kWh}}T\sum_{h\in\mathcal{H}}\text{real}\Big{\{} \mathbf{U}_{h}^{T}\mathbb{Y}^{\star}\mathbf{U}_{h}^{\star}\Big{\}}. \tag{10}\]