## 3 Methodology
### Optimization Problem Formulation  
Once the algorithm has identified all possible branch combinations to form radial systems, the optimization process begins on a system-by-system basis. The optimization process involves the following elements:Decision Variable  
The decision variables for this optimization problem are the active (\(P\)) and reactive (\(Q\)) power at the flexible buses in the distribution system. These variables allow the system to dynamically respond to demand and generation needs. For each flexible bus \(i\), the decision variables are represented as follows:  
\[ \begin{array}{c}P_{\textit{{{nudo flexible}}}}\ i\\ Q_{\textit{{{nudo flexible}}}}\ i\end{array}  \tag{7}\]  
B. Objective Function  
The objective of the optimization problem is to minimize the total costs associated with the operation of the distribution system. These costs include both active power losses in the network and the costs related to the use of flexible power at buses that allow variability in active and reactive power injection. Therefore, the goal is to determine, for each radial configuration generated by the algorithm, the optimal values of \(P\) and \(Q\) at the flexible buses, minimizing the economic impact of both active power losses and the use of flexibility at these buses. \[\text{Minimize}\ C_{\textit{{totals}}}=C_{\textit{{PP}}}\cdot P_{\textit{{TS} }}+C_{\textit{{PF}}}\cdot S_{\textit{{FTU}}} \tag{8}\]  
where  
* \(P_{\textit{{TS}}}\) represents the total active power losses of the system. * \(S_{\textit{{FTU}}}\) represents the amount of flexible power used at the flexible buses. * \(C_{\textit{{PP}}}\) is the cost associated with active power losses. * \(C_{\textit{{PF}}}\) is the cost associated with the use of flexible power. The flexible power utilized, \(S_{\textit{{FTU}}}\), is defined as follows:  
\[S_{\textit{{FTU}}}=\sqrt{\left({P_{\textit{{FTU}}}}\right)^{2}+\left({Q_{ \textit{{FTU}}}}\right)^{2}} \tag{9}\]  
The values of \(P_{\textit{{FTU}}}\) and \(Q_{\textit{{FTU}}}\) are calculated as follows:  
\[ \begin{array}{c}P_{\textit{{FTU}}}=\left|{P_{\textit{{base}}\ \textit{{inical}}}-P_{ \textit{{nudo flexible}}}\ i}\right|\\ Q_{\textit{{FTU}}}=\left|{Q_{\textit{{base}}\ \textit{{inical}}}-Q_{\textit{{nudo flexible}}}\ i}\right| \end{array}  \tag{10}\]  
where \(P_{\textit{{base}}\ \textit{{inical}}}\) and \(Q_{\textit{{base}}\ \textit{{inical}}}\) are the active and reactive power of the base system, respectively, and \(P_{\textit{{nudo flexible}}}\ i\) and \(Q_{\textit{{nudo flexible}}}\ i\) are the decision variables of the optimization problem as previously defined. If the values of \(P\) and \(Q\) have not changed, then the associated costs for that term will be zero. C. Constraints  
The optimization problem must satisfy several operational constraints to ensure that the proposed solution is feasible and secure:  
1. Load flow equations:  
These equations ensure the balance of active and reactive power at each bus of the system. They are represented as follows:  
\[ \begin{array}{c}P_{i}=V_{i}\sum\limits_{n=1}^{N}\left[{V_{n}(G_{\textit{{ in}}}cos\delta_{\textit{{in}}}+B_{\textit{{in}}}sen\delta_{\textit{{in}}})}\right] \\ Q_{i}=V_{i}\sum\limits_{n=1}^{N}\left[{V_{n}(G_{\textit{{in}}}sen\delta_{ \textit{{in}}}-B_{\textit{{in}}}cos\delta_{\textit{{in}}})}\right]\end{array}  \tag{11}\]  
where \(P_{i}\) and \(Q_{i}\) are the active and reactive power at buses \(i\), \(V_{i}\) and \(V_{n}\) are the voltage magnitudes at buses \(i\) and \(n\), \(G_{\textit{{in}}}\) and \(B_{\textit{{in}}}\) are the conductance and susceptance between buses \(i\) and \(n\), and \(\delta_{\textit{{in}}}=\delta_{\textit{{i}}}-\delta_{\textit{{n}}}\) is the phase angle difference between buses \(i\) and \(n\). 2. Power at flexible buses: The range of power that the decision variable can take is limited as follows: \[ \begin{array}{l}P_{min}\leq P_{nudo\ flexible\ i}\leq P_{max}\\ Q_{min}\leq Q_{nudo\ flexible\ i}\leq Q_{max}\end{array} \] (12)
3.