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

📄 main.asv

📁 多种群的链式智能体遗传算法
💻 ASV
字号:
% sum_lattice = 0;
% sum_cell = 0;
% sum_cell_li = 0;
% sum_dai_lattice = 0;
% sum_dai_cell = 0;
% sum_dai_cell_li = 0;

clear all;

var_num = 2;

% fun_num = 3;
fun_num = 12;
% fun_num = 8;
% fun_num = 13;

switch fun_num
    case 1
        n=20000;
        chromlength=15; %字符串长度(个体长度),染色体长度
        fun_max=20000;
        up_range=100;
        down_range=-100;
        
    case 2
        n=2000;
        chromlength=11; %字符串长度(个体长度),染色体长度
        fun_max=121;
        up_range=10;
        down_range=-10;
        
    case 3 %worse
        n=20000;
        chromlength=15; %字符串长度(个体长度),染色体长度
        fun_max=50000;
        up_range=100;
        down_range=-100;
        
    case 4
        n=20000;
        chromlength=15; %字符串长度(个体长度),染色体长度
        fun_max=20000;
        up_range=100;
        down_range=-100;
        
    case 5 %use short time
        n=60000;
        chromlength=16; %字符串长度(个体长度),染色体长度
        fun_max=87000000;
        up_range=30;
        down_range=-30;
      
    case 6 % only a little
        n=20000;
        chromlength=15; %字符串长度(个体长度),染色体长度
        up_range=100;
        down_range=-100;
        
    case 7 % rand
        n=25600;
        chromlength=15; %字符串长度(个体长度),染色体长度
        fun_max=30;
        up_range=1.28;
        down_range=-1.28;
        
    case 8 %much better
        n=100000;
        chromlength=17; %字符串长度(个体长度),染色体长度
        fun_max=1500;
        up_range=500;
        down_range=-500;

    case 9 % only a little
        n=102400;
        chromlength=17; %字符串长度(个体长度),染色体长度
        fun_max=120;
        up_range=5.12;
        down_range=-5.12;
        
    case 10 %only a little
        n=64000;
        chromlength=16; %字符串长度(个体长度),染色体长度
        fun_max=30;
        up_range=32;
        down_range=-32;
        
    case 11 % good
        n=120000;
        chromlength=17; %字符串长度(个体长度),染色体长度
        fun_max=200;
        up_range=600;
        down_range=-600;
        
    case 12 %use more time 
        n=20000;
        chromlength=15; %字符串长度(个体长度),染色体长度
        up_range=100;
        down_range=-100;
        
    case 13
        n=20000;
        chromlength=15; %字符串长度(个体长度),染色体长度
        up_range=100;
        down_range=-100;
        
    otherwise
        break
end
popsize=66; %设置初始参数,群体大小


for countor = 1:50

% clear all;
pop = [];

pop=my_sga_initpop(popsize,n,var_num,up_range,down_range); %运行初始化函数,随机产生初始群体
% pop = zeros(2,popsize);

% [best_fit]=main_sga(pop,n,popsize,chromlength);
% plot(best_fit,'m')
% hold on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  海明交叉SGA+精英保留
% [best_fit]=main_haimingcross_sga(pop,n,popsize,chromlength,fun_num,up_range,down_range);
% % plot(fun_max-best_fit,'b-.')
% % plot(best_fit,'b-.')
% plot(-best_fit,'b-.')
% 
% gtext('haiming');
% hold on

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   自适应交叉概率的SGA+精英保留 Pm=0.08

% [best_fit]=main_adaptivePC_sga(pop,n,popsize,chromlength,fun_num,up_range,down_range);
% % plot(fun_max-best_fit,'m-')
% % plot(best_fit,'m-')
% plot(-best_fit,'m-')
% gtext('adaptivePCPM');
% hold on
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  自适应遗传算法(单点交叉变异+精英保留)

% best_fit=main_adaptive_sga(pop,n,popsize,chromlength,fun_num,up_range,down_range);
% % plot(fun_max-best_fit,'c-.')
% % plot(best_fit,'c-.')
% plot(-best_fit,'c-.')
% gtext('adaptiveSGA');
% hold on

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  自适应邻域竞争(4邻域)
best_fit1 = [];
[best_fit1,best_fitvalue1,out_dai1,best_dna1,time1]=main_complete(pop,n,popsize,chromlength,fun_num,up_range,down_range,var_num);
% % % % % % % % % % % best_fit
% % % % % % % % % % % % plot(fun_max-best_fit,'g:')
% % % % % % % % % % % % plot(best_fit,'g:')

% plot(-best_fit1,'g:')
% % % % % % % % gtext('lattice');
% hold on


bestfitvalue_lattice_vector(countor) = -best_fitvalue1;

outdai_lattice_vector(countor) = out_dai1;
bestDNA_lattice_vector(:,countor) = best_dna1;
time_lattice_vector(countor) = time1;
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5  链表式邻域竞争(3邻域)
% best_fit=main_complete3(pop,n,popsize,chromlength);
% plot(best_fit,'k-')
% gtext('三邻域');
% hold on

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   改进的链表式3邻域
% best_fit = [];
% [best_fit,best_fitvalue,out_dai]=main_improve_complete3_new(pop,n,popsize,chromlength,fun_num,up_range,down_range,var_num);
% % best_fit
% % % plot(fun_max-best_fit,'r-')
% % % plot(best_fit,'r--')
% % plot(-best_fit,'r--')
% % gtext('chain');
% % legend('lattice','chain');
% % hold off
% bestfitvalue_chain_vector(countor) = -max(best_fit);
% sum_chain = sum_chain - max(best_fit);
% sum_dai_chain = sum_dai_chain + out_dai;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  cellga
best_fit2 = [];
[best_fit2,best_fitvalue2,out_dai2,best_dna2,time2]=main_cell_li(pop,n,popsize,chromlength,fun_num,up_range,down_range,var_num);

% plot(-best_fit2,'b:')
% hold on;

bestfitvalue_cell_li_vector(countor) = -best_fitvalue2;

outdai_cell_li_vector(countor) = out_dai2;
bestDNA_cell_li_vector(:,countor) = best_dna2;
time_cell_li_vector(countor) = time2;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  cellga
best_fit3 = [];
[best_fit3,best_fitvalue3,out_dai3,best_dna3,time3]=main_cell(pop,n,popsize,chromlength,fun_num,up_range,down_range,var_num);

% plot(-best_fit3,'r--')
% % gtext('cell');
% % legend('lattice','cell_li','cell');
% % hold off
% hold on;

bestfitvalue_cell_vector(countor) = -best_fitvalue3;

outdai_cell_vector(countor) = out_dai3;
bestDNA_cell_vector(:,countor) = best_dna3;
time_cell_vector(countor) = time3;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   text
best_fit4 = [];
[best_fit4,best_fitvalue4,out_dai4,best_dna4,time4]=main_text(pop,n,popsize,chromlength,fun_num,up_range,down_range,var_num);

% plot(-best_fit4,'k:')
% % gtext('cell');
% legend('lattice','cell_li','cell','text');
% hold off

bestfitvalue_text_vector(countor) = -best_fitvalue4;

outdai_text_vector(countor) = out_dai4;
bestDNA_text_vector(:,countor) = best_dna4;
time_text_vector(countor) = time4;




end

% best_dai_lattice = sum_dai_lattice/5
% best_value_lattice = sum_lattice/5
% best_dai_chain = sum_dai_chain/5
% best_value_chain = sum_chain/5

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  MGA
bestfitvalue_lattice_ave = mean(bestfitvalue_lattice_vector);
outdai_lattice_ave = mean(outdai_lattice_vector);
time_lattice_ave = mean(time_lattice_vector);

f_max_lattice = max(bestfitvalue_lattice_vector);
f_min_lattice = min(bestfitvalue_lattice_vector);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  cell_li
bestfitvalue_cell_li_ave = mean(bestfitvalue_cell_li_vector);
outdai_cell_li_ave = mean(outdai_cell_li_vector);
time_cell_li_ave = mean(time_cell_li_vector);

f_max_cell_li = max(bestfitvalue_cell_li_vector);
f_min_cell_li = min(bestfitvalue_cell_li_vector);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  cellGA
bestfitvalue_cell_ave = mean(bestfitvalue_cell_vector);
outdai_cell_ave = mean(outdai_cell_vector);
time_cell_ave = mean(time_cell_vector);

f_max_cell = max(bestfitvalue_cell_vector);
f_min_cell = min(bestfitvalue_cell_vector);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   test
bestfitvalue_text_ave = mean(bestfitvalue_text_vector);
outdai_text_ave = mean(outdai_text_vector);
time_text_ave = mean(time_text_vector);

f_max_text = max(bestfitvalue_text_vector);
f_min_text = min(bestfitvalue_text_vector);





⌨️ 快捷键说明

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