一、简介
1、狼群算法中的狼种类分为以下几种:
头狼、探狼、猛狼。
2、猎物分配规则:论功行赏,先强后弱。
3、狼群算法的主体构成:探狼游走、头狼召唤、猛狼围攻3种智能行为,“胜者为王”的头狼角逐规则和“优胜劣汰”的狼群更新规则。
Step1:在解空间中随机初始化狼群的空间坐标,依据目标函数值的大小角逐出人工头狼。
Step2:探狼开始随机游走搜索猎物,若发现某个位置的目标函数值大于头狼的目标函数值,将更新头狼位置,同时头狼发出召唤行为;若未发现,探狼继续游走直到达到最大游走次数,头狼在原本的位置发出召唤行为。
Step3:听到头狼召唤的猛狼以较大的步长快速向头狼奔袭,若奔袭途中猛狼的目标函数值大于头狼的目标函数值,则将对头狼位置进行更新;否则,猛狼将继续奔袭直到进入围攻范围。
Step4:靠近头狼的猛狼将联合探狼对猎物(把头狼位置视为猎物)进行围捕,围捕过程中若其他人工狼的目标函数值大于头狼的目标函数值,则对头狼位置进行更新,直到捕获猎物。
Step5:淘汰狼群中目标函数值较小的人工狼,并在解空间中随机生成新的人工狼,实现狼群的更新。
Step6:最后判断头狼的目标函数值是否达到精度要求或算法是否达到最大迭代次数。
二、源代码
%% 清空环境
clc
clear all
close all
%% 数据初始化
%下载数据
load HeightData
% HeightData=HeightData';
%网格划分
LevelGrid=10;
PortGrid=21;
%起点终点网格点
starty=6;starth=1;
endy=8;endh=21;
m=1;
%算法参数
PopNumber=10; %种群个数
BestFitness=[]; %最佳个体
iter=100;
%初始信息素
pheromone=ones(21,21,21);
dim=PortGrid*2;
Max_iter=100;
ub=PortGrid;
lb=1;
% 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 path of search agents
Convergence_curve=zeros(1,Max_iter);
l=0;% Loop counter
%% 初始搜索路径
[path,pheromone]=searchpath(PopNumber,LevelGrid,PortGrid,pheromone, ...
HeightData,starty,starth,endy,endh);
fitness=CacuFit(path); %适应度计算
[bestfitness,bestindex]=min(fitness); %最佳适应度
bestpath=path(bestindex,:); %最佳路径
BestFitness=[BestFitness;bestfitness]; %适应度值记录
l=0;% Loop counter
% Main loop
while l<Max_iter
for i=1:size(path,1)
% Return back the search agents that go beyond the boundaries of the search space
Flag4ub=path(i,:)>ub;
Flag4lb=path(i,:)<lb;
path(i,:)=round((path(i,:).*(~(Flag4ub+Flag4lb)))+ub.*Flag4ub+lb.*Flag4lb);
% Calculate objective function for each search agent
fitness=CacuFit(path(i,:));
% Update Alpha, Beta, and Delta
if fitness<Alpha_score
Alpha_score=fitness; % Update alpha
Alpha_pos=path(i,:);
end
if fitness>Alpha_score && fitness<Beta_score
Beta_score=fitness; % Update beta
Beta_pos=path(i,:);
end
end
三、运行结果
四、备注
版本:2014a