Mar 13, 1996 - we show how our bottleneck shortest-path techniques can be used to obtain fast ... In an algebraic combinatorial optimization problem, we are given a .... where s1; s2;:::;sm+n is the sorted sequence obtained by merging the .... k, the array A` = fa` i; j]g is algebraic Monge. Our algorithm contains k phases.
Algebraic Monge Property and Applications Wolfgang W. Bein
Peter Bruckery Dina Kravetsz March 13, 1996
James K. Parkx
Abstract
When restricted to cost arrays possessing the sum Monge property, many combinatorial optimization problems with sum objective functions become signi cantly easier to solve. (An array A = fa[i; j ]g possesses the sum Monge property if for all i < k and j < `, a[i; j ] + a[k; `] a[i; `] + a[k; j ].) Examples include the usual sum-objective-function versions of the assignment problem, the transportation problem, the traveling-salesman problem, and several shortest-path problems. Furthermore, the more general algebraic assignment and transportation problems, which are formulated in terms of an ordered commutative semigroup (H; ; ), are similarly easier to solve given cost arrays possessing the corresponding algebraic Monge property, which requires that for all i < k and j < `, a[i; j ] a[k; `] a[i; `] a[k; j ]. In this paper, we show that Monge-array results for two sum-of-edge-costs shortest-path problems can likewise be extended to a general algebraic setting, provided the problems' ordered commutative semigroup (H; ; ) satis es one additional restriction. Speci cally, we require that for all a; b; c 2 H , a b implies c a c b. In addition to this general result, we also show how our algorithms can be modi ed to solve certain bottleneck shortest-path problems, even though the ordered commutative semigroup ( c[i; j 0 ], then L R. In all the cases, we have shown that we can tell the relationship between L and R by examining and comparing only f [i], c[i; j ] and c[i; j 0 ].
Because of the above claim, instead of storing and manipulating an entire tuple, we can simply keep its rst element. Thus, the times ta and tc are reduced to O(1), and using the proof of Theorem 3, we can solve the bottleneck k-edge shortest-path problem in O(kn) time. 6
Theorem 8 The bottleneck unrestricted shortest-path problem for an n-vertex directed acyclic graph whose edge costs possess the strict bottleneck Monge property can be solved in O(n) time.
Proof All the discussion in the proof of Theorem 6 applies here. The only dierence is that in
solving the algebraic unrestricted shortest-path problem (Theorem 4), we used the algorithm of Larmore and Schieber [LS91], instead of SMAWK. However, just like in SMAWK, the algorithm of Larmore and Schieber also makes comparisons only between elements in the same row of the input array. Thus, using the proofs of Theorems 4 and 6 we can solve the bottleneck unrestricted shortest-path problem in O(n) time.
4 An Alternate Algorithm for the Bottleneck k-edge Shortest-path In this section we present a second algorithm for the bottleneck k-edge shortest-path problem that in some sense generalizes Aggarwal, Schieber, and Tokuyama's [AST94] algorithm. Our algorithm is based on a O(n)-time query subroutine for determining whether the graph contains a k-edge 1 ; n path using only edges whose costs are less than or equal to some threshold T . To create the query subroutine, we need two technical lemmas. We say that a path satis es the threshold if every edge on the path is less than or equal to T . De ne the following two graphs with the same vertex and edge sets at G, but with dierent cost functions: a graph G0T = (V; E ) with edge costs (
c[i; j ] T c0 [i; j ] = 1+1 ifotherwise and a graph G00T = (V; E ) with edge costs
c00 [i; j ] =
(
?1 if c[i; j ] T +1 otherwise
Lemma 9 If the cost array C = fc[i; j ]g is bottleneck Monge, then the arrays C 0 = fc0 [i; j ]g and C 00 = fc00 [i; j ]g are Monge. Proof We prove the lemma for the array C 0 = fc0 [i; j ]g. The proof for C 00 is identical. We prove by contradiction. Since all the entries in C 0 are either 1 or +1, there are only two possible ways how C 0 may not be Monge. Case 1: For some i; j; k; `, both c0 [i; `] and c0 [j; k] are 1 and either c0[i; j ] or c[k; l] are +1. Case 2: For some i; j; k; `, one of c0[i; `] or c0 [j; k] is +1 and both c0[i; j ] and c0 [k; l] are +1. Case 1 implies that in C , both c[i; `] and c[j; k] are T and either c[i; j ] or c[k; l] are > T . This means that maxfc[i; j ]; c[k; l]g > maxfc[i; `]; c[j; k]g, which violates the bottleneck Monge property of C . Case 2 implies that in C one of c[i; `] or c[j; k] is > T and both c[i; j ] and c[k; l] are > T . This means that either maxfc[i; j ]; c[k; l]g > maxfc[i; `]; c[j; k]g, which violates the bottleneck Monge property of C ; or that both maxfc[i; j ]; c[k; l]g = maxfc[i; `]; c[j; k]g and minfc[i; j ]; c[k; l]g > minfc[i; `]; c[j; k]g, which also violates the bottleneck Monge property of C .
Lemma 10 Suppose the unrestricted shortest 1 ; n path P in G0T contains k0 edges and has length that is less than +1. Also, suppose the unrestricted shortest 1 ; n path Q in G00T contains k00 edges and has length that is less than +1. Then there exists a k-edge 1 ; n path in G that satis es the threshold if k0 k k00 . 7
Proof Note that because of the edge costs in G0T and G00T , k0 k00 . Also, if either k = k0 or k = k00 ,
we are done. Thus, assume that k0 < k < k00 . Our approach is to take the two paths P and Q and use them to create two new 1 ; n paths P 0 and Q0 that contain k0 + 1 and k00 ? 1 edge respectively, and satisfy the threshold. By repeating this procedure, we can create a 1 ; n path of any length k for k0 < k < k00 that satis es the threshold, thus proving the lemma. Let i ; j be the subpath of P from vertex i to vertex j and let ji ; j j be the number of edges on that subpath. To create P 0 and Q0 , notice that by the pigeon-hole principle, there is an edge (i; t) in P and an edge (s; j ) in Q such that i < s < j t and j1 ; tj = j1 ; sj. Let Q0 consists of 1 ; i, followed by the edge (i; j ), followed by j ; n; and P 0 consists of 1 ; s, followed by the edge (s; t), followed by t ; n. Clearly, P 0 and Q0 are both 1 ; n paths. Since j1 ; ij = j1 ; sj? 1, we conclude that j1 ; nj = k0 + 1 and j1 ; nj = k00 ? 1. The only thing that remains to be shown is that both P 0 and Q0 satisfy the threshold. If j = t, then the set of edges that appear in P 0 and Q0 are exactly the same as the set of edges that appear in P and Q, and therefore P 0 and Q0 satisfy the threshold. Thus, we assume that j < t. The set of edges that appear in P 0 and Q0 are the same as the set of edges that appear in P and Q, except that the edges (i; t) and (s; j ) are replaced by edges (i; j ) and (s; t). By the bottleneck Monge property, we know that maxfc[i; j ]; c[s; t]g < maxfc[i; t]; c[s; j ]g or both maxfc[i; j ]; c[s; t]g = maxfc[i; t]; c[s; j ]g and minfc[i; j ]; c[s; t]g minfc[i; t]; c[s; j ]g. Since the edges (i; t) and (s; j ) are on paths P and Q, we know that they both cost T . By the bottleneck Monge property, both c[i; j ] and c[s; t] are T , and thus P 0 and Q0 satisfy the threshold. P
P
P
Q
P
Q
P
P'
P
P
P
Q'
We are now ready to design the query subroutine for determining whether the given graph contains a k-edge 1 ; n path that uses only edges whose costs are less than or equal to some threshold T . Given Lemmas10, such a path exists if k0 k k00 , where k0 is the length of the unrestricted shortest 1 ; n path in G0T and k00 is the length of the unrestricted shortest 1 ; n path in G00T . Using the algorithm of Larmore and Schieber [LS91], we can determine the length of the unrestricted shortest 1 ; n path in a graph with Monge property in O(n) time. Since the cost arrays of both G0T and G00T satisfy the Monge property (Lemma 9), our query subroutine runs in O(n) time.
Theorem 11 The bottleneck k-edge shortest-path problem for an n-vertex graph whose edge costs
possess the strict bottleneck Monge property can be solved in O(n3=2 lg2 n) time (or in O(n lg2 n) time if the problem's cost array is also bitonic1).
Proof We use the result of Agarwal and Sen [AS94], who show how to nd the d-th smallest entry p in an m n totally monotone array in O((m + n) n lg n) time. For our n n totally monotone array, this translates into O(n3=2 lg n) time. There are n2 entries in the n n cost array CT of
the bottleneck shortest-path problem. We perform a binary search on these n2 entries by calling the procedure Binary-Search(CT , 1, n2 ). Binary-Search(CT , i, j ) does the following. We use Agarwal and Sen [AS94] to nd the b j +2 i c-th smallest entry in CT , which we call . We use our query algorithm to test if the graph contains a k-edge 1 ; n path that uses only edges whose costs are less than or equal to . If the query answers \yes", then we call Binary-Search(CT , i, b j +2 i c); otherwise we call Binary-Search(CT , b j +2 i c, j ). The binary search returns to us the smallest entry in CT for which there exists a k-edge 1 ; n path that uses only edges whose costs are less than or equal to . Thus, is the bottleneck-cost of the bottleneck k-edge shortest-path. To nd the actual path, we can use the ideas from the proof of Lemma 10. We compute the unrestricted shortest 1 ; n paths P and Q, jP j = k0 , jQj = k00 , in the graphs G0 and G00 . Scanning An n-entry vector B = fb[i]g is called bitonic if there exists an i satisfying 1 i n such that b[1] b[i ? 1] b[i] b[i + 1] b[n]. We call a 2-dimensional array bitonic if its rows or its columns are bitonic. 1
8
vertices in increasing order starting at 1, we then look for the edge (i; t) in P and an edge (s; j ) in Q that satisfy i < s < j t and j1 ; tj = j1 ; sj. Let Q0 consists of 1 ; i, followed by the edge (i; j ), followed by j ; n; and P 0 consists of 1 ; s, followed by the edge (s; t), followed by t ; n. From Lemma 10, we know that P 0 and Q0 are both 1 ; n paths that satisfy and that jP 0 j = k0 + 1 and jQ0 j = k00 ? 1. If k = k0 + 1 or k = k00 ? 1, we are done. Otherwise, we repeat this procedure, except that we start our search for the new edges where we want to switch the paths not from vertex 1, but from vertices i and s. Thus, the total running time to nd the path given is O(n + k) = O(n). The total running time to nd the bottleneck k-edge shortest-path is O(lg n2 (n3=2 lg n + n)) = O(n3=2 lg2 n). In the case of bitonic cost array, the selection problem is simpler. The selection algorithm of Frederickson and Johnson [FJ82] computes the n largest elements overall in O(n) sorted lists in O(n) time. When the array is bitonic, we can easily decompose it into 2n sorted lists in O(n lg n) time. Applying Frederickson and Johnson [FJ82], we can compute the d-th smallest entry in an n n bitonic array in O(n lg n) time. Thus, for cost arrays that satisfy the string bottleneck Monge property and are bitonic, the k-edge shortest-path can be found in O(n lg2 n) time. Using a similar query technique, we can also obtain the following result for unbalanced assignment problem. Theorem 12 The bottleneck assignment problem for an m n bipartite graph,pwhere m n and the edge costs possess the strict bottleneck Monge property can be solved in O((m n lg m + n) lg2 n) time (or in O(m lg2 n + n lg n) time if the problem's cost array is also bitonic). Proof We say that a matching satis es the threshold T if all the edges of the matching have weight T or less. First, we design a query algorithm analogous to the one used in Theorem 11. The query algorithm is given a bipartite graph G and a threshold T , determines is there is a perfect matching of G that satis es the threshold. The query algorithm is greedy. It works by nding the minimum value j1 such that w[1; j1 ] T , then the minimum value j2 such that w[2; j2 ] T and j2 > j1 , then minimum value j3 such that w[3; j3 ] T and j3 > j2 , and so forth. This algorithm takes O(n) time. If this algorithm produces a perfect matching, then clearly this matching satis es the threshold. Furthermore, it is not dicult to see that if there exists a perfect matching that satis es the threshold, then our algorithm nds one such matching. To see this, consider any perfect matching M that satis es the threshold. Consider the rst vertex i such that (i; ji ) 62 M . We show how to get another perfect matching M 0 in which the rst vertex i0 such that (i0 ; ji0 ) 62 M 0 is greater than i. Suppose that i is matched to ` in M . Our computation of ji guarantees that ` > ji . If ji is unmatched in M , then we can simply remove (i; `) and add (i; ji ) to get another perfect matching M 0 that satis es the threshold and contains (i; ji ). Hence, assume that ji is matched in M to s, s > i. By the strict bottleneck Monge property, we have that maxfc[i; ji ]; c[s; `]g < maxfc[i; `]; c[s; ji ]g or both maxfc[i; ji ]; c[s; `]g = maxfc[i; `]; c[s; ji ]g and minfc[i; ji ]; c[s; `]g minfc[i; `]; c[s; ji ]g. Thus, if M satis es the threshold, then M 0 = M ?f(i; `); (s; ji )g + f(i; ji ); (s; `)g is another perfect matching and it contains (i; ji ). To complete the proof, we use the query algorithm just as in the proof of Theorem 11. We use the algorithm of Agarwal and Sen [AS94] in our binary search, and for each d-th smallest value T in the m n cost array, we query to see if there exists a perfect matching that satis es the threshold T . The total running time is O(lg(mn)((m + n)pn lg n + n)) = O(n3=2 lg2 n). Similarly, if the cost array is bitonic, then the running time is O(lg(mn)(m lg n + n)) = O(m lg2 n + n lg n). P
P
Q
P
Q
P
5 Applications We conclude with three applications of our bottleneck-shortest-path techniques. 9
5.1 A Paragraph-formation Problem
The rst is a variant of Hirschberg and Larmore's optimal-paragraph-formation problem [HL87]. A slightly simpli ed version of their problem is to break a sequence of words w1 ; : : : ; wn into lines in order to form a paragraph. De ne c[i; j ] to be the cost of a line consisting of words wi through wj?1 . Let L be the optimal line width and jwi j be the length of word wi plus one for the cost of the space after word wi . Then, following the ideas of Hirschberg and Larmore, the cost function is c[i; j ] = (jwi+1 j + jwi+2 j + : : : + jwj j? 1 ? L)2 . Their objective is to construct a paragraph minimizing the sum of the paragraph's line costs. This problem is easily transformed into an instance of the sum unrestricted shortest-path problem. Consider a dag G = (V; E ), where the vertices are numbered 0 through n and (i; j ) 2 E if and only if i < j . The cost of edge (i; j ) is c[i; j ] de ned above. A 0 ; n path p = h(0; i1 ); (i1 ; i2 ); : : : ; (is ; n)i corresponds to putting words w1 through wi into the rst line, words wi +1 through wi into the second line, and so forth, with words wis through wn forming the last line. The shortest 0 ; n path in this graph corresponds to the minimum sum of the paragraph's line costs. Hirschberg and Larmore prove that the above cost function satis es the sum Monge property, and thus it can be solved in O(n) time. (Credit for the linear-time algorithm belongs to Wilber [Wil88].) If we instead seek to minimize the maximum line cost, we obtain an instance of the bottleneck unrestricted shortest-path problem. The following two lemmas prove that the edge costs in this problem possess the strict bottleneck Monge property. We call a line cost function f [i; j ] strictly bitonic if any sequence of costs f [i1 ; j1 ]; f [i2 ; j2 ]; : : : ; f [is ; js ], which satis es the following conditions for every 1 ` < s: 1. either i` = i`+1 and j` < j`+1 , 2. or j` = j`+1 and i` > i`+1 is strictly decreasing then strictly increasing. Note that either the strictly decreasing subsequence or the strictly increasing subsequence may have length zero. 1
1
2
Lemma 13 Let F = ff [i; j ]g, where f [i; j ] is a line cost function that is strictly bitonic. Then F satis es the strict bottleneck Monge property.
Proof Take any indices i < k < j < ` and consider the two sequences f [k; j ]; f [k; `]; f [i; `] and
f [k; j ]; f [i; j ]; f [i; `]. Both of these sequences must be bitonic. For the rst sequence, this implies that it is not possible that f [k; j ] < f [k; `] and f [i; `] < f [k; `], i.e. either f [k; j ] > f [k; `] or f [i; `] > f [k; `]. Similarly, either f [k; j ] > f [i; j ] or f [i; `] > f [i; j ]. Together, these two statements imply that maxff [i; j ]; f [k; `]g < maxff [i; `]; f [k; j ]g and thus F satis es the strict bottleneck Monge property.
Lemma 14 Cost function c[i; j ] = (jwi+1 j + jwi+2 j + : : : + jwj j ? 1 ? L)2 is strictly bitonic. Proof Let p[i; j ] = jwi+1j+jwi+2j+: : :+jwj j. Notice that any sequence p[i1 ; j1 ]; p[i2 ; j2 ]; : : : ; p[is ; js ], which for every 1 ` < s satis es: 1. either i` = i`+1 and j` < j`+1 , 2. or j` = j`+1 and i` > i`+1 is strictly increasing. Now consider any sequence (p[i1 ; j1 ] ? 1 ? L)2 ; (p[i2 ; j2 ] ? 1 ? L)2 ; : : : ; (p[is ; js ] ? 1 ? L)2 , which for every 1 ` < s satis es: 1. either i` = i`+1 and j` < j`+1 , 10
2. or j` = j`+1 and i` > i`+1 . This sequence is a quadratic function and thus is strictly decreasing and then strictly increasing. From these two lemmas, we conclude that any strictly bitonic line cost function f (i; j ) satis es the strict bottleneck Monge property, and thus, by Theorem 8, a variant of Hirschberg and Larmore's problem which uses f (i; j ) can also be solved in O(n) time. In particular, the variant with cost function c[i; j ] can be solved in O(n) time. We have thus far considered a simpli ed version of Hirshberg and Larmore cost function. There are three other factors about paragraph formation which they include in their cost. One is the ability to hyphenate a word at a xed cost per hyphenation. Another is the fact that in addition to penalizing quadratically lines that dier too much from the ideal line length, there may be some lower and upper limits beyond which the line length is simply not allowed. And nally, the last line in the paragraph should not be penalized for being too short. We now attempt to incorporate these factors into our cost function. The second factor is fairly easy to incorporate. Suppose that that the maximum and the minimum allowed length for a line are maxlen and minlen. Then de ne the cost function to be (
2 if minlen p[i; j ] maxlen c[i; j ] = (Mp[ii;+jj ] ? 1 ? L) otherwise
where M is a very large number (say the sum of all the word lengths). It is not hard to see that the proof that c[i; j ] is bitonic holds with this new de nition of the cost function. To take into account the last factor, we would need to de ne a new cost function 8 >
(p[i; j ] ? 1 ? L)2 if minlen p[i; j ] maxlen : M i+j otherwise Unfortunately, this new cost function c0 [i; j ] is not strictly bitonic and furthermore not even bottleneck Monge. Thus, we stick to c[i; j ] as our cost function, but we modify the algorithm. Instead of computing the 1 ; n bottleneck shortest path in Theorem 8, we compute the bottleneck cost of the 1 ; n ? 1 bottleneck shortest path. The algorithm in the proof of this theorem actually computes all d[i]'s for 1 i n ? 1, where d[i] is the bottleneck cost of the bottleneck shortest 1 ; i path. To nd the bottleneck shortest 1 ; n path, we evaluate the following, which takes O(n) time: 8 9 > > if p[i; n] L < d[i] = 2 d[n] = 1min max f d [ i ] ; ( p [ i; n ] ? 1 ? L ) g if L p [ i; n ] maxlen > in?1 > :
1
otherwise
;
Unfortunately, it is not possible to incorporate the rst factor into the bottleneck framework. If we are to assign a xed penalty function B for breaking a word in the middle and hyphenating it, the cost function is no longer bottleneck Monge. More speci cally, we assume that each wi is now a syllable. Suppose we have i < k < j < ` and j -th syllable is not the last syllable of its word, but the `-th syllable is. Then for the cost function to be bottleneck Monge, we would need to have n
o
n
max (p[i; j ] ? 1 ? L)2 + B; (p[k:`] ? 1 ? L)2 max (p[k; j ] ? 1 ? L)2 + B; (p[i:`] ? 1 ? L)2
o
It is easy to come up with a numerical example when this does not hold. We also consider one variation of the cost function. In some circumstances, a more accurate portrayal of a typical text formatting application would be that instead of having an ideal line length and penalizing for both running under and running over this ideal length, the application 11
has L as the available line width. In this case, there is a very large penalty for running over this available line width and a quadratic penalty for running under this width. The cost function in this case is ( 2 p[i; j ] L c[i; j ] = (Mp[ii;+jj ] ? 1 ? L) ifotherwise
where M is a very large number (say the sum of all the word lengths). It is not hard to see that this c[i; j ] is strictly bitonic.
References [AKM+ 87] A. Aggarwal, M. M. Klawe, S. Moran, P. Shor, and R. Wilber. Geometric applications of a matrix-searching algorithm. Algorithmica, 2(2):195{208, 1987. [AS94] P. K. Agarwal and S. Sen. Selection in monotone matrices and computing kth nearest neighbors. In Proceedings of the 4th Scandinavian Workshop on Algorithm Theory, 1994. Submitted to Journal of Algorithms. [AST93] A. Aggarwal, B. Schieber, and T. Tokuyama. Finding a minimum weight k-link path in graphs with Monge property and applications. In Proc. 9th Annu. ACM Sympos. Comput. Geom., pages 189{197, 1993. [AST94] A. Aggarwal, B. Schieber, and T. Tokuyama. Finding a minimum-weight k-link path in graphs with the concave Monge property and applications. Discrete Comput. Geom., 12:263{280, 1994. [BS91] R. E. Burkard and W. Sandholzer. Eciently solvable special cases of bottleneck travelling salesman problems. Discrete Applied Mathematics, 32(1):61{76, 1991. [Bur79] R. E. Burkard. Remarks on some scheduling problems with algebraic objective functions. Operations Research Verfahren, 32:63{77, 1979. [Bur92] R. E. Burkard. A note on greedily solvable time transportation problems. Technical Report Report 243, Institut fur Mathematik, Technische Universitat, Graz, Graz, Austria, November 1992. [BZ82] R. E. Burkard and U. Zimmermann. Combinatorial optimization in linearly ordered semimodules: A survey. In B. Korte, editor, Modern Applied Mathematics: Optimization and Operations Research, pages 391{436. North-Holland Publishing Company, Amsterdam, Holland, 1982. [FJ82] G. N. Frederickson and D. B. Johnson. The complexity of selection and ranking in X + Y and matrices with sorted columns. Journal of Computer and System Sciences, 24(4):197{208, 1982. [GT88] H. N. Gabow and R. E. Tarjan. Algorithms for two bottleneck optimization problems. Journal of Algorithms, 9(3):411{417, 1988. [HL87] D. S. Hirschberg and L. L. Larmore. The least weight subsequence problem. SIAM Journal on Computing, 16(4):628{638, 1987. [Hof61] A.J. Homan. On simple linear programming problems. In Convexity, Proc. Symposia in Pure Mathematics, volume 7, pages 317 { 327, Providence, RI, 1961. American Mathematical Society. 12
[KRW95] B. Klinz, R. Rudolf, and G.J. Woeginger. On the recognition of bottleneck monge matrices. Discrete Applied Mathematics, 63:43{74, 1995. [LS91] L. L. Larmore and B. Schieber. On-line dynamic programming with applications to the prediction of RNA secondary structure. Journal of Algorithms, 12(3):490{515, 1991. [Sei93] E. Seiart. Algebraic transportation and assignment problems with \Monge-property" and \quasi-convexity". Discrete Applied Mathematics, 1993. [Wil88] R. Wilber. The concave least-weight subsequence problem revisited. Journal of Algorithms, 9(3):418{425, 1988.
13