Jump Point Search-跳点搜索法 matlab代码改动

文章讨论了在使用JumpPointSearch算法时,代码中`insert_closelist`函数的问题,即错误地覆盖了具有相同父节点的跳点,导致路径不连续。作者提出了修正后的函数并增加了`GetPath`函数,用于从终点通过父节点获取完整路径。
摘要由CSDN通过智能技术生成

本文的源码来自以下博客:

Jump Point Search-跳点搜索法-原理&matlab代码-与A*算法比较(路径规划)_跳点搜索算法-CSDN博客

在复制了代码进行实验后,我发现代码中存在问题,主要如下:

  insert_closelist(将跳点插入到closelist)函数,这个函数将跳点插入closelist,但是我发现,在其中一行它把父节点相同的跳点给覆盖了,它为什么要这么做呢?

function closelist = insert_closelist(point,closelist)
%   将跳点插入到closelist
%   此处显示详细说明
flag=0;
point_temp=[point(1,1:3),point(1,7:8)];
for i = 1:length(closelist(:,1))
    if isequal(point(1,7:8),closelist(i,4:5))
        closelist(i,:)=point_temp;  %这一行
        flag=1;
        break
    end
end
if flag
    return
else
    closelist=[point_temp;closelist];
end
end

  原因在下面这段代码,这一段代码是将closelist中的点拿出用来绘制路径的,显然,它提取了closelist中所有的点,这是有问题的,因为一个父节点可能会有几个子节点,所以作者在插入时直接将父节点相同的节点覆盖掉了。


%将closelist中的节点x y坐标分别拿出 准备绘制路线
for pp=1:length(closelist(:,1))
    x = closelist(pp,1);
    y = closelist(pp,2);
    A(pp,1)=x;
    A(pp,2)=y;%这部分是将路径坐标拿出来另外存放

  这种覆盖是有问题的,我们最后得到的路径会出现跳跃,因为它们的父节点是不连续的。要解决这个问题,只需要正常的将跳点加入closelist中,不进行覆盖。

insert_closelist.m

function closelist = insert_closelist(point,closelist)
%   将跳点插入到closelist
%   此处显示详细说明
%flag=0;
%point_temp=[point(1,1:3),point(1,7:8)];
%for i = 1:length(closelist(:,1))
%    if isequal(point(1,7:8),closelist(i,4:5))
%        closelist(i,:)=point_temp;  %这一行
%        flag=1;
%        break
%    end
%end
%if flag
%    return
%else
    closelist=[point_temp;closelist];
end
end

然后再选择路径时,正常的从终点不断的找到父节点,画出完整路径就行了,增加一个函数:

增加一个函数文件,此文件是从终点开始,通过父节点找路径的

GetPath.m

function path=GetPath(close,start)

ind=1;
path=[];
while 1
    path=[path; close(ind,1:2)];
    if isequal(close(ind,1:2),start) %到起点了  
        break;
    end
    for io=1:length(close(:,1))
        if isequal(close(io,1:2),close(ind,4:5))%找到父节点
            ind=io;
            break;
        end
    end
end
end

路径搜索的代码是以前找到的一个A*算法代码中的,但我忘记出处了,就不标注了。

  • 10
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值