달력

5

« 2024/5 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
2015. 12. 9. 20:58

A shortest-path algoritnm 전자공학이론/이산수학2015. 12. 9. 20:58

Dijkstra's Algorithm

Input:    A connected, weighted graph in which all weights are positive;

vertices a and z

Output:    L(z), the length of a shortest path from a to z

1
2
3
4
5
6
7
8
9
10
11
12
13
dijkstra(w, a, z, L){
    L(a) = 0
    for all vertices x≠a
        L(x) = ∞
    T = set of all vertices
 
    while(z∈T){
        choose v∈T with minimum L(v)
        T = T-{v}
        for each x∈T adjacent to v
            L(x) = min{L(x), L(v) + w(v, x)}
    }
}
cs

2~5행:     vertex a의 길이를 0으로 설정하고 a를 제외한 나머지 vertex의 L은 ∞로 설정한다. T는 그래프              의 모든 vertex의 집합이다.

8~11행:     T안에있는 vertex 중에서 L이 최소인 vertex v를 선택하고 그 v를 집합 T에서 삭제한다. T에                 포함되어 있는 것중 v와 연결되어 있는 vertex에 대하여, L를 업데이트한다. 이것은 z가 T에                 포함되지 않을 때가지 반복한다.

 ***최소 path 찾기*** vertex에 label을 붙일 때, 최소 길이 뿐만아니라 이어지는 바로 전 vertex의 이름을 같이 적으면 두 vertex 사이의 최소 path를 찾을 수 있다.






'전자공학이론 > 이산수학' 카테고리의 다른 글

Tree  (0) 2015.12.10
Isomorphic Graphs / Homeomorphic graphs/ Planar graph  (0) 2015.12.09
Euler cycle & Hamiltonian cycle  (0) 2015.12.09
Graph  (0) 2015.12.09
6. Proofs  (0) 2015.10.17
:
Posted by youjin.A