Information Processing North-Holland
ROUTING
Letters
34 (1990) 13-19
WITH CRITICAL
Shai SIMONSON EECS Department (M/C
22 February
1990
PATHS
* 154), University of Illinois at Chicago, Box 4348, Chicago, IL 60680, US_4
Communicated by D. Plaisted Received 12 December 1988 Revised 22 August 1989
Given an undirected graph, a set of simple paths in the graph and a bound for each path, we wish to know whether the vertices of the graph can be laid out on a line so that each path is stretched no more than its bound. The problem is solvable in polynomial time for fixed bounds and path lengths.
Keywords:
Embedding,
graph,
routing,
VLSI, layout
1. Introduction An embedding of one graph into another is a l-l association of the vertices in G, the source graph, with the vertices in H, the host graph. A great amount of research has appeared on the problems of how to embed one graph into another while minimizing various costs [l-13]. The cost depends on the particular motivating application. Such applications include VLSI layout and routing problems [3,10], communication costs in multiprocessor architectures [l], efficient representations of data structures, and the design of parallel architectures [S]. The following path routing problem has motivated a great deal of research. One has a collection of chips with connections specified between them and wishes to embed these chips on a board so as to minimize either the length of the longest connection or the average length of all the connections. When the embedding is done onto a line, there are well-known problems which formalize both these costs.
The bandwidth minimization problem (BMP) asks for a given undirected graph, whether we can lay out the vertices on a line so as to minimize the maximum of the lengths of the stretched edges. The optimal linear arrangement problem (OLA) asks to minimize the sum of the lengths of the
Bandwidth
Bandwidth * Supported
in part by NSF grant
0020-0190/90/$3.50
CCR-8710730.
0 1990, Elsevier Science Publishers
= 4
= 2
Fig. 1. Examples
OLA Cost = 17
OLA Cost = 11 of BMP and OLA costs.
B.V. (North-Holland) 13
Volume
34. Number
1
INFORMATION
PROCESSING
stretched edges. (Minimizing the sum is equivalent to minimizing the average.) BMP is NP-complete even when the source graph is a binary tree [5] while OLA is NP-complete in general [6] but has an 0(n’.6) time algorithm for trees [2]. Examples of these problems are shown in Fig. 1. A situation that often occurs with path routing is that certain paths along the connections are more critical than others. That is, we may require a particular path to be quite short while others can be much longer. This is caused by the timing requirements of the circuit. Neither BMP nor OLA is an appropriate formalization for these requirements. This information about how long each path must be, allows the path router to focus on the critical paths and build the embedding in an ad hoc fashion around them. We show that this natural information is useful for more than just ad hoc methods. In order to do this, we formalize the problem in light of the new specifications. with critical paths ( RCP) graph G = (I/, E). (2) Collection of simple paths P in G (not necessarily vertex disjoint). (3) An integer bound 6, for each path p, in P. Question: Is there a l-l function f from V to { 1, 2,. , . , 1V 1) such that dilation( p,) G b, for all p, in P (where dilation( p,) is the sum of ]f( u) f(u) 1for all edges {u, u} in p,)? Routing
Znpuz: (1) Undirected
The problem is clearly NP-complete in general, since BMP and OLA are special cases. In fact, even if we require P to contain at least two paths, and each path p, in P to have at least two edges, the problem remains NP-complete for bipartite graphs [ll]. However, we show here that the problem can be solved in O(ndp’+‘) where d (dilation) is an upper bound on the b,‘s, I (length) is a lower bound on the length of the paths in P, and n is the number of vertices in the graph. This gives a polynomial-time algorithm when the bounds on the dilation and the path lengths are fixed. The closer the smallest path length I and the largest dilation bound d, the faster we can solve the problem. In other words, the tighter the 14
22 February
LETTERS
1990
specifications are, the faster it is to check whether they can be obtained. The next section discusses this algorithm. It is based on the dynamic programming algorithm of [7] for the bandwidth minimization problem with fixed cost k. Section 3 considers some open problems.
2. Dynamic programming algorithm for fixed bounds and path lengths When the dilation bound for each path is fixed at no more than d and each path has length no less than I, then there is an O(nd-‘+I) time dynamic programming algorithm to solve RCP (n is the number of vertices in the graph). The technique we use is similar to the O(nk) result for determining whether or not a graph has bandwidth k [7]. We first review the methods used in [7] and then describe our generalization. Throughout the discussion we can assume without loss of generality that: (1) each edge is contained in at least one path (or else we could just delete it); (2) the degree of each vertex is bounded by 2k (or else we know immediately that no acceptable layout exists). The idea in the bandwidth algorithm is to avoid looking at every one of the exponential number of layouts. This is accomplished by considering partial layouts of the graph. A partial layout is a layout which includes only some of the vertices in
A
0
C
D
E
F
El Partial
Layout
Fig. 2. Partial
layout
and representation.
Volume
34. Number
1
INFORMATION
PROCESSING
the graph (leaving a set of edges dangling off the right side) see Fig. 2. One tries to determine whether or not a partial layout with bandwidth k can be extended to a full layout with bandwidth k. Towards this end, a partial layout is represented by its dangling edges and the sequence of vertices in the partial layout incident to them. Any partial layout with more than k vertices in its representation (or without bandwidth k) is automatically excluded from extending to a full layout. Such partial layouts are not considered in the algorithm. The ones we do consider are called plausible. 2. I. Central lemma The central lemma of Gurari and Sudborough [7] is that any two plausible partial layouts with the same representation are either both extendible to full layouts, or both not extendible to full layouts. Their algorithm starts with a queue of representations initialized with the representation of the empty partial layout. It works by removing the next representation from the queue and extending
LETTERS
22 February
1990
it by one vertex. This extends the representation into many new representations. Each resulting representation which is plausible and has not yet been on the queue is put on the queue. This process continues until a representation with no dangling edges appears (a full layout exists) or until the queue is empty (no full layout exists). The number of different representations is 0( n”). We can choose up to k vertices and then any subset of edges incident to them as dangling edges. By the degree-2k restriction on each vertex this gives O(nk) possibilities. Each such representation with exactly k vertices is extended in constant time. (The vertex incident to the dangling edge on the leftmost vertex of the representation must be laid out next.) The representations with less than k vertices are extended in linear time since we need to try every new vertex. There are O(n”-‘) of these representations. Since each representation is put on the queue at most once, it gets extended at most once and we have a total time complexity of 0( nk). Our idea is to use the notions of plausible partial layouts and representations, but with some important distinctions. First of all, we demand
PC
L
Not
Extendible
=
EFBAD
b,
P2
=
EFBD
b
Pg
=
EFAC
bg
P
I
Extendible
=5
1
Fig. 3. Example
of an inadequate
2
= 5 =5
representation. 1.5
Volume
34, Number
1
INFORMATION
PROCESSING
that the number of vertices in the representation of a plausible partial layout does not exceed d - I + 1. We claim that more than this would automatically make the partial layout not extendible. Consider the leftmost vertex u in the representation. We know that u must be part of some path with length at least 1. The dilation of this path under any extension is equal to the sum of the dilation of the dangling edge incident to u plus the number of edges in the rest of the path. This is (d - / + 2) + (I - 1) which is greater than d. Note: this also implies that if there are exactly d - I + 1 vertices, we can extend the layout in constant time. This is because only the successor of u in the path can extend the layout. The idea is that this change cuts the number of representations down to O(nd-‘+‘) which, in turn, implies our claimed time bound. Unfortunately, this simple idea has a gaping flaw. Although the time bound is cut down according to our claim, the algorithm is no longer correct since the central lemma of the bandwidth algorithm holds no longer. That is, it is possible to have two plausible partial layouts with the same representation where one can be extended to a full layout and one cannot. A simple example of this is shown in Fig. 3. Consider the graph in Fig. 3 with paths p, = EFBAD, pz = EFBD and p3 = EFAC; bounds 6, = 5, b, = 5 and b, = 5. Then consider the two plausible partial layouts EFBAD and FEBAD. The representation of each is the same: (A, D) with a dangling edge from A to C. However, it is clear that EFABDC is a full extension of the first while there is no possible way to fully extend the second. To fix this, we must add extra information to our representation. However, since adding more information to a representation may increase the number of them, we must make sure that: (1) the central lemma holds and (2) the number of distinct representations is still only 0( nd-‘+I). It suffices to add: (1) a list of the paths in P that contain dangling edges, (2) the “partial” dilation of each of these paths.
16
LETTERS
22 February
1990
The proof that this suffices is described in the formal presentation ahead. A partial-layout of G = (I’, E) is a I - 1 function f from a subset V’ of V to (1, 2,. . . , 1V’ I}. The unassigned vertices are those in V- V’, and the dangling-edges connect vertices in V’ to unassigned vertices. The partial-dilation of a path in a partial layout is the sum of the dilations of all the edges in the path having both ends in V’. A plausible-partial-layout is one where no path completely in I/’ has dilation greater than its bound; and where all the vertices incident to dangling edges are in the d - I + 1 rightmost locations of the layout. The representation of a plausible partial layout is the triple (L, D, PA), where L is the sequence (left to right) of all vertices in the partial layout that are incident to dangling edges; D is the set of dangling edges; and PA is the set of paths which contain edges in D and their partial dilations. A plausible partial layout f can be extended if and only if there is a full layout satisfying the path constraints which is identical to f on the first 1V’ 1vertices. The central lemma follows. Lemma 2.1. If the representations of two plausible partial lyyouts f, and f, are equal, then either both f, and f, can be extended or neither can. Proof. It suffices to show that if one can be extended, then the other can too. Assume that f, can be extended and consider the sequence of vertices in the last 1V) - 1V’ 1 locations of the extension. We claim that the same sequence of vertices will extend f,. The proof is a direct consequence of the definition of representation. The L and D parts of the representation imply that we actually get a well-defined extension for fi. That is, the unassigned vertices for f, need to be the same as those for f,. For this it is necessary to assume that the graph is connected. Otherwise there may be a whole component of vertices which is unassigned for f, but assigned for fi (or vice versa), implying that the claimed extension for fi is not well defined. Fortunately, we can assume connectivity without any loss of generality. The PA part is necessary to prove that the resulting paths have the same dilation as they do
Volume
34. Number
1
INFORMATION
PROCESSING
in the extension for f,. Otherwise it is possible that f, and f, each contain the same partial path with a different partial dilation, and that one of them could be extended while the other could not. See the example in Fig. 3 for two plausible partial layouts with identical L and D, but different PA, where one can be extended and the other cannot. The reader should note that whenever L and D are the same in two representations, then the paths in PA are also the same. It is only the different partial dilations of these paths that distinguish the two representations. q
22 February
LETTERS
1990
to the leftmost vertex in L; let (L’, D’, PA’) be the representation one gets by adding u to (L, D, PA); PROCESS( L’, D’, PA’) end else for each unassigned begin
vertex
u do
let (L’, D’, PA’) be the representation one gets by adding u to (L, D, PA); PROCESS( L’, D’, PA’) end end.
2.2. Algorithm
REJECT
I
The algorithm uses two data structures: (1) A queue Q to hold representations of plausible partial layouts. (2) A boolean array T to store whether or not each representation has been put on queue. T is used to ensure that we consider each representation at most once. The procedure PROCESS takes care of this bookkeeping, and checks if a full layout has been reached. PROCESS(
L’, D’, PA’);
begin if D’ is empty then ACCEPT
{a full layout
exists};
{Q is empty
and no full layout
exists}
The correctness of this algorithm is implied by our previous discussion and Lemma 2.1. A few brief words about implementation will help the reader understand more clearly. The paths in PA are not stored explicitly. Instead. a pointer (or index) to the path and a partial dilation are stored. This information, along with L and D, allows us to take a representation and a new vertex with which to extend it, and compute the representation of the extension. Also, the L part of the representation needs to be a sequence of vertices in order for the algorithm to choose the /eftmost. It remains to show that the time complexity is O(n u’-‘+‘).
if( L’, D’, PA’) is plausible Lemma
2.2. There are O(n”) distinct representations of pluusihle partial layouts. uvhere M is the maximum number of vertices appearing in L in an-v representation.
then begin
add it to Q; let T( L’, D’, PA’) = TRUE end end
Proof. Each representation
The main procedure ADD
the empty
representation
while Q is not empty begin
REMOVE
follows below: to Q;
do
a representation
(L,
D, PA) from
0; if L has d - I + 1 vertices then begin
let u be the unassigned
vertex adjacent
is defined by the triple (L, D, PA). There are n possibilities for each of the 1L 1 vertices giving a total of nlr.l. We now prove that the D and PA parts of the representation add no more than a constant factor to this number. Without loss of generality, as in BMP, we assume a degree-2d bound for each vertex (or else we would immediately be able to say that a full layout is impossible). Therefore 1D ) is bounded above by 2d 1L I. This implies that choosing a subset for D gives at most 22JILI new possibilities which is a constant in d and ( L I. 17
Volume
34, Number
1
INFORMATION
Furthermore, there are less than g(d) paths which contain edges in D, where g(d)
= 2d 1L 1(2d-
PROCESSING
different
l)<‘.
1 runs in 0( nd-‘+‘)
= O(nd-‘+I).
+ O(n”-‘)*0(n) 0
3. Conclusions and open problems RCP is NP-complete even for bipartite graphs but has a polynomial-time algorithm for the case where the minimum path length and maximum dilation bound are fixed. The closer these two values are, the faster the algorithm. That is, it pays to make the specifications as tight as possible. There are some open problems about RCP to consider. RCP is sandwiched between two NPcomplete problems. If each path had just one edge and the dilation bounds were all equal, we get BMP; while if we had just one path including all 18
A
1990
GJ B
D
E
time.
Proof. Since our algorithm puts each representation on the queue at most once, the time complexity is bounded by the number of representations times the amount of time it takes to process each one as it comes off the queue. When 1L) equals d - I + 1, then by Lemma 2.2 the number of these representations is 0( n d-‘+ ’ ). Furthermore, each can be processed in constant time. This is because we know exactly which vertex must be added (if that one does not work, then there is no extension). When the number of vertices is less than d - I + 1 then (again by Lemma 2.2) we have O(nd-‘) representations. Each of these is processed in linear time since every unassigned vertex must be considered as a possible extension, The total complexity is
O(n ‘-‘+‘)*O(l)
22 February
C
(Each dangling edge has at most 2d - 1 choices for each successive vertex in the path, up to d vertices.) This implies that choosing a subset of paths for PA adds at most a constant factor in d and 1L 1 to the total number of representations.
Theorem 2.3. Algorithm
LETTERS
MCLA Cost E 3 Fig. 4. Example of MCLA
cost
the edges, we get OLA. For trees, BMP is NPcomplete and OLA is solvable in polynomial time. What happens to RCP with respect to trees? What happens when we fix the number of paths at some value between 1 and I E I? What about the combination of these restrictions? Another, perhaps better motivated and more challenging, variation of RCP is to make the bounds relative rather than absolute. That is, consider the bound of a path as a (linear) function of its length. The input in this version would be the paths and the constant of the linear function. This problem is unexplored. A problem similar to RCP can be defined which is a “hybrid” between the min cut linear arrangement problem (MCLA) and OLA. In MCLA we wish to embed a graph on a line while minimizing the “cut” cost. This cost is the maximum over all intervals on the line of the number of edges passing over that interval. The problem is NP-complete in general [6] and can be solved in 0( n log n) time for trees [13]. An example is shown in Fig. 4. A problem that bridges the gap between MCLA and OLA the same way RCP does for BMP and OLA is defined below. One is given a graph which is to be laid out on a line, a set of intervals on this line and a bound for each set. The problem is to lay out the graph so that the total “cut” cost over each set of intervals is less than the bound for that set. When
Volume
34, Number
I
INFORMATION
PROCESSING
the number of sets is 1 we get OLA; and when the number is 1V) - 1 where each set contains one interval, we get MCLA. The complexity of this problem is unknown for other fixed values. Finally, all these problems can be considered for other host graphs besides lines. Natural host graphs are trees [11,12] and hypercubes [l]. These problems are all unexplored.
Acknowledgment
We thank an anonymous referee for pointing out an error in the original proof of Lemma 2.1, and for many helpful suggestions.
References
111S. Bhatt, F.R.K. Chung. T. Leighton and A.L. Rosenberg, Optimal simulations of tree machines, in: Proc. IEEE FOCS Symposium (1986) 274-282. of trees, Pl F.R.K. Chung, On optimal linear arrangement Comput. Math. Appl. 10 (I) (1984) 43-60. EmbedI31 F.R.K. Chung, T. Leighton and A.L. Rosenberg, ding graphs in books: A layout problem with applications to VLSI design, SIAM J. Algebratc Discrete Methods 8 (1987) 33-58.
LETTERS
22 February
1990
I41 J. Ellis. Embedding
graphs in lines, trees and grids, Ph.D Dissertation, EECS Dept.. Northwestern University, Evanston. IL (1984). D.S. Johnson and D.E. Knuth. [51 M.R. Carey, R.L. Graham. Complexity results for bandwidth minimization, SIAM J. Appl. Math. 34 (1978) 477-495. D.S. Johnson and L.J. Stockmeyer. Some [61 M.R. Carey. simplified NP-complete graph problems. Theoret. Conrput. Ser. I (1976) 237-267. Improved dynamic pro[71 E. Gurari and I.H. Sudborough. gramming algorithms for bandwidth minimization and the min-cut linear arrangement problem. J. Algorithms 5 (1984) 531-546. and B.T. Smith, The physical 181 L.S. Heath, A.L. Rosenberg mapping problem for parallel architectures. J. ACM 35 (1988) 603-634. Layout problems and their complexity. Ph.D 191 F. Makedon. Dissertation, EECS Dept.. Northwestern University. Evanston. IL (1982). H. Mori. E.S. Kuh, T. Kashiwabara and T. [lOI T. Ohtsuki, Fujisawa. One dimensional logic gate assignment and interval graphs, IEEE Trans. Orcuits and Systems 26 (9) (1979) 675-684. Layout problems on trees. Ph.D Disserta[111 S. Simonson. tion. EECS Dept.. Northwestern University. Evanston. IL (1986). A variation on the min cut linear arrangeu21 S. Simonson. ment problem. Math. Systems Theor?, 20 (1987) 235-252. A polynomial time algorithm for the min u31 M. Yannakakis. cut linear arrangement of trees. J. ACM 32 (4) (1985) 950-988.
19