Hello Mat

 找回密码
 立即注册
查看: 13099|回复: 5

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

[复制链接]

1294

主题

1520

帖子

110

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22633
发表于 2018-4-5 07:15:57 | 显示全部楼层 |阅读模式
布谷鸟算法的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
  1. % 布谷鸟的pareto多目标函数优化分析
  2. % cuckoo_search -- CS算法
  3. % web('halcom.cn')
  4. %% 清空环境
  5. clc % 清屏
  6. clear all; % 删除workplace变量
  7. close all; % 关掉显示图形窗口
  8. tic
  9. %% 参数初始化
  10. global nObj nvar
  11. nObj = 2;   % 2个目标
  12. nvar = 2;   % 2个未知量
  13. maxiter = 50;     % 最大迭代次数
  14. sizepop = 100;     % 种群规模
  15. popmin1 = -1;  popmax1 = 1; % x1
  16. popmin2 = -1;  popmax2 = 1; % x2
  17. pa=0.25;        % 发现新巢的概率Discovery rate of alien eggs/solutions
  18. repository = 50;    % 非支配解种群数量
  19. nGrid=7;            % 每个目标函数解集域的扩展网格大小,单周期数
  20. alpha=0.1;          % 非支配解的解集的扩展因子
  21. beta=2;             % 非支配解的选择因子
  22. gamma=2;            % 非支配解的淘汰因子
  23. % 初始化种群
  24. x.Pos=[];  % 未知量的解
  25. x.fitness=[];         % 粒子适应度值
  26. x.IsDominated=[];        % 是否非支配解,支配解=1, 非支配解=0
  27. x.GridIndex=[];          % 非支配解的网格化参数值-索引总循环数(并排目标函数的序列化内)
  28. x.GridSubIndex=[];       % 每一个非支配解的网格化索引值(扩展取值范围内)
  29. pop=repmat(x,sizepop,1); % 初始化的种群
  30. clear x
  31. for i=1:sizepop
  32.     pop(i).Pos(1) = unifrnd(popmin1,popmax1,1);
  33.     pop(i).Pos(2) = unifrnd(popmin2,popmax2,1);
  34.     % 适应度函数
  35.     pop(i).fitness = fun(pop(i).Pos);
  36. end
  37. % 确定种群之间是否存在支配解
  38. pop=JudgePopDomination(pop);
  39. % 然后获取非支配解
  40. rep=pop(~[pop.IsDominated]);
  41. % 扩展非支配解的适应度函数取值范围
  42. Grid=CreateGrids(rep,nGrid,alpha);
  43. % 计算扩展非支配解的GridIndex
  44. for i=1:numel(rep)
  45.     rep(i)=FindGridIndex(rep(i),Grid);
  46. end
  47. %% CS算法的多目标函数寻优主程序
  48. for i=1:maxiter
  49.    
  50.     % 粒子位置更新
  51.     new_nest=[];
  52.     new_nest = get_cuckoos(pop,[popmin1,popmin2],[popmax1,popmax2], rep, beta); % Levy flights 粒子位置更新
  53.     [pop, new_nest]=get_best_nest(pop, new_nest);

  54.     % 增加非支配解
  55.     rep =[rep; pop(~[pop.IsDominated])];
  56.     % 非支配解是否有支配解
  57.     rep=JudgePopDomination(rep);
  58.     % 删除支配解
  59.     rep=rep(~[rep.IsDominated]);
  60.    
  61.     % 寻找新的鸟巢--新的解
  62.     new_nest=[];
  63.     new_nest=empty_nests(pop, [popmin1,popmin2],[popmax1,popmax2], pa) ;
  64.     [pop, new_nest]=get_best_nest(pop, new_nest);
  65.    
  66.     % 增加非支配解
  67.     rep =[rep; pop(~[pop.IsDominated])];
  68.     % 非支配解是否有支配解
  69.     rep=JudgePopDomination(rep);
  70.     % 删除支配解
  71.     rep=rep(~[rep.IsDominated]);
  72.     % 扩展非支配解的适应度函数取值范围
  73.     Grid=CreateGrids(rep,nGrid,alpha);
  74.     for k=1:numel(rep)
  75.         rep(k)=FindGridIndex(rep(k),Grid);
  76.     end
  77.     % 非支配解是否达到最大的非支配解的种群数
  78.     if numel(rep)>repository
  79.         % 将超过的种群删除
  80.         Extra=numel(rep)-repository;
  81.         for k=1:Extra
  82.             rep=DeleteOneRepMemebr(rep,gamma);
  83.         end
  84.     end
  85.      
  86.     figure(1);
  87.     Plotfitness(pop,rep);
  88.     pause(0.01);
  89. end
  90. toc
  91. % % 确定种群之间是否存在支配解
  92. % pop=JudgePopDomination(pop);
  93. % % 增加非支配解
  94. % rep =[rep; pop(~[pop.IsDominated])];
  95. rep = uniqueRep(rep);
  96. figure(1);
  97. Plotfitness(pop,rep);

  98. % 最优结果
  99. for i=1:size( rep,1 )
  100.     zbest_sol(i,:) = rep(i).Pos;
  101.     if i==1
  102.         fprintf('\n')
  103.         disp('PSO多目标计算的第一组结果如下:')
  104.         disp(['x1 = ',num2str(zbest_sol(i,1))])
  105.         disp(['x2 = ',num2str(zbest_sol(i,2))])
  106.         disp(['最优适应度值为  ',num2str([rep(i).fitness]')])
  107.         fprintf('\n')
  108.     else
  109.         disp('PSO多目标计算结果有多个Pareto解集')
  110.     end
  111. end
复制代码
empty_nests函数:
  1. function new_nest=empty_nests(nest, popmin, popmax, pa)
  2. global nObj nvar
  3. nest1 = [nest.Pos];
  4. nest1 = reshape(nest1, [nvar, size(nest,1)])';

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

  10. for i=1:n
  11.     for j=1:size( new_nest1, 2 )
  12.         if(new_nest1(i, j)>popmax(j))
  13.             new_nest1(i, j) = popmax(j);
  14.         end
  15.         if(new_nest1(i, j)<popmin(j))
  16.             new_nest1(i, j)=popmin(j);
  17.         end
  18.     end
  19.     new_nest(i).Pos = new_nest1(i,:);
  20. end
复制代码
get_best_nest函数:
  1. function [nest, new_nest]=get_best_nest(nest, new_nest)
  2. % nest      输入   上一代的解
  3. % fun:     输入   适应度函数
  4. % new_nest  输入   新产生的解

  5. for i=1:size(nest,1)
  6.     new_nest(i).fitness = fun( new_nest(i).Pos );  % 适应度值
  7.    
  8.     % 是否受支配
  9.     if Domination(new_nest(i), nest(i))
  10.         nest(i).Pos=new_nest(i).Pos;
  11.         nest(i).fitness=new_nest(i).fitness;
  12.     else
  13.         if rand<0.5
  14.             nest(i).Pos=new_nest(i).Pos;
  15.             nest(i).fitness=new_nest(i).fitness;
  16.         end
  17.     end
  18.    
  19. end
  20. % % 找当前最好的个体
  21. % [bestfitness,bestindex]=min(fitness);  % 最优适应度值
  22. % bestnest = nest(bestindex,:);   % 全局最佳种群
复制代码
get_cuckoos函数:
  1. function new_nest = get_cuckoos(pop, popmin, popmax, rep, betaPareto)
  2. % Levy flights 粒子位置更新
  3. global nObj nvar
  4. nest = [pop.Pos];
  5. nest = reshape(nest, [nvar, size(pop,1)])';
  6. new_nest = pop;
  7. pop = [];

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

  13. % new_nest = nest;
  14. for i=1:n   % 种群个数
  15.     pop = nest(i,:);
  16.     % Levy flights by Mantegna's algorithm
  17.     u=randn(size(pop))*sigma;
  18.     v=randn( size(pop) );
  19.     step=u./abs(v).^(1/beta);
  20.    
  21.     % 轮盘赌算子随机选择一个非支配解,扰动解,避免陷入局部最优
  22.     zbest=Selectzbest(rep, betaPareto);
  23.     bestnest = zbest.Pos;
  24.    
  25.     stepsize=0.01*step.*(pop-bestnest);
  26.     pop = pop + stepsize.*randn(size(pop));
  27.     % 防止越界
  28.     for k=1:length( pop )
  29.         if pop(k)>popmax(k)
  30.             pop(k)=popmax(k);
  31.         end
  32.         if pop(k)<popmin(k)
  33.             pop(k)=popmin(k);
  34.         end
  35.     end
  36. %     new_nest(i,:) = pop;  % 更新种群
  37.     new_nest(i).Pos = pop;   % 更新种群
  38. end
复制代码
参考:
【1】http://halcom.cn/forum.php?mod=viewthread&tid=357&extra=page%3D1
【2】Solving Multiobjective Optimization Problems Using Artificial Bee Colony Algorithm










算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复

使用道具 举报

0

主题

8

帖子

24

金钱

新手上路

Rank: 1

积分
32
发表于 2019-4-23 23:34:15 | 显示全部楼层
感谢楼主,学习学习
回复 支持 反对

使用道具 举报

0

主题

22

帖子

1

金钱

新手上路

Rank: 1

积分
23
发表于 2020-2-11 10:06:17 | 显示全部楼层
非常好的学习资源,感谢分享
回复 支持 反对

使用道具 举报

0

主题

22

帖子

1

金钱

新手上路

Rank: 1

积分
23
发表于 2020-2-13 02:13:28 | 显示全部楼层
机器码:FF48E712CD53F57C-0-FF48C202D90BF17C
回复 支持 反对

使用道具 举报

0

主题

3

帖子

24

金钱

新手上路

Rank: 1

积分
27
发表于 2020-8-11 20:16:31 | 显示全部楼层
期待,学习一下~:lol
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Python|Opencv|MATLAB|Halcom.cn ( 蜀ICP备16027072号 )

GMT+8, 2024-4-19 17:10 , Processed in 0.251510 second(s), 24 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表