?? routingmove.m
字號:
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 %如果不比最優(yōu)解優(yōu),轉(zhuǎn)回循環(huán)
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
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -