去看【原文】

Dijkstra算法是一种单向的最短路径算法,有研究者就提出了一种优化方法,即双向Dijkstra算法。其主要思想就是从起点和终点同时开始搜索,这样应该能够提升算法效率。事实证明,在大部分情况下,双向Dijkstra算法还是要优于单向的Dijkstra算法。

算法介绍

前面介绍过Dijkstra算法,一些相关的定义可以参考前文。

图的定义以及优先队列的有关定义可以参考前面推送的文章:
去看【最短路径算法–Dijkstra】

Dijkstra算法是单点源的形式往外搜索,它的搜索空间长这样:
双向Dijkstra算法顾名思义,就是从两个方向同时开始搜索,它的搜索空间长这样:

算法原理

Dijkstra算法一个方向搜索需要一个优先队列,那双向Dijkstra算法也就需要两个优先队列了。两个优先队列交替取出最小的元素来扩展,扩展的时候需要检测是否包含环,其扩展过程与Dijkstra算法一样。其原理是从起点和终点依次执行单向的Dijkstra算法,即前向和后向Dijkstra扩展搜索。当两个方向第一次相遇时,会得到一条候选最短路径,第一次相遇后,后续节点扩展时,只需访问已经出过队列的那些节点即可。在这个过程中,全局最优路径就是所有相遇节点的正向代价和方向代价之和的最小值。

实验对比

测试部分比较了单向Dijkstra算法、双向Dijkstra算法、A*算法的计算效率。随机取了100对OD,分别记录每对OD最短路径计算的运行时间以及扩展节点数量。

使用路网1时的计算结果:

Construct network adjacent list ...
Construct network adjacent finished! It consumes 0.931 seconds.
Start to calculate 1th shortest path from 1129 to 167 ...Dijkstra Algo: The shortest path cost is 17289.119, It consumes 0.048 seconds and selects 832 nodesAStar Algo: The shortest path cost is 17289.119, It consumes 0.003 seconds and selects 48 nodes
Bi-Dijkstra Algo: The shortest path cost is 17289.119, It consumes 0.016 seconds and selects 366 nodes
Start to calculate 2th shortest path from 769 to 3498 ...Dijkstra Algo: The shortest path cost is 5522.333, It consumes 0.016 seconds and selects 301 nodesAStar Algo: The shortest path cost is 5522.333, It consumes 0.005 seconds and selects 93 nodes
Bi-Dijkstra Algo: The shortest path cost is 5522.333, It consumes 0.032 seconds and selects 447 nodes
Start to calculate 3th shortest path from 2801 to 2504 ...Dijkstra Algo: The shortest path cost is 31011.622, It consumes 0.071 seconds and selects 1217 nodesAStar Algo: The shortest path cost is 31011.622, It consumes 0.069 seconds and selects 832 nodes
Bi-Dijkstra Algo: The shortest path cost is 31011.622, It consumes 0.080 seconds and selects 1394 nodes
Start to calculate 4th shortest path from 2100 to 161 ...Dijkstra Algo: The shortest path cost is 29805.903, It consumes 0.080 seconds and selects 1285 nodesAStar Algo: The shortest path cost is 29805.903, It consumes 0.008 seconds and selects 117 nodes
Bi-Dijkstra Algo: The shortest path cost is 29805.903, It consumes 0.022 seconds and selects 459 nodes
Start to calculate 5th shortest path from 3473 to 3440 ...Dijkstra Algo: The shortest path cost is 2693.313, It consumes 0.008 seconds and selects 156 nodesAStar Algo: The shortest path cost is 2693.313, It consumes 0.002 seconds and selects 25 nodes
Bi-Dijkstra Algo: The shortest path cost is 2693.313, It consumes 0.009 seconds and selects 170 nodes
...The mean consumption times is: Dijkstra: 0.042, Bi-Dijkstra: 0.034, A*: 0.019
The mean expanded nodes is: Dijkstra: 680.260, Bi-Dijkstra: 619.000, A*: 267.760


使用路网2时的计算结果:

Construct network adjacent list ...
Construct network adjacent finished! It consumes 24.804 seconds.
Start to calculate 1th shortest path from 12443 to 12627 ...Dijkstra Algo: The shortest path cost is 20328.300, It consumes 0.577 seconds and selects 5741 nodesAStar Algo: The shortest path cost is 20328.300, It consumes 0.087 seconds and selects 966 nodes
Bi-Dijkstra Algo: The shortest path cost is 20328.300, It consumes 0.683 seconds and selects 6779 nodes
Start to calculate 2th shortest path from 4144 to 10838 ...Dijkstra Algo: The shortest path cost is 22007.953, It consumes 0.389 seconds and selects 3578 nodesAStar Algo: The shortest path cost is 22007.953, It consumes 0.085 seconds and selects 787 nodes
Bi-Dijkstra Algo: The shortest path cost is 22007.953, It consumes 0.475 seconds and selects 4833 nodes
Start to calculate 3th shortest path from 8114 to 11581 ...Dijkstra Algo: The shortest path cost is 19407.315, It consumes 0.771 seconds and selects 6845 nodesAStar Algo: The shortest path cost is 19407.315, It consumes 0.035 seconds and selects 356 nodes
Bi-Dijkstra Algo: The shortest path cost is 19407.315, It consumes 0.592 seconds and selects 6615 nodes
Start to calculate 4th shortest path from 6406 to 10489 ...Dijkstra Algo: The shortest path cost is 20019.205, It consumes 1.020 seconds and selects 7920 nodesAStar Algo: The shortest path cost is 20019.205, It consumes 0.134 seconds and selects 1184 nodes
Bi-Dijkstra Algo: The shortest path cost is 20019.205, It consumes 0.612 seconds and selects 6426 nodes
Start to calculate 5th shortest path from 6822 to 8476 ...Dijkstra Algo: The shortest path cost is 25945.571, It consumes 0.424 seconds and selects 3912 nodesAStar Algo: The shortest path cost is 25945.571, It consumes 0.085 seconds and selects 762 nodes
Bi-Dijkstra Algo: The shortest path cost is 25945.571, It consumes 0.674 seconds and selects 6890 nodes
...The mean consumption times is: Dijkstra: 0.624, Bi-Dijkstra: 0.560, A*: 0.126
The mean expanded nodes is: Dijkstra: 5437.020, Bi-Dijkstra: 5419.480, A*: 1018.031



为了方便阅读,两幅图中结果都根据Dijkstra算法的测试结果进行了排序。可以看出,整体来说,双向Dijkstra算法较单向Dijkstra算法有一定优势,例如,在路网2中,每对OD的平均计算时间Dijkstra算法需要0.624s,双向Dijkstra算法只需0.560s。但是也存在部分情况双向Dijkstra算法计算效率慢于单向Dijkstra算法。同理,大部分情况下,双向DIjkstra算法的搜索空间比Dijkstra算法要小。在这三个算法中,A*算法还是最快的。

去看【原文】

更多精彩内容,请关注“探索GIS的小蜗牛”。

双向Dijkstra算法、Dijkstra算法对比相关推荐

  1. 最短路算法 :Bellman-ford算法 Dijkstra算法 floyd算法 SPFA算法 详解

     本文链接   :http://www.cnblogs.com/Yan-C/p/3916281.html . 在本文中因为邻接表在比赛中不如前向星好写,而且前向星效率并不低所以,本文的代码 存图只 ...

  2. 最短路径算法——Dijkstra,Bellman-Ford,Floyd-Warshall,Johnson,无一幸免

    文章出自:http://dsqiu.iteye.com/blog/1689163 最短路径算法--Dijkstra,Bellman-Ford,Floyd-Warshall,Johnson,无一幸免 本 ...

  3. 其他算法-Dijkstra

    目录 连通图 Dijkstra简介 算法过程 连通图 图中从一个顶点到达另一顶点,若存在至少一条路径,则称这两个顶点是连通着的.例如下图,虽然 V1 和 V3 没有直接关联,但从 V1 到 V3 存在 ...

  4. 坐在马桶上看算法:Dijkstra最短路算法

                                                             [坐在马桶上看算法]算法7:Dijkstra最短路算法 上周我们介绍了神奇的只有五行的 ...

  5. C语言dijkstra最短距离的算法(附完整源码)

    C语言dijkstra最短距离的算法 C语言dijkstra最短距离的算法完整源码(定义,实现,main函数测试) C语言dijkstra最短距离的算法完整源码(定义,实现,main函数测试) #in ...

  6. Dijkstra 最短路算法(只能计算出一条最短路径,所有路径用dfs)

    上周我们介绍了神奇的只有五行的 Floyd 最短路算法,它可以方便的求得任意两点的最短路径,这称为"多源最短路".本周来来介绍指定一个点(源点)到其余各个顶点的最短路径,也叫做&q ...

  7. 图论基础知识--最小生成树算法kruskal(克鲁斯克尔)和普里姆算法(Prim算法);最短路径算法Dijkstra(迪杰斯特拉)和Floyd(弗洛伊德)

    一.基础知识   有向图   无向图 以无向图为例: 邻接矩阵: 度矩阵(对角矩阵): 二.最小生成树 应用:将网络顶点看着城市,边看着城市之间通讯网,边的权重看着成本,根据最小生成树可以构建城市之间 ...

  8. 计算机网络最短路径路由选择,最短路径算法Dijkstra算法在路由选择中的应用.pdf...

    最短路径算法Dijkstra算法在路由选择中的应用.pdf 计算机与网络 江苏联合职业技术学院徐州机电工程分院 王恒青 江苏联合职业技术学院徐州生物工程分院 宋如敏 [摘要]本文介绍了路由算法的设计目 ...

  9. dijkstra算法_最短路径问题——迪杰斯特拉算法(Dijkstra)

    假期过长,导致停更了好长时间,复习一道算法题找找感觉. 前段时间看到一篇文章,里面提到了统治世界的十大算法,其中之一就是迪杰斯特拉算法(Dijkstra),该算法主要解决的"最短路径&quo ...

  10. spfa算法_10行实现最短路算法——Dijkstra

    今天是算法数据结构专题的第34篇文章,我们来继续聊聊最短路算法. 在上一篇文章当中我们讲解了bellman-ford算法和spfa算法,其中spfa算法是我个人比较常用的算法,比赛当中几乎没有用过其他 ...

最新文章

  1. 如何使用Azure API管理服务?
  2. 净核心vs节点js您应该选择什么
  3. ASP防止SQL注入-代码片段
  4. 04_ClickHouse表引擎概述、MergeTree系列引擎、Log系列引擎、集成引擎、特定功能的引擎(学习笔记)
  5. 一、pytorch搭建实战以及sequential的使用
  6. CentOS7中NAT网卡设置静态IP
  7. c语言猜拳游戏思考,这是一个猜拳游戏的程序 大家有更好的解决方法么?
  8. Sentinel介绍和Windows下安装Sentinel-dashboard
  9. python写520_用Python做一个520表白神器,值得收藏
  10. 超界文字滚动 (id和类型两种实现方式)
  11. oracle10自动扩分区,Oracle 11g数据库的分区表扩展(按年度)
  12. linux超级终端配置交换机路由器
  13. docker服务及镜像开机自动启动
  14. GCD中dispatch_group的使用方法
  15. 恭主驾到:最新的汽车年审新规,都了解了吗?
  16. 2017年西南民族大学程序设计竞赛-网络同步赛
  17. 开上新能源车之后,如何摆脱“充电焦虑”?
  18. 国产磁力架的用途,特点和使用方法
  19. 为什么建议将成员属性设置为私有
  20. Verilog:【7】超详细WaveDrom教程,时序图绘制利器,看这一篇就够了。

热门文章

  1. ws832设置虚拟服务器,华为路由器ws832怎么设置
  2. 数据库面试题(一)------开窗函数OVER(PARTITION BY)
  3. VC++ 2010 创建高级Ribbon界面详解(2)
  4. (一)MFC读取并显示一幅位图图像,并获取鼠标点击位置的像素坐标和灰度值(接上篇博客)
  5. 三天打渔两天晒网问题(python)
  6. 通过Matlab分析语音信号的时频特性
  7. linux7查看ftp用户,linux vsftp查看ftp账号信息的方法
  8. Cadence OrCAD Capture 检查多部分元件是否设计正确的方法图文教程
  9. 机器学习 - 主成分分析法 (PCA)
  10. python基础-变量,变量类型,字符串str,元组tuple,列表list,字典dict操作详解(超详细)