⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 binbin_ant.m

📁 改进的蚁群算法matlab程序
💻 M
📖 第 1 页 / 共 2 页
字号:
    output_rout = strcat('MMAS_dywin_2opt_accept_noinit_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_newwin_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_newwin_2opt_accept(TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
    output_sta = strcat('MMAS_newwin_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_newwin_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_newwin_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_newwin_2opt(TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
    output_sta = strcat('MMAS_newwin_2opt_sta_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
    output_rout = strcat('MMAS_newwin_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_accept_1(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_1(TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
    output_sta = strcat('MMAS_win_2opt_accept_1_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_1_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_newwin_2opt_accept_1(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_newwin_2opt_accept_1(TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
    output_sta = strcat('MMAS_newwin_2opt_accept_1_sta_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
    output_rout = strcat('MMAS_newwin_2opt_accept_1_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_newnewwin_2opt_accept_1(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_newnewwin_2opt_accept_1(TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
    output_sta = strcat('MMAS_newnewwin_2opt_accept_1_sta_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
    output_rout = strcat('MMAS_newnewwin_2opt_accept_1_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_2opt_1(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_2opt_1(TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
    output_sta = strcat('MMAS_2opt_1_sta_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
    output_rout = strcat('MMAS_2opt_1_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_BB_AS(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] = BB_AS(TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
    output_sta = strcat('BB_AS_sta_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
    output_rout = strcat('BB_AS_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_BB_AS_1(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] = BB_AS_1(TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
    output_sta = strcat('BB_AS_1_sta_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
    output_rout = strcat('BB_AS_1_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_2opt_ani(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_2opt_ani(TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
    output_sta = strcat('MMAS_2opt_ani_sta_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
    output_rout = strcat('MMAS_2opt_ani_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_BB_AS_mov(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] = BB_AS_mov(TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
    output_sta = strcat('BB_AS_mov_sta_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
    output_rout = strcat('BB_AS_mov_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_2opt_mov(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_2opt_mov(TSPfile,NC_max,m,Alpha,Beta,Rho,WIN);
    output_sta = strcat('MMAS_2opt_mov_sta_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'_',num2str(First),'_',num2str(floor(L_ave_best)),'_',num2str(floor(L_ave_ave)));
    output_rout = strcat('MMAS_2opt_mov_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 output_tour(FUN_num,myNC,TSPfile,NC_max,m,Alpha,Beta,Rho,WIN,Shortest_Length,Shortest_Route,First,L_ave_best,L_ave_ave);

Name = TSPfile;

switch FUN_num 
case 1 
    funname = 'MMAS';
case 2 
    funname = 'MMAS_win_2opt';
case 3 
   funname = 'MMAS_win_2opt_mid';
case 4 
   funname = 'MMAS_win_2opt_cand';
case 5 
   funname = 'MMAS_win_2opt_gather';
case 6 
   funname = 'MMAS_win_2opt_search';
case 7 
   funname = 'MMAS_win_accept';
case 8
   funname = 'MMAS_win_2opt_accept';
case 9
   funname = 'MMAS_nowin_2opt_accept';
case 10
   funname = 'MMAS_dywin_2opt_accep';
case 11
   funname = 'MMAS_dywin_2opt_accept_noinit';
case 12
   funname = 'MMAS_newwin_2opt_accept';
case 13
   funname = 'MMAS_newwin_2opt';
case 14
   funname = 'MMAS_newdywin_2opt_accept'; 
case 15
   funname = 'MMAS_win_2opt_accept_1';
case 16
   funname = 'MMAS_newwin_2opt_accept_1';
case 17
   funname = 'MMAS_newnewwin_2opt_accept_1';
case 18
   funname = 'MMAS_2opt_1';
case 19
   funname = 'BB_AS';   
case 20
   funname = 'BB_AS_1';
case 21
   funname = 'MMAS_2opt_ani';
case 22
   funname = 'BB_AS_mov';
case 23
   funname = 'MMAS_2opt_mov';
end 


output = strcat(funname,'_',num2str(myNC),'_',num2str(floor(Shortest_Length)),'.opt.tour');


fid = fopen(output,'ab');
fprintf(fid, 'm : %d Alpha : %2.1f Beta : %2.1f Rho : %2.2f WIN : %d NC_max : %d \n',m,Alpha,Beta,Rho,WIN,NC_max);
fprintf(fid, 'myNC : %d Shortest_Length : %4.4f First : %3d L_ave_best : %4.4f L_ave_ave : %4.4f\n',myNC,Shortest_Length,First,L_ave_best,L_ave_ave);
fprintf(fid, 'NAME : %s.opt.tour.frer\n', Name);
fprintf(fid, 'TYPE : TOUR\n');
fprintf(fid, 'COMMENT : frer''s Optimal tour for %s (%6.4f)\n', Name,Shortest_Length);
% fprintf(fid, 'DIMENSION : %d\n',Dimension);
fprintf(fid, 'TOUR_SECTION\n');

fprintf(fid, '%d\n', Shortest_Route);
fprintf(fid, '%d\n',-1);
fprintf(fid, 'EOF\n');
fclose(fid)

⌨️ 快捷键说明

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