当前位置:   article > 正文

五大经典智能算法实现机器人路径规划,包含简单路径与复杂路径,详细对比实验..._机器人路径规划算法有哪些

机器人路径规划算法有哪些

本期文章采用五大经典的智能优化算法,对机器人路径进行规划。

五大经典算法分别是:粒子群算法(PSO),遗传算法(GA),差分进化算法(DE),灰狼优化算法(GWO),麻雀优化算法(SSA)。

学会这五种算法后,其他任何智能优化算法可以随意替换!地图也是可以随意更改!

参考一些论文,还可以将改进的智能算法用于机器人路径规划中,突出改进智能算法的优势!

接下来先上结果图:其中,红线表示遗传算法,黄线表示麻雀算法,蓝线表示粒子群算法,绿线表示差分进化算法,青线表示灰狼算法。

简单路径规划结果

8cc065b41b85cfe7b2b3aae242e8c683.gif

04f5b11eca608aca5cc67b60647a8be1.png

b25ebe93abe5f3d649bc4f66ad3a142c.png

复杂路径规划结果

7d655a044e258a675e437c25db164244.gif

470ae8ebbe3cf877b0a0a7e252b33b06.png

370586ae84b2bb78d389949c7fc8dfaf.png

在复杂路径下,其实更能展现一个算法的优劣!因此可以将改进的智能算法用于此模型中,算法替换十分简单!

部分代码展示

  1. clc
  2. clear
  3. close all
  4. tic
  5. %% 地图
  6. G=[0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0;
  7. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
  8. 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0;
  9. 0 0 0 0 0 0 0 1 1 0 0 0 1 0 1 1 1 1 0 0;
  10. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0;
  11. 0 1 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 0 0 0;
  12. 0 1 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0;
  13. 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
  14. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
  15. 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0;
  16. 0 0 0 0 0 0 0 1 1 0 1 1 0 0 1 0 0 0 0 0;
  17. 0 0 0 0 0 0 0 1 1 0 1 1 0 0 1 0 0 0 0 0;
  18. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0;
  19. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0;
  20. 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0;
  21. 1 1 0 1 0 0 1 1 0 0 0 1 0 0 0 0 0 0 0 0;
  22. 0 0 0 0 0 0 1 1 0 1 1 1 0 0 0 0 0 1 1 0;
  23. 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0;
  24. 0 0 0 1 1 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0;
  25. 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0;];
  26. num = size(G,1);
  27. for i=1:num/2
  28. for j=1:num
  29. m=G(i,j);
  30. n=G(num+1-i,j);
  31. G(i,j)=n;
  32. G(num+1-i,j)=m;
  33. end
  34. end
  35. %%
  36. S = [1 1];
  37. E = [num num];
  38. G0 = G;
  39. G = G0(S(1):E(1),S(2):E(2));
  40. [Xmax,dimensions] = size(G); X_min = 1;
  41. dimensions = dimensions - 2;
  42. %% 参数设置
  43. max_gen = 100; % 最大迭代次数
  44. num_polution = 50; % 种群数量
  45. fobj=@(x)fitness(x,G);
  46. [Best_score,Best_pos,GA_curve]=GA(num_polution,max_gen,X_min,Xmax,dimensions,fobj,G);
  47. %结果分析
  48. Best_pos = round(Best_pos);
  49. disp(['GA算法寻优得到的最短路径是:',num2str(Best_score)])
  50. route = [S(1) Best_pos E(1)];
  51. path_GA=generateContinuousRoute(route,G);
  52. path_GA=GenerateSmoothPath(path_GA,G);
  53. path_GA=GenerateSmoothPath(path_GA,G);
  54. [Best_score,Best_pos,SSA_curve]=SSA(num_polution,max_gen,X_min,Xmax,dimensions,fobj,G);
  55. %结果分析
  56. Best_pos = round(Best_pos);
  57. disp(['SSA算法寻优得到的最短路径是:',num2str(Best_score)])
  58. route = [S(1) Best_pos E(1)];
  59. path_SSA=generateContinuousRoute(route,G);
  60. path_SSA=GenerateSmoothPath(path_SSA,G);
  61. path_SSA=GenerateSmoothPath(path_SSA,G);
  62. [Best_score,Best_pos,PSO_curve]=PSO(num_polution,max_gen,X_min,Xmax,dimensions,fobj,G);
  63. %结果分析
  64. Best_pos = round(Best_pos);
  65. disp(['PSO算法寻优得到的最短路径是:',num2str(Best_score)])
  66. route = [S(1) Best_pos E(1)];
  67. path_PSO=generateContinuousRoute(route,G);
  68. path_PSO=GenerateSmoothPath(path_PSO,G);
  69. path_PSO=GenerateSmoothPath(path_PSO,G);
  70. [Best_score,Best_pos,DE_curve]=DE(num_polution,max_gen,X_min,Xmax,dimensions,fobj,G);
  71. %结果分析
  72. Best_pos = round(Best_pos);
  73. disp(['DE算法寻优得到的最短路径是:',num2str(Best_score)])
  74. route = [S(1) Best_pos E(1)];
  75. path_DE=generateContinuousRoute(route,G);
  76. path_DE=GenerateSmoothPath(path_DE,G);
  77. path_DE=GenerateSmoothPath(path_DE,G);
  78. [Best_score,Best_pos,GWO_curve]=GWO(num_polution,max_gen,X_min,Xmax,dimensions,fobj,G);
  79. %结果分析
  80. Best_pos = round(Best_pos);
  81. disp(['GWO算法寻优得到的最短路径是:',num2str(Best_score)])
  82. route = [S(1) Best_pos E(1)];
  83. path_GWO=generateContinuousRoute(route,G);
  84. path_GWO=GenerateSmoothPath(path_GWO,G);
  85. path_GWO=GenerateSmoothPath(path_GWO,G);
  86. %% 画寻优曲线
  87. figure(1)
  88. plot(GA_curve,'k-o')
  89. hold on
  90. plot(SSA_curve,'y-^')
  91. hold on
  92. plot(PSO_curve,'b-*')
  93. hold on
  94. plot(DE_curve,'g-P')
  95. hold on
  96. plot(GWO_curve,'c-v')
  97. legend('GA','SSA','PSO','DE','GWO')
  98. title('简单路径下各算法的收敛曲线')

代码目录

1304bb0f119d067bc102ad76f8e51b07.png

其中simplemain.m是简单路径规划,complexmain.m是复杂路径规划。运行这两个脚本文件即可!

点击下方卡片获取更多代码!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/511716
推荐阅读
相关标签
  

闽ICP备14008679号