9-PSO粒子群算法的障碍路径寻优Path Planning-三角形障碍
9-PSO粒子群算法的障碍路径寻优Path Planning-三角形障碍链接:https://pan.baidu.com/s/1IZ_On5XWVkKIHGrNbQ8H5Q 提取码:33td
具体链接在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)
参考:
【1】结果动态图
【2】子函数参考链接
【3】粒子群算法PSO视频讲解
【4】基于PSO的火车票分配问题:链接:http://pan.baidu.com/s/1nvRYrg9 密码:bfua
【5】基于PSO的机器人路径优化问题:链接:http://pan.baidu.com/s/1jI0uNlk
【6】PSO_source_error_NRMSE_惯性因子gbest,改进的PSO算法结构体化编程
页:
[1]