|
免疫布谷鸟算法的函数寻优分析(MATLAB视频)
百度网盘链接:
链接:https://pan.baidu.com/s/1alG9Eqe7YF4ojHKayRl51g
具体链接在halcom.cn论坛,联系人QQ:3283892722
该论坛是一个学习交流平台,我会逐一的和大家分享学习。
欢迎大家录制视频,并提交给我,我来设置视频,你可在论坛进行打赏分享。
视频专用播放器:http://halcom.cn/forum.php?mod=viewthread&tid=258&extra=page%3D1
主程序如下:
- % 基于免疫布谷鸟算法的函数寻优
- clc,clear,close all
- warning off
- tic % 计时开始
- %% AIA算法参数
- nvar = 2; % 2个未知数
- % 取值范围
- popmin = [-1, -1]; % Lb
- popmax =[ 1, 1]; % Ub
- itermax = 30; % 迭代次数
- sizepop = 30; % 种群
- Ak = -0.01; % 聚合适应度常数k
- lamda = 0.9; % 相似度常数[0.9,1]
- %% CS算法参数
- pa=0.25; % 发现新巢的概率Discovery rate of alien eggs/solutions
- %% 初始化种群
- for i=1:sizepop
- pop(i,:) = code(popmin,popmax); % 实数编码
- fitness(i) = fun(pop(i,:)); % 目标函数值
- end
- [bestfitness,index] = min(fitness); % 极小值
- zbest = pop(index,:); % 最佳个体
- fitnesszbest = bestfitness; % 全局最优
- %% 迭代寻优
- for i=1:itermax
- % 选择算子
- pop = select_AIA(sizepop,pop,fitness,popmin,popmax);
- % 布谷鸟的位置更新
- new_nest = get_cuckoos(pop,zbest,popmin,popmax); % Levy flights 粒子位置更新
- [fitnessgbest,bestgbest,pop,fitness]=get_best_nest(pop, fitness, new_nest);
- % 比较适应度值
- if fitnessgbest<fitnesszbest
- fitnesszbest = fitnessgbest;
- zbest = bestgbest;
- end
-
- % 计算相似度
- for j=1:sizepop
- % 交叉算子
- pop1 = cross_AIA2(sizepop,pop,popmin,popmax);
- AN = 1./( 1+norm( zbest-pop1, 2 ) );
- if(AN>lamda)
- Ci = 1;
- else
- Ci = 0;
- end
- fitness1 = fun( pop1 ) .* exp( Ak*Ci ); % 计算适应度值
- if fitness1<fitness(j)
- fitness(j) = fitness1;
- pop(j,:) = pop1;
- end
-
- % 变异
- pop2 = mutation_AIA2(sizepop,pop,popmin,popmax);
- AN = 1./( 1+norm( zbest-pop2, 2 ) );
- if(AN>lamda)
- Ci = 1;
- else
- Ci = 0;
- end
- fitness2 = fun( pop2 ) .* exp( Ak*Ci ); % 计算适应度值
- if fitness2<fitness(j)
- fitness(j) = fitness2;
- pop(j,:) = pop2;
- end
-
- % 全局比较
- if fitness(j)<fitnesszbest
- fitnesszbest = fitness(j);
- zbest = pop(j,:);
- end
-
- % 寻找新的鸟巢--新的解
- new_nest=empty_nests(pop, popmin, popmax, pa) ;
- [fitnessgbest,bestgbest,pop,fitness]=get_best_nest(pop, fitness, new_nest);
- % 比较适应度值
- if fitnessgbest<fitnesszbest
- fitnesszbest = fitnessgbest;
- zbest = bestgbest;
- end
-
- end
-
- fitness_iter(i) = fitnesszbest;
- end
- toc; % 结束开始
- figure,
- plot(fitness_iter,'ro-','linewidth',2)
- % loglog(fitness_iter,'ro-','linewidth',2)
- grid on
- axis tight
- disp(['最优解 ', num2str(zbest)] )
复制代码
|
|