*3.1. Objective Function*

The objective Function (2) aims to minimize the operating costs of the DSO to maintain the distribution grid operating within the limits. It includes the costs related to each of the stages, in which the first stage (*FDA*) comprises the here-and-now decisions and the second-stage (*FRT*) the wait-and-see decisions.

$$\min \quad F^{DA} + F^{RT} \tag{2}$$

where *FDA* and *FRT* are described as in (3) and (4).

$$F^{DA} = \sum\_{\mathcal{g}=1}^{N\_G} \left( \mathcal{C}^{Q, \text{IPP}}\_{\text{DER}(\mathcal{g})} R^{Q, \text{IPP}}\_{\text{DER}(\mathcal{g})} + \mathcal{C}^{Q, \text{DW}}\_{\text{DER}(\mathcal{g})} R^{Q, \text{DW}}\_{\text{DER}(\mathcal{g})} \right) + p^{Q, \text{IPP}}\_{\text{TSO}} \mathcal{R}X^{Q, \text{IPP}}\_{\text{TSO}} + p^{Q, \text{DW}}\_{\text{TSO}} \mathcal{R}X^{Q, \text{DW}}\_{\text{TSO}} \tag{3}$$

$$F^{\rm EFT} = \sum\_{\omega=1}^{\Omega} \pi\_{(\omega)} \left[ \begin{array}{c} \sum\_{f=1}^{\mathcal{N}\_{\mathbb{C}}} \left( \operatorname{cart}\_{\operatorname{EIR}(g)} \left( p\_{\operatorname{EIR}(g,\omega)}^{\mathcal{Q},\operatorname{IDF}} - p\_{\operatorname{EIR}(g,\omega)}^{\mathcal{Q},\operatorname{IDF}} \right) + \operatorname{C}\_{\operatorname{EIR}(g)}^{\operatorname{at}} P\_{\operatorname{EIR}(g,\omega)}^{\operatorname{at}} \right) + p\_{\operatorname{TSC}}^{\operatorname{tr},\operatorname{ad}} \left( \operatorname{rfc}\_{\operatorname{TSC}(\omega)}^{\mathcal{Q},\operatorname{IDF}} - \operatorname{rfc}\_{\operatorname{TSC}(\omega)}^{\mathcal{Q},\operatorname{IDF}} \right) + p\_{\operatorname{TSC}(\omega)}^{\operatorname{tr},\operatorname{d}} \operatorname{rfc}\_{\operatorname{TSC}(\omega)}^{\operatorname{t}} + \operatorname{s}\_{\operatorname{TSC}}^{\operatorname{\!}} \left( \operatorname{rfc}\_{\operatorname{EIR}(g)} \left( \operatorname{lE}\_{\operatorname{EIR}(\omega)} \operatorname{lE}\_{\operatorname{V}(\omega)} \operatorname{lE}\_{\operatorname{V}(\omega)} \operatorname{lE}\_{\operatorname{V}(\omega)} \operatorname{lE}\_{\operatorname{V}(\omega)} \operatorname{lE}\_{\operatorname{V}(\omega)} \operatorname{lE}\_{\operatorname{V}(\omega)} \operatorname{lE}\_{\operatorname{V}(\omega)} \operatorname{lE}\_{\operatorname{V}(\omega)} \operatorname{lE}\_{\operatorname{V}(\omega)} \operatorname{lE}\_{\operatorname{V}(\omega)} \operatorname{lE}\_{\operatorname{V}(\omega)} \operatorname{lE}\_{\operatorname{V}(\omega)} \operatorname{lE}\_{\operatorname{V}(\omega)} \operatorname{lE}\_{\operatorname{V}(\omega)} \operatorname{lE}\_{\operatorname{V}(\omega)} \operatorname{lE}\_{\operatorname{V}(\omega)$$

*FDA* represents the first-stage decision of contracting reactive power flexibility. Here, DER provides cost inflicted, upward and downward reactive power flexibility. It is mathematically presumed that the TSO request of reactive power may be needed to be relaxed (represented by *RLX*). This mathematical relaxation proposes the possibility of a certain deviation of the requested *tan* φ value in the upstream connection and is affected by its own penalty. The *tan* φ value is dependent on agreements between the TSO and the DSO.

Concerning *FRT*, it portrays the real-time operating costs of the distribution network. By the cost of an activation price, generators may change their reactive power operating point. In cases of higher need of flexibility (when the DSO cannot entirely provide the service), a different relaxation is activated through the binary variable *rlxExtra* allowing the DSO to provide part of the TSO request. By applying an even greater cost, it is possible to curtail the generators active power for relaxing situations where active power is creating problems in the distribution network. Demand response can also be contemplated to decrease the active power consumption, which in turn will reduce the reactive power consumption, under even greater penalties for this relaxation. These alternatives options will ensure that DSO prioritizes DER and consumers over providing the reactive power service to the TSO.

Capacitor banks and the transformers OLTC ability are also considered with a cost related to the lifetime degradation of the equipment by changing the tap set point [16].
