【优化算法】自适应对抗粘菌优化算法 (AOSMA)【含Matlab源码 1425期】
【摘要】
一、获取代码方式
获取代码方式1: 通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。
获取代码方式2: 完整代码已上传我的资源:【优化算法】自适应对抗粘菌优化算法 (AOSMA)【含...
一、获取代码方式
获取代码方式1:
通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。
获取代码方式2:
完整代码已上传我的资源:【优化算法】自适应对抗粘菌优化算法 (AOSMA)【含Matlab源码 1425期】
备注:
订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);
二、部分源代码
%% The Adative Opposition Slime Mould Algorithm (AOSMA) function
function [Destination_fitness,bestPositions,Convergence_curve]=AOSMA(N,Max_iter,lb,ub,dim,fobj)
bestPositions=zeros(1,dim);
Destination_fitness=inf;%change this to -inf for maximization problems
AllFitness = inf*ones(N,1);%record the fitness of all slime mold
weight = ones(N,dim);%fitness weight of each slime mold
%Initialize the set of random solutions
X=initialization(N,dim,ub,lb);
Convergence_curve=zeros(1,Max_iter);
it=1; %Number of iterations
lb=ones(1,dim).*lb; % lower boundary
ub=ones(1,dim).*ub; % upper boundary
del=0.03; % parameter
for i=1:N
% Check if solutions go outside the search space and bring them back
Flag4ub=X(i,:)>ub;
Flag4lb=X(i,:)<lb;
X(i,:)=(X(i,:).*(~(Flag4ub+Flag4lb)))+ub.*Flag4ub+lb.*Flag4lb;
AllFitness(i) = fobj(X(i,:));
end
% Main loop
while it <= Max_iter
oldfitness=AllFitness;
[SmellOrder,SmellIndex] = sort(oldfitness); %Eq.(7)
worstFitness = SmellOrder(N);
bestFitness = SmellOrder(1);
S=bestFitness-worstFitness+eps; % plus eps to avoid denominator zero
%calculate the fitness weight of each slime mold
for i=1:N
for j=1:dim
if i<=(N/2) %Eq.(6)
weight(SmellIndex(i),j) = 1+rand()*log10((bestFitness-SmellOrder(i))/(S)+1);
else
weight(SmellIndex(i),j) = 1-rand()*log10((bestFitness-SmellOrder(i))/(S)+1);
end
end
end
%update the best fitness value and best position
if bestFitness < Destination_fitness
bestPositions=X(SmellIndex(1),:);
Destination_fitness = bestFitness;
end
a = atanh(-(it/Max_iter)+1); %Eq.(11)
b = 1-it/Max_iter; %Eq.(12)
% Update the Position of search agents
for i=1:N %Eq.(13)
if rand<del
X(i,:) = (ub-lb)*rand+lb; %Eq.(13c)
else
p =tanh(abs(oldfitness(i)-Destination_fitness)); %Eq.(4)
vb = unifrnd(-a,a,1,dim);
vc = unifrnd(-b,b,1,dim);
A = randi([1,N]); % one positions randomly selected from population
r2 = rand();
for j=1:dim
if r2<p %Eq.(13a)
X(i,j) = bestPositions(j)+ vb(j)*(weight(i,j)*bestPositions(j)-X(A,j));
else %Eq.(13b)
X(i,j) = vc(j)*X(i,j);
end
end
end
end
for i=1:N
% Check if solutions go outside the search space and bring them back
Flag4ub=X(i,:)>ub;
Flag4lb=X(i,:)<lb;
X(i,:)=(X(i,:).*(~(Flag4ub+Flag4lb)))+ub.*Flag4ub+lb.*Flag4lb;
AllFitness(i) = fobj(X(i,:));
end
for i=1:N
if AllFitness(i)>oldfitness(i) %Eq.(16)
D(i,:)=min(X(i,:))+max(X(i,:))-X(i,:); %Eq.(14)
Flag4ub=D(i,:)>ub;
Flag4lb=D(i,:)<lb;
D(i,:)=(D(i,:).*(~(Flag4ub+Flag4lb)))+ub.*Flag4ub+lb.*Flag4lb;
if fobj(D(i,:))<AllFitness(i) %Eq.(15)
X(i,:)=D(i,:);
end
end
end
Convergence_curve(it)=Destination_fitness;
it=it+1;
end
end
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
三、运行结果
四、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,2016.
[2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,2017.
文章来源: qq912100926.blog.csdn.net,作者:海神之光,版权归原作者所有,如需转载,请联系作者。
原文链接:qq912100926.blog.csdn.net/article/details/120894968
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)