资源简介
A*算法 最短路径 万能通用 matlab代码
代码片段和文件信息
function astardemo
%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
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)]
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 10766 2013-07-05 14:08 astarfirst.m
文件 1330 2011-02-21 08:47 license.txt
文件 5351 2010-02-17 04:55 pewee-ahh.wav
文件 4830 2010-02-17 04:55 wee.wav
文件 11147 2012-12-04 13:44 astardemo.m
- 上一篇:蚁群算法最短路径万能matlab源代码
- 下一篇:边缘检测的matlab实现代码
相关资源
- 蚁群算法最短路径万能matlab源代码
- MATLAB蚁群算法ACA最短路径-注释完整
- dijkstra算法的MATLAB实现258163
- A*算法航迹规划
- matlab遗传算法求最短路径
- dijkstra算法通用matlab程序
- 移动机器人路径规划 几种A*算法改进
- 基于A*算法的机器人路径规划的MATLA
- A*算法 matlab版
- floyd最短路径算法MATLAB代码
- 复杂网络最短路径matlab
- Floyd最短路径算法
- 基于matlab的双向A*算法
- 蚁群算法求解最短路径问题MATLAB代码
- A*算法 A star 算法matlab
- 遗传算法解决最短路径问题matlab程序
- ksp最短路径删除算法dijstra
- 复杂网络中无向无权图的最短路径m
- 蚁群算法求解TSP最短路径规划
- Floyd算法的完整Matlab程序
- A*算法路径规划的matlab核心代码
- prim算法在matlab中的代码
- 蚁群算法的最短路径MATLAB程序
- A*算法 路径规划MATLAB代码
- A*搜索算法matlab实现GUI
- dijkstra的matlab代码
- 路径规划A*算法matlab
- 蚁群算法最短路径通用Matlab程序
- 求平均最短路径长度的matlab编程代码
- Dijkstra算法MATLAB代码
评论
共有 条评论