## 2 Materials and Methods
### Stage 2. Successive Quadratic Programming-Based OPF
#### 2.2.1 OPF Problem Formulation
The OPF problem aims to determine the optimal tap positions of the power transformers at each hour that will lead to the change of voltage values at the buses, with an effect on minimizing the power loss:  
\[min(F_{Loss})=min\left(\sum_{e=1}^{E}G_{e}\cdot[V_{i,h}^{2}+V_{j,h}^{2}-2\cdot V _{i,h}\cdot V_{j,h}\cdot cos(\theta_{i,h}-\theta_{j,h})]\right),\ h=1,\ldots,T_{H} \tag{1}\]  
subject to the constraints regarding:  
* Active and reactive power balances \[P_{G_{i,h}}-P_{L_{i,h}}=\sum_{j=1}^{N}V_{i,h}\cdot V_{j,h}\cdot[G_{ij}\cdot cos (\theta_{i,h}-\theta_{j,h})+B_{ij}\cdot sin(\theta_{i,h}-\theta_{j,h})]\quad i \in N\backslash s,\quad h=1,\ldots,T_{H}\] (2) \[Q_{G_{i,h}}-Q_{L_{i,h}}=\sum_{j=1}^{N}V_{i,h}\cdot V_{j,h}\cdot[G_{ij}\cdot sin (\theta_{i,h}-\theta_{j,h})-B_{ij}\cdot con(\theta_{i,h}-\theta_{j,h})]\quad \forall i\in N\backslash s,\quad h=1,\ldots,T_{H}\] (3)
* Voltage magnitude \[V_{i,min}\leq V_{i,h}\leq V_{i,max}\quad\forall i\in N,\quad h=1,\ldots,T_{H}\] (4)
* Active and reactive power generation at the conventional generator buses \[P_{G_{i}}^{min}\leq P_{G_{i},h}\leq P_{G_{i}}^{max}\quad\forall l\in N_{S}\subset N,\quad h=1,\ldots,T_{H}\] (5) \[Q_{G_{i}}^{min}\leq Q_{G_{i},h}\leq Q_{G_{i}}^{max}\quad\forall l\in N_{S} \subset N,\quad h=1,\ldots,T_{H}\] (6)
* Active power generation at buses associated with a wind farm \[P_{w}^{min}\leq P_{w,h}\leq P_{w}^{max}\quad\forall w\in N_{w}\subset N,\quad h =1,\ldots,T_{H}\] (7)
* Transformer tap \[t_{ij}^{min}\leq t_{ij,h}\leq t_{ij}^{max}\quad i,j\in N,\quad h=1,\ldots,T_{H}\] (8)
* Line loading \[S_{ij,h}\leq S_{ij\,max}\quad i,j\in N,\quad h=1,\ldots,T_{H}\] (9) where: \(E\)--the total number of the elements (lines and transformers) in the networks; \(s\)--slack bus; \(N_{g}\)--the set of conventional generator buses in the network; \(G_{e}\)--the real part of element \(e\) between the \(i\)-th bus and \(j\)-th bus from the nodal admittance matrix; \(V_{i,h}\)--the voltage magnitude at the \(i\)-th bus and hour \(h\); \(V_{j,h}\)--the voltage magnitude at the \(j\)-th bus and hour \(h\); \(G_{ij}\)--the real part of element \(ij\) from the nodal admittance matrix; \(B_{ij}\)--the imaginary part of element \(ij\) from the nodal admittance matrix;
\(P_{G,h}\), \(Q_{G,h}\)--the active and reactive powers generated at the \(i\)-th bus and hour \(h\); \(P_{L,i,h}\), \(Q_{L,i,h}\)--the active and reactive powers required at the \(i\)-th bus and hour \(h\); \(t_{ij,h}\)--the tap position of the transformer connected between the \(i\)-th bus and \(j\)-th bus and hour \(h\); \(S_{ij\ max}\)--the maximum load of the line connected between the \(i\)-th bus and \(j\)-th bus; \(P_{G}{}^{min}\), \(P_{G}{}^{max}\)--the active power limits of the \(l\)-th conventional power plant; \(Q_{G}{}^{min}\), \(Q_{G}{}^{max}\)--the reactive power limits of the \(l\)-th conventional power plant; \(P_{w}{}^{min}\), \(P_{w}{}^{max}\)--the active power limits of the \(w\)-th wind farm; \(P_{w}\)--the active power of the \(w\)-th wind farm. Considering this mathematical optimization model and knowing the topology of the network integrating the wind farms, the optimization process aims to obtain the optimal intervals of tap position for each transformer that leads to the minimum power losses of the network subject to all technical constraints.