Halcom 发表于 2018-4-5 07:15:57

布谷鸟算法的Pareto多目标函数优化

布谷鸟算法的Pareto多目标函数优化
https://pan.baidu.com/s/1G_XE4C9kUwYJk3le3L9PiQ
https://pan.baidu.com/s/1H1qHD1u6Bb1awo1-6gIh8w
具体链接在halcom.cn论坛,联系人QQ:3283892722
该论坛是一个学习交流平台,我会逐一的和大家分享学习。
欢迎大家录制视频,并提交给我,我来设置视频,你可在论坛进行打赏分享。
视频专用播放器:http://halcom.cn/forum.php?mod=viewthread&tid=258&extra=page%3D1
% 布谷鸟的pareto多目标函数优化分析
% cuckoo_search -- CS算法
% web('halcom.cn')
%% 清空环境
clc % 清屏
clear all; % 删除workplace变量
close all; % 关掉显示图形窗口
tic
%% 参数初始化
global nObj nvar
nObj = 2;   % 2个目标
nvar = 2;   % 2个未知量
maxiter = 50;   % 最大迭代次数
sizepop = 100;   % 种群规模
popmin1 = -1;popmax1 = 1; % x1
popmin2 = -1;popmax2 = 1; % x2
pa=0.25;      % 发现新巢的概率Discovery rate of alien eggs/solutions
repository = 50;    % 非支配解种群数量
nGrid=7;            % 每个目标函数解集域的扩展网格大小,单周期数
alpha=0.1;          % 非支配解的解集的扩展因子
beta=2;             % 非支配解的选择因子
gamma=2;            % 非支配解的淘汰因子
% 初始化种群
x.Pos=[];% 未知量的解
x.fitness=[];         % 粒子适应度值
x.IsDominated=[];      % 是否非支配解,支配解=1, 非支配解=0
x.GridIndex=[];          % 非支配解的网格化参数值-索引总循环数(并排目标函数的序列化内)
x.GridSubIndex=[];       % 每一个非支配解的网格化索引值(扩展取值范围内)
pop=repmat(x,sizepop,1); % 初始化的种群
clear x
for i=1:sizepop
    pop(i).Pos(1) = unifrnd(popmin1,popmax1,1);
    pop(i).Pos(2) = unifrnd(popmin2,popmax2,1);
    % 适应度函数
    pop(i).fitness = fun(pop(i).Pos);
end
% 确定种群之间是否存在支配解
pop=JudgePopDomination(pop);
% 然后获取非支配解
rep=pop(~);
% 扩展非支配解的适应度函数取值范围
Grid=CreateGrids(rep,nGrid,alpha);
% 计算扩展非支配解的GridIndex
for i=1:numel(rep)
    rep(i)=FindGridIndex(rep(i),Grid);
end
%% CS算法的多目标函数寻优主程序
for i=1:maxiter
   
    % 粒子位置更新
    new_nest=[];
    new_nest = get_cuckoos(pop,,, rep, beta); % Levy flights 粒子位置更新
    =get_best_nest(pop, new_nest);

    % 增加非支配解
    rep =)];
    % 非支配解是否有支配解
    rep=JudgePopDomination(rep);
    % 删除支配解
    rep=rep(~);
   
    % 寻找新的鸟巢--新的解
    new_nest=[];
    new_nest=empty_nests(pop, ,, pa) ;
    =get_best_nest(pop, new_nest);
   
    % 增加非支配解
    rep =)];
    % 非支配解是否有支配解
    rep=JudgePopDomination(rep);
    % 删除支配解
    rep=rep(~);
    % 扩展非支配解的适应度函数取值范围
    Grid=CreateGrids(rep,nGrid,alpha);
    for k=1:numel(rep)
      rep(k)=FindGridIndex(rep(k),Grid);
    end
    % 非支配解是否达到最大的非支配解的种群数
    if numel(rep)>repository
      % 将超过的种群删除
      Extra=numel(rep)-repository;
      for k=1:Extra
            rep=DeleteOneRepMemebr(rep,gamma);
      end
    end
   
    figure(1);
    Plotfitness(pop,rep);
    pause(0.01);
end
toc
% % 确定种群之间是否存在支配解
% pop=JudgePopDomination(pop);
% % 增加非支配解
% rep =)];
rep = uniqueRep(rep);
figure(1);
Plotfitness(pop,rep);

% 最优结果
for i=1:size( rep,1 )
    zbest_sol(i,:) = rep(i).Pos;
    if i==1
      fprintf('\n')
      disp('PSO多目标计算的第一组结果如下:')
      disp(['x1 = ',num2str(zbest_sol(i,1))])
      disp(['x2 = ',num2str(zbest_sol(i,2))])
      disp(['最优适应度值为',num2str(')])
      fprintf('\n')
    else
      disp('PSO多目标计算结果有多个Pareto解集')
    end
endempty_nests函数:
function new_nest=empty_nests(nest, popmin, popmax, pa)
global nObj nvar
nest1 = ;
nest1 = reshape(nest1, )';

n=size(nest1,1);% 种群个数
% 发现新巢的概率Discovery rate of alien eggs/solutions
K=rand(size(nest1))>pa;
stepsize = rand*( nest1(randperm(n),:) - nest1(randperm(n),:) );
new_nest1 = nest1 + stepsize.*K;

for i=1:n
    for j=1:size( new_nest1, 2 )
      if(new_nest1(i, j)>popmax(j))
            new_nest1(i, j) = popmax(j);
      end
      if(new_nest1(i, j)<popmin(j))
            new_nest1(i, j)=popmin(j);
      end
    end
    new_nest(i).Pos = new_nest1(i,:);
endget_best_nest函数:
function =get_best_nest(nest, new_nest)
% nest      输入   上一代的解
% fun:   输入   适应度函数
% new_nest输入   新产生的解

for i=1:size(nest,1)
    new_nest(i).fitness = fun( new_nest(i).Pos );% 适应度值
   
    % 是否受支配
    if Domination(new_nest(i), nest(i))
      nest(i).Pos=new_nest(i).Pos;
      nest(i).fitness=new_nest(i).fitness;
    else
      if rand<0.5
            nest(i).Pos=new_nest(i).Pos;
            nest(i).fitness=new_nest(i).fitness;
      end
    end
   
end
% % 找当前最好的个体
% =min(fitness);% 最优适应度值
% bestnest = nest(bestindex,:);   % 全局最佳种群get_cuckoos函数:
function new_nest = get_cuckoos(pop, popmin, popmax, rep, betaPareto)
% Levy flights 粒子位置更新
global nObj nvar
nest = ;
nest = reshape(nest, )';
new_nest = pop;
pop = [];

% Levy flights
n=size(nest,1);   % 种群个数
% Levy exponent and coefficient
beta=3/2;
sigma=(gamma(1+beta)*sin(pi*beta/2)/(gamma((1+beta)/2)*beta*2^((beta-1)/2)))^(1/beta);

% new_nest = nest;
for i=1:n   % 种群个数
    pop = nest(i,:);
    % Levy flights by Mantegna's algorithm
    u=randn(size(pop))*sigma;
    v=randn( size(pop) );
    step=u./abs(v).^(1/beta);
   
    % 轮盘赌算子随机选择一个非支配解,扰动解,避免陷入局部最优
    zbest=Selectzbest(rep, betaPareto);
    bestnest = zbest.Pos;
   
    stepsize=0.01*step.*(pop-bestnest);
    pop = pop + stepsize.*randn(size(pop));
    % 防止越界
    for k=1:length( pop )
      if pop(k)>popmax(k)
            pop(k)=popmax(k);
      end
      if pop(k)<popmin(k)
            pop(k)=popmin(k);
      end
    end
%   new_nest(i,:) = pop;% 更新种群
    new_nest(i).Pos = pop;   % 更新种群
end参考:
【1】http://halcom.cn/forum.php?mod=viewthread&tid=357&extra=page%3D1
【2】Solving Multiobjective Optimization Problems Using Artificial Bee Colony Algorithm










George 发表于 2019-4-23 23:34:15

感谢楼主,学习学习

jackian 发表于 2020-2-11 10:06:17

非常好的学习资源,感谢分享

jackian 发表于 2020-2-13 02:13:28

机器码:FF48E712CD53F57C-0-FF48C202D90BF17C

风飞纤手 发表于 2020-8-11 20:16:31

期待,学习一下~:lol
页: [1]
查看完整版本: 布谷鸟算法的Pareto多目标函数优化