建立电动汽车概率出行模型,该模型考虑了路网、排队时间等,以投资成本和时间成本最优为目标,优化电动汽车的建设位置,采用基因遗传算法求解。内附参考文献
1、部分代码
clear ; clc; global data; global CodeL; load data; B = Road_Net_Drawing(); Size=100; CodeL=9*3; for i=1:CodeL/3 MinX((i-1)*3+1)=0; MaxX((i-1)*3+1)=25; MinX((i-1)*3+2)=0; MaxX((i-1)*3+2)=25; MinX((i-1)*3+3)=5; MaxX((i-1)*3+3)=15; end for i=1:CodeL E(:,i)=MinX(i)+(MaxX(i)-MinX(i))*rand(Size,1); end G=100; BsJ=0; ag=0; dg1=0; ah1=0; ah2=0; dh1=0; dh2=0; for kg=1:1:G time(kg)=kg; %****** Step 1 : 寻找最佳染色体 ****** for i=1:1:Size xi=E(i,:); [C_T,C_c]=finess(xi); F(i)=10000000000-(C_T+C_c); Ji=1./F; BsJi(i)=min(Ji); end [OderJi,IndexJi]=sort(BsJi); BestJ(kg)=OderJi(1); BJ=BestJ(kg); Ji=BsJi+1e-10; fi=F; [Oderfi,Indexfi]=sort(fi); %对染色体按照适应度值进行排序 Bestfi=Oderfi(Size); BestS=E(Indexfi(Size),:); bfi(kg)=10000000000-Bestfi; kg BestS %****** Step 2 : 选择****** fi_sum=sum(fi); fi_Size=(Oderfi/fi_sum)*Size; fi_S=floor(fi_Size); r=Size-sum(fi_S); Rest=fi_Size-fi_S; [RestValue,Index]=sort(Rest); for i=Size:-1:Size-r+1 fi_S(Index(i))=fi_S(Index(i))+1; end k=1; for i=Size:-1:1 for j=1:1:fi_S(i) TempE(k,:)=E(Indexfi(i),:); k=k+1; end end %************ Step 3 : 交叉 ************ Pc=0.90; for i=1:2:(Size-1) temp=rand; if Pc>temp alfa=rand; TempE(i,:)=alfa*E(i+1,:)+(1-alfa)*E(i,:); TempE(i+1,:)=alfa*E(i,:)+(1-alfa)*E(i+1,:); end end TempE(Size,:)=BestS; E=TempE; %************ Step 4:变异 ************** Pm=0.10-[1:1:Size]*(0.01)/Size; Pm_rand=rand(Size,CodeL); Mean=(MaxX + MinX)/2; Dif=(MaxX-MinX); for i=1:1:Size for j=1:1:CodeL if Pm(i)>Pm_rand(i,j) TempE(i,j)=Mean(j)+Dif(j)*(rand-0.5); end end end TempE(Size,:)=BestS; E=TempE; end for i=1:CodeL/3 positions(i,1)=BestS(((i-1)*3+1)); positions(i,2)=BestS((i-1)*3+2); q(i)=round(BestS((i-1)*3+3)); end hold on scatter(positions(:,1),positions(:,2),'*r') % positions(9,1)=4.12; % positions(9,2)=4.21; % % positions(5,1)=1.67; % positions(5,2)=3.51; figure(2); plot(time,bfi,'b'); xlabel('迭代次数');ylabel('目标函数'); dWqk=135./q; C_allnum=[4,2150; 5 2060; 6 2050; 7 2150; 8 2060; 9 1980; 10 2050;11 2180;12 2260 ]; for i=1:9 C_allnum(i,2) = C_allnum(i,2)*3110/1980; end figure(3); plot(C_allnum(:,1),C_allnum(:,2),'-ob'); xlabel('充电站数目');ylabel('总成本(万元)'); [C_c,C_v,T1,T2,T3]=verify(BestS); c1=14.32*365*(T1)/60; %寻找充电站的耗时本 c2=14.32*365*(T2)/60; %排队等待成本成本 c3=14.32*365*(T3)/60; %寻找乘客的成本
2、结果展示
标签:基于,end,TempE,positions,电动汽车,fi,BestS,遗传算法,Size From: https://www.cnblogs.com/lovematlab/p/16893000.html