algorithm - "uniform-cost search"算法中的路径如何获取?

标签 algorithm search data-structures artificial-intelligence

我一直在研究统一成本搜索的算法,尽管我能够理解整个优先级队列过程,但我无法理解算法的最后阶段。

如果我们看at this graph ,在应用该算法后,我将得到每个节点的最小距离,但假设我想知道 A 到 G 之间的路径(就像示例一样),我将如何计算它?

最佳答案

通常,您从尚未探索的每个节点的无限总成本开始。然后你可以稍微调整一下算法来保存前身:

for each of node's neighbours n
    if n is not in explored
        if n is not in frontier
            frontier.add(n)
            set n's predecessor to node
        elif n is in frontier with higher cost
            replace existing node with n
            set n's predecessor to node

之后,您可以从您的目标开始,检查前辈的顺序。

关于algorithm - "uniform-cost search"算法中的路径如何获取?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12755893/

相关文章:

python - Python 的 'in' 列表运算符是否具有成功搜索的早期输出

c++ - 我的队列数据结构实现错误

algorithm - 翻转二维列表(或列表列表)的维度,其中每个子列表具有相等的长度

algorithm - 3D平面算法中点到线的最小垂直距离

algorithm - LZW数据解压算法

java - 如何在 JAVA GUI 中创建类似于 Google 搜索样式的搜索栏

django - 在 Django 管理搜索中格式化搜索字符串

java - 将私有(private)实例的访问权限引入外部类的最佳方法

c - 在c中使用指针进行字符串操作

c - 无法理解c中的空指针