functionf=myfun(x)
矩阵定义省略
forj=1:28
a=0;
fori=1;27;
a=a+x(i)*A(i,j)*T(i);
end
JT1(j)=a;
end
forj=1:28
a=0;
fori=1;27;
a=a+x(2*i)*A(i,j)*T(i);
end
JT2(j)=a;
end
forj=1:28
a=0;
fori=1;27;
a=a+x(i*3)*A(i,j)*T(i);
end
JT3(j)=a;
end
N=[0,0];
fori=1:27
forj=1:28
ifx(2*i)==1&&A(i,j)==1;
N(k)=j;k=k+1;
end
end
end
a=N(1);b=N(2);
ifJT1(a)-JT1(b)>0;%这步就是错的
WT1(a)=JT1(a)-JT1(b);
elseWT1(b)=JT1(b)-JT1(a);
end
k=1;
fori=1:27
forj=1:28
ifx(3*i)==1&&A(i,j)==1;
N(k)=j;k=k+1;
end
end
end
a=N(1);b=N(2);
ifJT2(a)+WT1(a)>JT2(b)+WT1(b)
WT2(a)=JT2(a)+WT1(a)-JT2(b)+WT1(b);
elseWT2(b)=JT2(b)+WT1(b)-JT2(a)+WT1(a);
end
m=0;
forj=1:28
ifJT1(m)+JT2(m)+JT3(m)+WT1(m)+WT2(m)