tabu_routingmove.m

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

M
69
字号
 function [x1,changex,l1,tabu]=tabu_routingmove(x0,l0,tabu)

 
 
 
global bestx;
global bestl;
global bestSC;
 global best_iter;        
           nu1=rand;
if nu1>0.5
[x1,changex,l1]=insert(x0,l0); 
%elseif nu1>0.4
   % [x1,changex,l1]=swap_routing(x0,l0); 
else
     [x1,changex,l1]=swap_routing(x0,l0); 
end
   

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

⌨️ 快捷键说明

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