⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swap_location.asv

📁 TSP问题,即旅行商问题,matlab环境下可以运行
💻 ASV
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -