【智能优化算法】基于象鼻虫优化算法求解单目标优化问题附matlab代码

1 内容介绍

基于象鼻虫优化算法求解单目标优化问题附matlab代码​

2 仿真代码

%% Weevils Scattering

clc;

clear;

close all;

warning('off');

%% Variables

Gen= 200; % Number of Generations

for ooo=1:Gen

nVar = 3;                             % Number of Decision Variables

VarSize = [1 nVar];                   % Decision Variables Matrix Size

VarMin = -2;                          % Decision Variables Lower Bound

VarMax = 2;                           % Decision Variables Upper Bound

%% WOA Parameters

MaxIt = 80;          % Maximum Number of Iterations

nPop = 3;            % Number of weevils 

DamageRate = 0.2;                   % Damage Rate

nweevil = round(DamageRate*nPop);   % Number of Remained weevils

nNew = nPop-nweevil;                % Number of New weevils

mu = linspace(1, 0, nPop);          % Mutation Rates

pMutation = 0.1;                    % Mutation Probability

MUtwo = 1-mu;                       % Second Mutation

SnoutPower = 0.8;                   % Weevil Snout power Rate

FlyPower = 0.03*(VarMax-VarMin);    % Weevil Fly Power Rate

%----------------------------------------

%% Cost Functions

a=["@(x) Ackley(x)"];

c=str2num(a);

CostFunction = c;        % Cost Function

%% Basics

% Empty weevil

weevil.Position = []; 

weevil.Cost = [];

% Weevils Array

pop = repmat(weevil, nPop, 1);

% First weevils

for i = 1:nPop

pop(i).Position = unifrnd(VarMin, VarMax, VarSize);

pop(i).Cost = CostFunction(pop(i).Position);end;

% Sort 

[~, SortOrder] = sort([pop.Cost]);pop = pop(SortOrder);

% Best Solution

BestSol = pop(1);

% Best Costs Array

BestCost = zeros(MaxIt, 1);

%--------------------------------

%% WOA Body

for it = 1:MaxIt

newpop = pop;

for i = 1:nPop

for k = 1:nVar

if rand <= MUtwo(i)

TMP = mu;TMP(i) = 0;TMP = TMP/sum(TMP);

j = RouletteWheelS(TMP);

newpop(i).Position(k) = pop(i).Position(k)+SnoutPower*(pop(j).Position(k)-pop(i).Position(k));

end;

% Mutation

if rand <= pMutation

newpop(i).Position(k) = newpop(i).Position(k)+FlyPower*randn;

end;end;

% Apply Lower and Upper Bound Limits

newpop(i).Position = max(newpop(i).Position, VarMin);

newpop(i).Position = min(newpop(i).Position, VarMax);

newpop(i).Cost = CostFunction(newpop(i).Position);end;% Asses power

[~, SortOrder] = sort([newpop.Cost]);newpop = newpop(SortOrder);% Sort

pop = [pop(1:nweevil);newpop(1:nNew)];% Select 

[~, SortOrder] = sort([pop.Cost]);pop = pop(SortOrder);% Sort 

BestSol = pop(1);% Update 

BestCost(it) = BestSol.Cost;% Store 

AllSol(it)=BestSol;

% Iteration 

disp(['In Iteration No ' num2str(it) ': Weevil Optimizer Best Cost = ' num2str(BestCost(it))]);

all=AllSol(it).Position;

allone=all(1,1);

alltwo=all(1,2);

meshone(it)=all(1,1);

meshtwo(it)=all(1,2);

aaa(it)=allone;

bbb(it)=alltwo;

end;

aaaa(ooo,:)=aaa;

bbbb(ooo,:)=bbb;

end;

plot(aaaa,bbbb,'kp','MarkerEdgeColor','k','MarkerFaceColor','r');

3 运行结果

4 参考文献

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

matlab科研助手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值