二、蝙蝠优化算法(MOBA)简介
蝙蝠算法( BA) 是 Yang 教授于 2010 年基于群体智能提出的启发式搜索算法,是一种搜索全局最优解的有效方法。该算法是一种基于迭代的优化技术,初始化为一组随机解,然后 通过迭代搜寻最优解,且在最优解周围通过随机飞行产生局部新解,加强了局部搜索。与其他算法相比,BA 在准确性和有效性方面远优于其他算法,且没有许多参数要进行调整。
三、部分源代码
% ============================================================ %
% ------------------------------------------------------------ %
function Q=moba_demo(NPareto)
if nargin<1,
NPareto=40; % Number of points on the Pareto front
end
global w;
for k=1:NPareto,
% Generate a weighting coefficient:w so that w1=w, w2=1-w, w1+w2=1.
% Observations suggest that systematically monotonic weights are
% better than random weights.
w=k/NPareto;
[best,fmin]=bat_algorithm;
[obj1,obj2]=Funobj(best);
Q(k,:)=[obj1,obj2];
% Output/display
disp(['Weight: ',num2str(w)]);
disp(['Best Obj1=',num2str(obj1),' Obj2=',num2str(obj2)]);
end
% Display the Pareto front
plot(Q(:,1),Q(:,2),'o');
xlabel('Obj_1'); ylabel('Obj_2');
% The main part of the Bat Algorithm %
% Usage: bat_algorithm([20 0.25 0.5]); %
function [best,fmin,N_iter]=bat_algorithm(para)
% Default parameters
if nargin<1, para=[10 0.25 0.5]; end
n=para(1); % Population size, typically 10 to 25
A=para(2); % Loudness (constant or decreasing)
r=para(3); % Pulse rate (constant or decreasing)
% This frequency range determines the scalings
Qmin=0; % Frequency minimum
Qmax=2; % Frequency maximum
% Iteration parameters
%% In order to obtain better/more accurate results, N_iter
%% should be increased to N_iter=2000 or more if necessary.
N_iter=1000; % Total number of function evaluations
% Dimension of the search variables
d=3;
% Initial arrays
Q=zeros(n,1); % Frequency
v=zeros(n,d); % Velocities
% Initialize the population/solutions
for i=1:n,
Sol(i,:)=randn(1,d);
Fitness(i)=Fun(Sol(i,:));
end
% Find the current best
[fmin,I]=min(Fitness);
best=Sol(I,:);
% ====================================================== %
% Note: As this is a demo, here we did not implement the %
% reduction of loudness and increase of emission rates. %
% Interested readers can do some parametric studies %
% and also implementation various changes of A and r etc %
% ====================================================== %
% Start the iterations -- Bat Algorithm
for i_ter=1:N_iter,
% Loop over all bats/solutions
for i=1:n,
Q(i)=Qmin+(Qmin-Qmax)*rand;
v(i,:)=v(i,:)+(Sol(i,:)-best)*Q(i);
S(i,:)=Sol(i,:)+v(i,:);
% Pulse rate
if rand>r
S(i,:)=best+0.01*randn(1,d);
end
% Evaluate new solutions
Fnew=Fun(S(i,:));
% If the solution improves or not too loudness
if (Fnew<=Fitness(i)) & (rand<A) ,
end
% Update the current best
if Fnew<=fmin,
best=S(i,:);
fmin=Fnew;
end
end
end
% End of the main bat algorithm and output/display can be added here.
四、运行结果
五、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,2016.
[2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,2017.