반응형
0archlinux0
Fun math Cute momonga
0archlinux0
전체 방문자
오늘
어제
  • Categories (20)
    • Algorithm (4)
      • Graph Theory (3)
      • Number Theory (0)
      • Data Structure (0)
      • String (0)
      • Etc (1)
    • Math (9)
      • Number Theory (2)
      • Proof of PS solutions (1)
      • 미적분학 (0)
      • 복소해석학 (0)
      • 리만기하학 (0)
      • Linear Algebra 선형 대수학 (0)
      • 이산수학-그래프이론 (0)
      • Analysis 해석학 (6)
    • PS (7)
      • 백준 (7)
      • leetcode (0)
      • codeforce (0)
      • 프로그래머스 (0)
      • PS일지 (0)
    • CS (0)
      • Network (0)
      • Automata theory (0)
      • Computer Graphics (0)
    • 다락방 (0)
      • CS (0)
      • Math (0)
      • Physics (0)
      • Language (0)
      • Etc (0)
      • Todo-Daily (0)
    • Machine Learning (0)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

  • !

인기 글

태그

  • 증명
  • Automata Theory
  • 해석학
  • set theory
  • 오토마톤
  • analysis
  • 백준
  • math
  • algorithm
  • ps

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
0archlinux0

Fun math Cute momonga

Algorithm/Graph Theory

Floyd-Warshall Algorithm - 플로이드 워셜 알고리즘

2022. 4. 3. 04:22
반응형

# Expression

$ \forall u,v \in G: \ \ cost(u,v)$

그래프 G에 대해서 모든 정점간의 최소 비용을 계산할때 쓰이며 음의 가중치 간선이 있어도 동작한다. 

이러한 최소 비용 문제를 일반적으로 Shortest Path Problem 으로 분류한다.


# Algorithm

let cost[V+1][V+1] // cost[i][j]: cost of the shortest path from i to j
//init
for(i: 0~V)
  for(j: 0~V) 
  	if(i == j) cost[i][j] = 0
  	else cost[i][j] = w[i][j] ? w[i][j] : INF

//relaxation
for(mid: 0~V)
  for(start: 0~V)
  	for(end: 0~V)
      if(cost[start][mid] + cost[mid][end] < cost[start][end])
      	cost[start][end] = cost[start][mid] + cost[mid][end]

# Proof of correctness

Definition)

$path\_vertices(path)$

$path\_vertices(path) $ $= \left\{ v \ | v \in G ,\ v \ was \ included \ in \ the \ path \right\}$ 

경로 path상에서 방문한 모든 정점들의 집합

 

$shortest\_path(i, j, k) $ : 

$ path\_vertices(shortest\_path(i, j, k))$ $ \subset \left\{ x | 1 \leq x \leq k \right\} $

i에서 j로 가는 경로중, 경로상의 모든 점이 {1, 2, ... k }에 포함되며 최소 비용인 경로(또는 그 값)

 

$w_{i,j}$ : i에서 j로 가는 간선의 가중치(비용)

 

Proof)

 

$shortest_path(i, j, k)$에 대하여 생각해보면 두가지 경우가 존재 할 수 있다.

 

1. $k \in $ $path\_vertices(shortest\_path(i, j, k)) $ (k를 포함하는 경우)

$shortest\_path(i, j, k) $ $= shortest\_path(i, k - 1, k) + $ $shortest\_path(k, j, k - 1)$

 

2. $k \not\in $ $path\_vertices(shortest\_path(i, j, k))$ (k를 포함하지 않는 경우)

$shortest\_path(i, j, k) $ $= shortest\_path(i, j, k-1)$

 

$ \therefore shortest\_path(i, j, k) $ $= min(shortest\_path(i, k - 1, k) $ $+ shortest\_path(k, j, k - 1),$ $ shortest\_path(i, j, k-1)$

로 나타낼 수 있다.


후술할 내용들

#floyds-cycle-detection-algorithm

#Path reconstruction

 

 

반응형
저작자표시 (새창열림)
    'Algorithm/Graph Theory' 카테고리의 다른 글
    • Flow network - 네트워크 플로우
    • Max-flow min-cut theorem - 최대 유량 최소 컷 정리
    0archlinux0
    0archlinux0
    수학과 다람쥐가 좋은 사람

    티스토리툴바