Relaxation of an edge in Dijkstra's algorithm

左心房为你撑大大i 提交于 2019-11-29 10:35:51

问题


What does relaxation of an edge mean in the context of graph theory ? I came across this while studying up on Dijkstra's algorithm for single source shortest path.


回答1:


Here's a nice description of the Algorithm that also explains the notion of relaxation.

The notion of "relaxation" comes from an analogy between the estimate of the shortest path and the length of a helical tension spring, which is not designed for compression. Initially, the cost of the shortest path is an overestimate, likened to a stretched out spring. As shorter paths are found, the estimated cost is lowered, and the spring is relaxed. Eventually, the shortest path, if one exists, is found and the spring has been relaxed to its resting length.




回答2:


The relaxation process in Dijkstra's algorithm refers to updating the cost of all vertices connected to a vertex v, if those costs would be improved by including the path via v.




回答3:


Relaxing an edge, (a concept you can find in other shortest-path algorithms as well) is trying to lower the cost of getting to a vertex by using another vertex.

You are calculating the distances from a beginning vertex, say S, to all the other vertices. At some point, you have intermediate results -- current estimates. The relaxation is the process where you check, for some vertices u and v:

if directly_connected(v, u)
    if est(S, v) > est(S, u) + dist(u,v)
       est(S, v) = est(S, u) + dist(u, v)

where est(S,a) is the current estimate of the distance, and dist(a,b) is the distance between two vertices that are neighbors in the graph.

What you are basically checking in the relaxation process is weather your current estimate from a to b could be improved by "diverting" the path through c (this "diversion" would be the length of a path from a to c and from c to b).




回答4:


lets suppose in graph if we have (u,v)∈ E where w(u,v)=10 then if by adding a third vertex in between them like w(u,y)=1 and w(y,v)=3 now we find a path between u and v with weight 1+3=4<10. Now we will consider the second path as shortest which is (u,y,v) and will ignore the first one, this is relaxation.




回答5:


Edge relaxation.

To relax an edge v -> w means to test whether the best-known way from s to w is to from s to v, then take the edge from v to w, and, if so, update our data structures.

Java code:

private void relax(DirectedEdge e) {
    int v = e.from(), w = e.to;
    if (distTo[w] > distTo[v] + e.weight()) {
        distTo[w] = distTo[v] + e.weight();
        edgeTo[w] = e;
    }
}

There is also vertex relaxation. That means to relax all the edges pointing from a given vertex.

private void relax(EdgeWeightedGraph G, int v) {
    for (DirectedEdge e : G.adj(v)) {
        relax(e);
    }
}

From https://algs4.cs.princeton.edu/44sp/



来源:https://stackoverflow.com/questions/12782431/relaxation-of-an-edge-in-dijkstras-algorithm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!