蝙蝠算法( BA) 是 Yang 教授于 2010 年基于群体智能提出的启发式搜索算法,是一种搜索全局最优解的有效方法。该算法是一种基于迭代的优化技术,初始化为一组随机解,然后 通过迭代搜寻最优解,且在最优解周围通过随机飞行产生局部新解,加强了局部搜索。与其他算法相比,BA 在准确性和有效性方面远优于其他算法,且没有许多参数要进行调整。
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function moba_ns_new(inp),
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if nargin<1, % Check inputs (otherwise, default values)
inp=[100 1000]; % [Pop size, #Iteration] e.g., inp=[100 1000]
end
npop = inp(1); %% Population size
Gen = inp(2); %% Number of Iterations
m=2; %% Number of objectives
ndim=30; %% ndim=dimensions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Parameter settings (initial values) %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
AL = 0.9;
r = 0.9;
alpha = 0.9;
Gamma = 0.9;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Initialize the increment components for bats/locations
del_bats = zeros(npop,ndim);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
new_bats = zeros(npop,ndim);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Lb=zeros(1,ndim); % Lower bounds
Ub=ones(1,ndim); % Upper bounds
minf=0; maxf=1; % Frequnecy range
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Initialize the population
for i=1:npop,
x(i,:)=Lb+(Ub-Lb).*rand(1,ndim);
f(i,1:m) = obj_funs(x(i,:), m);
end
%% Combining x and f into a large matrix for easy storage
%% x is an npop x ndim matrix, while f is an (npop x m) matrix.
%% So the combined matrix has a size of npop x (ndim+m),
%% with the last m columns being the m objective values
bats=[x f];
end
%% Displaying the final Pareto Front as a graph
figure(2)
plot(bats(:,ndim+1), bats(:,ndim+2),'rd');
title(strcat(num2str(npop),' Points on the Pareto Front'));
xlabel('Objective (f_1)'); ylabel('Objective (f_2)');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Make sure all the bats are within the limits
function [ns]=findlimits(ns,Lb,Ub)
% Apply the lower bound
ns_tmp=ns;
I=ns_tmp < Lb;
ns_tmp(I)=Lb(I);
% Apply the upper bounds
J=ns_tmp>Ub;
ns_tmp(J)=Ub(J);
% Update this new move
ns=ns_tmp;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Objective functions
function f = obj_funs(x, m)
% Zitzler-Deb-Thiele's funciton No 3 (ZDT function 3)
% m = number of objectives
% ndim = number of variables/dimensions
ndim=length(x); % ndim=30 for ZDT 3
% First objective f1
f(1) = x(1);
g=1+9/29*sum(x(2:ndim));
h=1-sqrt(f(1)/g)-f(1)/g*sin(10*pi*f(1));
% Second objective f2
f(2) = g*h;
%%%%%%%%%%%%%%%%%% end of the definitions of obojectives %%%%%%%%%%%%%%%%%%
%% Clean up the populations (both old and new) to give a new population
% This cleanup here is similar to the Non-dominated Sorting Genetic
% Algorithm (NSGA-II) by K. Deb et al. (2002), which can be applied to
% any cleanup of 2*npop solutions to form a set of npop solutions.
function new_bats = cleanup_batspop(bats, m, ndim, npop)
% The input population to this part has twice (ntwice) of the needed
% population size (npop). Thus, selection is done based on ranking and
% crowding distances, calculated from the non-dominated sorting
ntwice= size(bats,1);
% Ranking is stored in column Krank
Krank=m+ndim+1;
% Sort the population of size 2*npop according to their ranks
[~,Index] = sort(bats(:,Krank)); sorted_bats=bats(Index,:);
% Get the maximum rank among the population
RankMax=max(bats(:,Krank));
%% Main loop for selecting solutions based on ranks and crowding distances
K = 0; % Initialization for the rank counter
% Loop over all ranks in the population
for i =1:RankMax,
% Obtain the current rank i from sorted solutions
RankSol = max(find(sorted_bats(:, Krank) == i));
% In the new bats/solutions, there can be npop solutions to fill
if RankSol new_bats(K+1:RankSol,:)=sorted_bats(K+1:RankSol,:);
end
% If the population after addition is large than npop, re-arrangement
% or selection is carried out
if RankSol>=npop
% Sort/Select the solutions with the current rank
candidate_bats = sorted_bats(K + 1 : RankSol, :);
[~,tmp_Rank]=sort(candidate_bats(:,Krank+1),'descend');
% Fill the rest (npop-K) bats/solutions up to npop solutions
for j = 1:(npop-K),
new_bats(K+j,:)=candidate_bats(tmp_Rank(j),:);
end
end
% Record and update the current rank after adding new bats
K = RankSol;
end
[1]康志龙, 张雪萍, 陈雷,等. 基于多目标蝙蝠优化的高光谱图像解混算法[J]. 光电子.激光, 2018, 29(3):8.
[2]裴文杰, 汪沨, 谭阳红,等. 基于蝙蝠算法的电力恢复机组选择多目标优化[J]. 计算机工程与应用, 2017.
部分理论引用网络文献,若有侵权联系博主删除。