current position:Home>Matlb| optimal scheduling of electric vehicle charging and discharging

Matlb| optimal scheduling of electric vehicle charging and discharging

2022-06-24 07:56:23Power system code

Catalog

One 、 summary

Two 、 electric vehicle

2.1  Types of electric vehicles

2.2 Start time of electric vehicle journey

2.3 Electric vehicle mileage

3、 ... and 、Matlab Realization

3.1 Preparation before code

3.2 Matlab Code

3.3 Running results

  Four 、 Looking back

 

One 、 summary

The good development of electric vehicles can not be separated from accurate electric vehicle charging load forecasting , at present , Most of the research on charging load forecasting is based on Monte Carlo simulation algorithm . among , The literature [13] Divide electric cars into private cars 、 Three types of buses and taxis are analyzed and modeled , However, there is a certain subjectivity in the selection of the initial state of charge and the initial charging time distribution of the vehicle . The literature [14] The statistical method is used to establish the probability distribution model of travel end time and daily mileage , It is considered that the end time of the journey is equal to the starting charging time , But the daily charging frequency is greater than 1 It doesn't make sense for the next electric car . The literature [15] The daily mileage and battery capacity of electric vehicles are considered , However, the determination of the starting time of charging is not accurate . in summary , The current research is not comprehensive enough , The prediction is not accurate enough , for example :1) The travel trajectory distribution of electric vehicles is not considered ;2) The uncertainty of the EV charging site is not taken into account .

Two 、 electric vehicle

For the load of electric vehicles , The influencing factors are never single , It is influenced by many factors . Its size and travel trajectory distribution are also controlled by various situations , For example, whether the performance of electric vehicles is good 、 Whether the use mode of automobile users is appropriate 、 Whether the charging environment of the electric vehicle is suitable and whether the driving road surface of the electric vehicle is flat . If you want to further accurately predict the travel trajectory distribution of electric vehicle charging load , The following possible influencing factors need to be considered in depth : Types of electric vehicles 、 Starting time of electric vehicle journey electric vehicle mileage ﹑ Dwell time 、 Charging mode, etc .

2.1  Types of electric vehicles

At present, there are three kinds of electric vehicles widely used in China : Private car 、 The taxi 、 The bus , The bus basically runs according to the planned track and time point , The travel track and time are relatively fixed , Therefore, it is relatively simple to determine the charging place ; It is difficult to determine the charging place for private cars and taxis due to the complex travel trajectory and uncertain travel time . therefore , The location and size of charging load will show some differences due to different types of electric vehicles .

2.2 Start time of electric vehicle journey

For electric cars , There is obviously a close relationship between the daily use time and the time distribution of charging , This paper uses the statistical results of a survey , From it, the starting time of a private car's journey in a day is called out to study the operating characteristics of electric vehicles .
Using actual data , The probability distribution of travel start time of electric private car can be obtained . The probability distribution of user travel start time is shown in the figure 1 Shown .

              

Fit the probability distribution , It is found that the probability of the user's travel start time approximately obeys the normal distribution, and its probability density function is :

                

among ,\mu Is the expected start time of the trip ,\sigma Is the standard deviation . After fitting, obtain \mu =7.89,\sigma=1.96.

2.3 Electric vehicle mileage

The charging frequency and time of electric vehicle users are closely related to their daily mileage . The mileage of sunrise trip will also vary according to different users , This is mainly due to the different usage habits of electric vehicle users , For private cars , It is mainly used for commuting, leisure and entertainment , The mileage is short and regular .

according to 2017 year NHTS The results show that , The mileage of electric private cars tends to be lognormal distribution , Its probability density function is :

      

among ,\mu Is the expected travel distance ,\sigma Is the standard deviation . After fitting, obtain \mu =3.68,\sigma =0.88. 

  The daily mileage of taxis is about 300km, It is the model with the longest mileage among the three ; The bus runs daily than the taxi

The mileage is relatively small , about 200km.

3、 ... and 、Matlab Realization

3.1 Preparation before code

install CVX package :

First click here : Stochastic dynamic economic dispatch model of wind power

then : It is also the preparation before the code

3.2 Matlab Code

This paper is an optimal scheduling algorithm , To minimize the total cost of electric vehicle charging and discharging .

This article only shows part of the code , All code points here : We are shipping your work details

close all;
clc;
clear;


%%  Parameter setting 

%==(1) Basic charge vector ===
L_b=[
    1648181.19
    1510114.92
    1404600.51
    1348140.62
    1355294.53
    1380434.41
    1472398.73
    1619859.88
    1774726.71
    1891739.09
    2024589.36
    2154006.65
    2214969.44
    2248348.3
    2257444.05
    2253898.58
    2251095.52
    2240891.11
    2187658.11
    2060455.55
    2032531.95
    1984614.47
    1846244.76
    1676395.15];

%====(2) Predicted base load ( Average relative error  = 0.089)====
P_L_b1=[
    1737223.863
    1603267.075
    1501043.33
    1434323.708
    1427034.265
    1445808.13
    1535646.84
    1703557
    1878913.403
    2041190.428
    2189203.243
    2300813.958
    2376838.56
    2431838.998
    2456820.033
    2472628.88
    2497750.498
    2502256.753
    2487853.418
    2333072.535
    2313458.498
    2278059.543
    2121749.573
    1908084.005];


%====(3) Predicted base load ( Average relative error  = 0.0414)====
P_L_b2=[
    1599948.91
    1468345.518
    1370502.199
    1310946.046
    1308525.559
    1330298.288
    1417044.254
    1592177.276
    1774327.31
    1935791.394
    2081450.673
    2194127.508
    2266347.528
    2310264.895
    2317806.969
    2328853.886
    2350763.395
    2356239.943
    2340220.599
    2215920.234
    2192252.838
    2168526.739
    2014122.374
    1803843.804];

%=====(4) Base load for the second forecast ( Better prediction )( Average relative error =0.0234)===
P_L_b3=[
    1648037.519
    1458944.669
    1366366.043
    1310276.476
    1309105.99
    1329282.055
    1411672.493
    1587762.671
    1728429.463
    1888917.875
    2032770.183
    2133804.711
    2199858.463
    2240117.111
    2241852.165
    2245048.574
    2259487.69
    2260142.395
    2243557.341
    2145562.018
    2122157.145
    2104126.554
    1948760.596
    1740961.875];

%===== Select which forecast load to use ====
P_L_b=P_L_b2;

%%  Base load of microgrid 
Scale_factor=1/1500;
L_b_mic=L_b*Scale_factor;  %  Base load 
P_L_b_mic=P_L_b*Scale_factor;  %  Basic forecast load 

%%  Price model 
% alfa=1.0;
% theta=1;
omega=1.2*max(L_b_mic);
k_0=0.0001;
k_1=0.00012;
k_2=0;
%====(1) Life reduction costs ======
beta=0.001;
beta=0;

%=== Simple multiplication =====
% k_con=alfa/(omega^theta*(theta+1));

%===== Charging interval ======
tau=1; %  Within hours 

%===== Number of charging intervals ========
num_slot=length(L_b_mic);

%====(2) Basic price =======
price_basic=zeros(num_slot,1); %  Base load based prices 
for i=1:num_slot
    price_basic(i)=k_0+k_1* L_b_mic(i);
end
fprintf(' Price , The lowest price =%g, The highest price =%g.\n',min(price_basic), max(price_basic));


%%  electric vehicle EV Capacity 
Cap_battery_org=16; % KWh
gamma=0.9; %  Percentage of battery at completion of charging 
Cap_battery=gamma*Cap_battery_org;

%% == Maximum charge rate ===
P_max=5; % KW

%%  Number of electric vehicles 
num_EV=200;

%  Percentage of electric vehicles that only charge the battery 
P_Chg=0;

% CHG EVs Number 
num_CHG_EV=round(P_Chg*num_EV);  % CHG EV  Will be located at  EV  The front part of the information matrix .
% V2G EVs Number 
num_V2G_EV=num_EV-num_CHG_EV;

%%  Electric vehicle charging mode 
% 30%  Of electric cars at intervals  1  Previously connected to the charging station , The rest are evenly distributed 

%EV matrix :1)  Arrival time ,2)  Departure time ,3)  Initial energy ,4)  Charging cycle ,5)  Minimum charging time %

% EV_info=zeros(num_EV,3);
%=== interval 1 Front access station EVS percentage ====
% Per_EV=0.1;
%===== Arrival times of other vehicles are evenly distributed in [  1,20 ] Between ======
% for i=1:num_EV
%     temp_00=rand;
%     if temp_00<=Per_EV
%         T_arrival(i,1)=1;
%     else
%         T_arrival(i,1)=round(1 + (20-1).*rand);
%     end
% end
%
%===== The charging time is evenly distributed over  [4, 12]  Between hours ======
% T_charging= round(4 + (12-4).*rand(num_EV,1));
% T_charging=-1*sort(-1*T_charging);
%
% % the departure time
% for i=1:num_EV
%     T_departure(i,1)=min(24, T_arrival(i,1)+T_charging(i,1));
% end
%==== The initial charge is evenly distributed over the battery capacity [0 0.8] Between ======
% Ini_percentage=0+ (0.8-0).*rand(num_EV,1);
% % fill the EV_info
% EV_info(:,1)=T_arrival;
% EV_info(:,2)=T_departure;
% EV_info(:,3)=Cap_battery_org*Ini_percentage;
%
% for i=1:num_EV
%     EV_info(i,4)=EV_info(i,2)-EV_info(i,1)+1; %  Charging cycle 
%     EV_info(i,5)=EV_info(i,3)/P_max; %  Minimum charging time 
%     if EV_info(i,4) < EV_info(i,5)
%         fprintf('EV %g  The charging time is unreasonable .\n',i);
%     end
% end
%
% % save and load EV_info
% save EV_info.txt EV_info -ascii;

load EV_info.txt;
EV_info=EV_info(1:num_EV,:);

%%  Relationship between electric vehicle and charging interval 
F=zeros(num_EV, num_slot);
G=ones(num_EV, num_slot);
for i=1:num_EV
    for j=EV_info(i,1):EV_info(i,2)
        F(i,j)=1;
        G(i,j)=0;
    end
end
F1=reshape(F',1,[]);
% F=ones(num_EV, num_slot);

%%  Draw the base load 
xx_1=1:num_slot;
figure;
yy_1(:,1)=L_b_mic;
yy_1(:,2)=P_L_b_mic;
plot(xx_1,yy_1);
ylabel(' load [KW]');
xlabel(' Hours ');
legend(' Actual load ',' Forecast load ');

%%  Use CVX The tool V2G Global optimal solution 

%(1) Equality constraints : Ax=b
% (2) Optimization variables x=[z1, z2, ..., z_24, x11, x12, ...., x_100,24]'
num_OptVar=1*num_slot+num_slot*num_EV;
b_a=L_b_mic; % The first equality constrained matrix 
A1_a=zeros(num_slot, num_OptVar-1*num_slot);
A1=[eye(num_slot) A1_a];

A2_a=zeros(num_slot, num_OptVar-1*num_slot);
s_temp=0;
for i=1:num_slot
    for j=1:num_EV
        A2_a(i, (j-1)*num_slot+i)=F(j,i);
        % fprintf('Assign F(%g,%g)=%g, to A2_a(%g, %g).\n',j,i,F(j,i),i,(j-1)*num_slot+1);
        s_temp=s_temp+F(j,i);
    end
end
A2_b=zeros(num_slot, num_slot);
A2=[A2_b A2_a];

A_a=A1-A2;  %  The first equality constrained matrix 
clear A1 A2 A1_a A2_a A2_b;

%====== The first equality constrained matrix =====
B_1=zeros(num_EV, num_OptVar-1*num_slot);
for i=1:num_EV
    B_1(i,(i-1)*num_slot+1:(i-1)*num_slot+num_slot)=F(i,:);
end
temp_1=zeros(num_EV, num_slot);
B1=[temp_1 B_1];    %  Matrix of the second equality constraint 
b_b=(Cap_battery/tau)*ones(num_EV,1)-EV_info(:,3);%  Matrix of the second equality constraint 
clear  B_1  temp_1;

% Merge equality matrix 
% Eq_left=[A_a' B1']';
% Eq_right=[b_a' b_b']';


%% ====== Equality constraints =====
Eq_L=A_a;
Eq_R=b_a;
clear  A_a  b_a;
%% ====== Inequality constraints =====
% ====1) The first inequality constraint =====
In_1=zeros(num_EV*num_slot, num_OptVar);
for i=1:num_slot
    for j=1:num_EV
        In_1((i-1)*num_EV+j,num_slot+(j-1)*num_slot+1:num_slot+(j-1)*num_slot+i)=F(j,1:i);
        %         fprintf('set row %g, col %g:%g by using F(%g,1:%g).\n',(i-1)*num_EV+j,num_slot+(j-1)*num_slot+1,num_slot+(j-1)*num_slot+i,j,i);
    end
end
In_1=-1*In_1;  %  The first inequality , On the left 
In_b1=zeros(num_EV*num_slot, 1);    %  The first inequality , On the right , [EV1_slot1, EV2_slot1, ..., EV1_slot2, EV2_slot2,...]'
for i=1:num_slot
    In_b1( (i-1)*num_EV+1:(i-1)*num_EV+num_EV, 1 )= (1/tau)*EV_info(1:num_EV,3);
end

%=====2) The second inequality constraint =====
In_2=-1*In_1; % The second inequality constraint , On the left 
In_b2=zeros(num_EV*num_slot, 1);    %  The second inequality constraint , On the right , [EV1_slot1, EV2_slot1, ..., EV1_slot2, EV2_slot2,...]'
temp_b2=Cap_battery_org - EV_info(1:num_EV,3);
for i=1:num_slot
    In_b2( (i-1)*num_EV+1:(i-1)*num_EV+num_EV, 1 )= (1/tau)*temp_b2;

''''''''''''

%  Draw each electric car ( Global optimal solution ) Electric energy level evolution diagram .
figure;
xxx=0:num_slot;
plot(xxx,v_Energy_variation(1:40,:));
ylabel(' electric energy [KWH]');
xlabel(' Hours ');
legend('EV1','EV2','EV3','EV4','EV5','EV6','EV7','EV8','EV9','EV10');
title(' The change of electric energy in the global optimal scheme ');

%  Draw the energy level evolution of each electric vehicle ( Local optimal scheme )
figure;
xxx=0:num_slot;
plot(xxx,Energy_variation);
ylabel(' electric energy [KWH]');
xlabel(' Hours ');
legend('EV1','EV2','EV3','EV4','EV5','EV6','EV7','EV8','EV9','EV10');
title(' The change of electric energy in the local optimal scheme ');

%  Draw each EV The evolution of energy levels ( Equal distribution scheme )
figure;
plot(xxx,N_Energy_variation);
ylabel(' electric energy [KWH]');
xlabel(' Hours ');
legend('EV1','EV2','EV3','EV4','EV5','EV6','EV7','EV8','EV9','EV10');
title(' The change of electric energy in the optimal scheme of equal distribution ');

% % Plot the charging rate of each EV 
figure;
EV_ID=65;
energy_mmm(1,:)=v_Energy_variation(EV_ID,:);
energy_mmm(2,:)=Energy_variation(EV_ID,:);
energy_mmm(3,:)=N_Energy_variation(EV_ID,:);
plot(xxx,energy_mmm);
ylabel(' electric energy  [KWH]');
xlabel(' Time (Hours)');
legend(' Global optimal solution ',' Local optimal scheme ',' Equal distribution scheme ');
title(' Changes in electric energy of electric vehicles ');

figure;
nnn(:,1)=v_x_Matrix(EV_ID,:)';% The best in the world 
nnn(:,2)=x_Matrix(EV_ID,:)';% Local optimum 
nnn(:,3)=N_x_Matrix(EV_ID,:)';% Equal distribution 
h=bar(xx,nnn);
ylabel(' rate [KW]');
xlabel(' Time (Hours)');
legend(' The best in the world ',' Local optimum ',' Equal distribution ');
title(' Charge discharge rate in the global optimal scheme ');

3.3 Running results




 

 

 

 

  Four 、 Looking back

Simulate the charging behavior of large-scale electric vehicles (Matlab Realization )

The influence of electric vehicle on system operation (Matlab Realization )

Large scale electric vehicle charging load forecasting based on Monte Carlo method (Python&Matlab Realization )

Route optimization with time window based on electric vehicle (Python&Matlab Code implementation )

(Matlab Realization ) Electric vehicle scheduling based on Monte Carlo and Lagrange multiplier method 【 Orderly 、 Disordered charge and discharge 】

copyright notice
author[Power system code],Please bring the original link to reprint, thank you.
https://caren.inotgo.com/2022/175/202206240409060830.html

Random recommended