Contents
- 最短路Shortest-Path
- Algorithm: Dijkstra
最短路Shortest-Path
Algorithm: Dijkstra
Given a graph G G G, an total-order ≤ \leq ≤ on the set of the weight of all path ∣ A B ∣ |AB| ∣AB∣ (AB can be same) and a binary operator + + +, then the weight of a path (the sum of all edges on the path, denotes ∣ A B ∣ |AB| ∣AB∣) must satisfying a property (a bit like triangular inequality, but not same):
- If ∣ A B ∣ ≤ ∣ A C ∣ |AB| \leq |AC| ∣AB∣≤∣AC∣, then ∣ A B ∣ ≤ ∣ A C ∣ + ∣ C B ∣ |AB| \leq |AC| + |CB| ∣AB∣≤∣AC∣+∣CB∣ ( A B C ABC ABC maybe the same)
Then, Dijkstra is used to calculate the least-element under the order ≤ \leq ≤ of the weight ∣ S X ∣ |SX| ∣SX∣ where S S S is a start-point, X X X is a any point.
There are some examples:
-
A graph (may contains loop (self-loop or non-self-loop)) with all edges ≥ 0 \geq 0 ≥0, the weight of a path is the sum of all edges on it and given a start-point S S S, calculate the minimal-distance of ∣ S X ∣ |SX| ∣SX∣ (X is an arbitrary point)
Defining the Dijkstra-Order ≤ ( a , b ) = a ≤ b \leq(a,b) = a \leq b ≤(a,b)=a≤b, Dijkstra-Add + ( a , b ) = a + b +(a,b) = a + b +(a,b)=a+b
Then, we can found this satisfies the Dijkstra-Triangular-Inequality -
A graph (may contains loop (self-loop or non-self-loop)) with all edges ≤ 0 \leq 0 ≤0, the weight of a path is the sum of all edges on it and given a start-point S S S, calculate the maximal-distance of ∣ S X ∣ |SX| ∣SX∣ (X is an arbitrary point)
Defining the Dijkstra-Order ≤ ( a , b ) = a ≥ b \leq(a,b) = a \geq b ≤(a,b)=a≥b (notice here), Dijkstra-Add + ( a , b ) = a + b +(a,b) = a + b +(a,b)=a+b
Then, we can found this satisfies the Dijkstra-Triangular-Inequality -
A graph (may contains loop (self-loop or non-self-loop)) with all edges be any real-number in [ 0 , 1 ] [0, 1] [0,1], the weight of a path is the product of all edges on it and given a start-point S S S, calculate the maximal-distance of ∣ S X ∣ |SX| ∣SX∣ (X is an arbitrary point)
Defining the Dijkstra-Order ≤ ( a , b ) = a ≥ b \leq(a,b) = a \geq b ≤(a,b)=a≥b (notice here), Dijkstra-Add + ( a , b ) = a ∗ b +(a,b) = a * b +(a,b)=a∗b
Then, we can found this satisfies the Dijkstra-Triangular-Inequality