THE SOLUTION OF DISCRETE CONSTRAINT PROBLEMS USING
BOOLEAN MODELS
The Use of Ternary Vectors for Parallel SAT-Solving
Christian Posthoff
Department of Mathematics & Computer Science, The University of the West Indies, Trinidad & Tobago
Bernd Steinbach
Institute of Computer Science, Freiberg University of Mining and Technology, Freiberg, Germany
Keywords:
Constraint problems, Boolean models, Ternary vectors, Intersection, Bit-parallel, XBOOLE.
Abstract:
The use of Boolean models for discrete constraint problems has been tried at several occasions, it was, how-
ever, not recognized as efficient (Rossi et al., 2006). The solution methods were dominated by using decision
trees together with depth-first or breadth-first search and/or resolution algorithms. In this paper we will show
the use of ternary vectors for the solution of SAT-problems and all the problems that can be modeled by means
of SAT-equations. They are an appropriate data structure representing sets of Boolean vectors. They also
allow to include problem-relevant knowledge into the problem-solving process at an early point of time. The
respective set operations (mainly the intersection) can be executed in a bit-parallel way (64 bits at present).
For larger problems the processing can be transferred to processors working fully in parallel. There is no
need for any search algorithms. The approach always finds all solutions of the problem without considera-
tion of special cases (i.e. no solution, one solution, all solutions). Some examples are used to illustrate the
approach or have been published before (Sudoku, Queen’s problems on the chessboard, node bases in graphs,
graph-coloring problems).
1 INTRODUCTION
The satisfiability problem (SAT) has been very well
explored. Besides of special tools for SAT solv-
ing we apply in this paper the more general tool
XBOOLE (Posthoff and Steinbach, 2004), (Steinbach
and Posthoff, 2009). XBOOLE allows to solve logic
equations and manipulate solution sets efficiently.
The efficiency of solving complex problems results
particularly from the compression of sets in ternary
vectors and their bit-parallel computation. Addition-
ally it is possible to distributethe problem to be solved
to several processors (Posthoff and Steinbach, 2006).
Based on the mentioned very efficient parallel al-
gorithms for its solution, it will be shown that many
combinatorial problems can be transformed into sat-
isfiability problems and solved using these developed
algorithms. The approach is constructive and very
general, no research procedures are involved, and the
results are always complete.
As extension to the classical SAT approach we
suggest a new modeling approach called two-phase
SAT solver which works on a higher level and utilizes
the efficient operations of XBOOLE.
2 TERNARY VECTORS AS THE
MAIN DATA STRUCTURE
As a first step we introduce the data structure of a
ternary vector. Let x = (x
1
, ··· , x
n
), x
i
{0, 1, −}, i =
1, . . . , n. Then x is called a ternary vector which can
be understood as an abbreviation of a set of binary
vectors. When we replace each by 0 or 1, then we
get several binary vectors generated by this ternary
vector. In this way the vector (01) represents four
binary vectors (0010), (0011), (0110) and (0111). A
list (matrix) of ternary vectors can be understood as
the union of the corresponding sets of binary vectors.
487
Posthoff C. and Steinbach B. (2010).
THE SOLUTION OF DISCRETE CONSTRAINT PROBLEMS USING BOOLEAN MODELS - The Use of Ternary Vectors for Parallel SAT-Solving.
In Proceedings of the 2nd International Conference on Agents and Artificial Intelligence - Artificial Intelligence, pages 487-493
DOI: 10.5220/0002703804870493
Copyright
c
SciTePress
There is a direct relation of ternary vectors with
conjunctions of Boolean variables. When there is
given a conjunction C with variables x
1
, . . . , x
k
, then
we can build a ternary vector t with the components
t
1
, . . . , t
k
according to the following coding:
x
i
: t
i
= 1 ,
x
i
: t
i
= 0 ,
x
i
missing : t
i
= . (1)
This coding expresses directly on one side the re-
spective conjunction, on the other side the set of all
binary vectors satisfying C = 1.
Example. Let be given x
1
x
2
x
3
x
5
= 1, then we
have t = (101 0) which expresses the two binary
vectors (10100) and (10110).
Hint. It will be assumed that the problem-relevant
Boolean space includes the variables x
1
, x
2
, x
3
, x
4
, x
5
.
Let be given two ternary vectors x and y. The in-
tersection of these two vectors (i.e. the intersection
of the respective two sets of binary vectors) will be
computed according to Table 1 which has to be ap-
plied in each component of the two vectors. The sym-
bol
/
0 indicates that the intersection of the two sets is
empty and can be omitted. A sophisticated coding of
Table 1: Intersection of ternary values.
x
i
0 0 0 1 1 1
y
i
0 1 0 1 0 1
x
i
y
i
0
/
0 0
/
0 1 1 0 1
the three values 0, 1 and allows the introduction of
binary vector operations that can be executed on the
level of registers (32, 64 or even 128 bits in parallel).
We use the coding of Table 2. The first bit indicates
that the variable has a value in the ternary vector, the
second bit indicates the value itself.
Table 2: Binary code of ternary values.
ternary value bit1 bit2
0 1 0
1 1 1
0 0
When the three-valued operations for the intersec-
tion are transferred to these binary vectors, then the
intersection is empty iff
bit1(x) bit1(y) (bit2(x) bit2(y)) 6= 0 . (2)
If the intersection is not empty, then it can be de-
termined by the following bit vector operations:
bit1(x y) = bit1(x) bit1(y) , (3)
bit2(x y) = bit2(x) bit2(y) (4)
Hint. indicates the exclusive-or, 0 is the vector
where all the components are equal to 0. Hence, by
using some very fast and very simple bit vector oper-
ations (available on the hardware level), we can find
the intersection of two ternary vectors.
3 BASIC APPROACHES OF
PARALLEL SAT-SOLVING
Using these ternary vectors as the basic data structure,
we are able to solve SAT-problems directly. We will
use the following small example:
(a b c)(b d e)(a d e)(b c e) = 1 . (5)
This equation is equivalent to the system od four sin-
gle equations:
a b c = 1 , (6)
b d e = 1 , (7)
a d e = 1 , (8)
b c e = 1 . (9)
The first equation (6) now will be transformed into
a ternary matrix (a set or list of ternary vectors):
a b c d e
1
0 0
0 1 0
This matrix shows all the vectors that satisfy the
first equation. If a = 1, then the values of the other
variables are not important. If a = 0, then b must be
equal to 1, i. e. b = 0. Finally, if a = 0 and b = 1, then
c must be equal to 0. This construction has the addi-
tional property (advantage) that every pair of vectors
of this matrix has an empty intersection, and there-
fore any double solutions cannot exist. b indicates the
negation of b. It is very characteristic that each vec-
tor of the matrix includes more information than the
previous vectors. The number of vectors in the result-
ing matrix is equal to the number of variables in the
disjunction. In the example each disjunction has three
variables.
If we repeat this procedure for all four equations,
then we get the following four matrices.
solution of equation (6)
a b c d e
1
0 0
0 1 0
ICAART 2010 - 2nd International Conference on Agents and Artificial Intelligence
488
solution of equation (7)
a b c d e
1
0 0
0 1 0
solution of equation (8)
a b c d e
0
1 1
1 0 1
solution of equation (9)
a b c d e
1
0 1
0 0 0
In order to get the final solution, these four matri-
ces have to be combined by intersection (see above).
Each line of one matrix has to be combined with each
line of the next matrix, empty intersections can be
omitted.
For the first and second matrix, we get, for in-
stance, after some simplifications:
a b c d e
1
0 0
0 1 0
\
a b c d e
1
0 0
0 1 0
=
a b c d e
0 1 0
0 0
0 1 0
1 1
, (10)
and the final result is equal to
a b c d e
0 0 0
0 1 0 1
1 1 1
0 1 0
1 1 0
. (11)
This matrix of ternary vectors represents all solu-
tions of the original SAT-problem. Since the value
represents 0 as well as 1, the equation has 18 solu-
tions.
4 SUDOKU AS AN EXAMPLE
Over the last years a Japanese game with the name
Sudoku became very popular. It is played mostly on
a board with 9 x 9 fields, but other square numbers are
5 3 7
6 1 9 5
9 8 6
8 6 3
4 8 3 1
7 2 6
6 2 8
4 1 9 5
8 7 9
Figure 1: Example of a 9× 9 Sudoku.
also possible, such as 4 x 4 or 16 x 16 or even 25 x 25.
It is easy to understand and a bit challenging for hu-
man beings, and it can be used comfortably to spend
waiting time on airports or similarly. But there are
also mathematical and logical properties that deserve
some attention.
There is a quadratic board of, for instance, size 9 x
9. In each column, in each row and in nine subsquares
of size 3 x 3 the values 1, . . . , 9 have to be set such that
in each column, in each row and in each subsquare
each value is used once and only once.
Some values already have been set, and the other
values have to be found according to the existing val-
ues. We enumerate the columns from the left to the
right and the rows bottom-up (in the same way as a
normal planar coordinate system).
We know at least two papers that are using SAT
for the modelingof the game and existing SAT-solvers
for the solution of the problem (Lynce and Ouaknine,
2006), (Weber, 2005). These papers used the follow-
ing approach: a binary variable x
ijk
describes the con-
tent of the field (i, j), 1 i, j, k 9:
x
ijk
=
1 if the value on the field (i, j) = k
0 if the value on the field (i, j) 6= k
.
(12)
The transformation into a SAT-problem uses sev-
eral steps:
x
ij1
x
ij2
x
ij3
x
ij4
x
ij5
x
ij6
x
ij7
x
ij8
x
ij9
= 1 . (13)
expresses the requirement that one of the numbers
1, . . . , 9 must be used for the field (i, j). Such a dis-
junction must be written for each field of the board
which results in 81 clauses which must be satisfied
simultaneously.
The second step expresses all the constraints for
rows, colums and squares as clauses as well. For ex-
ample for the field (1, 1) and the value 1 on this field,
no other value can be on this field:
x
111
x
112
, x
111
x
113
, . . . ,
x
111
x
118
, x
111
x
119
. (14)
THE SOLUTION OF DISCRETE CONSTRAINT PROBLEMS USING BOOLEAN MODELS - The Use of Ternary
Vectors for Parallel SAT-Solving
489
The same set of clauses must be written for the
other values 2, . . . , 9 on the same field. The require-
ments for the first column can be expressed in the
same way:
x
111
x
121
, x
111
x
131
, . . . ,
x
111
x
181
, x
111
x
191
. (15)
The constraints for the row are given as
x
111
x
211
, x
111
x
311
, . . . ,
x
111
x
811
, x
111
x
911
, (16)
and finally we must consider the remaining value 1 in
the respective square:
x
111
x
221
, x
111
x
231
,
x
111
x
321
, x
111
x
331
. (17)
Again all these clauses have to be written for all
numbersfrom 1 to 9 and finally for all fields. By using
the rule x y = x y the whole set of implications
can be transformed into disjunctions, all of them must
be satisfied at the same time, and this is the problem
in SAT-format. Each satisfying set of values for the
binary variables is a solution of the Sudoku.
We will show that this game easily can be modeled
by using a logic equation, with ternary vectors as the
most appropriate data structure. Actually, the logic
equation does not even have to be written down, the
ternary vectors can be generated directly.
We are using the same encoding (12) as the two
other papers mentioned above. The constraints can be
stated by one single conjunction for each number on
each field:
K
111
= x
111
x
112
x
113
x
114
x
115
x
116
x
117
x
118
x
119
x
121
x
131
x
141
x
151
x
161
x
171
x
181
x
191
x
211
x
311
x
411
x
511
x
611
x
711
x
811
x
911
x
221
x
231
x
321
x
331
. (18)
This conjunction describes completely the setting
of 1 on the field (1, 1) and all the consequences.
There are 729 of such conjunctions which are defined
uniquely. It is important to understand that not only
the requirement in terms of 9 variable x
ijk
are taken
into consideration, but the conjunctionsK
ijk
so that all
the consequences resulting from a given setting are
used immediately. The existing knowledge or con-
straints are directly built into the ternary vectors.
Now we must express the possibilities of the
game. In order to do this, we can use one of the fol-
lowing four types of equations.
1. The equation
K
111
K
112
K
113
K
114
K
115
K
116
K
117
K
118
K
119
= 1 (19)
describes that one of the 9 values must be assigned
to one field (the field (11) is only an example).
2. The equation
K
111
K
121
K
131
K
141
K
151
K
161
K
171
K
181
K
191
= 1 (20)
describes that the value 1 must be assigned to one
of the fields in a row (row 1 and value 1 are only
examples).
3. The equation
K
111
K
211
K
311
K
411
K
511
K
161
K
711
K
811
K
911
= 1 (21)
describes that the value 1 must be assigned to one
of the fields in a column (column 1 and value 1
are only examples).
4. The equation
K
111
K
121
K
131
K
211
K
221
K
231
K
311
K
321
K
331
= 1 (22)
describes that the values 1 must be assigned to one
of the fields in a subsquare (the first subsquare and
value 1 are only examples).
Each type of these equations generates a system
of 81 disjunctions that must be satisfied at the same
time. They are completely equivalent, one system can
be selected once and for ever. All the conjunctions are
represented by ternary vectors, and this representa-
tion can be generated before any real game which
is given by special settings. Each ternary vector will
have 729 components, and all intersections from the
left to the right have to be calculated.
Since the values which have already been set re-
sult in one vector for the given field, many of these
matrices will have only one row (30 in the given ex-
ample). Therefore it is advisable (however, not nec-
essary), to intersect the single vectors first, because
thereafter many intersections will be empty. This al-
gorithm does not need any considerations for special
cases. If there are no solutions, then the intersec-
tion will be empty at a given point of time, if there
is a unique solution, then we will have precisely one
vector in the final intersection, and more than one so-
lution will be expressed by the respective number of
vectors.
The solution set S consists of all binary vectors
of the length 729 that solve the SAT problem of the
given Sudoku. Each solution vector includes exactly
81 values 1 that indicate the solution numbers asso-
ciated to the fields. The remaining 648 components
of each solution vector carry the value 0. Thus, by
taking the index (i, j, k) of the values 1 in the solution
ICAART 2010 - 2nd International Conference on Agents and Artificial Intelligence
490
vector, a representation of the value k in the field(i, j)
of column i and row j can be established.
As a summary we can see that the solution of the
problem has two steps. The first phase covers the
modeling of the problem and the calculation of par-
tial solution sets (or solution candidates). Of course
the first phase depends on the problem to be solved -
in our case any Sudoku game.
The second phase mainly considers the different
action possibilities and combines these possibilities
by . The intersections of the different possible ac-
tions are evaluated by the intersections of the respec-
tive ternary vectors.
The advantage of this new approach in compari-
son with the known traditional SAT-models is the si-
multaneous assignment of values to many variables.
In case of a 9 × 9 Sudoku a single assignment spec-
ifies additionally 28 variables of the solution space,
and this strongly restricts the remaining search space.
5 EXPERIMENTAL RESULTS
In case of a 16× 16 board the matrix of the partial so-
lution sets required approximately 2 Megabyte. Each
row of this matrix includes one value 1, 54 values 0.
The remaining values of the 4096 variables are filled
with dashes. Therefore we decided to store only the
index values of the elements with the value 0 and 1
and to generate any vector of a partial solution set
at the time when it is required. Without any other
changes the problem of a 16 × 16 Sudoku that maps
into a problem of 4096 variables and 111616 clauses
could be solved within about two and a half minutes.
6 OTHER PROBLEMS
Based on this methodology, many other problems
have been solved. It will not be very difficult to apply
the same methodology.
1. It is expected that on a chessboard of size n × n
with k additional pawns n + k queens can be
placed without threatening each other. Figure 2
shows one solution for one pawn on a board of
size 8× 8.
The pawn interrupts the effective lines of the
queens, and the diagram really shows 9 queens on
this board.
Figrue 3 shows the number of solutions depending
on the position of the pawn.
Figure 4 shows finally the result for two pawns,
and Table 3 summarizes the experimental results
Q
Q
Q
Q P Q
Q
Q
Q
Q
Figure 2: Example of a solution of 9 queens and 1 pawn.
0 0 0 0 0 0 0 0
0 0 2 4 4 2 0 0
0 2 6 2 2 6 2 0
0 4 2 10 10 2 4 0
0 4 2 10 10 2 4 0
0 2 6 2 2 6 2 0
0 0 2 4 4 2 0 0
0 0 0 0 0 0 0 0
Figure 3: Distribution of the solutions of 9 queens and 1
pawn.
for chessboards of several sizes.
2. The case of n = 0 is the ”normal” problem of ar-
rangements of queens on a chessboard n × n that
has been solved as well up to n = 17.
3. There are many problems asking for minimum
and maximum numbers, for instance, how many
bishops are at least required to cover all the fields
on a chessboard, or how many bishops can at most
be placed on a chessboard without covering each
other etc. These problems also have been solved
on boards of size m× n for many values of m, n.
4. The same relates to graph problems, such as
Hamiltonian and Eulerian paths in a graph, the
minimum number of nodes with a given property
or the maximum number of nodes with a given
property etc.
5. As a last example we will show the solution of
coloring problems. Our method can be applied to
color any graph. As example we use the graph
Q
Q
Q
Q P Q
Q
Q P Q
Q
Q
Figure 4: Example of a solution of 10 queens and 2 pawns.
THE SOLUTION OF DISCRETE CONSTRAINT PROBLEMS USING BOOLEAN MODELS - The Use of Ternary
Vectors for Parallel SAT-Solving
491
Table 3: Number of variabels and solutions for 2 pawns and
the maximal number of queens on chessboards of size n×n.
n # variables # solutions time in sec
3 9 0 0.00
4 16 0 0.0
5 25 0 0.0
6 36 0 0.0
7 49 4 0.20
8 64 44 0.92
9 81 280 3.31
10 100 1304 11.09
11 121 12452 97.21
12 144 105012 406.07
called Birkhoffs Diamond shown in Figure 5 (a).
The structure of a graph can described using an
adjacency matrix. A value 1 in the row i and col-
umn j indicates an edge from node i to node j
in the graph. In case of an undirected graph we
get an symmetric adjacency matrix. The graph
Birkhoffs Diamond has the following adjacency
matrix.
A
BD
=
0100011100
1010000110
0101000010
0010100011
0001011001
1000101000
1000110101
1100001011
0111000101
0001101110
(23)
Using the adjacency matrix (23) the partial solu-
tion sets can be generated directly. The logic vari-
ables describe whether a certain color is assigned
to the a node of the graph or not. Hence, the num-
ber of required variables is equal to the product of
the number of nodes and considered colors.
x
cn
=
1 if the color on the node n = c
0 if the color on the node n 6= c
.
(24)
These partial solution sets cover the the restrictive
rules. When a color is assigned to one node, it is
not allowed that:
(a) another color is assigned to the same node, and
(b) the some color is assigned to another node con-
nected by an edge.
Figure 6 shows the generated matrix of the par-
tial solution sets (mpss) in the XBOOLE mon-
itor (Posthoff and Steinbach, 2004), (Steinbach
(a)
(b)
Figure 5: Birkhoffs diamond: (a) uncolored graph, (b) one
solution using 4 colors.
Figure 6: Generated matirx of the partial solution sets to
color the graph of Birkhoffs diamond using four colors.
and Posthoff, 2009). Each row represents a con-
junction K
cn
covering seven, eight or nine compo-
nents.
The second phase of the new two-phase SAT -
ICAART 2010 - 2nd International Conference on Agents and Artificial Intelligence
492
Table 4: Calculation of all solutions to color the Birkhoffs
diamond using 3, 4 of 5 colors.
number of time in
nodes colors variables solutions seconds
10 3 30 0 0.00
10 4 40 576 0.00
10 5 50 40800 0.02
Table 5: Calculation of all solutions to color the Birkhoffs
diamond and graphs that include two or four such graphs
using 4 colors.
number of time in
nodes colors variables solutions seconds
10 4 40 576 0.00
20 4 80 99888 0.20
40 4 160 100800 4.97
solver is controlled by the requirement clauses.
For graph coloring we have the simple require-
ment that there must be one color assigned to each
node of the graph. In order to find all allowed as-
signments of four colors for the graph of Figure 5,
we must solve the equation:
10
^
i=1
(K
1i
K
2i
K
3i
K
4i
) = 1 . (25)
The time to solve this equation using the oper-
ations
UNI
and
ISC
of XBOOLE (Posthoff and
Steinbach, 2004) was less than a single time-tick
(15 ms). Figure 5 (b) shows one of the 576 solu-
tions that have been found.
Two experiments demonstrate the power of this
approach. In the first experiment we calculated all
solutions to color Birkhoffs diamond using three,
four or five colors. Table 4 summarizes these re-
sults.
In the second experimentwe created several larger
graphs: we combined first two Birkhoffs dia-
monds using some additional edges and thereafter
four Birkhoffs diamonds in a similar way. Table
5 summarizes these results.
7 SUMMARY
There are several results presented in this paper.
1. Many finite discrete constraint-related problems
can bee modeled as a SAT-problem. It has been
shown that it is not necessary to write down the
huge number of clauses of the conjunctive forms
which must be solved by a SAT-solver. Based on
the explored properties of the problem, it is possi-
ble to generate partial solution sets of the restric-
tive properties of the problem.
2. A new implicit two-phase SAT-solver has been
used. In the first phase this SAT-solver creates
partial solution sets which are used in the second
phase to calculate the solution without any further
decisions.
3. The matrix of the partial solution sets describes
general constraints of the problem without any
consideration of clauses.
4. The use of the partial solution sets in the second
phase of the SAT-solver allows to solve the SAT-
problems very fast. The partial solution sets help
to restrict significantly the enormous search space.
The remaining clauses of the problem are replaced
by unions of partial solution sets which speed up
the solution procedure.
5. In many applications the Boolean modeling can
be considered as very efficient, and it is not neces-
sary to develop special algorithms; it is much eas-
ier to use a general methodology based on ternary
vectors.
REFERENCES
Lynce, I. and Ouaknine, J. (2006). Sudoku as a sat problem.
In Proceedings of the 9 th International Symposium
on Artificial Intelligence and Mathematics, AIMATH
2006, Fort Lauderdale. Springer.
Posthoff, C. and Steinbach, B. (2004). Logic Functions
and Equations - Binary Models for Computer Science.
Springer, Dordrecht, The Netherlands.
Posthoff, C. and Steinbach, B. (2006). A multi-processor
approach to sat-problems. In Proceedings of the 7th
International Workshop on Boolean Problems, pages
49–62, Freiberg University of Mining and Technol-
ogy, Freiberg, Germany.
Rossi, F., van Beek, P., and Walsh, T. (2006). Handbook of
Constraint Programming. ELSEVIER.
Steinbach, B. and Posthoff, C. (2009). Logic Functions and
Equations - Examples and Exercises. Springer Sci-
ence + Business Media B.V.
Weber, T. (2005). A SAT-based Sudoku solver. In Sut-
cliffe, G. and Voronkov, A., editors, LPAR-12, The
12th International Conference on Logic for Program-
ming, Artificial Intelligence, and Reasoning, Short Pa-
per Proceedings, pages 11–15.
THE SOLUTION OF DISCRETE CONSTRAINT PROBLEMS USING BOOLEAN MODELS - The Use of Ternary
Vectors for Parallel SAT-Solving
493