maxFlow-dinic - ' n "i . hmgto Unhemts mSt Lows...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

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

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

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

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9

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

View Full DocumentRight Arrow Icon
Background image of page 10
Background image of page 11

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

View Full DocumentRight Arrow Icon
Background image of page 12
Background image of page 13
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ' n "i . hmgto Unhemts mSt Lows Engineering Max Flow Problem Din/C’s Algorithm Jon Turner Computer Science & Engineering Washington University www.ar1.wustl.edu/~jst $Wash1ngton UanCFSIthStlDUIS Engineering Dinic’s Algorithm - Shortest augmenting path algorithm often explores same “dead-ends” multiple times >> can avoid some redundant effort by ignoring edges that cannot possibly appear in augmenting paths of the “current length" I Let f be flow function on G and let R be residual graph >> /eve/(u)=number of edges in a shortest path from s to u in R >> only edges (u,v) for which Ievel(v)=level(u)+1 can possibly be on a shortest augmenting path I Dinic’s algorithm restricts path search to those edges (u,v) for which res(u,v)>0 and /eve/(v)= /eve/(u)+1 >> this can be done by explicitly constructing a subgraph of R with only these edges >> or, it can be done by efficiently ignoring other edges during path searches ;. Washmgton Unwersm 1n Stloum Engineering I Dinic's algorithm begins by setting f(u,v) to zero for all edges in G, computes leve/(u) for all vertices u and then repeats the following step as long as /eve/(t)<n >> while there is an augmenting path using edges (u,v) with level (v)=/eve/(u)+1, select such a path and saturate it >> recalculate [eve/(u) for all u .The subroutine that finds augmenting paths uses depth-first search and maintains certain information across searches >> for each vertex u, maintain a pointer nextedge(u) into adjacency list for u >> outgoing searches for u always start at nextedge(u) >> pointer is advanced past edges used for unsuccessful searches from u >> nextedge(u) is reset to the start of the adjacency list every time level is recalculated :1,- Mshmgton UniversuymStloms Engineering Review Questions 1. Draw a flow graph with at least 6 vertices and 12 directed edges. Assign capacities to each edge and add flow to two source/sink paths. Now, draw the residual graph for this flow and for each vertex u, write the value of leve/(u) next to u in the graph. Draw an x through each edge (u,v) for which /eve/(v)=#/eve/(u)+1. The subgraph of the residual graph defined by the edges that have not been crossed out is called the level graph. . For each vertex u, assign an ordering to the outgoing edges from u in the level graph. You can use any ordering you want, but a simple way to do this is to use the “clockwise” ordering in the drawing of the level graph (that is start with the edge that is closest to the “12 o’clock” position and proceed in clockwise fashion around the vertex). For each vertex u, define nextedge(u) to be the first vertex in the clockwise ordering. . Try to find a path from s to t by following the edges defined by the nextedge values. That is, starting at 5, follow nextedge(s), and continue until you reach t or a dead-end. If you reach a dead-end, then backup to the previous vertex x and advance nextedge(x) to the next edge in the list of outgoing edges from x, then resume your search. Continue in this fashion, backing up and adjusting the nextedge values until you find a path from s to t. Write down the final nextedge values. :1,- Mshmgton UnlverSItymStlouls Engineering Implementing Dinic’s Algorithm class dinic : public augPath { public: dinic(Flograph&,int&); ~dinic(); private: int* nextEdge; // ignore edges before nextEdge[u] int* level; // level[u]=# of edges in path from source bool findPath(vertex); // find augmenting path newPhase(); // prepare for a new phase }; dinic::dinic(Flograph& fgl, ints floVal) : augPath(fgl,floVal) { level - new int[fg—>n()+1]; nextEdge = new edge[fg->n()+1]; floVal = 0; while (newPhase()) { while (findPath(fg—>src())) floVal += augment(); at nggitpraieps $Msh1ngton UanCFSIthStlDUIS Engineering bool dinic::newphase() ( // Prepare for new phase. Return true if there is a source/sink path. vertex u,v; edge e; UiList q(G->n()); for (u = 1; u <= fg—>n(); u++) { level[u] = fg—>n(); nextEdge[u] = fg—>first(u); breadth-first search } 0(m) time q.addLast(fg—>src()); 1evel[fg—>src()] 0; ;;;Z:////F————————_J while (lq.empty()) { u = q.first(); q.removefirst(); for (e = fg->firstAt(u); e != 0; e = fg->nextAt(u,e)) ( v = fg—>mate(u,e); if (fg->res(u,e) > 0 && level[v] == fg->n()) { level[v] = level[u] + 1; if (v == fg—>snk()) return true; q.addLast(v); ) M } early return prevents return false; useless exploration of vertices that are further from source than sink ‘IIIIIIIIIIIIIIIIIIIIII Engineering E Washington University in St. Louis bool dinic::findpath(vertex u) ( diig;ggst // Find a shortest path with unused residual capacity. vertex v; edge e; for (e = nextEdge[u]; e != 0; e fg->next(u,e)) { v = fg->mate(u,e); if (fg—>res(u,e) == || 1eve1[v] != 1eve1[u] 1) continue; if (v == fg—>snk() || findpath(v)) { pEdge[v] = e; nextEdge[u] = e; return true; } ignore ineligible } edges nextEdge[u] = 0; return false; return path in pEdge and update nextEdge on failure, make nextEdge null to block future searches :1,- Mshmgton UniverSItymStlouis Engineering Analysis of Dinic’s Algorithm l Define a phase of Dinic’s algorithm to be the period from one calculation of level function to the next - Theorem 8.4. Dinic’s algorithm executes sn—l phases proofsketch. Level(t) increases by 21 after each phase; since no path is longer than n—1, there can be at most n—l phases l Theorem 8.7. Dinic's algorithm spends at most 0(mn) time per phase and finds a max flow in O(mn2) time Proof. Time per phase is O(mn) excluding time for path searches. Let N,- be number of edges traced by i-th top level call to findpath in a phase. Time for all calls to findpath is proportional to 215,5”, N,- A nextedge pointer is advanced for every edge traced in i-th top level call that is not part of path returned by findpath. So pointers are advanced at least (N,—n) times during the i—th call. Thus, 2lsism(Ni_n) 5 2m and 215/5", N,‘ is So, 0(mn) time per phase and O(mn2) time overall I shi' n nir'rsiIi .1" ' ' \Va ngto U W [l HSthUb Engineering Performance on Hard Cases I For each path length, Dinic does k2 path searches, spending 0(k) time per search, so 0(k4) altogether I Because augmenting path algorithm uses breadth-first search, it re-examines “dead-ends” on every search :1,- Washmgton UniverSItymStlouls Engineering Dinic’s Algorithm on Unit Networks I In a unit network all edges have capacity one and every vertex other than 5 or t has either a single entering edge or a single outgoing edge - Theorem 8.5. On unit network, Dinic's algorithm takes 0(m) time/phase and finds max flow in O(mn1/2) time Proof. Time for i-th top level call to findpath in a phase is proportional to number of edges N,- that are traced A nextedge pointer is advanced for every edge traced in i-th call that is not part of the path returned by findpath So, if k,- is length of i-th augmenting path, nextedge pointers are advanced at least (N,—k,-) times during findpath and all k, edges on path are saturated when flow is added Consequently, 2,k, sm and 2,(N,-— k,)52m, so 2,N,-s 2m+2,k,s 3m and thus, number of edges examined in all calls to findpath during a phase is 0(m) In :1,- Mshington UniversitymStlouis Engineering Now show there are at most 2[(n-2)1/2] phases; suppose the we’ve completed k phases, and let f be current flow, f* be a max flow and R be the residual graph for f. The number of remaining phases is at most |f*|-|f|, so the total number of phases is at most k+|f*|-|f|. We can complete the analysis by finding an upper bound on this expression. Note that f*-f is a flow on R, R is a unit network and f*-fis zero or one on every edge. We can partition edges on which f*- f is one into a collection of If *|-|f| paths from s to t and possibly some cycles . Since R is unit, any vertex other than s or t can be on at most one of these paths; hence, there is some augmenting path in R with at most (n—2)/(|f*|—|f|)+1 edges Since we’ve completed k phases, the next augmenting path will have at least k+1 edges, so k+1 s (n—2)/(|f*|—|f|) +1 or |f*|—|f| s (n—2)/k Hence, the total number of phases is sk+(n—2)/k, no matter what value k has. Choosing k=[(n—2)1/2] yields the desired result. I II \X/ashington University in St. Louis Exercises 1‘ The diagram below shows an intermediate state in the execution of Dinic's algorithm. In the diagram, the numbers by the vertices represent the value of the level function The arcs around each vertex indicate the order of the edges in the adjacency list, and the heavy dot on each arc shows the position of the next edge pointer 50, for example, the next edge at vertex e is (he) Which augmenting path is selected next? see/{ft Show the state of the algorithm after flow is added to the next augmenting path, Be sure to update the next edge pointers as appropriate. Engineering The new shite appears below. 0. . 3,3 2 3 5,3 6,6 ' 0 4,4 2'0 ,3 1,1 4'3 0&33fij @H‘QD»; 1 1,0 3,2 2'0 4 1,0 3,2 5,2 2,213 1 2 5 i Explain how Dinic's algorithm can be used to compute a maximum size matching in a bipartite graph in Omit“) time We have seen earlier how a maximum size iiiatchiiigflwr a bipartite graph can be computed by solving a maximumflow problem. The flow problem used ta salve the matching problem is a unit network, Tliereflu‘e, [free solve it usingY Diiiie’s algorithm, the rmmiii‘s‘Y time is 0(mtll/3) by the analysis (in pages 9 and 10. 1’) E \X/ashington University in St. Louis 3, The left-hand diagram below shows a residual graph R for some flow. The number next to each vertex is its level value (that is, the number of edges in a shortest path from the source). The subgraph shown at right excludes the edges tat are ignored by Dinic’s algorithm and is sometimes called the low] graph, We can view each phase of Dinic's algorithm as finding a lrlm‘kiugflow in the level graph. A flow is called a blocking flow, if every source-to-sink path contains some saturated edge. Find a blocking flow with a total value of 2 in the level graph, Show that this is not a maximum flow. Iwa mid our uni! offlow to the pull: surf and one unit offlin to the path sluit, we get 17 liloi‘kingflow. Tngct n maximumflnw, add one unit oft/law to mull oft/Iv Hm’v paths sndf, sin" and slu‘t, — Engineering I? ...
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 / 13

maxFlow-dinic - ' n &amp;quot;i . hmgto Unhemts mSt Lows...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online