%灰狼算法
function [Alpha_score,Alpha_pos,Convergence_curve,BestNet]=GWO(SearchAgents_no,Max_iter,lb,ub,dim,fobj)
% initialize alpha, beta, and delta_pos
Alpha_pos=zeros(1,dim);
Alpha_score=inf; %change this to -inf for maximization problems
Beta_pos=zeros(1,dim);
Beta_score=inf; %change this to -inf for maximization problems
Delta_pos=zeros(1,dim);
Delta_score=inf; %change this to -inf for maximization problems
%Initialize the positions of search agents
Positions=initialization(SearchAgents_no,dim,ub,lb);
Convergence_curve=zeros(1,Max_iter);
l=0;% Loop counter
net = {};%用于存储网络
% Main loop
while l<Max_iter
disp(['第',num2str(l),'次迭代'])
for i=1:size(Positions,1)
% Return back the search agents that go beyond the boundaries of the search space
Flag4ub=Positions(i,:)>ub;
Flag4lb=Positions(i,:)<lb;
Positions(i,:)=(Positions(i,:).*(~(Flag4ub+Flag4lb)))+ub.*Flag4ub+lb.*Flag4lb;
% Calculate objective function for each search agent
[fitness]=fobj(Positions(i,:));
% Update Alpha, Beta, and Delta
if fitness<Alpha_score
Alpha_score=fitness; % Update alpha
Alpha_pos=Positions(i,:);
% BestNet = net{i};
end
if fitness>Alpha_score && fitness<Beta_score
Beta_score=fitness; % Update beta
Beta_pos=Positions(i,:);
end
if fitness>Alpha_score && fitness>Beta_score && fitness<Delta_score
Delta_score=fitness; % Update delta
Delta_pos=Positions(i,:);
end
end
a=2-l*((2)/Max_iter); % a decreases linearly fron 2 to 0
% Update the Position of search agents including omegas
for i=1:size(Positions,1)
for j=1:size(Positions,2)
r1=rand(); % r1 is a random number in [0,1]
r2=rand(); % r2 is a random number in [0,1]
A1=2*a*r1-a; % Equation (3.3)
C1=2*r2; % Equation (3.4)
D_alpha=abs(C1*Alpha_pos(j)-Positions(i,j)); % Equation (3.5)-part 1
X1=Alpha_pos(j)-A1*D_alpha; % Equation (3.6)-part 1
r1=rand();
r2=rand();
A2=2*a*r1-a; % Equation (3.3)
C2=2*r2; % Equation (3.4)
D_beta=abs(C2*Beta_pos(j)-Positions(i,j)); % Equation (3.5)-part 2
X2=Beta_pos(j)-A2*D_beta; % Equation (3.6)-part 2
r1=rand();
r2=rand();
A3=2*a*r1-a; % Equation (3.3)
C3=2*r2; % Equation (3.4)
D_delta=abs(C3*Delta_pos(j)-Positions(i,j)); % Equation (3.5)-part 3
X3=Delta_pos(j)-A3*D_delta; % Equation (3.5)-part 3
Positions(i,j)=(X1+X2+X3)/3;% Equation (3.7)
end
end
l=l+1;
Convergence_curve(l)=Alpha_score;
end
天天Matlab科研工作室
- 粉丝: 4w+
- 资源: 1万+
最新资源
- ssm网络教学平台的设计与实现+vue.zip
- 电网管理中的分层决策 matlab源代码,代码按照高水平文章复现,保证正确 由于可再生能源发电、可变需求和计划外停电等因素的影响,电网管理是一个多时间尺度决策和随机行为的难题 在面对不确定性的情况下
- ssm四六级报名与成绩查询系统+jsp.zip
- ssm铁岭河医院医患管理系统+vue.zip
- ssm田径运动会成绩管理系统的设计与实现+vue.zip
- ssm实验室开放管理系统+jsp.zip
- ssm蜀都天香酒楼的网站设计与实现+jsp.zip
- ssm视频点播系统设计与实现+vue.zip
- ssm神马物流+vue.zip
- ssm实验室耗材管理系统设计与实现+jsp.zip
- ssm生活缴费系统及相关安全技术的设计与实现+jsp.zip
- ssm人事管理信息系统+jsp.zip
- ssm社区管理与服务的设计与实现+jsp.zip
- ssm社区文化宣传网站+jsp.zip
- Dell EMC Unity-Unisphere CLI Guide
- ssm汽车养护管理系统+jsp.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈