0% found this document useful (0 votes)
74 views19 pages

Msms 2

The document presents a new algorithm for solving the maximum flow problem with multiple sources and sinks in directed planar graphs. The algorithm runs in near-linear O(n log3 n) time, which is a significant improvement over the previous best algorithms that took O(n2 log n) time by reducing the problem to the general graph case. The maximum flow problem with multiple sources and sinks arises in computer vision applications such as image segmentation. The new algorithm employs various graph algorithms and data structures tailored for planar graphs.

Uploaded by

ttungl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views19 pages

Msms 2

The document presents a new algorithm for solving the maximum flow problem with multiple sources and sinks in directed planar graphs. The algorithm runs in near-linear O(n log3 n) time, which is a significant improvement over the previous best algorithms that took O(n2 log n) time by reducing the problem to the general graph case. The maximum flow problem with multiple sources and sinks arises in computer vision applications such as image segmentation. The new algorithm employs various graph algorithms and data structures tailored for planar graphs.

Uploaded by

ttungl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Multiple-Source Multiple-Sink Maximum Flow in Directed Planar Graphs in Near-Linear Time

Glencora Borradaile Oregon State University Philip N. Klein Brown University Shay Mozes Brown University

Yahav Nussbaum Tel-Aviv University

Christian Wul-Nilsen Carleton University

May 11, 2011


Abstract We give an O(n log n) algorithm that, given an n-node directed planar graph with arc capacities, a set of source nodes, and a set of sink nodes, nds a maximum ow from the sources to the sinks. Previously, the fastest algorithms known for this problem were those for general graphs.
3

Introduction

The maximum ow problem with multiple sources and sinks in a directed graph with arc-capacities is, informally, to nd a way to route a single commodity from a given set of sources to a given set of sinks such that the total amount of the commodity that is delivered to the sinks is maximum subject to each arc carrying no more than its capacity. In this paper we study this problem in planar graphs. The study of maximum ow in planar graphs has a long history. In 1956, Ford and Fulkerson introduced the max st-ow problem, gave a generic augmenting-path algorithm, and also gave a particular augmentingpath algorithm for the case of a planar graph where s and t are on the same face Researchers have since published many algorithmic results proving running-time bounds on max st-ow for (a) planar graphs where s and t are on the same face, (b) undirected planar graphs where s and t are arbitrary, and (c) directed planar graphs where s and t are arbitrary. The best bounds known are (a) O(n) [14], (b) O(n log log n) [17], and (c) O(n log n) [2], where n is the number of nodes in the graph. Maximum ow in planar graphs with multiple sources and sinks was studied by Miller and Naor [29]. When it is known how much of the commodity is produced/consumed at each source and each sink, nding a consistent routing of ow that respects arc capacities can be reduced to negative-length shortest paths, which we now know can be solved in planar graphs in O(n log2 n/ log log n) time [30]. Otherwise, Miller and Naor gave an O(n log3/2 n) algorithm for the case where all the sinks and the sources are on the boundary of a single face, and generalized it to an O(k 2 n3/2 log2 n)-time algorithm for the case where the sources and the sinks reside on the boundaries of k dierent faces.1 However, the problem of maximum ow with multiple sources and sinks in planar graphs without any additional restrictions remained open. In general (i.e., non-planar) graphs, multiple sources and sinks can be reduced to the single-source single-sink case by introducing an articial source and sink and connecting them to all the sources and sinks, respectivelybut this reduction does not preserve planarity. For more than twenty years since the problem was explicitly stated and considered [29], the fastest known algorithm for computing multiple-source multiple-sink max-ow in a planar graph has been to use this reduction in conjunction with a general maximum-ow algorithm such as that of Sleator and Tarjan [32] which leads to a running time of O(n2 log n). For integer capacities less than U , one could instead use the algorithm of Goldberg and Rao [10], which leads to a running time of O(n1.5 log n log U ). No planarity-exploiting algorithm was known for the problem. Our Result The main result of this paper is an algorithm for the problem that is optimal up to a small poly-logarithmic factor. Theorem 1.1. There exists an algorithm that solves the maximum ow problem with multiple sources and sinks in an n-node directed planar graph in O(n log3 n) time. Application to computer vision problems Multiple-source multiple-sink min-cut arises in addressing a family of problems associated with the terms metric labeling (Kleinberg and Tardos, [26]), Markov Random Fields [9], and Potts Model (see also [4, 15]). In low-level vision problems such as image restoration, segmentation, stereo, and motion, the goal is to assign labels from a set to pixels so as to minimize a penalty function. The penalty function is a sum of two parts. One part, the data component, has a term for each pixel; the cost depends on the discrepancy between the observed data for the pixel and the label chosen for it. The other part, the smoothing component, penalizes neighboring pixels that are assigned dierent labels. For the binary case (when the set of available labels has size two), nding the optimal solution is reducible to multiple-source multiple-sink min-cut. [12]. For the case of more than two labels, there is a powerful and eective heuristic [4] using very-large-neighborhood [1] local search; the inner loop consists of solving the two-label case. The running time for solving the two-label case is therefore quite important. For this reason, researchers in computer vision have proposed new algorithms for max ow and done experimental studies comparing the run-times of dierent max-ow algorithms on the instances arising in this context [3, 27]. All of this is evidence for the importance of the problem.
1 The time bound of the rst algorithm can be improved to O (n log n) using the linear-time shortest-path algorithm of Henzinger et al. [14], and the time bound of the second algorithm can be improved to O(k2 n log2 n) using the O(n log n)-time single-source single-sink maximum ow algorithm of Borradaile and Klein [2].

For the (common) case where the underlying graph of pixels is the two-dimensional grid graph, our result yields a theoretical speed-up for this important computer-vision subroutine.2 Hochbaum [15] describes a special case of the penalty function in which the data component is convex and the smoothing component is linear; in this case, she shows that an optimal solution can be found in time O(T (m, n) + n log U ) where U is the maximum label, and T (m, n) is the time for nding a minimum cut. She mentions specically image segmentation, for which the graph is planar. For this case, by using our algorithm, the optimal solution can be found in nearly linear time Application to maximum bipartite matching Consider the problem of maximum matching in a bipartite planar graph. It is well-known how to reduce this problem to multiple-source, multiple-sink maximum ow. Our result is the rst planarity-exploiting algorithm for this problem (and the rst near-linear one). Techniques To obtain our result, we employ a wide range of sophisticated algorithmic techniques for planar graphs, some of which we adapted to our needs while others are used unchanged. Our algorithm uses pseudoows [11, 16] and a divide-and-conquer scheme inuenced by that of [19] and that of [29]. We adapt a method for using shortest paths to solve max st-ow when s and t are adjacent [13], and a data structure for implementing Dijkstra in a dense distance graph derived from a planar graph [8]. Among the other techniques we employ are: using cycle separators [28] recursively while keeping the boundary nodes on a constant number of faces [25, 33, 8], an algorithm for single-source single-sink max ow [2, 7], an algorithm for computing multiple-source shortest paths [23, 5], a method for cancelling cycles of ow in a planar graph [20], an algorithm for nding shortest paths in planar directed graphs with negative lengths [24, 30], and a data structure for range queries in a Monge matrix [21].

1.1

Preliminaries

We assume the reader is familiar with the basic denitions of planar embedded graphs and their duals (cf. [2]). Let G = (V, E ) be a planar embedded graph with node-set V and arc-set E . We use the term arc to emphasize that edges are directed. The term edge is used when the direction of an arc is not important. For each arc a in the arc-set E , we dene two oppositely directed darts, one in the same orientation as a (which we sometimes identify with a) and one in the opposite orientation [2]. We dene rev() to be the function that takes each dart to the corresponding dart in the opposite direction. It is notationally convenient to equate the edges, arcs and darts of G with the edges, arcs and darts of the dual G . Let S V be a set of nodes called sources, and let T V S be a set of nodes called sinks. A ow assignment f () is a real-valued function on darts satisfying antisymmetry: f (rev(d)) = f (d) A capacity assignment c() is a real-valued function on darts. A ow assignment f () respects the capacity of dart d if f (d) c(d). f () is called a pseudoow if it respects the capacities of all darts. For a given ow assignment f (), the net inow (or just inow) node v is inowf (v ) = dart d:head(d)=v f (d)3 . The outow of v is outowf (v ) = inowf (v ). A ow assignment f () is said to obey conservation at node v if inowf (v ) = 0. A feasible ow is a pseudoow that obeys conservation at every node other than the sources and sinks. A feasible circulation is a pseudoow that obeys conservation at all nodes. The value of a feasible ow f () is the sum of inow at the sinks, tT inowf (t) or, equivalently, the sum of outow at the sources. The maximum ow problem is that of nding a feasible ow with maximum value. For two ow assignments f , f , the addition f + f is the ow that assigns f (d) + f (d) to every dart d. A residual path in G is a path whose darts all have strictly positive capacities. For two sets of nodes G A, B , A B is used to denote the existence of some residual a-to-b path in G for some nodes a A and G b B . Conversely, A B is used to denote that no such path exists. We will omit the graph G when it is clear from the context.
2 Note that the single-source, single-sink max-ow algorithm of [2] was implemented by computer-vision researchers [31] and found to be useful in computer vision and to be faster than the competitors. 3 An equivalent denition, in terms of arcs, is inow (v ) = f aE :head(a)=v f (a) aE :tail(a)=v f (a).

The residual graph of G with respect to a ow assignment f () is the graph Gf with the same arc-set, nodeset, sources and sinks, and with capacity assignment cf () such that for every dart d, cf (d) = c(d) f (d). It is well known that a feasible ow f in G is maximum if and only if S T. Let f be a pseudoow in a planar graph G. Let V + denote the set of nodes {v V (S T ) : inowf (v ) > 0}. Similarly, let V denote the set of nodes {v V (S T ) : inowf (v ) < 0}. Suppose SV+ T V . For a graph with n nodes and m edges, there exists an O(m log n)-time algorithm that converts the pseudoow f into a maximum feasible ow f [19, 32]. In planar graphs, this can be done in linear time by rst canceling ow cycles using the technique of Kaplan and Nussbaum [20], and then by sending back ow from V + and into V in topological sort order. See Appendix C for details.
Gf Gf

1.2

Overview of the algorithm

Consider the following recursive approach for nding a maximum multiple-source multiple-sink ow: split the input graph G in two using a simple cycle separator C [28] and recursively solve the max ow problem in the two subgraphs. When the two recursive calls have been executed, in each of the two subgraphs there is no residual path from any source to any sink. If we further make sure that in each of the two subgraphs there is no residual path from any source to C and from C to any sink, then, since C is a separator, there is no residual path from any source to any sink in G. We therefore solve a slightly more general problem recursively in the two subgraphs: roughly speaking, nd a ow such that there is no residual path from a source to a sink or to C and no residual path from C to a sink (Section 2). After the two recursive calls there is no residual path from any source to any sink in G. However, the requirement that there is no residual path from any source to C and from C to any sink cannot be achieved by a feasible ow but rather by a pseudoow in which there might be excess inow or excess outow on nodes of C . We deal with this by solving a new max ow problem where nodes of C are treated as sources and sinks, limited in supply/demand by their excess inow/outow (Section 3). We exploit a relation between primal circulations and dual shortest paths to maintain a succinct repre sentation of the ow during critical phases of the algorithm, using the fact that there are only O( n) sources and sinks, all cyclically ordered on C (Section 3.2). Even though our representation does not explicitly store the ow on nearly any arc in the graph, we can augment it eciently towards optimality while maintaining feasibility. An important tool we use is Fakcharoenphol and Raos ecient implementation of Dijkstras algorithm [8], which we adapt to our needs. The resulting pseudoow can then be turned into a max ow in linear time using existing techniques (Appendix C). This leads to an O(n log3 n) time algorithm for max ow.

The Algorithm

Now we describe the algorithm, referred to as MultipleSourceMultipleSinkMaxFlow, in more detail. In order to treat nodes of the cycle separator both as sources and as sinks in recursive calls, we introduce a new node set A. At the top recursion level, A = . In general, A has constant size; more precisely |A| 6. MultipleSourceMultipleSinkMaxFlow(G, c,S ,T ,A) Input: a directed planar graph G with non-negative capacities c, a set S of source nodes, a set T of sink nodes, a set A of at most six nodes Output: a pseudoow f obeying conservation everywhere but S, T, A and s.t. S
Gf

T, S

Gf

A, A

Gf

T.

The algorithm nds a simple cycle separator C [28] and contracts all edges of C except one. This, essentially, merges all the nodes of C into a single supernode v , and turns C into a self loop. For simplicity of presentation we assume that no sources or sinks lie on C .4 The algorithm then recursively solves the problem on the subgraphs enclosed and not enclosed by that self loop (the self loop itself need not be included in any of the subgraphs), adding the supernode v that represents C to the set A. In order to keep
4 This does not lose generality since if a node u C is a source, one can introduce a new node u and an arc u u whose capacity equals the sum of capacities of arcs outgoing from u. Now consider u as a source instead of u. Since the separator has just O( n) nodes, this will not aect the running time. Sinks can be handled in a similar fashion.

the cardinality of A at most six, the algorithm alternately applies the cycle separator theorem with weights uniformly distributed on all nodes and uniformly distributed on only the nodes of A. This technique is similar to that used in [25, 33, 8]. After the recursive calls, the algorithm uncontracts the edges of C . At this stage there are no residual paths between sources and sinks in the entire graph, but there might be excess inow (positive or negative) at the nodes of C . The algorithm then calls the procedure FixConservationOnPath that pushes ow between the nodes of C so that there are no residual paths between nodes of C with positive inow and nodes of C with negative inow (the path in the name of the procedure is the cycle C without one edge). This procedure is discussed in Section 3; the interface is: FixConservationOnPath(G, P, c, f0 ) Input: a directed planar graph G, simple path P , capacity function c, and a pseudoow f0 Output: a pseudoow f s.t. (i) f f0 satises conservation everywhere but P , and (ii) {v P : inow(v ) > 0} {v P : inow(v ) < 0}. Running Time: O(n log2 n/ log log n + |P |2 log2 n) Next, the algorithm iterates over the nodes ai of A. The algorithm calls the procedure CycleToSingleSinkLimitedMaxFlow that, roughly speaking, pushes as much excess ow as possible from C to ai . + If Ci is the set of nodes of C that are reachable via residual paths from some node of C with positive inow at the beginning of iteration i, CycleToSingleSinkLimitedMaxFlow pushes ow among the nodes of + + + Ci and from the nodes of Ci to ai . The result is that remaining inow at nodes of Ci is non-negative and there are no residual paths from nodes of C with positive inow to ai . See Section 4; the interface is: CycleToSingleSinkLimitedMaxFlow(G, c, f0 , C, ai ) Input: a directed planar graph G with capacities c, a pseudoow f0 , a simple cycle C , a sink ai .
0 Assumes: v C + , inowf0 (v ) 0, where C + = {v C : {x C : inowf0 (x) > 0} v }. + Output: a pseudoow f s.t. (i) f f0 obeys conservation everywhere but C {t}, (ii) v

Gf

Gf

C + , inowf (v ) 0, (iii) {v C : inowf (v ) > 0} ai . Running Time: O(n log2 n/ log log n + |C |2 log2 n). A similar procedure SingleSourceToCycleLimitedMaxFlow is called to push ow from ai to C to eliminate as much negative inow as possible (using a similarly dened set Ci ). Finally, the algorithm pushes back ow from any nodes of C with positive inow to S and pushes ow back from T into any nodes of C with negative inow. Algorithm 1 MultipleSourceMultipleSinkMaxFlow(G, c,S ,T ,A) Input: a directed planar graph G with non-negative capacities c, a set S of source nodes, a set T of sink nodes, a set A consisting of a constant number of nodes A = {ai }k i=1 . Output: a pseudoow f obeying conservation everywhere except S, T, A and s.t. S
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
Gf

Gf

T, S

Gf

A, A

Gf

T.

add zero capacity arcs to triangulate and 2-connect G (required for simple cycle separators) nd a balanced (w.r.t. |G| and |A|, alternately) cycle separator C in G disjoint from S and T let P be a path comprising of all of C s edges except one edge e contract all the edges of P , turning e into a self loop incident to the only remaining node v of C let G1 and G2 be the subgraph of G enclosed and not enclosed by e, respectively f := MultipleSourceMultipleSinkMaxFlow(G1 , c|G1 , S G1 , T G1 , (A G1 ) {v }) f := f + MultipleSourceMultipleSinkMaxFlow(G2 , c|G2 , S G2 , T G2 , (A G2 ) {v }) uncontract the edges of P f := FixConservationOnPath(G, P, c, f ) for i = 1, 2, . . . , k f := CycleToSingleSinkLimitedMaxFlow(G, c, f , C, ai ) f := SingleSourceToCycleLimitedMaxFlow(G, c, f , ai , C ) push positive excess from C to S and negative excess to C from T return f

Correctness of Algorithm 1 The correctness of Algorithm 1 is proved in detail in Appendix A. The proof consists of a sequence of lemmas that prove that each step of the algorithm eliminates some undesired residual paths without reintroducing undesired residual paths. The arguments used are elementary. Running Time Analysis The number of nodes of the separator cycle C used to partition G into G1 and G2 is O( |G|). Therefore, each invocation of FixConservationOnPath, CycleToSingleSinkLimitedMaxFlow and SingleSourceToCycleLimitedMaxFlow in G takes O(|G| log2 |G|/ log log |G| + |C |2 log2 |C |) = O(|G| log2 |G|) time. The way we recursively partition into subgraphs is very similar to that of Fakcharoenphol and Rao [8]. In their algorithm, they spend O(|G | log2 |G |) time on each subgraph G in the recursive decomposition and prove a total time bound of O(n log3 n). By the same arguments, our algorithm runs in O(n log3 n) time.

Eliminating Residual Paths Between Nodes with Positive Inow and Nodes with Negative Inow on a Path

In this section we present an ecient implementation of the xing procedure which, roughly speaking, given a path with nodes having positive, negative, or zero inow, pushes ow between the nodes of the path so that eventually there are no residual paths from nodes with positive inow to nodes with negative inow. We begin by describing an abstract algorithm for the xing procedure. The abstract algorithm is given as Algorithm 2. It is similar to a technique used by Venkatesan and Johnson [19]. Let M be the sum of capacities of all of the darts of G. The algorithm rst increases the capacities of darts of the path P and their reverses by M . Let p1 , p2 , . . . , pk+1 be the nodes of P . The algorithm processes the nodes of P one after the other. Processing pi consists of decreasing the capacities of di = pi pi+1 and rev (di ) by M (i.e., back to their original capacities), and trying to eliminate positive inow x at pi by pushing at most x units of ow from pi to pi+1 . The intuition for doing so is that the ow after the push either obeys conservation at pi or there are no residual paths from pi to any of the other nodes of P (this is where we use the large capacities on the darts between unprocessed nodes). See appendix B for a formal proof of correctness. Negative inow at pi is handled in a similar manner by pushing ow from pi+1 to pi . Algorithm 2 AbstractFixConservationOnPath(G, P, c, f0 ) Input: directed planar graph G, simple path P = d1 d2 . . . dk , capacity function c, and pseudoow f0 Output: a pseudoow f s.t. (i) f f0 satises conservation at nodes not on P , and (ii) with respect to f , there are no residual paths from nodes of P with positive inow to nodes of P with negative inow.
1: 2: 3: 4:

f = f0 c[d] = c[d] + M for all darts d of P rev(P ) for i = 1, 2, . . . , k let pi and pi+1 be the tail and head of di , respectively
% reduce the capacities of d and rev(d) by M and adjust the ow appropriately

5: 6: 7: 8: 9: 10: 11: 12:

for d {di , rev(di )} c[d] := c[d] M f [d] := min{f [d], c[d]} f [rev(d)] := f [d] excess := inow at pi if excess > 0 then d := di else d := rev(di ) nd in which direction ow should be pushed add to f a maximum feasible ow from tail(d) to head(d) with limit excess return f

3.1

An Inecient Implementation

In this section, we give an inecient implementation of line 11 of the abstract algorithm. This will facilitate the explanation of the ecient procedure in the next section. We rst review the necessary ideas and tools. 3.1.1 Hassins algorithm for maximum st-planar ow

An st-planar graph is a planar graph in which nodes s and t are incident to the same face. Hassin [13] gave an algorithm for computing a maximum ow from s to t in an st-planar graph. We briey describe this algorithm here since we use it in implementing line 11 of Algorithm 2. Hassins algorithm starts by adding to G an articial innite capacity arc a from t to s. Let d be the dart that corresponds to a and whose head is t. Let t be the head in G of the dual of d. Compute in the dual G a shortest path tree rooted at t , where the length of a dual dart is dened as the capacity of the primal dart. Let [] denote the shortest path distances from t in G . Consider the ow [d ] = [headG (d )] [tailG (d )]for all darts d (1)

After removing the articial arc a from G, is a maximum feasible ow from s to t in G. We say that is a face potential vector that induces . In our algorithm we are interested in a max ow with limit x from s to t rather than a maximum ow, i.e., a ow whose value is at most a given number x but is otherwise maximal. It is not dicult to see that setting the capacity of the articial arc a to x instead of innity results in the desired limited max ow [22]. In our implementation, instead of using an articial arc from t to s, we use an existing arc whose endpoints are s and t as the arc a above. In order for this to work, the capacity of the dart d that corresponds to a and whose head is t must be zero (as is indeed the case if a is an articial arc from t to s). This can always be achieved by rst pushing ow on d to saturate it. Also note that in this case, we do not remove a from G. Hence, is a feasible circulation, rather than a maximum ow, since ow is being pushed back from t to s along a. To convert it into a maximum ow one just has to undo the ow on a. If we dene f by f [d ] = [d ] if d corresponds to a , 0 otherwise (2)

then + f is a maximum feasible st-ow. We will use the fact that this ow can be represented implicitly by the face potential vector , and the ow values f [d ] for the two darts corresponding to a. 3.1.2 The Inecient Implementation

Recall that f0 is the ow at the beginning of the procedure. Observe that the change to the ow in iteration i of the abstract algorithm (line 11) is a ow between the endpoints of the dart di . As discussed in Section 3.1.1, this ow can be represented as the sum of (i) a circulation i and (ii) a ow on di and rev(di ). Summing over the rst i iterations, the ow f at that time can be represented as the sum f =+f
i

(3)

where = j =1 j is a circulation and f is a ow assignment that diers from f0 only on the darts of {dj }i j =1 and their reverses. The inecient implementation of line 11 of the abstract algorithm appears as Algorithm 3. We now describe it. The total ow f is maintained by representing f and the circulation as in Eq. (3). f is represented explicitly, but, in preparation for the ecient implementation, the circulations j are represented i implicitly by the face-potentials j . By linearity of Eq. (1), the sum = j =1 j is the face potential vector that induces the circulation . Recall that d is the dart of C such that ow needs to be sent from tail(d) to head(d) (line 10 of Algorithm 2). In lines 1 3, the procedure pushes as much as possible on d itself. Consequently, either d is saturated or conservation at pi is achieved. Next, an implementation of Hassins algorithm pushes a maximum ow with limit |inow(pi )| from tail(d) to head(d). The procedure rst sets the length of darts to their residual capacities (line 4) and sets the length 6

of rev(d) to be the ow limit |inow(pi )| (line 5). Since the ow maintained is feasible, all residual capacities are non-negative. The procedure then computes all the headG (d)-to-f distances i [f ] in G using Dijkstras algorithm (line 6). Let i be the circulation corresponding to the face-potential vector i . The procedure sets val equal to [d] in line 7, then subtracts val from f [d] and adds it to f [rev(d)]. Finally, in the last line, the current circulation is added to the accumulated circulation by adding the potential i to . Algorithm 3 Inecient Implementation of line 11 of AbstractFixConservationOnPath (Algorithm 2)
% push ow on d to make its residual capacity zero as required for Hassins algorithm
1: 2: 3:

residual capacity := c[d] f [d] [headG (d)] + [tailG (d)] val := min{residual capacity, |inow(pi )|} f [d] := f [d] + val ; f [rev(d)] := f [d]
% push excess inow from tail(d) to head(d) using Hassins algorithm

amount of ow to push on d

let [d ] := c[d ] f [d ] [headG (d )] + [tailG (d )] for all darts d G lengths are residual capacities [rev(d)] := |inow(pi )| set the limit on the residual capacity of rev(d) i () := Dijkstra(G , , headG (d)) face potential are distances in G from headG (d) w.r.t. residual capacities val := i [headG (d)] i [tailG (d)] the amount of ow assigned to d by the circulation corresponding to i f [d] := f [d] val ; f [rev(d)] := f [(d)] do not push the circulation on d and rev(d) 9: = + i accumulate the current circulation
4: 5: 6: 7: 8:

3.2

An Ecient Implementation

In this section we give an ecient implementation of Algorithm 2. We rst review the necessary tools. 3.2.1 Fakcharoenphol and Raos Ecient Dijkstra Implementation

Let X be a set of nodes. Let H be a planar graph in which the nodes of X lie a single face. Let x1 , x2 , be the clockwise order of the nodes of X on that face. Let P be a set of darts not necessarily in the graph H whose endpoints are nodes in X . Fakcharoenphol and Rao [8] described a data structure that can be used in a procedure that eciently implements Dijkstras algorithm in H P . The procedure takes as input a table D such that D[i, j ] stores the distance between xi and xj in H , an array that stores the lengths of the darts in P , and a node v X . It is assumed that the lengths in D and in are non-negative. The procedure outputs the distances of the nodes of X from v in H P in O(|X | log2 |X | + |P | log |X |)-time. We mention a technical issue whose importance will become apparent in the sequel. The procedure partitions the table D into several subtables {D } that correspond to distances between pairs of disjoint sets of nodes of X , where each set consists of nodes that are consecutive in X . It is assumed in [8, footnote on p. 884] that for each such subtable D , a data structure that supports range minimum queries of the form minj1 j j2 {D [i, j ]} for every i, j1 , j2 is given. Fakcharoenphol and Rao note that such a data structure can be easily implemented by using a range-search tree [6] for every row i of D . The time required to construct all of the range-search trees for D is proportional to the size of D . 3.2.2 Price Functions, Reduced Lengths and FR-Dijkstra

For a directed graph G with dart-lengths (), a price function is a function from the nodes of G to the reals. For a dart d, the reduced length with respect to is (d) = (d) + (tail(d)) (head(d)). A feasible price function is a price function that induces nonnegative reduced lengths on all darts of G (see [18]). Single-source distances form a feasible price function. Suppose that, for some node r of G, for every node v of G, (v ) is the r-to-v distance in G with respect to (). Then for every arc uv , (v ) (u) + (uv ), so (uv ) 0. Here we assume, without loss of generality, that all distances are nite (i.e., that all nodes are reachable from r) since we can always add arcs with suciently large lengths to make all nodes reachable without aecting the shortest paths in the graph. We will use the following variant of Fakcharoenphol and Raos ecient Dijkstra implementation. The procedure FR(D, , X , v ) takes as input the table D and the array as described above, as well as a feasible price function X on the nodes of X and a node v X . It outputs the distances of the nodes of X from v 7

Figure 1: An example illustrating that the nodes of X are on the boundary of a single face of H . The diagram shows part of the graph G and some edges of its dual G . Edges of G are solid blue. Edges of P are bold. Dual edges are double lined red. The dual edges of P are in double lined dashed red.

in H P w.r.t. the reduced lengths w.r.t. X . We stress that lengths in D and in may be negative, but the reduced lengths are all non-negative. The computation takes O(|X | log2 |X | + |P | log |X |) time. This diers from the procedure described in Section 3.2.1 only in the existence of the price function X . We cannot aord to compute the entire table of reduced lengths since that would dominate the running time of the algorithm in [8]. Instead, whenever their algorithm requires some specic reduced length, we can compute it in constant time from D. This, however, does not suce. Recall that the algorithm in [8] requires that, for each of the subtables D , range-search trees that support range minimum queries of the form minj1 j j2 {D [i, j ] + X [xi ] X [xj ]} for every i, j1 , j2 are given. Note that the results of such queries may be dierent for dierent price functions. Computing the range-search trees would take O(|X |2 ) which will dominate the running time of the entire procedure. To overcome this diculty we use Monge range-query data structures, due to Kaplan and Sharir [21], which can be constructed from the table D in O(|X | log |X |) time, and answer queries of the desired form in O(log |X |) time. 3.2.3 The Procedure

Finally, we describe the ecient implementation. The procedure keeps track of the inow at each node of P in an array v []. As in the inecient implementation, the procedure will maintain the total ow as the sum of a circulation and a ow assignment f that diers from f0 only on the darts of P rev(P ). Initially f is set equal to f0 . The circulation will be represented by a face-potential vector . However, we will show that it suces to maintain just those entries of that correspond to faces incident to P . Dene each dart ds length by (d) = c[d] f [d]. Let X be the set of endpoints in the planar dual G of the darts of P (i.e. the primal faces incident to P ). Let H be the graph obtained from G by removing the darts of P . Note that in H , all the nodes of X that did not disappear (i.e., that have degree greater than zero) are on the boundary of a single face, see Figure 1. The procedure uses a multiple-source shortest paths (MSSP) algorithm [23, 5] to compute a table D [, ] of X -to-X distances in H with respect to the lengths (). The implementation of lines 1 10 of the abstract algorithm using the chosen representation of f is straightforward. We therefore focus on the implementation of line 11 of Algorithm 2, given as Algorithm 4. Consider iteration i of the algorithm. The main dierence between the inecient implementation and the ecient one is in implementing the Dijkstra step for computing shortest paths in the dual. Instead of computing the entire shortest-path tree, the procedure computes just the distance labels of nodes in X . This is done using the FR data structure, whose initialization requires the X -to-X distances in H with respect to the residual capacities. We now explain how these distances can be obtained. The ow on a dart d in the primal is f [d] + [headG (d)] [tailG (d)]. Therefore the residual capacity of d is (c[d] f [d]) [headG (d)] + [tailG (d)] 8 (5) (4)

which is its reduced length [d] with respect to the length () and price function . Suppose that d belongs to H , i.e. d is not one of the darts of P rev(P ). The procedure never changes f [d], so f [d] = f0 [d]. Therefore (d) = c[d] f0 [d]. These lengths are known at the beginning of the procedures execution. The reduced length of an X -to-X path Q = d1 , d2 , , dj in H is
j j

( (di ) [headG (di )] + [tailG (di )]) =


i=1 i=1

(di )

[end(Q)] + [start(Q)].

(6)

Therefore, for any nodes x, y X , the x-to-y distance in H w.r.t. the residual capacity is given by D [x, y ] [y ] + [x]. Since the procedure maintains the restriction of to faces of X , this distance can be obtained in constant time. Adapting FRs data structure to handle reduced distances w.r.t. a price function was discussed in Section 3.2.1. Algorithm 4 Ecient Implementation of line 11 of AbstractFixConservationOnPath (Algorithm 2)
1: 2: 3: 4:

residual capacity := c[d] f [d] X [headG (d)] + X [tailG (d)] val := min{residual capacity, |v [pi ]|} f [d] = f [d] + val ; f [rev(d)] := f [d] v [tail(d)] = v [tail(d)] val ; v [head(d)] = v [head(d)] + val let [d ] := c[d ] f [d ] for all darts d P rev(P ) [rev(d)] := |v [pi ]| X [tailG (rev(d))] +
X X i () := F R(D , , , headG (d))

% push ow on d to make its residual capacity zero as required for Hassins algorithm
amount of ow pushed on d update the inow at pi and pi+1

% push excess inow from tail(d) to head(d) using Hassins algorithm


5: 6: 7: 8: 9: 10: 11:
lengths of explicit darts are residual capacities (not including circulation component) set the limit on the residual capacity of rev(d) X [headG (rev(d))] (adjusted by circulation component) face potential are distances in G from headG (d) w.r.t. the reduced lengths induced by X

X the amount of ow assigned to d by the circulation corresponding to X val := X i i [head(d)] i [tail(d)] f [d] := f [d] val ; f [rev(d)] := f [(d)] do not push the circulation on d and rev(d) accumulate the current circulation X = X + X i v [tail(d)] = v [tail(d)] val ; v [head(d)] = v [head(d)] + val update the inow at pi and pi+1

It follows from the above discussion that, after executing line 11 of Algorithm 2 using the ecient implementation (Algorithm 4) for the last time, the ow assignment f maintained by the ecient implementation is the same as the one that would have been computed if the inecient implementation (Algorithm 3) were used. Moreover, the potential function X computed by the ecient implementation is the restriction to X of the potential function that would have been computed by the inecient implementation. In order to output the ow f in the entire graph G, we need to know the potential function rather than just its restriction X . Observe, however, that any pseudoow that diers from f by a circulation is a valid output of FixConservationOnPath since a circulation does not change the inow at any node, nor does it introduce residual paths between nodes that are not connected by a residual path in Gf . It therefore suces to nd any feasible circulation in Gf . This can be done by computing shortest paths in G w.r.t. the lengths := c f from an arbitrary node x G . Note, however, that for darts of P rev(P ) these lengths might be negative. We therefore use the O(n log2 n/ log log n)-time algorithm for shortest paths with negative lengths in planar graphs [30] to compute a feasible circulation . 5 The pseudocode for the ecient implementation of FixConservationOnPath is given in appendix D. Running Time Analysis Let n and k be the number of nodes in G and in P , respectively. The initialization time is dominated by the O(n log n + k 2 log n) time for MSSP. The execution of each iteration of the main loop is dominated by the call to FR, which takes O(k log2 k ) time. The number of iterations is k 1, leading to a total of O(k 2 log2 k ) time for execution of the main loop. Computing the circulation requires one shortest path computation, which takes O(n log2 n/ log log n) time. Thus total running time of the ecient implementation of FixConservationOnPath is O(n log2 n/ log log n + k 2 log2 k ).
5 In appendix E, we show how to use one more call to FR followed by a call to Dijkstras algorithm to compute these distances. While we think doing so is more elegant and simpler to implement, it does not change the asymptotic running time of the algorithm.

Pushing Excess Inow from a Cycle

In this section we describe the procedure CycleToSingleSinkLimitedMaxFlow that pushes excess inow from a cycle to a node not on the cycle. The procedure is given as Algorithm 5. The procedure SingleSourceToCycleLimitedMaxFlow is very similar. We omit its description. Algorithm 5 CycleToSingleSinkLimitedMaxFlow(G, c, f0 , C, t) Input: a directed planar graph G with capacities c, a pseudoow f0 , a simple cycle C , a sink ai .
0 Assumes: v C + , inowf0 (v ) 0, where C + = {v C : {x C : inowf0 (x) > 0} v }. + Output: a pseudoow f s.t. (i) f f0 obeys conservation everywhere but C {t},

Gf

(ii) v C + , inowf (v ) 0, (iii) {v C : inowf (v ) > 0}


1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
+

Gf

ai .

let C := {v C : there exists a residual path to v from a node x C with inowf0 (x) > 0} delete the nodes of C C + let v1 , v2 , . . . , v be the nodes of C + , labeled according to their cyclic order on C add articial arcs vi vi+1 for 1 i < let P be the v1 -to-v path of articial arcs contract all the edges of P , collapsing C + into the single node v1 f := SingleSourceSingleSinkMaxFlow(G, c f0 , c1 , t) undo the contraction of the edges of P f := FixConservationOnPath(G, P, c, f0 + f ) f0 modify f to push back ow to nodes of C + whose inow w.r.t f0 + f is negative f := f0 + f return f

To compute C + in Line 1, consider the residual graph of G w.r.t. f0 . Add a node v and non-zero capacity arcs vw for every node w whose inow w.r.t. f0 is positive (these arcs may not preserve planarity). In O(|G|) time, nd the set X of nodes that are reachable from v via darts with non-zero capacity. Then C + = C X . Since C + consists of all nodes of C reachable via residual paths from the nodes of C with positive inow, the ow computed by the procedure involves no darts incident to nodes in C C + . Thus, restricting the computation to the graph obtained from G by deleting the nodes in C C + (line 2) does not restrict the computed ow. After deletion, adding articial arcs between consecutive nodes of C + (line 4) will not violate planarity. Contracting the articial arcs eectively turns C + into a single node v1 . Next, the procedure computes a maximum ow f from C + to t w.r.t. residual capacities c f0 . This is done by invoking a singlesource single-sink maximum ow algorithm [2] with source v1 and sink t (line 7). Uncontracting the articial arcs turns f into a maximum C + -to-t ow in G w.r.t. the residual capacities c f0 . However, some of the nodes of C + may have negative inow w.r.t. f0 + f . In line 9, the procedure calls FixConservationOnPath to reroute the ow f among the nodes of C + so that, w.r.t. f0 + f , there are no residual paths from nodes of C + with positive inow to nodes of C + with negative inow. This implies that any node of C + that still has negative inow has pushed too much ow. Line 10 modies f to push back such excess ow so that no node of C + has negative inow w.r.t. f0 + f . This is done using the procedure of Section 1.1 described in the appendix. Finally, the procedure returns f0 + f . See Appendix F for a formal proof of correctness. We next analyze the running time of this procedure on an n-node graph G and a k -node cycle C . The st-maximum ow computation in line 7 takes O(n log n) time using the algorithm of Borradaile and Klein [2]. The running time of the procedure is therefore dominated by the call to FixConservationOnPath in line 9 which takes O(n log2 n/ log log n + k 2 log2 k ) time.

Acknowledgements
We thank Haim Kaplan and Micha Sharir for discussions of their unpublished data structure [21]. PNK and SM thank Robert Tarjan for encouraging us to work on this problem.

10

References
Ergun, J. Orlin, and A. Punnen. A survey of very large scale neighborhood search [1] R. Ahuja, O. techniques. Discrete Applied Mathematics, 23:75102, 2002. [2] G. Borradaile and P. N. Klein. An O(n log n) algorithm for maximum st-ow in a directed planar graph. Journal of the ACM, 56(2), 2009. [3] Y. Boykov and V. Kolmogorov. An experimental comparison of min-cut/max-ow algorithms for energy minimization in vision. IEEE Transactions on Pattern Analysis and Machine Intelligence, 26(9):1124 1137, 2004. [4] Y. Boykov, O. Veksler, and R. Zabih. Ecient approximate energy minimization via graph cuts. IEEE Transactions on Pattern Analysis and Machine Intelligence, 20(12):12221239, 2001. [5] S. Cabello and E. W. Chambers. Multiple source shortest paths in a genus g graph. In Proceedings of the 18th Annual ACM-SIAM Symposium on Discrete Algorithms, pages 8997, 2007. [6] M. de Berg, M. van Kreveld, M. Overmars, and O. Schwarzkopf. Computational Geometry: Algorithms and Applications. Springer-Verlag, 2nd edition edition, 2000. pp. 9699. [7] J. Erickson. Maximum ows and parametric shortest paths in planar graphs. In Proceedings of the 21st Annual ACM-SIAM Symposium on Discrete Algorithms, pages 794804, 2010. [8] J. Fakcharoenphol and S. Rao. Planar graphs, negative weight edges, shortest paths, and near linear time. Journal of Computer and System Sciences, 72(5):868889, 2006. [9] S. Geman and D. Geman. Stochastic relaxation, Gibbs distributions, and the Bayesian relation of images. IEEE Transactions on Pattern Analysis and Machine Intelligence, 6(6):721742, 1984. [10] A. Goldberg and S. Rao. Beyond the ow decomposition barrier. Journal of the ACM, 45(5):783797, 1998. [11] A. V. Goldberg and R. E. Tarjan. Solving minimum-cost ow problems by successive approximation. In Proceedings of the 19th Annual ACM Symposium on Theory of Computing, pages 718, 1987. [12] D. Greig, B. Porteous, and A. Seheult. Exact maximum a posteriori estimation for binary images. Journal of the Royal Statistical Society, Series B, 51(2):271279, 1989. [13] R. Hassin. Maximum ow in (s, t) planar networks. Information Processing Letters, 13(3):107, 1981. [14] M. R. Henzinger, P. N. Klein, S. Rao, and S. Subramanian. Faster shortest-path algorithms for planar graphs. Journal of Computer and System Sciences, 55(1):323, 1997. [15] D. S. Hochbaum. An ecient algorithm for image segmentation, Markov random elds and related problems. Journal of the ACM, 48(4):686701, 2001. [16] D. S. Hochbaum. The pseudoow algorithm: A new algorithm for the maximum-ow problem. Operations Research, 56(4):9921009, 2008. [17] G. F. Italiano, Y. Nussbaum, P. Sankowski, and C. Wul-Nilsen. Improved algorithms for min cut and max ow in undirected planar graphs. In Proceedings of the 43rd Annual ACM Symposium on Theory of Computing, 2011. To appear. [18] D. B. Johnson. Ecient algorithms for shortest paths in sparse networks. Journal of the ACM, 24(1):1 13, 1977. [19] D. B. Johnson and S. Venkatesan. Using divide and conquer to nd ows in directed planar networks in O(n3/2 log n) time. In Proceedings of the 20th Annual Allerton Conference on Communication, Control, and Computing, pages 898905, 1982.

11

[20] H. Kaplan and Y. Nussbaum. Maximum ow in directed planar graphs with vertex capacities. In Proceedings of the 17th European Symposium on Algorithms, pages 397407, 2009. [21] H. Kaplan and M. Sharir. Finding the maximal empty rectangle containing a query point. manuscript, 2011. [22] S. Khuller, J. Naor, and P. Klein. The lattice structure of ow in planar graphs. SIAM Journal on Discrete Mathematics, 6(3):477490, 1993. [23] P. N. Klein. Multiple-source shortest paths in planar graphs. In Proceedings of the 16th Annual ACMSIAM Symposium on Discrete Algorithms, pages 146155, 2005. [24] P. N. Klein, S. Mozes, and O. Weimann. Shortest paths in directed planar graphs with negative lengths: A linear-space O(n log2 n)-time algorithm. ACM Transactions on Algorithms, 6(2):118, 2010. [25] P. N. Klein and S. Subramanian. A fully dynamic approximation scheme for shortest paths in planar graphs. Algorithmica, 22(3):235249, 1998. [26] J. Kleinberg and E. Tardos. Approximation algorithms for classication problems with pairwise relationships: Metric labeling and Markov random elds. In Proceedings of the 40th Annual Symposium on Foundations of Computer Science, 1999. [27] P. Kohli and P. H. S. Torr. Dynamic graph cuts for ecient inference in Markov random elds. IEEE Transactions on Pattern Analysis and Machine Intelligence, 29(12):20792088, 2007. [28] G. L. Miller. Finding small simple cycle separators for 2-connected planar graphs. Journal of Computer and System Sciences, 32(3):265279, 1986. [29] G. L. Miller and J. Naor. Flow in planar graphs with multiple sources and sinks. SIAM Journal on Computing, 24(5):10021017, 1995. Preliminary version in FOCS 1989. [30] S. Mozes and C. Wul-Nilsen. Shortest paths in planar graphs with real lengths in O(n log2 n/ log log n) time. In Proceedings of the 18th European Symposium on Algorithms, pages 206217, 2010. [31] F. R. Schmidt, E. Toeppe, and D. Cremers. Ecient planar graph cuts with applications in computer vision. In Proceedings of the IEEE Computer Society Conference on Computer Vision and Pattern Recognition, pages 351356, 2009. [32] D. D. Sleator and R. E. Tarjan. A data structure for dynamic trees. Journal of Computer and System Sciences, 26(3):362391, 1983. [33] S. Subramanian. Parallel and Dynamic Shortest-Path Algorithms for Sparse Graphs. PhD thesis, Brown University, 1995. Available as Brown University Computer Science Technical Report CS-95-04.

12

Correctness of Algorithm 1
G G

Lemma A.1. Let be a circulation. Let u and v be nodes in a graph G. Then u vu v.

Proof. Pushing a circulation does not change the amount of ow crossing any cut. This implies that if there was no u-to-v residual path before was pushed, then there is none after is pushed. We will use the following two lemmas in the proof of correctness: Lemma A.2. (sources lemma) Let f be a ow with source set X . Let A, B be two disjoint sets of nodes. Then Gf G AX BA B. Proof. The ow f may be decomposed into a cyclic component (a circulation) and an acyclic component. By Lemma A.1, it suces to show the lemma for an acyclic ow f . Suppose for the sake of contradiction that there exists a residual a-to-b simple path P after f is pushed for some a A and b B . Let P be the maximal sux of P that was residual before the push. Maximality implies that the dart d of P whose head is start(P ) was non-residual before the push, and f (rev(d)) > 0. The fact that f (rev(d)) > 0 implies that before f was pushed there was a residual path Q from some node x X to head(d). Therefore, the concatenation of Q and P was a residual x-to-b residual path before the push, a contradiction. The proof of the following lemma is symmetric. Lemma A.3. (sinks lemma) Let f be a ow with sink set X . Let A, B be two disjoint sets of nodes. Then A
G

BX A

Gf

B.

For node sets W, Y, Z , we will use the notation sources lemma (W, Y, Z ) to indicate the use of the sources lemma to establish that there are no W -to-Y residual paths after a ow with source set Z is pushed. We will use sinks lemma (W, Y, Z ) in a similar manner. Lemma A.4. At any time in the running of the algorithm after the last execution of line 7 and before the execution of line 13, S T, S A, S C, A T, C T. Proof. The fact that the properties hold just after line 7 follows from the properties of the recursive calls and from the fact that any residual path from a node in one piece to a node in the other consists of a residual path to C and a residual path from C . Note that, because of the contractions in line 4, at this time the cycle C consists of just the node v . The the nonexistence of residual paths with respect to v in the recursive calls implies the nonexistence of residual paths w.r.t. any node of C after the contractions are undone in line 8. Now, let us prove that the properties are maintained until just before the execution of line 13. By the above argument, there is a cut separating S from T A C which is saturated just after line 8. The procedure in line 9 only pushes ow between vertices of C , and in lines 10 12, ow is only pushed between the nodes of A and C . These sets are all on the same side of the cut which therefore stays saturated. It follows that S T, S A, and S C at any point after line 7 and before line 13. A similar argument applied to a saturated cut separating A C from T shows A T and C T.
+ Recall that Ci is the set of nodes of C that are reachable via residual paths from some node of C with positive excess at the beginning of iteration i, and that Ci is the set of nodes of C that have residual paths to some node of C with negative excess at the beginning of iteration i. + Lemma A.5. Just after line 9 of Algorithm 1 is executed, C1 C1 .

Proof. Follows from the denition of FixConservationOnPath.


+ + Lemma A.6. For all i < j , Cj Ci and Cj Ci

13

+ + Proof. It suces to show that, for all i, Ci +1 Ci and Ci+1 Ci . The ow pushed in iteration i of line 11 can be decomposed into a ow whose sources and sinks are all + + in Ci and a ow whose sources are in Ci and whose sink is ai . Therefore, the set X of nodes of C with + positive inow immediately after iteration i of line 11 is a subset of Ci . By denition of SingleSourceToCycleLimitedMaxFlow, the set of nodes of C with positive inow does not change after line 12 is + executed. Therefore, Ci +1 is the set of nodes reachable from X by a residual path after iteration i of line 12. + + + By denition of Ci , immediately before iteration i of line 11 there are no Ci -to-{C Ci } residual + + + + + paths. By sources lemma (Ci , C Ci , Ci ), there are no Ci -to-{C Ci } residual paths immediately after + iteration i of line 11 as well. This shows that there are no X -to-{C Ci } residual paths at that time. The ow pushed in line 12 can be decomposed into a ow whose sources and sinks are all in Ci and + + a ow whose source is ai and whose sinks are all in Ci . By sinks lemma (Ci , C Ci , Ci ), there are + + no Ci -to-{C Ci } residual paths immediately after iteration i of line 12. This shows that there are no + + + X -to-{C Ci } residual paths at that time. Hence Ci +1 Ci , as desired. The proof of the analogous claim for Ci+1 is similar. + Lemma A.7. Just after line 11 of Algorithm 1 is executed in iteration i, Ci {aj }j<i Ci . + Ci , Ci +1

{aj }j i ,

+ Proof. The ow pushed in line 11 can be decomposed into a ow whose sources and sinks are all in Ci and + a ow whose sources are in Ci and whose sink is ai . + Ci + Ci +1 + Ci +1 + + Ci by sources lemma (Ci , Ci , Ci ) + + {aj }j<i by sources lemma (Ci +1 , aj , Ci )

{ai } by denition of CycleToSingleSinkLimitedMaxFlow


+ Ci by sources lemma (aj , Ci , Ci )

{aj }j<i

+ Lemma A.8. Just after line 12 of Algorithm 1 is executed in iteration i, Ci {aj }j i Ci +1 .

+ Ci , Ci +1

{aj }j i ,

Proof. The ow pushed in line 12 can be decomposed into a ow whose sources and sinks are all in Ci and a ow whose source is ai and whose sinks are all in Ci . + Ci + Ci +1 + Ci by sinks lemma (Ci , Ci , Ci ) + {aj }j i by sinks lemma (Ci +1 , aj , Ci ) Ci +1 by sinks lemma (aj , Ci+1 , Ci )

{aj }j<i ai

Ci +1 by denition of SingleSourceToCycleLimitedMaxFlow

Let C + (C ) denote the set of nodes in C with positive (negative) inow just before line 13 is executed. Corollary A.9. Just before line 13 of Algorithm 1 is executed, C + Lemma A.10. The following are true upon termination: 1. f is a pseudoow 2. f obeys conservation everywhere except at S, T, A 3. S
Gf

C , C +

A, A

C .

T, S

Gf

A, A

Gf

T.

14

Proof. Since every addition to f along the algorithm respects capacities of all darts, f is a pseudoow at all times. By induction, the only nodes that do not obey conservations after the recursive calls are those of S, T and A. Subsequent changes to f only violate conservation on the nodes of C , but any such violation is eliminated in line 13. Therefore upon termination f obeys conservation everywhere except S, T and A. Since, by Lemma A.4 and Corollary A.9 before line 13 C + A and C T , the ow pushed back from + C in line 13 must be pushed back to S . Similarly, the ow pushed back to C must be pushed back from T. Let f+ (f ) be the ow pushed back from C + to S (from T to C ) in line 13. Consider rst pushing back f+ . S S A S A T by sources lemma (S, T, C + ) A by sources lemma (S, A, C + ) T by sources lemma (A, T, C + ) C by sources lemma (S, C , C + ) C by sources lemma (A, C , C + )

Next consider pushing f S S A T by sinks lemma (S, T, C ) A by sinks lemma (S, A, C ) T by sinks lemma (A, T, C )

Correctness of Algorithm 2
1. For j i, j > j , if pj has positive inow, there is no residual path from pj to pj . If pj has negative inow, there is no residual path from pj to pj . 2. For j, j i, if pj has positive inow and pj has negative inow then there is no pj -to-pj residual path.

Lemma B.1. The following holds immediately after iteration i of the main loop (line 3).

Proof. By induction on the number of iterations i of the loop. For i = 0 the invariants are trivially satised. First note that the adjustments to capacities and ow in lines 68 do not create any new residual paths since capacities are only reduced, and no residual capacity increases. Therefore, it suces to argue just about the ow pushed in line 11. Assume the invariants hold up until the beginning of the ith iteration. We show that the invariants hold at the end of the iteration. Suppose that pi has positive inow at the end of the ith iteration (the case of negative inow is similar). 1. Since the ow pushed in line 11 is limited by |inow(pi )|, the fact that pi has positive inow at the end implies that the ow pushed was a maximum ow from pi to pi+1 . Since the capacities of darts between pk+1 and pk for k > i are suciently large, the maximality of the ow implies that there are no pi -to-pk residual paths for any k > i. The invariant holds for nodes pj with positive inow and j < i by sinks lemma ({pj }, {pj : j > j }, {pi+1 }). 2. Invariant 2 holds for j, j < i by sinks lemma ( {pj : j < i, inow(pj ) > 0}, {pj : j < i, inow(pj ) < 0}, {pi+1 }). The invariant holds for pi by invoking the sources lemma ({pi }, {pj : j < i, inow(pj ) < 0}, {pi }). 15

Corollary B.2. Algorithm 2 is correct Proof. The ow f f0 satises conservation everywhere except at nodes of P since the algorithm only pushes ow between nodes of P . By Lemma B.1, with respect to f , there are no residual paths from nodes of P with positive inow to nodes of P with negative inow.

Converting a Pseudoow into a Maximum Feasible Flow


Gf

Let f be a pseudoow in a planar graph G with node set V , sources S and sinks T . Let V + denote the set of nodes {v V (S T ) : inowf (v ) > 0}. Similarly, let V denote the set of nodes {v V (S T ) : inowf (v ) < 0}. Suppose S V + T V . In this appendix we show how to convert f into a maximum feasible ow f . This procedure was rst described for planar graphs by Johnson and Venkatesan [19]. The original description of the procedure took O(n log n) time, but using the ow cycles canceling technique of Kaplan and Nussbaum [20] the running time is O(n). We begin by converting f to an acycic pseudoow in linear time [20]. That is, after the conversion there is no cycle C such that f [d] > 0 for every dart d of C . Since f is acyclic, the darts with a positive ow induce a topological ordering on the nodes of the graph G. Let v be the last member of V + in the topological ordering, and let d be an arbitrary dart that carries ow into v . We set f [d] = max{f [d] inowf (v ), 0}, and set f [rev(d)] accordingly. The ow assignment f maintains the invariant S V + T V by sinks + + lemma (S V ,T V ,{v }). As long as v is in V , there must be a dart d which carries ow to v . By changing the ow on d we cannot add to V + a new node that appears later than v in the topological ordering. We repeat this process until V + is empty. Since we reduce the ow on each dart at most once, this takes linear time. Next we handle V while keeping the invariant S V + repeatedly xing the rst vertex if V in the topological ordering.
Gf Gf

T V in a symmetric way, by
Gf

The total running time is O(n), and since V + , V are both empty, we get from the invariant S V + T V that the resulting pseudoow is a feasible ow. This is the required ow f .

16

Pseudocode for FixConservationOnPath

Algorithm 6 FixConservationOnPath(G, P, c, f0 ) Input: a directed planar graph G, simple path P = d1 d2 . . . dk , capacity function c, and a pseudoow f0 Output: a pseudoow f s.t. (1) f f0 satises conservation at nodes not on P and (2) w.r.t f , no residual path exists from {v P : inow(v ) > 0} to {v P : inow(v ) < 0}.
1: 2: 3: 4: 5: 6: 7: 8: 9:

let X be the set of endpoints in the planar dual G of the darts of P initialize to zero an array X [] indexed by the nodes of X let H be the graph obtained from G by removing the darts of P compute, using the MSSP algorithm [23, 5], a table D [, ] of distances in H between nodes of X w.r.t the lengths c f0 f := f0 c[d] := c[d] + M for all darts of P rev(P ) initialize an array of length k by v [i] := inow at pi with respect to f for i = 1, 2, . . . , k let pi and pi+1 be the tail and head of di , respectively
% reduce the capacities of d and rev(d) by M and adjust the ow appropriately

10: 11: 12: 13: 14: 15: 16: 17: 18:

for d {di , rev(di )} c[d] := c[d] M old ow := f [d] + X [headG (d)] X [tailG (d)] new ow := min{old ow, c[d]} f [d] := new ow X [headG (d)] + X [tailG (d)] f [rev(d)] := f [d] v [head(d)] := v [head(d)] + new ow old ow v [tail(d)] := v [tail(d)] new ow + old ow if v [pi ] > 0 then d := di else d := rev(di )

adjusted ow must not exceed adjusted capacity the explicit ow does not include the circulation component

update the inow at pi and pi+1

nd in which direction ow should be pushed

% push ow on d to make its residual capacity zero as required for Hassins algorithm
19: 20: 21: 22:

residual capacity := c[d] f [d] X [headG (d)] + X [tailG (d)] val := min{residual capacity, |v [pi ]|} f [d] = f [d] + val ; f [rev(d)] := f [d] v [tail(d)] = v [tail(d)] val ; v [head(d)] = v [head(d)] + val
% push excess inow from tail(d) to head(d) using Hassins algorithm

amount of ow pushed on d update the inow at pi and pi+1

23: 24: 25: 26: 27: 28: 29:

let [d ] := c[d ] f [d ] for all darts d P rev(P ) [rev(d)] := |v [pi ]| X [tailG (rev(d))] +
X X i () := F R(D , , , headG (d))

lengths of explicit darts are residual capacities (not including circulation component) X the limit on the residual capacity of rev(d) [headG (rev(d))] set (adjusted by circulation component) face potential are distances in G from headG (d) w.r.t. the reduced lengths induced by X

X X val := X i [head(rev(d))] i [tail(rev(d))] the amount of ow assigned to d by the circulation corresponding to i f [d] := f [d] + val ; f [rev(d)] := f [(d)] do not push the circulation on d and rev(d) X = X + X accumulate the current circulation i v [tail(d)] = v [tail(d)] val ; v [head(d)] = v [head(d)] + val update the inow at pi and pi+1

% nd a feasible circulation
30: 31: 32: 33: 34:

let x be an arbitrary node in G let [d] := c[d] f [d] for all darts d G := SingleSourceShortestPaths(G , , x) f [d] := f [d] + [headG (d)] [tailG (d)] for every dart d G return f

distances of the nodes of G from x add explicit ow and implicit circulation

17

Alternative to Line 32 of Algorithm 6

In this section we show that it is not necessary to use a generic shortest path algorithm that works with negative lengths to compute a feasible circulation in line 32 of Algorithm 6. Instead of choosing x to be an arbitrary node in G , let x be an arbitrary node of X . Let (y ) denote the x-to-y distance in G w.r.t. the lengths . Instead of computing using a shortest path algorithm that accepts negative lengths, we will compute it more eciently in two steps. Pseudocode is given below as Algorithm 7. In the rst step we use FR to compute the distances to just the nodes of X . In the second step we extend these distances to all other nodes using Dijkstras algorithm. In the rst step the algorithm computes distances in G from x to all nodes of X w.r.t. X , the reduced lengths of induced by the feasible price function X . This is done by an additional invocation of FR (line 2). Let X denote these distance labels. By denition of reduced lengths and a telescoping sum similar to the one in the derivation of Eq. (6), X [y ] = (y ) + X [x] X [y ]. (7)

Since both X and X are known, the algorithm can compute the unreduced distances [y ] for all y X (line 4). Next, the algorithm runs Dijkstras algorithm on G , initializing the label of each node y of X to its correct value [y ]. Since in the dual the darts of P rev(P ) are only incident to nodes of X , Dijkstras algorithm initialized in this manner correctly outputs the distance labels for all nodes of G even if some of the darts of P rev(P ) may have negative lengths. Algorithm 7 Alternative to line 32 of Algorithm 6 1: let x be an arbitrary node in X X X 2: = F R(D , , , x) nd distances of the nodes of X from x w.r.t. price function X 3: initialize to an array indexed by the nodes of G X X X 4: [y ] = [y ] [x] + [y ] for every y X distances of the nodes of X from x 5: extend to all darts of G by [d] := c[d] f0 [d] for every dart d G 6: := Dijkstra(G , , x, ) distances of the nodes of G from x

Correctness of Algorithm 5

Lemma F.1. Algorithm 5 is correct. Proof. Any ow that is pushed by the algorithm originates at C + and terminates at C + {t}. Therefore, f f0 violates conservation only at C + {t}. In line 10, ow of f is pushed back so that no node of C + has negative inow w.r.t. f0 + f . It is possible to do so by only pushing back ow of f (rather than ow of f0 + f ) since by assumption no node of C + has negative inow w.r.t. f0 . By maximality of the ow pushed in line 7, just after line 7 is executed there are no C + -to-t residual paths. Clearly, this remains true when the capacities of the articial darts are set to zero. In line 9 ow is pushed among the nodes of C + , so by sources lemma (C + , t, C + ), there are no C + -to-t residual paths after line 9 either. Moreover, by denition of FixConservationOnPath, there are no C>0 -to-C<0 residual paths immediately after line 9 is executed, where C>0 (C<0 ) is the set of nodes of C + with positive (negative) inow at that time. Line 10 pushes ow into C<0 , making all the nodes of C<0 obey conservation. By sinks lemma (C>0 , t, C<0 ) there are no C>0 -to-t residual paths upon termination of the procedure. This completes the proof since C>0 is the set of nodes of C with positive inow upon termination.

18

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy