|
改进的蝙蝠算法的函数寻优分析
百度网盘链接:
链接:https://pan.baidu.com/s/1O7t7kOcBTrCNmUAYgMHArQ
具体链接在halcom.cn论坛,联系人QQ:3283892722
该论坛是一个学习交流平台,我会逐一的和大家分享学习。
欢迎大家录制视频,并提交给我,我来设置视频,你可在论坛进行打赏分享。
视频专用播放器:http://halcom.cn/forum.php?mod=viewthread&tid=258&extra=page%3D1
- clc,clear,close all
- warning off
- % BA算法参数
- maxiter = 20; % 迭代次数
- sizepop = 10; % 种群数量
- % 频率范围
- popmin1 = -1; popmax1 = 1; % x1 频率
- popmin2 = -1; popmax2 = 1; % x2 频率
- fmin = 0.1; % 最小频率
- fmax = 0.5; % 最大频率
- A = 0.1; % 音量 (不变或者减小)
- alpha = 0.98; % 音量阻尼系数
- impluse = 0.85; % 脉冲率 (不变或增加)
- gama = 1000; % M
- Vmin = -1; % 最小速度
- Vmax = 1; % 最大速度
- %% 初始化种群
- for i=1:sizepop
- x1 = popmin1 + (popmax1-popmin1)*rand;
- x2 = popmin2 + (popmax2-popmin2)*rand;
- pop(i,1) = x1;
- pop(i,2) = x2;
- fitness(i) = fun([x1,x2]);
- V(i,1)=0;
- V(i,2)=0;
- end
- % 记录一组最优值
- [bestfitness,bestindex]=min(fitness);
- zbest=pop(bestindex,:); % 全局最佳
- gbest=pop; % 个体最佳
- fitnessgbest=fitness; % 个体最佳适应度值
- fitnesszbest=bestfitness; % 全局最佳适应度值
- %% 迭代寻优
- for i=1:maxiter
- for j=1:sizepop
- f = fmin + (fmax-fmin)*rand;
- V(j,:) = V(j,:) + (pop(j,:)-zbest)*f;
- V(j,:) = lb_ub(V(j,:),Vmax,Vmin);
-
- pop(j,:) = pop(j,:) + V(j,:);
-
- % 脉冲率
- if rand>impluse
- pop(j,:) = zbest + A * randn(1,2);
- end
-
- % x1 越界限制
- pop(j,1) = lb_ub(pop(j,1),popmax1,popmin1);
- % x2 越界限制
- pop(j,2) = lb_ub(pop(j,2),popmax2,popmin2);
-
- % 适应度更新
- fitness(j) = fun(pop(j,:));
-
- % 比较 个体间比较
- if fitness(j)<fitnessgbest(j)
- fitnessgbest(j) = fitness(j);
- gbest(j,:) = pop(j,:);
- end
- if fitness(j)<bestfitness
- bestfitness = fitness(j);
- zbest = pop(j,:);
- end
-
- % 随机的产生新的解
- newpop = pop(j,:) + (2*rand(1,2)-1)*A;
- % x1 越界限制
- newpop(1) = lb_ub(newpop(1),popmax1,popmin1);
- % x2 越界限制
- newpop(2) = lb_ub(newpop(2),popmax2,popmin2);
- if(rand<A && fun(newpop)<fun(zbest))
- bestfitness = fun(newpop);
- zbest = newpop;
- A = alpha*A;
- impluse = impluse*( 1-exp(-gama*i) );
-
- fitness(j) = fun(newpop);
- pop(j,:) = newpop;
- end
-
- end
- fitness_iter(i) = bestfitness;
- end
- %% 显示结果display results
- disp('最优解')
- disp(zbest)
- fprintf('\n')
- disp(['最优解对应的最优目标函数值(适应度值)', num2str( bestfitness )])
- figure('color',[1,1,1])
- plot(fitness_iter,'ro-','linewidth',2)
- axis tight
复制代码
参考:Xin-She Yang. A New Metaheuristic Bat-Inspired Algorithm
|
|