network flows chun-ta, yu graduate institute information management dept. national taiwan university

50
Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Upload: norman-preston

Post on 21-Jan-2016

214 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Network Flows

Chun-Ta, YuGraduate InstituteInformation Management Dept.National Taiwan University

Page 2: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Chapter 12

ASSIGHMENTS AND MATCHINGS

Page 3: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Outline

Introduction Bipartite Cardinality Matching Problem Bipartite Weighted Matching Problem Stable Marriage Problem Nonbipartite Cardinality Matching Problem

Page 4: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Introduction

Bipartite matching problem1. The cardinality problem

2. The weighted problem

Stable marriage problem Nonbipartite matching problem

Page 5: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Bipartite Cardinality Matching Problem Transform this problem into a maximum

flow problem in a simple network– Each arc has a unit capacity and each node has an

indegree of at most 1 or an outdegree of at most 1– Introduce a source node s and a sink node t

Solving this problem at worst-case ( ) O n m

Page 6: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Bipartite Cardinality Matching Problem

Page 7: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Bipartite Weighted Matching Problem Assignment problem Given a weighted bipartite network

1 2 1 2( , ) and arc weights

find a perfect matching of minimum weight

ijG N N A with N N c

( , )

1{ :( , ) }

2{ :( , ) }

1

1

0 ( , )

ij iji j A

ijj i j A

jij j i A

ij

Minimize c x

subject to

x for all i N

x for all i N

x for all i j A

Page 8: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Bipartite Weighted Matching Problem The assignment problem can be viewed as

adaptation of algorithm for the minimum cost flow problem

Four algorithm to solve:1. Successive Shortest Path Algorithm

2. Hungarian Algorithm

3. Relaxation Algorithm

4. Cost Scaling Algorithm

Page 9: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Successive Shortest Path Algorithm

Discuss in section 9.7 Augment 1 unit flow in every iteration Let S( S( n ,m ,Cn ,m ,C)) denote the time needed to

solve a shortest path problem with nonnegative arc lengths and nn11=|N=|N11||

The algorithm would terminate within n1 iterations and would require O(O(nn11S( S( n ,m ,Cn ,m ,C))))

Page 10: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Hungarian Algorithm

Discuss in section 9.7, primal-dual algorithm With a single supply node s*s* and a single

demand node t*.t*.At every iteration ,the primal-dual algorithm computes shortest path distance from s*s* to all other nodes

The algorithm would terminate within nn11 iterations and would require O(O(nn11S( S( n ,m ,Cn ,m ,C)) ))

Page 11: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Relaxation Algorithm

Closely related to the successive shortest path algorithm

Relax the constraint

thus allowing any node in NN22 to be assigned to more than one node in NN11

Overall running time O(O(nn11S( S( n ,m ,Cn ,m ,C)) ))

2{ :( , ) }

1 jij j i A

x for all i N

Page 12: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Stable Marriage Problem

A certain community consists of n men and n women. Each person ranks those of the opposite sex in accordance with his or her preferences for a spouse.

Unstable – if man-woman are not married to each other but prefer each other to their current spouses

For any set of rankings, we can always find a stable matching in O(O(nn22)) time

Page 13: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Stable Marriage Problem

The input to the stable marriage problem consists of two n x nn x n matrices.

Each rank is an integer between 1 and n Priority list is a vector of n elements for each

person, can be sorted using bucket sort in O(O(nn22)) time

Page 14: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Stable marriage algorithm

Propose-and-reject algorithm Time complexity:

– Each iteration each woman receiving a proposal either (1) receives her first proposal (2) rejects some proposal

– Each woman rejects any man’s proposal at most once, so total rejection times is (n-1)(n-1) for each woman

– Total time is O(O(nn22))

Man-optimal matching

Page 15: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Nonbipartite Cardinality Matching Problem Alternating Paths

– We refer to a path P=iP=i11-i-i22--……iikk in the graph as an alternating path with respect to a matching MM if every consecutive pair of arcs in the path contains one matched and one unmatched arc

ex : 1-2-4-3-5

Page 16: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Nonbipartite Cardinality Matching Problem Augmenting Paths

– We refer to an odd alternating path PP with respect to matching M as an augmenting path if the first and last nodes in the path are unmatched

ex : 1-2-4-3-5-6

– Interchanging the matched and unmatched arcs on augmenting paths can add one more cardinality

Page 17: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Symmetric Difference

Let SS11 and SS22 be two sets; the symmetric difference of these sets, denoted SS11⊕⊕SS22, is the set SS11⊕⊕SS22 = (= (SS11∪∪SS22)-()-(SS11∩∩SS22))

for example, SS11 = {4,5,7,8} and SS22 = {2,4,8,9} , then SS11⊕⊕SS22 ={2,5,7,9}

Page 18: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Property 12.6

If MM is a matching and PP is an augmenting path with respect to MM, then MM⊕⊕PP is a matching of cardinality ||MM| + 1| + 1. Moreover, in the matching MM⊕⊕PP, all the matched nodes in M remain matched and two additional nodes, namely the first and last nodes of PP, are matched

Page 19: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Property 12.7

If MM and M*M* are two matchings, their symmetric difference defines the subgraph G*G* = ( = (NN, , MM⊕⊕M*M*)) with the property that every component is one of the six types shown in Figure 12.7

Page 20: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University
Page 21: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Augmenting Path Theorem

If a node pp is unmatched in a matching MM, and this matching contains no augmenting path that starts at node pp, then node pp is unmatched in some maximum matching.

Page 22: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Bipartite Matching Algorithm

Start with a feasible matching MM (which might be a null matching) and then repeat the following step for every unmatched node

Try to identify an augmenting path starting at node pp. If we find such a path PP, replace MM with MM⊕⊕PP; otherwise, delete node pp and all the arcs incident to it from the graph

p N

Page 23: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Bipartite Matching Algorithm

Search algorithm

Page 24: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Bipartite Matching Algorithm

Page 25: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University
Page 26: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Bipartite Matching Algorithm

Time complexity:– The search algorithm execute at most nn times– For each node ii, the search procedure performs

one of the following two operations at most once (1) examine-even (2) examine-odd, the former operation require OO(|A(i)|(|A(i)|)) time, about O(O(mm))

– Total time O(O(nmnm))

Page 27: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Unique label property

A graph is said to possess a unique label property with respect to a given matching MM and a root node pp if the search procedure assigns a unique label to every labeled node irrespective of the order in which it examines labeled nodes

Page 28: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Bipartite network satisfy it; nonbipartite network doesn’t satisfy it

Page 29: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Flower and Blossoms

A flower, defined with respect to a matching MM and a root node pp, is a subgraph with two components:– Stem. A stem is an eveneven length alternating path that starts

at the root node pp and terminates at some node ww. We permit the possibility that p = wp = w, in which case we say that the stem is empty

– Blossom. A blossom is an oddodd length alternating cycle that starts and terminates at the terminal node ww of a stem and has no other node in common with the stem. We refer to node ww as the base of the blossom

Page 30: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Flower and Blossoms

Page 31: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Property 12.9

a) A stem spans 2l+12l+1 nodes and contains ll matched arcs for some integer l 0≧l 0≧

b) A blossom spans 2k+12k+1 nodes and contains kk matched arcs for some integer k 1. ≧k 1. ≧ The matched arcs match all nodes of the blossom except its base

c) The base of blossom is an even node

Page 32: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Property 12.10

Every node ii in the blossom (except its base) is reachable from the root (or from the base of the blossom) through two distinct alternating paths. One has even length and the other has odd length

Page 33: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Contracting a Blossom

1. Introduce a new node b (pseudonode) and define its adjacency list A(A(bb)) = = A(A(ii11) A(∪) A(∪ ii22)∪)∪…… A(∪A(∪ jjkk))

2. Update the adjacency list of every node

by executing A(A(jj))==A(A(jj) {∪) {∪ bb}}

3. To be able to recover, set contracted node to “inactive” mode

( )j A b

Page 34: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University
Page 35: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University
Page 36: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Nonbipartite matching algorithm

Page 37: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Nonbipartite matching algorithm-- Find a augmenting path

Page 38: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Complexity of nonbipartite matching algorithm Lemma 12.13

– During an execution of the search procedure, the algorithm performs at most n/2n/2 contractions

Since each contraction adds at most one element to any adjacency list (the pseudonode), and since the algorithm performs at most n/2n/2 contractions, no adjacency list will ever contain more than 3n/23n/2

Each search procedure performs one of the following operation at most once: (1)it discovers that node ii is inactive (2)examine-odd(3)examine-even, (3) require ||AAcc(i)| 3n/2, ≦(i)| 3n/2, ≦ so running time is O(O(nn22))

Total time complexity O(O(nn33))

Page 39: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Chapter 13

MINIMUM SPANNING TREES

Page 40: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Outline

Introduction Optimality Condition Kruskal’s Algorithm Prim’s Algorithm Sollin’s Algorithm

Page 41: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Introduction

Page 42: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Optimality Condition

Cut Optimality Conditions– A Spanning tree T*T* is a minimum spanning tree

if and only if it satisfies the following cut optimality condition: For every tree arc ,

ccijij c≦c≦ klkl for every arc (k, l)(k, l) contained in the cut formed by deleting arc (i, j)(i, j) from T*T*

( , ) *i j T

Page 43: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Optimality Condition

Path Optimality Conditions– A spanning tree T* is a minimum spanning tree if

and only if it satisfies the following path optimality conditions: For every nontree arc (k, (k, l)l) of GG, ccijij c≦c≦ klkl for every arc (i, j)(i, j) contained in the path in T*T* connecting nodes kk and ll

Page 44: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Kruskal’s Algorithm

Time Complexity OO(mn )(mn )

Page 45: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Prim’s Algorithm

Time Complexity OO(m log n) (m log n)

Page 46: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Sollin’s Algorithm

Time Complexity OO(m log n)(m log n)

Page 47: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Summary of minimum spanning tree algorithm

Page 48: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Matroids and the Greedy Algorithm

Independent : a subset II of objects do not form a cycle in the network

Subset System (E, (E, ζ)ζ) : a finite set of objects E and nonempty collection ζζ of subsets of these objects

Matroid : a subset system satisfies the growth property that if IIpp and IIp+1p+1 are independent sets containing pp and p+1 p+1 elements, we always can find an element , satisfying the property that IIpp {e}∪{e}∪ is an independent set

1p pe I I

Page 49: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Matroids and the Greedy Algorithm

Maximal independent set : an independent set I satisfying the property that we cannot add any other element e to I and produce another independent set

Greedy algorithm:

Page 50: Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University

Thank You!