% 寄生捕食算法
%
%
function [fmin,bestnest,Convergence_curve]=PPA(n,maxiter,lb,ub,d,fobj)
fitness=inf*ones(n,1);
if length(lb) < d
lb=lb*ones(1,d);ub=ub*ones(1,d);
end
% Random initial solutions using Eq.(5)
nest =init(n,ub,lb);
[nest,fitness]=get_best_nest(fobj,nest,nest,fitness);
% Get the current best
[fitness,I]=sort(fitness);nest=nest(I,:);
fmin=fitness(1); bestnest=nest(1,:);
Convergence_curve(1)=fmin;
wMax = 0.9;
wMin = 0.3;
w = linspace(wMax, wMin, maxiter);
Cats_v = 0.25 * nest; % Initial velocity of tracking mode cats
% Growth rate (Section 3.1.2.1, Fig. 3)
[GrowthRateCrows,GrowthRateCats,GrowthRateCuckoos] =Growth_rate(n,maxiter);
% Starting iterations
for t=2:maxiter
nCats=GrowthRateCats(t);%current no. of Cats
nCrows=GrowthRateCrows(t);%current no. of Crows
nCuckoos=GrowthRateCuckoos(t);%current no. of Cuckoos
% __________________ Nesting Phase: Crows _____________________________
% The current best group discover Crow's nest using Eqs.(6-9)
new_Crows=get_Crows(nest(1:nCrows,:),lb,ub);
% _______________ crow-cuckoo subsystem: Parasitism phase _________
% Select parasitized nests based on their fitness
Rolette_index = RankingSelection(n, nCuckoos);
parasitized_nests = nest(Rolette_index(1:nCuckoos),:);
% Replace some Crow's eggs (host) by Cuckoo's eggs
% (the better nests the higher chance for parasitism)
new_Cuckoos = get_Cuckoos(parasitized_nests,lb,ub,t,maxiter);
% Choosing non-parasitized nests, randomly
non_parasitized_nests = randperm( n);
% cuckoo chicks reveal repulsive compounds that repel cats.
% Eliminate nests with high malodorous secretion that occupied by Cuckoos
non_parasitized_nests(Rolette_index(1:nCuckoos)) = []; % Fixing
% Select nests with low malodorous secretion
Cats_nests = nest(non_parasitized_nests( 1:nCats),:); % Choosing
new_Cats_v = Cats_v(non_parasitized_nests( 1:nCats),:);
% Cats track the nest with a low malodorous secretion
[new_Cats, new_Cats_v] = ...
get_Cats(new_Cats_v, Cats_nests, bestnest,t,maxiter, w(t),lb,ub);
% update the velocities
Cats_v(non_parasitized_nests( 1:nCats),:) = new_Cats_v;
% ___________________ Evaluation: ___________________________________
% new system
newnest = [new_Crows;new_Cuckoos;new_Cats];
[nest,fitness] = get_best_nest(fobj,nest,newnest,fitness);
% Find the best objective so far
[fitness,I] = sort(fitness);
nest = nest(I,:);
fmin = fitness(1);
bestnest = nest(1,:);
Convergence_curve(t) = fmin;
% Display the iteration and best optimum obtained so far
% if mod(t,10)==0
% display(['At iteration: ', num2str(t), ' Best fitness is: ', num2str(fmin)]);
% end
end %% End of iterations
end
function choice = RankingSelection(n, N)
ranking = (1:n);% for sorted fitness
weights=ranking/sum(ranking);
Select_Fitness = cumsum(weights);
% (the better nests the higher chance for parasitism)
choice=[];
while length(choice) < N
Random_Fitness=rand(1,n);
selected = ranking(Select_Fitness <= Random_Fitness);
choice=union(choice,selected,'stable')';
end
end
function Sol=simplebounds(Sol,lb,ub)
for i=1:size(Sol,1)% return back populations
% Sol(i,:)=max(Sol(i,:),lb);
% Sol(i,:)=min(Sol(i,:),ub);
Vub=Sol(i,:)>ub;
Vlb=Sol(i,:)<lb;
% Sol(i,:)=(Sol(i,:).*(~(Vub+Vlb)))+ub.*Vub+lb.*Vlb;
Sol(i,:)=(Sol(i,:).*(~(Vub+Vlb)))+(lb+rand(size(lb)).*(ub-lb)).*(Vub+Vlb);
end
end
% Growth rates (Section 3.1.2.1, Fig. 3)
function [GrowthRateCrows,GrowthRateCats, GrowthRateCuckoos] =Growth_rate(n,maxiter)
% According to references [?40-43], and using:
% r1=1: The intrinsic growth rate of crows
% r2=0.1: The death rate of cuckoos
% r3=0.1: The death rate of Cats
% d1=0.01:The density-dependent mortality rate of crows
% d2=0.01:The density-dependent mortality rate of cuckoos
% B1=0.1:The quantity of resources consumed by a cuckoo
% B2=0.1:cats? saturation level in predation
% c1=0.1:The half-saturation density in predation
% c2=0.1:The time lost by cats due to deterrence of cuckoos
% Alpha1=0.2:Cuckoos? efficiency in converting their consumption into fitness
% Alpha2=0.25:cats? efficiency in converting the predation into fitness
% with a crow膨uckoo膨at model:
% dx(i)=r1*x(i-1)*(1-c1*x(i-1)-B1*y(i-1)-B2*z(i-1));
% dy(i)=r2*y(i-1)*(-1+Alpha1*x(i-1)-c2*y(i-1)); %#ok<*AGROW>
% dz(i)=r3*z(i-1)*(-1+Alpha2*x(i-1)-B3*y(i-1)-c3*z(i-1));
% x(i)=x(i-1)+dx(i);
% y(i)=y(i-1)+dy(i);
% z(i)=z(i-1)+dz(i);
% the growth rates can be obtained as follows:
GrowthRateCrows= round(n*linspace(2/3,1/2, maxiter));%Growth rate of Crows
GrowthRateCats= round(n*linspace(0.01,1/3, maxiter));%Growth rate of Cats
GrowthRateCuckoos=n-GrowthRateCrows-GrowthRateCats;%Growth rate of Cuckoos
end
% Find the current best nest
function [nest,fitness]=get_best_nest(fobj,nest,newnest,fitness)
% Evaluating all new solutions
for j=1:size(nest,1)
fnew = fobj(newnest(j,:));
if fnew<=fitness(j)
fitness(j)=fnew;
nest(j,:)=newnest(j,:);
end
end
end
% 3.1.2.4. Predation phase (crow-cat)
% Tracking mode function of Cat Swarm
function [Cats, Cats_v] = ...
get_Cats(Cats_v, Cats, gx,t,maxiter, w,lb,ub)
%velocity limits is modified to be decreased linearly from 1 to 0.25
perCnt = 1-t/maxiter/4;
vlb = perCnt*lb;
vUp = perCnt*ub;
c=2-t/maxiter; % c (social learning) is modified to be decreased linearly from 2 to 1
for iSz2 = 1:size(Cats,1)
V_vec = w * Cats_v(iSz2,:) + c*rand*(gx - Cats(iSz2,:)); % Eq. (13)
% Apply simple bounds/limits to velocity of cats
V_vec = max(V_vec, vlb);
V_vec = min(V_vec, vUp);
Cats_v(iSz2,:) = V_vec;
end
Cats = Cats + Cats_v; % Eq. (14)
% Apply simple bounds/limits to position of cats
Cats = simplebounds( Cats, lb, ub);
end
% 3.1.2.2. Nesting phase (crow痴 nest)
% Levy Crow search algorithm is used to generate new solutions
function nest=get_Crows(nest,lb,ub)
% Levy flights by Mantegna's algorithm for Crow search algorithm
n=size(nest,1);
beta=3/2; sigma=0.6965745;
% Generation of random candidate crows for following (chasing)
num=ceil(n*rand(1,n));
for i=1:n
s=nest(i,:);
u=randn(size(s))*sigma;
v=randn(size(s));
step=u./abs(v).^(1/beta); % Eq.(7)
stepsize=0.1*step.*randn(size(s)); % Eq.(8)
% Generation of a new position for crow i (state 1)
s= s+stepsize.*(nest(num(i),:)-s); % Eq.(6)
% Generation of a new position for crow i (state 2)for more exploration
out=s<lb | s > ub;
s(:,out)=lb(out)+(ub(out)-lb(out)).*rand(1,nnz(out)); % Eq.(9)
nest(i,:)=s;
end
end
% 3.1.2.3. Parasitism phase (crow-cuckoo subsystem)
% Replace some nests by constructing new solutions/nests
function new_nest=get_Cuckoos(nest,lb,ub,t,maxiter)
pa=t/2/maxiter; % Adaptive Discovery rate of alien eggs/solutions
n=size(nest,1);
% probability Eq. (12)
K=rand(size(nest)) > pa; % Discovered or not -- a status vector
stepsize=rand*(nest(randperm(n),:)-nest(randperm(n),:));
new_nest=nest+stepsize.*K; % Eq. (10)
% Apply simple bounds/limits
new_nest=simplebounds(new_nest,lb,ub);
end
function nest =init(n,ub,lb)
for i=1:n
nest(i,:)=lb+(ub-lb).*rand(size(lb)); % Eq.(5)
end
end
寄生捕食算法.zip
需积分: 5 140 浏览量
2023-07-16
14:57:54
上传
评论
收藏 6KB ZIP 举报
![avatar](https://profile-avatar.csdnimg.cn/1e529c6af006432cb55c280e71efde36_weixin_63199521.jpg!1)
昨日与你1
- 粉丝: 253
- 资源: 220
最新资源
- 微分方程 - Differential Equations - Jeffrey R. Chasnov
- POP3服务第三方软件Visendo SMTPExtender(64位)
- 停车场车位管理系统-课程设计报告.zip
- 细菌觅食优化算法BFOAmatlab实现
- 利用DS1302的可调时钟
- 基于 python实现对一幅 BMP 格式的灰度图像先进行二元霍夫曼编码和游程编码【信息论与编码课程设计】(课程设计报告+源码)
- python头歌换披萨模拟场景示例
- 基于 yolo 的行人目标检测 + 源代码 + 详细文档
- 基于springboot+vue+MySQL实现的在线考试系统+源代码+文档
- 基于 yolo 的行人目标检测 + 源代码 + 详细文档
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)