1 简介
蜘蛛猴算法( SMO) 是 2014 年由 Jagdish Chand Bansal 等学者提出的,是一种建立在对蜘蛛猴群觅食行为建模基础上产生的新型解决优化问题的数值优化方法. 根据原始 SMO 算法多种改进算法被研发用来解决优化问题.
2 部分代码
clc;
clear;
close all;
%% TARGET EQUATION
% ((ABS(X)-20)^2+(Y)^2) -100<X<100 -100<Y<100
%% MONKEY DEFINITION
empty_particle.Position=[];
empty_particle.Cost=[];
empty_particle.LimitCount=[];
%% GENERAL CONFIGURATION
config;
confg = repmat(empty_config,1,1);
confg.VarMin = [-100,-100];
confg.VarMax=[100,100];
confg.nVar = 2;
confg.nPop = 50;
confg.nGrp = 1;
confg.MaxGrps = 5;
confg.MaxIt=50;
confg.LocalLimitCount = 50;
confg.GlobalLimitCount = 150;
%confg.LocalLimitCount = 30;
%confg.GlobalLimitCount = 50;
confg.PR = 0.1;
confg.grpSize=ceil(confg.nPop/confg.nGrp);
%% SMO
SM = repmat(empty_particle,confg.nPop,1);
LL = repmat(empty_particle,confg.nPop,1);
GL = repmat(empty_particle,1,1);
SM = Initialize(SM,confg);
GL.Cost=Inf;
[LL,GL] = SetInitialLeaders(SM,GL,LL,confg);
for run=1:1
for it=1:confg.MaxIt
SM = LocalLeaderPhase(SM,LL,confg);
SM = GlobalLeaderPhase(SM,GL,confg);
LL = LocalLeaderLearningPhase(SM,LL,confg);
GL = GlobalLeaderLearningPhase(GL,LL,confg);
[SM,LL] = LocalLeaderDecisionPhase(SM,GL,LL,confg);
[GL,LL,confg] = GlobalLeaderDecisionPhase(SM,GL,LL,confg);
yy(it)=GL.Cost;
fprintf('Iteration=%d Cost=%f Position=(%f %f)\n',it,GL.Cost,GL.Position(1),GL.Position(2));
% plotData(SM,GL,LL,confg);
end
end
figure(1)
plot(yy)
xlabel('迭代次数')
ylabel('适应度值')
3 仿真结果
4 参考文献
[1]徐小平, 杨转, & 刘龙. (2020). 求解物流配送中心选址问题的蜘蛛猴算法. 计算机工程与应用.