testalgorithms.m

来自「硕士论文三个点中的一个」· M 代码 · 共 43 行

M
43
字号
% 多种算法
% x种选择
%   1) 自己的算法  mymopso
%   2) 其他的     othermopso
%   ...
n = 30;
runCounts = 20;
generations = 300;
fname1 = strcat('zdt2_mymopso.', num2str(generations)); % 自己的算法
fid1 = fopen(fname1,'w');
% fname2 = strcat('zdt2_othermopso.',num2str(generations)); % 其他人的算法,待改
% fid2 = fopen(fname2,'w');

realGens = [0, 0]' ;
for (i= 1 :runCounts) 
    outf =[];
    realGen =0;
    [pop realGen]= ZDT2_mymopso;
    realGens(1, 1) = realGen + realGens(1, 1);
    outf = pop(:, n+1:n+2);% zdt6特有的,n=10,函数值在11,12列
    if (i ~= 1) % another run's population
        fprintf(fid1,'\n');    
    end
    fprintf(fid1,'%.9e  %.9e\n',outf');
  
% % %     outf =[];
% % %     realGen =0;
% % %     [pop realGen] = ZDT6_othermopso;
% % %     realGens(2, 1) = realGen + realGens(2, 1)
% % %     outf = pop(:, 11:12);
% % %     if (i ~= 1) % another run's population
% % %         fprintf(fid2,'\n');    
% % %     end
% % %     fprintf(fid2,'%f  %f\n',outf');
end 
fclose(fid1);
% fclose(fid2);

aveRealGens = realGens / runCounts;
fname_aveRealGens = strcat('zdt2_aveRealGens.',num2str(generations)); % 其他人的算法,待改
fid_aveRealGens = fopen(fname_aveRealGens,'w');
fprintf(fid_aveRealGens,'%f\n',aveRealGens);
fclose(fid_aveRealGens);

⌨️ 快捷键说明

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