Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relaxation of an edge in Dijkstra's algorithm

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.

like image 620
Geek Avatar asked Oct 08 '12 13:10

Geek


People also ask

In which algorithm is edge relaxation applied?

We widely use the algorithms to solve the shortest paths problem from competitive programming to Google Maps directions search. By understanding the key notion, “edge relaxation”, it is really easier to understand the concrete algorithms, say Dijsktra's algorithm or Bellman-Ford algorithm.

What is relaxation in shortest path algorithm?

The single - source shortest paths are based on a technique known as relaxation, a method that repeatedly decreases an upper bound on the actual shortest path weight of each vertex until the upper bound equivalent the shortest - path weight.

What is relax function?

Simply put, the relaxation function checks whether going to a vertex v from a source vertex s through an intermediary vertex u reduces the current shortest distance from s to v. If it does, we add u to the shortest path from s to v, and update the shortest distance of v from s (i.e., v.

Which algorithm relaxes each edge only once?

Dijkstra's algorithm and the shortest-paths algorithm for directed acyclic graphs relax each edge exactly once.


4 Answers

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.

like image 99
krjampani Avatar answered Oct 04 '22 21:10

krjampani


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.

like image 28
digitalvision Avatar answered Oct 04 '22 23:10

digitalvision


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).

like image 38
penelope Avatar answered Oct 04 '22 21:10

penelope


Edge relaxation process

Initialization

In shortest-path algorithms, you first assign a path-cost of zero to a starting node (e.g. S), and a path-cost of infinity to every other node (e.g. A, E).

shortest_path_01

S := new Node()
A := new Node()
E := new Node()

// To go from S to S is zero
S.path_cost = 0

// high cost
A.path_cost = 1000 // "infinity"
E.path_cost = 1000 // "infinity"

Edge relaxation

Infinity is the highest cost we could have, so we want to reduce "relax" that to a lower cost if possible. To do that we compute the cost of a path (e.g. a or ab) between the starting node and another node, and update the path-cost for the node, if that path cost is less.

shortest_path_02

a := 3
b := 5

SS := S.path_cost + 0
if (S.path_cost > SS) {
  // 0 !> 0 + 0
  S.path_cost = SS
}

Sa := S.path_cost + a
if (A.path_cost > Sa) {
  // 1000 > 0 + 3
  A.path_cost = Sa
  // A = 0 + 3
}

ab := A.path_cost + b
if (E.path_cost > ab) {
  // 1000 > 3 + 5
  E.path_cost = ab
  // E = 3 + 5
}

Edge relaxation repeated

shortest_path_03

c := 1

Sc := S.path_cost + c
if (E.path_cost > Sc) {
  // 8 > 0 + 1
  E.path_cost = Sc
  // E = 0 + 1
}
like image 35
tim-montague Avatar answered Oct 04 '22 21:10

tim-montague