Polynomial-Time Analysis of Toroidal Periodic Graphs

Journal of Algorithms 34, 14᎐39 Ž2000. Article ID jagm.1999.1046, available online at http:rrwww.idealibrary.com on Polynomial-Time Analysis of Toroi...
Author: Everett Hall
1 downloads 2 Views 167KB Size
Journal of Algorithms 34, 14᎐39 Ž2000. Article ID jagm.1999.1046, available online at http:rrwww.idealibrary.com on

Polynomial-Time Analysis of Toroidal Periodic GraphsU F. Hofting ¨ Deutsche Telekom Mobilnet GmbH, Post Office Box 300463, D-53184 Bonn, Germany E-mail: [email protected]

and E. Wanke Department of Computer Science, Mathematical Institute, D-40225 Dusseldorf, Germany Heinrich-Heine Uni¨ ersity Dusseldorf, ¨ ¨ E-mail: [email protected] Received May 23, 1996

A toroidal periodic graph G D is defined by an integral d = d matrix D and a directed graph G in which the edges are associated with d-dimensional integral vectors. The periodic graph has a vertex for each vertex of the static graph and for each integral position in the parallelpiped defined by the columns of D. There is an edge from vertex u at position y to vertex ¨ at position z in the periodic graph if and only if there is an edge from u to ¨ with vector t in the static graph such that the difference z y Ž y q t . is the sum of integral multiples of columns of D. We show that Ž1. the general path problem in toroidal periodic graphs can be solved with methods from linear integer programming, Ž2. path problems for toroidal periodic graphs G D can be solved in polynomial time if G has a bounded number of strongly connected components, Ž3. the number of strongly connected components in a toroidal periodic graph can be determined in polynomial time, and Ž4. a periodic description for each strongly connected component of G D can be found in polynomial time. 䊚 2000 Academic Press

1. INTRODUCTION A toroidal periodic graph Žtoroidal graph. G D is a finite directed graph described by a so-called static graph G and a so-called modulus matrix D. A static graph is a directed graph in which the edges are associated with * A short abstract of this paper has appeared in the ‘‘Proceedings of the 21st International Colloquium on Automata, Languages and Programming, 1994.’’ 14 0196-6774r00 $35.00 Copyright 䊚 2000 by Academic Press All rights of reproduction in any form reserved.

ANALYSIS OF TOROIDAL PERIODIC GRAPHS

15

integral vectors. A d-dimensional modulus matrix D g ⺪ d= d is an integral d = d-matrix of full row rank. The columns of the modulus matrix define an integral parallelpiped RŽ D . [  y g ⺪ d N y s D ⭈ ␣ , ␣ g ⺢ d, 0 F ␣ - 14 . The toroidal graph G D is defined by the following procedure: Place a copy of the vertex set of G at each position y in the integral parallelpiped RŽ D . defined by D. Then for each edge in G from ¨ to w associated with integral vector t, the copy of ¨ at position y is connected with the copy of w at position z by an edge if and only if z s Ž y q t . q D ⭈ x for some x g ⺪ d. The notion toroidal results from the similarity between the geomtric construction of a torus in the one- or two-dimensional space and the manner in which certain edges are wrapped around in the construction of G D ; see Fig. 1.1 for an example. If RŽ D . is defined to be the infinite integral space ⺪ d then the corresponding periodic graph is also called an infinite periodic graph. The infinite periodic graph model has been considered by several authors under various respects; see, for example wBST92, CM91, CM93, HW95, IS87, KO91, KS88, Orl84x. An interesting field in which the infinite periodic graph model finds applications is the area of the so-called synthesis techniques for the automatic mapping of algorithms onto regular arrays. Karp, Miller, and Winograd wKMW67x analyze so-called systems of uniform recurrence equations in which the variables are indexed by integral vectors. The dependencies between variables are modeled by a so-called infinite dependence graph which corresponds to an infinite periodic graph. The infinite dependence graph is represented by a so-called reduced dependence graph which corresponds to a static graph. A similar mathematical model which has become increasingly popular is the so-called polytope

FIG. 1.1. A 2-dimensional static graph G, a modulus matrix D to the left, and the toroidal graph G D to the right.

16

HOFTING AND WANKE ¨

model. In the polytope model, a perfect nest of d FOR-loops is represented by a d-dimensional convex polytope. The boundaries of each loop specify the extent of the polytope in distinct dimensions. An overview concerning automatic parallelization in the polytope model is given in wLen93x. The methods for mapping a dependence structure onto a processor array, in general, consist of two steps, finding a scheduling for the computation which is compatible with the dependence structure and then mapping the index domain onto a finite set of coordinates each representing a processor of a systolic array. The mappings are built in such a way that successive computation steps are scheduled one after the other and concurrent computation steps are mapped onto different processor positions. However, each mapping is designed for a given dependence structure. When the size of the index domain is enlarged, a new mapping has to be found, because the target array is usually some hardware which cannot arbitrarily be enlarged. One way to escape this problem is to use toroidal processor arrays and mappings with computations in modular arithmetic. Then almost arbitrarily sized dependence structures could be mapped onto a fixed sized array using the same mapping. So the analysis of toroidal graphs seems to be an interesting and promising challenge also in the area of automatic processing of dependence structures. In this paper, we present polynomial time algorithms for analyzing toroidal graphs. The polynomial running time is not straightforward, because G D has n ⭈ volŽ D . vertices, where n is the number of vertices in G and volŽ D . is the absolute value of the determinant of D. That is, constructing the toroidal graph G D for an analysis could take exponential time with respect to the size of G and D. In Section 2, we introduce the preliminaries. We define the staticrperiodic graph model in a more formal way and show that each toroidal graph can be defined by some rectangular parallelepiped. In Section 3, we consider path problems on periodic graphs. We show that path problems on toroidal graphs can be solved with methods from integer linear programming, and that they can be solved in polynomial time, if G is strongly connected or has a constant number of strongly connected components, respectively. The general path problem on toroidal graphs is shown to be NP-complete even if D is a positive diagonal matrix. In Section 4, we consider connectivity problems on toroidal graphs. We present an efficient procedure for determining the number of strongly connected components in a toroidal graph. This procedures takes polynomial time for all instances G and D. We prove that all strongly connected components of G D are isomorphic and introduce a polynomial time method which modifies G into GX and D into DX such that the periodic

ANALYSIS OF TOROIDAL PERIODIC GRAPHS

17

X

graph GX D is isomorphic to each of the strongly connected components of G D. All methods introduced in this paper are very general and can also be used to solve further graph problems on toroidal graphs in polynomial time. Some of these problems are discussed in Section 6.

2. PRELIMINARIES In the following three subsections, we define step by step the necessary preliminaries used in the forthcoming sections. 2.1. Periodic Graphs Let a, b, m g ⺪ be integers. We say that a is congruent to b modulo m, written a ' b mod m, if and only if the difference a y b is an integral multiple of m. The least nonnegati¨ e remainder of a divided by m, denoted by a mod m, is the integer from 0, . . . , m y 1 which is congruent to a modulo m. Integer m is called the modulus and assumed to be nonzero. The integral vector containing the same integer a at each coordinate is denoted by a. The comparison of two vectors y and z is carried out step by step for each coordinate. That is, y - z holds if and only if y is less than z in each coordinate. Let y and z be two d-dimensional integral vectors and D be some integral d = d matrix of full row rank. We say that y is congruent to z modulo the column image of D, written y ' z mod D, if and only if the difference z y y is equal to Dx for some d-dimensional integral vector x g ⺪ d. Matrix D yields an equivalence relation, denoted by ;D , which is defined by y ;D z if and only if y ' z mod D. The number of equivalence classes of ;D is denoted by volŽ D ., the ¨ olume of D, which is the absolute value of the determinant of D; see also Subsection 2.2. If the determinant of D is zero then D does not have full row rank and thus ;D has an infinite number of equivalence classes. To define a periodic graph, we need a finite set RŽ D . : ⺪ d of representatives for the equivalence classes of ;D . That is, for each vector y g ⺪ d there has to be exactly one vector z g RŽ D . such that y ;D z. There are several ways where such a set RŽ D . of representatives can be defined. For

HOFTING AND WANKE ¨

18

example, the set of all integral vectors in the parallelepiped defined by the columns of D

 x g ⺪ d N x s D ⭈ ␣ , ␣ g ⺢ d , 0 F ␣ - 14 defines such a set of representatives. It is also possible to define such a set of representatives by enumerating the equivalence classes with nonnegative integral vectors in lexicographical order, i.e., y -lex z if there is some i, 1 F i F d, such that yi - z i and for j s 1, . . . , i y 1 and y j s z j . However, for the rest of this paper we assume that for each integral d = d matrix D of full row rank the set of representatives RŽ D . for the equivalence classes of ;D is defined in some fixed way. For example, for matrix D s Ž 30 32 . the integral vectors in the parallelepiped defined by the columns of D are 0 1 2 2 3 4 , , , , , 0 0 0 1 1 1

½ž / ž / ž / ž / ž / ž /5

,

where the lexicographical enumeration by nonnegative integral vectors yields the set 0 0 1 1 2 2 , , , , , 0 1 0 1 0 1

½ž / ž / ž / ž / ž / ž /5

;

see Fig. 2.2. For some integral vector y g ⺪ d, let z be the integral vector from RŽ D . that is congruent to y modulo the column image of D, i.e., y ;D z. Vector z is also denoted by y mod D. Matrix D is called the modulus matrix. DEFINITION 2.1 ŽStatic graph.. A d-dimensional static graph is a directed graph G s Ž V, E . with a finite set of vertices V and a finite set of edges E : V = V = ⺪ d. Each edge e s Ž ¨ , w, t . consists of 䢇 䢇 䢇

a source vertex ¨ , denoted by sourceŽ e ., a target vertex w, denoted by targetŽ e ., and a d-dimensional integral transit vector t, denoted by tranŽ e ..

The underlying unlabeled graph with edge set Ž u, ¨ . N Ž u, ¨ , t . g E for some t 4 is denoted by unlabŽ G .. DEFINITION 2.2 ŽToroidal periodic graph.. For a d-dimensional static graph G s Ž V, E . and an integral d = d modulus matrix D, the toroidal period graph Žtoroidal graph. G D s Ž V D , E D . is defined by vertex set V D s V = RŽ D . and edge set E D : V D = V D consisting of all edges ŽŽ ¨ , y ., Ž w, z .., where Ž ¨ , w, t . g E, and z s Ž y q t . mod D. 䢇 䢇

ANALYSIS OF TOROIDAL PERIODIC GRAPHS

19

FIG. 2.2. The cycles represent 2-dimensional integral vectors. The letters in the cycles enumerate the six equivalence classes of ;D by a, b, c, d, e, f. The arrows Žthe columns of D . show how the differences of the integral vectors from equivalence class ‘a’ can be expressed by integral multiples of columns of D. An equivalence class of ;D is sometimes also called a lattice. D s 30 32 .

ž /

2.2. The Volume of Integral Square Matrices Next we show that column and row operations of the form 1. adding an integral multiple of one column Žrow. to another, 2. multiplying a column Žrow. by y1, and 3. interchanging two columns Žrows. applied to a modulo matrix D do not change the number of equivalence classes of ;D , i.e., the volume of D. We will frequency use these so-called elementary column and row operations to transform periodic graphs. For an arbitrary matrix M and two distinct columns i and j of M, let c iqj Ž M . and c iyj Ž M . be the matrix M in that the ith column is added to the jth column or subtracted from the jth column, respectively. Let riqj Ž M . and riyj Ž M . be the matrix M in that the ith row is added to the jth row or subtracted from the jth row, respectively. ŽHere we have used for a matrix the symbol M and not D, because M need not be a d = d matrix..

20

HOFTING AND WANKE ¨

Let D be an integral d = d matrix of full row rank and 1 F i, j F d, i / j. Then Dx s c iqj Ž D . r jyi Ž x . s c iyj Ž D . r jqi Ž x . . Thus, two vectors y, z g ⺪ d are congruent modulo the column image of D if and only if they are congruent modulo the column image of c iqj Ž D . or c iyj Ž D ., respectively. So we can add or subtract any integral multiples of one column to another column without changing the equivalence relation ;D . The same holds for multiples of a column by y1 and for interchanging two columns. For any x, y g ⺪ d, we have Dx s y if and only if riqj Ž D . x s riqj Ž y . if and only if riyj Ž D . x s riyj Ž y .. That is, two vectors y, z g ⺪ d are congruent modulo the column image of D if and only if riqj Ž y . and riqj Ž z . are congruent modulo the column image of riqj Ž D . if and only if riyj Ž y . and riyj Ž z . are congruent modulo the column image of riyj Ž D ., because riqj Ž y . y riqj Ž z . s riqj Ž y y z . and riyj Ž y . y riyj Ž z . s riyj Ž y y z .. Since both mappings riqj , riyj are one-to-one mappings with reverse riyj , riqj , respectively, it follows that all three equivalence relations ;D , ;r iy jŽ D . , ; r iq jŽ D . have the same number of equivalence classes. A bijection between the equivalence class of ;D and the equivalence classes of ;r iq jŽ D . and ;r iq jŽ D . can simply be defined by any bijection between the representatives of the corresponding equivalence classes, as, for example, by h iqj : R Ž D . ª R Ž riqj Ž D . . defined by h iqj Ž x . s riqj Ž x . mod riqj Ž D . and by h iyj : R Ž D . ª R Ž riyj Ž D . . defined by h iyj Ž x . s riyj Ž x . mod riyj Ž D ., respectively. Here also, the same holds for multiplying a row by y1 and for interchanging two rows. So the volume of matrix D does not change when performing elementary column or row operations, whereby additionally, the matrices D, c iqj Ž D . , c iyj Ž D . , riqj Ž D . , riyj Ž D . even have the same determinant, where multiplying a column or row by y1 or interchanging two columns or rows changes the sign of the determinant. Analogously, we can define the congruence of two vectors modulo the

ANALYSIS OF TOROIDAL PERIODIC GRAPHS

21

column image of an integral d = l matrix M of full row rank for l ) d. That is, y is congruent to z modulo the column image of M, written y ' z mod M, if and only if the difference z y y is equal to Mx for some d-dimensional integral vector x g ⺪ d. The number of equivalence classes of ;M can now be computed by transforming M into an equivalent d = d matrix D and then computing the volume of D. Such a transformation of M into D can even be done in polynomial time by transforming M into Hermite normal form; see wKB79x. 2.3. Orthogonal Toroidal Graphs Now we show how to transform in polynomial time a static graph G into a static graph GX and a modulus matrix D into a positive diagonal matrix DX such that the unlabeled static graphs unlabŽ G . and unlabŽ GX . are X isomorphic and the periodic graphs G D and GX D are isomorphic. This shows that each toroidal graph can be defined by some static graph and some positive diagonal matrix. The transformation only uses elementary column and row operations on the modulus matrix D and elementary row operations on the transit vectors of the edges of the static graph. THEOREM 2.3. Gi¨ en a static graph G and a modulus matrix D, it is always possible to transform G in polynomial time into a static graph GX , and to transform D into a X positi¨ e diagonal matrix DX such that unlabŽ G ., unlabŽ GX ., and G D , GX D are isomorphic. Proof. Elementary column operations on D do not change the equivalence relation ;D and thus have no effect on the periodic graph G D. Let T be the d = m matrix such that the ith column of T is the transit vector tranŽ e j . of edge e i , i.e., the entry in T at row i and column j is the entry at coordinate i of transit vector tranŽ e j .. T is called the transit matrix of G. For the rest of this proof, we assume that changing entries in T means changing the corresponding entries in the transit vectors of the edges of G. An elementary row operation on matrix D does not change the periodic graph G D if the same row operation is done on matrix T. For example, let GX be the static graph with transit matrix T X s riqj ŽT ., and DX s riqj Ž D ., X X then G D and GX D are isomorphic. An isomorphism between G D and GX D is, for example, h: VG = R Ž D . ª VG = R Ž g iqj Ž D . . defined by hŽ u, x . s hŽ u, riqj Ž x . mod riqj Ž D ..; see Subsection 2.2. The

22

HOFTING AND WANKE ¨

same holds for the other elementary row operations if they are applied simultaneously to D and to T. Let w DT x be the d = Ž d q m. matrix composed by modulus matrix D and transit matrix T of G. We have seen that we can apply elementary column operation on D, i.e., on the first d columns of w D T x and elementary row operations on w D T x, without changing the periodic graph defined by the new static graph and the new modulus matrix. It is easy to transform an integral d = d matrix D of full row rank by a sequence of elementary column and row operations into a positive diagonal matrix. The result of such a transformation is called the Smith normal form if additionally d i, i divides d iq1, iq1 for 1 F i - d Žwhich is not necessarily here.; see wSmi61x. Algorithms that compute Smith normal forms are given Žamong others. by Barnette and Pace wBP74x, Bodewig wBod56x, Bradley wBra70x, Frumkin wFru77x, and Hu wHu56x. A transformation into Smith normal form by elementary column and row operations is even possible in polynomial time; see wKB79x. If the same column and row operations that transform matrix D into Smith normal form are applied to the first d columns and rows of w DT x, then we get a positive d = d modulus matrix DX and a static graph GX with X X XD D transit matrix T such that G and G are isomorphic. Let us illustrate such a transformation by a simple example. EXAMPLE 2.4. Assume we have a modulus matrix D[

ž

2 7

y1 1

/

and a static graph G with two edges e1 , e2 with transit vectors tran Ž e1 . [

2 2

and tran Ž e2 . [

ž/

3 . 2

ž/

Then we get

wDTx s 2

ž

7

y1 1

2 2

3 . 2

/

After multiplying the second column of w D T x by y1 we get

wDTx s 2

ž

7

1 y1

2 2

3 . 2

/

ANALYSIS OF TOROIDAL PERIODIC GRAPHS

23

Subtracting two times the second column of w D T x from the first column yields

wDTx s 0

ž

1 y1

9

2 2

3 . 2

/

Adding the first row of w D T x to the second row yields

wDTx s 0

ž

1 0

9

2 4

3 . 5

/

Interchanging the first two columns yields the result

wDTx s 1

ž

0

DX s

ž

0 9

2 4

3 . 5

/

The new modulus matrix is 1 0

0 . 9

/

The new transit vectors are X

tran Ž e1 . [

2 4

ž/

X

and tran Ž e2 . [

3 . 5

ž/

3. PATHS IN TOROIDAL GRAPHS For our analysis, a path p is an alternating sequence

Ž u1 , e1 , u 2 , . . . , u n , e n , u nq1 . of vertices and edges such that e i is an edge from u i to u iq1. The length of the path p is the number of edges involved; the transit vector of p, denoted by tranŽ p ., is the sum of all transit vectors of the edges of p; i.e., tranŽ p . s Ý nis1 tranŽ e i .. The path problem for toroidal graphs is the question whether for a given static graph G s Ž V, E ., a given modulus matrix D g ⺪ d= d, and a given vertex pair Ž ¨ , y ., Ž w, z . g V D there is a path from Ž ¨ , y . to Ž w, z . in G D . Since the set of representatives RŽ D . is not required to be explicitly given, it is not clear how to specify the vertices Ž ¨ , y . and Ž w, z .. However, for each y g ⺪ d it holds, if ŽŽ u1 , x 1 ., e1 , . . . , e n , Ž u nq1 , x nq1 .. is a path in G D , then ŽŽ u1 , x 1 q y mod D ., e1 , . . . , e n , Ž u nq1 , x nq1 q y mod D .. is a path in G D. So we can alternatively ask the question whether for a given static graph G s Ž V, E ., a given modulus matrix D g ⺪ d= d, a given vertex pair

HOFTING AND WANKE ¨

24

¨ , w g V, and a given pair of integral vectors y, z g ⺪ d there is a path from Ž ¨ , y mod D . to Ž w, z mod D . in G D .

3.1. General Solution The path problem for toroidal graphs can be solved with methods from integer linear programming.1 Let G s Ž V, E . be a d-dimensional static graph with vertex set V s  u1 , . . . , u n4 and edge set E s  e1 , . . . , e m 4 , let D g ⺪ d= d be a modulus matrix, let ¨ g V be some initial ¨ ertex, and let w g V be some final ¨ ertex. We define 䢇

the n = m incidence matrix A with

¡y1 ¢0

if u i s source Ž e j .

A Ž i , j . s~1 䢇

if u i s target Ž e j . else

the d = m transit matrix T with T Ž i , j . s tran Ž e j . i



and the column vector b s

¡ ¢

b1 ⭈ ⭈ ⭈ bn

ž/

y1 bi s 1 0 The transit matrix is defined as in the

~

defined by if u i s ¨ if u i s w else. proof of Theorem 2.3.

EXAMPLE 3.1. For the static graph G s Ž V, E . from Fig. 3.3, with vertex set V s  u1 , u 2 , u 3 , u 4 4 and edge set E s  e1 , e2 , e3 , e4 , e5 , e6 4 , the modulus matrix D s 4 ⭈ I, the initial vertex u1 , and the final vertex u 4 , we obtain y1 0 As 0 1

1 0 0 y1



1 Ts 0

ž

1 0

0 1

0 y1 1 0 0 1

1 1

0 1 y1 0 1 , 0

/

y1 1 0 0

0 0 , y1 1

0

Ds

ž

4 0

0 , 4

/

y1 0 bs . 0 1

0

1 For background information about integer linear programming, see, for example, wNW89, Sch86x.

ANALYSIS OF TOROIDAL PERIODIC GRAPHS

25

FIG. 3.3. A 2-dimensional static graph.

A Ždirected. graph G is called weakly connected if for each pair of vertices ¨ , w the edges in G can be redirected such that there is a path from ¨ to w or, equivalently, if there is an alternating sequence

Ž ¨ s u1 , e1 , u 2 , . . . , u n , e n , u nq1 s w . of vertices and edges such that e i is either an edge from u i to u iq1 or an edge from u iq1 to u i . For an edge set F : E of G, let GŽ F . s ŽU, F . be the subgraph of G induced by the edges in F. That is, GŽ F . has edge set F and vertex set U s  u N u s source Ž e . k u s target Ž e . for e g F 4 . THEOREM 3.2. There is a path in G D from a ¨ ertex Ž ¨ , y . to a ¨ ertex Ž w, z . if and only if the system A⭈xsb

x nonnegati¨ e integral X

T⭈xsD⭈x qzyy

xX integral

Ž 3.1.

has a solution such that the subgraph GŽ e j g E N x j ) 04. of G induced by the edges e j with x j ) 0 is weakly connected. Proof. Assume that A ⭈ x s b for some nonnegative integral vector x. The entries in x can be considered as the frequencies of edges in a possible path p from ¨ to w in G. Then the entry at coordinate i indicates how often edge e i is used. By the definition of A, it follows that all vertices except the initial vertex ¨ and the final vertex w are reached as often as they are left. The entry y1 in b at coordinate i for u i s ¨ ensures that the initial vertex ¨ is left once more than it is reached; the entry 1 in b at coordinate i for u i s w ensures that the final vertex w is reached once more than it is left. One of Euler’s first results in graph theory is the following well-known fact. A weakly connected directed graph has a path from ¨ to w that

HOFTING AND WANKE ¨

26

passes through each edge exactly once if and only if all vertices except ¨ and w have even degree; see wHar69x. If GŽ e j g E N x j ) 04. is weakly connected it follows that there is a path p in G from vertex ¨ to vertex w that passes through each edge e i exactly x i times. We know that for each t g ⺪ d there is a path p in G from ¨ to w with tranŽ p . s t if and only if there is a path in G D from Ž ¨ , y . g VD to some Ž w, z . g VD with y q t mod D s z, for some y, z g RŽ D .. This shows that G D has a path from Ž ¨ , y . to Ž w, z . if and only if System Ž3.1. has a solution such that the subgraph of G induced by the used edges  e j g E N x j ) 04 is weakly connected. THEOREM 3.3. The path problem in toroidal graphs is NP-complete e¨ en for positi¨ e diagonal modulus matrices D in which all diagonal entries are 2. Proof. For the membership to NP, choose an edge set F : E such that GŽ F . is weakly connected and contains the vertices ¨ , w. Then verify whether the following system of integer linear equations Žinteger linear programming belongs to NP; see wBT76x. A⭈xsb

x nonnegative integer X

T⭈xsD⭈x qzyy

xX integer

has a solution, where A and T are defined for GŽ F .. We sketch the NP-hardness by a reduction from SATISFIABILITY, which is log-space complete for NP; see, for example, wGJ79x. Let X s  x 1 , . . . , x n4 be a set of Boolean ¨ ariables. For a variable x g X, x and x are literals over X. A truth assignment for X is a set of literals t such that for each variable x i either literal x i or literal x i is in t. If literal x i is in t, we say that variable x i is true under t; if literal x i is in t we say that x i is false. A clause over X is a set of literals over X. A clause is satisfied by a truth assignment t if and only if at least one of its members is in t. A collection F of clauses over X is satisfiable if and only if there exists some truth assignment t for X that simultaneously satisfies all clauses in F. The SATISFIABILITY problem is the question whether for a given set X s  x 1 , . . . , x n4 of variables and a given collection C s  C1 , . . . , C d 4 of clauses over X there is a truth assignment for X that satisfies C . We will describe a d-dimensional static graph G such that G D , where D is the d = d diagonal matrix with diagonal entries 2, has a path from Ž ¨ , 0. to Ž w, 1. for some ¨ , w if and only if there is a truth assignment for X that satisfies C . The jth dimension of the vectors is associated with the jth clause. G has n q 1 vertices u 0 , . . . , u n and some further vertices which are not explicitly addressed here. There are always two collections of paths from u iy1 to u i

ANALYSIS OF TOROIDAL PERIODIC GRAPHS

27

FIG. 3.4. The static graph G for the clauses C1 s  x 1 , x 2 , x 3 4, C2 s  x 1 , x 2 , x 4 4, C3 s  x 3, x 4, x 5 4, and C4 s  x 1 , x 4, x 5 4. For each edge with a nonzero transit vector there is a parallel edge with a zero transit vector. Here the transit vectors are drawn as row vectors.

for each 1 F i F n; one collection for literal x i and one collection for literal x i. Let t Ž x i . Ž t Ž x i.. be the integral vector in which the jth coordinate is 1 if and only if x i Ž x i, respectively. is contained in clause C j ; all remaining coordinates are zero. The collection of paths for x i Ž x i. contains a path p from u iy1 to u i with tranŽ p . s tX for each 0 F tX F t Ž x i . Ž0 F tX F t Ž x i., respectively.. An example of such a construction is shown in Fig. 3.4. Obviously, there is a path from Ž u 0 , 0. to Ž u n , 1. in G D if and only if there is a truth assignment for X that satisfies C . Note that the corresponding problem for infinite periodic graphs is also NP-complete; see wHW95x. 3.2. Strongly Connected Static Graphs Although, in general, the path problem in toroidal graphs is NP-complete, we now show that it can be solved in polynomial time if the underlying unlabeled graph of the static graph is strongly connected. A graph is strongly connected if and only if for each vertex pair ¨ , w there is a path from ¨ to w and vice versa. Strong connectivity is decidable in linear time by depth-first-search strategies. The polynomial time algorithm for the path problem in toroidal graphs is based on the following fact: If G is strongly connected, then System Ž3.1. has a solution such that the subgraph of G induced by the used edges

HOFTING AND WANKE ¨

28

 e j g E N x j ) 04 is weakly connected if and only if the following system of integer linear equations has a solution: A⭈xsb

x integer X

T⭈xsD⭈x qzyy

xX integer.

Ž 3.2.

There are two differences between System 3.2 and the general solution specified by System 3.1 with the additional property that GŽ e j N x j ) 04. is weakly connected. First, in System 3.2 we do not demand x be nonnegative, and second, GŽ e j N x j ) 04. need not be weakly connected. In the following lines, we show that both properties are unimportant if G is strongly connected. Let c be a cycle that passes through all edges of G. Such a cycle always exists if G is strongly connected. Note that this cycle may use some edges more than others and does not have to be simple; otherwise, such a cycle does not always exist. Let ␤ Ž c . be the m-dimensional nonnegative integral vector whose jth coordinate represents the number of occurrences of edge e j in cycle c. Since c is a cycle, we have A ⭈ ␤ Ž c . s 0. Let cU be the cycle obtained by repeating the cycle c volŽ D . times. That is, if c passes through the nodes in the order u1 , u 2 , . . . , u n , u1 then cU passes through the nodes u1 , u 2 , . . . , u n , u1 , u 2 , . . . , , . . . , u n , u1 , u 2 , . . . , u n , where the vertex sequence u1 , u 2 , . . . , u n is repeated volŽ D . times. Then we have again A ⭈ ␤ Ž cU . s 0, and additionally T ⭈ ␤ Ž cU . ' 0 mod D, because each entry in ␤ Ž cU . is a multiple of each entry in the diagonal of D and we have assumed without loss of generality that D is a diagonal matrix. Note that this is not important for the correctness but only easier to understand. Now assume x is a solution for System Ž3.2. such that some entries in x are negative. Let minŽ x . be the least entry in x. Then

␥ [ x q Ž ymin Ž x . q 1 . ⭈ ␤ Ž cU .

ANALYSIS OF TOROIDAL PERIODIC GRAPHS

29

is positive, because cU contains each edge at least once, and ␥ satisfies A⭈␥sb T ⭈ ␥ ' z y y mod D, and GŽ e j g E N ␥ j ) 04. s G is weakly connected. Thus, ␥ is a solution for System 3.1. If x is a nonnegative solution for System Ž3.2. and GŽ e j N x j ) 04. is not weakly connected, then x q ␤ Ž cU . is a nonnegative solution and GŽ e j N x j q ␤ Ž cU . j ) 04. s G is weakly connected. Since integer linear equations with integral solutions Žlinear Diophantine equations. can be solved in polynomial time, see wFru77, Sch86x, we have proved the following theorem. THEOREM 3.4. The path problem for toroidal graphs can be sol¨ ed in polynomial time if the static graph is strongly connected. Let us illustrate the transformation with the instance considered in Example 3.1. Suppose we are interested in the existence of a path from Ž u1 , Ž 10 .. to Ž u 4 , Ž 22 .. in G D . The integral vector 1 0 y1 xs y1 0 0

0

satisfies A⭈xsb T⭈xsD⭈

0 1 q , y1 2

ž / ž/

but is not a solution for System Ž3.1., because some entries of x are negative. Let c s Ž u1 , e 5 , u 2 , e 3 , u 3 , e 4 , u 2 , e 3 , u 3 , e 6 , u 4 , e 2 , u1 , e 1 , u 4 , e 2 , u1 .

30

HOFTING AND WANKE ¨

be the cycle that passes through all edges of G. Then 1 2 2 ␤ Ž c. s , det Ž D . s 16, 1 1 1

0

16 32 32 U ␤Žc . s , min Ž x . s y1, ␥ s 16 16 16

0

A ⭈ ␥ s b, T⭈␥sD⭈

33 64 63 , 31 32 32

0

40 1 q , 11 2

ž / ž/

and GŽ e1 , e2 , e3 , e4 , e5 , e6 4. s G is weakly connected. 3.3. Almost Strongly Connected Static Graphs A strongly connected component GX s Ž V X , EX . of a graph G s Ž V, E . is a maximal strongly connected subgraph of G. That is, V X : V, EX : E, GX is strongly connected, and each GY s Ž V Y , EX . with V X ; V Y : V and EX ; EY : E is not strongly connected. Now we show that the path problem in toroidal graphs can also be solved in polynomial time if the number of strongly connected components of the static graph G is bounded by some constant. We will explain later how the running time of the algorithm depends on the number of connected components. Let F : E be the set of all edges which do not belong to some strongly connected component of G. First, choose a subset F X of F such that there is a path p from ¨ to w passing all edges from F X and no edge from F y F X . If there are k connected components in G then each such path has at most k y 1 edges from F and we need only to consider subsets F X with at most k y 1 edges. X 1Ž l . So there are at most Ý ky is1 i such subsets F , where l is the number of edges in F. These subsets F X can easily be enumerated. Second, remove all edges of G except those which belong to F X or to a strongly connected component passed by p. Let the resulting graph be GX s Ž V X , EX ..

ANALYSIS OF TOROIDAL PERIODIC GRAPHS

31

Third, extend System Ž3.2. which is now defined for the new graph GX by the equations B ⭈ x s 1, where B is an Ž< F X < = < EX