Code for Intelligent Charging Strategy of Electric Vehicle

(29 customer reviews)


Total downloads: 5

This repository of code optimize the charging schedule of EV and maximizes the profit by reducing the charging cost. It also charges the vehicle upto 95% SoC. We used Ant Lion optimization algorithm to optimize the multiobjective nonlinear constraint problem of charging using MATLAB.

This repository contains:

  • Complete MATLAB code

Note: The free version of this code has a limited 5 trials and few protected files. Once the 5 trials are completed, the code will be deleted and MATLAB will be closed.



  • 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 single-objective problem.

Code Execution Video

You are reading this article at

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 SoCdesired 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.

Pipeline to Optimize the EV Charging Schedule - Free-thesis
Pipeline to Optimize the EV Charging Schedule – Free-thesis

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 vice-versa. 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. Multi-objective Function Converted to the Single Objective

We converted this multi-objective 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 The equilibrium betwen ALO and EV charging schedule is shown in figure 2.

System between ALO optimization and EV charging - Free-Thesis
System between ALO optimization and EV charging – Free-Thesis

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 all-electric 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 1-8 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

Code Overview free-thesis

This code is developed for simulating the power management strategy of Plug-in 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.


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 time-of-use 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 state-of-charge (SOCini) is randomly assigned within a range of 0.2 to 0.6. The maximum state-of-charge (SOCmax) and the desired state-of-charge (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 time-of-use pricing structure for summer and winter seasons. The code then sets the parking time of PHEVs and the initial state-of-charge (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:

  1. 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.
  2. 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 Time-of-Use (TOU) pricing of electricity during peak and off-peak 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:

  1. 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’.
  1. 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.6-0.2).*rand(1,n): Sets the initial SOC of each PHEV randomly between 0.2 and 0.6.
  • PkTime=1+(8-1).*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.


  1. Tong, J., Zhao, T., Yang, X., & Zhang, J. (2014, August). Intelligent charging strategy for PHEVs in a parking station based on Multi-objective optimization in smart grid. In 2014 IEEE Conference and Expo Transportation Electrification Asia-Pacific (ITEC Asia-Pacific) (pp. 1-6). IEEE.
  2. Mirjalili, S. (2015). The ant lion optimizer. Advances in engineering software83, 80-98.
  3. 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. 1-6). IEEE.
  4. 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. 1-6). IEEE.

admin is an innovative and first of its kind platform created by Vidhilekha Soft Solutions Pvt Ltd, a Startup recognized by the Department For Promotion Of Industry And Internal Trade, Ministry of Commerce and Industry, Government of India recognised innovative research startup.

Additional information

Download Type


29 reviews for Code for Intelligent Charging Strategy of Electric Vehicle

  1. 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 meta-heuristic algorithms.

  2. sowmya.r (verified owner)

    Very good resources

  3. k.park (verified owner)


  4. bijaydas123 (verified owner)

    I am working electric vehicle charging cost minimization using pso. The matlab coding will be helpful to me

  5. sumeet.kumar (verified owner)


  6. jayati.vaish (verified owner)


  7. addef.afrcs (verified owner)


  8. yasin.bektas (verified owner)

    very good

  9. karthick.tamilarasu (verified owner)


  10. karthick.tamilarasu (verified owner)


  11. karthick.tamilarasu (verified owner)


  12. karthick.tamilarasu (verified owner)


  13. kumar.das (verified owner)

    p file

  14. uday.deshmukh (verified owner)


  15. magda.el-afifi (verified owner)

    very good

  16. akbaralipaper (verified owner)


  17. bijaydas123 (verified owner)

    I am working on Electric Vehicle charge scheduling. It will be helpful in my research

  18. shawon.chowdhury (verified owner)


  19. hrishikesh.urde (verified owner)


  20. subra (verified owner)


  21. nandan.navin (verified owner)


  22. sasmita.tripathy (verified owner)


  23. sheila.khan (verified owner)

    I m working on SOC of electric vehicles battery bms

  24. sheila.khan (verified owner)

    I m working on SOC of electric vehicles battery bms

  25. amisha.maithil (verified owner)


  26. ajay.sharma (verified owner)


  27. 13557020979 (verified owner)


  28. 13557020979 (verified owner)


  29. aya.desoky (verified owner)


Only logged in customers who have purchased this product may leave a review.