资源简介
用A*算法进行二维路径规划,即AStar算法, matlab程序,可以直接运行
代码片段和文件信息
function astardemo_Hong
%ASTARDEMO Demonstration of ASTAR algorithm
%
% Copyright Bob L. Sturm Ph. D. Assistant Professor
% Department of Architecture Design and Media Technology
% formerly Medialogy
% Aalborg University i Ballerup
% formerly Aalborg University Copenhagen
% $Revision: 0.1 $ $Date: 2011 Jan. 15 18h24:24$
n = 20; % field size n x n tiles 20*20的界面
wallpercent = 0.15; % this percent of field is walls 45%的界面作为阻碍物(墙)
% create the n x n FIELD with wallpercent walls containing movement costs
% a starting position STARTPOSIND a goal position GOALPOSIND the costs
% A star will compute movement cost for each tile COSTCHART
% and a matrix in which to store the pointers FIELDPOINTERS
[field startposind goalposind costchart fieldpointers] = ...
initializeField(nwallpercent); %初始化界面
% initialize the OPEN and CLOSED sets and their costs
setOpen = [startposind]; setOpenCosts = [0]; setOpenHeuristics = [Inf];
setClosed = []; setClosedCosts = [];
movementdirections = {‘R‘‘L‘‘D‘‘U‘‘DR‘‘DL‘‘UR‘‘UL‘};
% keep track of the number of iterations to exit gracefully if no solution
counterIterations = 1;
% create figure so we can witness the magic
axishandle = createFigure(fieldcostchartstartposindgoalposind);
% as long as we have not found the goal or run out of spaces to explore
while ~max(ismember(setOpengoalposind)) && ~isempty(setOpen) %ismember(AB)返回与A同大小的矩阵,其中元素1表示A中相应位置的元素在B中也出现,0则是没有出现
% for the element in OPEN with the smallest cost
[temp ii] = min(setOpenCosts + setOpenHeuristics); %从OPEN表中选择花费最低的点tempii是其下标(也就是标号索引)
% find costs and heuristic of moving to neighbor spaces to goal
% in order ‘R‘‘L‘‘D‘‘U‘
[costsheuristicsposinds] = findFValue(setOpen(ii)setOpenCosts(ii) ...
fieldgoalposind‘euclidean‘); %扩展temp的四个方向点,获得其坐标posinds,各个方向点的实际代价costs,启发代价heuristics
% put node in CLOSED and record its cost
setClosed = [setClosed; setOpen(ii)]; %将temp插入CLOSE表中
setClosedCosts = [setClosedCosts; setOpenCosts(ii)]; %将temp的花费计入ClosedCosts
% update OPEN and their associated costs 更新OPEN表 分为三种情况
if (ii > 1 && ii < length(setOpen)) %temp在OPEN表的中间,删除temp
setOpen = [setOpen(1:ii-1); setOpen(ii+1:end)];
setOpenCosts = [setOpenCosts(1:ii-1); setOpenCosts(ii+1:end)];
setOpenHeuristics = [setOpenHeuristics(1:ii-1); setOpenHeuristics(ii+1:end)];
elseif (ii == 1)
setOpen = setOpen(2:end); %temp是OPEN表的第一个元素,删除temp
setOpenCosts = setOpenCosts(2:end);
setOpenHeuristics = setOpenHeuristics(2:end);
else %temp是OPEN表的最后一个元素,删除temp
setOpen = setOpen(1:end-1);
setOpenCosts = setOpenCosts(1:end-1);
setOpenHeuristics = setOpenHeuristics(1:end-1);
end
% for each of these neighbor spaces assign costs and pointers;
% and if some are in the CLOSED set and their costs are smaller
% update their costs and pointers
for jj=1:length(posinds) %对于扩展的四个方向的坐标
- 上一篇:图像拼接程序
- 下一篇:基于直方图双峰特性的图像分割Matlab代码
相关资源
- 清洁机器人路径规划matlab仿真程序
- 基于遗传算法的机器人路径规划matl
- 单机器人的多任务路径规划GUI
- 针对栅格路径规划的蚁群算法MATLAB
- 蚁群算法实现三维路径规划Matlab源码
- 路径规划算法MATLAB仿真合集
- 三种不同路径规划的仿真
- 基于栅格地图的蚁群算法路径规划
- 基于智能优化的机器人路径规划matl
- 自主移动机器人路径规划新方法含m
- 多机器人路径规划-matlab
- 多机器人路径及避障规划——Matlab
- 路径规划MATLAB版代码
- 基于matlab的机器人最优路径规划仿真
- 基于栅格地图的A-星算法路径规划
- 基于栅格地图的A星算法路径规划
- A*路径规划算法
- 多种蚁群算法在机器人路径规划中的
- 基于A-Star算法的机器人路径规划.rar
- 路径规划算法Matlab仿真更新
- 路径规划随机地图建立MATLAB源码
- RRT、RRT-Connect、LazyRRT、RRTextend、RRT*的
- 蚁群算法进行二维路径规划.zip
- 粒子群算法应用在路径规划matlab
- 蚁群算法路径规划避障MATLAB源程序
- 蚁群算法无人机路径规划
- A星算法的路径规划MATLAB实现
- 蚁群算法算法的路径规划MATLAB实现
- path-planning 路径规划d*算法
- path-planning 路径规划RRT算法
评论
共有 条评论