二、蚱蜢优化算法简介

GOA是一种用于全局优化的新型元启发式算法

提出的蝗虫优化算法(GOA)在数学上模拟并模拟了蝗虫群的行为,以解决优化问题。

提出了一种称为蚱蜢优化算法(GOA)的优化算法,并将其应用于结构优化中具有挑战性的问题。该算法通过数学建模和模拟自然界中蝗虫群的行为来解决优化问题。首先将GOA算法应用于包括CEC2005在内的一组测试问题上,对其性能进行了定性和定量的测试和验证。并以52杆桁架、三杆桁架及悬臂梁为例,探讨其适用性。

【优化算法】蚱蜢优化算法(GOA)【含Matlab源码 1070期】_算法

1 GOA数学模型

【优化算法】蚱蜢优化算法(GOA)【含Matlab源码 1070期】_matlab_02

【优化算法】蚱蜢优化算法(GOA)【含Matlab源码 1070期】_线性代数_03

【优化算法】蚱蜢优化算法(GOA)【含Matlab源码 1070期】_线性代数_04

2 GOA迭代模型

【优化算法】蚱蜢优化算法(GOA)【含Matlab源码 1070期】_优化算法_05

【优化算法】蚱蜢优化算法(GOA)【含Matlab源码 1070期】_算法_06

3 GOA算法的基本流程

【优化算法】蚱蜢优化算法(GOA)【含Matlab源码 1070期】_算法_07

【优化算法】蚱蜢优化算法(GOA)【含Matlab源码 1070期】_优化算法_08

4 GOA缺点

【优化算法】蚱蜢优化算法(GOA)【含Matlab源码 1070期】_线性代数_09

【优化算法】蚱蜢优化算法(GOA)【含Matlab源码 1070期】_优化算法_10

三、部分源代码

%_________________________________________________________________________%
% Grasshopper Optimization Algorithm (GOA) source codes demo V1.0 %
% %
% Developed in MATLAB R2016a %


% The Grasshopper Optimization Algorithm
function [TargetFitness,TargetPosition,Convergence_curve,Trajectories,fitness_history, position_history]=GOA(N, Max_iter, lb,ub, dim, fobj)

disp('GOA is now estimating the global optimum for your problem....')

flag=0;
if size(ub,1)==1
ub=ones(dim,1)*ub;
lb=ones(dim,1)*lb;
end

if (rem(dim,2)~=0) % this algorithm should be run with a even number of variables. This line is to handle odd number of variables
dim = dim+1;
ub = [ub; 100];
lb = [lb; -100];
flag=1;
end

%Initialize the population of grasshoppers
GrassHopperPositions=initialization(N,dim,ub,lb);
GrassHopperFitness = zeros(1,N);

fitness_history=zeros(N,Max_iter);
position_history=zeros(N,Max_iter,dim);
Convergence_curve=zeros(1,Max_iter);
Trajectories=zeros(N,Max_iter);

cMax=1;
cMin=0.00004;
%Calculate the fitness of initial grasshoppers

for i=1:size(GrassHopperPositions,1)
if flag == 1
GrassHopperFitness(1,i)=fobj(GrassHopperPositions(i,1:end-1));
else
GrassHopperFitness(1,i)=fobj(GrassHopperPositions(i,:));
end
fitness_history(i,1)=GrassHopperFitness(1,i);
position_history(i,1,:)=GrassHopperPositions(i,:);
Trajectories(:,1)=GrassHopperPositions(:,1);
end

[sorted_fitness,sorted_indexes]=sort(GrassHopperFitness);

% Find the best grasshopper (target) in the first population
for newindex=1:N
Sorted_grasshopper(newindex,:)=GrassHopperPositions(sorted_indexes(newindex),:);
end

TargetPosition=Sorted_grasshopper(1,:);
TargetFitness=sorted_fitness(1);

% Main loop
l=2; % Start from the second iteration since the first iteration was dedicated to calculating the fitness of antlions
while l<Max_iter+1

c=cMax-l*((cMax-cMin)/Max_iter); % Eq. (2.8) in the paper

for i=1:size(GrassHopperPositions,1)
temp= GrassHopperPositions';
for k=1:2:dim
S_i=zeros(2,1);
for j=1:N
if i~=j
Dist=distance(temp(k:k+1,j), temp(k:k+1,i)); % Calculate the distance between two grasshoppers

r_ij_vec=(temp(k:k+1,j)-temp(k:k+1,i))/(Dist+eps); % xj-xi/dij in Eq. (2.7)
xj_xi=2+rem(Dist,2); % |xjd - xid| in Eq. (2.7)

s_ij=((ub(k:k+1) - lb(k:k+1))*c/2)*S_func(xj_xi).*r_ij_vec; % The first part inside the big bracket in Eq. (2.7)
S_i=S_i+s_ij;
end
end
S_i_total(k:k+1, :) = S_i;

end

X_new = c * S_i_total'+ (TargetPosition); % Eq. (2.7) in the paper
GrassHopperPositions_temp(i,:)=X_new';
end
% GrassHopperPositions
GrassHopperPositions=GrassHopperPositions_temp;

for i=1:size(GrassHopperPositions,1)
% Relocate grasshoppers that go outside the search space
Tp=GrassHopperPositions(i,:)>ub';Tm=GrassHopperPositions(i,:)<lb';GrassHopperPositions(i,:)=(GrassHopperPositions(i,:).*(~(Tp+Tm)))+ub'.*Tp+lb'.*Tm;

% Calculating the objective values for all grasshoppers
if flag == 1
GrassHopperFitness(1,i)=fobj(GrassHopperPositions(i,1:end-1));
else
GrassHopperFitness(1,i)=fobj(GrassHopperPositions(i,:));
end
fitness_history(i,l)=GrassHopperFitness(1,i);
position_history(i,l,:)=GrassHopperPositions(i,:);

Trajectories(:,l)=GrassHopperPositions(:,1);

% Update the target
if GrassHopperFitness(1,i)<TargetFitness
TargetPosition=GrassHopperPositions(i,:);
TargetFitness=GrassHopperFitness(1,i);
end
end

Convergence_curve(l)=TargetFitness;
disp(['In iteration #', num2str(l), ' , target''s objective = ', num2str(TargetFitness)])

l = l + 1;
end

四、运行结果

【优化算法】蚱蜢优化算法(GOA)【含Matlab源码 1070期】_算法_11

五、matlab版本及参考文献

1 matlab版本

2014a

2 参考文献

[1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,2016.

[2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,2017.