Professional Documents
Culture Documents
Chapter 12 Ngoc Le
Flows
Discrete Structures for Computing
Contents
Flows
Motivation
Max Flow
Max Flow & Min Cost
Algorithm
State-of-the-art
Max Flow
Exercise
Max Flow & Min Cost
Application
Multi-source Multi-sink
Maximum Flow Problem
Bipartite Matching
Vertex Capacities
Huynh Tuong Nguyen, Tran Tuan Anh, Nguyen Ngoc Le Maximum Path
{htnguyen;trtanh}@hcmut.edu.vn
12.1
Flows
Contents
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
1 Flows Ngoc Le
Motivation
Max Flow
Max Flow & Min Cost
2 Algorithm
Contents
State-of-the-art
Flows
Max Flow Motivation
12.3
Flows
Motivation
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
• Distributed manufacturing system :
((((M 1 ∧ M 4) ∨ M 2) ∧ M 5) ∨ (M 3 ∧ M 6)) ∧ (M 7 ∨ M 8)
• Production capacity of each branch is defined in graph G
• How to determine the production capacity (e.g. pieces/min)?
• How to determine the production paths with the minimum transportation cost ?
Contents
Flows
Motivation
Max Flow
Max Flow & Min Cost
Algorithm
State-of-the-art
Max Flow
Exercise
Max Flow & Min Cost
Application
Multi-source Multi-sink
Maximum Flow Problem
Bipartite Matching
Vertex Capacities
Maximum Path
Exercise
Numerical exercises
Application
12.4
Flows
Maximum flow problem
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Given data
• A directed graph G = (V, E) with source node s and sink node t Contents
Exercise
Numerical exercises
Application
12.5
Flows
Maximum flow problem with minimum cost
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Given data
• A directed graph G = (V, E) with source node s and sink node t
• capacity function c : E −→ R, i.e. c(u, v) ≥ 0 for any edge (u, v) ∈ E Contents
Flows
• cost function a : E −→ R, i.e. a(u, v) ≥ 0 for any edge (u, v) ∈ E
Motivation
Max Flow
Max Flow & Min Cost
Objective Algorithm
State-of-the-art
Send as much flow as possible with minimum cost such that Max Flow
• Multi-source Multi-sink
P
(u,v)∈E a(u, v)f (u, v) should be minimized Maximum Flow Problem
Bipartite Matching
Vertex Capacities
Maximum Path
Exercise
Numerical exercises
Application
12.6
Flows
State-of-the-art
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Flow Algorithms
• Linear programming
• Ford-Fulkerson algorithm O(E max |f |) Contents
Exercise
Numerical exercises
Application
12.7
Flows
Ford-Fulkerson’s algorithm for solving Max Flow Problem
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Input: graph G with flow capacity c, a source node s, and a sink node t
Output: a maximum flow f from s to t
k = 0; G(0) = G;
c(0) (u, v) = c(u, v), c(0) (v, u) = 0, ∀(u, v) ∈ G(0) ; Contents
Flows
While ∃ a path Π(k) (s, t) in G(k) such that c(k) (u, v) > 0, ∀(u, v) ∈ Π(k) do
Motivation
(k) (k) (k)
Find f (Π ) = min{c (u, v)|(u, v) ∈ Π }; Max Flow
Max Flow & Min Cost
(k)
For each edge (u, v) ∈ Π do Algorithm
If (u, v) ∈ G then State-of-the-art
Max Flow
(k+1) (k) (k)
c (u, v) = c (u, v) − f (Π ); Exercise
Max Flow & Min Cost
(k+1) (k) (k)
c (v, u) = c (v, u) + f (Π ); Application
Else Multi-source Multi-sink
Maximum Flow Problem
c(k+1) (u, v) = c(k) (u, v) + f (Π(k) ); Bipartite Matching
Vertex Capacities
c(k+1) (v, u) = c(k) (v, u) − f (Π(k) ); Maximum Path
k + +; Exercise
Numerical exercises
Application
12.8
Flows
Example 1
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
GG(0) B G(1) B
6 6 6 6
A 1 D A 1 D
8 4 8 4
C C Contents
Flows
G(2) B G B Motivation
6 6 6 6 Max Flow
Max Flow & Min Cost
Algorithm
A 1 D A 1 D
4 4 8 4 State-of-the-art
Max Flow
4 Exercise
Application
Multi-source Multi-sink
Maximum Flow Problem
k Π(k) (A,B) (A,C) (B,C) (B,D) (C,D) f (Π(k) ) Bipartite Matching
0 {(A,B),(B,D)} 6 - - 6 - 6 Vertex Capacities
1 {(A,C),(C,D)} - 4 - - 4 4 Exercise
6 4 - 6 4 10 Numerical exercises
Stop with fmax = 10 Application
12.9
Flows
Example 2
Huynh Tuong Nguyen,
GG(0) B G(1) 1 B Tran Tuan Anh, Nguyen
6 6 5 6 Ngoc Le
A 1 D A 1 D
8 4 8 3
1
C C
Contents
6
G(2) 1 B G(3) B 5 Flows
5 6 1 Motivation
Max Flow
Max Flow & Min Cost
A 1 D A 1 D
5 5 Algorithm
3 4 4
State-of-the-art
3 Max Flow
C C Exercise
Max Flow & Min Cost
6 6 G B
Application
G(4) B
6 6
Multi-source Multi-sink
Maximum Flow Problem
Bipartite Matching
Vertex Capacities
A 1 D A 1 D Maximum Path
4 8 4 Exercise
4 4 Numerical exercises
C C Application
12.10
(k) (k)
Flows
Problem
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Find the maximum flow and the min-cut in the following network.
Contents
Flows
Motivation
Max Flow
Max Flow & Min Cost
Algorithm
State-of-the-art
Max Flow
Exercise
Max Flow & Min Cost
Application
Multi-source Multi-sink
Maximum Flow Problem
Bipartite Matching
G1 Vertex Capacities
Maximum Path
Exercise
Numerical exercises
Application
12.11
Flows
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
8
8 A C
6 8 Contents
S 9 2 Flows
Motivation
4 E Max Flow
B D 3 Max Flow & Min Cost
4 Algorithm
(G9 ) 2 State-of-the-art
Max Flow
F Exercise
Max Flow & Min Cost
Application
Multi-source Multi-sink
Maximum Flow Problem
Bipartite Matching
Vertex Capacities
Maximum Path
Exercise
Numerical exercises
Application
12.12
Flows
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
A
8 8 4 Contents
B
Flows
4
S 5 C 2 Motivation
Max Flow
Application
Multi-source Multi-sink
Maximum Flow Problem
Bipartite Matching
Vertex Capacities
Maximum Path
Exercise
Numerical exercises
Application
12.13
Flows
Resolution for Max Flow and Min Cost Problem
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Input: graph G with flow capacity c, a source node s, and a sink node t
Output: a maximum flow f from s to t
k = 0; G(0) = G; c(0) (u, v) = c(u, v), c(0) (v, u) = 0, ∀(u, v) ∈ G(0) ;
Contents
While ∃ a shortest path Π(k) (s, t) in G(k) such that c(k) (u, v) > 0,
∀(u, v) ∈ Π(k) do Flows
Motivation
Find f (Π(k) ) = min{c(k) (u, v)|(u, v) ∈ Π(k) } ; Max Flow
Max Flow & Min Cost
(k)
For each edge (u, v) ∈ Π do
Algorithm
If (u, v) ∈ G then State-of-the-art
Max Flow
c(k+1) (u, v) = c(k) (u, v) − f (Π(k) ); Exercise
Max Flow & Min Cost
(k+1) (k) (k)
c (v, u) = c (v, u) + f (Π );
Application
Else Multi-source Multi-sink
Maximum Flow Problem
c(k+1) (u, v) = c(k) (u, v) + f (Π(k) ); Bipartite Matching
Vertex Capacities
c(k+1) (v, u) = c(k) (v, u) − f (Π(k) ); Maximum Path
k + +; Exercise
Numerical exercises
Application
12.14
Flows
Multi-source Multi-sink Maximum Flow Problem
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
s
+∞ +∞ +∞
Exercise
Numerical exercises
t Application
12.15
Flows
Maximum Cardinality Bipartite Matching
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Algorithm
State-of-the-art
Max Flow
Exercise
Max Flow & Min Cost
Application
Multi-source Multi-sink
Maximum Flow Problem
Bipartite Matching
Vertex Capacities
Maximum Path
Exercise
Numerical exercises
Application
12.16
Flows
Minimum Path Cover in Directed Acyclic Graph
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
• Given a directed acyclic graph G = (V, E), we are to find the minimum
number of paths to cover each vertex in V. We can construct a bipartite Contents
graph G0 = (V out ∪ V in, E 0 ) from G, where Flows
1 V out = {v ∈ V : v has positive out-degree }. Motivation
Max Flow
2 V in = {v ∈ V : v has positive in-degree }.
Max Flow & Min Cost
3 E 0 = {(u, v) ∈ (V out, V in): (u, v) ∈ E}.
Algorithm
• Then it can be shown that G0 has a matching of size m iif there exists State-of-the-art
n − m paths that cover each vertex in G, where n is the number of Max Flow
Exercise
vertices in G. Max Flow & Min Cost
Exercise
Numerical exercises
Application
12.17
Flows
Maximum Flow Problem with Vertex Capacities
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
• Given a network N = (V, E), in which there is capacity at each node in addition
to edge capacity, that is, a mapping c : V → R+, denoted by c(v), such that the
flow f has to satisfy not only the capacity
P constraint and the conservation of flows, Contents
but also the vertex capacity constraint i∈V fi,v ≤ c(v), ∀v ∈ V \ s, t Flows
• =⇒ the amount of flow passing through a vertex cannot exceed its capacity. Motivation
Max Flow
• To find the maximum flow across N , we can transform the problem into the Max Flow & Min Cost
Exercise
Numerical exercises
Application
12.18
Flows
Maximum Independent Path
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Exercise
Numerical exercises
Application
12.19
Flows
Maximum Edge-disjoint Path
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Flows
• given a directed graph G = (V, E) and two vertices s and t
Motivation
• find the maximum number of edge-disjoint paths from s to t. Max Flow
• This problem can be transformed to a maximum flow problem by constructing a Max Flow & Min Cost
network N = (V, E) from G with s and t being the source and the sink of N Algorithm
respectively and assign each edge with unit capacity. State-of-the-art
Max Flow
Exercise
Max Flow & Min Cost
Application
Multi-source Multi-sink
Maximum Flow Problem
Bipartite Matching
Vertex Capacities
Maximum Path
Exercise
Numerical exercises
Application
12.20
Flows
Problem
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Find the maximum flow in the following networks
Contents
Flows
Motivation
Max Flow
Max Flow & Min Cost
Algorithm
State-of-the-art
Max Flow
Exercise
Max Flow & Min Cost
Application
Multi-source Multi-sink
Maximum Flow Problem
Bipartite Matching
Vertex Capacities
Maximum Path
Exercise
Numerical exercises
Application
12.21
Flows
Restaurant management
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Flows
Motivation
Max Flow
Max Flow & Min Cost
Algorithm
State-of-the-art
Max Flow
Exercise
Max Flow & Min Cost
Application
Multi-source Multi-sink
Maximum Flow Problem
Bipartite Matching
Vertex Capacities
Maximum Path
Exercise
Numerical exercises
Application
12.22
Flows
Production quantity measuring
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
• Distributed manufacturing system :
((((M 1 ∧ M 4) ∨ M 2) ∧ M 5) ∨ (M 3 ∧ M 6)) ∧ (M 7 ∨ M 8)
• Production capacity of each branch is defined in graph G
• How to determine the production capacity (e.g. pieces/min)?
• How to determine the production paths with the minimum transportation cost ?
Contents
Flows
Motivation
Max Flow
Max Flow & Min Cost
Algorithm
State-of-the-art
Max Flow
Exercise
Max Flow & Min Cost
Application
Multi-source Multi-sink
Maximum Flow Problem
Bipartite Matching
Vertex Capacities
Maximum Path
Exercise
Numerical exercises
Application
12.23
Flows
Travelling problem
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
• The table below gives the expenses for persons W , X, Y and Z to travel
to places A, B, C and D.
Contents
• The objective is to send each person to one of the four places such that
Flows
all places will be visited, whilst the total costs are as small as possible. Motivation
• Translate this problem into a maximum flow problem and solve it with Max Flow
Max Flow & Min Cost
the maximum flow algorithm.
Algorithm
State-of-the-art
Max Flow
A B C D
Exercise
W 16 12 11 12 Max Flow & Min Cost
X 13 11 8 14 Application
Y 10 6 7 9 Multi-source Multi-sink
Maximum Flow Problem
Z 11 15 10 8 Bipartite Matching
Vertex Capacities
Maximum Path
Exercise
Numerical exercises
Application
12.24
Flows
Seminar assignment problem
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
• In class, we modeled a version of the problem where the total number of Flows
Exercise
Numerical exercises
Application
12.25
Flows
Blood donation problem
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
• The number of units of blood available in each of the four major blood groups and Flows
Motivation
the distribution of patients among the groups is summarized below. Max Flow
• type A patients can only receive type A or O; Max Flow & Min Cost
• type B patients can receive only type B or O;
Algorithm
• type O patients can receive only type O;
State-of-the-art
• type AB patients can receive any of the four types.
Max Flow
Exercise
Max Flow & Min Cost
Blood type A B O AB
Application
Supply 46 34 45 45
Multi-source Multi-sink
Demand 39 38 42 50 Maximum Flow Problem
Bipartite Matching
Vertex Capacities
Maximum Path
Give a max flow formulation that determines a distribution that satisfies the demands of a Exercise
maximum number of patients. Numerical exercises
Application
12.26
Flows
Energy supplying problem
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Dining Services wonders how little money they can spend on food while still supplying
sufficient energy (2000 kcal), protein (55g), and calcium (800mg) to meet the minimum
Federal guidelines and avert a potential lawsuit. A limited selection of potential menu
items along with their nutrient content and maximum tolerable quantities per day is given Contents
in the table below.
Flows
Motivation
Energy Protein Calcium Cost per serving
Max Flow
(kcal) (g) (mg) (cents) Max Flow & Min Cost
Oatmeal 110 4 2 3
Algorithm
Chicken 205 32 12 24
State-of-the-art
Eggs 160 13 54 13 Max Flow
Whole milk 160 8 285 9 Exercise
Cherry pie 420 4 22 20 Max Flow & Min Cost
Pork with beans 260 14 80 19 Application
Multi-source Multi-sink
Maximum Flow Problem
Bipartite Matching
Vertex Capacities
Formulate a linear program to find the most economical menu.
Maximum Path
Exercise
Numerical exercises
Application
12.27
Flows
Circulation problem
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Given data
• A directed graph G = (V, E) with source node s and sink node t
• lower bound l(u, v) and upper bound u(u, v) ≥ 0 for any edge (u, v) ∈ E Contents
Flows
• cost function a : E −→ R, i.e. a(u, v) ≥ 0 for any edge (u, v) ∈ E
Motivation
Max Flow
Max Flow & Min Cost
Objective Algorithm
State-of-the-art
Send as much flow as possible with minimum cost such that Max Flow
• Multi-source Multi-sink
P
(u,v)∈E a(u, v)f (u, v) should be minimized Maximum Flow Problem
Bipartite Matching
Vertex Capacities
Maximum Path
Exercise
Numerical exercises
Application
12.28