资源简介
A*算法,动态路径规划算法的一种,程序直接放到matlab即可运行。
代码片段和文件信息
function astardemo
%ASTARDEMO Demonstration of ASTAR algorithm
n = 20; % field size n x n tiles
wallpercent = 0.45; % this percent of field is walls
% 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‘};
% 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)
% for the element in OPEN with the smallest cost
[temp ii] = min(setOpenCosts + setOpenHeuristics);
% 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‘);
% put node in CLOSED and record its cost
setClosed = [setClosed; setOpen(ii)];
setClosedCosts = [setClosedCosts; setOpenCosts(ii)];
% update OPEN and their associated costs
if (ii > 1 && ii < length(setOpen))
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);
setOpenCosts = setOpenCosts(2:end);
setOpenHeuristics = setOpenHeuristics(2:end);
else
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)
% if cost infinite then it‘s a wall so ignore
if ~isinf(costs(jj))
% if node is not in OPEN or CLOSED then insert into costchart and
% movement pointers and put node in OPEN
if ~max([setClosed; setOpen] == posinds(jj))
fieldpointers(posinds(jj)) = movementdirections(jj);
costchart(posinds(jj)) = costs(jj);
setOpen = [setOpen; posinds(jj)];
setOpenCosts = [setOpenCosts; costs(jj)];
setOpenHeuristics = [setOpenHeuristics; heuristics(jj)];
% else node has already been seen so check to see if we have
% found a better route to it.
elseif max(setOpen == posinds(jj))
I = find(setOpen == posinds(jj));
% update if
- 上一篇:异步电机的各种仿真模型
- 下一篇:SRM直接转矩MATLAB仿真
相关资源
- SRM直接转矩MATLAB仿真
- 交通灯的识别——自然场景中
- 基于matlab遗传算法的微网运行优化
- IQ调制MATLAB程序
- 虹膜定位详尽的虹膜识别matlab源代码
- 基于对偶四元数航天器姿轨耦合一体
- PLSmatlab工具包讲解
- 基于形态学滤波去噪matlab代码
- 图像超分辨重建matlab代码
- 基于MATLABGUI实现图像阈值分割处理的
- RSSI定位 MATLAB
- Ncut图像分割算法MATLAB实现
- magnify用于matlab的放大插件
- matlab-快速搜索随机树算法实现RRT
- PID参数整定的临界比例度法的实现
- 基于MATLAB的分数阶负反馈控制系统的
- matlab编程100篇
- RRT* RRT star RRT 星路径规划算法的matl
- SVPWM整流器逆变器matlab仿真
- fm调制解调系统matlab仿真
- matlab 2012b crack
- Matlab_WebRTC_回声消除_fullaec
- matlab2011a 破解文件
- 三个参与主体演化博弈matlab.docx
- 支持向量机用于肌电信号模式识别的
- 数字信号处理实验MATLAB版的
- NSST(非下采样剪切波变换)matlab工具
- DFS优先算法matlab实现
- 多径信道下 简单OFDM matlab仿真
- FastSLAMmatlab仿真算法
评论
共有 条评论