BA算法简介
该论文修改
作者在原有BA算法上进行3个修改
①跳出局部最优(扰动个体)
②使得算法变得稳定
③脉搏和响度修改,平衡局部与全局搜索
主要思想
流程图
MATLAB代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
function [bestMin, bestID] = ILSSIWBA() %A new bat algorithm based on iterative local search and stochastic inertia weight %omegaxyz.com QQ: 644327005 clc; %% 经典BA参数设置 t = 1; maxT = 100; %最大迭代次数 dim = 30; %问题的维度 sizep = 50; %种群大小 xmin = -0.5; xmax = 0.5; %位置向量的范围 A = 0.6.*ones(sizep,1); % 响度 (不变或者减小) r = zeros(sizep,1); % 脉冲率 (不变或增加)) Qmin = 0; % 最小频率 Qmax = 1; % 最大频率 %% 初始化 Lb = xmin*ones(1,dim); Ub = xmax*ones(1,dim); pop = Lb+(Ub-Lb).*rand(sizep,dim); %种群初始化 popv = zeros(sizep,dim); % 速度 Q = zeros(sizep,1); % 频率 pfitness = zeros(dim,1); for i = 1:sizep pfitness(i) = evaluate2(pop(i,:)); %评价 end [bestMin, bestID]=min(pfitness); bestS = pop(bestID, :); bestArchive = zeros(maxT,1); %% 论文中的新策略参数 umin = 0.4; %The second modification (SIW method) umax = 0.9; sigma = 0.2; R0 = 0.1; %The 3th modification Rupper = 0.7; A0 = 0.9; Alower = 0.6; %% 具体迭代过程 while t <= maxT for i = 1:sizep Q(i)=Qmin+(Qmin-Qmax)*rand(); w = umin +(umax-umin)*rand()+sigma*randn(); %The second modification (SIW method) popv(i,:)=w*popv(i,:)+(pop(i,:)-bestS)*Q(i); %The second modification (SIW method) Stemp = pop(i,:)+popv(i,:); % 脉冲率 if rand>r(i) Stemp=bestS-1+2*rand(1,dim); end fitTemp = evaluate2(Stemp); if (fitTemp<=pfitness(i))&&(rand()<A(i)) pop(i,:) = Stemp; pfitness(i) = fitTemp; A(i) = (A0-Alower)/(1-maxT)*(t-maxT)+Alower; %The 3th modification r(i) = (R0-Rupper)/(1-maxT)*(t-maxT)+Rupper; %The 3th modification end if fitTemp <= bestMin bestID = i; bestMin = fitTemp; bestS = Stemp; end end interX = bestS.*rand(); %The 1th modification (ILS method) interXfit = evaluate2(interX); if interXfit < bestMin bestMin = interXfit; bestS = interX; pop(bestID,:) = bestS; pfitness(bestID,:) = bestMin; else if exp(bestMin-interXfit) > rand() bestMin = interXfit; bestS = interX; pop(bestID,:) = bestS; pfitness(bestID,:) = bestMin; end end bestArchive(t) = bestMin; fprintf('GEN: %d min: %.4f\n', t, bestMin); t = t +1; end end%.m end |
评价函数:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
function z = evaluate2(u) %Weierstrass dim= length(u); sum_1=0; sum_2=0; sum_3=0; a = 0.5; b = 3; for i=1:dim for k=0:30 sum_1=sum_1+(a^k)*(cos(2*pi*(b^k)*(u(i)+0.5))); end sum_2=sum_2+sum_1; sum_1 = 0; end for k=0:30 sum_3=sum_3+(a^k)*(cos(2*pi*(b^k)*0.5)); end z=sum_2-dim*sum_3; end |
这个代码有问题,应该是没有在变异后进行边界处理,导致变量的约束失效了。
好的,欢迎提出解决方案