swap_routing.m

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

M
25
字号
function [x1,changex,l1]=swap_routing(x0,l0)

global customer;
global depot;
global demand; 
NumberRoute=length(l0);  
a=ceil(NumberRoute*rand);
b=ceil(NumberRoute*rand);
while a==b
a=ceil(NumberRoute*rand);
b=ceil(NumberRoute*rand);
end
c1_index=ceil(l0(a)*rand);
c1=x0(a,c1_index+1);
for j=1:l0(b)
    alldis(j)=distance(demand,c1,x0(b,j+1));
end
[dis,c2_index]=min(alldis);
c2=x0(b,c2_index+1);

x0(a,c1_index+1)=c2;
x0(b,c2_index+1)=c1;
x1=x0;
l1=l0;
changex=[4 c1 c2];

⌨️ 快捷键说明

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