Description
Highlights
 This MATLAB code implements the intelligent charging scheduling of EVs for minimum electricity cost and minimum load on the grid.
 A heuristic optimization called Ant Lion Optimization (ALO) is followed to minimize the charging time and cost of the EV charging
 The multiobjective problem is presented as a weighted singleobjective problem.
Code Execution Video
You are reading this article at https://freethesis.com.
Problem Statement
The smart charger of Electric vehicle charging has all information like the initial state of charge, the desired state of charge, departure time, plug in time etc. All this information is passed through the controller which estimates the charging time and adjusts the cost of charging. As soon as the electric vehicle connects with charger, the controller calculates maximum charging time for the desired SoC. If the SoC_{desired }is not attained in that charging time then the vehicle will not take part in the scheduling and it charges fully without pool till desired SoC for customer’s satisfaction.
We used ALO as intelligent charging scheduler of electric vehicles. The two objective functions are combined to a single objective function.
Objective Function
1. Minimizing Charging Cost
The charging cost of the electric vehicle depends on the load variance. The nature of the load affects the electricity requirement. For heavy loadsÃ‚Â high demand of electricity is required so, charging cost increases and viceversa. The objective function for this is
2. Minimizing the load variance
The load variance minimization is necessary as cost minimization inserts the load peak in the grid which results in power losses. So load variation is defined as:
3. Multiobjective Function Converted to the Single Objective
We converted this multiobjective problem into a single objective as:
This objective function is optimized with the help of ant lion optimization considering few constraints. The main constraint is maximum power provided to each electric vehicle which should not be greater than the power provided to the charger. Following constraints are
ALO Optimization of charging controller
The intelligent charging of electric vehicle depends on the power supplied to the vehicle for the charging purpose at each time stamp. This power is optimally tuned by the Ant Lion Optimization algorithm (ALO). Ant lion optimization is available on freethesis.com. The equilibrium betwen ALO and EV charging schedule is shown in figure 2.
As shown in the figure the ALO module gets the power for all EV at each time stamp for charging in the input and updated objective function as equation 3 in the output. This output of the objective function is fed back to ALO which affects the power of the charging and minimize the objective function value. It is an iterative process and in each iteration, the position of the Ant lion’s will be updated and forward to PHEV charging module which then computes the value of objective function.
We considered 50 electric vehicles for the time stamp of 24 hrs and it makes the tuning variables of dimension 50×24= 1200. Each set of tuning parameter represents the ant lion’s and ant’s position. The ALO optimization method converges to minima by setting these 1200 variables in the fitness function. In each iteration, the ant’s position is updated to satisfy the constraints above.Ã‚Â For the first iteration, the position of all ants and lion ants are initialized randomly within the limits of maximum and minimum power. A new matrix is saved for the objective value in every iteration for all ants and lion ants. Minimum value index in the matrix is the best value so far which is further updated by ALO. After a few iterations, the saturation value of the objective function is reached and no more minimum value is obtained. This is the termination criteria of ALO optimization algorithm which indicates that the best power set of allelectric vehicle in each time stamp is achieved. Earlier is this convergence better is the optimization.Ã‚Â The equivalent terminology of ALO with the PHEV charging schedule application is shown in table 1.
Table 1: Terminology for PHEV in ALO
ALO terminology  Equivalent terminology in PHEV charging scheduling 
Searching space of ants and ant lions  Minimum and maximum constraint of charging power for each vehicle 
Dimension of searching space  Number of tuning variables which is equal to 
Fitness value  Objective function value 
Steps for controlling of EV charging
 consider the input attributes like maximum/ minimum power, maximum /minimum SoC, number of electric vehicles etc.
 initialise the ant’s and ant lion’s positions randomly which is the power applied to each vehicle for the charging.
 this power applied is sent to objective function module which considers the electric load in summer and winter separately with corresponding TOU price.
 The parking time of each EV is randomly decided between 18 hrs.
 Based on the charging rate, charging of each EV during that parking time is calculated by the charging power received.
 check the constraints of state of charge (SoC). If it violates the limit then change the violated value with either minimum or maximum boundary which keeps them at the boundary as a penalty.
 calculate the cost of charging for the given charging power based on per unit price from the grid.
 calculate the load variation in due to the all EV charging
 combine both values in step 7 and step 8 using equation 4.3 and pass these values to ALO module.
 ALO update the previous charging power to minimize the objective function value in step 9 using equations from 3.2 to 3.8.
 The minimum values out of all iterations are considered as the best power set supplied to the EV which occurs the minimum cost on the customer with least load variation in supply and with EV charged till desired SoC.
EV Charging Scheduling Code Overview
This code is developed for simulating the power management strategy of Plugin Hybrid Electric Vehicles (PHEVs) charging in a residential environment. The code is written in MATLAB and requires MATLAB version R2019a or higher.
Data Load
The code first loads the load demand data of several household appliances from three different regions: USAAKFairbanksData, USAAKAnchorageData, and USAKSHaysData [4]. Then, it combines the load data for a whole year, converts the timestamp into decimal, and creates two different profiles for summer and winter seasons.
Visualization
The code plots the load profile comparison for various household appliances in summer and winter, separately, along with the total load profile comparison for a day in both seasons.
Charging Strategy
The charging strategy is based on the optimization of charging schedule of PHEVs in a residential environment. The code defines charging parameters such as the number of charging vehicles, maximum power (Pmax) that can be drawn by a single vehicle, and the time steps (m). The code also sets the timeofuse pricing structure for summer and winter seasons.
The charging strategy implemented is the Artificial Lion Optimization (ALO) algorithm. The ALO algorithm is a metaheuristic optimization algorithm that is inspired by the hunting behavior of lions. It has been used to solve various optimization problems, including the scheduling of charging of PHEVs.
The objective function (objf) used in the ALO algorithm is defined outside the main code. It is passed to the ALO algorithm as a function handle. The ALO algorithm optimizes the charging schedule for PHEVs by minimizing the objective function, which takes into account the constraints and requirements of the problem.
Charging Parameters
The code sets the charging parameters such as the number of charging vehicles (n), maximum power (Pmax), total time steps (m), time step interval (deltaT), and parking time of PHEVs (PkTime). The initial stateofcharge (SOCini) is randomly assigned within a range of 0.2 to 0.6. The maximum stateofcharge (SOCmax) and the desired stateofcharge (SOCdesire) are set at 0.95 and 0.9, respectively.
Main Code
The main code starts by setting the number of charging vehicles, maximum power that can be drawn by a single vehicle, and the total time steps (in Hr). It also sets the time step interval and the timeofuse pricing structure for summer and winter seasons. The code then sets the parking time of PHEVs and the initial stateofcharge (SOCini) for each vehicle.
The ALO algorithm starts after the initialization of the required variables. It optimizes the charging schedule for PHEVs by minimizing the objective function (objf). The ALO algorithm is run for 60 iterations. Finally, the charging schedule is plotted for each vehicle, showing the charging power at each time step.
The main code can be segmented into two major sections:
 Load profile analysis: The code loads the load demand data of several household appliances, combines it for a whole year, and then splits it into two parts – summer and winter. It then plots the load profiles of the appliances for a day in summer and winter and also plots the total load profile for a day.
 PHEV charging schedule optimization: The code uses an Artificial Life Optimization (ALO) algorithm to optimize the charging schedule of a fleet of PHEVs. The algorithm minimizes the charging cost of PHEVs while ensuring that the State of Charge (SOC) of each PHEV is maintained within a certain range. The charging cost is calculated based on the TimeofUse (TOU) pricing of electricity during peak and offpeak hours in summer and winter. The optimization algorithm is implemented in a function ‘objf’.
Here is a small gist of some of the key codes in the above two parts:

Load profile analysis:
load USAAKFairbanksData
: Loads the data for one of the locations.combineData=cell2mat(USAAKFairbanks(:,2:end))+cell2mat(USAAKAnchorage(:,2:end))+cell2mat(USAKSHays(:,2:end))
: Combines the data for all three locations.summerdataIndex=[find(data(:,1)==summerTime(1)):find(data(:,1)==summerTime(2))]
: Finds the indices of data for the summer season.TotalsummerLoad=sum(summerLoadData,2)
: Calculates the total load in summer in KW.fobj = @objf
: Assigns the optimization function ‘objf’ to the variable ‘fobj’.

PHEV charging schedule optimization:
n=50
: Specifies the number of charging vehicles.TOUPrice.summer=[0.15085.*ones(1,12),0.01514.*ones(1,12)]
: Sets the TOU pricing for summer season.SOCini=0.2+(0.60.2).*rand(1,n)
: Sets the initial SOC of each PHEV randomly between 0.2 and 0.6.PkTime=1+(81).*rand(1,n)
: Sets the parking time of each PHEV randomly between 1 and 8 hours.fobj = @objf
: Assigns the optimization function ‘objf’ to the variable ‘fobj’.ALO(fobj,dim,Max_iteration)
: Calls the ALO function to optimize the charging schedule of PHEVs.
References
 Tong, J., Zhao, T., Yang, X., & Zhang, J. (2014, August). Intelligent charging strategy for PHEVs in a parking station based on Multiobjective optimization in smart grid. InÂ 2014 IEEE Conference and Expo Transportation Electrification AsiaPacific (ITEC AsiaPacific)Â (pp. 16). IEEE.
 Mirjalili, S. (2015). The ant lion optimizer.Â Advances in engineering software,Â 83, 8098.
 Su, W., & Chow, M. Y. (2011, July). Performance evaluation of a PHEV parking station using particle swarm optimization. InÂ 2011 IEEE power and energy society general meetingÂ (pp. 16). IEEE.
 Shao, S., Zhang, T., Pipattanasomporn, M., & Rahman, S. (2010, April). Impact of TOU rates on distribution load shapes in a smart grid with PHEV penetration. InÂ IEEE PES T&D 2010Â (pp. 16). IEEE.
Kay (verified owner) –
A good code for skipping a whole bunch of stress to develop a charging system. The code guides through the basics of charging and also helps understand metaheuristic algorithms.
sowmya.r (verified owner) –
Very good resources
k.park (verified owner) –
x
bijaydas123 (verified owner) –
I am working electric vehicle charging cost minimization using pso. The matlab coding will be helpful to me
sumeet.kumar (verified owner) –
Ghn
jayati.vaish (verified owner) –
good
addef.afrcs (verified owner) –
Fab
yasin.bektas (verified owner) –
very good
karthick.tamilarasu (verified owner) –
fdhrswfhgrrrrrrrrrrrrr
karthick.tamilarasu (verified owner) –
fdhrswfhgrrrrrrrrrrrrr
karthick.tamilarasu (verified owner) –
fdhrswfhgrrrrrrrrrrrrr
karthick.tamilarasu (verified owner) –
fdhrswfhgrrrrrrrrrrrrr
kumar.das (verified owner) –
p file
uday.deshmukh (verified owner) –
great
magda.elafifi (verified owner) –
very good
akbaralipaper (verified owner) –
excellent
bijaydas123 (verified owner) –
I am working on Electric Vehicle charge scheduling. It will be helpful in my research
shawon.chowdhury (verified owner) –
fine
hrishikesh.urde (verified owner) –
good
subra (verified owner) –
good
nandan.navin (verified owner) –
thanx
sasmita.tripathy (verified owner) –
good
sheila.khan (verified owner) –
I m working on SOC of electric vehicles battery bms
sheila.khan (verified owner) –
I m working on SOC of electric vehicles battery bms
f.w (verified owner) –
Very nice
akbaralipaper (verified owner) –
very good