*3.1. State in the Final Time (ECO/V2G)*

In order to establish a final value for the SOC, and thus enable a starting point for the dynamic programming method, it is proposed:

$$E\_{\rm soc} = \gamma \left( \Delta SOC\_{f, EV\_{E, V2G}} E\_{\rm bat, EV\_{E, V2G}} \right) \tag{5}$$

Herein, *Esoc* represents the error between calculated *SOCf* and the reference SOC for the last vehicle connection sample, where:

$$
\Delta \text{SOC}\_{f, EV\_{E, V2G}} = \left( \text{SOC}\_{f, EV\_{E, V2G}} - \text{SOC}\_{EV\_{E, V2G}}(t\_f) \right)^2. \tag{6}
$$

The gain *γ* defines a weight for the final state; Δ*SOCf* ,*EVE*,*V*2*<sup>G</sup>* represents the error between the desired SOC at final time (*SOCf* ,*EVE*,*V*2*<sup>G</sup>* ) and the calculated one (*SOCEVE*,*V*2*<sup>G</sup>* (*tf*)); and *Ebat*,*EVE*,*V*2*<sup>G</sup>* is the maximum capacity of each vehicle in ECO and V2G modes.
