# 最短路径问题

由于要考试了，这里只是简单的罗列一下，考试完毕之后继续完善~

RELAX(u,v,w)
if d[v] > d[u]+w(u,v)
d[v]= d[u]+w(u,v)
father[v]=u

INITIALIZE-SINGLE-SOURCE(G,s)
for each vertex v in G
d[v]= MAX
father[v]=NIL
d[s]=0

BELLMAN-FORD(G,w,s)
INITIALIZE-SINGLE-SOURCE(G,s)
for i = 1 to |V|-1
do for each edge (u,v) in E(G)
RELAX(u,v,w)
for each edge (u,v) in E(G)        //没有收敛，存在负权环
if d[v]>d[u]+w(u,v)
return FALSE
return TRUE

//这里考虑是针对顺序进行松弛，但是根据路径松弛性质，必须按照路径的顺序进行，所以这里结合拓扑排序进行计算
DAG-SHORTEST-PATH(G,w,s)
topologically sort the vertices of G
INITIALIZE-SINGLE-SOURCE(G,s)
for each vertex u, taken in toplogically sorted order
for each vertex v in Adj[u]
RELAX(u,v,w)

DIJKSTRA(G,w,s)
INITIALIZE-SINGLE-SOURCE(G,s)
S=空集
Q=V[G]
while Q!=空集
do u=EXTRACT-MIN(Q)
S=S+{u}
for each vertex v in Adj[u]
RELAX(u,v,w)

V次EXTRACT-MIN操作，内隐含E次的DECREASE-KEY操作

Floyd-Warshall

FOLYD-WARSHALL(W)
n = rows[w]
D0 = w
for k =1 to n
for i = 1 to n
for j=1 to n
dij(k) = min(dij(k-1),dik(k-1),dkj(k-1))

posted @ 2012-12-28 11:20  weixliu  阅读(...)  评论(...编辑  收藏