Halcom 发表于 2019-2-23 21:53:54

63-鸽群算法PIO算法

鸽群算法PIO算法:Pigeon-inspiredoptimization algorithm


百度网盘链接:
链接:https://pan.baidu.com/s/1Immoe1w6OblYVbGtB16XGw

具体链接在halcom.cn论坛,联系人QQ:3283892722
该论坛是一个学习交流平台,我会逐一的和大家分享学习。
欢迎大家录制视频,并提交给我,我来设置视频,你可在论坛进行打赏分享。
视频专用播放器:http://halcom.cn/forum.php?mod=viewthread&tid=258&extra=page%3D1

程序如下:
clc,clear,close all
warning off
format longG
T1=90;         % Global search algebra,迭代次数
T2=15;         % Local search algebra,迭代次数
pigeonnum=30;    % 种群数量
nvar = 1;             % 未知量个数
R = 0.3;         % 地磁场参数parameters of magnetic field
bound=[-1,1];    % 搜索范围
%% 初始化种群
for i=1:pigeonnum
    pop(i,1) = bound(1) + (bound(2)-bound(1))*rand;
    fitness(i) = fun( pop(i,1));   % 适应度函数
    v(i,1) = rand;                   % 飞行速度
end
% 记录一组最优值
=min(fitness);
zbest=pop(bestindex,:);   %全局最佳
gbest = pop;                % 个体最佳
fitnessgbest=fitness;   %个体最佳适应度值
fitnesszbest=bestfitness; %全局最佳适应度值
%% 地图和指南针算子 magnetic compass and solar operator
for t=1:T1% 迭代次数
    for i=1:pigeonnum
      v(i,:)=v(i,:)*(1-exp(-R*t))+rand*(gbest(i,:)-pop(i,:));
      pop(i,:)=pop(i,:)+v(i,:);   %check whether beyond the searching space
      for j=1:nvar
            if abs(i-1)<=eps
                if pop(i,j)<bound(1)||pop(i,j)>bound(2)
                  pop(i,j)=bound(1)+rand*(bound(2)-bound(1));
                  pop(i,j)=rand;
                end
            else
                if pop(i,j)<bound(1)||pop(i,j)>bound(2)
                  pop(i,j)=pop(i-1,j);
                  v(i,j)=v(i-1,j);
                end   
            end
      end
      fitness(i) = fun( pop(i,:));   % 适应度函数
      % 比较个体间比较
      if fitness(i)<fitnessgbest(i)
            fitnessgbest(i) = fitness(i);
            gbest(i,:) = pop(i,:);
      end
      if fitness(i)<bestfitness
            bestfitness = fitness(i);
            zbest =pop(i,:);
      end
    end
    fitness_iter(t) = bestfitness;
end
%% 地标算子 landmark operator
pop = gbest;                % 个体最佳
fitness = fitnessgbest;   %个体最佳适应度值
for t=1:T2
    % sort the pigeons
    = sort( fitness, 'ascend' );
    pop = pop(b0, :);
    fitness = a0;
    % 取前一半的最优解进行分析
    pigeonnum1=ceil(pigeonnum/2);               % remove half of the pigeons according to the landmark
    % 鸽子的中心值
    addpigeonnum = sum( pop(1:pigeonnum1, :) );                  
    pigeoncenter=ceil(addpigeonnum./pigeonnum); % calculate central position
    for i=1:pigeonnum
      v(i,:)=v(i,:)*(1-exp(-R*t))+rand*(gbest(i,:)-pop(i,:));
      pop(i,:)=pop(i,:)+v(i,:);   %check whether beyond the searching space
      for j=1:nvar
            if abs(i-1)<=eps
                if pop(i,j)<bound(1)||pop(i,j)>bound(2)
                  pop(i,j)=bound(1)+rand*(bound(2)-bound(1));
                  pop(i,j)=rand;
                end
            else
                if pop(i,j)<bound(1)||pop(i,j)>bound(2)
                  pop(i,j)=pop(i-1,j);
                  v(i,j)=v(i-1,j);
                end   
            end
      end
      fitness(i) = fun( pop(i,:));   % 适应度函数
      % 比较个体间比较
      if fitness(i)<fitnessgbest(i)
            fitnessgbest(i) = fitness(i);
            gbest(i,:) = pop(i,:);
      end
      if fitness(i)<bestfitness
            bestfitness = fitness(i);
            zbest =pop(i,:);
      end
    end
    fitness_iter(T1+t) = bestfitness;
end
disp('最优解')
disp(zbest)
fprintf('\n')

figure('color',)
plot(fitness_iter,'ro-','linewidth',2)

figure('color',)
loglog(fitness_iter,'ro-','linewidth',2)


于琳 发表于 2019-3-19 09:19:00

博主,程序中的fun函数定义呢?

wjy@qq.com 发表于 2019-7-5 11:13:21

这个代码里nvar是未知量个数,没有设置D维度吗

Halcom 发表于 2019-7-6 10:58:01

wjy@qq.com 发表于 2019-7-5 11:13
这个代码里nvar是未知量个数,没有设置D维度吗

就是那个D吧,表达式一个意思,nvar个未知量,和你常见的D维度应该是一个意思。
页: [1]
查看完整版本: 63-鸽群算法PIO算法