这是一段MATLAB遗传算法代码,用于求解带时间窗的VRP问题的
有没有大神指教一下数组具体含义啊
clc;clf;clear all;
tic;
D=0;Q=0;T=0;dz=0;uz=0;sumz=inf;average=0;
m=input(‘请输入初始群数:’);
MAXGEN=input(‘最大遗传代数:’);
b=zeros(m,10);
z=zeros(1,21);
for i=1:m
b(i,:)=[randperm(10)+1];
end
b ;
sumd=zeros(m,1);u=ones(m,1);sumd2=zeros(m,1);u2=ones(m,1);o=zeros(m,10);oo=zeros(m,1);
load(‘d.mat’);
load(‘t.mat’);
q=[0,10,15,21,16,25,22,15,12,20,25];
s=[0,0.2,0.3,0.35,0.3,0.4,0.35,0.3,0.2,0.35,0.4];
ae=[0,0;0,5;0,0;0,5;0,0;0,3;1,0;0,5;1,0;1,4;0,0];
al=[inf,0;2,7;7,0;4,6;8,0;2,8;7,0;3,8;8,0;3,8;6,0];
A=zeros(m,21);
for i=1:m
a=ones(1,21);
for j=1:10
index1=a(j+u(i)-1);index2=b(i,j);
D=D+d(index1,index2)+d(index2,1);
Q=Q+q(index2);
if (D<=200) &&( Q<=90 )&&…
( ( ( ae(index2,1)<=T+t(index1,index2) )&&( (T+t(index1,index2)+s(index2))<=al(index2,1) ) )||(( ae(index2,2)<=T+t(index1,index2) )&&( (T+t(index1,index2)+s(index2))<=al(index2,2) ) ));
D=D-d(index2,1);sumd(i)=sumd(i)+d(index1,index2);
a(j+u(i))=b(i,j);T=T+t(index1,index2)+s(index2);
else D=0;Q=0;T=0;u(i)=u(i)+1;a(j+u(i))=b(i,j);sumd(i)=sumd(i)+d(a(j+u(i)-2),1)+d(1,b(i,j));D=d(1,b(i,j));Q=Q+q(b(i,j));T=T+t(1,b(i,j))+s(b(i,j));
end
end
D=0;Q=0;T=0;
sumd(i)=sumd(i)+d(b(i,j),1);
A(i,:)=a;
end
A;
gen=0;
objv=zeros(m,1);
trace=zeros(1,MAXGEN);
for i=1:m
objv(i)=50u(i)+20sumd(i);
end
objv;
while gen
sumd=zeros(m,1);u=ones(m,1);
objv1=2*max(objv)-objv;
for i=1:m
sum=sum+objv1(i);
end
fitv1=objv1/sum;
for i=1:m-1
for j=i+1:m
if fitv1(i)==fitv1(j)
fitv1(i)=fitv1(i)+fitv1(j);
fitv1(j)=0;
end
end
end
fitv1;
fitv=cumsum(fitv1);
r=rand(1,m);
o=b;oo=objv;
for i=1:m
j=1;
while fitv(j)
end
b(i,:)=o(j,:);objv1(i)=oo(j);
end
b ;
objv1;
for i=1:m
h1=h1+objv1(i);
end
h1;
average=h1/m;
temp1=zeros(10);
for i=1:m-1
for j=i+1:m
if b(i,:)==b(j,:)
temp1=b(i+1,:);
b(i+1,:)=b(j,:);
b(j,:)=temp1;
end
end
end
b;
c=zeros(m,10);o=zeros(m,10);
x1=0;m1=0;m2=0;
if rem(m,2)~=0
m1=fix(m/2);m2=round(m/2)+1;
c(m1+1,:)=b(m1+1,:);
else m1=m/2;m2=m/2+1;
end
n1=zeros(m1,1);n2=zeros(m1,1);
for i=1:m1
c1=randperm(8)+1;
if c1(1)
else n1(i)=c1(2);n2(i)=c1(1);
end
c(i,n1(i):n2(i))=b(m+1-i,n1(i):n2(i));
for j=1:(n1(i)-1)
x=find(c(i,:)==b(i,j));
if x~=0
while find(c(i,:)==b(i,x))~=0
x=find(c(i,:)==b(i,x));
end
c(i,j)=b(i,x);
else c(i,j)=b(i,j);
end
end
for j=n2(i)+1:10
x=find(c(i,:)==b(i,j));
if x~=0
while find(c(i,:)==b(i,x))~=0
x=find(c(i,:)==b(i,x));
end
c(i,j)=b(i,x);
else c(i,j)=b(i,j);
end
end
end
n1;
n2;
for i=mm2
x1=m+1-i;
c(i,n1(x1):n2(x1))=b(x1,n1(x1):n2(x1));
for j=1:(n1(x1)-1)
x=find(c(i,:)==b(i,j));
if x~=0
while find(c(i,:)==b(i,x))~=0
x=find(c(i,:)==b(i,x));
end
c(i,j)=b(i,x);
else c(i,j)=b(i,j);
end
end
for j=n2(x1)+1:10
x=find(c(i,:)==b(i,j));
if x~=0
while find(c(i,:)==b(i,x))~=0
x=find(c(i,:)==b(i,x));
end
c(i,j)=b(i,x);
else c(i,j)=b(i,j);
end
end
end
c ;
o=c;
A=zeros(m,21);sumd=zeros(m,1);u=ones(m,1);
for i=1:m
a=ones(1,21);
for j=1:10
index1=a(j+u(i)-1);index2=c(i,j);
D=D+d(index1,index2)+d(index2,1);
Q=Q+q(index2);
if (D<=200) &&( Q<=90 )&&…
( ( ( ae(index2,1)<=T+t(index1,index2) )&&( (T+t(index1,index2)+s(index2))<=al(index2,1) ) )||(( ae(index2,2)<=T+t(index1,index2) )&&( (T+t(index1,index2)+s(index2))<=al(index2,2) ) ));
D=D-d(index2,1);sumd(i)=sumd(i)+d(index1,index2);
a(j+u(i))=c(i,j);T=T+t(index1,index2)+s(index2);
else D=0;Q=0;T=0;u(i)=u(i)+1;a(j+u(i))=c(i,j);sumd(i)=sumd(i)+d(a(j+u(i)-2),1)+d(1,c(i,j));D=d(1,c(i,j));Q=Q+q(c(i,j));T=T+t(1,c(i,j))+s(c(i,j));
end
end
D=0;Q=0;T=0;
sumd(i)=sumd(i)+d(c(i,j),1);
A(i,:)=a;
end
A;
sumd2=sumd;
u2=u;
objv2=zeros(m,1);
for i=1:m
objv2(i)=50u(i)+20sumd(i);
end
objv2 ;
for i=1:m
h2=h2+objv2(i);
end
h2;
if h2>h1
for i=1:m
n1=1;i1=0;temp=0;
while (objv2(i)>average)&&(n1<=10)
temp=objv2(i)-average;
c(i,:)=o(i,:);
c5(1,:)=randperm(10)+1;
c6=c5(1,1:2);
v1=find(c(i,:)==c6(1,1));
v2=find(c(i,:)c6(1,2));
c(i,v1)=c6(1,2);
c(i,v2)=c6(1,1);
a=ones(1,21);sumd(i)=0;u(i)=1;
D=0;Q=0;T=0;
for j=1:10
index1=a(j+u(i)-1);index2=c(i,j);
D=D+d(index1,index2)+d(index2,1);
Q=Q+q(index2);
if (D<=200) &&( Q<=90 )&&…
( ( ( ae(index2,1)<=T+t(index1,index2) )&&( (T+t(index1,index2)+s(index2))<=al(index2,1) ) )||(( ae(index2,2)<=T+t(index1,index2) )&&( (T+t(index1,index2)+s(index2))<=al(index2,2) ) ));
D=D-d(index2,1);sumd(i)=sumd(i)+d(index1,index2);
a(j+u(i))=c(i,j);T=T+t(index1,index2)+s(index2);
else D=0;Q=0;T=0;u(i)=u(i)+1;a(j+u(i))=c(i,j);sumd(i)=sumd(i)+d(a(j+u(i)-2),1)+d(1,c(i,j));D=d(1,c(i,j));Q=Q+q(c(i,j));T=T+t(1,c(i,j))+s(c(i,j));
end
end
sumd(i)=sumd(i)+d(c(i,j),1);
objv2(i)=50u(i)+20sumd(i);
A(i,:)=a;
n1=n1+1;
end
if n111&&(objv2(i)>average)
[sum,i1]=min(objv2);
A(i,:)=A(i1,:);
c(i,:)=c(i1,:);
objv2(i)=sum;
sumd(i)=sumd2(i1);
u(i)=u2(i1);
end
h2=h2-temp-(average-objv2(i));
if h2
end
plot(1:gen,trace(1,:),‘b-’);
hold on, grid;
xlabel(‘进化代数’);
ylabel(‘最优解变化’);
title(‘SGA进化过程’);
z(1,1:10+uz+1)
dz
uz
sumz
toc