优化算法蚱蜢优化算法(GOA)含Matlab源码 1070期
Posted 紫极神光(Q1564658423)
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了优化算法蚱蜢优化算法(GOA)含Matlab源码 1070期相关的知识,希望对你有一定的参考价值。
一、简介
GOA是一种用于全局优化的新型元启发式算法
提出的蝗虫优化算法(GOA)在数学上模拟并模拟了蝗虫群的行为,以解决优化问题。
提出了一种称为蚱蜢优化算法(GOA)的优化算法,并将其应用于结构优化中具有挑战性的问题。该算法通过数学建模和模拟自然界中蝗虫群的行为来解决优化问题。首先将GOA算法应用于包括CEC2005在内的一组测试问题上,对其性能进行了定性和定量的测试和验证。并以52杆桁架、三杆桁架及悬臂梁为例,探讨其适用性。
1 GOA数学模型
2 GOA迭代模型
3 GOA算法的基本流程
4 GOA缺点
二、源代码
%_________________________________________________________________________%
% 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
三、运行结果
四、备注
版本:2014a
以上是关于优化算法蚱蜢优化算法(GOA)含Matlab源码 1070期的主要内容,如果未能解决你的问题,请参考以下文章
预测模型基于蚱蜢算法优化支持向量机实现预测分类模型matlab源码