📄 binbin_ant.m
字号:
function binbin_ant(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN,Q);
% 设置用代号为FUN_num的函数来计算myNC_max次,并将结果输出到文件
% [R_best,L_best,L_ave,Shortest_Route,Shortest_Length]=
% FUN_num = 2;myNC_max = 20;TSPfile='Oliver30.tsp';m=30;Alpha=1;Beta=2;Rho=0.98;NC_max=300;WIN = 3;Q=100;
% FUN_num表示使用的蚂蚁算法1为MMAS 2为MMAS_WIN_2opt... eil51
% myNC_max 表示调用该算法的次数
% FUN_num = 22;myNC_max = 1;TSPfile='eil51.tsp';m=51;Alpha=1;Beta=2;Rho=0.98;NC_max=600;WIN = 10;Q=100;
switch FUN_num
case 1
binbin_ant_MMAS(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho);
case 2
binbin_ant_MMAS_win_2opt(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
case 3
binbin_ant_MMAS_win_2opt_mid(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
case 4
binbin_ant_MMAS_win_2opt_cand(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
case 5
binbin_ant_MMAS_win_2opt_gather(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
case 6
binbin_ant_MMAS_win_2opt_search(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
case 7
binbin_ant_MMAS_win_accept(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
case 8
binbin_ant_MMAS_win_2opt_accept(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
case 9
binbin_ant_MMAS_nowin_2opt_accept(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
case 10
binbin_ant_MMAS_dywin_2opt_accept(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
case 11
binbin_ant_MMAS_dywin_2opt_accept_noinit(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
case 12
binbin_ant_MMAS_newwin_2opt_accept(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
case 13
binbin_ant_MMAS_newwin_2opt(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
case 14
binbin_ant_MMAS_newdywin_2opt_accept(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
case 15
binbin_ant_MMAS_win_2opt_accept_1(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
case 16
binbin_ant_MMAS_newwin_2opt_accept_1(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
case 17
binbin_ant_MMAS_newnewwin_2opt_accept_1(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
%MMAS+2-opt+accept窗口
case 18
binbin_ant_MMAS_2opt_1(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
%MMAS+2-opt采用sumTauBate策略
case 19
binbin_ant_BB_AS(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
case 20%动态画图
binbin_ant_BB_AS_1(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
case 21 %动态画图
binbin_ant_MMAS_2opt_ani(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
case 22 %动态画图mov
binbin_ant_BB_AS_mov(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
case 23 %动态画图mov
binbin_ant_MMAS_2opt_mov(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
end
%%
function binbin_ant_MMAS(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho);
myNC = 1;
while myNC <= myNC_max
[L_ave_best,L_ave_ave,R_best,L_best,L_ave,Shortest_Route,Shortest_Length,First] = MMAS(TSPfile,NC_max,m,Alpha,Beta,Rho);
output_sta = strcat('MMAS_sta_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
output_rout = strcat('MMAS_rout_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
saveas(gcf, output_sta , 'fig');
saveas(gcf, output_sta , 'jpg');
close gcf;
saveas(gcf, output_rout , 'fig');
saveas(gcf, output_rout , 'jpg');
close gcf;
output_tour(FUN_num,myNC,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN,Shortest_Length,Shortest_Route,First,L_ave_best,L_ave_ave);
myNC
myNC = myNC + 1;
end
%%
function binbin_ant_MMAS_win_2opt(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
myNC = 1;
while myNC <= myNC_max
[L_ave_best,L_ave_ave,R_best,L_best,L_ave,Shortest_Route,Shortest_Length,First] = MMAS_win_2opt(TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
output_sta = strcat('MMAS_win_2opt_sta_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
output_rout = strcat('MMAS_win_2opt_rout_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
saveas(gcf, output_sta , 'fig');
saveas(gcf, output_sta , 'jpg');
close gcf;
saveas(gcf, output_rout , 'fig');
saveas(gcf, output_rout , 'jpg');
close gcf;
output_tour(FUN_num,myNC,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN,Shortest_Length,Shortest_Route,First,L_ave_best,L_ave_ave);
myNC
myNC = myNC + 1;
end
%%
function binbin_ant_MMAS_win_2opt_mid(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
myNC = 1;
while myNC <= myNC_max
[L_ave_best,L_ave_ave,R_best,L_best,L_ave,Shortest_Route,Shortest_Length,First] = MMAS_win_2opt_mid(TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
output_sta = strcat('MMAS_win_2opt_mid_sta_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
output_rout = strcat('MMAS_win_2opt_mid_rout_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
saveas(gcf, output_sta , 'fig');
saveas(gcf, output_sta , 'jpg');
close gcf;
saveas(gcf, output_rout , 'fig');
saveas(gcf, output_rout , 'jpg');
close gcf;
output_tour(FUN_num,myNC,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN,Shortest_Length,Shortest_Route,First,L_ave_best,L_ave_ave);
myNC
myNC = myNC + 1;
end
%%
function binbin_ant_MMAS_win_2opt_cand(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
myNC = 1;
while myNC <= myNC_max
[L_ave_best,L_ave_ave,R_best,L_best,L_ave,Shortest_Route,Shortest_Length,First] = MMAS_win_2opt_cand(TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
output_sta = strcat('MMAS_win_2opt_cand_sta_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
output_rout = strcat('MMAS_win_2opt_cand_rout_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
saveas(gcf, output_sta , 'fig');
saveas(gcf, output_sta , 'jpg');
close gcf;
saveas(gcf, output_rout , 'fig');
saveas(gcf, output_rout , 'jpg');
close gcf;
output_tour(FUN_num,myNC,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN,Shortest_Length,Shortest_Route,First,L_ave_best,L_ave_ave);
myNC
myNC = myNC + 1;
end
%%
function binbin_ant_MMAS_win_2opt_gather(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
myNC = 1;
while myNC <= myNC_max
[L_ave_best,L_ave_ave,R_best,L_best,L_ave,Shortest_Route,Shortest_Length,First] = MMAS_win_2opt_gather(TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
output_sta = strcat('MMAS_win_2opt_gather_sta_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
output_rout = strcat('MMAS_win_2opt_gather_rout_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
saveas(gcf, output_sta , 'fig');
saveas(gcf, output_sta , 'jpg');
close gcf;
saveas(gcf, output_rout , 'fig');
saveas(gcf, output_rout , 'jpg');
close gcf;
output_tour(FUN_num,myNC,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN,Shortest_Length,Shortest_Route,First,L_ave_best,L_ave_ave);
myNC
myNC = myNC + 1;
end
%%
function binbin_ant_MMAS_win_2opt_search(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
myNC = 1;
while myNC <= myNC_max
[L_ave_best,L_ave_ave,R_best,L_best,L_ave,Shortest_Route,Shortest_Length,First] = MMAS_win_2opt_search(TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
output_sta = strcat('MMAS_win_2opt_search_sta_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
output_rout = strcat('MMAS_win_2opt_search_rout_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
saveas(gcf, output_sta , 'fig');
saveas(gcf, output_sta , 'jpg');
close gcf;
saveas(gcf, output_rout , 'fig');
saveas(gcf, output_rout , 'jpg');
close gcf;
output_tour(FUN_num,myNC,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN,Shortest_Length,Shortest_Route,First,L_ave_best,L_ave_ave);
myNC
myNC = myNC + 1;
end
%%
function binbin_ant_MMAS_win_accept(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
myNC = 1;
while myNC <= myNC_max
[L_ave_best,L_ave_ave,R_best,L_best,L_ave,Shortest_Route,Shortest_Length,First] = MMAS_win_accept(TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
output_sta = strcat('MMAS_win_accept_sta_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
output_rout = strcat('MMAS_win_accept_rout_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
saveas(gcf, output_sta , 'fig');
saveas(gcf, output_sta , 'jpg');
close gcf;
saveas(gcf, output_rout , 'fig');
saveas(gcf, output_rout , 'jpg');
close gcf;
output_tour(FUN_num,myNC,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN,Shortest_Length,Shortest_Route,First,L_ave_best,L_ave_ave);
myNC
myNC = myNC + 1;
end
%%
function binbin_ant_MMAS_win_2opt_accept(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
myNC = 1;
while myNC <= myNC_max
[L_ave_best,L_ave_ave,R_best,L_best,L_ave,Shortest_Route,Shortest_Length,First] = MMAS_win_2opt_accept(TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
output_sta = strcat('MMAS_win_2opt_accept_sta_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
output_rout = strcat('MMAS_win_2opt_accept_rout_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
saveas(gcf, output_sta , 'fig');
saveas(gcf, output_sta , 'jpg');
close gcf;
saveas(gcf, output_rout , 'fig');
saveas(gcf, output_rout , 'jpg');
close gcf;
output_tour(FUN_num,myNC,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN,Shortest_Length,Shortest_Route,First,L_ave_best,L_ave_ave);
myNC
myNC = myNC + 1;
end
%%
function binbin_ant_MMAS_nowin_2opt_accept(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
myNC = 1;
while myNC <= myNC_max
[L_ave_best,L_ave_ave,R_best,L_best,L_ave,Shortest_Route,Shortest_Length,First] = MMAS_nowin_2opt_accept(TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
output_sta = strcat('MMAS_nowin_2opt_accept_sta_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
output_rout = strcat('MMAS_nowin_2opt_accept_rout_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
saveas(gcf, output_sta , 'fig');
saveas(gcf, output_sta , 'jpg');
close gcf;
saveas(gcf, output_rout , 'fig');
saveas(gcf, output_rout , 'jpg');
close gcf;
output_tour(FUN_num,myNC,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN,Shortest_Length,Shortest_Route,First,L_ave_best,L_ave_ave);
myNC
myNC = myNC + 1;
end
%%
function binbin_ant_MMAS_dywin_2opt_accept(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
myNC = 1;
while myNC <= myNC_max
[L_ave_best,L_ave_ave,R_best,L_best,L_ave,Shortest_Route,Shortest_Length,First] = MMAS_dywin_2opt_accept(TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
output_sta = strcat('MMAS_dywin_2opt_accept_sta_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
output_rout = strcat('MMAS_dywin_2opt_accept_rout_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
saveas(gcf, output_sta , 'fig');
saveas(gcf, output_sta , 'jpg');
close gcf;
saveas(gcf, output_rout , 'fig');
saveas(gcf, output_rout , 'jpg');
close gcf;
output_tour(FUN_num,myNC,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN,Shortest_Length,Shortest_Route,First,L_ave_best,L_ave_ave);
myNC
myNC = myNC + 1;
end
%%
function binbin_ant_MMAS_dywin_2opt_accept_noinit(FUN_num,myNC_max,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
myNC = 1;
while myNC <= myNC_max
[L_ave_best,L_ave_ave,R_best,L_best,L_ave,Shortest_Route,Shortest_Length,First] = MMAS_dywin_2opt_accept_noinit(TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
output_sta = strcat('MMAS_dywin_2opt_accept_noinit_sta_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -