Hello Mat

 找回密码
 立即注册
查看: 19818|回复: 19

10-PSO粒子群算法的障碍路径寻优Path Planning-圆形障碍

[复制链接]

1294

主题

1520

帖子

110

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22633
发表于 2019-10-8 23:05:51 | 显示全部楼层 |阅读模式
10-PSO粒子群算法的障碍路径寻优Path Planning-圆形障碍
链接:https://pan.baidu.com/s/1oH9bCvym0inHc0RGrEXS6Q 提取码:yl3v

具体链接在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. % 初始化种群
  4. model = CreateModel();
  5. % PSO 参数
  6. c1 = 1.4995;  
  7. c2 = 1.4995;
  8. Vmin = -1;
  9. Vmax = 1;
  10. w = 1;         % 权重
  11. wdamp = 0.98;  % 阻尼
  12. maxiter = 50;  % 迭代次数
  13. sizepop = 20;  % 种群数量

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

  19. init_pop.position = [];  % 位置信息
  20. init_pop.Velocity = [];  % 速度信息
  21. init_pop.fitness = [];   % 适应度值信息
  22. init_pop.sol = [];       % 解集信息
  23. init_pop.Best.position = [];  % 个体最优 位置信息
  24. init_pop.Best.fitness = [];   % 个体最优 适应度值信息
  25. init_pop.Best.sol = [];       % 个体最优 解集信息
  26. % 粒子群
  27. pop = repmat(init_pop, sizepop, 1);
  28. clear init_pop

  29. %% 初始化种群
  30. fitnesszbest = inf;
  31. for i=1:sizepop
  32.     pop(i).position = CreateRandomSolution(model); % 初始化个体
  33.     [pop(i).fitness , pop(i).sol]= fun( pop(i).position, model );         % 适应度值
  34.     pop(i).Velocity.x = zeros(1, nvar);
  35.     pop(i).Velocity.y = zeros(1, nvar);
  36.     % 更新个体最优
  37.     pop(i).Best.position = pop(i).position;
  38.     pop(i).Best.fitness = pop(i).fitness;
  39.     pop(i).Best.sol = pop(i).sol;
  40.     if(pop(i).Best.fitness<fitnesszbest)
  41.         fitnesszbest = pop(i).Best.fitness;
  42.         zbest = pop(i).Best;
  43.     end
  44. end

  45. %% 迭代寻优
  46. for i=1:maxiter
  47.     for j=1:sizepop
  48.         % 横坐标的操作
  49.         pop(j).Velocity.x = w*pop(j).Velocity.x + c1*rand(1,nvar).*(pop(j).Best.position.x-pop(j).position.x) ...
  50.                             + c2*rand(1,nvar).*(zbest.position.x-pop(j).position.x);
  51.         % 速度取值范围
  52.         pop(j).Velocity.x = max(pop(j).Velocity.x, Vmin);
  53.         pop(j).Velocity.x = min(pop(j).Velocity.x, Vmax);  
  54.         % 横坐标更新
  55.         pop(j).position.x = pop(j).position.x + pop(j).Velocity.x;
  56.         % 横坐标取值范围
  57.         pop(j).position.x = max(pop(j).position.x, popmin_x);
  58.         pop(j).position.x = min(pop(j).position.x, popmax_x);
  59.         
  60.         % 纵坐标的操作
  61.         pop(j).Velocity.y = w*pop(j).Velocity.y + c1*rand(1,nvar).*(pop(j).Best.position.y-pop(j).position.y) ...
  62.                             + c2*rand(1,nvar).*(zbest.position.y-pop(j).position.y);
  63.         % 速度取值范围
  64.         pop(j).Velocity.y = max(pop(j).Velocity.y, Vmin);
  65.         pop(j).Velocity.y = min(pop(j).Velocity.y, Vmax);  
  66.         % 纵坐标更新
  67.         pop(j).position.y = pop(j).position.y + pop(j).Velocity.y;
  68.         % 纵坐标取值范围
  69.         pop(j).position.y = max(pop(j).position.y, popmin_y);
  70.         pop(j).position.y = min(pop(j).position.y, popmax_y);
  71.         
  72.         [pop(j).fitness , pop(j).sol]= fun( pop(j).position, model );         % 适应度值
  73.         
  74.         if pop(j).fitness<pop(j).Best.fitness
  75.             pop(j).Best.fitness = pop(j).fitness;
  76.             pop(j).Best.position = pop(j).position;
  77.             pop(j).Best.sol = pop(j).sol;
  78.         end
  79.         if(pop(j).Best.fitness<fitnesszbest)
  80.             fitnesszbest = pop(j).Best.fitness;
  81.             zbest = pop(j).Best;
  82.         end
  83.         
  84.         w = w * wdamp;
  85.     end
  86.     fitness_iter(i) = fitnesszbest;
  87.    
  88.     figure(1)
  89.     PlotSolution(zbest.sol,model)
  90.     pause(0.1)
  91. end

  92. %% 最后的显示部分
  93. disp('最优解')
  94. disp(zbest)
  95. fprintf('\n')

  96. figure('color',[1,1,1])
  97. plot(fitness_iter,'ro-','linewidth',2)
  98. xlabel('迭代次数'); ylabel('适应度曲线');
  99. axis tight
  100. grid on

  101. figure(1)
  102. PlotSolution(zbest.sol,model)
  103. pause(0.1)
复制代码
CreateModel如下:
游客,如果您要查看本帖隐藏内容请回复




参考:
【1】结果动态图
【2】子函数参考链接
【3】粒子群算法PSO视频讲解
【4】改进的粒子群算法
【5】多目标粒子群算法











本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

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

使用道具 举报

0

主题

13

帖子

1

金钱

新手上路

Rank: 1

积分
14
发表于 2019-11-13 19:42:33 | 显示全部楼层
666666666666666666666666好
回复 支持 反对

使用道具 举报

0

主题

8

帖子

28

金钱

新手上路

Rank: 1

积分
36
发表于 2020-1-12 16:42:26 | 显示全部楼层
很好的代码
回复 支持 反对

使用道具 举报

0

主题

10

帖子

30

金钱

新手上路

Rank: 1

积分
40
发表于 2020-2-1 20:11:18 | 显示全部楼层
学习路径规划中,谢谢楼主
回复 支持 反对

使用道具 举报

0

主题

6

帖子

1

金钱

新手上路

Rank: 1

积分
10
发表于 2020-2-23 10:52:06 | 显示全部楼层
666666666666学习一下
回复 支持 反对

使用道具 举报

0

主题

3

帖子

7

金钱

新手上路

Rank: 1

积分
10
发表于 2020-2-26 09:52:30 | 显示全部楼层
楼主威武,毕业设计刚好用到
回复 支持 反对

使用道具 举报

1

主题

10

帖子

1

金钱

新手上路

Rank: 1

积分
11
发表于 2020-5-24 13:57:45 | 显示全部楼层
求求求QQQQQQQQQQ
回复 支持 反对

使用道具 举报

0

主题

59

帖子

1

金钱

注册会员

Rank: 2

积分
72
发表于 2020-5-26 12:01:36 | 显示全部楼层
非常好的代码
回复 支持 反对

使用道具 举报

0

主题

4

帖子

16

金钱

新手上路

Rank: 1

积分
20
发表于 2020-5-27 19:03:53 | 显示全部楼层
hello,看一下代码
回复 支持 反对

使用道具 举报

0

主题

1

帖子

6

金钱

新手上路

Rank: 1

积分
7
发表于 2020-5-30 21:06:48 | 显示全部楼层
sadasdasdasdasdd
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-19 14:01 , Processed in 0.237697 second(s), 25 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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