13
Faster Strongly Polynomial Algorithms for the Unbalanced Transportation Problem and Assignment Problem with Monge Costs Balachandran Vaidyanathan Operations Research, FedEx Express, Memphis, Tennessee 38125 We consider a transportation problem where the cost matrix satisfies the Monge property. The problem has supply nodes N 1 (|N 1 |= n 1 ), demand nodes N 2 (|N 2 |= n 2 ), supply s i 0 for i N 1 , and demand d j 0 for j N 2 (n = n 1 + n 2 , m = n 1 n 2 ). When the total sup- ply is equal to the total demand, the problem can be solved in O(n) time using the northwest corner rule (Hoff- man [10]). This algorithm and run-time, however, do not extend to the unbalanced case, where the total supply is not equal to the total demand. The fastest strongly polynomial run-time for the unbalanced transportation problem with Monge costs is O(n log n(m + n log n)), and for the unbalanced assignment problem (unit supplies and demands) with Monge costs is O(n(m + n log n)). In this article, we describe a simple algorithm that solves the unbalanced transportation problem with Monge costs in O(mn 1 ) time and the unbalanced assignment prob- lem with Monge costs in O(m) time using elementary data structures. We also develop a faster implementa- tion of the algorithm that utilizes a heap, a self-balancing binary search tree, and dynamic trees, and solves the transportation problem with Monge costs in O(m log n 1 ) time. Our algorithms improve the run-times for: (i) the unbalanced transportation problem with Monge costs by a factor of n log n/ log n 1 or better and (ii) the unbalanced assignment problem with Monge costs by a factor of n or better. © 2013 Wiley Periodicals, Inc. NETWORKS, Vol. 62(2), 136–148 2013 Keywords: Monge matrix; transportation problem; assignment problem; networks flow algorithms; computational complexity; minimum cost flow problem 1. INTRODUCTION The Monge property was first studied by the 18th century French mathematician Gaspard Monge. An n 1 × n 2 matrix C satisfies the Monge property if C ij + C rs C is + C rj for Received March 2012; accepted March 2013 Correspondence to: B. Vaidyanathan; e-mail: bala.vaidyanathan@ gmail.com DOI 10.1002/net.21507 Published online 28 May 2013 in Wiley Online Library (wileyonlinelibrary.com). © 2013 Wiley Periodicals, Inc. 1 i < r n 1 and 1 j < s n 2 ; such a matrix is also called a Monge matrix. Monge matrices arise in many natural situations. For example, C is a Monge matrix if ([3]): C ij = u i + v j for arbitrary real numbers u i ,1 i n 1 and v j ,1 j n 2 C ij = u i v j for increasing real numbers u i ,1 i n 1 and decreasing real numbers v j ,1 j n 2 C ij = min(u i , v j ) for increasing real numbers u i ,1 i n 1 and decreasing real numbers v j ,1 j n 2 C ij = d (P i , Q j ) where P 1 , P 2 , ... , P n1 and Q 1 , Q 2 , ... , Q n2 are points on disjoint paths P and Q (respectively) on a convex polygon, and d (P i , Q j ) is the Euclidean distance between P i and Q j Many combinatorial optimization problems can be solved very efficiently when there is an underlying Monge structure, and there is extensive literature on Monge properties and their applications. We refer the reader to the review articles by Burkard [3] and Burkard et al. [4] for details. The transportation problem is a fundamental network flow problem that has applications in several areas (Ahuja et al. [2]). It is a special case of the minimum cost network flow problem defined on a bipartite network. The network has sup- ply nodes and demand nodes and all arcs originate at a supply node and terminate at a demand node. Each supply/demand node has an associated nonnegative supply/demand quantity and each arc has a linear cost per unit flow. When the total supply is equal to the total demand the problem is balanced, and otherwise the problem is unbalanced. Without loss of generality, we assume that the total supply is greater than or equal to the total demand. The objective is to find the minimum cost solution that satisfies all the demands. The assignment problem is a special case of the transportation problem with unit supplies and demands. For the majority of this article, our discussion will be with respect to the transportation problem. The fastest strongly polynomial algorithm for the trans- portation problem with general costs is due to Orlin [13] and has a time complexity of O(n log n(m + n log n)). This algo- rithm, which is based on the scaling technique of Edmonds and Karp [7], solves the problem as a sequence of O(n log n) NETWORKS—2013—DOI 10.1002/net

Faster strongly polynomial algorithms for the unbalanced transportation problem and assignment problem with monge costs

Embed Size (px)

Citation preview

Page 1: Faster strongly polynomial algorithms for the unbalanced transportation problem and assignment problem with monge costs

Faster Strongly Polynomial Algorithms for theUnbalanced Transportation Problem and AssignmentProblem with Monge Costs

Balachandran VaidyanathanOperations Research, FedEx Express, Memphis, Tennessee 38125

We consider a transportation problem where the costmatrix satisfies the Monge property. The problem hassupply nodes N1(|N1| = n1), demand nodes N2(|N2| =n2), supply si ≥ 0 for i ∈ N1, and demand dj ≥ 0 forj ∈ N2(n = n1 + n2, m = n1n2). When the total sup-ply is equal to the total demand, the problem can besolved in O(n) time using the northwest corner rule (Hoff-man [10]). This algorithm and run-time, however, do notextend to the unbalanced case, where the total supplyis not equal to the total demand. The fastest stronglypolynomial run-time for the unbalanced transportationproblem with Monge costs is O(n log n(m +n log n)), andfor the unbalanced assignment problem (unit suppliesand demands) with Monge costs is O(n(m + n log n)). Inthis article, we describe a simple algorithm that solvesthe unbalanced transportation problem with Monge costsin O(mn1) time and the unbalanced assignment prob-lem with Monge costs in O(m) time using elementarydata structures. We also develop a faster implementa-tion of the algorithm that utilizes a heap, a self-balancingbinary search tree, and dynamic trees, and solves thetransportation problem with Monge costs in O(m log n1)time. Our algorithms improve the run-times for: (i) theunbalanced transportation problem with Monge costs bya factor of n log n/ log n1 or better and (ii) the unbalancedassignment problem with Monge costs by a factor of nor better. © 2013 Wiley Periodicals, Inc. NETWORKS, Vol. 62(2),136–148 2013

Keywords: Monge matrix; transportation problem; assignmentproblem; networks flow algorithms; computational complexity;minimum cost flow problem

1. INTRODUCTION

The Monge property was first studied by the 18th centuryFrench mathematician Gaspard Monge. An n1 × n2 matrixC satisfies the Monge property if Cij + Crs ≤ Cis + Crj for

Received March 2012; accepted March 2013Correspondence to: B. Vaidyanathan; e-mail: [email protected] 10.1002/net.21507Published online 28 May 2013 in Wiley Online Library(wileyonlinelibrary.com).© 2013 Wiley Periodicals, Inc.

1 ≤ i < r ≤ n1 and 1 ≤ j < s ≤ n2; such a matrix is alsocalled a Monge matrix. Monge matrices arise in many naturalsituations. For example, C is a Monge matrix if ([3]):

• Cij = ui + vj for arbitrary real numbers ui, 1 ≤ i ≤ n1 andvj , 1 ≤ j ≤ n2

• Cij = uivj for increasing real numbers ui, 1 ≤ i ≤ n1 anddecreasing real numbers vj , 1 ≤ j ≤ n2

• Cij = min(ui, vj) for increasing real numbers ui, 1 ≤ i ≤n1 and decreasing real numbers vj , 1 ≤ j ≤ n2

• Cij = d(Pi, Qj) where P1, P2, . . . , Pn1 and Q1, Q2, . . . , Qn2

are points on disjoint paths P and Q (respectively) on aconvex polygon, and d(Pi, Qj) is the Euclidean distancebetween Pi and Qj

Many combinatorial optimization problems can be solvedvery efficiently when there is an underlying Monge structure,and there is extensive literature on Monge properties and theirapplications. We refer the reader to the review articles byBurkard [3] and Burkard et al. [4] for details.

The transportation problem is a fundamental network flowproblem that has applications in several areas (Ahuja et al.[2]). It is a special case of the minimum cost network flowproblem defined on a bipartite network. The network has sup-ply nodes and demand nodes and all arcs originate at a supplynode and terminate at a demand node. Each supply/demandnode has an associated nonnegative supply/demand quantityand each arc has a linear cost per unit flow. When the totalsupply is equal to the total demand the problem is balanced,and otherwise the problem is unbalanced. Without loss ofgenerality, we assume that the total supply is greater thanor equal to the total demand. The objective is to find theminimum cost solution that satisfies all the demands. Theassignment problem is a special case of the transportationproblem with unit supplies and demands. For the majorityof this article, our discussion will be with respect to thetransportation problem.

The fastest strongly polynomial algorithm for the trans-portation problem with general costs is due to Orlin [13] andhas a time complexity of O(n log n(m + n log n)). This algo-rithm, which is based on the scaling technique of Edmondsand Karp [7], solves the problem as a sequence of O(n log n)

NETWORKS—2013—DOI 10.1002/net

Page 2: Faster strongly polynomial algorithms for the unbalanced transportation problem and assignment problem with monge costs

shortest path problems, each of which can be solved inO(m + n log n) time using Fibonacci heaps (Fredman andTarjan [9]). The scaling approach divides the algorithm into anumber of scaling phases and solves the problem to approx-imate optimality in each phase. In each phase, the degreeof approximation is reduced, and the algorithm finally con-verges to the optimal solution. For the assignment problem,the fastest strongly polynomial run-time is O(n(m + n log n)

(Edmonds and Karp [7] and Fredman and Tarjan [9]).Researchers have also developed algorithms for special

cases of the balanced transportation and assignment prob-lems. Hoffman [10] showed that if the cost matrix is Monge,then the transportation problem can be solved in O(n) timeusing the northwest corner rule. For the assignment prob-lem with Monge costs, the northwest corner rule will alwaysassign the variables corresponding to the diagonal of thecost matrix. The factored transportation problem for whichCij = uivj (Evans [8]) or Cij = ui + vj (Szwarc [16])are special cases of the transportation problem with Mongecosts. Marcotte and Suri [12] considered the complete graphinduced by a set of 2n points on the boundary of a polygon.The cost of each arc is the Euclidean distance between thetwo end points if the end points see each other and is ∞otherwise, and the objective is to find the minimum-weightperfect matching. Their algorithm runs in O(n log n) timewhen the polygon is convex and O(n log2 n) when the poly-gon is simple. Buss and Yianilos [5] developed an O(n log n)

time algorithm to solve the assignment problem where thenodes form a quasi-convex tour. This means that the nodesare arranged in a circular order such that given any four nodesi, j, k, and l in the tour order where i and j are supplies and kand l are demands, Cil + Cjk ≤ Cik+ Cjl. The quasi-convexcost structure is a generalization of the Monge cost structure(Buss and Yianilos [5]).

The unbalanced transportation (or assignment) problemcan be transformed into an equivalent balanced problem byadding a dummy demand(s) and connecting it to all supplieswith arcs of zero cost. However, this transformation destroysthe special cost structure that allows for the efficient algo-rithms described above. Hence, specialized algorithms forthe balanced problem do not extend to the correspondingunbalanced version.

We now summarize the literature for special cases of theunbalanced transportation and assignment problems. A spe-cial case of the Monge cost structure occurs when nodes lieon a line. Karp and Li [11] showed that the assignment prob-lem on a line can be solved in O(n) time. Aggarwal et al.[1] and Vaidyanathan and Ahuja [19] developed O(n log n)

algorithms for the transportation problem on a line. A com-bination of Orlin and Vaidyanathan [14]’s algorithm andVaidyanathan [18]’s algorithm improves the run-time for thetransportation problem on a line to O(sort(n)+nα(n)), wheresort(n) is the time to sort n real numbers and α(n) is the inverseAckermann function.

Aggarwal et al. [1] also studied the case when the costsare bitonic Monge, where the numbers in each row of Cform a monotone nonincreasing sequence followed by a

monotone nondecreasing sequence. They showed that theassignment problem with bitonic Monge costs can be solvedin O(n2 log n1) time and also use the algorithm to solvethe transportation problem with bitonic Monge costs inO(n1 log S) time (S is the total supply). This algorithm isnot efficient when S is large. Also, the algorithm only applieswhen the costs are bitonic Monge.

Quoting from Aggarwal et al. [1]’s article, “the threeimportant problems that we were not able to solve are:(i) an efficient computation of the minimum cost matching(or unbalanced assignment problem) when the cost array isMonge—a special case of this is when the sink and sourcepoints form a convex polygon; (ii) an efficient computationof the minimum cost matching (or unbalanced assignmentproblem) when the sink and source points form a simplepolygon; (iii) the unbalanced transportation problem whenthe underlying cost array is Monge.” The algorithms in thisarticle are the first to solve problems (i) and (iii) more effi-ciently than the fastest (strongly polynomial) general purposealgorithms.

In this article, we study the unbalanced transportationproblem with Monge costs (UTPM), for which the cur-rent fastest strongly polynomial run-time is O(n log n(m +n log n)) using Orlin’s scaling based algorithm describedearlier. Our algorithm, in contrast, exploits the propertiesof the problem, and is faster, simpler, and does not relyon scaling for the run-time guarantee. Our algorithm’s run-time is based on augmenting flows on shortest paths thatsatisfy certain properties, which we characterize in this arti-cle. We refer to these augmenting paths as noncrossingpaths.

We prove that the UTPM can be solved by solving asequence of O(m) shortest noncrossing path problems. Wealso show that the problem of finding the shortest noncross-ing path can be posed as a shortest path problem on anacyclic network with O(n1) arcs; hence, the shortest non-crossing path can be determined in O(n1) time. Using this, wedevelop a simple O(mn1) algorithm for the UTPM that onlyuses elementary data structures. For the unbalanced assign-ment problem with Monge costs (UAPM), the run-time ofthe algorithm is O(m). We also develop a faster implementa-tion of the algorithm for the transportation problem that runsin O(m log n1) time (the shortest noncrossing path is deter-mined in O(log n1) time). This implementation augmentsflows implicitly and uses a heap, a self-balancing binarysearch tree, and dynamic trees as well as properties of theproblem to achieve the speed-up.

Thus, our algorithm for the transportation problem solvesthe shortest path problem more frequently than Orlin’s algo-rithm (O(m) times vs. O(n log n) times) but determines theshortest augmenting path in significantly less time (O(log n1)

time vs. O(m+n log n)). For a sparse network with m = O(n),our algorithm gives an n log2 n/ log n1 factor improvementfor the UTPM and an n log n factor improvement for theUAPM. For a dense network with m = O(n2), our algorithmgives an n log n/ log n1 factor improvement for the UTPMand n factor improvement for the UAPM.

NETWORKS—2013—DOI 10.1002/net 137

Page 3: Faster strongly polynomial algorithms for the unbalanced transportation problem and assignment problem with monge costs

2. PRELIMINARIES

We consider a transportation problem with supply nodesN1(|N1| = n1), demand nodes N2(|N2| = n2), supply si ≥ 0for i ∈ N1, and demand dj ≥ 0 for j ∈ N2. Let the total supplybe S, the total demand be D, the total number of nodes be n,and let S > D. The cost matrix C of the problem satisfiesthe Monge property. Let the supply nodes be arranged in avertical line and numbered in the same order as the rows of Cusing indices 1, 2, 3, . . . , n1. Similarly, let the demand nodesbe arranged on a parallel vertical line in the same order asthe columns of C using indices n1 + 1, n1 + 2, . . . , n1 + n2.The transportation problem has m = n1n2 transportation arcsconnecting the set of supply nodes to the set of demand nodes.Transportation arc (i, j) is drawn as a straight line connectingsupply node i and demand node j, has infinite capacity, andhas a linear cost Cij per unit flow. It is important that thegraph is drawn as described above because we use geometricproperties of this representation in our algorithm.

The standard approach to solve an unbalanced transporta-tion problem is to create a dummy demand node with demandS−D and connect all supply nodes to this demand node usingarcs with zero costs. However, we do not adopt this approachbecause the newly introduced arcs spoil the inherent Mongecost structure. Instead, we create a super supply node 0 withsupply/demand b(0) = D and connect it to the other supplynodes using supply arcs (0, i) for i ∈ N1. The capacity ofarc (0, i) is si, the cost of flow on arc (0, i) is zero, and thesupply/demand of supply node i ∈ N1 is b(i) = 0. The sup-ply/demand of demand node j ∈ N2 is b(j) = −dj. This is theminimum cost flow representation of the original problem onwhich we apply our algorithm. Figure 1 gives an example ofthe network with four supply nodes and three demand nodes.

Our algorithm uses the concept of residual networks. Theresidual network G(x) corresponding to a flow x is defined asfollows. Replace each arc (i, j) in the original network withcost cij and capacity uij by two arcs (i, j) and (j, i). Arc (i, j) inG(x) has residual cost cij and residual capacity rij = uij − xij

and arc (j, i) in G(x) has a residual cost −cij and residualcapacity rji = xij. We refer to arc (i, j) as a regular arc andarc (j, i) as a reverse arc. G(x) only contains arcs with nonzeroresidual capacities. The residual capacity r(P) of a (directed)path P in G(x) is the minimum residual capacity of all the arcsthat belong to it and residual cost c(P) of path P is the sum ofthe residual costs of the arcs that belong to it. All arcs in G(x)are also drawn as straight lines connecting correspondingnodes. In our figures, we represent reverse arcs using dottedlines and regular arcs using solid lines.

A pseudo-flow of a minimum cost flow problem is a solu-tion x that satisfies the capacity constraints but may violate theflow balance constraints. The residual network for a pseudo-flow is defined in the same manner as the residual networkfor a flow. Given a pseudo-flow, the imbalance at node i ise(i) = b(i) – total flow out of node i+ total flow into node i.If e(i) > 0, node i is an excess node and if e(i) < 0, node i is adeficit node. Our algorithm starts with x = 0 and repeatedlyaugments flow on shortest paths in G(x) from excess node

FIG. 1. Example Network.

0 to a deficit node (or demand node) until the pseudo-flowbecomes a flow; this classical algorithm is called the succes-sive shortest path algorithm, and the paths on which flows areaugmented are called augmenting paths. The correctness ofthe algorithm is based on the following fundamental theoremof network flows (Ahuja et al. [2]).

Theorem 1.

(a) A flow x is optimal if and only if G(x) contains nonegative cost directed cycles (negative cycle optimalityconditions).

(b) Suppose a pseudo-flow x or a flow x satisfies the opti-mality condition and we obtain x’ from x by sending flowon a shortest path from node p to node q in G(x). Then,x’ also satisfies the optimality conditions.

Next, we introduce terminology that is used in this article.We say that arcs (i, j) and (r, s) in G(x) cross if they intersect inthe graphical representation of the problem (see, for example,Fig. 1 where one such crossing is between (1, 7) and (2, 6)).Due to our representation of the network, only transportationarcs (or their reversals) can cross. Suppose arcs (i, j) and (r, s)cross; then, the associated crossing is one of the following.

• regular crossing: If (i, j) and (r, s) are both regular arcs• reverse crossing: If (i, j) and (r, s) are both reverse arcs• mixed crossing: If (i, j) is a regular arc and (r, s) is a reverse

arc

The set of all crossings between arcs that belong to aug-menting path P is represented by Cr(P). Crossings in Cr(P)

are arranged in the same order as they would be encounteredin if one were to draw P. Consecutive crossings in Cr(P) arereferred to as adjacent crossings.

3. ESTABLISHING A BOUND ON THE NUMBER OFFLOW AUGMENTATIONS

The number of flow augmentations in the generic imple-mentation of the Successive Shortest Path Algorithm (SSPA)

138 NETWORKS—2013—DOI 10.1002/net

Page 4: Faster strongly polynomial algorithms for the unbalanced transportation problem and assignment problem with monge costs

for the transportation problem is O(nU), where U is themagnitude of the largest supply/demand (because each aug-menting path carries at least one unit of flow). For theassignment problem, the number of flow augmentationsreduces to O(n2). In this section, we develop a specific imple-mentation of the SSPA for the UTPM and show that thenumber of augmentations in this algorithm is O(m). Our algo-rithm: (i) considers demand nodes in the increasing orderof their indices; (ii) satisfies a demand node’s deficit fullybefore considering the next demand node; and (iii) augmentsflows on shortest paths that satisfy certain special proper-ties. In the rest of the section, we characterize the propertiesof these shortest paths, show that such shortest augmentingpaths always exist, and establish a bound on the number offlow augmentations in the algorithm.

Lemma 1. Let P be an augmenting path. Let I ={i1, i2, . . . , ik} be the set of supply nodes and J ={j1, j2, . . . , jt} be the set of demand nodes between two adja-cent crossings in P arranged in the same order as theyappear in P. Then, either (i) i1 < i2 < · · · < ik andj1 < j2 < · · · < jt; or (ii) i1 > i2 > · · · > ik andj1 > j2 > · · · > jt .

Proof. Let I contain three consecutive nodes p, q, and rsuch that p < q and q > r. Correspondingly, let P contain thesub path p − j − q − s − r. s > j because otherwise regulararc (q, s) will cross regular arc (p, j), which is a contradic-tion (Fig. 2). Since r < q, reverse arc (s, r) crosses reversearc (j, q), which is a contradiction. Similarly, we can showthat if p > q and q < r, it also leads to a contradiction.Hence, the nodes in I are monotonic. Similarly, we can provethat the nodes in J are monotonic. Suppose nodes in I arestrictly increasing and nodes in J are strictly decreasing (orvice versa); it is easy to show that there will once again be acontradiction. This establishes the result. ■

Lemma 2. Let j be the current demand node being consid-ered by the algorithm and let x be the current pseudo-flow.Then, xik = 0 for all demand nodes k > j.

Proof. This is true at the start of the algorithm. Ouralgorithm considers demand nodes in the increasing orderof indices. Hence, the proof follows by induction on the flowaugmentations. ■

FIG. 2. Illustration for Lemma 1.

FIG. 3. Illustration for Lemma 3, Case 1.

Based on Lemmas 1 and 2, we have the followingcorollary.

Corollary 1. Let P be an augmenting path that does notcontain crossings (Cr(P) = {}) and let jt be the currentdemand node being considered by the algorithm. Then, Pis of the form 0 − i1 − j1 − i2 − j2 − · · · − it − jt wherei1 < i2 < · · · < it and j1 < j2 < · · · < jt .

Next, we establish properties of Cr(P).

Lemma 3. Let the current pseudo-flow x satisfy the con-dition xijxrs = 0 if transportation arcs (i, j) and (r, s) crossand let P be an augmenting path in G(x). Then, (i) Cr(P)

does not contain reverse crossings; (ii) every mixed crossingin Cr(P) is preceded by a regular crossing in Cr(P).

Proof. If Cr(P) contains a reverse crossing betweenreverse arcs (j, i) and (s, r), then xij > 0 and xrs > 0 (propertyof G(x)) before the augmentation on P, which violates thecondition xijxrs = 0. This establishes (i). We divide the proofof (ii) into two cases.

Case 1: Cr(P) contains a mixed crossing between regular arc(i, j) and reverse arc (r, s) (the regular arc appears first in P).Consider the sub case where i < s and r < j as shown inFigure 3 (the other sub case s < i and j < r is similar). Let(j, k) be the next arc in P after arc (i, j). If k < s, then reversearcs (j, k) and (r, s) cross, which is not possible due to (i).Hence, k > s. For P to reach node r from node k, it has tocross arc (i, j). Let arc (p, q) be an arc in P that crosses arc(i, j). If (p, q) is a reverse arc, then reverse arcs (p, q) and(r, s) cross, which is not possible due to (i). Hence, (p, q) hasto be a regular arc. However, in that case the regular crossingbetween arcs (p, q) and (i, j) precedes the mixed crossingbetween arcs (i, j) and (r, s).

Case 2: Cr(P) contains a mixed crossing between reverse arc(r, s) and regular arc (i, j) (the reverse arc appears first in P).Consider the sub case where i < s and r < j as shown inFigure 4 (the other sub case s < i and j < r is similar). Letthe next arc in P after arc (r, s) be regular arc (s, k). Suppose

NETWORKS—2013—DOI 10.1002/net 139

Page 5: Faster strongly polynomial algorithms for the unbalanced transportation problem and assignment problem with monge costs

FIG. 4. Illustration for Lemma 3, Case 2.

k < r, then the regular crossing between arcs (s, k) and (i, j)precedes the mixed crossing between arcs (r, s) and (i, j) andwe are done. Consider the case where k > r (Fig. 4). Let thenext arc in P after arc (s, k) be reverse arc (k, v). If v < s,then reverse arcs (r, s) and (k, v) cross, which is not possibledue to (i). Hence, v > s. Let the next arc in P after (k, v) beregular arc (v, u). If u < k, then the regular crossing betweenarcs (s, k) and (v, u) precedes the mixed crossing betweenarcs (r, s) and (i, j) and we are done. Consider the case u > k(Fig. 4). In order for P to reach node i from node u, thereexists an arc (p, q) in P that crosses reverse arc (k, v). Arc(p, q) cannot be a reverse arc due to (i). If (p, q) were a regulararc, then the regular crossing between arcs (p, q) and (s, k)

precedes the mixed crossing between arcs (r, s) and (i, j) andwe are done. Last, note that while we show node j below nodeu in Figure 4 for the sake of illustration, the arguments madeabove are valid as long as r < j. ■

We are now ready to introduce the concept of noncrossing(augmenting) paths. A noncrossing path P is an augmentingpath that: (i) does not contain any crossings (Cr(P) = {});and (ii) does not cross any arc (i, j) in the current solutionwhich has nonzero flow. In the rest of this section, we provethat there always exists a shortest augmenting path in G(x)that is a noncrossing path. We then use this property to estab-lish a bound on the number of augmentations. The followingproperty follows directly from the definition of noncrossingpaths.

Lemma 4. Suppose the algorithm always augments flowson noncrossing paths. Then, for any two transportation arcs(i, j) and (r, s) that cross, xijxrs = 0.

Proof. The property is satisfied at the start of the algo-rithm. Let it be satisfied after the kth augmentation, and letthe (k + 1)th augmentation be on noncrossing path P. Then,

from the definition of noncrossing paths, the augmentationon P cannot introduce a violation of the property. ■

We now prove the central result of this section.

Theorem 2. The successive shortest path algorithm canbe implemented such that each flow augmentation is on ashortest noncrossing path of the form 0 − i1 − j1 − i2 − j2 −· · · − it − jt where i1 < i2 < · · · < it and j1 < j2 < · · · < jt .

Proof. From Corollary 1 and the definition of a non-crossing path, it follows that a noncrossing path is of the form0 − i1 − j1 − i2 − j2 − · · · − it − jt where i1 < i2 < · · · < itand j1 < j2 < · · · < jt .

The first augmentation is trivially on a noncrossing path.Let the 2nd, 3rd, . . . , and kth augmentations also be on non-crossing paths. Then, Lemma 4 is satisfied after the kthaugmentation. Let the (k + 1)th augmentation be on shortestaugmenting path P which violates at least one of the proper-ties of a noncrossing path. From Lemma 3, Cr(P) does notcontain reverse crossings and each mixed crossing in Cr(P)

is preceded by a regular crossing in Cr(P).We divide the proof into two parts. In the first part of the

proof, we show that P can be transformed into a shortestaugmenting path P′ that does not contain any regular cross-ings (and as a consequence will not contain any crossings).However, P′ may still cross an arc (which is not in P′) in thecurrent solution with nonzero flow. In the second part of theproof, we show if this is the case, then P′ can be transformedinto a shortest augmenting path P∗ that does not contain anycrossings and also does not cross an arc in the current solutionwith nonzero flow. This establishes the result.

Part 1: We prove that P can be transformed into a shortestaugmenting path P′ such that Cr(P′) does not contain anyregular crossings. Let the first regular crossing in Cr(P) bebetween regular arcs (i, j) and (r, s) where (i, j) precedes (r, s)in P. Consider the case where i < r and s < j as shown inFigure 5 (the case r < i and j < s is similar). Let the next arcin P after (i, j) be reverse arc (j, k). We divide the analysisinto the following cases.

Case 1: k < i. To reach node r from node k, P contains an arc(p, q) that crosses arc (i, j). Arc (p, q) cannot be a regular arcbecause if it were, the regular crossing between arcs (i, j) and(p, q) precedes the regular crossing between arcs (i, j) and

FIG. 5. Illustration for Theorem 2, Part 1.

140 NETWORKS—2013—DOI 10.1002/net

Page 6: Faster strongly polynomial algorithms for the unbalanced transportation problem and assignment problem with monge costs

(r, s). Also, (p, q) cannot be a reverse arc because in that casethe mixed crossing between arcs (p, q) and (i, j) has a regularcrossing preceding it (Lemma 3), and this regular crossingprecedes the regular crossing between arcs (i, j) and (r, s).

Case 2: k > r. Let reverse arc (v, r) precede arc (r, s) in P. Ifv < j, then the mixed crossing between reverse arc (v, r) andregular arc (i, j) has a regular crossing preceding it (Lemma3); this implies that the regular crossing between arcs (i, j)and (r, s) is not the first regular crossing, and therefore v ≮ j.If v > j, then reverse arcs (v, r) and (j, k) cross, which is alsonot possible (Lemma 3).

Case 3: i < k < r. In this case, the mixed crossingbetween arcs (j, k) and (r, s) has a regular crossing precedingit (Lemma 3), and this regular crossing precedes the regularcrossing between arcs (i, j) and (r, s). Hence, this case is notpossible.

Case 4: k = r. This is the only remaining possibility. Pcontains the sub path i − j − r − s. The cost of this subpath in G(x) is Cij − Crj + Crs. Due to the Monge property,Cij −Crj +Crs ≥ Cis, and we can replace sub path i− j−r−swith arc (i, s) to obtain a new shortest path. Any regular arcin P that crosses arc (i, s) crosses arc (r, s) or arc (i, j) orboth. Thus, replacing sub path i − j − r − s with arc (i, s)cannot increase the number of regular crossings. Also, theregular crossing between arcs (i, j) and (r, s) is eliminated.Hence, the number of regular crossings decreases by at leastone. By repeating the same procedure multiple times, we caneliminate all regular crossings from P and thereby constructa shortest augmenting path P′ without regular crossings. Thisconcludes the proof for Part 1.

Part 2: We now show that P′ can be transformed into ashortest path P* that does not contain any crossings and thatdoes not cross any arc in the current solution with nonzeroflow. Before the flow augmentation on P′, xijxrs = 0 forall transportation arcs (i, j) and (r, s) that cross (inductionhypothesis and Lemma 4). Let P′ contain one or more reg-ular arcs that cross transportation arc (r, s) : xrs > 0 and(r, s) /∈ P′. Since P′ does not contain crossings, it is of theform 0−i1−j1−i2−j2−· · ·−it −jt where i1 < i2 < · · · < itand j1 < j2 < · · · < jt (Corollary 1). Thus, exactly one regu-lar arc in P′ crosses arc (r, s) because otherwise there will beat least one reverse arc in P′ that crosses arc (r, s), which isnot possible from Lemma 4; let this regular arc be arc (iq, jq)(Fig. 6). Note that xiqjq = 0 before the augmentation (other-wise, there is a violation of Lemma 4 due to arcs (r, s) and(iq, jq) crossing). If q �= t, iq < r ≤ iq+1 and if q = t,iq < r. Also, if q �= 1, jq−1 ≤ s < jq and if q = 1, s < jq.If iq < r < iq+1 and jq−1 < s < jq we replace arc (iq, jq)with sub path iq − s − r − jq without increasing the cost (dueto the Monge property, Ciqs − Crs + Crjq ≤ Ciqjq). Usingsimilar arguments, we make one of the following modifica-tions without increasing the cost of P′: (i) if r = iq+1 andjq−1 �= s < jq, we replace sub path iq − jq − r with iq − s− r;(ii) if iq < r �= iq+1 and s = jq−1, we replace sub paths − iq − jq with sub path s − r − jq; and (iii) if r = iq+1 and

FIG. 6. Illustration for Theorem 2, Part 2.

s = jq−1, we replace sub path s − iq − jq − r with arc (s, r).This modification strictly decreases the number of crossingswith an arc with nonzero flow. By repeating the same proce-dure multiple times, we can transform P′ into shortest pathP∗. This completes the proof. ■

We are now ready to formally describe the algorithm forthe UTPM (and UAPM).

Algorithm 1 Algorithm for the UTPM.algorithm UTPMbegin

initialize x := 0 on all arcs and e(i) := b(i) on all nodes;for j = n1 + 1 to n dobegin

while e(j) < 0 dobegin

determine the shortest noncrossing path P in G(x);compute r(P) := min {rpq : (p, q) ∈ P};augment f := min {r(P), −e(j)} units of flow on Pand update x;update e(0) := e(0) − f and e(j) := e(j) + f ;

endend

end

The correctness of the algorithm follows from Theorems1 and 2. We now establish some properties that allow us tobound the number of flow augmentations in the algorithm.

Lemma 5. Let (j, i) be a reverse arc in a noncrossing pathP. Then, i = max {k : xkj > 0} and j = min {k : xik > 0}.

NETWORKS—2013—DOI 10.1002/net 141

Page 7: Faster strongly polynomial algorithms for the unbalanced transportation problem and assignment problem with monge costs

Proof. Let the last node in P be j′ where j′ > j (Theorem2). Our proof is by contradiction.

Let max {k : xkj > 0} = r > i (Fig. 7). Then, the nextarc in P after (j, i) will cross arc (r, j), which has nonzeroflow. This means P is not a noncrossing path; a contradiction.Therefore, r = i.

Let min {k : xik > 0} = s < j (Fig. 8). Let i′ be thenode preceding node j in P. Then, i′ < i (Theorem 2, seeFig. 8). Thus, arc (i′, j) crosses arc (i, s) which has nonzeroflow. This means P is not a noncrossing path; a contradiction.Therefore, s = j. ■

Lemma 6. Once the flow on transportation arc (i, j)decreases, xkj = 0 for k > i in the rest of the algorithm.

Proof. The first time the flow on arc (i, j) decreases, theproperty is satisfied (Lemma 5). Let the property be satisfiedafter the tth subsequent augmentation. Let the flow on arc(k, j) where k > i increase due to the (t + 1)th augmentationon noncrossing path P. Also, let the next arc in P after arc(k, j) be reverse arc (j, p) where p > k (Theorem 2). However,from the induction hypothesis and the nature of noncrossingpaths (Theorem 2), xpj = 0. Therefore, (j, p) cannot belongto P, which is a contradiction. ■

Lemma 7. Once the flow on an arc decreases, it cannotsubsequently increase.

Proof. Directly follows from Lemma 6 and Theorem 2.■

We now have the following result that bounds the numberof flow augmentations.

Theorem 3. The number of flow augmentations in thealgorithm is O(m).

Proof. Each augmentation satisfies a demand node com-pletely, and/or saturates a supply arc, and/or changes the flowon a transportation arc from a positive value to zero. FromLemma 7, and the fact that there are O(m) arcs and O(n)

nodes, we obtain the result. ■

Thus, we have established an O(m) bound on the numberof flow augmentations (or iterations) in the algorithm. In the

FIG. 7. Illustration for Lemma 5.

FIG. 8. Illustration for Lemma 5.

next section, we analyze the steps within each iteration andprove that each iteration can be implemented in O(n1) time.

4. AN EFFICIENT APPROACH TO DETERMINESHORTEST NONCROSSING AUGMENTING PATHS

Each iteration of the algorithm identifies a shortest non-crossing path in the residual network G(x). Given that G(x)has O(m) arcs and O(n) nodes, the fastest shortest path algo-rithm (Dijkstra’s algorithm implemented using Fibonacciheaps (Fredman and Tarjan [9])) will take O(m + n log n)

time in each iteration, provided the arc costs in the resid-ual network are nonnegative. (Note that in order to maintainnonnegative arc costs in G(x), the algorithm will have touse the optimal reduced costs defined by the complemen-tary slackness conditions; these reduced costs can be updatedby spending O(n) time per iteration using the shortest pathdistance labels (see Ahuja et al. [2], page 320 for completedetails)). Further, Dijkstra’s algorithm could produce a short-est path that is not a noncrossing path, which is undesirablebecause the bound on the number of augmentations cruciallydepends on augmenting flows on noncrossing paths.

In this section, we describe an algorithm that determinesa shortest noncrossing path in O(n1) time using elementarydata structures. We also show that the total time spent in eachiteration of the algorithm is O(n1), which gives an O(mn1)

algorithm for the UTPM, and an O(m) algorithm for theUAPM.

Next, we introduce a few terms. An outgoing arc (i, j) atsupply node i is called the highest outgoing arc with nonzeroflow at node i if j = min {k : xik > 0}. Similarly, an incomingarc (i, j) at demand node j is called the lowest incoming arcwith nonzero flow at node j if i = max {k : xkj > 0}. We referto an arc in G(x) as admissible if it could potentially belong toa noncrossing path. Thus, supply arc (0, i) is admissible if andonly if x0i < si. Also, in order for a transportation arc to beadmissible, it cannot cross an arc in the current solution withnonzero flow. We now establish other properties of admissibletransportation arcs.

Lemma 8. Let R be the set of admissible reverse trans-portation arcs. Then, (i) arc (jk , ik) ∈ R if and only if (ik , jk)is the highest outgoing arc at node ik with nonzero flow andis the lowest incoming arc at node jk with nonzero flow; (ii)

142 NETWORKS—2013—DOI 10.1002/net

Page 8: Faster strongly polynomial algorithms for the unbalanced transportation problem and assignment problem with monge costs

R can be represented as the set {(j1, i1), (j2, i2), . . . , (jt , it)}where i1 < i2 < · · · < it and j1 < j2 < · · · < jt; (iii)|R| ≤ min {n1, n2}.

Proof. Let j′ be the demand node currently being con-sidered by the algorithm. Construct set J as follows. Visit alldemand nodes j < j′ and add the lowest incoming arc withnonzero flow at node j to set J . Similarly, construct a set Iby visiting all supply nodes i and adding the highest outgo-ing arc at node i to set I . Let Y = I

⋂J . By construction,

|Y | ≤ min {n1, n2}. From Lemma 5, an admissible reversearc has to belong to Y . Further, since any arc (i, j) in Y hasnonzero flow, (i, j) cannot cross an arc with nonzero flow inthe current solution (Lemma 4). Thus, (j, i) is an admissiblereverse arc if and only if (i, j) belongs to Y . R is constructedfrom Y by reversing the directions of the arcs and sortingthe arcs based on their head (or tail) node indices. The resultfollows. ■

Lemma 9. Let R be the set of admissible reverse arcs, letj′ be the current demand node being considered by the algo-rithm, and let i be a supply node. Let ik = min {s : (r, s) ∈R and i < s}. Then, supply node i has exactly one outgoingadmissible regular arc which is arc (i, jk) if ik is defined orarc (i, j′) if ik is not defined.

Proof. Consider arc (i, jk) (we assume that ik is defined;the proof is similar if ik is not defined). We first show thatarc (i, jk) does not cross any arc in the current solutionwith nonzero flow and is, therefore, admissible. The proofis by contradiction. Let arc (i, jk) cross arc (p, q), which hasnonzero flow. Then, i < p and q < jk (because if p < i andjk < q, then arc (ik , jk) with nonzero flow crosses arc (p, q)

which has nonzero flow, which violates Lemma 4). Further,without loss of generality, let (p, q) be the highest arc at pwith nonzero flow. Then, p �= ik because from the definitionof R in Lemma 8, (ik , jk) is the highest arc at ik with nonzeroflow. Also, p ≯ ik because in that case arcs (p, q) and (ik , jk)with nonzero flow cross, which violates Lemma 4. Hence,i < p < ik (Fig. 9). Then, since (q, p) /∈ R (follows from thedefinition of ik), we know that (p, q) is not the lowest incom-ing arc at q with nonzero flow; let the lowest incoming arc at qwith nonzero flow be (v, q) where p < v. Now v ≯ ik becausethen arc (v, q) will cross arc (ik , jk) with nonzero flow, whichviolates Lemma 4. Hence, p < v ≤ ik . Also, (v, q) is thehighest outgoing arc at v with nonzero flow because other-wise the highest outgoing arc at v with nonzero flow willcross arc (p, q) with nonzero flow, which violates Lemma 4.Hence, (q, v) ∈ R and p < v < ik . This is a contradiction,because if it were true, min {s : (r, s) ∈ R and i < s} �= ik .Hence, we have proved that arc (i, jk) is admissible.

Next, we show that arc (i, jk) is the only admissible arcoriginating at node i. The proof is once again by contradiction.Let (i, l) be another admissible arc, where l �= jk . Suppose l >

jk . Then, arc (i, l) crosses arc (ik , jk) with nonzero flow, whichis not possible since it is admissible; hence, l < jk . Supposea noncrossing path P contains arc (i, l). Then, P contains an

FIG. 9. Illustration for Lemma 9.

admissible reverse arc (l, w). Now, w ≯ ik because then arc(l, w) will cross arc (ik , jk) with nonzero flow, which violatesLemma 4. Also, w �= ik because (ik , jk) is the highest arc at ikwith nonzero flow. If i < w < ik , then ik �= min {s : (r, s) ∈ Rand i < s}; a contradiction. Finally, w ≮ i because then Pwill contain the sequence of nodes i − l − w which violatesTheorem 2. Hence, we have shown that admissible arc (i, l)where l �= jk does not exist, and the result follows. ■

By the definition of admissible arcs, it is sufficient toconsider the sub graph G∗(x) (of G(x)) that is inducedby the admissible arcs while determining the shortest non-crossing path. G∗(x) contains O(n1) admissible supply arcs,O(n1) admissible regular transportation arcs (Lemma 9),and O(min {n1, n2}) admissible reverse transportation arcs(Lemma 8); hence, it contains O(n1) arcs. Also, observe thatG∗(x) is acyclic. Hence, the shortest noncrossing path in eachiteration of the algorithm can be determined in O(n1) time bysolving a shortest path problem on an acyclic network. Wesummarize the entire discussion as the following result.

Theorem 4. Let the set of admissible reverse arcs beR = {(j1, i1), (j2, i2), . . . , (jt , it)} as defined in Lemma 8. Anaugmenting path is noncrossing if and only if it is of theform 0 − i − jk − ik − jk+1 − ik+1 − · · · − jt − it − j whereik = min{s : (r, s) ∈ R and i < s}. The shortest noncrossingpath can be determined in O(n1) time by solving a shortestpath problem on a acyclic network G∗ with O(n1) arcs.

Each noncrossing path P has O(n∗) arcs (where n∗ =min {n1, n2}). Hence, determining the residual capacity of Pand updating the flows on its arcs can be performed in O(n∗)time.

So far, we have not accounted for the time spent in con-structing G∗. In order to efficiently construct G∗, we maintainthe following data structures. At each supply node i, we main-tain a list A(i) of outgoing arcs with nonzero flow sorted fromthe highest arc to the lowest arc. Similarly, at each demandnode j, we maintain a list B(j) of incoming arcs with nonzeroflow sorted from the lowest arc to the highest. Observe that:(i) at the start of the algorithm, A(i) = { } and B(j) = { }and (ii) |A(i)| ≤ n2 and |B(j)| ≤ n1. Also, given A(i) and

NETWORKS—2013—DOI 10.1002/net 143

Page 9: Faster strongly polynomial algorithms for the unbalanced transportation problem and assignment problem with monge costs

B(j) at the start of any iteration of the algorithm, we can con-struct R and G∗ in O(n1) time. Hence, updating A(i) and B(j)efficiently is crucial to the time complexity. The followingproperties allow us to perform these updates efficiently.

Lemma 10. Let (i, j) be a regular transportation arc innoncrossing path P. Then, after the augmentation on P, (i, j)is the lowest arc at node i with nonzero flow.

Proof. If (i, j) is the last arc in P, then the result followsfrom Lemma 2. If (i, j) is not the last arc in P, then P containsthe sub sequence i − j − k where i < k (Theorem 2) and(j, k) is a reverse arc. If (i, j) is not the lowest arc at node iwith nonzero flow, then the lowest arc at node i with nonzeroflow crosses arc (k, j) with nonzero flow (before the flowaugmentation), which violates Lemma 4. ■

Lemma 11. Let (i, j) be a regular transportation arc innoncrossing path P other than the second arc. Then, afterthe augmentation on P, (i, j) is the highest arc at node j withnonzero flow.

Proof. Similar to the proof of Lemma 10. ■

A(i) and B(j) need to be updated whenever the flow ona transportation arc changes from zero to a positive valueor vice versa during an augmentation. Suppose the flow ontransportation arc (i, j) changes from a positive value to zero;then (j, i) ∈ R before the flow augmentation. Also, (i, j) is thefirst arc in A(i) and the first arc in B(j) (Lemma 8). Accord-ingly, we delete the first item from both A(i) and B(j) in O(1)time, and we are done. Suppose the flow on transportation arc(i, j) changes from zero to a positive value. Then, we append(i, j) at the end of A(i) in O(1) time (Lemma 10). If (i, j) isthe not the second arc in P, then we append (i, j) at the endof B(j) in O(1) time (Lemma 11), and if (i, j) is the secondarc in P, then we insert (i, j) at the correct position in B(j) inO(n1) time. In each augmentation, the flows on at most O(n∗)arcs change from a positive value to zero or vice versa andthese arcs can be identified in O(n∗) time by traversing theaugmenting path. Thus, the total time spent in updating A(i)and B(j) after each augmentation is O(n∗ + n1) = O(n1).

Based on the preceding discussion, we have the followingresult.

Theorem 5. Our algorithm solves the unbalanced trans-portation problem with Monge costs in O(mn1) time and theunbalanced assignment problem with Monge costs in O(m)time.

5. A FASTER IMPLEMENTATION OF THEALGORITHM

Observe that the bottleneck steps in the previous imple-mentation are the time required to: (i) determine the shortestpath and update G∗, which is O(n1) and (ii) determine theresidual capacity of the augmenting path and augment or

FIG. 10. Illustration for Lemma 12.

update flows, which is O(n∗). We now describe the use ofdata structures and the properties of the problem to reduce theamortized time spent on these steps to O(log n1) per iteration.

The speed-up is specifically achieved through the follow-ing improvements to the algorithm:

• We prove that it is sufficient to store the flows on a smallset of O(n1) arcs; we refer to these arcs as critical arcs.

• We do not explicitly construct G∗; rather we manipulatethe flows on critical arcs using sophisticated data struc-tures. This allows us to determine the residual capacity ofa noncrossing path and augment flows in O(log n1) time(rather than in O(n∗) time).

• We maintain the cost of the shortest noncrossing path inG∗ between supply nodes i ∈ N1 and the current demandnode using sophisticated data structures. The data struc-tures allow us to determine the shortest path in O(log n1)

time (rather than in O(n1) time).

Let R = {(j1, i1,), (j2,i2), . . . , (jt,it)} be the set of admissi-ble reverse arcs. The set of critical arcs whose flows we storeconsist of the following: (i) admissible reverse arcs (in R); (ii)admissible regular arcs (i1, j2), (i2, j3), . . . , (it−1, jt); and (iii)supply arcs (0, i). The flows on all other arcs are determined(as needed) in constant time using the following property.

Lemma 12. Let P = 0 − i − jk − ik − jk+1 − ik+1 − · · · −jt − it − j be a noncrossing augmenting path in the algorithm.Let (jr , ir) and (jr+1, ir+1) be reverse arcs that belong to Pand let (p, q) be a transportation arc. Then, (i) if p = irand jr < q < jr+1, xpq = dq; and (ii) if q = jr+1 andir < p < ir+1, xpq = x0p.

Proof.

(i) jr < q < jr+1 (Fig. 10). Let (u, q) be an incoming arcat node q. If u < ir or u > ir+1, then xuq = 0 (becauseotherwise arc (u, q) with nonzero flow will cross an arcin the current solution with nonzero flow, which violatesLemma 4). Similarly, if ir < u ≤ ir+1, then xuq = 0because otherwise P crosses an arc with nonzero flow.Thus, (ir , q) is the only incoming arc at q with nonzeroflow, and the result follows.

144 NETWORKS—2013—DOI 10.1002/net

Page 10: Faster strongly polynomial algorithms for the unbalanced transportation problem and assignment problem with monge costs

(ii) Let ir < p < ir+1. Using similar arguments, we canshow that (p, jr+1) is the only outgoing arc at node pwith nonzero flow, and the result follows.

5.1. Data Structures Used

Let R = {(j1, i1, ), (j2,i2), . . . , (jt,it)} be the set of admis-sible reverse arcs as defined in Lemma 8. We maintain thefollowing primary data structures to store flows on criticalarcs:

• A dynamic tree TR which contains the set of admissiblereverse arcs in R and their residual capacities. TR is of theform i1 → j1 → i2 → j2 → · · · → it → jt . The value ofarc (ik,jk) is the residual capacity of arc (jk , ik) and the valueof arc (jk , ik+1) is infinity (or a suitably large number).

• A dynamic tree TF that contains the flow on admissibleregular arcs (i1, j2), (i2, j3), . . . , (it−1,jt). TF is of the formi1 → j2 → i2 → j3 → · · · → it−1 → jt . The value of arc(ik , jk+1) is the flow on arc (ik , jk+1) and the value of arc(jk , ik) is infinity.

• An array AS that contains the flows x0i on each supply arc.

We also maintain a dynamic tree TC that contains the costof the shortest path in G∗ between supply nodes i ∈ N1 andthe current demand node. TC is of the form 1 → 2 → 3 →· · · → n1 → (n1 + 1). The value of arc (i, i + 1) is the costof the shortest noncrossing path in G∗(x) from node i to thecurrent demand node j if x0i < u0i and is infinity otherwise.

Finally, we maintain the following auxiliary data struc-tures that allow us to update the flows on critical arcsefficiently.

• A self-balancing binary search tree TL (red-black tree orAVL tree) that contains intervals [1, i1), [i1, i2), [i2, i3), . . . ,[it−1, it). The key is the first element in each interval.

• A list of arcs LA(i) at each supply node i that containsoutgoing arcs with nonzero flow. The list is sorted fromthe highest arc to the lowest arc.

• A max-heap of arcs HB(j) at each demand node j thatcontains the incoming arcs with nonzero flow. The key isthe tail node index of the arcs in the heap.

TR and TF contain O(n∗) arcs, AS contains O(n1) arcs,LA(i) contains O(n2) arcs, HB(j) contains O(n1) arcs, TCcontains O(n1) arcs, and TL contains O(n∗) intervals.

In Appendix, we list the basic operations that are per-formed on the data structures and their time complexities.For complete details, we refer the reader to Sleator and Tar-jan [15] and Cormen et al. [6]. In the following discussion, wewill first focus on operations performed on the primary datastructures (assuming that all the auxiliary data structures havebeen updated as required) and will address the operations onthe auxiliary data structures toward the end of Section 5.

5.2. Initializing Primary Data Structures

At the start of the algorithm, TR and TF are empty, andTC contains arcs (i, i +1) for i ∈ [1, n1] with the value of arc

(i, i + 1) set to Ci,n1+1 (since, n1 + 1 is the index of the firstdemand node). TC is initialized in O(n1 log n1) time using n1

link(TC, i, i+1, Ci,n1+1) operations. Thus, the total time spentin initializing the primary data structures is O(n1 log n1).

5.3. Identifying the Shortest Noncrossing Path and itsResidual Capacity

Let j′ be the current demand node in the algorithm. Wedetermine the second node in the shortest noncrossing pathP in O(log n1) time using i := minvalue(TC, 1). Next, wedetermine the interval to [ik−1, ik) to which node i belongs inO(log n∗) time using [ik−1, ik) := find(TL, i). If the intervalis not defined, then P = 0− i− j′; otherwise, P = 0− i− jk −ik − jk+1 − ik+1 −· · ·− jt − it − j′. In the first case, the quantityof flow augmented is f := min {u0i −x0i, −e(j)} and it can bedetermined in O(1) time. In the second case, the quantity offlow augmented is f := min {u0i − x0i, −e(j), minvalue(TR,ik)} and it can be determined in O(log n∗) time. Thus, wedetermine the shortest noncrossing path and the quantity offlow augmented in O(log n1) time in each iteration, and thetotal time spent on operations described in this section isO(m log n1).

5.4. Updating Costs and Flows due to Flow Augmentation

Next, consider the time taken to update the data structuresafter augmenting f units of flow on shortest noncrossing pathPij′ , where i is the second node and j′ is the last node in thepath.

1. We update x0i := x0i + f and e(j) := e(j) + f in O(1)time.

2. We update the residual capacities of arcs in TR thatbelong to Pij′ using update(TR, ik , −f ) (if ik is defined)in O(log n∗) time.

3. We update the flows on arcs in TF that belong to Pij′using update(TF, ik , f ) in O(log n∗) time.

4. We update TC to account for the change in the costs ofshortest noncrossing paths. Suppose x0i = u0i after theaugmentation; we set value of arc (i, i + 1) to infinity inO(log n1) time using value(TC, i) := ∞. From Theo-rem 4, the cost of shortest noncrossing paths will changewhenever R changes, which can only happen when theflow on a transportation arc changes from a positive valueto zero. For each arc (il , jl) in TR whose flow becomeszero after the update in Step 2 (each such arc is identifiedin O(log n∗) time using a minvalue and parent operationon TR), we update TC as follows.

Let (p, jl) be the arc preceding (jl , il) and let (il , q)

be the arc succeeding (jl , il) in Pij′ (Fig. 11). Let (u, jl)be the root arc in HB(jl), where p ≤ u < il . Similarly, let(il , v) be the first arc in LA(il), where jl < v ≤ q. For thesake of discussion, let us assume that (u, jl) is the firstarc in LA(u) and (il , v) is the root arc in HB(v) (the mostgeneral scenario which requires the most updates).

Case 1: p < u < il and jl < v < q. Observe that thecosts of shortest noncrossing paths to demand node j′from supply nodes in [il , n1] do not change. The cost of

NETWORKS—2013—DOI 10.1002/net 145

Page 11: Faster strongly polynomial algorithms for the unbalanced transportation problem and assignment problem with monge costs

FIG. 11. Illustration for Section 5.4, Step 4.

shortest noncrossing paths to demand node j′ from allsupply nodes in [1, u) is updated in O(log n1) time usingupdate (TC, 1, u − 1, (−Cujl + Cuv − Cilv ) − (−Ciljl ))

(because the shortest noncrossing path from these nodescontains the sub-path jl − u − v − il instead of jl − il).

The cost of shortest paths from each node r in [u, il)is updated in O(log n1) time using update (TC, u, il −1, (Crv − Cilv) − (Crjl − Ciljl ) (sub path r − jl − il isreplaced with sub-path r − v − il). For each node r,this takes O(log n1) time. Observe that each time theupdate is performed at a given node r, the index of thecorresponding demand node v increases; this can happenat most O(n2) times for a given supply node r (since,there are n2 demand nodes). Because there are n1 supplynodes, the total time spent to update costs during theentire algorithm is O(n1n2 log n1) = O(m log n1).

Case 2: u = p and v = q. Similar operations as Case 1.

Case 3: p < u < il and v = q (or) u = p and jl < v < q.Similar operations as Case 1.

The number of flow augmentations is O(m) (The-orem 3) and the total number of times flow on an arcchanges from a positive value to zero or vice versa isO(m) (Lemma 6). Thus, the time spent in: (i) Step 1 isO(m); (ii) Steps 2 and 3 is O(m log n∗); and (iii) Step4 is O(m log n1). Accordingly, the total time spent onoperations described in this section is O(m log n1).

5.5. Updating Costs When Demand Node Changes

Consider the time spent to update the costs when the algo-rithm moves from demand node j′ to j′ + 1. Let (r, j’) bethe root arc in HB(j′). If (r, j’) is also the first arc in LA(r),we need to insert (j′, r) into R (see Section 5.6.2 to see howthis is achieved). This means that the shortest noncrossingpath to node j′ + 1 from any supply node i < r will be theshortest path from i to j′ concatenated with arcs (j′, r) and

(r, j′ +1). We update TC in O(log n1) time using update(TC,1, r−1, −C′

rj+Cr,j′+1). For p ∈ [r, n1], we set the value of arc(p, p+1) to Cp,j′+1 using value(TC, p) = Cp,j′+1 in O(log n1)

time (because the corresponding shortest noncrossing path is0 − p − (j′ + 1)); each time the algorithm moves to a nextdemand, this takes O(n1 log n1) time. The total time spentis, therefore, O(n1n2 log n1) or O(m log n1). Suppose (r, j′)is not the first arc in LA(r); then R does not change and weupdate TC in a similar manner.

5.6. Other Data Structure Updates

In this section, we describe the updates performed to theauxiliary data structures as well as other updates to the pri-mary data structures. At the start of the algorithm, all arcshave zero flow, and, therefore, all auxiliary data structuresare empty.

5.6.1. Updates After a Flow Augmentation. Consider thetime taken to update the data structures after augmenting flowon noncrossing path Pij′ , where i is the second node and j′ isthe last node in the path. We determine the interval [ik−1, ik)to which node i belongs in O(log n∗) time using [ik−1, ik) :=find(TL, i).

1. Let (i, q) be the second arc in Pij′ . From Lemma 10,(i, q) is the lowest arc at node i with nonzero flow afterthe flow augmentation. Hence, if (i, q) is not already thelast element in LA(i), its flow changes from zero to a pos-itive value; in that case, we append (i, q) to LA(i) usingenqueue(LA (i), (i, q)) in O(1) time, and insert (i, q) intoHB(q) using insert(HB(q), (i, q)) in O(log n1) time.

2. For each arc (r, s) in Pij′ , other than the first twoarcs, whose flow is zero before the flow augmentation,we add (r, s) to the end of LA(r) (Lemma 10) usingenqueue(LA(r), (r, s)) in O(1) time and insert (r, s) intoHB(s) using insert(HB(s), (r, s)) in O(log n1) time. Eachsuch arc is identified in O(log n∗) time as described next.The first such arc (r1, s1) (if any) is identified as follows:(i) Compute r1 = minvalue(TF, ik); (ii) If value(TF,r1) = 0, then s1 = parent(TF, r1); else (r1, s1) is notdefined. If (r1, s1) is defined, then the second such arc(r2, s2) (if any) is identified as follows: (i) Computer2 = minvalue(TF, ik , r1); (ii) If value(TF, r2) = 0, thens2 = parent(TF, r2); else (r2, s2) is not defined. Thus, byrepeating the procedure, we can identify all arcs whoseflows change from zero to a positive value.

3. For each arc (il , jl) in TR whose flow becomes zero afterthe flow augmentation (each such arc is identified inO(log n∗) time using minvalue and parent operations onTR similar to Step 2), we do the following to update thedata structures:3.1. From the definition of R, (il , jl) is the first arc

in LA(il) and the root arc in HB(jl). We delete(il , jl) from LA(il) using pop(LA(il)) in O(1)time. We also delete (il , jl) from HB(jl) usingdeletemax(HB(jl)) in O(log n1) time.

3.2. Let (p, jl) be the arc preceding (jl , il) and let(il , q) be the arc succeeding (jl , il) in Pij′ (asshown in Fig. 11). Let (u, jl) be the root arc in

146 NETWORKS—2013—DOI 10.1002/net

Page 12: Faster strongly polynomial algorithms for the unbalanced transportation problem and assignment problem with monge costs

HB(jl), where p ≤ u < il . Suppose (u, jl) is alsothe first arc in LA(u); then xujl = x0u (Lemma12) and we need to insert (u, jl) into TR. Simi-larly, let (il , v) be the first arc in LA(il), wherejl < v ≤ q. Suppose (il , v) is also the root arc inHB(v); then xilv = dv (Lemma 12) and we needto insert (il , v) into TR if it is not already in TRand if v �= j′. For the sake of discussion, let usassume that (u, jl) is the first arc in LA(u) and(il , v) is the root arc in HB(v) (the most generalscenario which requires the most updates). Wenow describe in detail the implementation of theupdates outlined above. We only describe Case1 in full detail, because Cases 2 and 3 involvesimilar operations.

Case 1: p < u < il and jl < v < q. Due to the augmenta-tion, arc (jl, il) is deleted from TR and arcs (jl, u) and (v, il)need to be inserted into TR. Let TR contain the sequenceof arcs il−1 → jl−1 → il → jl → il+1 → jl+1 (weassume that il−1, jl−1, il+1, and jl+1 exist; if not, the approachcan be suitably modified). Then, we need to replace thissequence with the sequence il−1 → jl−1 → u → jl →il → v → il+1 → jl+1. This is achieved in O(log n∗)time using the following sequence of operations: [il−1, il) :=find(TL, il − 1), jl−1 := parent(TR, il−1), jl := parent(TR,il), cut(TR, jl−1), cut(TR, il), cut(TR, jl), link(TR, jl−1, u, ∞),link(TR, u, jl, x0u), link(TR, jl, il, ∞), link(TR, il, v, dv), andlink(TR, v, il+1, ∞). Similarly, TF contains the sequence ofarcs il−1 → jl → il → jl+1, which has to be replaced bythe sequence of arcs il−1 → jl → u → v → il → jl+1.The value of arcs (jl, u) and (v, il) are set to infinity, and thevalue of arc (u, v) is zero (if xuv �= 0, we will violate Lemma4 before the augmentation because arc (il, jl) with nonzeroflow crosses arc (u, v)). The associated updates to TF canalso be performed in O(log n∗) time in a similar fashion tothe updates to TR described above.

We also split the interval [il−1, il) in TL into twoparts [il−1,u) and [u, il) in O(log n∗) time using delete(TL,[il−1, il)), insert(TL, [il−1,u)), and insert(TL, [u, il)).

The cases (i) u = p and v = q, (ii) p < u < il and v = q(or) u = p and jl < v < q can be achieved using similaroperations as Case 1.

The number of flow augmentations is O(m) (Theorem 3)and the total number of times flow on an arc changes from apositive value to zero or vice versa is O(m) (Lemma 6). Thus,the time spent in this section is O(m log n1).

5.6.2. Updates when Demand Node Changes. Considerthe time spent to update data structures when the algorithmmoves from demand node j′ to j′ + 1. Let (r, j′) be the rootarc in HB(j′). If (r, j′) is also the first arc in LA(r), we needto add (r, j′) to TR and perform the associated updates givenbelow:

1. Update TR in O(log n∗) time using [it−1, it) := find-max(TL), link(TR, it , j′, ∞), and link(TR, j′, r, x0r). Notethat xrj′ = x0r because (r, j′) is the highest outgoing arc

at node r with nonzero flow, and from Lemma 2, it isalso the only outgoing arc with nonzero flow.

2. Update TF in O(log n∗) time using link(TF, jt , it , ∞)

and link(TF, it , j′, xitj′). Note that we can keep track ofthe flow on arc (it , j′) by spending O(1) time per flowaugmentation.

3. Update TL in O(log n∗) time using insert(TL, [it , r)).

Because the problem has O(n2) demand nodes, the totaltime spent in Steps 1–3 is O(n2 log n∗ + m).

5.7. Overall Complexity of the Algorithm

From our preceding discussion in Sections 5.2–5.6, wesee that the total time spent in all operations described sofar is O(m log n1). Observe that at the end of the algorithm,we know the optimal values of x0i. Thus, we can apply thenorthwest corner algorithm for the balanced transportationproblem (Hoffman [10]) to determine the optimal flows on allarcs in O(n) time. We therefore have the following concludingresult.

Theorem 6. An implicit implementation of our algorithmusing sophisticated data structures solves the unbalancedtransportation problem with Monge costs in O(m log n1)

time.

Note that while this implementation is faster from a worstcase complexity point of view, it has associated overheadsdue to the reliance on sophisticated data structures. Whichimplementation is better from a practical point of view canonly be determined by performing an empirical analysis onrepresentative networks of different sizes. Also, as researchon data structures progresses, alternative and simpler imple-mentations of sophisticated data structures are discovered.The best data structure variant is a function of both the sizeof the network and the application or context in which thedata structure is used (see, e.g., Tarjan and Werneck [17] foran empirical comparison of nine variants of dynamic trees onvarious networks and applications). While the focus of thisarticle is on worst case time complexity, an empirical study todetermine the best practical implementation will be of valueto practitioners and could be the focus of a future study.

APPENDIX: DATA STRUCTURE OPERATIONS

Dynamic Tree Operations

• parent(T , i): Returns the parent of node i in T .• value(T , node i): Returns/initializes the value of arc (i,

parent(T , i)).• link(T , node i, node j, real f ): The operation assumes that

node i is the root of a tree in T . It adds arc (i, j) with realvalue f , making j the parent of i.

• cut(T , node i): Divides the tree containing node i into twotrees by deleting arc (i, parent(T , i)).

• update(T , node i, real f ): Adds a real number f to the valuesof all arcs in T in the path between node i and the root.

NETWORKS—2013—DOI 10.1002/net 147

Page 13: Faster strongly polynomial algorithms for the unbalanced transportation problem and assignment problem with monge costs

• update(T , node i, node j, real f ): The operation assumesthat node j is an ancestor of node i. It adds a real numberf to the values of all arcs in T in the path between node iand node j.

• minvalue(T , node i): Returns the node k closest to the rootsuch that value(T , k) is the smallest among the values ofall the arcs in the path between node i and the root.

• minvalue(T , node i, node j): The operation assumes thatnode j is an ancestor of node i. The operation returns thenode k closest to node j such that value(T , k) is the smallestamong the values of all arcs in the path between node i andnode j in T .

Red-Black Tree Operations

• insert(T , [r, s)): Adds an interval [r, s) to T .• delete(T , [r, s)): Deletes an interval [r, s) from T .• find(T , i): Returns the interval in T to which i belongs.• findmax(T): Returns the interval with the largest key.

Max-Heap Operations

• insert(H, (r, s)): Adds an arc (r, s) to H.• findmax(H): Returns the arc in H with the maximum tail

node index.• deletemax(H): Deletes the arc with the maximum tail node

index from H.

List Operations

• enqueue(L, (r, s)): Appends an arc (r, s) to L.• dequeue(L): Deletes the last arc from L.• pop(L): Deletes the first arc from L.

The operations on dynamic trees and red-black trees canbe performed in O(log y) time, where y is the number ofitems in the respective data structure. For the max-heap, find-max(H) can be performed in O(1) time, and insert(H, a)

and deletemax(H) can be performed in O(log y) time. Theoperations on the list can be performed in O(1) time.

Acknowledgments

The author thanks the anonymous referees, the AssociateEditor, and the Editor-in-Chief Professor Doug Shier fornumerous suggestions that resulted in an improved presen-tation of this research. The author dedicates this work to hiswife Sirisha and to his son Sanjeev.

REFERENCES

[1] A. Aggarwal, A. Bar-Noy, S. Khuller, D. Kravets,and B. Schieber, Efficient minimum cost matching and

transportation using the quadrangle inequality, J Algorithms19 (1995), 116–143.

[2] R.K. Ahuja, T.L. Magnanti, and B.J. Orlin, Network flows:Theory, algorithms, and applications, Prentice-Hall, NJ,1993.

[3] R.E. Burkard, Monge properties, discrete convexity andapplications, Eur J Oper Res 176 (2007), 1–14.

[4] R.E. Burkard, B. Klinz, and R. Rudolf, Perspectives of Mongeproperties in optimization, Discr Appl Math 70 (1996),95–161.

[5] S.R. Buss and P.N. Yainilos, “Linear and O(n log n) timeminimum cost matching algorithms for quasi-convex tours,”Proc 5th ACM-SIAM Sympo Discr Algorithms, Arlington,VA, USA, 1994, pp. 65–76.

[6] T.H. Cormen, C.E. Leiserson, R.L. Rivest, and C. Stein,Introduction to algorithms, MIT Press, Cambridge, MA,2001.

[7] J. Edmonds and R.M. Karp, Theoretical improvements inalgorithmic efficiency for network flow problems, J ACM 19(1972), 248–264.

[8] J.R. Evans, The factored transportation problem, Manage Sci30 (1984), 1021–1024.

[9] M.L. Fredman and R.E. Tarjan, Fibonacci heaps and theiruses in improved network optimization algorithms, J ACM34 (1987), 596–615.

[10] A.J. Hoffman, “On simple linear programming problems,”Proc Symposia in Pure Math, American Mathematical Soci-ety, Providence, RI, 1963, pp. 317–327.

[11] R.M. Karp and S.Y.R. Li, Two special cases of the assignmentproblem, Disc Mathe 13 (1975), 129–142.

[12] O. Marcotte and S. Suri, Fast matching algorithms for pointson a polygon, SIAM J Comput 20 (1991), 405–422.

[13] J.B. Orlin, A faster strongly polynomial minimum cost flowalgorithm, Oper Res 41 (1993), 377–387.

[14] J.B. Orlin and B. Vaidyanathan, Fast algorithms for convexcost flow problems on circles, lines, and trees, Accepted forpublication in Networks.

[15] D. Sleator and R.E. Tarjan, A data structure for dynamic trees,J Comput Sys Sci 26 (1983), 362–391.

[16] W. Szwarc, Instant transportation solutions, Nav Res LogQuart 22 (1975), 427–440.

[17] R.E. Tarjan and R.F. Werneck, Dynamic trees in practice,J Exp Algorithm 14 (2009).

[18] B. Vaidyanathan, Simple linear flow decomposition algo-rithms on trees, circles, and augmented trees, Networks 60(2012), 227–234.

[19] B. Vaidyanathan and R.K. Ahuja, Fast algorithms for spe-cially structured minimum cost flow problems with applica-tions, Oper Res 58 (2010), 1681–1696.

148 NETWORKS—2013—DOI 10.1002/net