On Channel Routing Problems with Interchangeable Terminals

The use of programmable logic cells in VLSI design allows the terminals on these cells to be interchanged since their geometrics are programmable. Recently, many exact algorithms and heuristics have been proposed for channel routing with interchangeable terminals [18, 25, 4, 11, 12, 20, 17, 3]. Various optimization problems have also been shown to be NP—hard [25, 23]. In this paper, we consider channels with exits. Let m, D be the number of terminals in the channel and the maximum number of terminals on a net, respectively. We present an O(m) algorithm that obtains optimal density for channels with exits that have one cell on each side. The existing algorithm for this problem [5] guarantees only an approximate density. Moreover, if one of the two cells has fixed terminals, we show that the density minimization problem is NP-hard. The latter problem was introduced in [5]. For instances with any number of cells we present an O(m) time algorithm for the via minimization problem, an O( m 2 ⋅ D ) algorithm for the problem of finding a maximum planar subset of nets in a channel, and an O(m) algorithm to determine whether the channel adopts external-internal layout. Also for the special case where there exists one cell per side, we present an alternative algorithm that finds a maximum planar set of nets in O(m) time.

INTRODUCTION hvannel routing is a fundamental problem in LSI design.In a channel routing problem the input consists of a collection of cells placed on ad- jacent positions and partitioned in two groups called the top and the bottom channel side, respectively.A rectilinear channel is formed between the two chan- nel sides.Each cell contains terminals (otherwise called pins).Terminals are labeled according to the net they belong.Terminals labeled with zero do not belong to any net and we call them zero terminals.We call the remaining terminals nonzero terminals.
Algorithms to route channels with fixed terminals have been proposed by several authors [19, 2, 6, 21,  27].Recently, a new model for channel routing has been proposed [12] in which we are considering that some or all of the cells on the channel sides consist of terminals whose relative positions within the cell is not fixed, i.e., the terminals can be interchanged in their cells.This is allowed if the cells have been implemented with programmable logic since their ge- ometries are programmable.Programmable logic cells (i.e., ROM's and PLA's) are widely used in VLSI design because of their structural regularity and flexibility [12].Terminals can be interchanged only if they are in the same cell.A methodology for performing the routing in this type of channels con- sists of two steps: We first interchange terminals within each cell in order to minimize some routing requirements (e.g., density, number of layers, num- ber of vias etc.) and second, route the "new" chan- nel.
The channel routing problem with interchangeable terminals in their cells has been extensively studied.
Kobyashi and Drozd [12] present heuristics for align- ing terminals, breaking cycles in the vertical con- straints graph, and merging nets.Lin and Sahni [18] present a linear time algorithm that obtains maxi- mum terminal alignment.We say that two terminals are aligned if they are on the same net, on opposite channel sides and on the same vertical column of the underlying rectilinear grid.Hou and Chen [11] and Pedram, Marek-Sadowska and Kuh [20] and Leong  and Liu [17] present heuristics that result in reduced [4, 5] handle channels with exits, i.e., there exist external nets.A left exit or left external net is a net that connects at least one terminal outside the chan- nel, the global routing phase has determined that the net will exit the channel from its left end only.We define similarly right exits (right external nets) and external nets with two exits.Let rn be the number of terminals in the channel.For simplicity, assume that the number of external nets is O(m).(This is not true, however, if the number of external nets with two exits and no terminals on the channel is large. In those cases the time complexity will depend on the number of the latter nets as well).The algorithm in [4] finds an optimal density for channels with two terminal nets in O(rn) time.However, the algorithm in [5] guarantees density within one unit from the optimal, for instances with multiterminal nets in O(rn logm) time.Leong [15] also examined the simplified instance of Cong [4], and Cong and Khoo [5] but he only considered channels without exits.
Let T and B be the number of cells at the top and bottom sides of the channel.Throughout this paper we assume that on each channel side the cells are labeled from left to right as cr crr and c cu.Let n, m, e, D be the number of terminal po- sitions on either side of the channel, the total number of the terminals which are endpoints of a net, the number of external nets, and the maximum number of terminals in a net, respectively.We assume that e O(m).We call internal any net which is not external.
In Section 2 we consider Cong and Khoo's [5] channel routing problem where there exists only one cell per side and we present optimal algorithms that minimize the density in O(m) time.There are three definitions of the density in the literature.The first density definition is given in [15, 17, 3, 25].The density d of the channel is defined to be equal to the maximum density at a column r; of the underlying rectilinear grid; The density at a column r. is equal to the number of nets crossing column r;, i.e., the number of nets with leftmost terminal to the left or on column r;, rightmost terminal to the right or on column r;, and at least one terminal outside column r;.The open density of a channel is equal to the maximum number of nets that intersect with a ver- tical line between any two columns of the underlying rectilinear grid.This density definition is very useful in the knock knee model [14].Finally, the closed density, useful in the Manhattan model [14], is equal to the maximum number of nets that have one ter- minal in a column < r; and another in a column > r;.We give O(m) algorithms that obtain optimal den- sity.We consider all three density definitions .M ore- over, we consider the variation proposed in [5] where only one of the two cells has interchangeable ter- minals, and we show that the density minimization problem is NP-hard for all three density definitions.
In Section 3, we consider the via minimization problem [14,19], the problem of finding the maxi- mum number of nets that can be routed in one layer [22], and the problem of determining whether the channel adopts internal-external layout [14,26].All three problems are studied for the general instance with an arbitrary number of cells with interchangeable terminals on both sides.We present an O(m) time algorithm for the first problem, an O(m D) time algorithm for the second and an O(m) time algorithm for the third problem.For the maximum planar subset problem we also give an alternative O(m) time algorithm for the special instance of chan- nels that have one cell per side.
Observe here that the closed density is no less than the tirst density definition and an algorithm that obtains the latter density guarantees optimal closed density as well.

DENSITY MINIMIZATION
We consider the density minimization problem.In Section 2.1 we present linear time optimal algorithms for channels with one cell per side.In Section 2.2 we show that the density minimization problem is NP-hard if we modify the instance so that the ter- minals on one side are fixed.However, we show that special cases can be solved or approximated effi- ciently.

One Cell per Channel Side
Thefirst density definition We first consider the den- sity definition in [3, 15, 17, 25] and we give a simple algorithm, we call it Algorithm 1, that obtains optimal density if there are no external nets.A similar algorithm has been presented in [15].However, we present Algorithm 1 in detail since we later modify it to handle open and closed density.We are based on the observation that for this special case the ter- minals can be interchanged so that the density is either one or two.Let k; denote the value of net N;, i.e., the difference between the number of terminals on the top side minus the number of terminals on the bottom side.(Therefore the value of a net can be a negative number.)Algorithm 1, uses as a sub- routine Internal_Nets which interchanges the ter- minals so that the density is never more than two.
Procedure Internal_Nets has as input parameters three stacks S1, $2 and $3 of nets.The stacks are generated from a procedure, which we call the preprocessing_step, as follows: procedure preprocessing_step Input: A channel with interchangeable terminals.
Output: Placement of the internal nets of the channel in three stacks $1, $2, and $3.(a) Sort, using bucketsort, all the nets according to their values.
(b) Scan the sorted list and push each net in stack $1 or $2 or $3, depending on whether its value is positive, zero or negative, respectively, so that the top of each stack has net N; with the smallest absolute value of k; (among the remaining nets in the stack).(c) return (S1, $2, $3) end of preprocessing__step procedure Internal_Nets Input" A channel with internal nets only.Output: A terminal assignment so that the density (as defined in [3, 15, 17, 25]) is no more than two.
(a) Place all the nets of stack $2 at the leftmost available terminal positions so that they are aligned; (b) S Sl (c) while both S1 and $3 are not empty do begin IfS S1 then pop a net N; from S and place it on the leftmost positions as illustrated (Observe that, at each iteration of the if- then-else statement above, only one of the terminal assignment rules of Figure 1 applies.Moreover, the patterns illustrated in Figures l(c) and l(e) never apply if our channel in- stance does not have external nets.As we de- scribe in Algorithm 2 later, procedure Internal _Nets is also used when the channel instance has external nets as well.In this case, the ter- minals in stack $2 must be assigned as Figures l(c) and l(e) illustrate.The terminals in stack $2 are the shaded terminals and have been assigned so that they are aligned.) if the number of placed terminals on the bottom channel side is less than the number of placed terminals on the bottom side then S := $3 else S S1. end (d) Let S be the nonempty stack.
Place the terminals of each net N. S at con- secutive channel positions so that no two nets N/, N S intersect each other. (Such placement is always feasible.)end of Internal_Nets Clearly, the channel density is no more than two.
At Step (a), we insist that the nets in $2 are aligned.This is important for Algorithm 2 (described later) that handles external nets.Let rn be the number of the terminals in the channel.The sorting of the nets in the preprocessing step is done with bucketsorting.The buckets correspond to the values of the nets.Bucketsorting takes O(m) time since for every net Ni we have that k; [-(m 1)/2,(m 1)/2].Steps (a)-(d) of Internal_Nets require O(m) time.There- fore the overall time complexity is O(m).

Algorithm 1
Input: A channel with one cell per side and internal nets only.
Output: A placement of the terminals so that optimal density (as defined in [3, 15, 17, 25]) is obtained.(a) Place all the nets N; with k 0 at the leftmost channel positions so that they are aligned; (Now the density is two).
For channels that do not have external nets the align- ment during Step (a) is trivially obtained by simply placing all nets with k; 0 on the leftmost channel positions.The explicit alignment at Step(a) is im- portant for Algorithm 2, given below, which handles external nets and uses Algorithm 1 as a subroutine.
Algorithm 2 is an improvement of the O(m logm) time, near optimal algorithm in [5].W.l.o.g.we as- sume that the channel instance does not contain ex- ternal nets with two exits since the terminals of each such net, if any, can be placed anywhere without affecting the channel density.(We consider them as zero terminals.)Let d; be the channel density when we only consider the external nets with left exits, d,.be the channel density when we only consider the external nets with right exits.Clearly max{d, d,.} is a lower bound for the channel density.Since we have exits, the above quantity cannot be zero.Assume w.l.o.g, that d > dr.
Algorithm 2 first uses procedure preprocessing_step to generate stacks S1, $2 and $3.Then it calls procedure concatenate(Sa, Sb, Sc, Sd) which has an in- put parameters stacks Sa, Sb, and Sc and as an output parameter stack Sd.The input parameters of con- catenate can be any of the stacks s;, {1,2,3}.Pro- cedure concatenate generates a new stack Sd which contains, from top to bottom, the items of stack Sa (in the same relative order) then the items of stack Sb (in the same relative order), and finally the items of stack Sc (in the same order).We found it more convenient to denote the operation of procedure con- catenate(Sa, Sb, Sc, Sd) as Sd := SalSblSc.Before we proceed to the description of Algorithm 2, we illustrate how we obtain optimal density in the special case where there is only one left exit N; with value k:, i.e., d: 1 and dr 0. Assume w.l.o.g. that ki > 0. We use {} to denote an empty stack.In this special case, we work as follows: Place the terminals of N; at the leftmost positions in the channel; if El k zero terminals on the bottom side then begin Place the k; zero terminals at the columns where net N has an assigned terminal; call Algorithm 1; exit; end else begin (S1, $2, $3) preprocessing_step," call S1 := Ni]S1 ]{}; call Internal_Nets; exit end Observe that if there exist k; zero terminals on the bottom channel side, the density can be either one or two.In order to guarantee density one the zero terminals must be placed as indicated and then we have to call Algorithm 1. Otherwise the density is two.Notice that in order to obtain density at most two we must place the left exit N; at the leftmost positions.We assumed that the left exit has more terminals on the top side.Therefore net N is placed at the top of stack S1 and is treated as an internal net.Now Internal_Nets guarantees that the density is two.
In a way similar to the algorithm above, one can derive algorithms to handle the following two special cases: (a) d: 0, dr 1 and (b) d: d,. 1.
Therefore we assume that Algorithm 2 below con- siders only cases where d: and dr are at least two.We use {} to denote an empty stack.Let a be an integer.
We use lal to denote its absolute value.

Algorithm 2
Input: A channel with one cell per side and external nets.
Output: A placement of the terminals so that optimal density (as defined in [3, 15, 17, 25]) is" obtained.
(a) Assume w.l.o.g, that the left and the right exits have more terminals on the top channel side; Consider first the left exits.Sort (using bucket- sort) the left exits according to the number of terminals they have on the top side; Push them sorted in stack Sl so that the top of Sl has net N/with the smallest number of nets on the top channel side; Similarly, create a stack Sr for the external nets with right exits; (b) repeat Pop a pair of terminals on net(s) in Sl to be assigned on the leftmost available column un- ( tii there are no terminals on left exits to be as- signed to the bottom channel side; Repeat Step (b) above in a symmetric way for the external nets with right exits.Now some nets in stacks Sl and Sr have been assigned terminals.
Steps (d)-(f) below treat the nets (or parts of nets that consist of the unassigned terminals on the nets) in stacks Sl and Sr as internal nets.
(dl) if d: > dr and there exists at least one left exit where all its terminals have been assigned then begin (S1, $2, $3) preprocessing_step; S1 SIlSIlSr; call Internal_Nets; exit end (d2) if d: > dr and there is no left exit that has all terminals assigned then begin (d2.1)Consider the left exit N; that was placed last and let K: denote the number of columns with one assigned terminal.
Case 3." d: dr (fl) If there exists at least one right exit that has all terminals assigned then work as in Step (d); (t2) If there exists at least one left exit that has all terminals assigned then work as in Step (e); else begin (t"2.1)Consider the left exit N; that was placed last and let K; denote the number of columns with one assigned terminal.Similarly, consider the right exit N that was placed last and let K,. denote the number of columns with one assigned terminal.
Proof: The time complexity of the algorithm is O(m) since the sorting of nets at Step (a) and pro- cedure Internal_Nets require O(m) time.Below we discuss the optimality of Algorithm 2. It is clear that the terminals on left and right exits must be placed at the leftmost and rightmost channel columns, re- spectively.We show here the optimality of the case described at Step (d) and similar arguments can apply for Steps (e) and (f).
If the condition at Step (dl) is satisfied, our al- gorithm guarantees that the assignment of the re- maining terminals gives overall density d which is a lower bound to the channel density.This is guaranteed by the simple modification of Internal_Nets described at Step (dl).This step allows procedure Internal_Nets to manipulate some left exits as inter- nal nets.These left exits have terminals on the top side only.Furthermore, they are assigned left of any internal net in the channel.Opposite to each such left exit there will be at most one internal net.However, the condition at Step (dl) guarantees that, be- fore procedure Internal_Nets operates, there is at least one left exit whose all terminals have already been assigned.Therefore the density is at most d.
Assume now that the condition of Step (d2) is satisfied.Here Step (d2.3) guarantees that the den- sity is at most d+ 1.In fact, in order to guarantee density d we must have K zero terminals on the bottom channel side so that can enforce that all the terminals of one left exit have already been assigned when Step (d2.3) starts.Thus, it is significant to as- sign the left exits so that we minimize K. Step (a)   sorts the external nets so that we obtain minimum value of K.This is shown below.
If there is no left exit with a terminal on the bottom side then the value of each left exit equals to the number of its terminals that must be assigned on the bottom side and our sorting manifestly guarantees minimization of K. Assume now that there is at least one left exit that connects a terminal on the bottom side.Let B be the sum of the terminals on left exits that have to be assigned on the bottom channel side.
Clearly, if there is a left external net N; that has B + K terminals on the top channel side, then it suf- fices to have K zero terminals on the bottom side to guarantee density d.Since we sort the external nets according to the number of terminals they have on the top channel side, the external net at the top of the stack guarantees minimization of K.In Figure 3 we illustrate that the sorting at Step (a) minimizes K.The terminal assignment in Figure 3 Closed and open density minimization Al- gorithms 1 and 2 serve for minimizing the closed density as well.(In fact, the closed density is never less than the density definition that we examined previously.)However, we need to modify Algo- rithms 1 and 2 in order to minimize the open density.
The modified algorithms are called Algorithm la and Algorithm 2a, respectively.Procedure Internal_Nets and its preprocessing_step are as in Algorithm 1.

Algorithm la
Input: A channel with one cell per side and internal nets only.
Output: A placement of the terminals so that optimal open density is obtained.
(a) Place all the nets with k; 0 at the leftmost channel positions so that they are aligned; (b) Transform each net N; of value k; > 2 to the pattern of Figure 4(a) by adding zero terminals on the bottom side; (These terminals will be part of N;.) if 71 enough zero terminals then go to Step (e)" (c) Transform each net N; of value k; < -2 to the pattern of Figure 4(b) by adding zero terminals on the top side.(These terminals will be part of Ni.) if 71 enough zero terminals lhen go to Step (e).{tl} (In this step we attempt to obtain density one.) Let tl, bl, t2, b2 be the set of nets N; with k; 1, -1, 2,.-2, respectively.
Let Itll, Ib-I, }t2], Ib2] be the number of nets in each set.
(all) If b21 > {t21 + 1 lhen combine the nets b2 U t2 tO form patterns as in Figure 4(c); We call each such pattern an island.Island 1 is formed by combining It21 + 1 nets in be with the nets in t2.Each of the remaining islands is a net N; b2 which is not in island 1 Add zero terminals or nets N; with k 1 before and after each island as Figure 4(d) il- lustrates; (We always have enough nets or zero terminals to do these island transformations.) Place the transformed islands one after the other at the leftmost available positions; Place all the remaining nets N with k {1, -1} so that the density remains 1; (Figure 4(e) illus- trates such a placement for the case when we (0 (g) FIGURE 4 Transformations on Algorithm la.(a) A net with positive value and its transformation.Added zero terminals are represented by empty cycles.(b) A net with negative value and its transformation.Added zero terminals are represented by empty cycles.(c) Three islands: An instance where Ib21 It21 + 3. (d) Island 2 of part (c) above is combined with one zero terminal and a net with value 1. (e) Illustrating the transformation.(f)[t;I Ib;I + 1. (g) Two zero terminals are added on the island of part (f).are left with two nets N with k 1, one net Ni with k.
1 and a zero terminal on the bottom side.)(d2) if ]b2] < It2] + 1 then work in a way similar to Step (dl); {-1, 0, 1}, then form only one island as in Figure 4(f) (or its mirror image); Transform the island as Figure 4(g) illustrates by adding either zero terminals or nets Ni of value ki {1, -1}; Place the transformed island at the leftmost available channel positions; Algorithm 1 obtains optimal density Proof: The optimality of the algorithm is justified by proving that Steps (a)-(d) correctly determine whether the channel density is one or two.Clearly, Step (a) does not affect the optimal solution, since any optimal solution can be easily transformed to an instance that satisfies the placement described at Step (a) without an increase in the density.
Observe that in order for the density to remain one, any net N; with value -2 > ki > 2 needs to have additional zero terminals on the opposite chan- nel side, as described in Steps (b) and (c).If these zero terminals do not exist, the density is two.We then generate the patterns illustrated in Figures 4(a) and 4(b) since these patterns allow us to place net N.withk. 2next to net N; with k; -2sothat we maintain density one without placing any zero terminal between the two nets.In Figures 5(a)-5(d), we illustrate that if we do not follow the patterns described in Steps (b)-(c), the density will always be optimal.
We claim now that the density is one after all nets Ni with -2 >-ki >-2 have been successfully trans- formed to one of the patterns of Figures 4(a) and 4(b).In Step (d) we describe a placement that obtains optimal density.First we combine the nets N with k {2, -2} so that they share columns as much as possible.(For example, Figure 5(d) shows that we need two additional zero terminals if the described condition is not satisfied.)If we succeed to a place- ment that aligns the terminals of all nets N; with ki FIGURE 5 Examples where we do not obtain optimal density if we do not follow Algorithm la.(a) The density is 2. We did not follow Step (d) of Algorithm la. (b) The density is 1. (c) Density 1.This is mirror image of part (b). (d) We did not follow Steps (b) and (c) of Algorithm la.We now need two extra zero terminals to obtain density 1.
{1, --1} as Figure 4 shows, the latter nets are identical to zero terminals and the density will be one.But after Steps (b) and (c) such a placement is always feasible.
For the time complexity analysis observe that Step (a) takes O(m).In O(m) time we are also able to determine the number of zero terminals on each channel side.This ensures that Steps (b) and (c) Algorithm 2a is now the same as Algorithm 2 but now in the special case where max {d, d} < 1 we substitute ki by ki-1.Similarly, at Steps (d)-(f) of Algorithm 2, we must substitute K and Kr by K 1 and K,. 1, respectively.The proof of correctness is similar to the one in Algorithm 2 and is omitted.

Fixed Terminals on One Side
We now examine a variation of the channel density minimization problem considered by Cong and Khoo [5].The channel consists of two cells, one cell per channel side, the terminals on one cell (w.l.o.g. the bottom cell) are fixed, and the terminals on the other cell are interchangeable.We initially show that the problem of obtaining minimum channel density by interchanging the terminals in the top channel cell is NP-hard.This is shown for all three density defini- tions, i.e., the density definition by Cai and Wong [3] and the open and closed density definitions [14].
We prove the latter by reducing the bin packing prob- lem, defined below, to the decision version of our problem in which we are examining whether there exists a terminal permutation such that the channel density is less than or equal to an input integer K.We call this problem the ith density decision (i-DD) problem, {1, 2, 3}.The values of depend on the definition of the density.Namely, 1 if the density is defined as in [5], 2 if we have open density and,/ 3 if we have closed density.Then we show that special instances of this density minimization problem can be solved or approxi- mated efficiently in polynomial time.The algorithms presented here can be trivially extended to handle the more general case where the top channel side has more than one cell.NP-complete proofs Our NP-complete reduc- tions are done from the bin packing problem, which is NP-complete in the strong sense [8], and is defined below.
Bin packing instance: A finite set U of items, a size s(u) Z + for each u U, a positive integer bin capacity B and a positive integer M.
Question: Is there a partition of U into disjoint sets U1, U2, UM such that sum of the sizes of the items in each Ui, 1 < < M, is B or less?Theorem 2.3 The 1 DD problem is NP-complete.Proof: Clearly, 1  DD is in NP.Consider an instance of the bin packing problem as described above.Let UI, Uil and N1 denote the size (number of items) of the set U, the size of each set Ui 1 < < M, and the number of items u U with s(u) 1, respectively.We construct the channel instance for the 1

DD problem as follows:
The length, n, of the constructed channel is equal to M B + 2 (M 1).The top side of the channel has N zero terminals, one for each item u U with s(u) 1.We call each such terminal an item zero terminal.We have [U -N nets, each having ter- minals in cell C. Each one of these nets corresponds to an item u U with size s(u) > 2. We call such a net an item net.For each item u with s(u) > 2 there exists an item net connecting s(u) terminals.The remaining terminals on the top side are zero termi- nals.See also Figure 6.
The bottom channel side consists of M 1 two terminal nets labeled ;)i t;),M_ Net ';)i has terminals at positions 2 (B + 2) 1 and 2 (B + 2).The remaining terminals on the bottom side are zero terminals.We call these zero terminals hole zero terminals since they do not contribute to the channel density.Any B consecutive hole zero terminals form a hole ci, 1 < < M, which corresponds to set U; of the bin packing instance.Clearly, from the descrip- tion of the top channel side we conclude that the nets in the channel connect terminals either on the top or the bottom side but not on both sides.See also Figure 6.
M-1 such two terminal nets N B zero B zero B zero terminals terminals terminals FIGURE 6 The bottom side of the constructed channel with the placed terminals.

B zero terminals
The number K in the 1 DD instance is equal to 1.The above construction can be done in polynomial time since the bin packing problem is NP- complete in the strong sense and we have selected the sizes of the sets to be polynomial.We will show that the bin packing instance is satisfied if and only if the constructed DD instance is satisfied.
From the channel instance construction, a lower bound to the density is equal to 1.This is encountered by considering the fixed nets on the bottom side only.If the bin packing problem is solvable, then we show that we can always place the item nets opposite to the holes so that no terminal in an item net is placed on a column that has a terminal on a two terminal net on the bottom side.(If a terminal of an item net is placed in such a terminal position, the density be- comes 2 and the I--DD instance is not satisfied.)The placement of the item nets and the item zero terminals is directed by the placement of the re- spective items u in the bin packing solution.Let the terminal positions of hole cj, 1 < j < m, be B B+.If the bin packing instance has r items u[, < 1 < r, in set U;, the respective item nets and the item zero terminals are placed at positions TI, up to (at most) position T+r, and in the order they are placed on set Ui. (This is always feasible).The above guar- antees density 1.  Conversely, assume that the density of the channel instance is 1 for some terminal assignment.Let F be the set of columns that have an item net on a column with a terminal on a two terminal net on the bottom channel side.On each .F there exists either an item zero terminal or some other zero terminal.Now interchange the terminals so that on each ri F we have zero terminals which are not item zero termi- nals.Such an interchange is always feasible because we have at least 2 (M 1) such zero terminals.Now interchange the terminals so that each item net occupies consecutive positions and such that the den- sity is still B. It is not difficult to observe that the terminal positions of the item nets and the item zero terminals leads us to an assignment of the corre- sponding items to set U. (The description of this assignment is similar to the inverse part of the proof and is omitted.)Thus the bin packing problem is satisfiable.
Theorem 2.4 The 2--DD problem is NP-complete.Proof: The reduction will be again done from the bin packing problem.The length of the channel is now 2. (B 1) + (M-2).(M-2) + 2.(M 1).The top side of the constructed channel is as in Theorem 2.3.The bottom side of the channel is as in Figure 7. Now, all holes have size B 2 besides the leftmost and rightmost holes that have size B 1. The reason for the latter modification is due to the definition of the open density.Let the terminal positions of hole c be in the range [BI,, Bi,].Then according to the definition of open density we can place nets in the range [TI,-1, T,+] without increas- ing the density lower bound due to the bottom chan- nel side.Note that positions TI,_ and B,M+I are not defined, however.Therefore these two holes have one more terminal position, i.e., B 1 positions.The number K in the 2 DD instance is 1.
If the bin packing problem is satisfiable then the channel density is 1.(The argument is the same as in Theorem 2.3 since we now consider the definition of open density.)Inversely, the sizes of the holes allow us to claim that if the density of the 2 DD instance is 1 then the bin packing problem is satisfiable.
Theorem 2.5 The 3 DD problem is NP-complete.Proof: The reduction is identical to the one in Theorem 2.3.From the construction of the channel we have that all nets connect terminals on the same side.Observe that for such a channel instance the definition of open density is identical to the density definition in [3].version can be solved optimally or approximated in polynomial time.The algorithms are described for the density definition in [3] but they can be extended to the other two definitions.They can also be ex- tended to handle channels with more than one cell on the top channel side.
Theorem 2,6 If the channel instance consists of two terminal nets then an optimal density can be found in O(m) time.
Proof; We describe a simple algorithm that consists of two steps and satisfies the lemma.In the first step, we align all nets with terminals on both sides.Let ': be the set of nets with both endpoints on the top side.We use lb to denote the density lower bound formed when considering nets with both endpoints on the bottom channel side.In the second step of the algorithm, we determine whether all the remain- ing two terminal nets with movable terminals can be assigned so that the density lower bound lb is main- tained.
Let m be the number of terminals on the channel instance.The alignment step requires O(m) time.
(See also [18].)We can show that an optimal solution can be transformed to an instance where all nets are aligned without increasing the channel density.(This is independent of the density definition.)The second step of the algorithm is simple.Let P be the set of columns where maximum density is encountered when we consider the nets with both terminals on the bottom side only.P partitions the terminal po- sitions on the top side and not in P into s sets S;.
(Assume w.l.o.g, that the labels are assigned from the to right.)Let ]S;] denote the number of terminal positions S;, 1 < < s.If the movable terminals on each net can be placed on the terminal positions of some set S;, 1 < < s, then the optimal channel density is equal to the density lower bound; other- wise the optimal channel density is equal to the den- sity lower bound plus one.We give a simple algo- rithm that determines whether the density, d is lb or Ib+l.
Let N be the set of nets with some terminals on the bottom side and some terminals on the top side.
For each net N/ N, let r(N/) denote the rightmost terminal position on the bottom side, l(N/) be the leftmost terminal position on the bottom side and T(Ni) be the number of terminals on the top side.
Let n be the channel length.Theorem 2.7 Iffor every pair of nets (Ni, N) such that Ni and N N, we have that r(Ni) < r(Ni), l(Ni) <(N/) and T(Ni) T(Ni) T, then we can obtain channel density which does not exceed the optimal by more one than unit in polynomial time.
Proof: Clearly, the relative order of the movable terminals of each net N/ Ne, if any, does not affect the density.From now on, we consider the channel problem where we have disregarded all nets that have all their terminals on the top side.The density of the induced channel is no less than one unit from the density of our original channel routing problem since we can always place the terminals of the re- moved nets so that no two such nets intersect with each other.
We now claim that there exists an optimal solution where for any two nets Ni, N N for which r(Ni) < r(Ni), and thus I(N) < I(Ni), all the movable ter- minals of net N; are assigned to the left of the mov- able terminals on net N/.This is sufficient for our approximation algorithm since we have now fixed the relative order of all the movable terminals on nets in N and we can use the algorithm in [3] to solve the latter problem in O(n2) time or the algo- rithm in [10] in O(n log n) time.
We show the claim as follows: Assume that there exists an optimal assignment of the terminals that do not follow the ordering of our claim.We show a series of terminal interchanges which does not increase the density and results to an assignment as in our claim.
Label the nets in N so that if r(N) < r(Ni) then < j.Now the nets in N are labeled NI to N,.. Assume also, for easier description, that the nets satisfy that r(Ni) < I(N+).Thebottom channel side looks as in Figure 8(a).For the remaining of this proof when- ever we refer to a net N; we imply that n; is in N.
Consider first nets N,. and N,._ in the optimal so- lution.If there is one movable terminal of N,. left to a movable terminal of N,._ then interchange their positions.At the end of this step all movable ter- minals of Nr are to the right of the movable terminals of Nr_ .This interchange does not increase the den- sity at columns right of r(Nr_).Observe that both nets Nr and Nr-I have T movable terminals.There- fore, the interchange does not also increase the den- sity left of r(N,._).
The latter is not true if the nets do not have the same number of movable terminals.For example, in  Figure 8(b) net N3 has 5 movable terminals and net N2 has two movable terminals.The figure shows the optimal terminal assignment which clearly does not follow the ordering in the claim.If we interchange the movable terminals of nets N3 and N2 as described above, we will still have one movable terminal of net N3 right at the column r at position r(N1).This in- terchange will then increase the density at column r and therefore the overall channel density.Now we finished interchanging terminals on nets N,. and Nr_l.This terminal interchange is then re- peated for nets Nr and Nr-2, then nets Nr and N,._3 and so on until we cannot interchange the position of a movable terminal from net N. Then we repeat the above terminal interchange procedure by just decrementing the subscripts of the nets involved previously, i.e., we first consider nets Nr_ and N,._2.This concludes the proof of the lemma.]

OTHER OBJECTIVE FUNCTIONS
In this section we give polynomial time algorithms that find optimal solutions for the via minimization problem, the problem of finding the maximum num- ber of nets that can be routed on a single layer, and to determine whether the channel adopts internal- external layout.The input instance in all three problems is a channel with an arbitrary number of cells on each side.

Via Minimization
We present an algorithm, we call it via_minimiza- tion, that minimizes the number of via holes needed for the routing of a channel.Any optimal solution for this problem requires that each net consists of at most one trunk section [14,19].If this was not the case and there exists an optimal solution with net N having more than trunk, we can reduce the number of trunks of Ni to be one and thus reduce the number of vias; a contradiction to the assumption that we had an optimal solution.We also assume that we do not have any external nets with two exits and no terminals in the channel since none of these nets requires any vias.
Observe also that an alignment of any two ter- minals of a multiterminal (internal or external) net or an external two terminal net reduces the number of vias by one, but an alignment of the two terminals of a two terminal net reduces the number of vias by two.Thus the problem of minimizing the number of vias is equal to the problem of maximizing the quan- tity 2 Ai2 -+-Ar, where Ai2 is the number of aligned two terminal internal nets and A,. is the number of aligned terminal pairs on any other net.This is a weighted version of the maximum alignment problem that Lin and Sahni examined in [18] for internal nets only.Now the alignment of the two terminals of an internal two terminal net equals to the align- ment of two pair of terminals on any other net(s).
Lin and Sahni's algorithm [181, we call it Lin_ Sahni(C), does not obtain optimal solution to our problem even for a channel C with internal nets only.
We give a counterexample of the latter in Figure 9.
In Figure 9(b) we construct the bipartite graph for the channel in Figure 9(a) as Lin and Sahni suggested [18].In this graph there exists an edge between any pair of terminals that are in an overlap region [18] and on the same net.(The reader is referred to [18] for formal definitions and description of the algo- rithm.)Then based on the graph of Figure 9(b), the resulting terminal interchange is shown in Figure 9(c).This is a suboptimal solution to our problem since the total number of vias for this interchange is seven but the minimum number of vias is six.
We show now that Lin and Sahni's algorithm [18] can serve as a subroutine for a simple algorithm that does not obtain via minimization.First, we give a straightforward modification of algorithm Lin_ proof of optimality for the later algorithm.)We also assume that each external net has at least one ter- minal on some side of the channel; otherwise it re- quires no via and it is omitted.Then we present algorithm via_minimization (Algorithm 3) thatuses generalized_Lin_Sahni(C) as a subroutine.
procedure generalized_Lin_Sahni( C) Input: A channel C with internal and external nets.
Output: An interchange of the terminals that obtains maximum alignment.

Algorithm 3 obtains via minimization
Proof: The optimality of the algorithm is based on the fact that the maximum alignment at Step (c) does not affect the maximum alignment of the remaining terminals since a contracted column with an aligned two terminal net can not be used for aligning more than one net.Moreover, the contracted column has a net with maximum weight.The time complexity is determined by Steps (a) and (c).Step (a) can be easily implemented in O(m2), where m2 is the num- ber of two terminal internal nets with endpoints on different sides.A greedy left to right alignment of the two terminal nets is optimal in this case.Al- though the complexity of the algorithm in [18] was mentioned to be O(n), it is indeed only O(m).Thus the overall time complexity of Algorithm 3 is O(m). 3.2 Maximum Planar Subset of Nets Our algorithm (Algorithm 4) for the maximum planar subset of nets consists of three phases.The first phase (phase_I) transforms the input channel instance to one consisting of internal nets only as follows.The channel has two more cells cz and Cr at the leftmost and rightmost positions on the (w.l.o.g.) top side.Each external net with a left exit has an additional terminal on cell c and each external net with a right exit has an additional terminal on c,..For simplicity, assume that the number of terminals in the new channel is m.The second phase of the al- gorithm interchanges the terminals on their cells so that we avoid the intersection between any two nets Ni and N if this is possible.This is procedure phase_2.Finally, the last part of the algorithm selects the maximum planar subset of nets.
We first describe procedure phase_2.The proce- dure ignores all nets that connect terminals in the same cell since we can avoid the intersection of such a net with any other net.Also assumes that each net has at most one terminal per cell.If this is not the case, the terminals of each net in a cell will be as- signed consecutive positions.Finally, for the sim- plicity of the description, assume that there are no two nets, each connecting exactly two terminals one in cell ci and the other in cell c.Phase_2 consists of two steps and is given below.Step (a) consists of a series of transformations in the channel.We first transform the channel to a switchbox C as shown in Figure 10.(Here, each ver- tical side is a cell that has zero terminals only.)We relabel the cells in the channel from c to Ct, by ar- bitrarily selecting a cell and moving in a clockwise manner.Similarly relabel in a clockwise manner the terminal positions in the channel.We now define, for each net, the first, last and middle terminals, sub- ject to the clockwise ordering that we imposed.We also define for each cell the low and the high bound- ary, subject to our ordering.See also Figure 10.
Step (b) assigns the terminals of the nets in their cells as follows.We scan the cells in clockwise man- ner starting from cell c.For each cell c;, we assign terminal t of net N as follows: If it is the first ter- minal it is assigned next to the high boundary, if it is the last terminal it is assigned next to the low boundary and if it is a middle terminal it is assigned anywhere in cell c.
Furthermore, we determine the relative order of any two first terminals t and i, on nets N and N i, respectively, as follows: If the last terminal of net N is on a cell that has higher label than the one where the last terminal of N resides, terminal t. will be assigned closer to the high boundary of cell c than terminal t.If the last terminals of nets N, and N are on the same cell and one of the two nets is a two terminal net, w.l.o.g,net N, terminal t. is assigned closer to the high boundary of cell c.
We also determine the relative order of two last terminals tk and i, on nets Nk and N i, respectively, in a similar way" If the first terminal of net N is on a cell that has higher label than the one where the last terminal of N resides, terminal will be assigned closer to the low boundary of cell c; than terminal t.
If the first terminals of nets N and N are on the same cell and one of the two nets is a two terminal net, w.l.o.g,net N, terminal ti is assigned closer to the low boundary of cell ci.This concludes the de- scription of procedure phase_2.
Step (b) can be implemented in O(m) time using bucketsorting as in [25].We skip here these imple- mentation details.In Figure 11 we show how Step (b) succeeds in placing the terminals in their cells so that we avoid the intersection between any two nets.(In the figure we assume that phase_2 has assigned the terminals.)Observe that in cell c; net N2 does not intersect with net N. We avoided such an inter- section by assigning the terminal on net N2 in cell c; to the right of the terminal on net N and the terminal on net N2 in cell c;_ to the left of the terminal on net N. Observe that both nets N and N_ have their last terminal on cell c;, and they have a terminal in cell c;_.The relative order of the terminals in cell c_ is determined by the fact that terminal on net N2 in that cell is not the last one.
Similar arguments hold when we consider any two nets in Figure 11.For example, the assignment guar- antees that net N. will not intersect with all the other FIGURE 11 The second phase of Algorithm 4.  of the nets in O(m) time.We can again assume w.l.o.g, that every net (either internal or external) has at most one terminal on each cell, i.e., at most one terminal on each side.Therefore an internal net can now be represented either as a two terminal (TT) net with endpoints in different sides or by a single terminal (ST).We also partition the left exits into three sets: left-exit top-side (LETS) external nets that have a terminal on the top side only, left-exit bottom- side (LEBS) external nets that have a terminal on the bottom side only, and left-exit top and bottom side (LETBS) external nets that have terminals on both sides.We similarly partition the right exits in right-exit top-side (RETS) external nets, right-exit bottom-side (REBS) external nets, and right-exit top and bottom side (RETBS) external nets that have terminals on both sides.Finally, we partition the external nets with two exits in: two-exit no-side (TENS) external nets that they connect no terminal in the channel, two-exit top-side (TETS) external nets that have a terminal on the top side, two-exit bottomside (TEBS) external nets with a terminal on the bottom side, and two-exit top-bottom side (TETBS) with a terminal on both sides.
Observe that all the basic nets can be routed on one layer independently of whether there exist additional nets that are not basic.Also observe that the set of nets {TENS, TEBS, TETS}, {TT, RETBS, LETBS}, {TETBS} are mutually exclusive in the sense that if a net from one set has been selected to be routed in the layer no net from the other two sets can be routed on the same layer.Furthermore, at most one net in TETS or TEBS or TETBS or LETBS or RETBS can exist in any valid routing: Finally observe that all the nets in TT or all the nets in TENS can be routed on the same layer.The above observations lead to the following algorithm.

Algorithm 4a
Input A channel with one cell per side.
Output A maximum planar subset P of the nets which is derived in O(m) time.

Internal-External Layout
In this Section, we modify Algorithm 4 of the pre- vious section to determine whether the channel ad- mits internal-external layout.In this decision prob- lem, we want to determine whether the set of nets : can be partitioned in two sets :,,.and ':,, so that all nets in ;'t.,,, :t [(,;.q,can be routed on the same layer.The new algorithm, we call it Algorithm 5, is given below: Algorithm 5 Input: A channel instance with interchangeable ter- minals on their cells.
Output: Determining whether the channel admits internal-external layout.
(a) Use phase_l of Algorithm 4 to transform all external nets to internal.Then use phase_2 of Algorithm 4 to assign the terminals so that we avoid an intersection between any two nets in the channel instance.Now the cells are labeled from c to c, and the input channel has been transformed to a switchbox as in Figure 10.
(b) %, := :: :;, := {}; c,.:= c; (c) while the switchbox has not been scanned do begin Scan the switchbox in a clockwise manner starting from cell c., until you find the first net N. ':,,.and in cell c that intersects with some other net in :).' :--?)tt Ni; :).,, :),,, 1.3 Ni; cs ci; end (d) call phase_2 of Algorithm 4 to assign the ter- minals in the induced switchbox instance con- sisting of the nets in (e) if ::t nets in ':,,,, that intersect with each other then the channel does not adopt internal-external lay- out else it does adopt.end of Algorithm 5 Theorem 3.4 Algorithm 5 determines whether the input channel adopts internal-external layout in O(m) time.
Proof: Algorithm 5 first interchanges the terminals so that we avoid the intersection of any two nets in ;%,,.The set of nets 0z,, forms the internal layout and therefore must be planar.Algorithm 5 removes greedily (Step (c)) each net in ':3., that violates the planarity of set ':L, and places this net in set ':z,,, which forms the external layout and must also be planar.
In this paper, we considered channels with inter- changeable terminals and we considered various op- timization problems.In the density minimization problem, we focused on the special case where there is only one cell per channel side.For that special instance, an approximation algorithm has been re- cently presented [5].Our algorithm is optimal and asymptotically faster than the algorithm in [5].The authors in [5] also proposed a variation of the above channel routing problem where one of the two cells has fixed terminals.In this paper, we showed that the latter problem is NP-complete.Many of the pre- sented algorithms can be modified to minimize sim- ilarly defined objective functions for switchbox rout- ing.Then we considered three more objective functions.We gave linear time algorithms for the via minimization problem and the problem of determin- ing whether the input instance adopts external-in- ternal layout.Finally, we presented a polynomial time algorithm for the problem of finding a maximum planar subset of nets.
In the literature, many algorithms and heuristics have been proposed for a similar but different chan- nel routing problem with movable terminals.Now the terminals are movable but their relative order remains unchanged in their cells.The algorithms and heuristics for this problem do not apply in our chan- nel routing problem with interchangeable terminals.Below we briefly review work for this problem.Wid- mayer and C.K. Wong [28], Gopal, Coppersmith and C.K. Wong [9], Deogun and Bhattacharya [7], and Schlag, Woo and C.K. Wong [24] present algorithms for various combinatorial optimization problems for the latter channel routing problem.In [7,16] optimal algorithms are given for switchbox routing with mov- able terminals.Cai and D.F. Wong [3] considered a more general instance of the channel problem in which position and order constraints exist for the terminals.Cai and D.F. Wong [3] showed that it is NP-hard to obtain optimal density for this more gen- in either Figure l(a) or l(b) or l(c)" else pop a net Ni from S and place it on the leftmost positions as illustrated in either Fig- ure l(d) or l(e)"

FIGURE
FIGUREIllustration of procedure Internal_Nets.Placed terminals are represented by solid cycles, the terminals of the most recently placed net are represented by empty cycles.
(b) Transform each net N of value k > 1 to the pattern of Figure 2(a) by adding zero terminals on the bottom side; (These terminals will be part of N;.)If 71 enough zero terminals [hen go Step (e); (e) Transform each net Ni of value k < -1 to the pattern of Figure 2(b) by adding zero terminals (d) (e) end on the top side.(These terminals will be part of If ] enough zero terminals then go to Step (e).(Now the density is one.)Place the transformed nets in Steps (b) and (c) at the leftmost available positions; exit;

FIGURE 2
FIGURE 2 Transformations of nets in Algorithm 1.A net with (a) positive, (b) negative value and its representation.Added zero terminals are represented by empty cycles.The terminals are assigned on consecutive positions after the transformation.
(a)  gives K 1 while the assignment in Figure3(b) gives K 2 and is suboptimal.

FIGURE 3
FIGURE 3 Sorting the external nets in Algorithm 2. (a) One zero terminal is needed.(b) Two zero terminals are needed.
require O(m) time.Similarly Step (d) requires O(m) time.

FIGURE 7
FIGURE 7The bottom side of the constructed channel with the placed terminals.

FIGURE 8
FIGURE 8 Examples for the special case.

FIGURE 9 A
FIGURE 9 A suboptimal solution using Lin-Sahni's maximum alignment algorithm.(a) The input instance.(b) The bipartite graph.(c) Final alignment.
while =1 an external net Ni do begin Place a new terminal ti at position T and in a new cell;j:= j + 1 end Let C be the new channel; call Lin_Sahni(C) end of generalized__Lin_Sahni(C) Algorithm 3(via_minimization)    Input: A channel C with internal and external nets.Output: A terminal interchange that obtains minimum number of vias.(a)Obtain maximum alignment in the reduced channel consisting of the two terminal internal nets only; (b) Contract the columns that have aligned nets; Let C2 be the reduced channel instance;

FIGURE 10 A
FIGURE 10 A channel and its switchbox.
(b) P= PUB End of Algorithm 4a