CS473-Algorithms I - PowerPoint PPT Presentation

About This Presentation
Title:

CS473-Algorithms I

Description:

CS473-Algorithms I Lecture ? Network Flows Finding Max Flow – PowerPoint PPT presentation

Number of Views:60
Avg rating:3.0/5.0
Slides: 31
Provided by: Berka8
Category:

less

Transcript and Presenter's Notes

Title: CS473-Algorithms I


1
CS473-Algorithms I
  • Lecture ?
  • Network Flows
  • Finding Max Flow

2
FORD-FULKERSON METHOD / ALGORITHM
  • iterative algorithm start with initial flow f
    0 with f 0
  • at each iteration, increase f by finding an
    augmenting path
  • repeat this process until no augmenting path can
    be found
  • by max-flow min-cut thm upon termination this
    process yields a max flow

FORD-FULKERSON-METHOD(G, s, t) initialize flow f
to 0 while ? an augmenting path p do augment
flow f along path p return f
3
FORD-FULKERSON METHOD / ALGORITHM
  • basic Ford-Fulkerson Algorithm data structures
  • note (u,v) ? Ef only if (u,v) ? E or (v,u) ? E
  • maintain an adj-list representation of directed
    graph G' (V', E'), where
  • E' (u,v) (u,v) ? E or (v,u) ? E, i.e.,
  • for each v ? Adju in G' maintain the record
  • note G' used to represent both G and Gf , i.e.,
    for any edge (u,v) ? E'
  • cu,v gt 0 ? (u,v) ? E and cf u,v gt 0 ? (u,v) ?
    Ef

v
f(u,v)
c(u,v)
cf (u,v)
4
FORD-FULKERSON METHOD / ALGORITHM
COMPUTE-GF (G', f) for each edge (u,v) ? E'
do if cu,v f u,v gt 0 then cf u,v ?
cu,v fu,v else cf u,v ? 0 return
G' CANCEL (G', u, v) min ? f u,v, f v,u f
u,v ? f u,v min f v,u ? f v,u min
FORD-FULKERSON (G', s, t) for each edge (u,v) ?
E' do f u,v ? 0 cf u,v ? 0 Gf ?
COMPUTE-GF(G', f) while ? an s t path p in
Gf do cf (p) ? min cf u,v (u,v) ? p for
each edge (u,v) ? p do f u,v ? f u,v
cf (p) CANCEL(G', u, v) Gf ?
COMPUTE-GF(G', f)
5
FORD-FULKERSON ALGORITHM
  • augmenting path in Gf is chosen arbitrarily
  • performance if capacities are integers O(E f)
  • while-loop time to find s t path in Gf
    O(E') O(E)
  • of while-loop iterations f, where f
    max flow
  • so, running time is good if capacities are
    integers and f is small

6
FORD-FULKERSON ALGORITHM
Gf0
f0
u
u
0/100
0/100
100
100
s
t
0/1
s
t
1
0/100
100
0/100
100
v
v
p lt s, u, v, t gt cf (p) 1 f1 f0
fp 01 1
7
FORD-FULKERSON ALGORITHM
Gf1
f1
u
u
1/100
0/100
100
99
1
s
t
1/1
s
t
1
99
0/100
100
1
1/100
v
v
p lt s, v, u, t gt cf (p) 1 f2 f1
fp 11 2
8
FORD-FULKERSON ALGORITHM
Gf2
f2
u
u
1/100
1/100
99
99
1
1
s
t
0/1
s
t
1
99
99
1/100
1
1
1/100
v
v
p lt s, u, v, t gt cf (p) 1 f3 f2
fp 21 3
9
FORD-FULKERSON ALGORITHM
Gf3
f3
u
u
2/100
1/100
98
99
2
1
s
t
1/1
s
t
1
99
98
1/100
2
1
2/100
v
v
p lt s, v, u, t gt cf (p) 1 f4 f3
fp 31 4
10
FORD-FULKERSON ALGORITHM
  • choose p lt s, u, v, t gt in odd iterations
  • choose p lt s, v, u, t gt in even iterations
  • 200 augmentations to reach f 200
  • might never terminate for non-integer capacities
  • efficient algorithms
  • augment along max-capacity path in Gf not
    mentioned in textbook
  • augment along breadth-first path in Gf
    Edmonds-Karp algorithm ? O(VE2)

11
EDMONDS-KARP ALGORITHM
  • def df (s,v) shortest path distance from s to
    v in Gf
  • unit edge weights in Gf ? df (s,v)
    breadth-first distance from s to v in Gf
  • L7 ? v ? V s,t d (s,v) in Gfs increases
    monotonically with each augmentation
  • proof suppose
  • (i) a flow f on G induces Gf
  • (ii) fp along an augmenting path in Gf produces
    f f fp on G
  • (iii) f on G induces Gf
  • notation d(s,v) df (s,v) and d(s,v) df
    (s,v)

12
ANALYSIS OF EDMONDS-KARP ALGORITHM
  • want to prove d' (s,v) d(s,v) ? v ? V s,t
  • for contradiction assume d'(s,v) lt d(s,v) for
    some v
  • without loss of generality assume d' (s,v) is
    minimal over all such vertices
  • i.e., d' (s,v) lt d' (s,u) ? u ? V s,t ? d'
    (s,u) lt d(s,u)
  • thus d' (s,u) lt d' (s,v) ? d' (s,u) d(s,u) (1)

13
ANALYSIS OF EDMONDS-KARP ALGORITHM
  • consider a shortest s v path p' s u ? v in
    Gf
  • d'(s,u) d'(s,v) 1 by subpath is also a
    shortest path
  • d' (s,u) lt d' (s,v) ? by (1), d' (s,u) d(s,u)
    (2)
  • consider this edge (u,v) ? Ef ' question was
    (u,v) ? Ef ?
  • YES i.e., (u,v) ? Ef ' and (u,v) ? Ef note
    f(u,v) lt c(u,v)
  • d(s,v) d(s,u) 1 by triangle inequality
  • d' (s,u) 1 by (2)
  • d' (s,v) ? d' (s,v) d(s,v)
    contradiction

14
ANALYSIS OF EDMONDS-KARP ALGORITHM
  • NO i.e., (u,v) ? Ef ' but (u,v) ? Ef note
    f(u,v)c(u,v)
  • fp pushes flow back along edge (u,v) ? (v,u) ? p
    in Gf
  • i.e., augmenting path p is of the form p s v
    ? u t
  • note p is a breadth-first path from s to t
    (Edmond-Karp algorithm)
  • d(s,v) d(s,u) 1 by subpath is also a
    shortest path
  • d' (s,u) 1 by (2)
  • (d' (s,v) 1) 1 by subpath is
    also a shortest path
  • d' (s,v) 2
  • lt d'(s,v) ? d'(s,v)
    d(s,v) contradiction

15
ANALYSIS OF EDMONDS-KARP ALGORITHM
  • what is the bound on the total of
    augmentations?
  • def an edge (u,v) in Gf is critical on an
    augmenting path p in Gf if cf (u,v) cf (p)
  • at least one edge on an augmenting path must be
    critical
  • a critical edge disappears from Gf after the
    augmentation
  • f '(u,v) (ffp)(u,v) f (u,v) fp(u,v)
  • f (u,v) (c(u,v) f (u,v)) c(u,v)
  • ? cf ' (u,v) c'(u,v) f '(u,v) c(u,v)
    c(u,v) 0

16
ANALYSIS OF EDMONDS-KARP ALGORITHM
  • Thm number of flow augmentations is O(EV)
  • proof find a bound on the number of times an
    edge (u,v) becomes critical
  • let (u,v) becomes critical the first time along
    path p s u ? v t in Gf
  • d(s,v) d(s,u) 1 (1), since p is a shortest
    path
  • then (u,v) disappears from the residual network
  • (u,v) can reappear an another augmenting path
  • only after net flow from u to v is decreased
  • this only happens if (v,u) appears on an
    augmenting path

17
ANALYSIS OF EDMONDS-KARP ALGORITHM
  • assume this event occurs along a path p' s u
    ? v t in Gf ' later
  • d'(s,u) d'(s,v) 1 since p' s u ? v
    t is a shortest path
  • d(s,v) 1 by L7
  • (d(s,u) 1) 1 since p' s u
    ? v t is a shortest path
  • d(s,u) 2 ? d' (s,u) d(s,u) 2
  • i.e., d(s,u) increase by 2 each time (u,v)
    becomes critical, except the first time
  • thus each edge (u,v) can become critical at most
    O(V) times, since
  • 1 d(s,u) V - 2 and d(s,u) never decreases
    by L7
  • ?(E) edges in Gfs ? of flow augmentations
    O(VE)
  • running time of Edmonds-Karp algorithm E
    O(VE) O(E2V)
  • finding an augmenting path in a Gf
    breadth-first search O(E)

18
MAXIMUM BIPARTITE MATCHING PROBLEM
  • many combinatorial optimization problems can be
    reduced to a max-flow problem
  • maximum bipartite matching problem is a typical
    example

19
MAXIMUM BIPARTITE MATCHING PROBLEM
  • given an undirected graph G (V, E)
  • def a matching is a subset of edges M ? E such
    that ? v ? V, at most one edge of M is incident
    to v
  • def a vertex v ? V is matched by a matching M if
    some edge M is incident to v, otherwise v is
    unmatched
  • def a maximum matching M is a matching M of
    maximum cardinality, i.e., M M for any
    matching M
  • def G(V,E) is a bipartite graph if VL?R where
    LnR? such that E(u,v) u ? L and v ? R

20
MAXIMUM BIPARTITE MATCHING PROBLEM
  • applications job task assignment problem
  • Assigning a set L of tasks to a set R of machines
  • (u,v) ? E ? task u ? L can be performed on a
    machine v ? R
  • a max matching provides work for as many machines
    as possible

21
MAXIMUM BIPARTITE MATCHING PROBLEM
  • example two matchings M1 M2 on a sample graph
    with M1 2 M2 3

L
R
L
R
u1
u1
v1
v1
u2
u2
v2
v2
u3
u3
v3
v3
u4
u4
v4
v4
u5
u5
M1 (u1,v1), (u3,v3)
M2 (u2,v1), (u3,v2) , (u5,v3)
22
FINDING A MAXIMUM BIPARTITE MATCHING
  • idea construct a flow network in which flows
    correspond to matchings
  • define the corresponding flow network G'(V', E')
    for the bipartite graph as
  • V' V ? s ? t s, t ? V
  • E' (s,u) ? u ? L?(u,v) u ? L, v ? R, (u,v)
    ? E ?(v,t) ? v ? R
  • assign unit capacity to each edge of E'

23
FINDING A MAXIMUM BIPARTITE MATCHING
1
u1
u1
v1
1
1
v1
1
u2
u2
1
1
1
v2
1
v2
1
u3
s
t
u3
1
1
v3
1
1
v3
1
u4
u4
1
1
v4
v4
1
u5
u5
24
FINDING A MAXIMUM BIPARTITE MATCHING
  • def a flow f on a flow network is integer-valued
    if f(u,v) is integer ?u,v ? V
  • L8 (a) IF M is a matching in G, THEN ? an
    integer-valued f on G' with f M (b) IF
    f is an integer-valued f on G', THEN ? a
    matching M in G with M f

25
FINDING A MAXIMUM BIPARTITE MATCHING
  • proof L8 (a) let M be a matching in G
  • define the corresponding flow f on G' as
  • ?u,v?M f(s,u)f(u,v)f(v,t) 1 f(u,v) 0 for
    all other edges
  • first show that f is a flow on G'
  • 1 unit of flow passes thru the path s ? u ? v ? t
    for each u,v ? M
  • these paths are disjoint s t paths, i.e., no
    common intermediate vertices
  • f is a flow on G' satisfying capacity constraint,
    skew symmetry flow conservation
  • because f can be obtained by flow augmentation
    along these s t disjoint paths

26
FINDING A MAXIMUM BIPARTITE MATCHING
  • second show that f M
  • net flow accross the cut (s ? L, R ?t) f
    by L3
  • f f (s ? L, R ? t) f (s, R ? t) f (L, R
    ? t) f (s, R ? t) f (L, R) f (L, t)
    0 f (L, R) 0 f (s, R ? t) f (L, t)
    since ? no such edges f (L, R) M
    since f(u,v) 1 ?u ? L, v ? R (u,v) ? M

27
FINDING A MAXIMUM BIPARTITE MATCHING
  • proof L8 (b) let f be a integer-valued flow in
    G'
  • define M(u,v) u ? L, v ? R, and f (u,v) gt 0
  • first show that M is a matching in G i.e., all
    edges in M are vertex disjoint
  • let pe(u) / pl(u) positive net flow entering /
    leaving vertex u, ?u ? V
  • each u ? L has exactly one incoming edge (s,u)
    with c(s,u)1 ? pe(u) 1 ?u?L

28
FINDING A MAXIMUM BIPARTITE MATCHING
  • since f is integer-valued ?u ? L, pe(u) 1??
    pl(u) 1 due to flow conservation ? ?u ? L,
    pe(u)1?? ? exactly one vertex v?R ? f(u,v)
    1 to make pl(u) 1
  • thus, at most one edge leaving each vertex u ? L
    carries positive flow 1
  • a symmetric argument holds for each vertex v ? R
  • therefore, M is a matching

29
FINDING A MAXIMUM BIPARTITE MATCHING
  • second show that M f
  • M f (L, R) by above def for M since f
    (u,v) is either 0 or 1
  • f (L, V' s L t)
  • f (L,V') f (L,s) f (L,L) f (L,t)
  • 0 f (L,s) 0 0
  • f (L,s) f (s,L) f due to skew
    symmetry then def.

f (L,V') f (L,V') 0 due to flow cons. f (L,t)
0 since no edges from L to t
30
FINDING A MAXIMUM BIPARTITE MATCHING
  • example a matching M with M 3 a f on the
    corresponding G' with f 3

u1
u1
v1
v1
1
1
u2
u2
1
1
v2
v2
1
1
u3
u3
s
t
v3
v3
1
u4
u4
1
v4
v4
1
u5
u5
Write a Comment
User Comments (0)
About PowerShow.com