matchings-edmonds

# matchings-edmonds - g-\\/ashmgt0nUmver51tymSt.Lou1s...

This preview shows pages 1–20. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: g-\\/ashmgt0nUmver51tymSt.Lou1s Engineering Maximum Size Matchings in General Graphs Jon Turner Computer Science & Engineering Washington University www.ar1.wustl.edu/~jst :1,- Mshlngton UnwersuymStlouls Engineering Recap of Augmenting Path Method ﬂ ISearch for augmenting path and swap edges on path -In bipartite graph, find paths by building forest with tree roots at unmatched vertices .Basic step: choose unexamined edge {v,w} with v even and examine it >> if w is even, stop; path from root of tree containing v to root of tree containing w forms an augmenting path >> if w is unreached and matched, make w odd, mate(w) even, p (w)=v and p(mate(w))=w \$Wash1ngton UnwersuymStlouls Engineering Blossoms .In general graphs, path search can fail if an edge is selected which joins two even vertices in same tree >> if {v,w} is such an edge, the cycle induced by the tree path connecting v and w together with {v,w} is called a blossom. >> handle this case by shrinking the blossom, that is, treating the set of vertices if the blossom like a single vertex - A blossom is an odd-length cycle with one vertex incident to two non-matching edges >> this vertex is called the base of the blossom >> the base is an ancestor of all other vertices in the cycle >> base may have a matching edge to its parent or may be unmatched >> in either case, the base of the blossom is an even vertex in path search \$Msh1ngton UnwersuymStLouls Engineering - Theorem 9.3. If G’ is formed from G by shrinking a blossom b, then G’ contains an augmenting path if and only if G does For now, we prove only that if G’ contains an augmenting path P, then G also contains an augmenting path >> if b is not on P, then P is an augmenting path in G >> if b is on P, we can construct an augmenting path in G by expanding b and reconnecting the now separated parts of P by going around the blossom in the appropriate direction G’O—O—O—O—O—O G The proof of the other direction follows from Theorem 9.4, below :1,- Washmgton UnlverSItymStLouls Engineering Edmonds-Karp Algorithm - Replace each edge {X,y} with pair [X,y], [y,x] - Basic step: choose an unexamined edge [v,w] with v even and examine it >> if w is unreached and matched, make w odd, mate(w) even, p (w)=v and p(mate(w))=w >> if w even and v,w are in different trees, path from root of v’s tree to root of w’s tree forms an augmenting path >> if w is even and v and w are in same tree, edge {v,w} together with tree path joining v and w forms a blossom 0 let u be nearest common ancestor of v and w (in the tree) and condense all descendants of u that are ancestors of either v or w into a shrunken blossom b, and let p(b) = p(u); make b even IA vertex is called shrunken if at some point in the algorithm if it has been included in a blossom >> both original vertices and blossoms may become shrunken E \X/ashington University in St. Louis Engineering ab, Cd, ki, k/ :> _ eligible edges ab,ac,ah,ai, kh,ki, kl, kn :1,- Washmgton UniverSItymStlouls Engineering Review Questions . In the bottom right ﬁgure on page 6, which vertices are free? Which are matched? Which are unreached? List the vertices in each of the blossoms. For each blossom, which vertex is its base? . What’s the maximum possible number of blossoms in a graph on n vertices? Explain why a graph cannot have any more blossoms than this. . Draw a graph with at least 10 vertices that demonstrates that it’s possible to achieve the bound in the previous question. — Engineering E \X/ashington University in St. Louis - Theorem 9.4. The blossom shrinking algorithm finds an augmenting path <2 there is one in the original graph Proof. (=>) If the algorithm succeeds then we can find augmenting path in original graph by expanding blossoms in reverse order (<=) Note the following points (1) if v is reached and matched, mate(v) is also reached and in same tree (2) if v is a free vertex contained in a blossom b, then b is free (3) if algorithm fails then any two adjacent vertices that are either shrunken or even are contained in a common blossom when the algorithm halts Suppose algorithm fails, but there is an augmenting path p=[XO,...,X2,+1] and consider the situation just after algorithm halts >> note that X0 and X2,+1 are in different trees; let k be any integer such that xk+1 is in different tree from x0 and xk+1 is in different tree from xk >> by point (3) above, either xk or ka is odd and unshrunken >>assume (w.l.o.g.) that Xk is odd and unshrunken; mate(xk)=xk_1, so k must be even; letj be smallest integer such thatj is even and x, is odd and unshrunken — Engineering last odd & _ matching unshrunken vertex on ‘ ' edge implies ungﬁfuﬁ‘ken path, has odd Index k \X/ashington University in St. Louis must include some odd first odd & unmatched edge & unshrunken vertex unshrunken vertex since endpoints with even index in different trees >>there must be an odd, unshrunken vertex among XO,...,Xj_1 since if not (by point 3), x0,...,xj_1 would all be contained in a common blossom - since this blossom contains a free vertex x0, it must (by point 2) be a free blossom; this implies that matching edge to x, must also be part of the blossom, contradicting the assumption that xj is unshrunken >>|et i be the largest integer such that i<j and x, is odd and unshrunken; then i is odd which means mate(x,) = X,-+1 >>this in turn implies that X,+1,...,Xj_1 are contained in a single blossom that is incident to two matched edges, which is impossible I :1,- Mshlngton UniverSItymStlouis Engineering Implementing Edmonds-Karp I Replace each edge {u,v} with edges [u,v], [v,u] ICurrent shrunken graph is represented implicitly using partition data structure >>each set corresponds to a vertex in current shrunken graph and contains the original vertices contained in current vertex; define v if v is an original vertex origin(v) = { 0rigin(base(v)) if vis a blossom >>origin(v) initialized to v for all v; whenever blossom forms, the canonical vertex v of set representing the blossom has origin(v) set to the origin of the blossom >>so, origin(find(v)) always equals origin of largest blossom containing v and represents vertex containing v in current graph >>if v’=origin(find(v)) for all vertices v then edge [x’,y’] is the edge in current graph corresponding to original edge [X,y] 10 In :1,- Washmgton UnwersuymStLouls Engineering I For each odd vertex in blossom, define a bridge >> if examination of original edge [v,w] causes an odd vertex X to be shrunk into a blossom, bridge(x)=[v,w] ifx is an ancestor of v’ before condensation and bridge(x)=[w,v], otherwise IAlgorithm: for each v let origin(v)=v, and make v even if v is free, unreached otherwise; repeat the following >> choose unexamined original edge [v,w] with v’ even and examine it >> if w’ is unreached and matched, make w’ odd, mate(w’) even, p (w’)=v and p(mate(w’))=w’ >> if w’ is even and v’ and w’ are in different trees, stop and recover augmenting path >> if w’ is even and v' and w’ are in same tree, let u be nca(v’,w') o for every X that is a descendant of u and an ancestor of v’, perform link(find(u),find(x)) and ifX is odd let bridge(x)=[v,w] o for every X that is a descendant of u and an ancestor of w’, perform link(find(u),find(x)) and ifX is odd let bridge(x)=[w,v] - let origin(find(u))=u II \$Wash1ngton UanCFSIthStlDUIS Engineering - Edges eligible for selection are kept in a list .To recover augmenting paths, use bridge information and reversible list data structure >> suppose [v,w] is examined by algorithm and v’ and w’ are in different trees with roots X and y >> the augmenting path from X to y is reverse(path(v,x)) & path (w,y) where reverse reverses a list and path is defined by [a] ifa=b [a,p(a)] & path(p2(a),b) if a :e b and a is even pat/(cub) = . . [a] & reverse(path(c,mate(a))) If a :é b and a 18 odd & path(d,b) and [ad] = bridge(a) o where the first argument of path() is a descendant of the second >> this allows the augmenting path to be recovered in O(n) time 1’) , — E Washington University in St. Louis Engineering Detailed Implementation In following, G assumed to be in digraph form function path augpath(digraph G, matching M) vertex u,v,w,x,y; mapping state:vertex—>{unreached,even,odd}; mapping matched:vertex—>{true,false}; mapping mate, origin, pzvertex—>vertex; mapping bridge:vertex—>edge; partition(V); list Q; for u E V :5 state(u) := even; matched(u) := false; rof; for {u,v} E M => state(u), state(v) := unreached; matched(u), matched(v) := true; mate(u) := v; mate(v) := u; rof; I? — Engineering E Washington University in St. Louis Q := l]; for uE[1,n] 2 for [u,v]Eout(u) 2 if state(u)=even 2 Q := Q & [u,v] fi rof; rof; do Q 7: 2 MW] := Q(1); Q := Q[2--]; v’ := origin(find(v)); w’ := origin(find(w)); if v’ ¢ w’ and state(w’) = unreached 2 := mate(w’); state(w’) := odd; p(w’) := v’; state(x) := even; p(x) := w’; for [X,y] E out(x): [X,y] g: Q 2 Q := Q & [X,y] rof; | v’ ye w’ and state(w’) = even and not sametree(v’,w’) 2 X := v’; do p(x) 7e null 2 X := origin(find(p(x))); od; := w’; do p(y) 7: null 2 y := origin(find(p(y))); od; return reverse(path(v,x)) & path(w,y); E Washington University in St. Louis — Engineering v’ 7: w’ and state(w’) = even and sametree(v’,w’) => u := nca(v’,w’); X := v’; do X :e u = |ink(find(u),find(x)); if state(x) = odd => bridge(x) := [v,w]; for [x,y]Eout(X): [x,y] 6E Q 2 Q := Q & [x,y] rof; fi; X := origin(find(p(x))); od; X := w’; do X a: u => |ink(find(u),find(x)); if state(x) = odd => bridge(x) := [w,v]; for [x,y]Eout(X): [Xv] 6’5 Q = Q := Q & [x,y] rof; fi; X := origin(find(p(x))); I: \$Wash1ngton UnwersuymStLouis Engineering Analysis of Edmond-Karp I Main loop is executed at most 2m times since each (directed) edge is put on the queue at most once >> similarly, the for-loops that put edges on the queue contribute a total of 0(m) to the running time I Function call sametree(v’,w’) returns true if v’ and w’ are in the same tree, otherwise it returns false - Function call nca(v’,w’) returns nearest common ancestor of v’ and w’ in current shrunken graph .Implement sametree and nca by moving up tree paths (in current shrunken graph) from v’ and w’ in parallel >> stop either on reaching different free vertices or on reaching an ancestor of v’ that was visited previously in search from w’ or vice versa IK \$Wash1ngton UnwersuymStlouls Engineering .Can perform path searches for sametree and nca in time O(# of vertices visited) >> if v’ and w’ are in different trees it takes O(n) time to complete path searches (this case is used only once) >> if v' and w’ are in same tree then # of vertices visited is stwice # on cycle defining blossom that is about to be condensed >> there are Sn/Z blossoms, since formation of a blossom reduces the number of vertices by at least two >> hence, number of vertices on all blossom cycles is s3n/2 and total time spent executing sametree and nca is O(n) - By same argument, the total time spent shrinking blossoms is O(n), excluding the partition operations - Hence, number of partition operations is O(m) and augmenting path can be found in O(ma(m,n)) time ISO, can find max size matching in O(mna(m,n)) time 1’7 E \X/ashington University in St. Louis Exercises 1. Suppose that during the execution of the Edmonds-Karp algorithm, u is a vertex on some blossom and edge [x,y] is the bridge of u. Is it possible that X is an ancestor of u? Why or why not? Is it possible for u to be an ancestor of X? Why or why not? X cannot be an ancestor of u. The edge [X, y] was the one that formed the blossom. At the time, all the edges on the blossom were either ancestors of X or ancestors of y. 50 u might be an ancestor of X, but X cannot be an ancestor of u. — Engineering Let 2 be the nearest common ancestor ofx and y. Is 2 even or odd? Can it be matched? Can it be free? The nearest common ancestor of X and y is the base of the blossom, so 2 must be even. Consequently, it may be either matched or free. Let v be a vertex on the blossom that is not 2. Is v incident to a matching edge? Why or why not? V must be incident to a matching edge. In general, any vertex that has been reached but is not a tree root must be incident to matching edge, and only the base ofa blossom can be a tree root. Since v is in the blossom, it has been reached and since it’s not the base of the blossom, it must be matched. IO E Washington University in St. Louis 2. The figure below shows an intermediate state in the execution of Edmonds-Karp algorithm. Which edges are eligible to be processed next? Edges ah, ai, bj, ce, ej, gm, ki and k/ are all e/gib/e. Show the state after edges kl, ik, bj and gm have been selected. Engineering Show the state after edges kl, ik, bj and gm have been selected. If the edge j/ is selected next, what augmenting path is returned? abcdfegmj/ik If) E Washington University in St. Louis 3.The figure below show an intermediate state in the execution of the Edmonds- Karp algorithm. The edges shown next to certain vertices correspond to their bridge values. The partition data structure is shown at right and the queue of edges to be processed is at the top. queue: ae, ih, la, kd, In partition In the diagram at right, draw a closed curve around the sets of vertices that have been condensed into a single vertex in the current shrunken graph. If any of these sets contain subsets, corresponding to smaller blossoms, circle the vertices in those smaller blossoms, as well. — Engineering What happens when the next edge in the queue is processed by the algorithm? Explain. Nothing. The edge ae joins two vertices that are contained in the same vertex in the current shrunken graph, so the algorithm just discards this edge. When the next edge, [i,h] is processed, an augmenting path is found. What is that augmenting path? i, h, q,p,j, b, g, a, d, e, c, r on ...
View Full Document

## This note was uploaded on 03/08/2012 for the course CSE 542 taught by Professor Jonturner during the Spring '12 term at Washington State University .

### Page1 / 20

matchings-edmonds - g-\\/ashmgt0nUmver51tymSt.Lou1s...

This preview shows document pages 1 - 20. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online