### [TWVRP] solving the electric vehicle path planning problem with time window based on MATLAB saving algorithm [including Matlab source code 1169]

Ziji Shengguang q1564658423 2021-08-05 09:25:28 阅读数:265

twvrp solving electric vehicle path

## One 、 brief introduction

The basic idea

The line passes through this arc .

Iterative steps

## Two 、 Source code

`````` function [outcome1,outcome2,outcome3]=cw(Numberoffacilities,assignofpoint,ttimeu,timewindow,distMatrix,quantity,Qofcar,p1)
H=1;
outcome3=zeros(1,Numberoffacilities);% It corresponds to the pseudo number of the facility point one by one
%%%%%%% Find the actually allocated facility point , Because of the previous chrom In Chinese, it means 1 The point of , Probably %%%%%%%%%%%%%
facilitypop=zeros(1:Numberoffacilities);
facilitypop(assignofpoint)=1;
trueSelectefacilities=find(facilitypop(1,:)==1); % Selected facility number
trueselectNumberoffacilities=size(trueSelectefacilities,2);
outcome1=cell(1,trueselectNumberoffacilities);
outcome2=cell(1,trueselectNumberoffacilities);
for i=1:trueselectNumberoffacilities% The facilities at this time are i
a=trueSelectefacilities(i);% Pseudo number of the facility
pointofsubroute=find(assignofpoint==a);% Pseudo numbers of all demand points belonging to the facility
Numberofpointsofsubroute=size(pointofsubroute,2);% Number of demand points for the facility
judge=zeros(1,Numberofpointsofsubroute); % Judge the position of the demand point
chrom1=zeros(1,Numberofpointsofsubroute);% The last input is the pseudo number
chrom2=sort(pointofsubroute); % Pseudo numbers of demand points are sorted from small to large
originalchrom2=chrom2;
%% Assign a vehicle to the key node first ？？？？？？？？？？？？？？？？？？？？？ Isn't it ？
%for j=1:Numberofpointsofsubroute
%if timewindow(chrom2(j),2)==timewindow(chrom2(j),3)
%chrom1(j)=H;
%H=H+1;
%end
%end
%%%%%%%% Calculate the arrival time %%%%%%%%%%%%%%%%%%%%
arrivetime=zeros(1,Numberofpointsofsubroute);% Arrival time of demand point , With the current originalchrom2 The positions correspond one by one , One to one correspondence with the demand points assigned to the facility
for j=1:Numberofpointsofsubroute
if ttimeu(chrom2(j)+Numberoffacilities,a)<timewindow(chrom2(j),2)
arrivetime(j)=timewindow(chrom2(j),2);
else
arrivetime(j)=ttimeu(chrom2(j)+Numberoffacilities,a);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%% Path savings list %%%%%%%%%%%%%%%%%%%%%%
savingnumber=zeros(Numberofpointsofsubroute);% It corresponds to the pseudo number of the demand point assigned to the facility one by one
for j=1:Numberofpointsofsubroute
for z=1:Numberofpointsofsubroute
if j~=z
savingnumber(j,z)=distMatrix(chrom2(j)+Numberoffacilities,a)+distMatrix(chrom2(z)+Numberoffacilities,a)-distMatrix(chrom2(j)+Numberoffacilities,chrom2(z)+Numberoffacilities);
end
end
end
[a b]=max(savingnumber);%a The input values ,b The corresponding number in is a line , The corresponding number of columns is column
[c d]=max(a);%c Enter specific current savings ,d Is the number of columns
e=b(d);%e For the line
%%% In the savings list e That's ok d Column is the biggest savings at present
E=chrom2(e);% At this time E In order to save the most demand points, one of the pseudo numbers
D=chrom2(d);% At this time D In order to save the most demand points, the number of pseudo numbers 1
done=1;
while(done<2)
if judge(e)==0&&judge(d)==0
PD=0;
a=quantity(E,2)+quantity(D,2);
aa=quantity(E,3)+quantity(D,3);
pp1=normcdf(Qofcar,a,sqrt(aa));
a2=find(chrom2==D);
b2=find(chrom2==E);
if pp1>p1
EFj=arrivetime(e)+ttimeu(E+Numberoffacilities,D+Numberoffacilities)-arrivetime(d);
if EFj<0
PD=1;
end
elseif EFj==0
PD=1;
elseif EFj>0
delaytime=timewindow(D,3)-arrivetime(d);
if delaytime>=EFj
PD=1;
end
end
if PD==1
chrom1(e)=H;
chrom1(d)=H;%H Number the vehicle
judge(e)=1;% The starting point directly connected to the facility is 1
judge(d)=2;% The end point directly connected to the facility is 2
H=H+1;
arrivetime(d)=arrivetime(d)+EFj;
if b2>a2
chrom2(a2)=E;
chrom2(b2)=D;
end
end
end
savingnumber(e,d)=0;
elseif judge(e)==0&&judge(d)==1;
a2=find(chrom2==D);
b2=find(chrom2==E);
a=find(chrom1==chrom1(a2));
b=sum(quantity(chrom2(a),2))+quantity(E,2);
bb=sum(quantity(chrom2(a),3))+quantity(E,3);
pp1=normcdf(Qofcar,b,sqrt(bb));
c=size(a,2);
if pp1>p1
EFj=arrivetime(e)+ttimeu(E+Numberoffacilities,D+Numberoffacilities)-arrivetime(d);
if EFj<0
a1=10000;
for j=1:c
b1=find(originalchrom2==chrom2(a(j)));
end
end
PD=1;
end
elseif EFj==0
PD=1;
elseif EFj>0
a1=10000;
for j=1:c
b1=find(originalchrom2==chrom2(a(j)));
Delaytime=timewindow(chrom2(a(j)),3)-arrivetime(b1);
if Delaytime<a1
delaytime=Delaytime;
a1=Delaytime;
end
end
if delaytime>=EFj
PD=1;
end
end
if PD==1
chrom1(b2)=chrom1(a2);
a1=find(chrom1==chrom1(a2));
CHROM2=chrom2;
chrom2(a1(1))=CHROM2(b2);
k=2;
while(k<=c+1)
chrom2(a1(k))=CHROM2(a(k-1));
k=k+1;
end
judge(d)=10;%10 Is the inner point
judge(e)=1;
end
end
savingnumber(e,d)=0;
elseif judge(e)==0&&judge(d)==2
a2=find(chrom2==D);
b2=find(chrom2==E);
a=find(chrom1==chrom1(a2));
b=sum(quantity(chrom2(a),2))+quantity(E,2);
bb=sum(quantity(chrom2(a),3))+quantity(E,3);
pp1=normcdf(Qofcar,b,sqrt(bb));
c=size(a,2);
if pp1>p1
EFj=arrivetime(d)+ttimeu(E+Numberoffacilities,D+Numberoffacilities)-arrivetime(e);
if EFj<0
else
end
PD=1;
end
elseif EFj==0
PD=1;
elseif EFj>0
delaytimee=timewindow(E,3)-arrivetime(e);
delaytimed=timewindow(D,3)-arrivetime(d);
if delaytimee<delaytimed
delaytime=delaytimee;
else
delaytime=delaytimed;
end
if delaytime>=EFj
PD=1;
end
end
if PD==1
chrom1(b2)=chrom1(a2);
a1=find(chrom1==chrom1(a2));
CHROM2=chrom2;
k=1;
while(k<=c)
chrom2(a1(k))=CHROM2(a(k));
k=k+1;
end
chrom2(a1(k))=E;
judge(d)=10;
judge(e)=2;
end
end
savingnumber(e,d)=0;
elseif judge(e)==1&&judge(d)==0
a2=find(chrom2==D);
b2=find(chrom2==E);
a=find(chrom1==chrom1(b2));
b=sum(quantity(chrom2(a),2))+quantity(D,2);
bb=sum(quantity(chrom2(a),3))+quantity(D,3);
pp1=normcdf(Qofcar,b,sqrt(bb));
c=size(a,2);
if pp1>p1
EFj=arrivetime(e)+ttimeu(E+Numberoffacilities,D+Numberoffacilities)-arrivetime(d);
if EFj<0
a1=10000;
for j=1:c
b1=find(originalchrom2==chrom2(a(j)));
end
end
PD=1;
end
elseif EFj==0
PD=1;
elseif EFj>0
a1=10000;
for j=1:c
b1=find(originalchrom2==chrom2(a(j)));
Delaytime=timewindow(chrom2(a(j)),3)-arrivetime(b1);
if Delaytime<a1
delaytime=Delaytime;
a1=Delaytime;
end
end
```

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
```

edition ：2014a