• 沒有找到結果。

Advanced Graph

N/A
N/A
Protected

Academic year: 2022

Share "Advanced Graph"

Copied!
34
0
0

加載中.... (立即查看全文)

全文

(1)

Advanced Graph

Homer Lee 2013/10/31

(2)

Reference

Slides from Prof. Ya-Yunn Su’s and Prof. Hsueh-I Lu’s course

(3)

Today’s goal

Flow networks

Ford-Fulkerson (and Edmonds-Karp)

Bipartite matching

(4)

Flow networks

(5)

Network

A directed graph G, each of whose edges has a capacity

Two nodes s and t of G

Denoted as (G,s,t)

*

s t

3

1 1

4

3 2

2

(6)

Flow

A flow of network (G,s,t) is (weighted) subgraph of G satisfying the capacity constraint and the conservation law

s t

3

1

4

3 2

2

2 1

1

1

2

1

(7)

Capacity constraint

Given capacity constraint function c, for all u, v ∈ V, 0 ≤ f(u,v) ≤ c(u,v)

流過edge的flow大小要小於流量限制

常表示為圖的edge的weight

s 3

1

4

3 2

2

2 1

1

1

2

1

(8)

Conservation Law

For all 𝑢 ∈ 𝑉 − {𝑠, 𝑡} , 𝑣∈𝑉 𝑓 𝑢, 𝑣 = 𝑣∈𝑉 𝑓 𝑣, 𝑢

換句話說,流進來的等於流出去的

上面的sigma是對所有的v,那假如u,v沒有接在一起

怎麼辦?

=> If (u,v)∉ E, f(u,v) = 0

s 3

1

4

3 2

2

2 1

1

1

2

1

(9)

What’s maximum flow problem?

The value of a flow is denoted as |f|

|f| = 𝑣∈𝑉 𝑓 𝑠, 𝑣 − 𝑣∈𝑉 𝑓 𝑣, 𝑠

Given flow network (G,s,t)

=> Find a flow of maximum value

(10)

A famous theorem

Maximum flow  Minimum cut

(11)

How to solve the problem?

s t

2

1 1

2

1 2

1

(12)

Ford-Fulkerson

Idea: Iteratively increase the value of the flow

Start with f(u,v) = 0

In each iteration

Find an augmenting path in the residual network 𝐺𝑓

Until no more augmenting paths exist

(13)

Residual Network

What if we choose the wrong path?

Just give it a second chance!!

For each edge (u,v) in G,construct 𝐺𝑓

If f(u,v) > 0, 𝐺𝑓 has an edge (v,u) with weight f(u,v)

If c(u,v) ≥ f(u,v) 𝐺𝑓 has an edge (u,v) with weight c(u,v) – f(u,v)

(14)

illustration

s t

3

1 1

4

3 2

2

2 1

1

1 1

2

1

s t

1

1

2

2 1 1

2 1

1

2

1

(15)

Some notes

Why adding an edge if c(u,v) ≥ f(u,v) ?

讓他有回頭的機會

|E𝑓|≤ 2|E|,Why?

Residual Networks上的edges會是原本Flow network 有的edge (with different weight) 或反方向

You can try to prove it by simply using case analysis.

(16)

How can residual network help us?

Lemma: Let G = (V,E) be a flow network, and let f be a flow in G. Let 𝐺𝑓 be the residual network of G induced by f. Let g be a flow in 𝐺𝑓. Then

f+g = is a valid flow in G.

Idea: capacity constraint and flow conservation still holds.

(17)

Augmenting paths

Given a flow network G and a flow f, an

augmenting path is a simple path from s to t in the residual network 𝐺𝑓

簡單的來說,就是在residual network上找一條可以 走的路

(18)

How can Augmenting paths help us?

There exists an augmenting path

=> there exist some potential flow in the path

=> By the capacity constraint, trivially the maximum flow in the path

= min{𝐶𝑓(u,v)|(u,v) is on augmenting path}

(19)

How do we know when we have found maximum flow?

From the maximum-flow-minimum-cut theorem, we stop when its residual graph contains no

augmenting graph

2 equivalent things:

1. f is a maximum flow in G

2. The residual network 𝐺𝑓 contains no augmenting path

(20)

Let’s prove it!

f is a maximum flow in G => The residual network 𝐺𝑓 contains no augmenting path

=> is simple, use contradiction.

If 𝐺𝑓 still contains augmenting paths, then we can still find 𝑓𝑝 to add to f. Then result in bigger flow |f| + |𝑓𝑝| > |f|

(21)

Let’s prove it!!

Goal: f is a maximum flow in G <= The residual network 𝐺𝑓 contains no augmenting path

Equivalent statement: f is not a maximum flow in G => The residual network 𝐺𝑓 contains some

augmenting path

If h is a flow whose value larger than that of f, then g = h – f has to be a positive flow in 𝐺𝑓

(22)

Let’s prove it!!!

Goal: f is not a maximum flow in G <= The

residual network 𝐺𝑓 contains some augmenting path

Here provides a sketch of the proof

If h is a flow whose value larger than that of f, then g = h – f has to be a positive flow in 𝐺𝑓

Then why g has to be a positive flow in 𝐺𝑓?

Do the remaining job by yourself!

(23)

Pseudo code

Ford-Folkerson (G,s,t){

for each edge (u,v) in G.E (u,v).f = 0

while there exists an augmenting path p in residual network 𝐺𝑓 𝒄𝒇(𝐩) = min(𝒄𝒇(u, v) | (u,v) is on p)

for each edge (u,v) on p //雙向都要考慮 if (u,v) ∈ E, (u,v).f += 𝒄𝒇 𝐩

else, (v,u).f -= 𝒄𝒇 𝐩 }

(24)

Example:

s t

3

1 1

4

3 2

2

(25)

Running time analysis

Initializing part: O(E)

How to find a path in residual network?

BFS or DFS

What time complexity does it take?

|E𝑓| ≤ 2|E|

It takes O(V+E𝑓) = O(E) times

(26)

Running time analysis

If the edge capacity are integer, and f be the maximum flow of the network

The for-loop may be executed at most f times(increment by 1 unit at a time)

Each time takes O(E) times

Totally O(E)+O(E)*O(f) = O(Ef)

=> This depends on f, not a good idea

(27)

Issues

What is C is not an integer?(each time the

amount that the augmenting path adding has no lower-bound)

How can we improve this bound?

(Edmonds-Karp)

(28)

To improve the time complexity

A key observation: Let P be a shortest path from s to t in the residual network 𝐺𝑓. Let g be the flow corresponding to P.

Then, the distance of any nodes v from s in 𝐺𝑓+𝑔 is no less than that in 𝐺𝑓

IDEA: If the above thing holds, it seems that the update times will be bounded

(29)

s t

3

2 2

3

3 2

2

2 1

1

1 1

2

1

1

0

2

1 2

3

1

1

2

2 1 1

2 1

1 1

1 1

1

(30)

s t

3

2 2

3

3 2

2

3 1

1

1 2

3

1

1

0

2

3 4

5

1 3

2 1

3 1

1 2

1 1

1

(31)

s t

3

2 2

3

3 2

2

3 2

2

2 1

3

2

0

2 3

3 1 2

1

2 1

(32)

Proof of the monotonically increased distance

Assume for contradiction that there is a node v whose distance d*(v) in 𝐺𝑓+𝑔 is less than its

distance d(v) in 𝐺𝑓

Let Q be a shortest path from s to v in 𝐺𝑓+𝑔

There has to be some node u on Q such that d*(u) ≥ d(u).(s is such a u.)

So we can assume Q = s~u->v, so d*(v) = d*(u)+1 and (u,v)∈ 𝐺𝑓+𝑔 . such u exists.

u s v

(33)

That’s what we said last page Note: d*(u) ≤ d(u)

s

v s

u v

(34)

Proof-contd.

Claim: (u,v) cannot be an edge in 𝐺𝑓 since the following contradiction:

d(v) ≤ d(u)+1 ≤ d*(u)+1 = d*(v)

Since (u,v) belongs to 𝐺𝑓+𝑔 but not 𝐺𝑓, we know g goes from v to u, but still reach the following contradiction:

d(v) = d(u)-1 ≤ d*(u)-1 = d*(v)-2

參考文獻

相關文件

6 《中論·觀因緣品》,《佛藏要籍選刊》第 9 冊,上海古籍出版社 1994 年版,第 1

After the Opium War, Britain occupied Hong Kong and began its colonial administration. Hong Kong has also developed into an important commercial and trading port. In a society

• helps teachers collect learning evidence to provide timely feedback &amp; refine teaching strategies.. AaL • engages students in reflecting on &amp; monitoring their progress

Robinson Crusoe is an Englishman from the 1) t_______ of York in the seventeenth century, the youngest son of a merchant of German origin. This trip is financially successful,

fostering independent application of reading strategies Strategy 7: Provide opportunities for students to track, reflect on, and share their learning progress (destination). •

Strategy 3: Offer descriptive feedback during the learning process (enabling strategy). Where the

How does drama help to develop English language skills.. In Forms 2-6, students develop their self-expression by participating in a wide range of activities

The existence of cosmic-ray particles having such a great energy is of importance to astrophys- ics because such particles (believed to be atomic nuclei) have very great