1990-The Complexity of Constraint Satisfaction in Prolog
Total Page:16
File Type:pdf, Size:1020Kb
From: AAAI-90 Proceedings. Copyright ©1990, AAAI (www.aaai.org). All rights reserved. The Complexity of Constraint §atisfaction in Prolog Bernard A. Nadel Department of Computer Science Wayne State University Detroit, Michigan, 48202 [email protected] Abstract rules, but only of facts all of which are ground, and a query which is a conjunction of positive literals con- We obtain here the complexity of solving a type of taining variables. Strategies for ordering the conjunc- Prolog problem which Genesereth and Nilsson have tive queries have been studied in [15] and [19]. called sequential constraint satisfactrlon. Such prob- The present paper provides the first analytic expres- lems are of direct relevance to relational database re- sions for the expected complexity of solving such prob- trieval as well as providing a tractable first step in ana- lems. The analysis is based on a division of the problem lyzing Prolog problem-solving in the general case. The class into what we call small classes, defined in section present paper provides the first analytic expressions 2. These classes, and the assumed probability model for the expected complexity of solving sequential con- defined in section 3, are analogs for Prolog of those used straint satisfaction problems. These expressions pro- in the author’s earlier analyses of the complexity of tra- vide a basis for the formal derivation of heuristics for ditional constraint satisfaction problem-solving [6], [8], such problems, analogous to the theory-based heuris- [12]. As opposed to the big classes which were also tics obtained by the author for traditional constraint used in prior work (but which are not defined here), satisfaction problem-solving. A first application has most instances of a small classes have remarkably sim- been in providing a formal basis for Warren’s heuris- ilar complexity values. tic for optimally ordering the goals in a conjunctive This homogeneity property is the result of taking into query. Due to the incorporation of “constraint loose- account “constraint tightness” (in terms of Sj or Rj ness” into the analysis, the expected complexity ob- below) in defining small classes. As a result of small tained here has the useful property that it is usually class homogeneity, the expected case complexity for a quite accurate even for individual problem instances, given small class is likely to be a good estimate of the rather than only for the assumed underlying problem “exact case” complexity of most individual instances in class as a whole. Heuristics based on these results can the small class. This makes the expected case results be expected to be equally instance-specific. Prelimi- much more practical by allowing them to be used for nary results for Warren’s heuristic have shown this to complexity prediction on an instance-by-instance basis, be the case. independent of the applicable probability distribution, if any, rather than only for a small class as a whole, under the assumed distribution. 1. Introduction The expected complexity for solving sequential con- Two areas of major interest in Artificial Intelligence are straint satisfaction problems is obtained in section 4, constraint satisfaction problem solving and the logic in terms of the expected number of nodes in the Pro- programming language Prolog. Recently there has been log search tree for finding all solutions of a problem in considerable interest in the relationship between these a small class. Extensions of the results are discussed two areas [4] [14] [16] [17] [NJ. This paper grew out briefly in section 5. A simple running example is used of a study of this relationship. It treats one of the throughout. simplest types of Prolog problems, which Genesereth The complexity expressions obtained here provide a and Nilsson [2] call sequential constraint satisfaction formal basis for the derivation of heuristics for solving problems. These involve a database consisting of no this kind of Prolog problem, analogous to the theory- NADEL 33 based derivation of heuristics (for choosing a good al- relational database theory [5]. It is not the same thing gorithm, search ordering and even problem represen- as a literal used in a query of the Prolog database, tation) which has been possible for regular constraint although they are related as discussed below. Zj = satisfaction problem-solving [3] [S] [7] [8] [9] [12] [13]. A {~ilr%,...,~iaj } and Aj = ]Zj] are respectively the first example of this for our Prolog problems has been argument set and urity of pj. We may assume without in providing a formal basis for Warren’s intuitively mo- loss of generality that the set 2 of all variables is given tivated heuristic for optimally ordering the goals in a byZ=UF=rZj. conjunctive query [19]. The instance-specificity of the Each database of the small class consists only of complexity results here is expected to carry over to ground facts for each of the predicate symbols pj. The the theory-based heuristics derived from them. Pre- fact templates serve to specify the form and range of liminary results for Warren’s heuristic show this to be these facts. Specifically, facts for pj must have the form the case. By generalizing the problem class under con- sideration (in particular, allowing databases with rules and variables) it should be possible to obtain simi- where h, is a value chosen only from the domain of lar instance-specific, theory-based guidance for Prolog the argument variable zik occurring for that position problem solving in general. in the fact template. Each fact pj (Zj) thus corresponds to an Aj-tuple Zj from the Cartesian product Dj of the 2. Sequential Constraint Satisfaction domains of the arguments of pj. Cartesian product Dj Problems and Small Classes and its size M are given respectively by Dj = X dzi ZiEZj To analyze the complexity of solving sequential con- and Mj = m.2;. straint satisfaction problems it is convenient to divide’ ZiEZj the space of all possible databases for such problems For each pj there is a parameter Sj, called the sut- into what we class small classes. The expected com- isfiubidity of pj, which specifies how many facts for pj plexity derived will be over the databases of a small are in the database. The quantity Rj = Sj/Mj we class, each database arising with equal probability as call the sutisfiubility ratio for pj. Of course Sj and Rj described in the next section. respectively satisfy 0 5 Sj 5 Mj and 0 5 Rj 5 1. Associated with a small class is an underlying set Rj is the fraction of possible tuples (formable from z= {q,z2,..., .z~} of n variables, each having a finite the domains of the corresponding argument variables) domain dzi = {1,2,. , m,;} of m,, candidate values. which actually correspond to facts in the database for We denote the domain values as integers here for con- Pj - Considering the goals of a conjunctive query as venience, but the results apply for values that are arbi- constraints to be simultaneously satisfied, Rj is a mea- trary Prolog ground terms. Variables zi will sometimes sure of the looseness of the constraint corresponding to be called domain variables or formal variables to dis- the pj goal. tinguish them from logical variables which appear in The required Sj facts for pj can correspond to any the queries to be asked with respect to a database. size-Sj subset of Dj and hence there are (7) ways There is a set P = {pr ,p2,. , PK} of Ii’ predicate to choose the facts for pj. Since such a choiie of Sj symbols, each having an associated fact template facts is required for each pj, 1 5 j 5 I<, the number of sequential constraint satisfaction databases scsd in Pj (-%I >%Q Y- * - Y%iaj) (1) a small class is which specifies its arguments variables zik E 2 and their corresponding argument positions. The order of ISCSD(n, m, I(, Z, S)l = fi (z) . j=l arguments in a template is usually, but not necessarily, in increasing order of the argument variable indices. Here SCSD( n, r-n, K, 2, S) denotes the generic small A fact template is analogous to a relation schema in class characterized by n problem variables, set lIl= } of domain sizes, K predicate sym- ‘This division is not a partition however, since a given (mzl,mzZ,...,mzn database may be considered as a member of an infinite num- bols, set Z = (Zi,&, . , 2~) of predicate argument ber of small classes, as implied in section 5 and discussed more sets and set S = {Sl , S2, . , SK) of predicate satisfia- fully in [ll]. bilities. 34 AUTOMATEDREASONING k: Nk N/c 0 1 1 = 1 ~3(~1,~2,1),~2(~1,~2) ~3(zl,z2,3),~2(~1,~2) 1 2 l(3.i) = 2 (az2) =/Ll) \o ‘I/ pw \(2,lPx%p 65 P2OJ) Pw&l) P2UJ) P2W) PWJ) Pww 2 6 2 - (4 * +$) = I I q q 3 5 S$(l-;) = 5 W>l) WJ) UA3) (2~3) w&3) 14 14i Fig. 1: The Prolog search tree for the scsp of solving query (2) with respect to our example database. For example, consider the set 2 = { ~1, ~2, zs} of labelled by the corresponding 3-tuple solution for the n = 3 underlying domain variables, having domains logical variables in the order (~1, ~2, ~3). In the follow- = {1,2,3} of respective ing sections we derive the expected case complexity of d 21 - dz2 = {1,2} and d,, sizes m,, = m,, = 2 and mz3 = 3. Let’s say the answering such queries with respect to the databases of database consists of facts for I< = 3 predicate sym- a small class.