*3.1. Objective Function*

In this paper, the proposed V2G optimization algorithm has the objective to optimize the grid-connected EV charging and discharging power in order to minimize the power grid load variance. A generalized daily power load curve is depicted in Figure 3. Besides, the desired grid loading is achieved by performing peak load shaving and load levelling to minimize the variance between the power grid loading and target loading as illustrated in Figure 3. The proposed V2G optimization algorithm is performed by enabling the EV charging during the period where the power grid loading is less than the target loading (G2V operation). On the contrary, EVs are required to discharge the energy from the batteries when the power grid loading is larger than the target loading (V2G operation). No power flows between the EVs and power grid when the target loading is equal to the power

grid loading. Equations (1) and (2) express the objective function in terms of grid load variance, target loading, charging and discharging rate:

$$\min \Delta P = P\_{\text{target}}(t) \ -\ P\_{\text{load}}(t) - P\_{\text{EV}}(t) \tag{1}$$

$$P\_{\rm EV}(t) = \begin{cases} \left(\sum\_{n=1}^{N} A\_{\rm n} K\_{\rm n} \right) \times P\_{\rm EV, \rm charging} & \text{, when } P\_{\rm load} < P\_{\rm target} \\ \left(\sum\_{n=1}^{N} A\_{\rm n} K\_{\rm n} \right) \times P\_{\rm EV, \rm discharging} & \text{, when } P\_{\rm load} > P\_{\rm target} \\ & 0 & \text{, when } P\_{\rm load} = P\_{\rm target} \end{cases} \tag{2}$$

where Δ*P* is the grid load variance, *t* is time, *P*target is the target loading, *P*load is the existing load of the power grid, *P*EV is the total power of EV loads/sources, *n* is the EV index, *N* is the maximum EV index, *An* is the availability of *n*th EV for the V2G application, *Kn* is the indicator of *n*th EV for V2G application, *P*EV,charging is the EV charging rate, and *P*EV,discharging is the EV discharging rate. In Equation (1), the grid load variance (Δ*P*) was minimized by optimizing the number of grid-connected EV to charge or discharge during valley load and peak load period, respectively. The determined optimal grid-connected EV numbers are then reflected in the indicator of *n*th EV for V2G application (*Kn*). Meanwhile, *An* refers to the availability of *n*th EV to the power grid prepared for the V2G application. This variable depends on the dynamic EV mobility characteristics, where the detailed EV grid-connection probability is discussed in Section 3.2.3. In the condition where *Kn* and *An* are available, the *n*th EV will be instructed to charge or discharge the battery.

**Figure 3.** The concept of peak load shaving and load levelling.

#### *3.2. Optimization Constraints*

The operation of V2G system is restricted under plenty of system constraints and uncertainties. Therefore, the proposed V2G optimization algorithm required the compliance with these power grid and EV constraints.

#### 3.2.1. Power Balance

The important power grid constraint to be considered in the proposed V2G optimization algorithm is the power balance between the grid generation and demand. The supplied power from the generation plants and distributed EV battery sources must satisfy the power grid load and EV charging demands:

$$P\_{\rm grid}(t) + \sum\_{n=1}^{N} A\_n K\_n P\_{\rm EV, discharging}(t) = P\_{\rm load}(t) + \sum\_{n=1}^{N} A\_n K\_n P\_{\rm EV,charging}(t) \tag{3}$$

where *P*grid is the active power from the generation plant.

#### 3.2.2. SOC of EV Battery

The SOC level of EV battery is one of the EV constraints which must be kept within certain limits during the V2G operation. It is important to establish these limits for two reasons. The first reason is to protect the health of the battery. Studies show that the SOC level of a lithium ion battery should best to be limited to a 60% swing (between 30% and 90% or 25–85%) to minimize the battery health degradation [60,61]. The second reason to keep the SOC level of the EV battery within certain limits is to reserve a certain amount of energy for the EV travel usage. Therefore, by taking both reasons into consideration, each EV is prevented from discharging if the battery SOC is lower than the *SOC*min which is set at 55%. Meanwhile, the EV charging process is only allowed if the SOC level of each EV battery is below the *SOC*max, which is set at 90% to prevent the battery overcharging issue. Both of the EV charging and discharging processes are allowed if the battery SOC is within the *SOC*min and *SOC*max:

$$\text{SOC}\_n \le \text{SOC}\_{\text{min}} \text{ allow for charging only}\tag{4}$$

*SOC*min ≤ *SOCn* ≤ *SOC*max, allow for charging and discharging (5)

$$\text{'SOC}\_{\text{ll}} \ge \text{'SOC}\_{\text{max}\_{\text{\textquotedbl}}} \text{ allow for discharging only} \tag{6}$$

where *SOCn* is the battery SOC for *n*th EV.

#### 3.2.3. EV Grid Connection Probability

The feasibility of V2G technology requires EVs to be connected to the power grid. Nevertheless, each EV can be connected to the power grid at different arrival and departure times in the car park, which will lead to the dynamic EV mobility characteristics [62–69]. Hence in this paper, the EV grid connection probability is estimated based on the driving behaviour of the township's residents and commercial workers. In Figure 4, the EV grid connection probability of the residential car park showed that more EVs are available in the car park, since the beginning of the day until 06:00 o'clock in the morning.

**Figure 4.** Electric Vehicle (EV) grid connection probability of the township.

Later on, most of the EV owners are away to their workplaces and schools. From 18:00 o'clock onwards, the residents started to return home and occupied the residential car park. On the other hand, the EV grid connection probability of the commercial car parks depicted that most of the parking spaces are occupied during the daytime office hours. Other than these periods, the commercial car park is almost empty. The combination of the EV grid connection probability of the residential and commercial car parks gave the total EV availability in the proposed generic township, as shown in Figure 4.

$$A\_n = 1,\text{ when }n\text{th EV was connected to the power grid}\tag{7}$$

$$A\_n = 0,\text{ when }n\text{th EV was not connected to the power grid}\tag{8}$$

#### 3.2.4. EV Power Exchange Rate

The power exchange rate between the EV batteries and power grid shall be restricted within a safe margin to protect the safety and health of EV batteries throughout the power exchange periods. A common EV battery available in the market is considered in this research. The EV battery used in this paper a lithium-ion battery, which has the rated capacity of 50 Ah. The power exchange rate of each EV battery is limited below 3.3 kW, which is the typical power rating for slow charging:

$$P\_{\text{EV,charging}} \le P\_{\text{EV,max}} \tag{9}$$

$$P\_{\rm EV, discharging} \leq -P\_{\rm EV, max} \tag{10}$$

where *P*EV,max is the maximum EV exchange rate.

#### *3.3. Optimization Algorithm*

The proposed V2G optimization algorithm is implemented in MATLAB software tool (R2013a, MathWorks, Natick, MA, USA) as shown in Figure 5.

In order to handle a large number of parameters, the GA optimization technique is adopted. The GA is an iteration method that is capable of searching for the global optimal solution within an execution time limit. Furthermore, the GA is inspired by the living organism evolutionary process, which requires the representation of a potential solution as the genetic chromosome. A proper fitness function is utilized to compute and evaluate the score of this genetic chromosome. After the evaluation, the GA principle is repeated again to reproduce a new generation of chromosome until this iteration converges to an optimal solution.

In the initial stage of the proposed V2G algorithm, the system parameters are obtained and updated into the database. With this information, the GA algorithm evaluates the fitness function of the grid load variance minimization, which later produce the next generation of solution. The evaluation repeated itself until the iteration converged to an optimal EV charging or discharging power. This optimization process is bound by the power grid and EV constraints. Meanwhile, the V2G optimization algorithm is executed for every hour.

With respect to the constraint limits, the proposed V2G optimization algorithm performed the peak load shaving and load levelling services by utilizing the EV battery storages in order to minimize the load variance, as it is shown in Figure 5.

**Figure 5.** Flowchart for the proposed V2G optimization algorithm.

#### **4. Results and Discussion**

In this section, the feasibility of the proposed V2G optimization algorithm that was investigated under different scenarios was elaborated. Various average initial SOC of EV batteries (*SOCi,ave*) and target load curve in percentage (*TLCpct*) were considered to examine the performance of the proposed V2G optimization algorithm. The definitions of the *SOCi,ave* and *TLCpct* are shown in Equations (11) and (12), correspondingly:

$$\text{Average initial SOC of EV Butteries (SOC}\_{i,\text{ave}}) \stackrel{\text{\tiny\begin{subarray}{l}\sum\space\in}K\_{\text{H}}A\_{\text{H}}\text{SOC}\_{\text{H}} \text{ \rightarrow \atop\sum\space\in} \text{F}}{\text{N}} \tag{11}$$

$$\text{Percentage of Target Load Curve } (TLC\_{pt}) = \frac{\text{target load curve}}{\text{peak load}} \times 100\% \tag{12}$$

All the scenarios were conducted in the generic commercial-residential township as depicted in Figure 2. Figures 6–8 present the comparison between the optimized power load curves and original power load curves, where the *TLCpct* were set at 50%, 55% and 60%, respectively. In each scenario, different *SOCi,ave* of 40%, 50%, 60%, 70% and 80% were applied. Based on the preset values of the *SOCi,ave* and *TLCpct*, different optimized power load curves were acquired with the implementation of the proposed V2G optimization algorithm. For instance, the scenario in Figure 6a shows that the

*SOCi,ave* was set at 40% and the *TLCpct* was kept at 50% of the peak loading of the power load curve. Since the *SOCi,ave* was low, the proposed V2G optimization algorithm can perform the load levelling service by the EV charging operation, but not the EV discharging operation for the peak load shaving service. In contrast, reversed outcomes can be observed for scenario in Figure 8e due to higher *SOCi,ave* and *TLCpct*.

**Figure 6.** Optimized power load curves with 50% *TLCpct* and *SOCi,ave* of (**a**) 40%, (**b**) 50%, (**c**) 60%, (**d**) 70% and (**e**) 80%.

**Figure 7.** Optimized power load curves with 55% *TLCpct* and *SOCi,ave* of (**a**) 40%, (**b**) 50%, (**c**) 60%, (**d**) 70% and (**e**) 80%.

**Figure 8.** Optimized power load curves with 60% *TLCpct* and *SOCi,ave* of (**a**) 40%, (**b**) 50%, (**c**) 60%, (**d**) 70% and (**e**) 80%.

The consideration of various values of *SOCi,ave* and *TLCpct* had led to different optimization results. In certain scenarios, the optimized load curves were not completely flat due to the fact the required energy demand for peak load shaving and load levelling services exceeded the available energy capacity of the EV batteries. In other words, EV batteries cannot supply or absorb the required energy for the minimization of grid load variance. Therefore, an index denoted as Performance Index was introduced to allow better comparison among the optimized power load curves. The Performance Index indicated the percentage of successful operations of the peak load shaving, load levelling or combination of both to achieve the preset target load curve over a day. The Performance Index can range from zero to one, where greater value indicates higher successful rate. Table 1 presents the Performance Index of the proposed V2G optimization algorithm for all the scenarios depicted in Figures 6–8. Three sets of the Performance Index were calculated for peak load shaving, load levelling and both services together.

With reference to the Performance Index in Table 1, the capability of peak load shaving was enhanced while the capability of load levelling was reduced with the increase of *SOCi,ave*. These situations were due to the increase in the available EV energy to be discharged for the peak load shaving, as well as the reduced need of EV batteries to receive charging from the power grid and thus limited the load levelling. Likewise, the occurrence of similar trends can be determined with the increase of the *TLCpct*, where more peak load shaving service can be accomplished while fewer load levelling can be achieved using the proposed optimization algorithm. The reason was due to the required EV discharging energy for the peak load shaving was greatly reduced when the set point of *TLCpct* was increased. However, the load levelling became more difficult to be achieved due to the significant increase of energy required to be charged into the EV batteries.


**Table 1.** Performance Index of the V2G optimization algorithm under various scenarios.

Other than the two individual set of Performance Index values for peak load shaving and load levelling, the overall Performance Index shows the success percentage for both peak load shaving and load levelling. The shaded region of the overall Performance Index in Table 1 indicates the best *TLCpct* to be selected with respect to the *SOCi,ave*. Figures 9 and 10 illustrate the Performance Index under various scenarios and gives a clearer perception on the overall optimized scenarios. The peak point in Figure 10 shows the best optimized scenario with the overall Performance Index of 0.965, which dropped under the 60% of *SOCi,ave* and 55% of *TLCpct* category. This has verified that the selection of target loading for the V2G optimization algorithm played a significant role in ensuring the performance of the algorithm.

A detailed analysis on the best scenario is further presented in Figure 11. With the implementation of the proposed V2G optimization algorithm, the achieved optimized power load curve for the category of 60% of *SOCi,ave* and 55% of *TLCpct* is shown in Figure 11a. The optimized power load curve has almost met all the target loadings throughout the day, except during the periods from 05:00 to 08:00 o'clock.

Figure 11b presents a clearer insight to explain the operations during these periods. The bar graphs in the positive and negative regions in Figure 11b depict the maximum available capacity of the EV batteries and stored energy for the load levelling and peak load shaving, correspondingly. These bar graphs were obtained by considering all the constraint limits as specified in Section 3.2 and therefore, served as the limits for the optimization process. The curve shown in Figure 11b presents the

optimized EV charging and discharging power required to achieve the optimized power load curve as shown in Figure 11a. During the periods from 05:00 to 08:00 o'clock, the optimized EV charging power had reached the maximum limit of the available capacity of EV batteries for the load levelling service. Consequently, the load levelling service was not completely achieved in the optimization process.

**Figure 9.** Performance Index under various scenarios: (**a**) peak load shaving and (**b**) load levelling.

**Figure 10.** Overall Performance Index under various scenarios.

**Figure 11.** Detailed description of the best optimized scenario: (**a**) optimized power load curve (**b**) optimized EV charging and discharging power within constraint limits.

Figure 12 shows the SOC status of some random selected EVs under the best optimized scenario. During the load levelling periods, all the EVs experienced the charging process, except for the EVs with the SOC level higher than the *SOC*max of 90%. Meanwhile, all the EVs discharged their battery energy during the peak shaving periods, due to having all the SOC levels of EV batteries higher than the *SOC*min of 55%. Another observation from Figure 12 is that the EVs participating in the V2G optimization program had the tendency to reach to a similar SOC level at the end of the optimization process. These findings indicated that the proposed V2G optimization algorithm can flatten the power load curve with respect to the pre-determined SOC constraints.

The performance of the proposed V2G optimization algorithm was compared with other algorithms in the latest literature. A comparative parameter defined as the percentage improvement of peak and valley load difference, *Pi* was introduced to assess the algorithm performances that were conducted under different scopes and conditions. The formulation of *Pi* is expressed in (13):

$$P\_l = \left| \frac{P\_{d,after} - P\_{d,before}}{P\_{d,before}} \right| \times 100\% \tag{13}$$

where *Pd,after* is the peak and valley load difference after V2G optimization and *Pd,before* is the peak and valley load difference before V2G optimization.

**Figure 12.** The SOC status of random selected EVs under the best optimized scenario.

Both *Pd,after* and *Pd,before* can be calculated using Equations (14) and (15), respectively:

$$P\_{d,after} = P\_{p,after} - P\_{v,after} \tag{14}$$

$$P\_{d,before} = P\_{p,before} - P\_{v,before} \tag{15}$$

where *Pp,after* is the peak load value after V2G optimization, *Pv,after* is the valley load value after V2G optimization, *Pp,before* is the peak load value before V2G optimization, and *Pv,before* is the valley load value before V2G optimization.

The V2G algorithm proposed in [55] was capable of performing peak shaving and valley filling control. The power grid loading before the implementation of V2G algorithm had *Pp,before* of 1090 MW and *Pv,before* of 855 MW. With the execution of V2G algorithm, the power grid loading presented *Pp,after* of 1080 MW and *Pv,after* of 950 MW. Hence, the computed *Pi* using (13) was 44.68%. A similar investigation was conducted for the researches in [56,57], where the computed *Pi* acquired was 46.89% and 36.84%, respectively. The analysis was also investigated on the best scenario (V2G optimization with 60% of *SOCi,ave* and 55% of *TLCpct*) in this paper. The power grid loading before the implementation of the proposed V2G algorithm presented *Pp,before* of 4.6 MW and *Pv,before* of 1.3 MW. Meanwhile, the power grid loading after the employment of the V2G algorithm achieved *Pp,after* of 2.5 MW and *Pv,after* of 2.1 MW. Thus, *Pi* was acquired to be 87.88%. By comparing with the other literatures, the proposed algorithm in this paper shows a better performance in terms of the percentage improvement of peak and valley load difference. The details of the comparative analysis are presented in Table 2.


**Table 2.** Comparative analysis of the proposed algorithm with other approaches for grid load variance minimization.
