一、获取代码方式

 

获取代码方式2:

通过紫极神光博客主页开通CSDN会员,凭支付凭证,私信博主,可获得此代码。

获取代码方式3:

通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。

备注:开通CSDN会员,仅只能免费获得1份代码(有效期为开通日起,三天内有效);

订阅紫极神光博客付费专栏,可免费获得2份代码(有效期为订阅日起,三天内有效);

二、蝙蝠优化算法(MOBA)简介

蝙蝠算法( BA) 是 Yang 教授于 2010 年基于群体智能提出的启发式搜索算法,是一种搜索全局最优解的有效方法。该算法是一种基于迭代的优化技术,初始化为一组随机解,然后 通过迭代搜寻最优解,且在最优解周围通过随机飞行产生局部新解,加强了局部搜索。与其他算法相比,BA 在准确性和有效性方面远优于其他算法,且没有许多参数要进行调整。

【优化算法】多目标蝙蝠优化算法(MOBA)【含Matlab源码 005期】_最优解

【优化算法】多目标蝙蝠优化算法(MOBA)【含Matlab源码 005期】_matlab_02

三、部分源代码

% ============================================================   % 

% ------------------------------------------------------------ %

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.

四、运行结果

【优化算法】多目标蝙蝠优化算法(MOBA)【含Matlab源码 005期】_算法_03

【优化算法】多目标蝙蝠优化算法(MOBA)【含Matlab源码 005期】_优化算法_04