*4.4. V2G Mode*

Similar to ECO mode, the optimization technique and the factors previously described are used to formulate the cost function. Nevertheless, this mode is divided in two regions: C, which represents *Pevpossible* 0 (charging); and D, which represents *Pevpossible* < 0 (discharging). The main idea is to deal with a specific design for each different region.

For the charging region C, the cost function is given by:

$$J\_{V2G^{+}} = E\_{\rm soc}(t\_f) + \sum\_{t\_m=t\_i}^{t\_f} \left[ R\_{pcc}(t\_m) + R\_{V2G}(t\_m) + E\_{0, \rm AP\_{EV}}(t\_m) + R\_{dcg}(t\_m) \right],\tag{26}$$

and for region D, it is written as:

$$J\_{V2G-} = E\_{\rm soc}(t\_f) + \sum\_{t\_m=t\_0}^{t\_f} \left[ R\_{\rm pcc}(t\_m) + R\_{V2G}(t\_m) + E\_{0, \rm AP\_{EV}}(t\_m) + R\_{\rm deg}(t\_m) + E\_{\rm deg, scc}(t\_m) \right]. \tag{27}$$

The expressions (26) and (27) differ by the term *Edeg*,*soc*(*tm*) in the discharging region. Naturally, *JV*<sup>2</sup>*G*<sup>+</sup> > *JV*<sup>2</sup>*G*<sup>−</sup> due to the operating charging power in the region D being negative, though with the addition of *Edeg*,*soc*(*tm*), the energy sale must overcome the degradation term to be feasible.

The dispatched power *P*∗ *<sup>V</sup>*2*G*,*EVV*<sup>2</sup>*<sup>G</sup>* is part of the set that comprises all possible quantized values (*Pevpossible*) and implies the total minimum cost described by:

$$J\_{V2G} = J\_{V2G^+} + J\_{V2G^-}.\tag{28}$$

The optimal power definition *P*∗ *<sup>V</sup>*2*G*,*EVV*<sup>2</sup>*<sup>G</sup>* is given by:

$$P\_{V2G,EV\_{V2G}}^{\*} \leftarrow f\_{V2G}(P\_{V2G,EV\_{V2G}}^{\*}) \lessapprox f\_{V2G}(P\_{\text{ev}\_{\text{posible}}}).\tag{29}$$

In the case of the demand limitation related to vehicles in ULTRA and FAST modes and if the SOC of the EV is over 40%, the index of discharging power follows the same expression of ECO mode (see (24)). However, in this case, the V2G vehicles discharge and supply the other modes and/or the load demand. Therefore, the resulting charging power for the V2G mode is defined by:

$$P\_{V2G,EV\_{V2G}} = \begin{cases} P\_{V2G,EV\_{V2G}}^\* & \text{if } P\_{nt}(t\_m) + P\_{ll}(t\_m) + P\_F(t\_m) \leqslant P\_{lim} \\ \overline{P}\_{V2G}(t\_m), & \text{otherwise}, \end{cases} \tag{30}$$

Herein, *PV*<sup>2</sup>*G*(*tm*) = *f <sup>V</sup>*2*G*(*tm*)*Pnom*.

For this situation, the current charging power of ULTRA and FAST modes is recalculated considering the *PV*<sup>2</sup>*<sup>G</sup>* charging power. In a scenario where the microgrid demand has reached the contracted demand prior to calculating the charging power, then the power dispatched to the vehicles in V2G mode is *PV*<sup>2</sup>*G*. V2G mode vehicles may increase the virtually value of the contracted demand from the microgrid because they store energy. Thus, when there are no vehicles in V2G mode, the limitation imposed on ULTRA (see Equation (18)) and FAST (see Equation (20)) modes is performed. Otherwise, if the microgrid demand is above the limit and there is energy stored in the vehicles in V2G, the charging power of ULTRA and FAST modes will be set in the V2G algorithm.
