python广度优先算法最短路径_最短路径问题的Dijkstra算法 -python

最短路径问题的Dijkstra算法

是由荷兰计算机科学家艾兹赫尔·戴克斯特拉提出。迪科斯彻算法使用了广度优先搜索解决非负权有向图的单源最短路径问题,算法最终得到一个最短路径树>    。该算法常用于路由算法或者作为其他图算法的一个子模块。

# Dijkstra's algorithm for shortest paths

# David Eppstein, UC Irvine, 4 April 2002

# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/117228

from priodict import priorityDictionary

def Dijkstra(G,start,end=None):

"""

Find shortest paths from the start vertex to all vertices nearer than or equal to the end.

The input graph G is assumed to have the following representation:

A vertex can be any object that can be used as an index into a dictionary.

G is a dictionary, indexed by vertices. For any vertex v, G[v] is itself a dictionary,

indexed by the neighbors of v. For any edge v->w, G[v][w] is the length of the edge.

This is related to the representation in

where Guido va

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值