Linköpings universitet SE–581 83 Linköping
Linköping University | Department of Computer and Information Science
Master thesis, 30 ECTS | Theoretical Computer Science
2019 | LIU-IDA/LITH-EX-A--19/094--SE
Solving Temporal CSPs via
Enu-meration and SAT Compilation
Leif Eriksson
Supervisor : Peter Jonsson Examiner : Victor Lagerkvist
Upphovsrätt
Detta dokument hålls tillgängligt på Internet - eller dess framtida ersättare - under 25 år från publicer-ingsdatum under förutsättning att inga extraordinära omständigheter uppstår.
Tillgång till dokumentet innebär tillstånd för var och en att läsa, ladda ner, skriva ut enstaka ko-pior för enskilt bruk och att använda det oförändrat för ickekommersiell forskning och för undervis-ning. Överföring av upphovsrätten vid en senare tidpunkt kan inte upphäva detta tillstånd. All annan användning av dokumentet kräver upphovsmannens medgivande. För att garantera äktheten, säker-heten och tillgängligsäker-heten finns lösningar av teknisk och administrativ art.
Upphovsmannens ideella rätt innefattar rätt att bli nämnd som upphovsman i den omfattning som god sed kräver vid användning av dokumentet på ovan beskrivna sätt samt skydd mot att dokumentet ändras eller presenteras i sådan form eller i sådant sammanhang som är kränkande för upphovsman-nens litterära eller konstnärliga anseende eller egenart.
För ytterligare information om Linköping University Electronic Press se förlagets hemsida http://www.ep.liu.se/.
Copyright
The publishers will keep this document online on the Internet - or its possible replacement - for a period of 25 years starting from the date of publication barring exceptional circumstances.
The online availability of the document implies permanent permission for anyone to read, to down-load, or to print out single copies for his/hers own use and to use it unchanged for non-commercial research and educational purpose. Subsequent transfers of copyright cannot revoke this permission. All other uses of the document are conditional upon the consent of the copyright owner. The publisher has taken technical and administrative measures to assure authenticity, security and accessibility.
According to intellectual property law the author has the right to be mentioned when his/her work is accessed as described above and to be protected against infringement.
For additional information about the Linköping University Electronic Press and its procedures for publication and for assurance of document integrity, please refer to its www home page: http://www.ep.liu.se/.
Abstract
The constraint satisfaction problem (CSP) is a powerful framework used in theoretical computer science for formulating a multitude of problems. The CSP over a constraint lan-guageΓ (CSP(Γ)) is the decision problem of verifying whether a set of constraints based on the relations inΓ admits a satisfying assignment or not. Temporal CSPs are a special subclass of CSPs frequently encountered in AI. Here, the relations are first-order definable in the structure(Q; ă), i.e the rationals with the usual order. These problems have previ-ously often been solved by either enumeration or SAT compilation. We study a restriction of temporal CSPs where the constraint language is limited to logical disjunctions of ă-,
=-, ‰- and ď-relations, and were each constraint contains at most k such basic relations (CSP(tă,=, ‰, ďu_k)).
Every temporal CSP with a finite constraint languageΓ is polynomial-time reducible to CSP(tă,=, ‰, ďu_k)where k is only dependent on Γ. As this reduction does not
in-crease the number of variables, the time complexity of CSP(Γ)is never worse than that of CSP(tă,=, ‰, ďu_k). This makes the complexity of CSP(tă,=, ‰, ďu_k)interesting to study.
We develop algorithms combining enumeration and SAT compilation to solve CSP(tă,=, ‰, ďu_k), and study the asymptotic behaviour of these algorithms for differ-ent classes. Our results show that all finite constraint languagesΓ first order definable over
(Q; ă)are solvable in O˚((( 1
e ln 2´ ek)n)n)time for some ek ą0 dependent onΓ. This is
strictly better than O˚(( n
e ln 2)n), i.e. O˚((0.5307n)n), achieved by enumeration algorithms.
Some examples of upper bounds on time complexity achieved in the thesis are CSP(tău_2)
in O˚((0.1839n)n)time, CSP(tă,=, ďu_2)in O˚((0.2654n)n)time, CSP(tă,=, ‰, u_3)in
O˚((0.4725n)n)time and CSP(tă,=, ‰, ďu_3)in O˚((0.5067n)n)time. For CSP(tău_2)
this should be compared to the bound O˚((0.3679n)n), from previously known
Acknowledgments
I would like to sincerely thank my supervisor Peter Jonsson, I know he and I see the world through different eyes, but without him this thesis would never have reached any acceptable standard. Further, I would like to thank Mats Aigner of MAI for his sanity check of the more mathematical parts of the thesis and Anton Hölscher for his help with the preparatory phase.
Contents
Abstract iii
Acknowledgments iv
Contents v
List of Figures vi
List of Tables vii
1 Introduction 1 1.1 Constraint Satisfaction . . . 1 1.2 Temporal CSPs . . . 1 1.3 Our Results . . . 2 2 Preliminaries 4 2.1 Propositional Logic . . . 4
2.2 Constraint Satisfaction Problems . . . 6
2.3 Orders . . . 7
3 Disjunctions of at most size two 9 3.1 CSPs Limited to ă-relations . . . 9
3.2 CSPs Limited to ă,=and ď-relations . . . 15
4 Disjunctions of at most size k 22 4.1 k+-SAT . . . 22
4.2 Exhaustive Search Algorithm . . . 24
4.3 Handling k-equality Clauses . . . 24
4.4 Constructing Strict Weak Orders From Strict Total Orders . . . 25
4.5 Removing Duplicates and Eulerian Polynomials . . . 27
4.6 Allowing ď-relations . . . 30
5 Discussion and Conclusion 32 5.1 Our Results . . . 32
5.2 Branching Before CNF . . . 33
5.3 Constructing Fewer Strict Total Orders And CSP(tău_k) . . . 33
List of Figures
List of Tables
1.1 Summary of the upper bounds achieved through pure enumeration . . . 2
1.2 Summary of the upper bounds achieved in this thesis . . . 3
3.1 The six assignments satisfying transitivity. . . 11
3.2 The thirteen assignments satisfying transitivity. . . 18
3.3 Translation table for W2SAT . . . 18
4.1 The first five n-anacci constants with four decimals precision . . . 23
1
Introduction
Informally, the constraint satisfaction problem (CSP) is the decision problem of deciding if, for a given set of variables and constraints, the variables can be assigned values so that all constraints are satisfied. CSPs are powerful enough to be used to model a multitude of prob-lems ranging from Sudoku, k-coloring and Boolean Satisfiability Problem (SAT) to schedul-ing, computer linguistics and automated planning problems, to mention a few. Thus, im-provements of CSP algorithms may lead to improved algorithms for relevant applications. In this thesis we are interested in how to solve CSPs only containing constrains built from relations that has a first-order definition in(Q, ă), also known as temporal CSPs, and the time complexity for solving such problems. This introduction introduces the constraint satis-faction problem and presents our results.
1.1
Constraint Satisfaction
Formally we define a CSP instance as follows: letΓ be a set of relations with domain D. An instance I = (V, C)of the CSP overΓ (CSP(Γ)) consists of a finite set of variables V and a finite set of constraints C where each constraint is an application of a relation R PΓ to a subset of V. We say that I is satisfied by an assignment f : V Ñ D if f satisfies each constraint in C. An example of a CSP instance is the problem of having multiple cars arrive at the same time to an intersection. Imagine that we have four cars and a set of four variables correspond-ing to these four cars: red, green, blue and yellow. We know that the car yellow is behind the car blue, so the car blue must go before the car yellow. Further we know that green must give way to blue and yellow while blue must give way to red. We can model these constraints as t(blue ă yellow),(blue ă green),(yellow ă green),(red ă blue)u. The question is now if this instance is solvable, and if so in which order does the cars go through the intersection? This example is of course solvable by red ă blue ă yellow ă green. But if red also had to give way to green, we would have an unsatisfiable instance.
1.2
Temporal CSPs
The CSPs that we study in this thesis are based on total orders and this class of CSPs is called temporal constraint satisfaction problems (tCSP). For a more elaborate background
1.3. Our Results
Table 1.1: Summary of the upper bounds achieved through pure enumeration, where n is the number of variables in an instance.
CSP(tău_k) CSP(tă,=, ‰u_k) CSP(tă,=, ďu_k) CSP(tă,=, ď, ‰u_k)
O˚((0.3679n)n) O˚((0.5307n)n) O˚((0.5307n)n) O˚((0.5307n)n)
of tCSPs, see for example Fisher et al. [9]. We will be interested in tCSP instances based on the basic binary relationsB = tă,=, ‰, ďu where the domain D is the rational numbers and where each constraint is a logical disjunction of relations fromB. A simple example of such a constraint is(x ă y _ z=w _ u ď v), where _ denotes logical disjunction. For a tCSP instance I= (V, C)to be satisfied by f : V Ñ D, each constraint in C must contain at least one basic relation that is satisfied by f . We let CSP(B_k)denote the set of tCSP instances where
each disjunction contains at most k basic relations — clearly, the constraint above contains three basic relations, and the car example can be viewed as a CSP(B_1)instance.
A well-known class of tCSPs is Allen’s Interval Algebra (IA) [2]. In IA the goal is not to decide relations between points, but instead between intervals. Constraints are then also lim-ited to only contain relations between two intervals. IA is closely related to CSP(B_k). As a
matter of fact, any IA instance I can be represented as an logically equivalent CSP(tă,=u_8)
or CSP(tă,=, ‰, ďu_4)instance I2. This can be done intuitively by representing each interval
x in I with two variables x´and x+in I
2, where x´ is the starting point of x and x+ is the
end point. The constraints can then be defined in a natural way1.
It is well-known that tCSP problems are in the complexity class NP and that solving an arbitrary problem CSP(Γ)may require non-polynomial time, assuming P‰NP. Here, P is the class of problems which can be solved in polynomial time while NP is the class of problems where a solution can be verified in polynomial time. Bodirsky and Kára have made a thor-ough study of the computational complexity of tCSPs and proved that CSP(Γ)is either in P or is NP-complete wheneverΓ is finite and first-order definable inB[6]. Their results imply that CSP(B_1)is in P and CSP(B_k)is NP-complete when k ě 2. From the results of Jonsson
and Lagerkvist [15] we know that CSP(B_k), k ě 4 cannot be solved in O(cn)time for any c
if the randomized exponential-time hypothesis [7] holds. The known upper bound is in turn given by Stockman [21] presenting an enumeration algorithm. The known upper bounds for CSP(B_k)are presented in Table 1.1.
1.3
Our Results
An interesting class of CSPs are satisfiability problems (SAT problems). The SAT-class is the problem class where the variables can only be assigned one of two values, normally true and f alse, or 1 and 0, and literals are either a single variable or a negation of a variable. For general SAT problems there are no known algorithm with an upper bound on run-time in O(cn¨ ||I||)
for any c ă 2. Here, n is the number of variables in the instance and ||I|| is the number of bits needed to represent the instance itself. There are, however, many sub-classes of SAT where faster algorithms are known, for example k-SAT and HORNSAT [19, 10], where HORNSAT is known to be in P.
Compiling, i.e. translating, CSPs to SAT is a well known approach for solving many different classes of CSPs both in practice and in theory. In theory, compilation to SAT is often used to prove complexity or correctness results. One prominent example in the tCSP literature is that of Nebel and Bürckert [17] where SAT compilation is used to prove that the ORD-Horn subclass of IA is indeed in P. Huang showed that when compiling an arbitrary IA instance I to the SAT instance ISAT, proving that ISAT is satisfiable can be done at least as
efficient as for I. Further, Huang showed that there are cases where native search on I requires
1To achieve a proper CSP(tă,=u_8)or CSP(tă,=, ‰, ďu_4) instance some simplifications might also be needed.
1.3. Our Results
Table 1.2: Summary of the upper bounds achieved in this thesis, where n is the number of variables in an instance.
k CSP(tău_k) CSP(tă,=, ‰u_k) CSP(tă,=, ďu_k) CSP(tă,=, ď, ‰u_k) 2 O˚((0.1839n)n) O˚((0.3679n)n) O˚((0.2654n)n) O˚((0.4725n)n) 3 N/A O˚((0.4725n)n) O˚((0.5067n)n) O˚((0.5067n)n) 4 N/A O˚((0.5067n)n) O˚((0.5200n)n) O˚((0.5200n)n) 5 N/A O˚((0.5200n)n) O˚((0.5257n)n) O˚((0.5257n)n)
8 N/A O˚((0.5307n)n) O˚((0.5307n)n) O˚((0.5307n)n)
exponential time to prove or disprove satisfiability, but ISAT requires polynomial time [12].
When compiling to SAT an additional benefit is that it allows the usage of optimized SAT-solvers. It has been shown by both Armando et al. [3] and by Pham et al. [19] that compiling to SAT and using modern SAT solvers is indeed often faster than native solvers in practice.
In this thesis we are interested in the run-time performance from compiling problems to SAT. More precisely how can we compile an arbitrary CSP(B_k)instance I = (V, C) to
SAT and gain a concrete super-polynomial reduction in time complexity? Considering the results for IA and its close relation to CSP(B_k)it is not a far-fetched idea to assume that
compilation to SAT can be a powerful tool for CSP(B_k), too. Naive compilation to SAT
tends to lead to one of two cases: In the first case where relations in V are handled as Boolean variables, an O(|V|2) increase in the number of variables occurs. The second case instead uses the Boolean variables for representing an assignment to V. This case only leads to an O(|V| log |V|)increase in the number of variables. Neither of these ideas are sufficient as they are both out-performed by known enumeration methods. Considering that the best known methods for CSP(B_k)is pure enumeration of orderings for V, it is natural to wonder if and
how we can combine enumeration with SAT compilation for improved complexity figures. In this thesis we will see how this can be done.
In Chapter 3 we start by analysing the simpler classes of CSP(tău_2) and CSP(tă,=, ďu_2). Through compilation to 2-SAT we prove how an arbitrary instance I = (V, C)can be solved faster than pure enumeration of orderings of V. The upper bound on these complexities are O˚((0.1839|V|)|V|)and O˚((0.2654|V|)|V|)respectively. This is to
be compared to the complexities presented in Table 1.1, showing a clear improvement. We continue in Chapter 4 by analysing the broader classes of CSP(tă,=, ‰u_k) and
CSP(tă,=, ‰, ďu_k). First, we introduce a previously unstudied subclass of SAT, that we
call k+-SAT, and we show how to solve k+-SAT instances faster than in O(2n)time, where n is the number of variables. We then continue by analysing how enumeration can be combined with compilation to k+-SAT to create an algorithm for CSP(tă,=, ‰u_k). Finally we extend
the algorithm for CSP(tă,=, ‰u_k)to CSP(tă,=, ‰, ďu_k). The complexities for these two
algorithms can be seen in Table 1.2 and can again be compared to those of Table 1.1, show-ing an improvement. The improvement decreases when increases k. However, even a small decrease of the constant c in a function(cn)nyields significant improvements for large n.
Previous results by Jonsson and Lagerkvist showed that every finite constraint languageΓ first-order definable over(Q; ă)can in polynomial time be reduced to CSP(tă,=, ‰, ďu_k)
where k is dependant on Γ [14]. Combined with the result of this thesis this implies that every CSP(Γ) is solvable in O˚((( 1
e log 2´ ek)n)n)time where n is the number of variables
and eką0 is dependant on k. Hence, for all such languages we beat pure enumeration which
is doable in O˚(( n
2
Preliminaries
In this chapter we will formally introduce and define the common notations that are used in this thesis.
To measure and compare complexity in this thesis we will use the big O notation, or Ordo notation. Ordo describes the asymptotic behaviour of functions as the input grows towards infinity1. There are multiple versions of the Ordo notation, but we are only interested in three of them.
Definition 2.1. Let f be a real valued function and g a real valued function, both defined on some unbounded subset of the real positive numbers, such that g(x)is strictly positive for all large enough values of x. Then it holds that
• f(x)PO(g(x))if there exists a c ą 0 and a N such that | f(x)| ďcg(x)for all x ě N, • f(x)Po(g(x))if for every c ą 0 there is a N such that | f(x)| ďcg(x)for all x ě N, and • f(x)¨2o(x) PO˚(f(x)).
Example 2.1. Smaller examples of Ordo notation usage. • 2x2+100x P O(x2), • 2x P o(x1.5), • 2n/ log nPo(2n), • n2n! P O˚(n!), and • o(f(x))ĂO(f(x))ĂO˚(f(x))
2.1
Propositional Logic
Propositional logic deals with evaluating logical formulas. A variable in propositional logic can only be assigned one of the two values true or f alse. We define a literal as an atomic formula, x or x, where x is a variable. There will be four operators used in this thesis: the
2.1. Propositional Logic
and operator ^, the or operator _, the implication operator Ñ and the negation operator . We define a formula inductively using five cases:
• A literal is a formula.
• If F is a formula, then F is a formula.
• If F and G are formulas, then F ^ G is a formula. • If F and G are formulas, then F _ G is a formula. • If F and G are formulas, then F Ñ G is a formula.
A formula is in conjunctive normal form (CNF) if it is a conjunction of one or more clauses, where a clause is a disjunction of literals. In CNF only three types of operators are allowed: ^, _ and .
A formula is in disjunctive normal form (DNF) if it is a disjunction of one or more conjunc-tive clauses, where a conjuncconjunc-tive clause is a conjunction of literals. Similarly to CNF, DNF does only allow the three operators ^, _ and .
We will be interested in evaluating truth values of propositional formulas. In other words we are interested in knowing if there for some formula F, only containing variables from some set V, exists a function f : V Ñ ttrue, f alseu defined in such a way that applying f to F evaluates to true, i.e. f satisfies F. We call a function f satisfying a formula F a model of F.
For propositional formulas we have two variants of equivalence: two propositional for-mulas F and G are said to be logically equivalent if all models of F are models of G and if all models of G are models of F. Two propositional formulas F and G are said to be satisfiable equivalent or equisatisfiable if F can be satisfied if and only if G can be satisfied.
We introduce four simple rules for logical equivalence between formulas: • ((x ^ y)_z) ðñ (x _ z)^(y _ z),
• (x Ñ y) ðñ ( x _ y), • (x ^ y) ðñ ( x _ y), and • ( x) ðñ x.
Our use of these rules will include transforming arbitrary formulas into CNF.
Example 2.2. FCNF = (x _ z)^(x _ w)^(y _ z)^(y _ w)^(v _ u) is one logically
equivalent CNF of the propositional formula F = ((x ^ y)_(z ^ w))^ (v Ñ u). Letting x=y=v=true is one way to satisfy F and FCNF.
Converting an arbitrary propositional formula to CNF, without increasing the number of variables, can lead to an exponential increase in the number of clauses. Fortunately, any formula we are converting into CNF in this thesis will have a sufficiently simple structure to only lead to a polynomial increase.
Example 2.3. Let f be a DNF formula such that
f = ((x1,1^x1,2^... ^ x1,i)_(x2,1^x2,2^... ^ x2,j)_... _(xk,1^xk,2^... ^ xk,l)).
Now f can be converted into a logically equivalent CNF formula fCNF. Each clause in fCNF
will contain exactly one variable from each conjunctive clause in f , and there will be one such clause for each possible combination.
fCNF =((x1,1_x2,1_... _ xk,1)^(x1,2_x2,1_... _ xk,1)^... ^(x1,i_x2,1_... _ xk,1)^
(x1,1_x2,2_... _ xk,1)^(x1,2_x2,2_... _ xk,1)^... ^(x1,i_x2,2_... _ xk,1)^...^
2.2. Constraint Satisfaction Problems
As we can see, fCNFquickly grows very large when f contains many conjunctive clauses or
if the conjunctive clauses themselves are large.
In this thesis we will only handle conversions of DNF formulas where the number of con-junctive clauses is limited by some integer k. For such formulas the conversion can be done in polynomial time by recursion, and the size of the resulting CNF formula is also polynomialy bounded. The bound is in fact nk, where n is the number of unique variables in the formula, as each variable can be selected once from each conjunctive clause, and there are at most k conjunctive clauses.
Example 2.4. Formulas that we in this thesis want to convert to CNF are all of
the form F = (f1^ f2 ^... ^ fn) where f1, ..., fn are all DNF formulas with a
con-junctive clause size limited by some k. A more concrete example of one such for-mula is G= (((x1^x2^x3)_(x4^x5))^(x6_x7))where((x1^x2^x3)_(x4^x5))and
(x6_x7)are DNF formulas. The logical equivalent of G is
GCNF = ((x1_x4)^(x1_x5)^(x2_x4)^(x2_x5)^(x3_x4)^(x3_x5)^(x6_x7)).
For F the equivalent CNF is FCNF = (f1,CNF^f2,CNF^... ^ fn,CNF), where fi,CNFif the
log-ically equivalent CNF formula of fi. As converting each fito fCNF is polynomial, then so is
converting F to FCNF.
For simplicity and to save space we will often refer to the non-CNF formulas instead of the CNF formulas as they are logically equivalent.
The exponential time hypothesis, or ETH for short, is a hypothesis by Impagliazzo and Paturi [13] about the complexity of deciding if an arbitrary propositional formula in CNF and where no clause contains more than three literals can be satisfied. The problem in question is also known as 3-SAT. Let s3be the infinum of the real numbers δ for which 3-SAT can be solved
in time O(2δn)time by a deterministic algorithm, where n is the number of variables in the
given 3-SAT instance. The exponential time hypothesis is the conjecture that s3ą0.
One can extend propositional logic to handle formulas built from relations with a first-order definition in(Q, ă). Here we define a literal as a relation x „ y, where x and y are variables and „ is one of the four relations less than ă, equal =, less than or equal ď and not equal ‰. A variable can take any value fromQ and a literal x „ y is satisfied by a function
f : V ÑQ, x, y P V if f(x)„ f(y). The other definitions remain the same.
Example 2.5. Consider
F= ((x1ăx2_x1=x4)^(x2ăx3_x1‰x2_x4=x3)^(x4‰x3_x1ăx2)).
The formula F is a propositional formula built from relations and is satisfied by x1 = 1,
x2=2, x3=3 and x4=0.
2.2
Constraint Satisfaction Problems
We will now formally define the constraint satisfaction problems that we analyse in this the-sis.
Definition 2.2. LetΓ be a set of finitary relations on some set D of values. The constraint satisfaction problem overΓ (CSP(Γ)) is defined as follows:
Instance: A set V of variables and a set C of constraints of the form R(v1, ..., vk)where k is
the arity of R, v1, ..., vkPV and R PΓ.
Question: Is there a function f : V Ñ D for which (f(v1), ..., f(vk)) P R for every
2.3. Orders
Definition 2.3. Let D be a set of values and let B = tB1, ..., Bmudenote a finite set of
rela-tions over D, i.e. Bi Ď Dj for some j ě 1. Let B_ω denote the set of relations defined by
logical disjunctions over B. This means that B_ωcontains every p-ary relation, R, for which
R(x1, ..., xp)”B1(x1)_... _ Bt(xt), where x1, ..., xtare sequences of variables from tx1, ..., xpu for which the length of xjequals the arity of Bj, and B1, ..., BtPB. We refer to B1(x1), ..., Bt(xt)
as the disjuncts of R. We assume, without loss of generality, that no disjunct occurs more than once in a disjunction. We define B_k, k ě 1, as the subset of B_ω where each relation is
defined by a disjunction of length at most k.
These types of relations are known as bounded disjunction relations and languages that only contains these relations as bounded disjunction languages.
Example 2.6. Let B = tău, then B_2contains relations such as ta ă b _ c ă du, but not
ta ă b _ c ă d _ a ă du as it contains three disjunctions.
2.3
Orders
A large part of this thesis will contain discussions about different types of orders, their con-nections and how they can be used to solve tCSPs. For this reason, definitions of all types of orders used will be provided here, together with brief discussions about their properties.
Definition 2.4. A pair P= (S, ăP), where S is a set and ăPa binary relation on S, is a strict
partial order if it satisfies the following properties:
• For any x P S, then x ăPx does not hold. (irreflexivity)
• For any x, y, z P S, if x ăPy ^ y ăPz then x ăP z. (transitivity)
• For any x, y P S, if x ăPy then not y ăPx. (asymmetry)
Strict partial orders are the most general case of orderings considered in this thesis and can be used to describe all other types of orders that we consider.
Definition 2.5. A strict partial order P1 = (S, ă1) is compatible with a strict partial order
P2= (S, ă2)if ă2Ďă1.
Definition 2.6. For a strict partial order P= (V, ăP)the index of an element x P V in P is the
number of elements y P V for which y ăP x.
The second type of ordering is strict total orders:
Definition 2.7. A pair T = (S, ăT), where S is a set and ăTa binary relation on S, is a strict
total order if it satisfies the following properties: • T is a strict partial order.
• For any x, y P S, either x ăT y or y ăT x. (connexity)
For simplicity we will often forgo our formal notation of strict total orders. Instead of saying(tx1, x2, ..., xnu, t(xi, xj)|@0ăiăjďnu), we will say x1 ăT x2 ăT ... ăT xn and consider
them equivalent.
An interesting property of strict total orders is that they closely resemble permuta-tions, and that strict total order and permutations can trivially be converted to each other. Given that there are |S|! different permutations of the set S, there are also |S|! different strict total orders T = (S, ăT). Using Stirling’s approximation [8] shows that
O˚(|S|!)ĎO˚((|S|
2.3. Orders
Example 2.7. Take the set of variables ta, b, c, du. Now the permutation b, c, a, d have a related total order of the form b ă c ă a ă d. Similarly the strict total order d ă c ă a ă b have the related permutation d, c, a, b.
The third type of ordering is strict weak orders:
Definition 2.8. A pair W = (S, ăW), where S is a set and ăWis a binary relation on S, is a
strict weak order if it satisfies the following properties: • W is a strict partial order.
• For all x, y, z P S, if x is incomparable with y and y is incomparable with z then x is incomparable with z. (transitivity of incomparability)
We will denote incompatibility between two variables x and y for the strict weak order W with x [Wy.
Similar to strict total orders, we will at times use a simpler notation for strict weak orders. In this simpler notation we use(x1, x2, ..., xn)to express groups of incomparable elements. Example 2.8. Consider the strict weak order W= (ta, b, c, d, e, f u, ăW)where a ăWb, a ăW c,
c ăW d, d ăW e and d ăW f , but ăWdoes not contain any relations between b and c, nor
be-tween e and f . The elements b and c are now incomparable and e and f are incomparable, too. We write W as a ăW (b, c)ăWd ăW(e, f)in our simpler form. A graphical representation of
the strict weak order W is given in figure 2.1.
a
b,c
d
e,f
Figure 2.1: Graphical representation of Example 2.8.
The integer sequence of the number of different strict weak orders W = (S, ăW)
for increasing sizes of S is known as the Ordered Bell Numbers (OBN) (see e.g. [16]). We will denote the nth number in this sequence as OBN(n). Using Barthelemy’s approximation [5] combined with Stirling’s approximation [8], we see that O˚(OBN(|S|)ĎO˚( |S|!
3
Disjunctions of at most size two
In this chapter we will study the two problems of CSP(tău_2)and CSP(tă,=, ďu_2). Since these two special cases of CSP(B)are quite restricted, we are able to use methods that do not work for more complex problems. We will show that CSP(tău_2)and CSP(tă,=, ďu_2)can in fact be solved significantly faster than previously known algorithms based on enumeration of strict total orders, and strict weak orders, respectively.
3.1
CSPs Limited to ă-relations
In this section we will introduce an algorithm for solving CSP(tău_2). We start by analysing the relation between strict orders and ’yes’-instances of CSP(tău_k).
Definition 3.1. A strict partial order P= (S, ăP)satisfies a clause c in some set of constraints
C, if there exists a literal x ă y P c and x ăP y. A strict partial order P = (S, ăP)satisfies a
CSP(tău_k)instance I= (V, C)if P satisfies all clauses in C.
Lemma 3.1. An arbitrary CSP(tău_k)instance I is solvable if and only if there exists a strict total order T satisfying I.
Proof. If a strict total order T = (V, ăT) satisfies I, then take the function
f : V Ñ t0, ..., |V| ´ 1u such that for all x P V, f(x)equals the index of x in T. The func-tion f will give a satisfying assignment of I since each literal xj ă xk that T satisfies in C is
also satisfied by f(xj)ă f(xk).
If I is a ’yes’-instance it is known that there is a satisfying assignment of V where all vari-ables are given unique values [15, Theorem 12]. Let f : V ÑQ denote such an assignment. Define the structure T = (V, ăT) such that x ăT y holds if and only if f(x) ă f(y). It is
obvious that T is a strict total order.
Transforming to SAT
The basis for the main algorithm of this section is that an arbitrary CSP(tău_2) instance I= (V, C)can be transformed into a SAT instance R, by viewing each relation, and in exten-sion every constraint, x ă y, as a Boolean variable Bx,y. In this thesis we will call all such
functions, taking an instance I and outputting another instance I1, or a set of instances S I, for
3.1. CSPs Limited to ă-relations
transforms. We will start by a naive transform we call Tnaive: Each pair of distinct variables
x, y P V will be assigned the Boolean variable Bx,y. Having Bx,yset to true implies x ă y in a
model of I. Similarly having Bx,yset to f alse implies (x ă y)in a model of I. The transform
Tnaiveconstructs R in such a way that for each clause(x ă y _ z ă w)in C, there will be a
clause(Bx,y_Bz,w)in R. For simplicity we assume that all clauses of size one, i.e. (x ă y),
are padded to size two, i.e.(x ă y _ x ă y).
The transformed instance Tnaive(I)will be a ’yes’-instance if I is, but the opposite is not
necessarily true. Consider the following example:
Example 3.1. The instance I = (tx, y, z, wu, t(x ă y _ x ă z)^(y ă z _ y ă x)^(z ă x)u)
will be transformed to the SAT formula R= ((Bx,y_Bx,z)^(By,z_By,x)^(Bz,x)). Setting all
variables to true satisfies R, but I is a ’no’-instance.
Algorithm 3.1Transform CSP(tău_2)to SAT
1: function TSAT(I= (V, C)) 2: RCÐ H
3: foreach clause(x ă y _ z ă w)in C do
4: RCÐRC^(Bx,y_Bz,w)
5: end for
6: RconnexityÐ H
7: foreach pair of distinct variables x, y P V do
8: RconnexityÐRconnexity^(Bx,y_By,x)^( Bx,y_ By,x)
9: end for
10: RtransitivityÐ H
11: foreach triple of distinct variables x, y, z P V do
12: RtransitivityÐRtransitivity^(By,x_Bz,y_Bx,z)
13: end for
14: return RC^Rconnexity^Rtransitivity 15: end function
There are two problems with Tnaive: the first is that it allows Bx,y and By,xto
simultane-ously be true or f alse. This implies that x ă y and y ă x can be true in I, i.e. a lack of asymmetry. Second, Tnaiveallows(Bx,y^By,z^Bz,x)to be true, implying that x ă y ă z ă x
in I, i.e. a lack of transitivity. To fix these problems we introduce a second transform TSAT,
that takes a CSP(tău_2)instance and produces a SAT instance that is a ’yes’-instance if and only if I is. Our transform TSAT will just as Tnaivehave a Boolean variable for each pair of
distinct variables x, y P V. The formula produced by TSAT consists of three parts. These
three parts, RC, Rconnexityand Rtransitivity, are given by line 2-5, 6-9 and 10-12 in Algorithm 3.1
respectively. These three parts of R will all be satisfied if and only if I are ’yes’-instances:
Lemma 3.2. For an arbitrary CSP(tău_2)instance I, TSAT(I)is a ’yes’-instance if and only if I is
a ’yes’-instance.
Proof. Let R = TSAT(I). We start by showing that if I is a instance, then R is a
’yes’-instance. From Lemma 3.1 we know that there exists a strict total order T= (V, ăT)satisfying
I. Take a function f : B Ñ ttrue, f alseu where B is the set of variables Bx,yfor all pairs of
distinct variables x, y P V. Define f such that f(Bx,y) = true if x ăT y and f(Bx,y) = f alse
otherwise. Each clause(x ă y _ z ă w)in C must be satisfied by T. This means that either x ăT y or z ăT w. We know that TSAT transforms(x ă y _ z ă w)to(Bx,y_Bz,w). Now
if x ăT y then f(Bx,y) = true and f satisfies (Bx,y_Bz,w). If y ăT x and z ăT w then
f(Bz,w) = true and thereby f satisfies(Bx,y_Bz,w)too. This is true for all clauses in C and
consequently for all clauses in RCsince for each clause(Bx,y_Bz,w)in RCthere exists a clause
3.1. CSPs Limited to ă-relations
Table 3.1: The six assignments satisfying transitivity.
B ăT T
Bx,y=By,z=Bx,z=true, By,x=Bz,y=Bz,x= f alse (x, y),(y, z),(x, z) (x ăTy ăT z)
Bx,z=Bz,y=Bx,y=true, Bz,x=By,z=By,x= f alse (x, z),(z, y),(x, y) (x ăTz ăT y)
By,x=Bx,z=By,z=true, Bx,y=Bz,x=Bz,y= f alse (y, x),(x, z),(y, z) (y ăTx ăT z)
By,z=Bz,x=By,x=true, Bz,y=Bx,z=Bx,y= f alse (y, z),(z, x),(y, x) (y ăTz ăT x)
Bz,x=Bx,y=Bz,y=true, Bx,z=By,x=By,z= f alse (z, x),(x, y),(z, y) (z ăTx ăT y)
Bz,y=By,x=Bz,x=true, By,z=Bx,y=Bx,z= f alse (z, y),(y, x),(z, x) (z ăTy ăT x)
We know that connexity holds for T and Rconnexitycontains the clauses(Bx,y_By,x)and
( Bx,y_ By,x)for all distinct variables x, y P V. Connexity means that for every pair of
distinct variables x, y P V, either x ăTy and (y ăT x), or y ăT x and (x ăT y). For f this
means that if x ăT y then f(Bx,y) = true and f(By,x) = f alse, which satisfies(Bx,y_By,x)
and( Bx,y_ By,x). If instead y ăT x then f(Bx,y) = f alse and f(By,x) = true, which also
satisfies(Bx,y_By,x) and( Bx,y_ By,x). Since Rconnexity contains clauses for all pairs of
distinct variables x, y P V, and connexity holds for all pairs of distinct variables x, y P V, Rconnexityis satisfied if T is a strict total order.
We now show that T has the transitivity property. This means that for each triple of distinct variables x, y, z P V, if x ăT y and y ăT z, then x ăTz.
This can be written as (x ăT y ^ y ăTz)Ñx ăTz which is logically equivalent to
( (x ăTy)_ (y ăTz)_x ăTz)in CNF. Using connexity this can be further rewritten as
(y ăT x _ z ăT y _ x ăT z). We know that for each triple of distinct variables x, y, z P V
there exists a clause(By,x_Bz,y_Bx,z)in Rtransitivity. If y ăT x then f(By,x) =true, if z ăT y
then f(Bz,y) = true and if x ăT z then f(Bx,z) = true. In either case (By,x_Bz,y_Bx,z)is
satisfied. Since Rtransitivitycontains one clause for each triple of distinct variables x, y, z P V,
and transitivity holds for each triple, Rtransitivityis satisfied if T is a strict total order.
We now know that f satisfies RC, Rconnexity and Rtransitivity. Since R equals
RC^Rconnexity^Rtransitivity, f satisfies R, and thereby R must be a ’yes’-instance.
We continue by proving that if R is a ’yes’-instance then I is a ’yes’-instance. Take a model of R and let B+be the set of variables set to true in that model. Let ăTbe the binary relation on
V with x ăTy if and only if Bx,yPB+. Consider the pair T= (V, ăT). Now for T to be a strict
total order, connexity, asymmetry and transitivity must hold. We will start by proving that connexity and asymmetry holds: for every pair of distinct variables x, y P V, there exists a pair of clauses(Bx,y_By,x)and( Bx,y_ By,x)in Rconnexity. This pair of clauses are satisfied
by either Bx,y = true and By,x = f alse, or Bx,y = f alse and By,x = true. For the case of
Bx,y=true and By,x= f alse, Bx,yis in B+and x ăTy is true while y ăTx is not. For the case
of Bx,y= f alse and By,x=true, By,xis in B+and y ăTx is true while x ăTy is not. Since this
is true for all pairs of distinct variables x, y P V, connexity and asymmetry holds for T. We continue with transitivity. For every triple of distinct variables x, y, z P V there exists a clause (By,x_Bz,y_Bx,z) in Rtransitivity by line 12 in Algorithm 3.1. For the same triple
of x, y and z there also exists five other relevant clauses in Rtransitivity: (Bz,x_By,z_Bx,y),
(Bx,y_Bz,x_By,z),(Bz,y_Bx,z_By,x),(Bx,z_By,x_Bz,y)and(By,z_Bx,y_Bz,x)since there
are five other permutations of x, y and z. This set of clauses is directly affected by the assign-ment of the six variables Bx,y, By,x, Bx,z, Bz,x, By,zand Bz,y. Combined with Rconnexity, the six
clauses are satisfied by six different assignments of this set of six variables. These six different assignments also gives six different ăTand six different options for T. These six assignments,
their corresponding ăT and corresponding T, are all presented in Table 3.1. In Table 3.1, we
can see that transitivity holds for each of these assignments. Since Rtransitivitycontains these
clauses for each triple of distinct variables x, y, z P V, transitivity will be enforced in T. We have now proved that T has the connexity, asymmetry and transitivity properties. Consequently T is a strict total order.
3.1. CSPs Limited to ă-relations
For every clause(x ă y _ z ă w)in C there exists a clause(Bx,y_Bz,w)in RC. To be a
model of R either Bx,y = true or Bz,w = true must hold. If Bx,y = true then Bx,yin B+and
thereby x ăT y and T satisfies(x ă y _ z ă w). Similarly, if Bz,w is in B+ then T satisfies
(x ă y _ z ă w). Since this is true for all clauses in C, T satisfies all clauses in C.
Since T is a strict total order and it satisfies all clauses in C, T satisfies I via Lemma 3.1, which concludes the proof.
Now that we know that I and R = TSAT(I)are equisatisfiable let us briefly discuss the
size of R: The subformulas RCand Rconnexitydo both contain two literals in each clause. The
subformula Rtransitivitycontains three literals in each clause. The number of variables in R is
n2´n, one for each pair of distinct variables x, y P V. Since 3-SAT cannot be solved faster than O(cn)for some c ą 1 under ETH [13], solving R using an algorithm for 3-SAT will give a complexity of O(cn2), which is not good enough.
Towards
2-SAT
The main disadvantages of TSATis the clause size of Rtransitivityand the quadratic increase of
the number of variables. If we can reduce the number of variables or reduce the size of the clauses in Rtransitivity, we can do better. The latter will be the approach of our choice.
If we know the relation between two variables x and y, we can add this knowledge to the transform. For example if x ă y then Bx,y = true and By,x = f alse, and if y ă x then
Bx,y= f alse and By,x=true. Each clause in Rtransitivitycontains three literals of three different
variables of the form(By,x_Bz,y_Bx,z). Since each pair of distinct variables v, u P tx, y, zu,
occurs once as either Bv,u or Bu,v in such a clause, knowing the relation between any two
variables of x, y and z will either directly prove the clause true, or prove a literal false. This effectively reduces the size of such a clause to two. If this can be done for all clauses of Rtransitivitythen R will become a 2-SAT instance. An easy way to achieve this is to enumerate
all strict total orders T= (V, ă), since this would order all pairs x, y P V. However, we can do better by instead taking two disjoint sets V1YV2=V and two strict total orders T1= (V1, ă1)
and T2 = (V2, ă2). For each triple of distinct variables x, y, z P V at least two variables will
be in V1or at least two will be in V2, and hence we have at least one known relation in each
triple. Taking more than two strict total orders would allow cases where x P V1, y P V2and
z P V3, and thereby there would still be clauses remaining of size three.
Example 3.2. Consider the two strict total orders T1 = (tx, yu, t(x, y)u)and T2 = (tzu, H)
and all transitivity clauses for x, y, z:
Rtransitivity=((Bx,y_By,z_Bx,z)^(Bx,z_Bz,y_Bx,y)^(By,x_Bx,z_By,z)^
(By,z_Bz,x_By,x)^(Bz,x_Bx,y_Bz,y)^(Bz,y_By,x_Bz,x)).
Given our T1and T2, then Bx,y=true and By,x= f alse. Our formula Rtransitivitycan therefore
be reduced to((Bx,z_By,z)^(By,z_Bz,x)^(Bz,y_Bz,x)), which only contains clauses of size
two.
We introduce another transform T2SATtaking some instance I= (V, C)and two strict total
orders, T1= (V1, ă1)and T2 = (V2, ă2), where V1and V2are disjoint sets and V1YV2 =V.
Out transform T2SATnow transforms I to a 2-SAT instance. This is done by treating each Bx,y
as true, if x ă1y or x ă2 y, and similarly Bx,yas f alse, if y ă1 x or y ă2 x. In Algorithm 3.2
we can see how T2SATdoes these two things: it replaces literals at line 4 and 8, and replaces
whole clauses at line 5 and 9.
Lemma 3.3. For an arbitrary CSP(tău_2) instance I = (V, C) and two strict total orders T1= (V1, ă1) and T2 = (V2, ă2), with V1YV2 = V and V1XV2 = H, T2SAT(I, T1, T2) is a
3.1. CSPs Limited to ă-relations
Algorithm 3.2Transform CSP(tău_2)to 2-SAT
1: function T2SAT(I= (V, C), T1= (V1, ă1), T2= (V2, ă2)) 2: R2ÐTSAT(I)
3: foreach x ă1y do
4: Replace all occurrences of By,xin R2with f alse 5: Replace all clauses in R2containing Bx,ywith true
6: end for
7: foreach x ă2y do
8: Replace all occurrences of By,xin R2with f alse 9: Replace all clauses in R2containing Bx,ywith true
10: end for
11: return R2
12: end function
’yes’-instance if and only if I is satisfied by a strict total order T = (V, ăT)compatible with both T1
and T2.
Proof. Let R2= T2SAT(I, T1, T2)and R=TSAT(I). We start by proving that if there is a strict
total order T compatible with T1 and T2 and satisfying I, then R2 is a ’yes’-instance. The
literals T2SAT removes from TSAT(I)are all either of the form Bx,ywhere y ă1 x or y ă2 x,
or Bx,ywhere x ă1 y or x ă2y. Take the function f such that f(Bx,y) =true if x ăT y and
f(Bx,y) = f alse if y ăT x. We know from Lemma 3.2 that f will be a model of R. The strict
total order T is compatible with T1and T2so ă1 Y ă2 Ď ăT. This means that for any pair
x, y P V such that x ă1y then f(Bx,y) =true and f(By,x) = f alse, and similarly for any pair
such that x ă2 y, it holds that f(Bx,y) = true and f(By,x) = f alse. As a consequence T2SAT
will only remove literals not satisfied by f . Each clause in R must contain at least one literal satisfied by f , and since no such literal is removed by T2SAT, at least one such literal must
remain for each clause in R2. Furthermore, T2SAT does not add any clauses to R2that does
not already exist in R. Since f satisfies all clauses in R and all clauses in R2exists in R, f
must also satisfy R2. Therefore if there is a strict total order T compatible with T1and T2and
satisfying I, then R2is a ’yes’-instance.
We continue by showing that if R2is a ’yes’-instance then R is a ’yes’-instance. Let a
func-tion f satisfy R2and be such that if x ă1y or x ă2y then f(Bx,y) =true and f(By,x) = f alse.
Such a satisfying function exists if R2is a ’yes’-instance since no variables Bx,yor By,xoccur
anywhere in R2if x ă1 y or x ă2 y. For each clause c2in R2, there will be a unique
coun-terpart c in R. Either c and c2are equal or c contains one or two literals that c2does not. So
every literal in c2will be in c. Since f satisfies c2it will also satisfy c. Every clause c in R not
having a unique counterpart in R2will by T2SAThave been replaced by true if and only if c
contains a literal Bx,yor By,xwhere x ă1y or x ă2y. Such a clause will also be satisfied by
f given our definition. So f satisfies R. Therefore R is a ’yes’-instance if R2is, and since R is
correct for I, I is a ’yes’-instance if R2is.
The Full Algorithm
Two minor questions remain before we can present the full algorithm: the existence of T1and
T2given an order T, and how to find them. We start with their existence.
Lemma 3.4. For any strict total order T= (V, ă)and a set VsubĎV there exists a strict total order
Tsub= (Vsub, ăsub)such that T is compatible with Tsub.
Proof. Let ăsub= t(x, y) PVsub2 |(x, y) P ău. Our strict total order T is compatible with Tsub
3.1. CSPs Limited to ă-relations
Algorithm 3.3Algorithm for CSP(tău_2)
1: functionMAIN(I = (V, C))
2: Choose two disjoint sets V1and V2, with V1YV2=V and 0 ď |V1| ´ |V2| ď1. 3: foreach strict total order T1= (V1, ă1)do
4: foreach strict total order T2= (V2, ă2)do 5: R2ÐT2SAT(I, T1, T2)
6: if R2is a ’yes’-instance then return true
7: end if
8: end for
9: end for
10: returnfalse
11: end function
For the question of how to find T1and T2, our solution is plain exhaustive search on the
sets V1and V2. This in turn raises the question of how to choose the sets V1and V2. We know
that V1YV2= V and that V1XV2 =H. Since there are equally many permutations of a set
of elements as there are strict total orders of the same set, we want to minimize |V1|! ¨ |V2|!.
This is done by letting V1and V2be of roughly the same size. The full algorithm is presented
in Algorithm 3.3.
Lemma 3.5. Algorithm 3.3 is correct.
Proof. From Lemma 3.4 we know that T1and T2exist if I is a ’yes’-instance, and from Lemma
3.3 we know that R2is correct, so Algorithm 3.3 answers true if and only if I is a ’yes’-instance.
We proceed with the complexity analysis. We will for simplicity divide this into two parts. First, we will prove that T2SAT(I, T1, T2)is in fact a 2-SAT formula. Second, we will prove the
complexity of Algorithm 3.3.
Lemma 3.6. T2SAT(I, T1, T2)is a 2-SAT formula.
Proof. Let R2 = T2SAT(I, T1, T2). The subformulas RCand Rconnexity are already 2-SAT
for-mulas since T2SATdoes not increase the size of clauses. The subformula Rtransitivitycontains
clauses of the form(By,x_Bz,y_Bx,z)for each triple of distinct variables x, y, z P V. Ignoring
symmetric cases x, y and z will be divided into one of four ways into V1and V2:
• x, y, z P V1,
• x, y P V1, z P V2,
• x, z P V1, y P V2, and
• y, z P V1, x P V2.
For the two cases of x, y, z P V1, and x, y P V1 with z P V2, connexity of T1will give that
either x ă1y or y ă1x. If x ă1y, then T2SATwill transform By,xto f alse, turning the clause
(By,x_Bz,y_Bx,z)into the 2-SAT clause(f alse _ Bz,y_Bx,z). If instead y ă1 x, then T2SAT
will transform the whole clause to true. For the case of x, z P V1and y P V2, connexity of T1
will give that either x ă1 z or z ă1 x. If x ă1 z, then T2SAT will transform the whole clause
to true. Instead if z ă1 x then T2SAT will transform Bx,z to f alse, turning the clause into the
2-SAT clause(By,x_Bz,y_f alse). For the case of y, z P V1and x P V2, connexity of T1will
give that either y ă1z or z ă1y. If y ă1z then T2SATwill transform Bz,yto f alse, turning the
clause into the 2-SAT clause(By,x_f alse _ Bx,z). Instead if z ă1y then T2SATwill transform
the whole clause to true. Thus, R2is a 2-SAT formula.
3.2. CSPs Limited to ă,=and ď-relations Proof. We start from the beginning: constructing the sets V1and V2can be done in polynomial
time. Our transform TSAT(I)can be computed in O(poly(||I||))time since RC, Rconnexityand
Rtransitivitycan all be constructed in O(poly(||I||))time.
There are |V1|! permutations of V1 and thereby |V1|! different strict total orders T1.
These can all be constructed in O˚(|V
1|!) time [10]. Similarly there are |V2|!
permuta-tions of V2 and thus |V2|! different strict total orders T2, which can all be constructed in
O˚(|V
2|!)time. Since |V1|and |V2| are roughly equal to n/2, the complexity of
construct-ing all combinations of T1 and T2 will be in O˚(n2!n2!). Stirling’s approximation [8] gives
O˚(n 2!
n
2!)ĎO˚(n!/2n)ĎO˚((0.1839n)n).
Our transform T2SAT can be computed in O(||TSAT||) Ď O(||I||) time. The
for-mula R2 is a 2-SAT formula and can be solved in polynomial time [4]. In
con-clusion the only non-polynomial step in Algorithm 3.3 is the construction of the combinations of the two strict total orders, and so the total complexity will be in O(n!/2n¨poly(||I||))ĎO((0.1839n)n¨poly(||I||)).
Theorem 3.8. An arbitrary CSP(tău_2) instance I = (V, C) can be solved in
O((0.1839|V|)|V|¨poly(||I||))time.
Proof. Combining Lemma 3.5 and Lemma 3.7 proves the theorem.
3.2
CSPs Limited to ă,
=
and ď-relations
We will now introduce an algorithm for solving CSP(tă,=, ďu_2). Since the algorithm will
closely resemble the CSP(tău_2)algorithm, the structure of this section will resemble that of Section 3.1. We start by showing a relation between strict weak orders and models of CSP(tă,=, ď, ‰u_k):
Definition 3.2. A strict weak order W = (S, ăW) satisfies a clause c, if there exists a literal
x ă y P c and x ăW y holds, or if there exists a literal x = y P c and neither x ăW y nor
y ăW x holds, i.e. x and y are incomparable in W. A strict weak order W= (S, ăW)satisfies a
CSP(tă,=, ď, ‰u_k)instance I= (V, C)if W satisfies all clauses in C.
Lemma 3.9. A CSP(tă,=, ď, ‰u_k)instance I is a ’yes’-instance if and only if there exists a strict
weak order W satisfying I.
Proof. If a strict weak order W = (V, ăW) satisfies I then take the function
f : V Ñ t0, ..., |V| ´ 1u such that for all x P V, f(x) equals the index of x in W. The func-tion f is a satisfying assignment of I since each literal xj ă xk that W satisfies in C is also
satisfied by f(xj) ă f(xk)and similarly for literals xj = xk. For the other direction, let the
function f : V ÑQ be a satisfying assignment of I. Define the pair W = (V, ăW)such that
x ăWy holds if and only if f(x)ă f(y). It is easy to verify that W is a strict weak order.
Transforming to SAT
The basis for the algorithm is that a CSP(tă,=, ďu_2)instance I = (V, C)can be transformed to a SAT instance by handling each relation as a Boolean variable Bx,y. The difference in
representation between CSP(tău_2)and CSP(tă,=, ďu_2)will be the relation between Bx,y
and By,xfor all x, y P V. In CSP(tău_2), Bx,y ‰ By,xis enforced. For CSP(tă,=, ďu_2)it
is enough that Bx,yand By,xare not true at the same time. To represent incomparability we
will use Bx,y = By,x= f alse. Since x ď y is logically equivalent to(x ă y _ x= y), x ď y is
also logically equivalent to (x ą y). Using this we can represent x ď y as By,xin our SAT
formulas.
Similar to TSAT for tău we will for tă,=, ďu have a transform WSAT for transforming
3.2. CSPs Limited to ă,=and ď-relations
Algorithm 3.4Transform CSP(tă,=, ďu_2)to SAT
1: function WSAT(I= (V, C)) 2: RCÐ H
3: foreach clause(x „1y _ z „2w)in C do 4: RCÐRC^(L(x „1y)_L(z „2w))
5: end for
6: RCÐCNF(RC) 7: RasymmetryÐ H
8: foreach pair x, y P V do
9: RasymmetryÐRasymmetry^( Bx,y_ By,x)
10: end for
11: RtransitivityÐ H
12: foreach triple x, y, z P V do
13: RtransitivityÐRtransitivity^( Bx,y_ By,z_Bx,z)
14: RtransitivityÐRtransitivity^(Bx,y_By,x_By,z_Bz,y_ Bx,z)
15: end for
16: return RC^Rasymmetry^Rtransitivity 17: end function
18: function L(x „ y)
19: if x „ yis x=y then
20: return( Bx,y^ By,x) 21: else if x „ yis x ă y then 22: return Bx,y 23: else if x „ yis x ď y then 24: return Bx,y 25: end if 26: end function
literal x „ y and returning the SAT representation of this literal. Our transform WSAT is
presented in Algorithm 3.4. Since L can return conjunctions, RC may not be a CNF
for-mula, and therefore we have to use standard methods for converting RC to CNF. In fact,
RCis of the form described in Example 2.4 and all conjunctive clauses have a size limited
by two. Hence, RC can be converted to CNF in polynomial time. For strict weak orders
connexity is not necessary, but asymmetry is. For this reason line 8-10 differ accordingly be-tween Algorithm 3.4 and Algorithm 3.2. Transitivity of ă is enforced in a similar way as for TSAT, but without using connexity, in line 13. We know that transitivity of
incompara-bility can be written as(x=y ^ y=z)Ñx=z which is logically equal to the CNF clause
(x ă y _ y ă x _ y ă z _ z ă y _ x=z). Our transform WSAT introduces the SAT
represen-tation of this CNF clause in line 14 to enforce transitivity of incomparability. Note that we simplify x = z to (x ă z) here, and not to (x ă z)^ (z ă x), to not get duplicated clauses from both the triples x, y, z and z, y, x.
Lemma 3.10. For an arbitrary CSP(tă,=, ďu_2)instance I, WSAT(I)is a ’yes’-instance if and
only if I is.
Proof. Let R = WSAT(I). We start by showing that if I is a ’yes’-instance, then R is
a ’yes’-instance. Take a strict weak order W = (V, ăW) satisfying I and a function
f : B Ñ ttrue, f alseu where B=tBx,y| x, y P Vu. Define f such that f(Bx,y) =true if x ăW y
and f(Bx,y) = f alse otherwise. Each clause c in C must be satisfied by W. If the satisfied
literal in c is x ă y and x ăW y then f(Bx,y) = true. We know that WSAT transforms the
clause(x ă y _ u „ v)to(Bx,y_L(u „ v)), which is satisfied by f(Bx,y) = true. If instead
the satisfied literal in c is x = y and x [Wy then f(Bx,y) = f alse and f(By,x) = f alse. We
3.2. CSPs Limited to ă,=and ď-relations thereafter further to CNF), which is satisfied by f(Bx,y) = f alse and f(By,x) = f alse. This is
true for all clauses in C and consequently for all clauses in RC.
We know that asymmetry holds for W and Rasymmetry contains clauses of the form
( Bx,y_ By,x). For f this means that if (x ăW y) then f(Bx,y) = f alse, which
sat-isfies ( Bx,y_ By,x). If instead (y ăW x) then f(By,x) = f alse, which also satisfies
( Bx,y_ By,x). Since Rasymmetry contains clauses for all pairs of distinct variables x, y P V,
and asymmetry holds for all pairs of distinct variables x, y P V, Rasymmetryis satisfied since W
is a strict weak order.
Furthermore, W has both of the transitivity properties. This means that for each triple x, y, z P V, (x ăW y ^ y ăW z) Ñ x ăW z and (x [Wy ^ y [Wz) Ñ x [Wz holds. We
know that for each triple x, y, z P V there exists the two clauses( Bx,y_ By,z_Bx,z)and
(Bx,y_By,x_By,z_Bz,y_ Bx,z)in Rtransitivity. From this we can see that if W has the two
transitivity properties, then f will satisfy the clauses in Rtransitivity. Since Rtransitivitycontains
one clause for each triple x, y, z P V, and transitivity holds for each triple, Rtransitivityis
satis-fied since W is a strict weak order.
We now know that f satisfies RC, Rasymmetry and Rtransitivity. Since R is equal to
RC^Rconnexity^Rtransitivity, f satisfies R, so R is a ’yes’-instance.
We continue by proving that if R is a ’yes’-instance, then I is a ’yes’-instance. Take a model of R and let B+be the set of variables set to true in the model. Let ăWbe the binary relation
on V with x ăW y if and only if Bx,yPB+. Consider the pair W= (V, ăW). Now for W to be
a strict weak order, then asymmetry and both types transitivity must hold. We will start by proving that asymmetry holds: For every pair x, y P V there exists a clause( Bx,y_ By,x)
in Rsymmetry. This clause is satisfied by either Bx,y= true and By,x = f alse, Bx,y = f alse and
By,x =true or Bx,y= f alse and By,x = f alse. For the case when Bx,y=true and By,x= f alse,
Bx,yis in B+ and x ăW y is true while y ăW x is not. Similar logic also hold for the cases
when Bx,y= f alse and By,x=true, and when Bx,y= f alse and By,x= f alse. Since this is true
for all pairs x, y P V, asymmetry holds for W.
We continue with Rtransitivty and the two types of transitivity. For every triple x, y, z P V
there exist two clauses ( By,x_ Bz,y_Bx,z) and (Bx,y_By,x_By,z _Bz,y_ Bx,z) in
Rtransitivity. For the same triple x, y, z there also exists five other pairs of relevant clauses
in Rtransitivitysince there are five additional permutations of x, y, z:
• ( Bz,x_ By,z_Bx,y)and(Bx,z_Bz,x_Bz,y_By,z_ Bx,y),
• ( Bx,y_ Bz,x_By,z)and(By,z_Bx,y_Bx,z_Bz,x_ By,z),
• ( Bz,y_ Bx,z_By,x)and(By,z_Bz,y_Bz,x_Bx,z_ By,x),
• ( Bx,z_ By,x_Bz,y)and(Bz,x_Bx,z_Bx,y_By,x_ Bz,y), and
• ( By,z_ Bx,y_Bz,x)and(Bz,y_By,z_By,x_Bx,y_ Bz,x).
The truth values of this set of clauses is directly affected by the assignment of the six variables Bx,y, By,x, Bx,z, Bz,x, By,zand Bz,y. Combined with Rasymmetrythis set of six clauses is satisfied
by thirteen different assignments of the six variables. These thirteen different assignments gives thirteen different options for ăWand thirteen different options of W. Table 3.2 presents
these thirteen assignments, their corresponding ăWand corresponding W. In Table 3.2 we see
that both types of transitivity hold for each of these assignments. Since Rtransitivitycontains
these clauses for each triple x, y, z P V, both types of transitivity will be enforced in W. We have now proved that W has the asymmetry and two transitivity properties, so it is a strict weak order.
Let u be such that if x „1y is x ă y then u=Bx,y, if x „1y is x ď y then u= By,xand if
x „1y is x=y then u= ( Bx,y^ By,x). Similarly, let v be such that if z „2w is z ă w then
v=Bz,w, if z „2w is z ď w then v= Bw,zand if z „2w is z=w then v= ( Bz,w^ Bw,z).
3.2. CSPs Limited to ă,=and ď-relations Table 3.2: The thirteen assignments satisfying transitivity.
B ăW W
Bx,y=By,z =Bx,z=true, By,x=Bz,y=Bz,x= f alse (x, y),(y, z),(x, z) (x ăW y ăW z)
Bx,y=Bx,z=true, By,x=By,z=Bz,y=Bz,x= f alse (x, y),(x, z) (x ăWy [Wz)
By,z=Bx,z=true, Bx,y=By,x=Bz,y=Bz,x= f alse (y, z),(x, z) (x [Wy ăWz)
Bx,y=By,z=Bx,z=By,x=Bz,y=Bz,x= f alse H (x [Wy [Wz)
Bx,z=Bz,y=Bx,y=true, Bz,x=By,z=By,x= f alse (x, z),(z, y),(x, y) (x ăW z ăW y)
Bz,y=Bx,y=true, Bx,z =Bz,x=By,z=By,x= f alse (z, y),(x, y) (x [Wz ăW y)
By,x=Bx,z=By,z=true, Bx,y=Bz,x=Bz,y= f alse (y, x),(x, z),(y, z) (y ăW x ăW z)
By,x=By,z =true, Bx,y=Bx,z=Bz,x=Bz,y= f alse (y, x),(y, z) (y ăW x [Wz)
By,z=Bz,x =By,x=true, Bz,y=Bx,z=Bx,y= f alse (y, z),(z, x),(y, x) (y ăWz ăW x)
Bz,x =By,x=true, By,z=Bz,y=Bx,z=Bx,y= f alse (z, x),(y, x) (y [Wz ăWx)
Bz,x =Bx,y=Bz,y=true, Bx,z=By,x=By,z= f alse (z, x),(x, y),(z, y) (z ăW x ăW y)
Bz,x =Bz,y=true, Bx,z=Bx,y=By,x=By,z= f alse (z, x),(z, y) (z ăW x [Wy)
Bz,y=By,x =Bz,x=true, By,z=Bx,y=Bx,z= f alse (z, y),(y, x),(z, x) (z ăW y ăW x)
Table 3.3: Translation table for W2SAT
Known Relation ( Bx,y_ By,z_Bx,z) (Bx,y_Bx,y_By,z_By,z_ Bx,z)
x ă y ( By,z_Bx,z) true
x=y true (By,z_ Bx,z)
x ą y true true
x ă z true (Bx,y_By,z)
x=z ( Bx,y_ By,z) true
x ą z ( Bx,y_ By,z) true
y ă z ( Bx,y_Bx,z) true
y=z true (Bx,y_ Bx,z)
y ą z true true
c= (u _ v)in RC. For any model of R, c must be satisfied. If c is satisfied by Bx,y=true then
Bx,yis in B+ and thereby x ăW y and W satisfies(x „1 y _ z „2 w)since x „1 y must be
x ă y. Similar logic hold for the other two cases satisfying u and for the symmetric cases for v. This analysis hold true for all clauses in C, so W satisfies all clauses in C. Since W is a strict weak order and satisfies all clauses in C, W must satisfy I via Lemma 3.9 and this completes the proof.
Towards
2-SAT
Our transform WSATwill just as TSATproduce clauses bigger than size two in Rtransitivityand
a quadratic increase of the number of variables. Our approach to reduce the size of Rtransitivity
will once again be to divide V into two sets V1, V2and two strict weak orders W1= (V1, ă1)
and W2= (V2, ă2). It will not be enough to just replace variables with known relations with
true or f alse. We will use Table 3.3 for translating clauses in Rtransitivity. Our algorithm W2SAT
for doing this is presented in Algorithm 3.5, where Table 3.3 is used at line 4.
Lemma 3.11. For an arbitrary CSP(tă,=, ďu_2)instance I = (V, C)and two strict weak orders
W1 = (V1, ă1)and W2= (V2, ă2), with V1YV2 =V and V1XV2= H, W2SAT(I, W1, W2)is a
’yes’-instance if and only if I is satisfied by a strict weak order W = (V, ăW)compatible with both
W1and W2.
Proof. Let R2=W2SAT(I, W1, W2), R =WSAT(I)and B=tBx,y|x, y P Vu. We start by
3.2. CSPs Limited to ă,=and ď-relations
Algorithm 3.5Transform CSP(tă,=, ďu_2)to 2-SAT
1: function W2SAT(I= (V, C), W1= (V1, ă1), W2= (V2, ă2)) 2: R2ÐWSAT(I)
3: foreach clause c in Rtransitivitydo 4: Translate c using Table 3.3
5: end for
6: foreach x ă1y do
7: Replace all occurrences of By,xin R2with f alse 8: Replace all clauses in R2containing Bx,ywith true
9: end for
10: foreach x ă2y do
11: Replace all occurrences of By,xin R2with f alse 12: Replace all clauses in R2containing Bx,ywith true
13: end for
14: foreach incomparable pairs x,y in ă1do
15: Replace all occurrences of Bx,yand By,xin R2with f alse 16: Replace all clauses in R2containing Bx,yor By,xwith true
17: end for
18: foreach incomparable pairs x,y in ă2do
19: Replace all occurrences of Bx,yand By,xin R2with f alse 20: Replace all clauses in R2containing Bx,yor By,xwith true
21: end for
22: return R2
23: end function
I, then R2is a ’yes’-instance. Take the function f : B Ñ ttrue, f alseu such that f(Bx,y) =true
if and only if x ăW y and f(Bx,y) = f alse otherwise. We know from Lemma 3.10 that f is a
model of R. Since W is compatible with W1and W2we know that ă1Y ă2ĎăW. This means
that for any pair such that x ă1 y then f(Bx,y) = true and f(By,x) = f alse, and similarly for
any pair such that x ă2 y, it holds that f(Bx,y) = true and f(By,x) = f alse. Consider the
six types of clauses remaining after translating Rtransitivityusing Table 3.3. For the case when
c= ( By,z_Bx,z)where x ăW y is known, we have five different possible relations between
z, x and y: z ăW x ^ z ăW y, x [Wz ^ z ăW y, x ăW z ^ z ăW y, x ăW z ^ y [Wz and
x ăW z ^ y ăWz. No other subcases exist since W is a strict weak order. If z ăWx ^ z ăWy,
x [Wz ^ z ăW y, x ăW z ^ z ăW y or x ăW z ^ y [Wz then f(By,z) = f alse, satisfying
c. Similarly if x ăW z ^ y ăW z then f(Bx,z) = true, satisfying c. Using a similar subcase
analysis we see that the remaining five types of clauses in Rtransitivityare satisfied by W. The
literals W2SAT removes from WSAT(I)are all either of the form Bx,ywhere y ă1 x, y ă2 x,
x [W1 y or x [W2y, or of the form Bx,ywhere x ă1 y or x ă2 y. As a consequence W2SAT
will only remove literals not satisfied by f . Each clause in R must contain at least one literal satisfied by f , and since no such literal is removed by W2SAT, at least one such literal must
remain for each clause in R2. Furthermore, W2SATdoes not add any clauses to R2that do not
already exists in R. Since f satisfies all clauses in R and all clauses in R2exists in R, f must
also satisfy R2. Therefore, if there is a strict weak order W compatible with W1and W2and
satisfying I, then R2is a ’yes’-instance.
We continue by showing that if R2is a ’yes’-instance, then R is a ’yes’-instance. Let a
func-tion f : B Ñ ttrue, f alseu satisfy R2in such a way that if x ă1y or x ă2y then f(Bx,y) =true
and f(By,x) = f alse, and if x [1y or x [2y then f(Bx,y) = f(By,x) = f alse. Such a function
exists if R is a ’yes’-instance since no variable Bx,yor By,xoccurs anywhere in R2if the
rela-tion between x and y is known in W1or W2. For each clause c2in R2, there will be a unique
counterpart c in R, with potentially the only difference that c contains one or two literals that c2does not. So every literal in c2will be in c. Since f satisfies c2it will also satisfy c. Every