clc
clear
%% 电池装载时间卸载时间分析
CZ=ones(1,50);%初始电池组SOC
State_arrival=ones(1,50);%公交车的到站状态
First_departure=ones(1,50);%首次出发
w=1440*ones(1,50);%公交车的到站时间
Strat_time=[6:22].*60;%
Interval=[3,2,5,5,6,6,6,7,9,9,4,3,9,15,20,30,60];
Count=[20,30,12,10,10,10,10,8,6,6,15,20,6,4,3,2,1];
E=1.3;%每公里平均耗电量
R=38;%行驶路程
V=30;%速度
B=220;%电池组容量
M=0.5;%荷电状态最低阈值
Time=[];
% 生成电车出发时间矩阵Time
for i=1:size(Strat_time,2)
temp=Strat_time(i);
for j=1:Count(i)-1
if j*Interval(i)==60
break;
end
temp=[temp,Strat_time(i)+Interval(i)*j];
end
Time=[Time,temp];
end
J=[6*60:5:23*60];%运行时段的j时段划分
i=1;
D=zeros(1,size(J,2));%充电需求初始化
kkk=1;
t_off=zeros(1,70);
t_index=zeros(1,70);
t_index_on=zeros(1,70);
t_on=zeros(1,70);
State_B=ones(1,70);
SOC=ones(1,70);
P_max=0.2*B;%最大充电功率
for j=1:size(J,2)-1%对每个时间段进行换电需求计算
% for j=1:180%对每个时间段进行换电需求计算
%判断一下是否完成所有的发车
if i==174
break
end
%更新到站状态、电池的卸载/装载状态
index_bus=find(w<Time(i));
index_battery=intersect(find(t_off<Time(i)),find(t_off>0));
State_B(index_battery)=1;
State_arrival(index_bus)=1;
%计算在第j个时段的换电需求
while Time(i)<J(j+1)
% 对各车的状态进行检查,并轮换派出
while (State_arrival(kkk)~=1)||( CZ(kkk)<M)
kkk=kkk+1;
if kkk==51
kkk=kkk-50;
end
end
%检查车辆是否为首轮出发
if First_departure(kkk)==1
D(j)=D(j)+1;
Index_battery_load=Superiority(State_B,t_off,SOC,B,P_max);
i=i+1;
% 更新首发状态
First_departure(kkk)=0;
if i==174
break
end
% 更新荷电状态
CZ(kkk)=CZ(kkk)-R*E/B;
% 更新电车到达状态、到达时间
State_arrival(kkk)=0;
w(kkk)=Time(i)+(R/V)*60+10;
%对电池组的装载时间进行更新
t_on(Index_battery_load)=Time(i);
t_index_on(Index_battery_load)=length(find(Time(i)>J));
%对电池组的SOC进行更新,该SOC为电池组卸载时的SOC状态
SOC(Index_battery_load)=CZ(kkk)-2*R*E/B;
% 更新电池卸载状态
State_B(Index_battery_load)=0;
% 首轮卸载时间
temp_time=Time(i)+3*(R/V)*60+10;
t_off(Index_battery_load)=J(length(find(temp_time>J)));
t_index(Index_battery_load)=length(find(temp_time>J));
if temp_time>t_off(Index_battery_load)
detla_SOC=fix(((-t_off(Index_battery_load)+temp_time)/(60*R/V)))*(R*E/B);
detla_t_off=fix(((-t_off(Index_battery_load)+temp_time)/(60*R/V)))*((R/V)*60);
SOC(Index_battery_load)=SOC(Index_battery_load)+detla_SOC;
t_off(Index_battery_load)=t_off(Index_battery_load)-detla_t_off;
end
continue
end
%计算下一次运行后的电量
SOC_test_temp=CZ(kkk)-R*E/B;
if SOC_test_temp<M
D(j)=D(j)+1;
%t_off(Index_battery_load)=Time(i);
Index_battery_load=Superiority(State_B,t_off,SOC,B,P_max);
i=i+1;
if i==174
break
end
% 更新荷电状态
CZ(kkk)=1-R*E/B;
% 更新电车到达状态、到达时间
State_arrival(kkk)=0;
w(kkk)=Time(i)+(R/V)*60+10;
%对电池组的卸载时间进行更新
t_on(Index_battery_load)=Time(i);
t_index_on(Index_battery_load)=length(find(Time(i)>J));
%对电池组的SOC进行更新,该SOC为电池组卸载时的SOC状态
SOC(Index_battery_load)=CZ(kkk)-2*R*E/B;
% 更新电池卸载状态
State_B(Index_battery_load)=0;
% 首轮卸载时间
temp_time=Time(i)+3*(R/V)*60+10;
t_off(Index_battery_load)=J(length(find(temp_time>J)));
t_index(Index_battery_load)=length(find(temp_time>J));
if temp_time>t_off(Index_battery_load)
detla_SOC=fix(((-t_off(Index_battery_load)+temp_time)/(60*R/V)))*(R*E/B);
detla_t_off=fix(((-t_off(Index_battery_load)+temp_time)/(60*R/V)))*((R/V)*60);
SOC(Index_battery_load)=SOC(Index_battery_load)+detla_SOC;
t_off(Index_battery_load)=t_off(Index_battery_load)-detla_t_off;
end
continue
else
i=i+1;
if i==174
break
end
CZ(kkk)=CZ(kkk)-R*E/B;
State_arrival(kkk)=0;
w(kkk)=Time(i)+3*(R/V)*60+10;
end
kkk=kkk+1;
if kkk==51
kkk=kkk-50;
end
end
end
%% 传统充电方式结果,没有进行优化的结果
P=zeros(70,1440);
P_rand=zeros(1,70);
for i=1:70
P_rand(i)=normrnd(0.2,0.05);
end
for i=1:size(SOC,2)
% P_rand=normrnd(0.2,0.05);
temp=(t_off(i)+ceil(60*(1-SOC(i))/P_rand(i)));
if temp>1440
temp=temp-1440;
P(i,t_off(i):1440)=1;
P(i,1:temp)=1;
else
P(i,t_off(i):temp)=1;
end
end
P_final=sum(P).*(220*0.2);
P_final=mean(reshape(P_final,5,288))';
%% 混合整型规划对充电进行优化,以充电费用最低为标准
%生成可控充电时间段
t_index_on=t_index_on+6*12-1;
t_index=t_index+6*12-1;
P=zeros(70,288);
for i=1:70
P(i,1:t_index_on(i))=1;
P(i,t_index(i):288)=1;
end
t=P;
Pmax=0.2./12;
Pmin=0.1./12;
%电价数据
c=zeros(1,288);
c(10*12+1:15*12)=1.164;
c(18*12+1:21*12)=1.164;
c(1:7*12)=0.365;
c(23*12+1:24*12)=0.365;
c(7*12+1:10*12)=0.754;
c(15*12+1:18*12)=0.754;
c(21*12+1:23*12)=0.754;
C=repmat(c,70,1);
f=reshape((C.*t)',1,288*70);
F=[f,zeros(1,70*288)];
% 最大值限制
A01=sparse(eye(288*70));
A02=sparse(Pmax*eye(288*70));
B1=[A01,-A02];
b1=zeros(288*70,1);
% 最小值限制
A03=sparse(eye(288*70));
A04=sparse(Pmin*eye(288*70));
B2=[-A03,A04];
b2=zeros(288*70,1);
% 电量限制
A00=sparse(zeros(70,288*70));
A1=sparse(zeros(70,70*288));
for i=1:70
A1(i,(i-1)*288+1:i*288)=t(i,:);
end
B3=[-A1,A00];
b3=-(1-SOC)';
A=[B1;B2;B3];
b=[b1;b2;b3];
ic=[288*70+1:288*70*2];
Aeq=[];
Beq=[];
lb=[zeros(288*70,1);-0.1*ones(288*70,1)];
ub=[1000*ones(288*70,1);ones(288*70,1)];
[x,fval,exitflag]=intlinprog(F,ic,A,b,Aeq,Beq,lb,ub);
result=reshape(x(1:288*70),288,70);
% result=reshape(x(288*70+1:end),288,70);
final=sum(result');
P_result=final.*12.*220;
% plot(final);hold on
% plot(c)
%% 结果图
figure(1)
plot(P_final);hold on
plot(P_result);hold on
title('电车充电策略结果对比图(电车线路1的仿真)')
set(gca, 'XLim',[1 288]); % X轴的数据显示范围
set(gca, 'XTick',[48,96,144,192,240,288] ); % X轴的记号点
set(gca, 'XTicklabel',{'4','8','12','16','20','24'}); % X轴的记号
xlabel('时间/h')
ylabel('负荷功率/kW')
legend('不进行充换电优化的充电负荷','location','northwest','充换电优化的充电结果','location','northwest')
figure(2)
plot(c)
title('当日分时电价')
set(gca, 'XLim',[1 288]); % X轴的数据显示范围
set(gca, 'XTick',[48,96,144,192,240,288] ); % X轴的记号点
set(gca, 'XTicklabel',{'4','8','12','16','20','24'}); % X轴的记号
xlabel('时间/h')
ylabel('电价/元/kW.h')
cost1=c*P_final./12;
cost2=c*P_result'./12;
disp('不进行充换电优化的充电负荷的充电费用')
disp(cost1)
disp('充换电优化的充电结果')
disp(cost2)
disp('不进行充换电优化的充电负荷的充电费用')
- 1
- 2
前往页