当前位置 : 主页 > 编程语言 > python >

【帝企鹅算法】基于帝企鹅算法求解单目标问题附matlab代码

来源:互联网 收集:自由互联 发布时间:2022-06-15
1 简介 2 部分代码 %% 帝企鹅算法测试函数 % AFO on shifted classcial benchmark functions clc; clear; close all; warning off %% rng('default') %% 测试函数 global option option.no=1; %选择测试函数 option.F=['F',num2str(

1 简介

【帝企鹅算法】基于帝企鹅算法求解单目标问题附matlab代码_sed

【帝企鹅算法】基于帝企鹅算法求解单目标问题附matlab代码_无人机_02

【帝企鹅算法】基于帝企鹅算法求解单目标问题附matlab代码_sed_03

2 部分代码

%% 帝企鹅算法测试函数
% AFO on shifted classcial benchmark functions
clc;
clear;
close all;
warning off
%%
rng('default')
%% 测试函数
global option
option.no=1; %选择测试函数
option.F=['F',num2str(option.no)];
[lb,ub,dim,fobj] = Get_Functions_details(option.F);
option.lb=lb;
option.ub=ub;
option.dim=dim;
if length(option.lb)==1
option.lb=ones(1,option.dim)*option.lb;
option.ub=ones(1,option.dim)*option.ub;
end
option.fobj0=fobj;
option.fobj=@fitFCN_BX;
option.showIter=0;
%% 实验参数
option.repeatNum=10; % Number of repetitions of the test
option.numAgent=150; % size of population
option.maxIteration=200; % maximum number of interation
option.v_lb=-(option.ub-option.lb)/4;
option.v_ub=(option.ub-option.lb)/4;
option.w2=0.5; %weight of Moving strategy III
option.w4=1;%weight of Moving strategy III
option.w5=1;%weight of Moving strategy III
option.pe=0.01; % rate to judge Premature convergence
option.gap0=ceil(sqrt(option.maxIteration*2))+1;
option.gapMin=5; % min gap
option.dec=2; % dec of gap
option.L=10; % Catastrophe
data=[];
str_legend=[{'AFO1'},{'AFO2'},{'AFO3'}];
for ii=1:option.repeatNum
ii
rng(ii)
%% shift classcial benchmark functions
option.RateB1=0.6; %Bound of Shift in x space
option.RateB2=0.3; %Bound of Shift in x space
temp1=rand(1,option.dim).*(option.RateB1-option.RateB2).*option.ub+option.RateB2.*option.ub;
temp2=rand(1,option.dim).*(option.RateB1-option.RateB2).*option.lb+option.RateB2.*option.lb;
tempR=rand(1,option.dim);
if lb==0
option.XB=temp1;
elseif ub==0
option.XB=temp2;
else
option.XB=zeros(1,option.dim);
option.XB(tempR>0.5)=temp1(tempR>0.5);
option.XB(tempR<0.5)=temp2(tempR<0.5);
end
option.XB=-option.XB;
%% Initialize population individuals (common to control experiment algorithm)
x=ones(option.numAgent,option.dim);
y=ones(option.numAgent,1);
for i=1:option.numAgent
x(i,:)=rand(size(option.lb)).*(option.ub-option.lb)+option.lb;
y(i)=option.fobj(x(i,:),option,data);
end
%% ??????·¨?ó??
% Based on the same population, solve the selected benchmarks functions by using different algorithms
bestX=x;
rng(ii)
tic
[bestY(1,:),bestX(1,:),recording(1)]=AFO1(x,y,option,data);
tt(ii,1)=toc;
rng(ii)
tic
[bestY(2,:),bestX(2,:),recording(2)]=AFO2(x,y,option,data);
tt(ii,2)=toc;
rng(ii)
tic
tt(ii,3)=toc;
for i=1:length(recording)
recordingCruve{i}(ii,1:option.maxIteration)=recording(i).bestFit(1:option.maxIteration);
recordingY(i,ii)=bestY(i,:);
end
end
%% Cruve
figure
hold on
for i=1:length(recording)
if i>=8
plot(mean(recordingCruve{i}),'LineWidth',2)
else
plot(mean(recordingCruve{i}),'--','LineWidth',2)
end
end
legend(str_legend)
%% Cruve based log
figure
subplot(122)
hold on
for i=1:length(recording)
if i >=8
plot(log(mean(recordingCruve{i})),'LineWidth',2)
else
plot(log(mean(recordingCruve{i})),'-.','LineWidth',2)
end
end
legend(str_legend)
%% ??×??á?? Aggregate results
meanY=mean(recordingY');
stdY=std(recordingY');
minY=min(recordingY');
maxY=max(recordingY');
maeY=mean(abs(recordingY'-meanY));
runningT=mean(tt(2:end,:));
%% ???????????? Plotting function images
option.F=['F',num2str(option.no)];
subplot(121)
func_plot(option.F)

3 仿真结果

【帝企鹅算法】基于帝企鹅算法求解单目标问题附matlab代码_sed_04


4 参考文献

[1]唐菁敏等. "一种基于帝企鹅差分算法的WSN覆盖优化." 云南大学学报:自然科学版 43.1(2021):6.

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

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

【帝企鹅算法】基于帝企鹅算法求解单目标问题附matlab代码_参考文献_05





上一篇:listview
下一篇:没有了
网友评论