请选择 进入手机版 | 继续访问电脑版

Hello Mat

 找回密码
 立即注册
查看: 5973|回复: 4

7-BFO细菌觅食算法的障碍路径寻优Path Planning-三角形障碍

[复制链接]

1278

主题

1504

帖子

90

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22549
发表于 2019-10-8 22:54:08 | 显示全部楼层 |阅读模式
7-BFO细菌觅食算法的障碍路径寻优Path Planning-三角形障碍
链接:https://pan.baidu.com/s/1JlaGt5Ovh_m3FNoVsbOJCg 提取码:ybe9

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

主程序如下:
  1. clc,clear,close all
  2. warning off
  3. format longG
  4. model = CreateModel();
  5. % BFO优化算法 参数
  6. sizepop = 50;              % 种群数量
  7. Nc = 20;                   % 趋化次数
  8. Ns = 4;                    % 游动次数
  9. Nre = 4;                   % 复制次数
  10. Ned = 2;                   % 驱散(迁移)次数
  11. Sr = ceil( sizepop/2 );    % 复制(分裂)次数
  12. Ped = 0.25;                             % 细菌驱散(迁移)概率

  13. nvar = model.n;   % n个未知量
  14. popmin_x = model.xmin; % x
  15. popmax_x = model.xmax; % x
  16. popmin_y = model.ymin; % y
  17. popmax_y = model.ymax; % y

  18. %% 初始化种群
  19. fitnesszbest = inf;
  20. for i=1:sizepop
  21.     pop(i).position = CreateRandomSolution(model); % 初始化个体
  22.     [pop(i).fitness , pop(i).sol]= fun( pop(i).position, model );         % 适应度值
  23.     % 更新个体最优
  24.     pop(i).Best.position = pop(i).position;
  25.     pop(i).Best.fitness = pop(i).fitness;
  26.     pop(i).Best.sol = pop(i).sol;
  27.     if(pop(i).Best.fitness<fitnesszbest)
  28.         fitnesszbest = pop(i).Best.fitness;
  29.         zbest = pop(i).Best;
  30.     end
  31. end
  32. %% 记录一组最优值
  33. NcSizepop = 0;            % 记录最优适应度值(函数值)
  34. %% 迭代寻优
  35. for i = 1:Ned                   % 驱散(迁移)次数
  36.     for k = 1:Nre               % 复制次数
  37.         
  38.         for m = 1:Nc            % 趋化次数
  39.             for j=1:sizepop     % 种群
  40.                
  41.                 % 翻转x
  42.                 delta = 2*rand(nvar, 1)-0.5;
  43.                 PHI = delta./(sqrt( delta'*delta ));
  44.                 C = 0.5*rand(nvar, 1);
  45.                 popnew.position.x = pop(j).position.x + C'.*PHI';
  46.                 % 取值范围约束
  47.                 popnew.position.x = max( popnew.position.x, popmin_x );
  48.                 popnew.position.x = min( popnew.position.x, popmax_x );
  49.                
  50.                 % 翻转y
  51.                 delta = 2*rand(nvar, 1)-0.5;
  52.                 PHI = delta./(sqrt( delta'*delta ));
  53.                 C = 0.5*rand(nvar, 1);
  54.                 popnew.position.y = pop(j).position.y + C'.*PHI';
  55.                 % 取值范围约束
  56.                 popnew.position.y = max( popnew.position.y, popmin_y );
  57.                 popnew.position.y = min( popnew.position.y, popmax_y );
  58.                
  59.                 % 更新当前适应度值?
  60.                 [popnew.fitness , popnew.sol]= fun( popnew.position, model );         % 适应度值
  61.    
  62.                 if popnew.fitness<pop(j).fitness
  63.                     pop(j).fitness = popnew.fitness;
  64.                     pop(j).position = popnew.position;
  65.                     pop(j).sol = popnew.sol;
  66.                 end
  67.                 if pop(j).fitness<pop(j).Best.fitness
  68.                     pop(j).Best.fitness = pop(j).fitness;
  69.                     pop(j).Best.position = pop(j).position;
  70.                     pop(j).Best.sol = pop(j).sol;
  71.                 end
  72.                 if(pop(j).Best.fitness<fitnesszbest)
  73.                     fitnesszbest = pop(j).Best.fitness;
  74.                     zbest = pop(j).Best;
  75.                 end
  76.                
  77.             end   % sizepop  种群数量
  78.             
  79.             % 记录最优适应度值
  80.             NcSizepop = NcSizepop+1;
  81.             fitness_iter(NcSizepop) = fitnesszbest;
  82.             
  83.             figure(1)
  84.             PlotSolution(zbest.sol, model)
  85.             pause(0.1)
  86.         end       % Nc       趋化次数
  87.         
  88.         % 复制操作
  89.         [maxF,index] = sort([pop.fitness],'descend');  % 降序排列
  90.         for Nre2 = 1:Sr   % 将最大适应度值的Sr个种群,进行更新
  91.             pop(index(Nre2)).position = CreateRandomSolution(model); % 初始化个体
  92.             [pop(index(Nre2)).fitness , pop(index(Nre2)).sol]= fun( pop(index(Nre2)).position, model );         % 适应度值
  93.             % 比较 个体间比较
  94.             if pop(index(Nre2)).fitness<fitnesszbest
  95.                 fitnesszbest = pop(index(Nre2)).fitness;
  96.                 zbest =  pop(index(Nre2)).Best;
  97.             end
  98.         end
  99.     end   % Nre  复制操作
  100.    
  101.     for j=1:sizepop     % 种群
  102.         if Ped>rand
  103.             pop(j).position = CreateRandomSolution(model); % 初始化个体
  104.             [pop(j).fitness , pop(j).sol]= fun( pop(j).position, model );         % 适应度值
  105.             % 比较 个体间比较
  106.             if pop(j).fitness<fitnesszbest
  107.                 fitnesszbest = pop(j).fitness;
  108.                 zbest =  pop(j).Best;
  109.             end
  110.         end
  111.     end
  112.    
  113. end       % Ned   驱散(迁移)次数

  114. disp('最优解')
  115. disp(zbest)
  116. fprintf('\n')

  117. figure('color',[1,1,1])
  118. plot(fitness_iter,'ro-','linewidth',2)
  119. xlabel('迭代次数'); ylabel('适应度曲线');
  120. axis tight
  121. grid on


  122. figure(1)
  123. PlotSolution(zbest.sol, model)
  124. pause(0.1)
复制代码
参考:
【1】结果动态图
【2】子函数参考链接
【3】细菌觅食算法BFO函数优化












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

使用道具 举报

0

主题

13

帖子

1

金钱

新手上路

Rank: 1

积分
14
发表于 2019-11-10 20:32:34 | 显示全部楼层
大神,请问如果把种群之间的影响值加上改怎么编写。我现在在学BFO算法的路径规划。
回复 支持 反对

使用道具 举报

0

主题

13

帖子

1

金钱

新手上路

Rank: 1

积分
14
发表于 2019-11-12 10:36:16 | 显示全部楼层
请问大神如果加上细菌之间的影响以后该怎么编写。我现在也在学习细菌觅食算法的路径规划问题。
回复 支持 反对

使用道具 举报

0

主题

13

帖子

1

金钱

新手上路

Rank: 1

积分
14
发表于 2019-11-12 10:37:01 | 显示全部楼层
大神请问加上细菌之间的影响以后该怎么编写。
回复 支持 反对

使用道具 举报

0

主题

13

帖子

1

金钱

新手上路

Rank: 1

积分
14
发表于 2019-11-12 10:38:10 | 显示全部楼层
大神请问加上细菌之间的影响该怎么编写。
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-3-29 00:16 , Processed in 0.218001 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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