资源简介
A*算法 A star 算法(matlab)
代码片段和文件信息
clc
clear all
m = 30;n = 30;
Spoint = [3 3];
Epoint = [29 22];
%%地图
for i = 1:m+2
if i == 1
for j = 1:n+2
Matrix(ij) = -inf;
end
elseif i == m+2
for j = 1:n+2
Matrix(ij) = -inf;
end
else
for j = 1:n+2
if ((j == 1)|(j == n+2))
Matrix(ij) = -inf;
else
Matrix(ij) = inf;
end
end
end
end
%%障碍
for j=2:10
Matrix(5j)=-inf;
for j=2:15
Matrix(24j)=-inf;
for j=9:24
%for j=6:24
Matrix(10j)=-inf;
for j=20:31
Matrix(15j)=-inf;
for j=5:20
Matrix(20j)=-inf;
for j=18:27
Matrix(28j)=-inf;
for i=2:6
Matrix(i18)=-inf;
for i=17:20
Matrix(i5)=-inf;
for i=23:25
Matrix(i20)=-inf;
for i=13:17
Matrix(i13)=-inf;
end
end
end
end
end
end
end
end
end
end
%end
%subplot(221);
h1 = plot(Spoint(1)Spoint(2)‘gO‘);
hold on
h2 = plot(Epoint(1)Epoint(2)‘rO‘);
%%寻路
Matrix(Spoint(1)Spoint(2))=0;
Matrix(Epoint(1)Epoint(2))=inf;
G=Matrix;
F=Matrix;
openlist=Matrix;
closelist=Matrix;
parentx=Matrix;
parenty=Matrix;
openlist(Spoint(1)Spoint(2)) =0;
%closelist(Epoint(1)Epoint(2))=inf;
for i = 1:n+2
for j = 1:m+2
k = Matrix(ij);
if(k == -inf)
%subplot(221);
h3 = plot(ij‘k.‘);
% elseif(k == inf) % show green feasible point
% %subplot(221);
% plot(ij‘gh‘);
% else
% %subplot(221);
% plot(ij‘gh‘);
end
hold on
end
end
axis([0 m+3 0 n+3]);
%subplot(221);
plot(Epoint(1)Epoint(2)‘b+‘);
%subplot(221);
plot(Spoint(1)Spoint(2)‘b+‘);
while(1)
num=inf;
for p=1:m+2
for q=1:n+2
if(openlist(pq)==0&&closelist(pq)~=1)
Outpoint=[pq];
if(F(pq)>=0&&num>F(pq))
num=F(pq);
Nextpoint=[pq];
end
end
end
end
closelist(Nextpoint(1)Nextpoint(2))=1;
for i = 1:3
for j = 1:3
k = G(Nextpoint(1)-2+iNextpoint(2)-2+j);
if(i==2&&j==2|closelist(Nextpoint(1)-2+iNextpoint(2)-2+j)==1)
continue;
elseif (k == -inf)
G(Nextpoint(1)-2+iNextpoint(2)-2+j) = G(Nextpoint(1)-2+iNextpoint(2)-2+j);
closelist(Nextpoint(1)-2+iNextpoint(2)-2+j)=1;
elseif (k == inf)
distance=((i-2)^2+(j-2)^2)^0.5;
G(Nextpoint(1)-2+iNextpoint(2)-2+j)=G(Nextpoint(1)Nextpoint(2))+distance;
openlist(Nextpoint(1)-2+iNextpoint(2)-2+j)=0;
% H=((Nextpoint(1)-2+i-Epoint(1))^2+(Nextpoint(2)-2+j-Epoint(2))^2)^0.5;%欧几里德距离启发函数
H_diagonal=min(abs(Nextpoint(1)-2+i-Epoint(1))abs(Nextpoint(2)-2+j-Epoint(2)));%比较复杂的对角线启发函数
H_strai
- 上一篇:Beale函数matlab程序
- 下一篇:克里金差值matlab程序完整整理版
相关资源
- 克里金差值matlab程序完整整理版
- Beale函数matlab程序
- SAR CS成像算法matlab
- 两挡电动汽车动力性仿真matlab程序.
- 运用遗传算法求解带出入点的车间布
- matlab三维重建程序
- 小波分解与重构的几个matlab程序
- buck boost恒流充电 恒压放电matlab仿真
- CURE算法和Matlab实现
- Matlab 2015b win32软件的baidu云盘地址
- GPS软件接收机MATLAB代码
- matlab实现基于DCT数字水印添加以及提
- rossler混沌同步的MATLAB程序169248
- 三相桥式有源逆变仿真
- 各向异性滤波的matlab程序一维、二维
- 相关干涉仪测向方法matlab仿真.rar
- 先进pid控制matlab仿真(第二版)随书
- 增量式PID的MATLAB实现.rar
- matlab的LDPC实现
- NCC图像匹配源码matlab
- matlab瑞利信道的程序
- ZF预编码MATLAB代码实现
- OFDM系统中基于导频的信道估计及其
- 最小二乘辨识模型+matlab代码
- 图论——有向图的关联矩阵和邻接矩
- 最小二乘法曲线拟合的matlab实现
- 三相逆变模型预测控制.rar
-
七自由度汽车模型Matlab/Simuli
nk - Matlab2012A crack破解文件
- 《MATLAB在振动信号处理中的应用》随
评论
共有 条评论