0% found this document useful (0 votes)
8 views40 pages

Lecture 27 - MaximumFlow - NP-Completeness

pttkgt

Uploaded by

Ngọc Hồ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views40 pages

Lecture 27 - MaximumFlow - NP-Completeness

pttkgt

Uploaded by

Ngọc Hồ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

Lecture 27.

Maximum Flow / P or NP
Introduction to Algorithms
Sungkyunkwan University

Hyunseung Choo
[email protected]

Superintelligence Laboratory Copyright 2000-2022 Superintelligence


H.CHOO
Laboratory
1/39
Max Flow Problem
 𝑮 = 𝐺(𝑉, 𝐸)
 𝒙𝑖𝑗 = flow on arc (𝑖, 𝑗)
 𝒖𝑖𝑗 = capacity of flow in arc (𝑖, 𝑗)
 𝒔 = source node
 𝒕 = sink node
 Maximize 𝒗
Subject to: σ𝒋 𝒙𝒊𝒋 − σ𝒌 𝒙𝒌𝒊 = 𝟎 for each 𝒊  𝒔, 𝒕
σ𝒋 𝒙𝒔𝒋 = 𝒗
𝟎 ≤ 𝒙𝒊𝒋 ≤ 𝒖𝒊𝒋 for all (𝒊, 𝒋) ∈ 𝑬

Superintelligence Laboratory H.CHOO 2/39


Maximum Flows
 We refer to a flow x as maximum if it is feasible and
maximizes v
 Our objective in the max flow problem is to find a
maximum flow

1
10, 8 8,7

s 1,1
t

6, 5 10,6
2

A max flow problem


Capacities and a non-optimum flow
Superintelligence Laboratory H.CHOO 3/39
Feasibility Problem: Find a Feasible Flow

warehouses retailers

6 1

6 6
5 2

7 7
4 3

8 6
5 4

9 5
4 5

Is there a way of shipping from the warehouses to


the retailers to satisfy demand?
Superintelligence Laboratory H.CHOO 4/39
Transformation to a Max Flow Problem
warehouses retailers

6 1
6
6 6
5 5 2 6

4 7 77
s 4 3 t
6
5
8 6
5 4 4 5

9 5
4 5

There is a 1-1 correspondence with flows from s to t


with 24 units (why 24?) and feasible flows for the
transportation problem
Superintelligence Laboratory H.CHOO 5/39
Feasibility Problem: Find a Matching

persons tasks

1 5

2 6

3 7

4 8

Is there a way of assigning persons to tasks so that each


person is assigned a task, and each task has a person
assigned to it?
Superintelligence Laboratory H.CHOO 6/39
Transformation to a Max Flow Problem

persons tasks

1 5
1 1

1 2 6 1
s 1 1 t
3 7
1
1
4 8

Does the maximum flow from s to t have 4 units?

Superintelligence Laboratory H.CHOO 7/39


Residual Networks

1 8,7
10, 8
1,1 uij ,xij
s t i j

6, 5 10,6
2

1
2 1
rij = uij - xij
8 7
s 1 t i j
1 4
xij
5 6
2
Let rij denote the
The Residual Network G(x) residual capacity of
arc (i,j)
Superintelligence Laboratory H.CHOO 8/39
Augmenting Paths

 An augmenting path is a path from s to t in the residual network

 The residual capacity of the augmenting path P

 d(P) = min{rij : (i,j)  P}

 To augment along P, send d(P) units of flow along each arc of the
path, then, modify x and the residual capacities appropriately

 rij := rij - d(P) and rji := rji + d(P) for (i,j)  P

1 1
2 1 2
8 7 8 8
s 1 t s 1 t
1 4 4
5 6 6 6
2 2

Superintelligence Laboratory H.CHOO 9/39


Ford-Fulkerson Max-Flow (1/16)

 Begin
 x := 0
 create the residual network G(x)
 while there is some directed path from s to t in G(x) do
 begin
 let P be a path from s to t in G(x)
  := d(P)
 send  units of flow along P
 update the r's
 end
 End {the flow x is now maximum}

Superintelligence Laboratory H.CHOO 10/39


Ford-Fulkerson Max-Flow (2/16)

4
2 5
3 1 1 1

2 2
s 4 t
3 1 2

This is the original network, plus reversals of the arcs

Superintelligence Laboratory H.CHOO 11/39


Ford-Fulkerson Max-Flow (3/16)

4
2 5
3 1 1 1

2 2
s 4 t
3 1 2

3
This is the original network, and
the original residual network

Superintelligence Laboratory H.CHOO 12/39


Ford-Fulkerson Max-Flow (4/16)

4
2 5
3 1 1 1

2 2
s 4 t
3 2
1

Find any s-t path in G(x)

Superintelligence Laboratory H.CHOO 13/39


Ford-Fulkerson Max-Flow (5/16)

4
2 5
3 1 1 1

2 1
2
s 4 t
2 1
3 1 2
1 1
3
Determine residual capacity  of the path
Send  units of flow in the path
Update residual capacities
Superintelligence Laboratory H.CHOO 14/39
Ford-Fulkerson Max-Flow (6/16)

4
2 5
3 1 1 1

2 1
2
s 4 t
1
2
3 2
1
1
3

Find any s-t path

Superintelligence Laboratory H.CHOO 15/39


Ford-Fulkerson Max-Flow (7/16)

4
2 5
3 1 1 1
2
1 11
s 4 t
1 1
2
3 1 2
1
1
1 1
3
Determine the residual capacity  of the path
Send  units of flow in the path
Update residual capacities
Superintelligence Laboratory H.CHOO 16/39
Ford-Fulkerson Max-Flow (8/16)

4
2 5
3 1 1 1
2
1 11
s 4 1
t
1
2
3 2
1
1
1 1
3

Find any s-t path

Superintelligence Laboratory H.CHOO 17/39


Ford-Fulkerson Max-Flow (9/16)

4
2 5
3 1 1 1
1 11
s 2
1 4 1
2
t
32 1
1
1
3 1

Determine the residual capacity  of the path


Send  units of flow in the path
Update residual capacities
Superintelligence Laboratory H.CHOO 18/39
Ford-Fulkerson Max-Flow (10/16)

4
2 5
3 1 1 1
1
2 11
s 21 4 1
2
t
2
3 1
1
1
3 1

Find any s-t path

Superintelligence Laboratory H.CHOO 19/39


Ford-Fulkerson Max-Flow (11/16)

4
2 5
3 1 1 1
1
2 11
s 2 4 2 t
1 1
2 1
1
11
2
1 2
1
3
Determine the residual capacity  of the path
Send  units of flow in the path
Update residual capacities
Superintelligence Laboratory H.CHOO 20/39
Ford-Fulkerson Max-Flow (12/16)

4
2 5
3 1 1 1
1
2 11
s 21
4 1
2
t
1
2 1
12 2
1
3

Find any s-t path

Superintelligence Laboratory H.CHOO 21/39


Ford-Fulkerson Max-Flow (13/16)

4
3
2 1
5
2
3 1 1 1
1 1

s 4 t
1 21
2 1
2
1
2
1 2
1
3
Determine the residual capacity  of the path
Send  units of flow in the path
Update residual capacities
Superintelligence Laboratory H.CHOO 22/39
Ford-Fulkerson Max-Flow (14/16)

4
3
2 5
1
23 1 1 1
1 1

s 21
4 1
2
t
1
2 1
2
1 2
1
3

There is no s-t path in the residual network


This flow is optimal
Superintelligence Laboratory H.CHOO 23/39
Ford-Fulkerson Max-Flow (15/16)

4
3
2 1
5
3
2 1 1 1
1 1

s 1
2 4 1
2 t
1
2
1
2
1 2
1
3

These are the nodes that are reachable from node s

Superintelligence Laboratory H.CHOO 24/39


Ford-Fulkerson Max-Flow (16/16)

1
2 5
1 1

2 2
s 4 t
2 2

Here is the optimal flow

Superintelligence Laboratory H.CHOO 25/39


How Do We Know
When a Flow Is Optimal?
1 8,8
10, 9

s 1,1
t

6,6 10,7
2
 METHOD
 There is no augmenting path in the residual network

1 reachable
1 8
from s in G(x)
9
s 1 t
3 not reachable
6
2
7 from s in G(x)

Superintelligence Laboratory H.CHOO 26/39


A Simple and Very Bad Example

1
M M

s 1 t
M M

Superintelligence Laboratory H.CHOO 27/39


After 1 Augmentation

1
M-1 M
1
s 1 t
M M-1
1
2

Superintelligence Laboratory H.CHOO 28/39


After Two Augmentations

1
M-1 M-1
1 1
s 1 t
M-1 M-1

1 1
2

Superintelligence Laboratory H.CHOO 29/39


After Three Augmentations

1
M-2 M-1
2 1
s 1 t
M-1 M-2

1 2
2

And so on
Superintelligence Laboratory H.CHOO 30/39
After 2M Augmentations

1
M M

s 1 t
M M

Superintelligence Laboratory H.CHOO 31/39


P or NP

I couldn’t find a
polynomial time
algorithm. I guess I’m
too dumb.

Superintelligence Laboratory H.CHOO 32/39


P or NP
I couldn’t find a
polynomial time
algorithm, because no
such algorithm exists !

Superintelligence Laboratory H.CHOO 33/39


P or NP

I couldn’t find a polynomial


time algorithm, but neither
could all these other smart
people.

Superintelligence Laboratory H.CHOO 34/39


P or NP

Superintelligence Laboratory H.CHOO 35/39


NP-Completeness
 Some problems are intractable
 They grow large, we are unable to solve them in reasonable
time
 What constitutes reasonable time?
Standard working definition: polynomial time
 For an input of size n, the worst-case running time is O(nk)
for some constant k
 Polynomial time: O(1), O(n lg n), O(n2), O(n3)
 Not in polynomial time: O(2n), O(nn), O(n!)

Superintelligence Laboratory H.CHOO 36/39


Polynomial-Time Algorithms
 Are some problems solvable in polynomial time?
 Every algorithm we’ve studied provides polynomial-time
solution to some problems
 We define P to be the class of problems solvable in polynomial
time
 Are all problems solvable in polynomial time?
 No: Turing’s “Halting Problem” is not solvable by any computer,
no matter how much time is given
 Such problems are clearly intractable, not in P

Superintelligence Laboratory H.CHOO 37/39


NP-Complete Problems
 Definition
 The class P (or NP) denotes the family of all problems that can
be solved by deterministic (nondeterministic) polynomial time
algorithms
All decision problems only answer YES or NO
 Nondeterministic polynomial time algorithm exist?

Superintelligence Laboratory H.CHOO 38/39


NP-Complete Problems
 The NP-Complete problems are an interesting class of
problems whose status is unknown
 No polynomial-time algorithm has been discovered for an NP-
Complete problem
 We call this the P = NP?
 The biggest open problem in CS
 Examples of NP-Complete problems:
 Vertex cover problem
 Traveling salesman problem
 Job scheduling problem
 …

Superintelligence Laboratory H.CHOO 39/39


Thanks to contributors
Mr. Pham Van Nguyen (2022)
Dr. Thien-Binh Dang (2017 – 2022)
Prof. Hyunseung Choo (2001 – 2022)

Superintelligence Laboratory Copyright 2000-2022 Superintelligence


H.CHOOLaboratory
40/39

You might also like