routingmove.m

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

M
110
字号
routingmove
function [x1,changex,l1,tabu]=sa_routingmove(x0,l0,tabu)
 nu1=rand;
if nu1>0.7
[x1,changex,l1]=insert(x0,l0);'inser'
elseif nu1>0.4
    [x1,changex,l1]=swap_routing(x0,l0);'swap_routing'
else
     [x1,changex,l1]=newroute(x0,l0);'newroute'
end
     % 满足容量需求
      while  condition(x1,changex,l1)==0  %不满足条件
          'sar1'
           nu1=rand;
if nu1>0.7
[x1,changex,l1]=insert(x0,l0);'inser'
elseif nu1>0.4
    [x1,changex,l1]=swap_routing(x0,l0);'swap_routing'
else
     [x1,changex,l1]=newroute(x0,l0);'newroute'
end
          end 
      
          while findintabu(changex,tabu)==1 %在tabu中
            'sar1'
            nu1=rand;
if nu1>0.7
[x1,changex,l1]=insert(x0,l0);'inser'
elseif nu1>0.4
    [x1,changex,l1]=swap_routing(x0,l0);'swap_routing'
else
     [x1,changex,l1]=newroute(x0,l0);'newroute'
end
               while  condition(x1,changex,l1)==0  %不满足条件
                   'sar3'
             nu1=rand;
if nu1>0.7
[x1,changex,l1]=insert(x0,l0);'inser'
elseif nu1>0.4
    [x1,changex,l1]=swap_routing(x0,l0);'swap_routing'
else
     [x1,changex,l1]=newroute(x0,l0);'newroute'
end
          end 
            end
           
        function [x1,changex,l1,tabu]=tabu_routingmove(x0,l0,tabu)

global bestx;
global bestl;
global bestSC;
         
           nu1=rand;
if nu1>0.7
[x1,changex,l1]=insert(x0,l0);'inser'
elseif nu1>0.4
    [x1,changex,l1]=swap_routing(x0,l0);'swap_routing'
else
     [x1,changex,l1]=newroute(x0,l0);'newroute'
end
   

% 满足容量需求
      while  condition(x1,changex,l1)==0  %不满足条件
         
                 'tbr1'       
          nu1=rand;
if nu1>0.7
[x1,changex,l1]=insert(x0,l0);'inser'
elseif nu1>0.4
    [x1,changex,l1]=swap_routing(x0,l0);'swap_routing'
else
     [x1,changex,l1]=newroute(x0,l0);'newroute'
end
      end
      
      while findintabu(changex,tabu)==1 %在tabu中
               SCx1=SC(x1,l1);
             if SCx1<=bestSC
                  bestx=x1;
                  bestl=l1;
                  bestSC=SCx1;
                  tabu=updatetaburouting(changex,tabu);
                  break;%解禁
              else %如果不比最优解优,转回循环
                    nu1=rand;
if nu1>0.7
[x1,changex,l1]=insert(x0,l0);'inser'
elseif nu1>0.4
    [x1,changex,l1]=swap_routing(x0,l0);'swap_routing'
else
     [x1,changex,l1]=newroute(x0,l0);'newroute'
end
                     % 满足容量需求
                    while  condition(x1,changex,l1)==0  %不满足条件
                        'tbr2'
                         nu1=rand;
if nu1>0.7
[x1,changex,l1]=insert(x0,l0);'inser'
elseif nu1>0.4
    [x1,changex,l1]=swap_routing(x0,l0);'swap_routing'
else
     [x1,changex,l1]=newroute(x0,l0);'newroute'
end
                       end
              end%与if相对
            
       end
       
 

⌨️ 快捷键说明

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