当前位置: 首页 > news >正文

【路径规划】基于A星算法和改进A星算法求解路径规划问题matlab代码

1 简介

一种基于A星算法的最短寻路方法.其包括将搜索区域划分为多个网格并将起点放入开启列表中,搜索起点所在网格相邻的网格并计算相邻的网格点与目标点的距离,采用A星算法计算从初始状态到目标状态的代价估计,通过判断起点至目标点各路径对应代价估计值是否为最小值寻找新起点,再通过判断新的起点是否为目标点完成寻路.

2 部分代码

%************************************************************************

%**************************************************************************

close all;

%**************************************************************************

%**************** Choose System Architecture ***************************

%**************************************************************************

% Here you can choose the hardware architecture implementation

% 1 . Single Robot mode

% 2 . Dual Robot Single Computer

% 3 . Dual Roboto Dual Computer

% 4 . Multi Robot Single Computer

% 5 . Multi Robot Ethernet Based

disp(' Generating Grid ... ');

co=or;

crn=s;

noOfNodes = nooc*noor;

nodmat=ones(nooc,noor,3);

nodmat(1:noOfNodes)=1:noOfNodes;

nodmat(:,:,2)=(find(nodmat(:,2,2)==1))*ones(1,noor);

nodmat(:,:,3)=ones(nooc,1)*(find(nodmat(2,:,3)==1));

nodmat(:,:,1)=flipdim((nodmat(:,:,1)),2);

nodmat(:,:,2)=flipdim((nodmat(:,:,2)),2);

nodmat(:,:,3)=flipdim((nodmat(:,:,3)),2);

noddata=reshape(nodmat,noOfNodes,3);

%rand('state', 0);

if plot_flag==1

scrsz = get(0,'ScreenSize');

h=figure(gcf);

set(h,'Position',[scrsz(3)/8 scrsz(4)/8 scrsz(3)-2*scrsz(3)/8 ...

scrsz(4)-2*scrsz(4)/8]);

clf;

hold on;

end

Astar_coor=noddata(:,2:3)*GTS;

netXloc = Astar_coor(:,1)';

netYloc = Astar_coor(:,2)';

axis([min(netXloc)-20 max(netXloc)+30 min(netYloc)-20 max(netYloc)+30])

Astar_connect = zeros(noOfNodes, noOfNodes);

Astar_coord = zeros(noOfNodes, 2);

for i = 1:noOfNodes

Astar_coord(i,1) = netXloc(i);

Astar_coord(i,2) = netYloc(i);

for j = 1:noOfNodes

distance = sqrt((netXloc(i) - netXloc(j))^2 + (netYloc(i) - netYloc(j))^2);

ll=isempty(find(o==i, 1));

lm=isempty(find(o==j, 1));

if (distance <= R && ll==1 && lm==1)

matrix(i, j) = distance; % if set to '1', Dijkstra computes Spath in terms of hops; if set to 'distance', it is the real shortest path

if i~=j % must be satisfied

Astar_connect(i, j) = 1;

else

Astar_connect(i, j) = 0;

end

if plot_flag==1

line([netXloc(i) netXloc(j)], [netYloc(i) netYloc(j)], 'color',[.65 .65 .65],'LineStyle', ':');

end

else

matrix(i, j) = inf;

Astar_connect(i, j) = 0;

end;

end;

end

for i = 1:noOfNodes

if plot_nodenum

text(netXloc(i)+20, netYloc(i), num2str(i));

end

if plot_flag==1

if i==s

plot(netXloc(i), netYloc(i),'square','MarkerSize',12,'MarkerFaceColor','g');

hold on;

end

if i==d

plot(netXloc(i), netYloc(i),'square','MarkerSize',12,'MarkerFaceColor','r');

end

if isempty(find(o==i))

plot(netXloc(i), netYloc(i),'.');

end

end

end;

% activeNodes = [];

% for i = 1:noOfNodes,

% % initialize the farthest node to be itself;

% farthestPreviousHop(i) = i; % used to compute the RTS/CTS range;

% farthestNextHop(i) = i;

% end;

Astar_coord=Astar_coord';

%Astar_connect;

%%

disp('Generating Paths ... ')

%[path, totalCost, farthestPreviousHop, farthestNextHop] = dijkstra(noOfNodes, matrix, s, d, farthestPreviousHop, farthestNextHop);

% combo = [noOfNodes s-1 d-1 R/2];

%[Astar_path, Astar_search] = Astar(Astar_coord', Astar_connect, combo); % notice, we must put Astar_coord' rather than Astar_coord

%[Astar_paths,cost_astar,astar_time] = Astarm(Astar_coord, Astar_connect, s , d);

%[Astar_path,Astar_search]=Astar(Astar_coord, Astar_connect, combo);

[Astar_path,cost_astar,astar_time,Astar_dist] =komegaA(Astar_coord, Astar_connect, s, d, 1, inf, 0);

[komega_path,cost_komega,ko_time,komega_dist]=komegaA(Astar_coord, Astar_connect, s, d, k , b, n);

%%

if disp_summary==1

Astar_path, komega_path,cost_astar,cost_komega,astar_time,ko_time, Astar_dist, komega_dist

end

if ~isempty(Astar_path)

for i = 1:(length(Astar_path)-1)

if plot_flag==1

astr=line([netXloc(Astar_path(i)) netXloc(Astar_path(i+1))], [netYloc(Astar_path(i)) netYloc(Astar_path(i+1))], 'Color','r','LineWidth', 2, 'LineStyle', '-.');

if plot_nodenum==1

text(netXloc(i), netYloc(i), num2str(i));

end

end

end;

end;

if ~isempty(komega_path)

for i = 1:(length(komega_path)-1)

if plot_flag==1

kom=line([netXloc(komega_path(i)) netXloc(komega_path(i+1))], [netYloc(komega_path(i)) netYloc(komega_path(i+1))], 'Color','g','LineWidth', 2, 'LineStyle', '-');

if plot_nodenum==1

text(netXloc(i), netYloc(i), num2str(i));

end

end

end;

end;

rest=title('Comparison Between A-Star and K-Omega');

set(rest,'Interpreter','latex');

dkstr=strcat('K-Omega(k=',num2str(k),' b=',num2str(b),' n=',num2str(n),')');

kleg=legend([astr kom],'A-Star',dkstr);hold on;

set(kleg,'Interpreter','latex');

if plot_flag == 1

hold off;

end

% Execute if K-Omega has not yet executed harware

if (n==0)

[done]=execnxt(komega_path);

end

% If Analysis mode requested, perform analysis

if AnalysisMode==1

AnalyzeKO;

end

3 仿真结果

4 参考文献

[1]邓顺平, 张艳军, & 刘会平. (2014). 一种基于威胁势场的a星路径规划算法. 科技视界(3), 2.

http://www.jsqmd.com/news/1387403/

相关文章:

  • 成都php网站建设如何选择靠谱的开发团队与构建高效稳定系统的深度避坑指南
  • 上海网站建设哪家便宜且靠谱?揭秘行业底价与避坑指南,老板必看!
  • 2026年温州泰顺县GEO服务商代理加盟靠谱推荐:本地创业者选型指南与避坑要点 - 小随科技
  • 2026 年儋州注册公司哪家流程办理快?3 家正规机构联系方式与时效汇总 - 米諾
  • B站缓存视频怎么转MP4?这个免费工具几分钟无损搞定
  • 安庆市大观区OEM白标贴牌GEO服务商怎么选?2026年靠谱推荐与选择指南 - 企业新闻快传
  • 域名空间网站建设全流程深度解析:从注册到上线的避坑指南
  • 如何轻松备份微信聊天记录并生成年度报告:WeChatMsg完整指南
  • 合肥肥西县OEM白标贴牌GEO服务商怎么选?2026年靠谱推荐与选型指南 - 企业新闻快传
  • 微信聊天记录永久保存:你的数字记忆保险箱
  • 2026福州台江区楼顶漏水避坑指南,本地老牌公司,质保可查 - 专业防水施工
  • 2026绍兴诸暨市楼顶漏水避坑指南,本地老牌公司,质保可查 - 专业防水施工
  • Web 爬虫与安全:反爬绕过与安全采集边界
  • 2026合肥蜀山区楼顶漏水避坑指南,本地老牌公司,质保可查 - 专业防水施工
  • mac 反编译/拆包/逆向apk记录
  • ubuntu下boa服务器编译运行
  • 揭秘长春网站建设phpjz背后的技术逻辑与本地化服务深度解析
  • 消息刚发出就被撤回?RevokeMsgPatcher 微信/QQ/TIM 防撤回补丁完整指南
  • 上海嘉定网站建设:从0到1的实战避坑指南,老板必看的企业数字化转型之路
  • 宣城市泾县OEM白标贴牌GEO服务商怎么选?2026年本地企业靠谱推荐与选型指南 - 子柔传媒
  • 2026福州仓山区楼顶漏水避坑指南,本地老牌公司,质保可查 - 专业防水施工
  • vue中使用腾讯API地图,实现搜索关键词获取经纬度和地址并显示地图
  • 池州市石台县OEM白标贴牌GEO服务商怎么选?2026年靠谱推荐与选择指南 - 科技快讯
  • 从零开始的单元测试:csharp_with_csharpfritz教你构建可靠C代码
  • 2026年合肥市包河区GEO服务商代理加盟本地靠谱推荐:城市合伙人模式解析 - 企业新闻快传
  • lamp-boot表单校验前后端统一验证:提升数据安全性的关键步骤
  • 济南网站建设工作室如何选择靠谱团队避坑指南与实战经验全解析
  • Windows微信QQ防撤回神器:3分钟永久保留重要消息
  • 搞笑视频瞬间变表情包!2026免费GIF制作完整攻略,两种主流工具保姆级教程 - 时时资讯
  • 【路径规划】基于遗传算法结合粒子群算法求解TSP问题matlab代码