• 検索結果がありません。

Algorithm Design

N/A
N/A
Protected

Academic year: 2021

シェア "Algorithm Design"

Copied!
52
0
0

読み込み中.... (全文を見る)

全文

(1)

アルゴリズム設計 Algorithm Design

落合 秀也

離散数学

(2)

著書 Algorithm Design を読み解く

2

(3)

章構成 (1/2)

1. Introduction: Some Representative Problems 2. Basics of Algorithm Analysis

3. Graphs

4. Greedy Algorithm 5. Divide and Conquer

6. Dynamic Programming 7. Network Flow

8. NP and Computational Intractability

(4)

章構成 (2/2)

9. PSPACE: A Class of Problems beyond NP 10. Extending the Limits of Tractability

11. Approximation Algorithm 12. Local Search

13. Randomized Algorithms

Epilogue: Algorithms That Run Forever

4

(5)

本日の進め方

1.これまでの講義で扱ってきた部分をピックアップ そして、

どのような位置づけになっているか どのような記述になっているか

を確かめる

2.関連する重要キーワードをピックアップ

そして、その意味について、考える

(6)

講義で扱った内容はどこで触れられているか

3 Graph

3.1 Basic Definitions and Applications

3.2 Graph Connectivity and Graph Traversal

3.3 Implementing Graph Traversal Using Queues and Stacks 3.6 Directed Acyclic Graphs and Topological Ordering

4 Greedy Algorithm

4.4 Shortest Paths in a Graph

4.5 The Minimum Spanning Tree Problem

6 Dynamic Programming

6.8 Shortest Paths in a Graph

6.9 Shortest Paths and Distance Vector Protocols

7 Network Flow

7.1 The Maximum-Flow Problem and the Ford-Fulkerson Algorithm

6

(7)

講義で扱った内容はどこで触れられているか

3 Graph

3.1 Basic Definitions and Applications

3.2 Graph Connectivity and Graph Traversal

3.3 Implementing Graph Traversal Using Queues and Stacks 3.6 Directed Acyclic Graphs and Topological Ordering

4 Greedy Algorithm

4.4 Shortest Paths in a Graph

4.5 The Minimum Spanning Tree Problem

6 Dynamic Programming

6.8 Shortest Paths in a Graph

6.9 Shortest Paths and Distance Vector Protocols

7 Network Flow

7.1 The Maximum-Flow Problem and the Ford-Fulkerson Algorithm

(8)

グラフ (Graph) を数学的に捉える

グラフ G は、二つの集合で構成されている

頂点

(vertex)

の集合

V

(point)

、節点

(node)

とも言う

(edge)

の集合

E

G (V, E) と書く

V={A, B, C, D, E, F}

E={ e1, e2, …, e10 }

e1={A,B}, e2={A,C}, …

8

頂点 辺

A

B

C

D

E

F e1

e2

e3 e4

e5

e6 e7 e8

e9

e10

3.1 Basic Definitions and Applications

(9)

有向グラフ

(directed graph, digraph)

有向グラフ D は、二つの集合で構成されている

頂点

(vertex)

の集合

V

(point)

、節点

(node)

とも言う

(arc):

頂点の順序対の集合

A

D (V, A) と書く

V={A, B, C, D, E, F}

A={ e1, e2, …, e10 }

e1=<B,A>, e2=<C,A>, …

頂点 弧

A

B

C

D

E

F e1

e2

e3 e4

e5

e6 e7 e8

e9

e10

向きの無いグラフを、無向グラフと呼ぶこともある

3.1 Basic Definitions and Applications

(10)

グラフによる実世界のモデル化

交通網

頂点: 都市や駅

辺 : 道路や路線

コンピュータ・ネットワーク

頂点: 端末やスイッチ

辺 : ケーブル

• WWW

頂点: ページ

辺 : リンク

ディジタル回路

頂点: 論理素子

辺 : 配線

分子構造

頂点: 原子

辺 : 結合

依存関係

頂点: 事象

辺 : 原因、結果の関係

• Social Network

頂点: 人間,

辺 : 関係(知人,

etc.

10

3.1 Basic Definitions and Applications

(11)

道 (path)

頂点 - 辺 - 頂点 - 辺 - 頂点 -…- 頂点 ( ただし、同じ頂点を 通らないもの ) を、道 ( パス : path) と呼ぶ

モデル上の道を考察する上で重要な概念

道は

「辺の列」または「頂点の列」

で表現可能

( 例 ) 右図の場合:

e4, e8, e10 または A, D, E, F

A

B

C

D

E

F e1

e2

e3 e4

e5

e6 e7 e8

e9

e10

3.1 Basic Definitions and Applications

(12)

連結 (connectivity)

グラフ G において、任意の 2 頂点間に道が存在す れば、グラフ G は連結である、という。

12

A

B

C

D

E

F e1

e2

e3 e4

e5

e6 e7 e8

e9

e10

A

B

C

D

E

F e1

e5

e6 e7 e8

連結なグラフ 連結でないグラフ

3.1 Basic Definitions and Applications

(13)

無閉路 (acyclic, cycle-free) グラフ

閉路のないグラフ

A

B

C

D

E

G

H

F A

B

C

D

E

G

H F

木 (tree) 森 (forest)

連結グラフ 連結でないグラフ

退化木

3.1 Basic Definitions and Applications

(14)

木の構造

根 (root)

枝 (branch)

葉 (leaf)

親 (parent)

子 (child)

先祖 (ancestor)

子孫 (descendant)

深さ (depth, level)

14

3.1 Basic Definitions and Applications

(15)

講義で扱った内容はどこで触れられているか

3 Graph

3.1 Basic Definitions and Applications

3.2 Graph Connectivity and Graph Traversal

3.3 Implementing Graph Traversal Using Queues and Stacks 3.6 Directed Acyclic Graphs and Topological Ordering

4 Greedy Algorithm

4.4 Shortest Paths in a Graph

4.5 The Minimum Spanning Tree Problem

6 Dynamic Programming

6.8 Shortest Paths in a Graph

6.9 Shortest Paths and Distance Vector Protocols

7 Network Flow

7.1 The Maximum-Flow Problem and the Ford-Fulkerson Algorithm

(16)

連結性の判定問題を考える

グラフ G(V,E) が与えられたとき、

G が連結かどうか、を判定したい。

小さいグラフなら、

紙に書いてみればよい

一般には簡単ではない

大きいグラフの場合

コンピュータに判断させる場合

グラフ G

16

3.2 Graph Connectivity and Graph Traversal

(17)

s

幅優先探索 (Breadth-First Search)

基本的な考え方

頂点

s

から開始 ・・・

L0

とする

L0

から、外向きに辺をつたい、接続 する頂点を取り込む ・・・

L1

とする

L1

から、外向きに辺をつたい、接続 する頂点を取り込む ・・・

L2

とする

L2

から、外向きに辺をつたい、接続 する頂点を取り込む ・・・

L3

とする

・・・

L0 L1 L2

L3

頂点

s

から湧き出す水によって引き起こされる洪水(

Flood

)が 到達可能な頂点すべてに伝搬するイメージ

3.2 Graph Connectivity and Graph Traversal

(18)

深さ優先探索 (Depth-First Search)

基本的な考え方

開始点

s

から、辺をたどって行きつく ところ(

=dead end

)まで行ってみる

(ただし同じ頂点は取らない)

行き止まり

(=dead end)

に当たれば、

1

つ戻って、別の辺をたどってみる

1

つ戻ってもダメなら、

2

つ戻ってみる

2

つ戻ってもダメなら、

3

つ戻ってみる

・・・

18

s

頂点

s

から歩き始めた人が、すべての行き止まりにあたるまで、

隈なく歩いていくイメージ

a b

c

d e

f

g h

i j

k

3.2 Graph Connectivity and Graph Traversal

(19)

深さ優先探索によって作られる木

出来るだけ深いところまで一気に作る

戻りながら、別に行ける頂点があれば、そちらの枝を作る

19

s

a b

c

d e

f

g h

i j

k

s b

c f

g i

j

k h

d a e

深さ優先探索木と呼ばれる

3.2 Graph Connectivity and Graph Traversal

(20)

講義で扱った内容はどこで触れられているか

3 Graph

3.1 Basic Definitions and Applications

3.2 Graph Connectivity and Graph Traversal

3.3 Implementing Graph Traversal Using Queues and Stacks 3.6 Directed Acyclic Graphs and Topological Ordering

4 Greedy Algorithm

4.4 Shortest Paths in a Graph

4.5 The Minimum Spanning Tree Problem

6 Dynamic Programming

6.8 Shortest Paths in a Graph

6.9 Shortest Paths and Distance Vector Protocols

7 Network Flow

7.1 The Maximum-Flow Problem and the Ford-Fulkerson Algorithm

20

(21)

グラフを隣接リストで表現する

隣接リスト (adjacency list)

1.

ある頂点

v

の、近隣の頂点をリストで表現したもの

: Adj[v]

2.

全頂点に対して、同様のリストを作る

: Adj –

配列

1

2

3

4

5

1 2 3 4 5

2 1 1 1 3

3 4 5 2 4

4

5

着目する頂点

近隣の頂点

Adj Adj

の大きさは

O(n+m)

n:

頂点の数

3.3 Implementing Graph Traversal Using Queues and Stacks

(22)

キュー (Queue) の働きと使い方

先入れ先出し装置: Fast In Fast Out (FIFO)

入れた順番に取り出せるメモリ:

3, 1, 2, 8, 6, 5, 4

の順に投入すれば、

3, 1, 2, 8, 6, 5, 4

の順に出てくる

22

Enqueue

キュー

(キューに入れる)

Dequeue

(キューから出す)

3.3 Implementing Graph Traversal Using Queues and Stacks

(23)

深さ優先探索を実現する

スタック (Stack) を利用する

後入れ先出し装置: Last In Fast Out (LIFO)

入れた順番の逆に取り出せるメモリ:

(1) 3, 1, 2

を投入

(2) 2

個取り出す

(3) 8, 6

を投入

(4) 3

個取り出す

(5) 5, 4

を投入

個取り出す

スタック

Push

(スタックに入れる)

Pop

(スタックから出す)

取り出される列は 2, 1, 6, 8, 3, 4, 5 となる

3.3 Implementing Graph Traversal Using Queues and Stacks

(24)

講義で扱った内容はどこで触れられているか

3 Graph

3.1 Basic Definitions and Applications

3.2 Graph Connectivity and Graph Traversal

3.3 Implementing Graph Traversal Using Queues and Stacks 3.6 Directed Acyclic Graphs and Topological Ordering

4 Greedy Algorithm

4.4 Shortest Paths in a Graph

4.5 The Minimum Spanning Tree Problem

6 Dynamic Programming

6.8 Shortest Paths in a Graph

6.9 Shortest Paths and Distance Vector Protocols

7 Network Flow

7.1 The Maximum-Flow Problem and the Ford-Fulkerson Algorithm

24

(25)

有向非巡回グラフ

Directed Acyclic Graph (DAG)

閉路の無い有向グラフ

半順序性を持つ

トポロジカルソートにより、頂点を一列に並べるこ とができる ( 全順序に対応付けできる )

上図の場合

: A, D, B, E, C, F, G

など

ジョブのスケジューリング等で使われる

A

B

C

D

E

F G

3.6 Directed Acyclic Graph and Topological Ordering

(26)

講義で扱った内容はどこで触れられているか

3 Graph

3.1 Basic Definitions and Applications

3.2 Graph Connectivity and Graph Traversal

3.3 Implementing Graph Traversal Using Queues and Stacks 3.6 Directed Acyclic Graphs and Topological Ordering

4 Greedy Algorithm

4.4 Shortest Paths in a Graph

4.5 The Minimum Spanning Tree Problem

6 Dynamic Programming

6.8 Shortest Paths in a Graph

6.9 Shortest Paths and Distance Vector Protocols

7 Network Flow

7.1 The Maximum-Flow Problem and the Ford-Fulkerson Algorithm

26

(27)

最短経路問題を考える

ラベル付 ( 重み付 ) グラフ G=(V,E) が与えられたとき、

頂点 s から頂点 t への最短経路 s-t を求めたい

辺のラベルの意味:

地点間の道のり

地点間の移動時間

地点間の移動に要 する燃料の量

状態の遷移で失う資金

最小コストでの移動経路を発見したい

2

3 5 2

2

4 1

6 7

9 8

4

1 8

8 4

8 5

3 1 5

4

s

2

t

=23

=17

=18

(*) 実際はコスト16の道が存在する

4.4 Shortest Paths in a Graph

(28)

ダイクストラ法 (Dijkstra’s Algorithm)

1959 年: Edsger Dijkstra によって考案された

考え方 -- G(V,E) に対して

開始点

sV

から各頂点へ の最短経路を求める問題

いま、すでに部分

H

に関して、

最短経路が導出されている とする

s

からの距離が判明している

H

と接する

v V-H

に対し、

s

からの距離を考える

その距離の最小値を与える

v

を、

H

に追加する

28

1 2

2

2 3

1

s

a

b

c

d

e

f

g

h

i

5

3 3

5 4

7 1

4 1

H

5

0 2

1 2

赤字: 判明しているsからの最短距離

6 7

10 8 7

6

4.4 Shortest Paths in a Graph

(29)

ダイクストラ法 ( もう少し正確な定義 )

用語の定義:

グラフ

G(V,E)

において、

u, v V, e=(u,v) E

とする。

e=(u,v)

の長さを

le

あるいは

l(u,v)

で表すとする。

開始点を

s

とする。

d(u)

で、

s

から

u

までの最短距離を表すとする。

prev(v)

で、

s

から

v

への最短経路における

v

の直前の頂点を表す。

挙動の定義:

V

の部分集合

H

を以下のように作成する。

初期状態:

H = {s}, d(s)=0, d(v)=∞ (v≠s), prev(v)=null (vV)

とする。

u H

で辺

e=(u, v)

でつながっている

v ( V-H)

を考え、

d’(v) = min

e=(u,v):uH

{ d(u) + l

e

}

を計算する。

v V-H

において、上記をさらに最小化する

v

を選定し、その

v

H

に 追加し、その距離を

d(v)

とおき、その時の

u

を用いて、

prev(v)=u

とす る。

29

d(u1) d’(v1) = min {d(u)+le}

l(u1,v1)

d(u2) d’(v2) = min {d(u)+le}

l

d(v1) または d(v2)

のどちらか片方

4.4 Shortest Paths in a Graph

(30)

ダイクストラ法 : 計算量の考察

• While

文の内部は

n

回実行される。

Foreach

文の内部は

nm

回実行される。

実装によっては

O(nm)

となりえる。

• Q

に リストや配列を使う場合

Q.extractMin()

O(n)

の時間を要する

Q.extractMin()

n

回 呼び出される

O(n2)

• Q

2

分ヒープを使う場合

Q.extractMin()

O(log n)

の時間を要する

Q.extractMin()

の呼び出しは

n

回ある

O(n log n)

d[v]

の更新に伴うヒープの組換え処理に、

O(log n)

の時間を要する

d[v]

の更新は、

m

回発生する

O(m log n)

O( (n+m) log n ) 30

While Q is not empty u := Q.extractMin() Foreach v in Adj[u]

If d[v] > d[u] + length(u, v) Then, d[v] := d[u] + length(u, v)

prev[v]=u

( Q.changeKey() ) EndIf

EndFor EndWhile

4.4 Shortest Paths in a Graph

(31)

講義で扱った内容はどこで触れられているか

3 Graph

3.1 Basic Definitions and Applications

3.2 Graph Connectivity and Graph Traversal

3.3 Implementing Graph Traversal Using Queues and Stacks 3.6 Directed Acyclic Graphs and Topological Ordering

4 Greedy Algorithm

4.4 Shortest Paths in a Graph

4.5 The Minimum Spanning Tree Problem

6 Dynamic Programming

6.8 Shortest Paths in a Graph

6.9 Shortest Paths and Distance Vector Protocols

7 Network Flow

7.1 The Maximum-Flow Problem and the Ford-Fulkerson Algorithm

(32)

最小全域木を考える

Minimum Spanning Tree Problem

ラベル付 ( 重み付 ) グラフ G(V, E) が与えられたとき、ラ ベルの和が最小となる全域木を作りたい

全域木 G(V, T)

V

のすべての頂点で構成される木

最小全域木

eT Ce

を最小にする

T

で作られる

G(V,T) (Ce

は辺

e

のラベル

)

例:ラベルを地点間の配線コストとする

このとき、全地点がつながるネットワークを

最小コストで配線したい

32

2

3 5

2 2

4 1

6 7

9 8

4

1 8

8 4

8 5

3 1 5

4 2

4.5 The Minimum Spanning Tree Problem

(33)

プリム法 : 計算量の考察

• While

文の内部は

n

回実行される。

Foreach

文の内部は

nm

回実行される。

実装によっては

O(nm)

となりえる。

• Q

に リストや配列を使う場合

Q.extractMin()

O(n)

の時間を要する

Q.extractMin()

n

回 呼び出される

O(n2)

• Q

2

分ヒープを使う場合

Q.extractMin()

O(log n)

の時間を要する

Q.extractMin()

の呼び出しは

n

回ある

O(n log n)

c[v]

の更新に伴うヒープの組換え処理に、

O(log n)

の時間を要する

c[v]

の更新は、

m

回発生する

O(m log n)

While Q is not empty u := Q.extractMin() Foreach v in Adj[u]

If c[v] > length(u, v) Then, c[v] := length(u, v)

prev[v] := u

( Q.changeKey() ) EndIf

EndFor EndWhile

4.5 The Minimum Spanning Tree Problem

(34)

講義で扱った内容はどこで触れられているか

3 Graph

3.1 Basic Definitions and Applications

3.2 Graph Connectivity and Graph Traversal

3.3 Implementing Graph Traversal Using Queues and Stacks 3.6 Directed Acyclic Graphs and Topological Ordering

4 Greedy Algorithm

4.4 Shortest Paths in a Graph

4.5 The Minimum Spanning Tree Problem

6 Dynamic Programming

6.8 Shortest Paths in a Graph

6.9 Shortest Paths and Distance Vector Protocols

7 Network Flow

7.1 The Maximum-Flow Problem and the Ford-Fulkerson Algorithm

34

(35)

最短経路問題の解法

ダイクストラ法

すべての辺の重みが非負の場合に適用可能

貪欲法

(Greedy Algorithm)

の一種

ベルマン・フォード法

辺の重みに負があっても良いケースがある(有向グラフ で、有向閉路の和が負でない場合)

動的計画法

(Dynamic Programming)

の一種

5

-5 7

9 -2

4

s

t

コストが、資金の支出の場合、

6.8 Shortest Paths in a Graph

(36)

ベルマン・フォード法

i 回目から、 i+1 回目への計算 ( 漸化式 ) を考える

ここで、

i

は、拡散量

(s

から伝搬した辺の数

)

に相当する

i 回目 ( i 個の辺の伝搬を考えたとき ) における、頂点 s から頂 点 v までの最短距離を OPT(i,v) とする。このとき、以下が言 える。

OPT(i+1, v) = min

unbr(v)

{OPT(i,u)+C

uv

}

(*)

ここで

nbr(v)

は、

v

の近隣頂点

(

自分自身も含む

)

の集合とする また

Cuv

は辺

(u,v)

のコストとし、便宜上

Cvv=0

とする。

初期条件 (i=0 のとき )

OPT(0,s)=0, OPT(0,v)=∞ (vV, v≠s) 36

6.8 Shortest Paths in a Graph

(37)

OPT(i+1, v) = min

unbr(v)

{OPT(i,u)+C

uv

} の意味

v a

b

c

C

bv

C

av

C

cv

OPT(i,a) OPT(i,b)

OPT(i,c)

C

vv

(=0) OPT(i+1,v) は、

上記で最小のものとする

OPT(i,v)

OPT(i,v)

OPT(i,a)+C

av

OPT(i,b)+C

bv

OPT(i,c)+C

cv

6.8 Shortest Paths in a Graph

(38)

講義で扱った内容はどこで触れられているか

3 Graph

3.1 Basic Definitions and Applications

3.2 Graph Connectivity and Graph Traversal

3.3 Implementing Graph Traversal Using Queues and Stacks 3.6 Directed Acyclic Graphs and Topological Ordering

4 Greedy Algorithm

4.4 Shortest Paths in a Graph

4.5 The Minimum Spanning Tree Problem

6 Dynamic Programming

6.8 Shortest Paths in a Graph

6.9 Shortest Paths and Distance Vector Protocols

7 Network Flow

7.1 The Maximum-Flow Problem and the Ford-Fulkerson Algorithm

38

(39)

ベルマンフォード法の分散化

グラフ G(V,E) において、各頂点は、辺で接続する

もう片方の頂点と通信を行うものとする。

このとき、

各頂点

u

から、頂点

v (nbr(u))

に向けて、

OPT(u)+Cuv

を発信する

受信側の頂点

v

では、受信した値の中

(

他者からのもの も含む

)

で、最小のものを

OPT(v)

として選ぶ

開始点

s

OPT(s)

0

に固定する

という処理を行うと、ベルマンフォード法を分散的 に実装できる

u v

OPT(u) + Cuv

6.9 Shortest Paths and Distance Vector Protocols

(40)

ベルマンフォード法の分散化:

各頂点の動作

40

u

v

3

v

1

v

2

OPT(u) + C uv3

OPT(u)

頂点 u からの送信

(

定期的に行う

)

v

u

3

u

1

u

2

OPT(u3) + C u3v

If OPT(v) >

受信結果

OPT(v) :=

受信結果

EndIf

頂点 v での受信と処理

6.9 Shortest Paths and Distance Vector Protocols

(41)

講義で扱った内容はどこで触れられているか

3 Graph

3.1 Basic Definitions and Applications

3.2 Graph Connectivity and Graph Traversal

3.3 Implementing Graph Traversal Using Queues and Stacks 3.6 Directed Acyclic Graphs and Topological Ordering

4 Greedy Algorithm

4.4 Shortest Paths in a Graph

4.5 The Minimum Spanning Tree Problem

6 Dynamic Programming

6.8 Shortest Paths in a Graph

6.9 Shortest Paths and Distance Vector Protocols

7 Network Flow

7.1 The Maximum-Flow Problem and the Ford-Fulkerson Algorithm

(42)

最大流問題 Maximum Flow Problem

ラベル付 ( 重み付 ) グラフ G(V, E) が与えられたとき、流入点 s から流出点 t までの総流量を最大化したい

辺のラベルの意味: 流量の容量 ( 最大量 )

運べる荷物の量

流せる水の量

送れるパケット数

このとき、

s

に流れ込む流量

= t

から流れ出る流量

(

グラフの外から見た場合

) s

から流れ出す流量

= t

に流れ込む流量

(

グラフの中で見た場合

)

である。

この量の最大値

(

とそのときのフロー

)

をどう求めればよいか?

42

2

3 5 2

2

4

1 6 7

9 8

4

1 8

8 4

8 5

3 1 5

4 2

s

2

t

2 5 5

5 3

5 3

1 1 1

1 1

4 4

10 4

10 7.1 The Maximum-Flow Problem and the Ford-Fulkerson Algorithm

(43)

フローの定式化

辺を流れるフロー

頂点への流入量と流出量

u v

f(u,v) f(u, v) ≦ C(u, v) f(v, u) = - f (u, v)

-C(v, u)

f(u, v)

C(u, v)

ただし

C(u, v) = C(v, u)

とは限らない

C(u,v) C(v,u)

v

流入量 : f

in

(v) = ∑

uV, f(u,v)>0

f(u,v) 流出量 : f

out

(v) = ∑

wV, f(v,w)>0

f(v,w) v≠s,t であれば f

in

(v) = f

out

(v)

総流量 : total(f)= f

out

(s) = f

in

(t)

7.1 The Maximum-Flow Problem and the Ford-Fulkerson Algorithm

(44)

フォード・ファルカーソン法 Ford-Fulkerson Algorithm

考え方

s-t

間の何らかの道を考え、その流量の上限 を算出する

そのフロー

f

を容量

C

から引いた値(残余容 量)を計算し、グラフから差し引く ・・・そのグ ラフを

Gf

とする

Gf

に対して、同様のことをする(つまり、

s-t

間の何らかの道を考え、その流量の上限を 算出し、総フローを算出し、容量から差し引 いて・・・)

s-t

間の道が無くなれば、終了

44

s t

u

v

20 30

10

20 20

20

30

10

10 10

s t

u

v

40 10

10

0 40

0

50

10

10 10

20

フローに沿って

-20

10

s t

u

v

40 20

0

0 40

0

40

20

0 フローに沿って(さらに) 20

-10

s-t間の道がなくなった

(容量>0の弧についてのみ考える)

このとき差し引いている 総フローが求める最大流

7.1 The Maximum-Flow Problem and the Ford-Fulkerson Algorithm

(45)

フォード・ファルカーソンの アルゴリズム

Max-Flow(G(V,E), s, t)

e

E, f(e)=0

While any paths from s to t exist in residual graph Gf P := simple-path(s,t) in Gf

f’ := augment(f, P) Update f to be f’

Update Gf to be Gf’

EndWhile Return f

フロー

f

に道

P

を流れるフローの上限分を 追加し、それを

f’

に代入する処理

道の発見には

「幅優先探索」「深さ優先探索」

などが用いられる

このアルゴリズムの停止性について

7.1 The Maximum-Flow Problem and the Ford-Fulkerson Algorithm

(46)

本日の進め方

1.これまでの講義で扱ってきた部分をピックアップ そして、

どのような位置づけになっているか どのような記述になっているか

を確かめる

2.関連する重要キーワードをピックアップ そして、その意味について、考える

46

(47)

キーワード

Greedy Algorithm ( 貪欲アルゴリズム )

Divide and Conquer ( 分割統治法 )

Dynamic Programming ( 動的計画法 )

NP and Computational Intractability

Approximation Algorithms

Local Search

Randomized Algorithms

(48)

Greedy Algorithm ( 貪欲アルゴリズム )

「小さなステップで、より良い方向に進んでいくと、最終 的に、最適解に到達できる」 アルゴリズムのファミリー

「ローカルな問題を解決し、積み上げていくと(それ自体 は正しいのかどうか自明ではないが)、最終的に全体の 問題を解決できる」アルゴリズムのファミリー

例)

ダイクストラ法

プリム法

Interval Scheduling

問題

Optimal Caching

問題

Huffman Codes and Data Compression

48

(49)

Divide and Conquer ( 分割統治法 )

「一つの問題を、複数の部分問題に分割し、それぞれ の部分問題について、同様の方法で解き、それらの解 を処理することで、問題の解に到達する」アルゴリズム のファミリー

「問題の分割・統合を再帰的に行うことによって問題を 解く」アルゴリズムのファミリー

例)

• Mergesort

• Finding the Closest Pair of Points

• Convolutions and the Fast Fourier Transform

(50)

Dynamic Programming ( 動的計画法 )

「貪欲アルゴリズム や 分割統治法よりも強力に問題を 解決する」アルゴリズム

「貪欲アルゴリズム や 分割統治法よりも適用範囲の広 い」アルゴリズム

「広い解の空間を作り出し、個別に最適解を計算し、注 意深くそれを伝搬させることで全体的な最適解に到達 する」アルゴリズム

「漸化式を走らせることで、力学的にそこにたどり着く

(収束する)」アルゴリズム

「分割統治法的な考えの潜んでいる」アルゴリズム

「貪欲アルゴリズムの反対の方向から攻める」アルゴリ ズム

例) ベルマンフォードのアルゴリズム

50

(51)

計算不可能な問題への 実用的アルゴリズム

NP and Computational Intractability

「計算複雑性」が理由で解けない問題が存在する。

Approximation Algorithms

最適解が得られなくても近似解を得られるものがある

(実用上十分であれば、良い、という考え方)

Local Search

いま考えられるよりも、より良い解にたどり着く(ただし、そ れが全体の最適解となっているかは不明)

(実用上十分であれば、良い、という考え方)

Randomized Algorithms

対象の期待値を問題にすることもある

(入力データを確率的に与えられている等)

動作を乱数にゆだねるものもある

(52)

「離散数学」 講義の内容(まとめ)

52

4 月 8 日 集合

4 月 15 日 関係 と 関数 4 月 22 日 順序集合 と 束 5 月 6 日 命題計算

5 月 16 日 ブール代数

5 月 20 日 グラフの構造と種類

5 月 27 日 グラフ探索アルゴリズム 6 月 3 日 最短経路問題

6 月 10 日 演習(レポート提出)

6 月 17 日 最小全域木、最大流問題 6 月 24 日 平面グラフ

7 月 1 日 スキップグラフ

7 月 8 日 アルゴリズム設計

参照

関連したドキュメント

Restricting the input to n-vertex cubic graphs of girth at least 5, we apply a modified algorithm that is based on selecting vertices of minimum degree, using operations that remove

In [4] it was shown that for an undirected graph with n nodes and m (undirected) edges, more than 2m - n chips guarantee that the game is infinite; fewer than m chips guarantee that

The case n = 3, where we considered Cayley’s hyperdeterminant and the Lagrangian Grass- mannian LG(3, 6), and the case n = 6, where we considered the spinor variety S 6 ⊂ P

This allows us obtain several linear time multi-sweep MNS algorithms for recognizing rigid interval graphs and unit interval graphs, generalizing a corresponding 3-sweep LBFS

3 Exceptional collections of line bundles on surfaces 1266 4 Heights of exceptional collections 1276 5 Secondary Burniat surfaces and effective divisors 1282 A Appendix: Acyclic

Directed postemergence (pineapple and weeds) interspace application – Apply Tide Hexazinone 75 WDG as a directed spray 3-10 months after planting in 50-200 gallons of

Directed postemergence (pineapple and weeds) interspace application – Apply Tide Hexar™ 2SL as a directed spray 3-10 months after planting in 50-200 gallons of water per

Legume Vegetables (Succulent or Dried) Crop Group 6 and Foliage of Legume Vegetables Crop Group 7 Onion, Bulb, Crop Subgroup 3-07A and Onion, Green, Crop Subgroup 3-07B.. Root