swap_location.asv

来自「TSP问题,即旅行商问题,matlab环境下可以运行」· ASV 代码 · 共 60 行

ASV
60
字号
function [x1,changex,l1]=swap_location(x0,l0)
global customer;
global depot;
global demand;



x0 =[ 1     6     0     0
     1     8     5    10
     1     3     0     0
     1     9     2     0
     1     4     0     0
     1     7     0     0
     1     1     0     0];
 l0=[1 3 1 2 1 1 1];
 
demand=[142 85 385
       163 175 430
        87 96 540
        63 57 324
        204 217 238
        130 165 296
        180 210 340
        93 114 286
        170 163 392
        78 103 310
        50 148 0
        34 82 0
        185 198 0]; 
 
 
 NumberRoute=length(l0);  
a=ceil(NumberRoute*rand);
b=0;
for j=1:NumberRoute
if x0(a,1)~=x0(j,1)
   b=j;
   break;
end
end

if b==0
      for j=1:depot
          if j==x0(a,1)
              alldis(j)=100000;
          else
            alldis(j)=distance(demand,x0(a,1)+customer,j+customer);
        end
      end
      [dis,n]=min(alldis);
       x0(a,1)=n;
else
 temp=x0(a,1);
x0(a,1)=x0(b,1);
x0(b,1)=temp;
l1=l0;
x1=x0;
changex=[2 a b];
end
x1

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?