Halcom 发表于 2019-10-8 23:05:51

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

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

主程序如下:
clc,clear,close all
warning off
% 初始化种群
model = CreateModel();
% PSO 参数
c1 = 1.4995;
c2 = 1.4995;
Vmin = -1;
Vmax = 1;
w = 1;         % 权重
wdamp = 0.98;% 阻尼
maxiter = 50;% 迭代次数
sizepop = 20;% 种群数量

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

init_pop.position = [];% 位置信息
init_pop.Velocity = [];% 速度信息
init_pop.fitness = [];   % 适应度值信息
init_pop.sol = [];       % 解集信息
init_pop.Best.position = [];% 个体最优 位置信息
init_pop.Best.fitness = [];   % 个体最优 适应度值信息
init_pop.Best.sol = [];       % 个体最优 解集信息
% 粒子群
pop = repmat(init_pop, sizepop, 1);
clear init_pop

%% 初始化种群
fitnesszbest = inf;
for i=1:sizepop
    pop(i).position = CreateRandomSolution(model); % 初始化个体
    = fun( pop(i).position, model );         % 适应度值
    pop(i).Velocity.x = zeros(1, nvar);
    pop(i).Velocity.y = zeros(1, nvar);
    % 更新个体最优
    pop(i).Best.position = pop(i).position;
    pop(i).Best.fitness = pop(i).fitness;
    pop(i).Best.sol = pop(i).sol;
    if(pop(i).Best.fitness<fitnesszbest)
      fitnesszbest = pop(i).Best.fitness;
      zbest = pop(i).Best;
    end
end

%% 迭代寻优
for i=1:maxiter
    for j=1:sizepop
      % 横坐标的操作
      pop(j).Velocity.x = w*pop(j).Velocity.x + c1*rand(1,nvar).*(pop(j).Best.position.x-pop(j).position.x) ...
                            + c2*rand(1,nvar).*(zbest.position.x-pop(j).position.x);
      % 速度取值范围
      pop(j).Velocity.x = max(pop(j).Velocity.x, Vmin);
      pop(j).Velocity.x = min(pop(j).Velocity.x, Vmax);
      % 横坐标更新
      pop(j).position.x = pop(j).position.x + pop(j).Velocity.x;
      % 横坐标取值范围
      pop(j).position.x = max(pop(j).position.x, popmin_x);
      pop(j).position.x = min(pop(j).position.x, popmax_x);
      
      % 纵坐标的操作
      pop(j).Velocity.y = w*pop(j).Velocity.y + c1*rand(1,nvar).*(pop(j).Best.position.y-pop(j).position.y) ...
                            + c2*rand(1,nvar).*(zbest.position.y-pop(j).position.y);
      % 速度取值范围
      pop(j).Velocity.y = max(pop(j).Velocity.y, Vmin);
      pop(j).Velocity.y = min(pop(j).Velocity.y, Vmax);
      % 纵坐标更新
      pop(j).position.y = pop(j).position.y + pop(j).Velocity.y;
      % 纵坐标取值范围
      pop(j).position.y = max(pop(j).position.y, popmin_y);
      pop(j).position.y = min(pop(j).position.y, popmax_y);
      
      = fun( pop(j).position, model );         % 适应度值
      
      if pop(j).fitness<pop(j).Best.fitness
            pop(j).Best.fitness = pop(j).fitness;
            pop(j).Best.position = pop(j).position;
            pop(j).Best.sol = pop(j).sol;
      end
      if(pop(j).Best.fitness<fitnesszbest)
            fitnesszbest = pop(j).Best.fitness;
            zbest = pop(j).Best;
      end
      
      w = w * wdamp;
    end
    fitness_iter(i) = fitnesszbest;
   
    figure(1)
    PlotSolution(zbest.sol,model)
    pause(0.1)
end

%% 最后的显示部分
disp('最优解')
disp(zbest)
fprintf('\n')

figure('color',)
plot(fitness_iter,'ro-','linewidth',2)
xlabel('迭代次数'); ylabel('适应度曲线');
axis tight
grid on

figure(1)
PlotSolution(zbest.sol,model)
pause(0.1)CreateModel如下:**** Hidden Message *****



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











wasd789 发表于 2019-11-13 19:42:33

666666666666666666666666好

siyecao1996 发表于 2020-1-12 16:42:26

很好的代码

weki 发表于 2020-2-1 20:11:18

学习路径规划中,谢谢楼主

az460 发表于 2020-2-23 10:52:06

666666666666学习一下

Reborn 发表于 2020-2-26 09:52:30

楼主威武,毕业设计刚好用到

king_wei 发表于 2020-5-24 13:57:45

求求求QQQQQQQQQQ

wal1985 发表于 2020-5-26 12:01:36

非常好的代码

lima 发表于 2020-5-27 19:03:53

hello,看一下代码

yy520 发表于 2020-5-30 21:06:48

sadasdasdasdasdd
页: [1] 2
查看完整版本: 10-PSO粒子群算法的障碍路径寻优Path Planning-圆形障碍