Leone 2006
Leone 2006
Disjunctive Logic Programming (DLP) is an advanced formalism for knowledge representation and
reasoning, which is very expressive in a precise mathematical sense: it allows one to express every
property of finite structures that is decidable in the complexity class 2P ( NPNP ). Thus, under
widely believed assumptions, DLP is strictly more expressive than normal (disjunction-free) logic
programming, whose expressiveness is limited to properties decidable in NP. Importantly, apart
from enlarging the class of applications which can be encoded in the language, disjunction often
allows for representing problems of lower complexity in a simpler and more natural fashion.
This article presents the DLV system, which is widely considered the state-of-the-art imple-
mentation of disjunctive logic programming, and addresses several aspects. As for problem solving,
we provide a formal definition of its kernel language, function-free disjunctive logic programs (also
known as disjunctive datalog), extended by weak constraints, which are a powerful tool to express
optimization problems. We then illustrate the usage of DLV as a tool for knowledge representation
and reasoning, describing a new declarative programming methodology which allows one to encode
complex problems (up to 3P -complete problems) in a declarative fashion. On the foundational side,
we provide a detailed analysis of the computational complexity of the language of DLV, and by
deriving new complexity results we chart a complete picture of the complexity of this language and
important fragments thereof.
Furthermore, we illustrate the general architecture of the DLV system, which has been influ-
enced by these results. As for applications, we overview application front-ends which have been
This work was supported by the European Commission under projects IST-2002-33570 INFOMIX,
and IST-2001-37004-WASP.
Authors’ addresses: N. Leone and S. Perri, Department of Mathematics, University of Calabria,
87030 Rende (CS), Italy; email: {leone,perri}@mat.unical.it; G. Pfeifer, W. Faber, T. Eiter,
and G. Gottlob, Institut für Informationssysteme, Technische Universität Wien, Favoritenstrasse
9-11, A-1040 Vienna, Austria; email: [email protected], {faber,eiter}@kr.tuwien.ac.at,
[email protected]; F. Scarcello, DEIS Department, University of Calabria, 87030 Rende
(CS), Italy; email: [email protected].
Permission to make digital or hard copies of part or all of this work for personal or classroom use is
granted without fee provided that copies are not made or distributed for profit or direct commercial
advantage and that copies show this notice on the first page or initial screen of a display along
with the full citation. Copyrights for components of this work owned by others than ACM must be
honored. Abstracting with credit is permitted. To copy otherwise, to republish, to post on servers,
to redistribute to lists, or to use any component of this work in other works requires prior specific
permission and/or a fee. Permissions may be requested from Publications Dept., ACM, Inc., 1515
Broadway, New York, NY 10036 USA, fax: +1 (212) 869-0481, or [email protected].
C 2006 ACM 1529-3785/06/0700-0499 $5.00
ACM Transactions on Computational Logic, Vol. 7, No. 3, July 2006, Pages 499–562.
500 • N. Leone et al.
developed on top of DLV to solve specific knowledge representation tasks, and we briefly describe
the main international projects investigating the potential of the system for industrial exploitation.
Finally, we report about thorough experimentation and benchmarking, which has been carried out
to assess the efficiency of the system. The experimental results confirm the solidity of DLV and
highlight its potential for emerging application areas like knowledge management and information
integration.
Categories and Subject Descriptors: I.2.3 [Artificial Intelligence]: Deduction and Theorem
Proving—Nonmonotonic reasoning and belief revision; I.2.4 [Artificial Intelligence]: Knowledge
Representation Formalisms and Methods—Representation languages, representations (procedural
and rule-based); D.3.1 [Programming Languages]: Formal Definitions and Theory
General Terms: Theory, Algorithms, Performance
Additional Key Words and Phrases: Answer sets, computational complexity, implementation,
knowledge representation, nonmonotonic reasoning, stable models
1. INTRODUCTION
The need for representing and manipulating complex knowledge arising in ar-
tificial intelligence and in other emerging areas, like knowledge management
and information integration (see also Section 8), has renewed the interest in
advanced logic-based formalisms for knowledge representation and reasoning
(KR&R), which started in the early 1980s. Among them, Disjunctive Logic Pro-
gramming (DLP), which was first considered by Minker [1982] in the deductive
database context, is one of the most expressive KR&R formalisms.
Disjunctive logic programs are logic programs where disjunction is allowed
in the heads of the rules and negation may occur in the bodies of the rules. Such
programs are now widely recognized as a valuable tool for knowledge represen-
tation and commonsense reasoning [Baral and Gelfond 1994; Lobo et al. 1992;
Wolfinger 1994; Eiter et al. 1999; Gelfond and Lifschitz 1991; Lifschitz 1996;
Minker 1994; Baral 2003]. One of the attractions of disjunctive logic program-
ming (DLP) is its capability of allowing the natural modeling of incomplete
knowledge [Baral and Gelfond 1994; Lobo et al. 1992]. Much research has been
spent on the semantics of disjunctive logic programs, and several alternative
semantics have been proposed [Brass and Dix 1995; Eiter et al. 1997c; Gelfond
and Lifschitz 1991; Minker 1982; Przymusinski 1990, 1991, 1995; Ross 1990;
Sakama 1989] (see Apt and Bol [1994], Dix [1995], Lobo et al. [1992], and Minker
[1994, 1996] for comprehensive surveys). The most widely accepted semantics
is the answer sets semantics proposed by Gelfond and Lifschitz [1991] as an
extension of the stable model semantics of normal logic programs [Gelfond and
Lifschitz 1988]. According to this semantics, a disjunctive logic program may
have several alternative models (but possibly none), called answer sets, each
corresponding to a possible view of the world.
Disjunctive logic programs under answer sets semantics are very expressive.
It was shown in Eiter et al. [1997b] and Gottlob [1994] that, under this seman-
tics, disjunctive logic programs capture the complexity class 2P (i.e., they allow
us to express, in a precise mathematical sense, every property of finite struc-
tures over a function-free first-order structure that is decidable in nondeter-
ministic polynomial time with an oracle in NP). As Eiter et al. [1997b] showed,
ACM Transactions on Computational Logic, Vol. 7, No. 3, July 2006.
DLV System for Knowledge Representation and Reasoning • 501
1 The term Answer Set Programming was coined by Vladimir Lifschitz in his invited talk at ICLP’99
2. CORE LANGUAGE
In this section, we provide a formal definition of the syntax and the semantics of
the kernel language of DLV, which is disjunctive datalog under the answer sets
semantics [Gelfond and Lifschitz 1991]2 (which involves two kinds of negation),
extended with weak constraints. For further background, see Lobo et al. [1992],
Eiter et al. [1997b], and Gelfond and Lifschitz [1991].
2.1 Syntax
Following Prolog’s convention, strings starting with uppercase letters denote
variables, while those starting with lower case letters denote constants. In ad-
dition, DLV also supports positive integer constants and arbitrary string con-
stants, which are embedded in double quotes. A term is either a variable or a
constant.
An atom is an expression p(t1 , . . .,tn ), where p is a predicate of arity n and
t1 ,. . . ,tn are terms. A classical literal l is either an atom p (in this case, it is
positive), or a negated atom ¬ p (in this case, it is negative). A negation as failure
(NAF) literal is of the form l or not l , where l is a classical literal; in the former
case is positive, and in the latter case negative. Unless stated otherwise, by
literal we mean a classical literal.
Given a classical literal l , its complementary literal ¬l is defined as ¬ p if
l = p and p if l = ¬ p. A set L of literals is said to be consistent if, for every
literal l ∈ L, its complementary literal is not contained in L.
Moreover, DLV provides built-in predicates such as the comparative predi-
cates equality, less than, and greater than (=, <, >), and arithmetic predicates
2 See footnote 4.
like addition or multiplication. For details, we refer the reader to Faber and
Pfeifer [1996].
A disjunctive rule (rule, for short) r is a formula
a1 v · · · v an :- b1 , . . . , bk , not bk+1 , . . . , not bm . (1)
where a1 , . . . , an , b1 , . . . , bm are classical literals and n ≥ 0, m ≥ k ≥
0. The disjunction a1 v · · · v an is the head of r, while the conjunction
b1 , . . . , bk , not bk+1 , . . . , not bm is the body of r. A rule without head literals
(i.e., n = 0) is usually referred to as an integrity constraint. A rule having pre-
cisely one head literal (i.e., n = 1) is called a normal rule. If the body is empty
(i.e., k = m = 0), it is called a fact, and we usually omit the “ :- ” sign.
The following notation will be useful for further discussion. If r is a rule
of form (1), then H(r) = {a1 , . . ., an } is the set of the literals in the head and
B(r) = B+ (r) ∪ B− (r) is the set of the body literals, where B+ (r) (the positive
body) is {b1 ,. . . , bk } and B− (r) (the negative body) is {bk+1 , . . . , bm }.
A disjunctive datalog program (alternatively, disjunctive logic program, dis-
junctive deductive database) P is a finite set of rules. A not-free program P
(i.e., such that ∀r ∈ P : B− (r) = ∅) is called positive3 and a v-free program P
(i.e., such that ∀r ∈ P : |H(r)| ≤ 1) is called datalog program (or normal logic
program, deductive database).
The language of DLV extends disjunctive datalog by another construct, which
is called weak constraint [Buccafurri et al. 2000]. We define weak constraints
as a variant of integrity constraints. In order to differentiate clearly between
them, we use for weak constraints the symbol ‘:∼’ instead of ‘ :- ’. Additionally,
a weight and a priority level of the weak constraint are specified explicitly.
Formally, a weak constraint wc is an expression of the form
:∼ b1 , . . . , bk , not bk+1 , . . . , not bm . [w : l ].
where for m ≥ k ≥ 0, b1 , . . . , bm are classical literals, while w (the weight) and l
(the level, or layer) are positive integer constants or variables. For convenience,
w and/or l might be omitted and are set to 1 in this case. The sets B(wc), B+ (wc),
and B− (wc) of a weak constraint wc are defined in the same way as for regular
integrity constraints.
A DLV program P (program, for short) is a finite set of rules (possibly includ-
ing integrity constraints) and weak constraints. In other words, a DLV program
P is a disjunctive datalog program possibly containing weak constraints. For a
program P, let W C(P) denote the set of weak constraints in P, and let Rules(P)
denote the set of rules (including integrity constraints) in P.
A rule is safe if each variable in that rule also appears in at least one positive
literal in the body of that rule which is not a comparative built-in. A program
is safe if each of its rules is safe, and in the following we will only consider safe
programs.
As usual, a term (an atom, a rule, a program, etc.) is called ground if no
variable appears in it. A ground program is also called a propositional program.
3 Inpositive programs negation as failure (not) does not occur, while strong negation (¬) may be
present.
2.2 Semantics
The semantics of DLV programs extends the (consistent) answer sets semantics
of disjunctive datalog programs, originally defined in Gelfond and Lifschitz
[1991], to deal with weak constraints. The semantics provided in this section is
a slight generalization of the original semantics proposed for weak constraints
in Buccafurri et al. [2000]. In particular, the original language allowed only
“prioritized weak constraints,” while the DLV language allows both priority
levels (layers) and weights for weak constraints.
— Herbrand Universe. For any program P, let UP (the Herbrand Universe) be
the set of all constants appearing in P. In case no constant appears in P, an
arbitrary constant ψ is added to UP .
— Herbrand Literal Base. For any program P, let BP be the set of all ground
(classical) literals constructible from the predicate symbols appearing in P
and the constants of UP (note that, for each atom p, BP contains also the
strongly negated literal ¬ p).
— Ground instantiation. For any rule r, Ground(r) denotes the set of rules ob-
tained by applying all possible substitutions σ from the variables in r to ele-
ments of UP . In a similar way, given a weak constraint w, Ground(w) denotes
the set of weak constraints obtained by applying all possible substitutions σ
from the variables in w to elements of UP . For any program P, Ground(P)
the set GroundRules(P) ∪ Ground W
denotes C(P), where GroundRules(P) =
Ground(r) and Ground W C(P) = Ground(w).
r∈Rules(P) w∈W C(P)
Note that for propositional programs, P = Ground(P) holds.
— Answer sets. For every program P, we define its answer sets using its ground
instantiation Ground(P) in three steps: first we define the answer sets of pos-
itive disjunctive datalog programs, then we give a reduction of disjunctive
datalog programs containing negation as failure to positive ones and use it
to define answer sets of arbitrary disjunctive datalog programs, possibly con-
taining negation as failure. Finally, we specify the way how weak constraints
affect the semantics, defining the semantics of general DLV programs.
An interpretation I is a set of ground classical literals, that is, I ⊆ BP
with respect to a program P. A consistent interpretation X ⊆ BP is called
closed under P (where P is a positive disjunctive datalog program) if, for every
r ∈ Ground(P), H(r) ∩ X = ∅ whenever B(r) ⊆ X . An interpretation X ⊆ BP is
an answer set for a positive disjunctive datalog program P if it is minimal (under
set inclusion) among all (consistent) interpretations that are closed under P.4
Example 2.1. The positive program P1 = {a v ¬b v c.} has the answer sets
{a}, {¬b}, and {c}. Its extension P2 = {a v ¬b v c. ; :- a.} has the answer sets
{¬b} and {c}. Finally, the positive program P3 = {a v ¬b v c. ; :- a. ; ¬b :- c. ;
c :- ¬b.} has the single answer set {¬b, c}.
4 Note that we only consider consistent answer sets, while in Gelfond and Lifschitz [1991] the in-
consistent set of all possible literals also can be a valid answer set.
5 Highervalues for weights and priority levels mark weak constraints of higher importance. For
example, the most important constraints are those having the highest weight among those with
the highest priority level.
P P
where wmax and l max denote the maximum weight and maximum level over
the weak constraints in P, respectively; NiP (A) denotes the set of the weak
constraints in level i that are violated by A, and wei g ht(w) denotes the weight
P
of the weak constraint w. Note that |W C(P)| · wmax + 1 is greater than the sum
of all weights in the program, and therefore guaranteed to be greater than the
sum of weights of any single level.
Intuitively, the function f P handles priority levels. It guarantees that the
violation of a single constraint of priority level i is more “expensive” then the
violation of all weak constraints of the lower levels (i.e., all levels < i).
For a DLV program P (possibly with weak constraints), a set A is an (optimal)
answer set of P if and only if (1) A is an answer set of Rules(P) and (2) H P (A)
is minimal over all the answer sets of Rules(P).
Example 2.4. Consider the following program Pwc , which has three weak
constraints:
a v b.
b v c.
d v ¬d :- a, c.
:∼b. [1 : 2]
:∼a, ¬d . [4 : 1]
:∼c, d . [3 : 1]
Rules(Pwc ) admits three answer sets: A1 = {a, c, d }, A2 = {a, c, ¬d }, and
A3 = {b}. We have: H Pwc (A1 ) = 3, H Pwc (A2 ) = 4, H Pwc (A3 ) = 13. Thus, the
unique (optimal) answer set is {a, c, d } with weight 3 in level 1 and weight 0 in
level 2.
Remark 2.5. In the ground case (actually, only in the ground case),
weak constraints can be mapped to Smodels “minimize” statements. A weak
constraint
:∼b1 , . . . , bn . [w : l ]
is replaced by the rule
γ :- b1 , . . . , bn .
and the statement
minimize [γ = w],
where γ is a new atom. The priority level l of weak constraints is ex-
pressed by the order of the minimize statements in Smodels program
(the first minimize statement has highest priority). For instance, the three
weak constraints of Example 2.4 can be translated in Smodels language as
follows.
γ1 :- b.
γ2 :- a, ¬d .
γ3 :- c, d .
minimize [γ1 = 1].
minimize [γ2 = 4, γ3 = 3].
ACM Transactions on Computational Logic, Vol. 7, No. 3, July 2006.
508 • N. Leone et al.
However, in the general (nonground) case, we do not see any uniform mapping
from weak constraints with variables to Smodels constructs.
Unlike Prolog, the order of the rules and the subgoals (literals) in rules bod-
ies does not matter and has no effect on the semantics. In particular, it does not
affect the termination of program evaluation, which is not guaranteed under
Prolog semantics if, for example, the last literal in the second rule is reordered
to the first position. Like other ASP systems, DLV thus supports a fully mod-
ular, rule-by-rule encoding of problems, where the semantics of each rule is
independent of its context.
3.2.2 Problems Beyond 2P . For problems which are beyond 2P , and in
particular for 2P -complete problems, the layered program schema above no
longer applies. If G has complexity in NP, which is the case if disjunction is just
used for making the guess and the layer is head-cycle free [Ben-Eliyahu and
Dechter 1994], then an answer set A of G∪F I can be guessed in polynomial time,
that is, nondeterministically created with a polynomial number of steps. Hence,
it can be shown easily that computing an answer set of the whole program,
G∪C∪F I ∪O, is feasible in polynomial time with an NPoracle. Thus, applicability
ACM Transactions on Computational Logic, Vol. 7, No. 3, July 2006.
DLV System for Knowledge Representation and Reasoning • 511
of the same schema to 2P -hard problems would imply 2P ⊆ 2P , which is widely
believed to be false.
Until now we tacitly assumed an intuitive layering of the program parts,
such that the checking part C has no “influence” or “feedback” on the guessing
part G, in terms of literals which are derived in C and invalidate the application
of rules in G, or make further rules in G applicable (and thus change the guess).
This can be formalized in terms of a “potentially uses” relation [Eiter et al.
1997b] or a “splitting set” condition [Lifschitz and Turner 1994]. Complexity-
wise, this can be relaxed to the property that the union of the program parts is
head-cycle free.
In summary, if a program solves a 2P -complete problem and has guessing
and checking parts G and C, respectively, with complexities below 2P , then
C must either contain disjunctive rules or interfere with G (and in particular
head-cycles must be present in G ∪ C).
We close this subsection with remarking that the GCO programming method-
ology has also positive implications from the software engineering viewpoint.
Indeed, the modular program structure in GCO allows for developing programs
incrementally, which is helpful to simplify testing and debugging. One can start
by writing the guessing part G and testing that G ∪ F I correctly defines the
search space. Then, one adds the checking part and verifies that the answer sets
of G ∪C ∪F I encode the admissible solutions. Finally, one tests that G ∪C ∪F I ∪O
generates the optimal solutions of the problem at hand.
This problem can be encoded in the DLV language by the following GCO
program Psch :
assign(Id, t1 ) v assign(Id, t2 ) v assign(Id, t3 ) :- exam(Id, P, C, Y ). Guess
:- assign(Id, T ), assign(Id , T ),
Check
Id <> Id , exam(Id, P, C, Y ), exam(Id , P, C , Y ).
⎫
:∼assign(Id, T ), assign(Id , T ) ⎪
⎪
⎬
exam(Id, P, C, Y ), exam(Id , P , C, Y ), Id <> Id . [: 2]
Optimize
:∼assign(Id, T ), assign(Id , T ) ⎪
⎪
⎭
exam(Id, P, C, Y ), exam(Id , P , C, Y ), Y <> Y . [: 1]
The guessing part G has a single disjunctive rule defining the search space.
It is evident that the answer sets of G ∪ F I are the possible assignments of
exams to time slots.
The checking part C consists of one integrity constraint, discarding the as-
signments of the same time slot to two exams of the same professor. The answer
sets of G ∪ C ∪ F I correspond precisely to the admissible solutions, that is, to all
assignments which satisfy the constraint S1.
Finally, the optimizing part O consists of two weak constraints with differ-
ent priorities. Both weak constraints state that exams of the same curriculum
should possibly not be assigned to the same time slot. However, the first one,
which has higher priority (level 2), states this desire for the exams of the cur-
riculum of the same year, while the second one, which has lower priority (level
1) states it for the exams of the curriculum of different years. The semantics of
weak constraints, as given in Section 2.2, implies that O captures precisely the
constraints S2 of the scheduling problem specification. Thus, the answer sets
of G ∪ C ∪ F I ∪ O correspond precisely to the desired schedules.
Suppose that the graph G is specified by using facts over predicates node
(unary) and arc (binary), and the starting node a is specified by the predi-
cate start (unary). Then the following GCO program Php solves the problem
HAMPATH (no optimization part is needed here):
⎫
inPath(X , Y ) v outPath(X , Y ) :- start(X ), arc(X , Y ). ⎬
inPath(X , Y ) v outPath(X , Y ) :- reached(X ), arc(X , Y ). Guess
⎭
reached(X ) :- inPath(Y, X ). (aux.)
⎫
:- inPath(X , Y ), inPath(X , Y 1), Y <> Y 1. ⎬
:- inPath(X , Y ), inPath(X 1, Y ), X <> X 1. Check
⎭
:- node(X ), not reached(X ), not start(X ).
ACM Transactions on Computational Logic, Vol. 7, No. 3, July 2006.
DLV System for Knowledge Representation and Reasoning • 513
The two disjunctive rules guess a subset S of the arcs to be in the path,
while the rest of the program checks whether S constitutes a Hamilto-
nian Path. Here, an auxiliary predicate reached is used, which is associated
with the guessed predicate inPath using the last rule. Note that reached
is completely determined by the guess for inPath, and no further guess-
ing is needed: from the outside, this assignment to reached is an “educated
guess” for this predicate, which is more appealing than a blind guess, us-
ing a rule “reached(X ) v ¬reached(X ) :- node(X ).” and subsequently checking
whether reached is compatible with the guess for inPath.
In turn, through the second rule, the predicate reached influences the guess of
inPath, which is made somehow inductively: initially, a guess on an arc leaving
the starting node is made by the first rule, followed by repeated guesses of arcs
leaving from reached nodes by the second rule, until all reached nodes have
been handled.
In the checking part, the first two constraints ensure that the set of arcs S
selected by inPath meets the following requirements, which any Hamiltonian
Path must satisfy: (i) there must not be two arcs starting at the same node, and
(ii) there must not be two arcs ending in the same node. The third constraint
enforces that all nodes in the graph are reached from the starting node in the
subgraph induced by S.
We remark that the above encoding may appear a bit advanced for the
unexperienced DLV user. A less sophisticated one guesses for each arc whether
it is in the path (i.e., replace the guessing part with a single rule inPath(X , Y )
v outPath(X , Y ) :- arc(X , Y )), and defines the predicate reached in the checking
part by rules reached(X ) :- start(X ) and reached(X ) :- reached(Y ), inPath(Y, X )
However, this encoding is less preferable from a computational point of view,
because it leads to a larger search space.
It is easy to see that any set of arcs S which satisfies all three constraints
must contain the arcs of a path v0 , v1 , . . . , vk in G that starts at node v0 = a,
and passes through distinct nodes until no further node is left, or it arrives at
the starting node a again. In the latter case, this means that the path is in
fact a Hamiltonian Cycle (from which a Hamiltonian Path can be immediately
computed, by dropping the last arc).
Thus, given a set of facts F for node, arc, and start, the program Php ∪ F has
an answer set if and only if the corresponding graph has a Hamiltonian Path.
The above program correctly encodes the decision problem of deciding whether
a given graph admits a Hamiltonian Path or not.
This encoding is very flexible, and can be easily adapted to solve the search
problems Hamiltonian Path and Hamiltonian Cycle (where the result has to
be a tour, i.e., a closed path). If we want to be sure that the computed result is
an open path (i.e., it is not a cycle), we can easily impose openness by adding
a further constraint :- start(Y ), inPath( , Y ). to the program (like in Prolog,
the symbol ‘ ’ stands for an anonymous variable whose value is of no interest).
Then, the set S of selected arcs in any answer set of Php ∪ F constitutes a
Hamiltonian Path starting at a. If, on the other hand, we want to compute the
Hamiltonian cycles, then we just have to strip off the literal not start(X ) from
the last constraint of the program.
ACM Transactions on Computational Logic, Vol. 7, No. 3, July 2006.
514 • N. Leone et al.
Given a set of facts F for nod e, arc, and start which specifies the input instance,
it is easy to see that the (optimal) answer sets of Ptsp ∪ F are in a one-to-one
correspondence with the optimal tours of the input graph.
Definition 3.3 (RAMSEY). The Ramsey number R(k, m) is the least integer
n such that, no matter how we color the arcs of the complete undirected graph
(clique) with n nodes using two colors, say red and blue, there is a red clique
with k nodes (a red k-clique) or a blue clique with m nodes (a blue m-clique).
Ramsey numbers exist for all pairs of positive integers k and m [Radziszowski
1994]. We next show a program Pramse y that allows us to decide whether a given
integer n is not the Ramsey Number R(3, 4). By varying the input number n,
we can determine R(3, 4), as described below. Let F be the collection of facts for
input predicates node and arc encoding a complete graph with n nodes. Pramse y
is the following GCO program:
blue(X , Y ) v red(X , Y ) :- arc(X , Y ). Guess
⎫
:- red(X , Y ), red(X , Z ), red(Y, Z ). ⎬
:- blue(X , Y ), blue(X , Z ), blue(Y, Z ), Check
⎭
blue(X , W ), blue(Y, W ), blue(Z , W ).
Intuitively, the disjunctive rule guesses a color for each edge. The first constraint
eliminates the colorings containing a red clique (i.e., a complete graph) with
three nodes, and the second constraint eliminates the colorings containing a
blue clique with four nodes. The program Pramse y ∪ F has an answer set if
and only if there is a coloring of the edges of the complete graph on n nodes
containing no red clique of size 3 and no blue clique of size 4. Thus, if there is
an answer set for a particular n, then n is not R(3, 4), that is, n < R(3, 4). On
the other hand, if Pramse y ∪ F has no answer set, then n ≥ R(3, 4). Thus, the
smallest n such that no answer set is found is the Ramsey number R(3, 4).
The problems considered so far are at the first level of the Polynomial Hi-
erarchy; their complexities, in the ground case, do not exceed 2P , which is
usually placed at the first level, since it is computationally much closer to NP
than to 2P ). We next show that also problems located at the second level of the
Polynomial Hierarchy can be encoded by the GCO technique.
3.3.5 Quantified Boolean Formulas (2QBF). The first problem at the sec-
ond level of the Polynomial Hierarchy which we consider is the canonical 2P -
complete problem 2QBF [Papadimitriou 1994]. Here, we have to decide whether
a quantified Boolean formula (QBF) of the shape = ∃X ∀Y φ, where X and
Y are disjoint sets of propositional variables and φ = C1 ∨ . . . ∨ Ck is a 3DNF
formula over X ∪ Y , evaluates to true. Moreover, in this case, we may want to
have a witnessing assignment σ to the variables X , that is, an assignment σ
such that φ[X /σ (X )] is a tautology, where X /σ (X ) denotes the substitution of
X by σ (X ).6 This naturally leads to a Guess & Check disjunctive logic program,
in which the witness assignment σ is guessed by some rules and the rest of the
program is devoted to checking whether φ[X /σ (X )] is a tautology.
Our encoding is a variant of the reduction of 2QBF into a propositional DLP
in Eiter and Gottlob [1995]. Here, a QBF as above is encoded as a set of facts
6 Note that such a witness does no exist for universally quantified formulas of shape ∀X ∃Y φ.
The guessing rule rs1 intuitively selects one of the companies c1 and c2 that
produce some item g , which is described by prod by( g , c1 , c2 ). If there were no
company control information, minimality of answer sets would naturally ensure
that the answer sets of F ∪ {rs1 } correspond to the strategic sets; no further
checking would be needed. However, in case control information is available,
the rule rs2 checks that no company is sold that would be controlled by other
companies in the strategic set, by simply requesting that this company must be
strategic as well. The minimality of the strategic sets is automatically ensured
by the minimality of answer sets.
The answer sets of Pstrat ∪ F correspond one-to-one to the strategic sets of
the holding described in F; a company c is thus strategic iff strat(c) is in some
answer set of Pstrat ∪F.
An important note here is that the checking “constraint” rs2 interferes with
the guessing rule rs1 : applying rs2 may “spoil” the minimal answer set generated
by rs1 . For example, suppose the guessing part gives rise to a ground rule rsg 1
strat(c1) v strat(c2) :- prod by( g , c1, c2).
and the fact prod by( g , c1, c2) is given in F. Now suppose the rule is satisfied
in the guessing part by making strat(c1) true. If, however, in the checking part
an instance of rule rs2 is applied which derives strat(c2), then the application of
the rule rsg1 to derive strat(c1) is invalidated, as the minimality of answer sets
implies that strat(c1) cannot be derived from the rule rsg1 if another atom in its
head is true.
By the complexity considerations in Section 3.2, such interference is needed
to solve STRATCOMP in the above way (without disjunctive rules in the Check
part), since deciding whether a particular company is strategic is 2P -complete.
If Pstrat is rewritten to eliminate such interference and layer the parts hier-
archically, then further disjunctive rules must be added. An encoding which
expresses the strategic sets in the generic GCO paradigm with clearly sepa-
rated guessing and checking parts is given in Eiter et al. [2000a].
Note that, as described in Remark 2.3, the program above cannot be replaced
by a simple normal (nondisjunctive) program. Intuitively, this is due to the fact
that disjunction in the head of rules is not exclusive, while at the same time
answer sets are subset-minimal. Using techniques like the ones in Eiter et al.
[2003a], Pstrat can be extended to support an arbitrary number of producers per
product and controlling companies per company, respectively.
handle this quite naturally. Let us assume for simplicity that the president’s
preferences are represented by a single predicate avoid (csell , ckeep , pr), which
intuitively states that selling csell while keeping ckeep should be avoided with
priority pr; in the above example, the preferences would be avoid(a, c , top),
avoid(b, c, top−1), avoid(d , c , top−1), . . . , where c is a dummy company which
belongs to every strategic set, and top is the highest priority number. Then, we
can easily represent this more complicated problem, by adding the following
weak constraint to the original encoding for STRATCOMP:
The (optimal) answer sets of the resulting program then correspond to the
solutions of the above problem.
0P = 0P = 0P = P; and for all k ≥ 1, kP = Pk−1 , kP = NPk−1 , kP = co-kP ,
P P
where NPC denotes the class of decision problems that are solvable in polyno-
mial time on a nondeterministic Turing machine with an oracle for any decision
problem π in the class C. In particular, NP = 1P , co-NP = 1P , and 2P = PNP .
The oracle replies to a query in unit time, and thus, roughly speaking, models
a call to a subroutine for π that is evaluated in unit time.
Observe that, for all k ≥ 1,
kP ⊆ k+1
P
⊆ k+1
P
⊆ PSPACE,
ACM Transactions on Computational Logic, Vol. 7, No. 3, July 2006.
520 • N. Leone et al.
(1) for any l ∈ B+ (r), and for any l ∈ H(r), ||l ||s ≤ ||l ||s ;
(2) for any l ∈ B− (r), and for any l ∈ H(r), ||l ||s < ||l ||s ;
(3) for any l , l ∈ H(r), ||l ||s = ||l ||s .
As for P8 , an admissible level mapping would need to satisfy || p(a)||s < ||q(b)||s
and ||q(b)||s < || p(a)||s , which is impossible.
(1) for any l ∈ B+ (r), and for any l ∈ H(r), ||l ||h ≤ ||l ||h ;
(2) for any pair l , l ∈ H(r) ||l ||h = ||l ||h .
P9 : a v b.
a :- b.
ACM Transactions on Computational Logic, Vol. 7, No. 3, July 2006.
DLV System for Knowledge Representation and Reasoning • 521
7 Following Buccafurri et al. [2000], possible restrictions on the support of negation affect Rules(P),
that is, the rules (including the integrity constraints) of the program, while weak constraints, if
allowed, can freely contain both positive and negative literals in any fragment of the DLV language
we consider.
denotes the fragment allowing head-cycle free disjunction and stratified nega-
tion, but no weak constraints.
all closed interpretations not containing q̄ must contain nq̄ and are hence in-
comparable with M (with respect to set inclusion). Moreover, observe that the
cost of M is H P ( M ) = 1.
We show that M is not an (optimal) answer set for P if and only if there is
some answer set M for P containing q.
Indeed, suppose that M is not an optimal answer set for P . Then there is
an (optimal) answer set M for P having cost H P (M ) = 0, that is, all weak
constraints are satisfied. By the first one, we conclude that q̄ ∈/ M , which, by
the first rule in P , implies that nq̄ ∈ M . Thus, by the second weak constraint,
we have that q ∈ M . By the minimality of M , we furthermore obtain that
q̄ ∈
/ M . Now it is easy to see that M = M − {nq̄} is an answer set of P which
contains q.
Conversely, consider any answer set M for P containing the atom q. It is easy
to see that M = M ∪{nq̄} is an answer set for Rules(P ). Moreover, H P (M ) = 0;
hence, M is not an optimal answer set for P . This proves the claim.
Clearly, P is computable in polynomial time from P and q. Moreover, if P is
head-cycle free, then P is head-cycle free too. Indeed, a new “bad” cycle would
imply that one of the fresh atoms q̄, q̄ , and nq̄ already occured in the body of
some rule and also in the head of some rule with nonempty body. Obviously,
this is not the case.
THEOREM 4.14. Checking whether a given model M is an answer set for a
DLV program P is
(1) P-complete if P belongs to DLV[nots , w]; hardness holds even if P is positive;
(2) co-NP-complete if P belongs to DLV[vh , not, w]; hardness holds even if P is
either positive or nondisjunctive;
(3) 2P -complete if P belongs to DLV[v, not, w]; hardness holds even if P is pos-
itive.
PROOF. (1). A DLV[nots , w] program P has a unique answer set, computable
in polynomial time. Thus, weak constraints do not affect the complexity of this
problem, which remains the same as for DLV[nots ] and DLV[] programs, namely,
P-completeness. The hardness part for the latter is obtained by an easy reduc-
tion from deciding whether an atom A is in the answer set of a DLV[] program
P: just add clauses p :- A. for all p ∈ BP and check whether BP is the answer
set of the resulting program.
(2). Membership. Let P be a program in DLV[vh , not, w], and M be a set of
ground literals. We can check that M is not an answer set for P as follows.
First we verify in polynomial time whether M is an answer set for Rules(P). If
this is not the case, we stop. Otherwise, we compute its cost c = H P (M ), and
then decide whether there exists an answer set M for P such that H P (M ) < c.
From Lemma 4.9, this task is feasible in NP, and thus the checking problem
is in co-NP.
Hardness. Recall that, given a DLV[vh ] program P and an atom q, deciding
whether q ∈ / M for each answer set of P is co-NP-complete cf. Eiter et al.
[1998b]. From Lemma 4.13, this problem can be reduced to answer set checking
for DLV[vh , w] programs.
ACM Transactions on Computational Logic, Vol. 7, No. 3, July 2006.
DLV System for Knowledge Representation and Reasoning • 527
Moreover, it is well known that, for each DLV[vh ] program P, we can construct
in polynomial time a DLV[not] program having the same answer sets as P
by replacing disjunction by unstratified negation [Ben-Eliyahu and Dechter
1994]. The same reduction clearly allows us to reduce answer set checking for
DLV[vh , w] programs to answer set checking for DLV[not, w] programs. Thus,
the latter problem is co-NP-hard, as well.
(3). Membership. Let P be a program in DLV[v, not, w], and M be a set of
ground literals. We show that the complementary problem of checking that M
is not an answer set for P is in 2P . First we decide in co-NP whether M is an
answer set for Rules(P) or not. If this is not the case, we stop. Otherwise, we
compute its cost c = H P (M ) and then decide whether there exists an answer
set M for P such that H P (M ) < c. This is feasible in 2P , according to Lemma
4.6.
Hardness. Deciding whether a given literal is not contained in any answer
set of a DLV[v] program is 2P -complete [Eiter et al. 1997b]. From Lemma 4.13
it follows that this problem can be reduced to answer set checking for DLV[v, w]
programs.
of DLV is strictly more expressive than Disjunctive Datalog (unless the poly-
nomial hierarchy collapses). For instance, the Preferred Strategic Companies
problem in Section 3.3.7 can be naturally expressed in the full DLV language,
but it cannot be expressed at all if weak constraints are disallowed.
5. DLV FRONT-ENDS
Besides its kernel, the DLV system offers a number of front-ends for various
domain-specific reasoning formalisms, for which we provide brief overview in
this section. For in-depth descriptions and download information for executa-
bles, we must refer to the quoted sources.
Currently, the DLV system has “internal” front-ends for inheritance rea-
soning, model-based diagnosis, planning, and SQL3 query processing; several
“external” front-ends have been made available by other research teams. Each
front-end maps its problem-specific input into a DLV program, invokes the DLV
kernel, and then postprocesses any answer set returned, extracting from it the
desired solution; optionally, further solutions are generated.
DLV’s built-in diagnosis front-end [Eiter et al. 1997a] supports, under cer-
tain restrictions, an instance of abductive diagnosis for T being a logic program
and consistency-based diagnosis for T under classical semantics. Moreover, it
offers computation of different types of diagnoses, namely, general, ⊆-minimal
(irredundant), and single failure diagnoses. The following simple example il-
lustrates the usage of logic program semantics.
Example 5.2 (Network Diagnosis). Suppose in the computer network of
Figure 1 machine a is up, but we observe that it cannot reach machine e. Which
machines are down?
This can be easily modeled as a diagnosis problem, where the theory T is the
logic program
reaches(X,X) :- node(X), not down(X ).
reaches(X,Z) :- reaches(X,Y), connected(Y,Z), not down(Z ).
the observations O are not down(a) and not reaches(a,e), and the hypotheses H
are down(a), . . . , down(f). Running the diagnosis front-end, we can compute all
diagnoses; the irredundant ones are down(e)}, {down(b), down(f)}, and {down(c),
down(d ), down(f)}. Note that a logic programming representation of T is bene-
ficial, since nonreachability is easily expressed; under classical semantics, this
is more cumbersome.
5.1.4 SQL3 Front-End. Different from earlier versions, SQL3 allows re-
cursive database queries. DLV’s built-in SQL3 front-end, available since the
early days, provides a playground for getting a grasp on SQL3, which for-
merly database systems did not support. It covers an SQL3 fragment, including
queries like the “list-of-materials” query.
5.1.5 Meta-Interpreter Front-End. A meta-interpretation technique for pri-
oritized logic programs is described in Eiter et al. [2001a, 2003a], devel-
oped for computing different notions of preferred answer sets from Brewka
and Eiter [1999] and Schaub and Wang [2001]. In this setting, a particu-
lar fixed program, the meta-interpreter, is used in combination with an in-
put prioritized logic program, which is represented by a set of facts. The
answer sets of the meta-interpreter augmented with the facts then corre-
spond to the preferred answer sets of the original prioritized program. The
meta-interpreters, several examples, and further information are available at
http://www.dlvsystem.com/preferred/.
5.2.2 Update Front-End. A front-end for update logic programs, that is,
sequences P = (P0 , . . . , Pn ) of extended logic programs Pi , where P0 is the
initial program and Pi , i > 0, represents an update at time i ∈ {1, 2, . . . , n},
is described in Eiter et al. [2001e]. The semantics of P, defined in Eiter et al.
ACM Transactions on Computational Logic, Vol. 7, No. 3, July 2006.
DLV System for Knowledge Representation and Reasoning • 533
[2002c], extends standard answer sets for a single program (n = 1). The front-
end supports different reasoning tasks and was used to realize policies for up-
dating knowledge bases [Eiter et al. 2001d]; it is available for download at
http://www.kr.tuwien.ac.at/staff/giuliana/project.html.
5.2.3 The nlp Front-End. Most recent is the nlp front-end, which trans-
forms nested logic programs to Answer Set Programs; see Pearce et al. [2002]
for a description and http://www.cs.uni-potsdam.de/∼ torsten/nlp/ for a
prototype download.
6. THE IMPLEMENTATION OF THE DLV SYSTEM: AN OVERVIEW
The high expressiveness of the DLV language, together with the ambition to
deal efficiently also with larger instances of simpler problems, made the imple-
mentation of DLV system a challenging task.
The DLV core has three layers (see Figure 2), each of which is a powerful sub-
system per se: the Intelligent Grounder (IG; also Instantiator) has the power
of a deductive database system; the Model Generator (MG) is as powerful as a
Satisfiability Checker; and the Model Checker (MC) is capable of solving co-NP-
complete problems. These layers have been improved over the years through
the implementation of sophisticated data structures and of advanced optimiza-
tion techniques. It is infeasible to give a detailed description of the implemen-
tation of DLV in this article. Instead, we describe the general architecture of
DLV, illustrate the inspiring principles underlying the DLV system, and give an
overview of the main techniques which were employed in the implementation,
pointing the reader to specific articles that provide full details.
The system architecture of DLV is shown in Figure 2. The internal system
language is the one described in Section 2, and the DLV Core (the shaded part
of the figure) is an efficient engine for computing answer sets (one, some, or all)
of its input. In addition to various front-ends (described in Section 5), there is
a Graphical User Interface (GUI) that provides convenient access to some of
these front-ends as well as the system itself.
The implementation of the DLV system is based on very solid theoretical
foundations, and exploits the results on the computational complexity of DLV
language fragments discussed in Section 4. Ideally, the performance of a system
should reflect the complexity of the problem at hand, such that “easy” problems
ACM Transactions on Computational Logic, Vol. 7, No. 3, July 2006.
534 • N. Leone et al.
(say, those of polynomial complexity) are solved fast, while only harder problems
involve methods of higher run-time cost. Indeed, the DLV system is designed
according to this idea, and thrives to exploit the complexity results reported in
Section 4. Note that in general, without syntactic restrictions, it is impossible
to detect whether a program uniformly encodes an “easy” problem, since this
task is clearly undecidable.
For example, stratified normal programs (which have polynomial complex-
ity, as reported in Table I8 ) are evaluated solely using techniques from the
field of deductive databases, without employing the more complex techniques
which are needed to evaluate full DLV programs; in fact, such normal stratified
programs are evaluated without generating the program instantiation at all.
Datalog programs encoding deductive problems like Reachability or Same Gen-
eration (cf. Sections 3.1.1 and 3.1.2) and SQL3 front-end, which only generates
such programs, benefit from this and exhibit good performance.
The architecture of the DLV Core closely reflects complexity results for var-
ious subsets of our language. As mentioned before, the Intelligent Grounding
module is able to completely solve some problems which are known to be of
polynomial time complexity (like normal stratified programs); the Model Gen-
erator (together with the Grounding) is capable of solving NP-complete prob-
lems. Adding the Model Checker is needed to solve 2P -complete problems. The
WCH (Weak Constraints Handler) comes into play only in the presence of weak
constraints. More precisely, referring to the notation of Section 4, we have the
following five disjoint language classes L1 –L5 for evaluation:
— L1 contains the programs included in the class {}, {w, nots }, which all have
polynomial complexity. They are completely evaluated by the IG module,9
which runs in polynomial time (referring to propositional complexity).
— L2 contains the programs which are in the subclass corresponding to
{ vh }, {not}, but not in L1 . The complexity of this fragment is NP, and the
programs are evaluated by the MG module (besides the IG) with only a call to
the linear-time part of the MC module. Note that the MG implements a flat
backtracking algorithm and is suitable for solving NP-complete problems.
— L3 contains the DLV programs from { vh }, {not, w} minus L1 ∪ L2 . The com-
plexity of this fragment is 2P . Here, also the WCH module is employed,
which iteratively invokes the MG. Again, only the linear-time part of the MC
is invoked.
— L4 contains the programs from the subclass corresponding to { v }, {not}
minus L1 ∪ L2 ∪ L3 . The complexity of this fragment is 2P , and the programs
are evaluated by the MG module (besides the IG) with calls to the full MC
module. Note that a flat backtracking algorithm is not sufficient to evaluate
2P -complete problems, and such a nested evaluation scheme, with calls to
MC, is needed.
8 Note that the complexity of propositional DLV programs reported in Tables I–III coincides with
the data complexity of nonground DLV programs.
9 In this section, for evaluation we mean the process of generating an answer set of the input
— Finally, L5 contains all other programs, that is, those in the full class (cor-
responding to { v }, {not, w}) which are not contained in L1 ∪ L2 ∪ L3 ∪ L4 ,
where we have the full language complexity of 3P . The evaluation proceeds
as for L4 , but also the WCH module comes into play for handling the weak
constraints.
The three DLV modules, MG, MC, and WCH, thus deal with the three sources
of complexity denoted by (s1 ), (s2 ), and (s3 ) in Section 4; each of them is fully
activated only if the respective source of complexity is present in the program
at hand.
Let us now look at the evaluation flow of the DLV computation in some more
detail. Upon startup, the DLV Core or one of the front-ends parses the input
specified by the user and transforms it into the internal data structures of DLV.
In both cases, this is done efficiently (requiring only linear memory and time).
The input is usually read from text files, but DLV also provides a bridge to
relational databases through an ODBC interface, which allows for retrieving
facts stored in relational tables.
Using differential and other advanced database techniques (see Faber et al.
[1999]; Leone et al. [2001]) together with suitable data structures, the In-
telligent Grounding module then efficiently generates a ground instantiation
Ground(P) of the input that has the same answer sets as the full program in-
stantiation, but is much smaller in general. For example, in case of a stratified
program, the IG module already computes the single answer set, and does not
produce any instantiation.
The heart of the computation is then performed by the Model Generator and
the Model Checker. Roughly, the former produces some “candidate” answer
sets, the stability of which is subsequently verified by the latter. In presence
of weak constraints, further processing is needed, which is performed under
the control of the WCH module. Since the handling of weak constraints is
somehow orthogonal to the rest of the computation, we first focus on the
evaluation of standard disjunctive logic programs, describing the processing of
weak constraints later on.
The generation of the answer sets of a program P relies on a monotonic
operator WP [Leone et al. 1997] which extends the well-founded operator of van
Gelder et al. [1991] for normal programs to disjunctive programs. It is defined
in terms of a suitable notion of unfounded set. Intuitively, an unfounded set for
a disjunctive program P with respect to an interpretation I is a set of positive
literals that cannot be derived from P assuming the facts in I [Leone et al. 1997].
Briefly, the MG works as follows: first, WPω (∅) (the fixpoint of WP ) is computed,
which is contained in every answer set. If WPω (∅) is a total model, it is returned
as the (unique) answer set. Otherwise, moving from WPω (∅) toward the answer
sets, a literal (called possibly-true literal in Leone et al. [1997]), the truth of
which allows one to infer new atoms, is assumed true. Clearly the choice of
“good” possibly-true literals at each step (i.e., a sequence of possibly-true liter-
als that quickly leads to an answer set) is crucial for an efficient computation,
so we employ novel heuristics with extensive lookahead and also propagate
knowledge about choices that lead to inconsistency [Faber et al. 2001].
ACM Transactions on Computational Logic, Vol. 7, No. 3, July 2006.
536 • N. Leone et al.
10 By
cost of an answer set we mean the sum of the weights of the weak constraints violated by the
answer set, weighted according to their priority level—see Section 2.2.
purposes only and are not much concerned with efficiency; there are almost
no elaborated, robust implementations of DLP to evaluate the performance of
DLV against. Only the GnT system Janhunen et al. [2000, 2003] (described
below) is an efficient and robust implementation of DLP under the answer set
semantics, which we thus selected for an experimental comparison with DLV.
Furthermore, in order to elucidate the performance of DLV in comparison
with more specialized systems, we have also considered some efficient ASP
engines which are close relatives of DLV, but do not support disjunction. The
comparison of DLV with these systems is of other interest than its comparison
with DLP systems: it should provide an idea how disjunctive systems like DLV
and GnT compare (on natural disjunctive encodings) against nondisjunctive
systems which use unstratified negation. It is worthwhile noting, however,
that nondisjunctive ASP systems have lower expressiveness than DLV. In
particular, on benchmark problems in NP, DLV (and GnT as well) has an
overhead with respect to these systems since it is designed as a solver for a
larger class containing much harder problems, while nondisjunctive systems
are tailored for a special fragment in this class which is, in general, not
efficiently recognizable in a syntactic way.
Recently, the scientific community has made considerable efforts on the im-
plementation of answer set programming, and a number of systems nowadays
support this formalism to some extent [Anger et al. 2001; Aravindan et al.
1997; Babovich 2002; Chen and Warren 1996; Cholewiński et al. 1996, 1999;
East and Truszczyński 2000, 2001a, 2001b; Egly et al. 2000; Eiter et al. 1998a;
Janhunen et al. 2000; Janhunen et al. 2003; Lin and Zhao 2002; McCain and
Turner 1998; Niemelä and Simons 1997; Rao et al. 1997; Seipel and Thöne
1994; Simons et al. 2002]. Most of these systems have common roots, but differ
in several respects, especially in the languages they support.
For a comparison with DLP systems, we have considered ASP systems
whose languages are as close to Disjunctive Logic Programming (and to the
DLV language) as possible, since we feel that it is difficult to make a fair
comparison among systems supporting very different languages. We have
thus focused on systems supporting the full language of function-free logic
programs under the answer set semantics, including recursion and unstratified
negation. Among those, we preferred more widely used systems which are at
a more advanced engineering stage; several other ASP systems are research
prototypes implemented just for experimental purposes, and would need quite
some engineering work to be made efficient and robust.
In particular, in addition to GnT , we picked Smodels [Simons et al. 2002;
Niemelä et al. 2000; Niemelä and Simons 1997]—one of the most robust and
widely used ASP systems—and ASSAT [Lin and Zhao 2002], which is not as
widely used and robust as Smodels yet, but appeared to be very efficient in a cou-
ple of recent experimental comparisons [Simons et al. 2002; Lin and Zhao 2002].
It is worthwhile noting that another system named Cmodels [Babovich
2002] has recently emerged. Cmodels is similar in spirit to ASSAT, in that it
translates the logic program to a CNF theory and uses a SAT-solver for its eval-
uation. The original version of Cmodels required the input program to satisfy
a so called tightness condition, and it seems that this only applies to a single
ACM Transactions on Computational Logic, Vol. 7, No. 3, July 2006.
538 • N. Leone et al.
7.1.1 Smodels. [Simons et al. 2002; Niemelä et al. 2000; Niemelä and
Simons 1997]. This is one of the best-known and most widely used answer
set programming systems. It implements the answer set semantics for normal
logic programs extended by built-in functions as well as cardinality and weight
constraints for domain-restricted programs.
Disregarding the extension for cardinality and weight constraints, the
Smodels system takes as input normal (v-free) rules as described in Section 2.
Programs must be domain-restricted, which intuitively amounts to the fol-
lowing property: the predicate symbols in the program are divided into two
classes, namely, domain predicates and nondomain predicates, where the
former are predicates whose definition11 does not involve rules with negative
recursion [Syrjänen 2002]. Every rule must be domain-restricted in the sense
that every variable in that rule must appear in a domain predicate which
appears positively in the rule body.
In addition to normal rules, Smodels supports rules with cardinality and
weight constraints. To illustrate the idea on an example, the cardinality
constraint
1{a, b, not c}2.
holds in an answer set if at least 1 but at most 2 of the literals in the constraint
are satisfied by that answer set.
The instantiation module of Smodels is a separate application called Lparse,
which preprocesses the programs which are then evaluated by Smodels.
In our tests, we used the current versions of these two at the time of this
writing, Lparse 1.0.11 and Smodels 2.27, running them in a UNIX pipe and
measuring overall CPU time.
7.1.2 GnT [Janhunen et al. 2000, 2003]. This is a DLP system that extends
the Smodels language by disjunction rule heads, written as {a1 , . . . , an }. GnT
has been implemented on top of Smodels by means of a rewriting technique.
Roughly, a disjunctive input program P is rewritten to a nondisjunctive
11 The
definition of a predicate p contains all rules with head p plus the definitions of all predicates
appearing in the bodies of the rules with head p.
program P , such that the answer sets of P form a superset of the answer sets
of P. Program P is passed to Smodels for the evaluation, and each answer set
M produced is then processed by a nested call to Smodels, to check whether
M is also an answer set of P. GnT is not a strict generalization of Smodels in
that it does not support the full language of Smodels (in particular, it has no
cardinality constraints).
For our tests, we used GnT 2 as downloaded from http://www.tcs.hut.fi/
Software/gnt/ in April 2003, together with Lparse 1.0.11, running both in a
UNIX pipe and measuring overall CPU time.
7.1.4 Using the DLV Instantiator with Smodels, GnT, and ASSAT. In
addition to the “native” setting where Smodels, GnT , and ASSAT all employ
Lparse to compute the ground instantiation of their input, we also used the in-
stantiator mode of DLV (requested by the command-line option -instantiate),
where DLV just computes and prints the ground instantiation of its input which
ACM Transactions on Computational Logic, Vol. 7, No. 3, July 2006.
540 • N. Leone et al.
then can be fed to other systems. The actual invocation chain in this case was
dlv -instantiate | lparse | smodels/gnt2/assat
since Smodels, GnT , and ASSAT expect their input in a particular internal
format only supported by Lparse (which performs very efficiently when only
used as a filter to convert ground programs into that format, so in general the
extra time employed by Lparse here is negligible).
As far as the encodings are concerned, we did not look for tricky ones;
rather, we tried to exploit the expressiveness of the language to design simple
and declarative encodings. We kept the encodings as close as possible to the
standard DLP language,12 avoiding system-specific language features.13 In the
main comparison (DLV vs. GnT ), we ran the two systems precisely on the same
(disjunctive) encoding, when using the DLV instantiator for GnT ; also when
GnT was run with its native instantiator Lparse, we used nearly the same
encodings for the two systems (only some domain predicate had to be added
for GnT in some cases). Disregarding domain predicates, also for Smodels
and ASSAT we could use the same encodings adopted for DLV and GnT , by
just translating disjunction to unstratified negation in a straightforward way
(Smodels and ASSAT were not benchmarked on 2QBF and STRATCOMP,
since their languages miss the needed expressiveness).
All benchmark instances and encodings we have used are available on the
Web at http://www.dlvsystem.com/examples/tocl-dlv.zip.
We next specify the data and the encodings which we have used for the
experiments.
12 The language adopted in Gelfond and Lifschitz [1991] is generally acknowledged in the literature,
We did not need to adapt the encodings for GnT , Smodels, and ASSAT,
as the encoding from Section 3.1.2 already satisfies the domain restriction
constraint of Lparse.
15 Weused the domain predicate arc instead of node, since Lparse seems to produce a more advan-
tageous instantiation this way; cf. the discussion on the encodings of RAMSEY.
is found. In this way, solutions with a minimal number of push actions are
computed.
The puzzle in Figure 4 is solvable with six push actions, so each of the scripts
uses the corresponding ASP system to first prove that no solutions with one to
five push actions exist, and then to compute a solution with six push actions.
We used the same encoding also for GnT (just rewriting the disjunction in
GnT syntax).
We could not consider ASSAT and Smodels, as they lack support for
disjunction.
Fig. 6. 2QBFGW .
for each problem size, we report two graphs visualizing the average and the
maximum computation time, respectively, consumed by each system over the
50 instances of the same size. For HAMPATH we provide two such pairs of
graphs: the first for the “native” runs of the systems, the second for runs where
DLV served as the instantiator.
On average, DLV outperformed the other systems on the set of proposed
problems, but the results must be taken with some caveats since they depended
on the specific benchmark problems and, in some cases, also on the adopted
encodings. We next discuss the results of the experiments, grouping similar
cases together.
was run with DLV encodings where for ASSAT and Smodels disjunction (only appearing in the
“guessing rules”) was translated by unstratified negation.
Fig. 7. 2QBFCGS .
17 Recallthat Smodels and ASSAT were not considered here, since they do not support disjunction,
which is strictly needed to solve 2P -complete problems like 2QBF and STRATCOMP.
7.3.3 HAMPATH and TSP. On HAMPATH, the picture for DLV and GnT
was similar to the one for 2QBFGW , which showed better performance of DLV.
The results for the other systems are more surprising, however: DLV solved
all instances up to size 105, while Smodels stopped at size 50, and GnT and
ASSAT stopped at size 45.
Both Smodels and ASSAT are specialized for problems in NP, and we are
aware that both are rather efficient on several NP-complete problems. In the
literature, benchmark results on Hamiltonian Path or Hamiltonian Circuit
have been reported also in Lin and Zhao [2002] and Nicolas et al. [2002].
While the findings in Nicolas et al. [2002] appear to confirm our results,
those in Lin and Zhao [2002] are quite different. Apparently, this difference
is mainly due to the encodings employed in the benchmarks. Indeed, we have
tested the Hamiltonian Path programs of our benchmarks on the instances
used in Lin and Zhao [2002], and we arrived at similar results as reported
above.
Interestingly, when we used DLV as the instantiator, Smodels and GnT
stopped earlier (and solved all instances up to size 40 vs. size 45 with Lparse),
while ASSAT reached size 45. This is somewhat unexpected, since the in-
stantiation produced by the DLV instantiator is, in general, a subset of that
generated by Lparse (on these examples they often coincide). The difference
was probably due to the different orderings of the ground rules generated by
the two instantiators, which may have had an impact on the heuristics of GnT
and Smodels in this case.
Finally, we observe that Smodels behaved better than ASSAT on small
instances, and that the two systems scaled similarly.
ACM Transactions on Computational Logic, Vol. 7, No. 3, July 2006.
550 • N. Leone et al.
The picture for TSP was different18 : the optimality of a solution made the
problem harder than HAMPATH. Both DLV and Smodels got significantly
slower and had very similar run times, with DLV being slightly faster. This
behavior suggests that the implementation of the optimization constructs is
still to be improved in both DLV and Smodels.
18 Recallthat ASSAT and GnT could not be tested on this problem, since they have no optimization
constructs.
19 The instantiator of DLV does not need the addition of domain predicates and, if domain predicates
are added, their impact is very marginal on the instantiation time and they do not affect the size
of the generated instantiation.
20 Wecannot explain the performance of GnT around RAMSEY4-4/16, but we verified that the
timings were indeed correct.
7.4 Summary
Summarizing, we can draw the following conclusions:
Two strong points of DLV in comparison to the other systems are (i) the
built-in implementation of disjunction, which allows DLV to efficiently solve
2P -complete problems, and (ii) its advanced instantiation module, which
allows DLV to efficiently deal with deductive database applications, which
supports a simpler way of programming (the user does not have to bother
about domain predicates), and which also tends to affect performance on hard
problems (like SOKOBAN) positively, as it produces a smaller instantiation
than Lparse and requires less memory.
Our experimental results are complemented by other efforts on benchmark-
ing ASP systems recently reported in the literature [Dix et al. 2002; Koch
and Leone 1999; Lin and Zhao 2002; Nicolas et al. 2002; Simons et al. 2002;
Eiter et al. 1998a; Janhunen et al. 2003]. In general, these confirm our claim
that DLV handles deductive database applications and 2P -complete problems
more efficiently than the other systems, while the situation is less clear on
NP-complete problems where the results depend, to a larger extent, on the
encodings adopted. While the experiments in Koch and Leone [1999], Lin and
Zhao [2002], Nicolas et al. [2002], Simons et al. [2002], and Eiter et al. [1998a]
were conducted on benchmark problems very similar to those used in this
article, a completely different approach was taken in Dix et al. [2002]. This
article reported on a most recent comprehensive benchmarking activity which
was independently performed in the context of Hierarchical Task Network
(HTN) Planning based on ASP. Dix et al. considered instances of several
planning problems, which were transformed to logic programs and solved
by invoking an answer set engine. These experiments are relevant, as they
compared the systems in the important domain of AI planning on benchmark
instances which are really used to compare planning systems. In particular,
Dix et al. used DLV and Smodels (version v2.27) and compared the behaviors of
the systems. Summarizing their findings in Dix et al. [2002], the authors stated
that DLV was significantly faster than Smodels in their experiments. They
believed one of the reasons for this was grounding, as Smodels requires domain
predicates, creating many ground instances of the program clauses which are
often irrelevant. But Dix et al. also concluded that the better grounding was
not the only source for DLV’s superiority in their experiments: DLV was still
faster than Smodels running on an instantiation provided by DLV.
8. CONCLUSION
After an extensive period of mainly foundational and theoretical research on
nonmonotonic logics and databases, during the last years several implemen-
tations became available which can be utilized as advanced and powerful
tools for problem solving in a highly declarative manner. They provide a
computational back-end for the Answer Set Programming (ASP) paradigm, in
which the solutions to a problem are encoded in the models (or answer sets) of
a nonmonotonic logic program.
In this article, we have presented the DLV system, which is a state-of-the-
art implementation of disjunctive logic programming under the answer set
semantics [Gelfond and Lifschitz 1991], enriched by further useful language
ACM Transactions on Computational Logic, Vol. 7, No. 3, July 2006.
DLV System for Knowledge Representation and Reasoning • 555
convenient for the encoding of many practical problems. On the other hand,
improvements at the algorithmic level are underway by the development
and implementation of more sophisticated magic set techniques than those
which are currently available for disjunctive logic programs [Greco 1999].
Furthermore, refinements of the heuristics in the model generation process
should improve performance and scalability.
From what has been achieved and what may be expected, we are confi-
dent that DLV, as well as similar ASP systems, will provide us with more
and more widely applicable tools which will render computational logic an
important component in advanced information technology. ASP has been
recognized as a promising approach for dealing with problems which require
advanced modeling capabilities for problem representation—recently, the
European Commission granted funding for a special Working Group on
Answer Set Programming (WASP) formed by a number of research groups in
Europe.
For GnT , we used the same encoding with the addition of domain predicates
and minor syntactic changes to conform to the different syntax.
The encoding for Smodels and ASSAT has been obtained from the encoding
for GnT , rewriting disjunction in the “guessing” rules for push by unstratified
negation.
ACKNOWLEDGMENTS
REFERENCES
ANGER, C., KONCZAK, K., AND LINKE, T. 2001. NoMoRe: A system for non-monotonic reasoning.
In Proceedings of the 6th International Conference on Logic Programming and Nonmonotonic
Reasoning (LPNMR’01), Vienna, Austria, T. Eiter, W. Faber, and M. Truszczyński, Eds. Lecture
Notes in Computer Science/Lecture Notes in Artificial Intelligence, vol. 2173. Springer, Berlin,
Germany, 406–410.
APT, K. AND BOL, N. 1994. Logic programming and negation: A survey. J. Logic Programm. 19/20,
9–71.
APT, K. R., BLAIR, H. A., AND WALKER, A. 1988. Towards a theory of declarative knowledge. In
Foundations of Deductive Databases and Logic Programming, J. Minker, Ed. Morgan Kaufmann,
San Francisco, CA, 89–148.
ARAVINDAN, C., DIX, J., AND NIEMELÄ, I. 1997. Dislop: A research project on disjunctive logic
programming. AI Commun. Europ. J. Artific. Intell. 10, 3/4, 151–165.
BABOVICH, Y. 2002. Cmodels homepage. http://www.cs.utexas.edu/users/tag/cmodels.html.
BARAL, C. 2003. Knowledge Representation, Reasoning and Declarative Problem Solving.
Cambridge University Press, Cambridge, U.K.
BARAL, C. AND GELFOND, M. 1994. Logic programming and knowledge representation. J. Logic
Programm. 19/20, 73–148.
BEN-ELIYAHU, R. AND DECHTER, R. 1994. Propositional semantics for disjunctive logic programs.
Ann. Math. Artific. Intell. 12, 53–87.
BEN-ELIYAHU, R. AND PALOPOLI, L. 1994. Reasoning with minimal models: Efficient algorithms and
applications. In Proceedings of the Fourth International Conference on Principles of Knowledge
Representation and Reasoning (KR-94). 39–50.
BRASS, S. AND DIX, J. 1995. Disjunctive semantics based upon partial and bottom-up evalua-
tion. In Proceedings of the 12th International Conference on Logic Programm., Tokyo, Japan,
L. Sterling, Ed. MIT Press, Cambridge, MA, 199–213.
BREWKA, G. AND EITER, T. 1999. Preferred answer sets for extended logic programs. Artific.
Intell. 109, 1-2, 297–356.
BREWKA, G., NIEMELÄ, I., SCHAUB, T., AND TRUSZCZYŃSKI, M. (ORGANIZERS). 2002. Dagstuhl Seminar
Nr. 0238, Nonmonotonic Reasoning, Answer Set Programming and Constraints, September
15–20, 2002. System Competition. Go online to http://www.cs.uni-potsdam.de/~canger/
dagstuhl.html.
BUCCAFURRI, F., FABER, W., AND LEONE, N. 2002. Disjunctive logic programs with inheritance.
Theor. Pract. Logic Programm. 2, 3.
BUCCAFURRI, F., LEONE, N., AND RULLO, P. 2000. Enhancing disjunctive datalog by constraints.
IEEE Trans. Knowl. Data Eng. 12, 5, 845–860.
CADOLI, M., EITER, T., AND GOTTLOB, G. 1997a. Default logic as a query language. IEEE Trans.
Knowl. Data Eng. 9, 3 (May/June), 448–463.
CADOLI, M., GIOVANARDI, A., AND SCHAERF, M. 1997b. Experimental analysis of the computational
cost of evaluating quantified boolean formulae. In Proceedings of the 5th Congress of the Italian
Association for Artificial Intelligence (AI*IA 97), Rome, Italy. Lecture Notes in Computer Science
1321, Springer, Berlin, Germany, 207–218.
CALIMERI, F., FABER, W., LEONE, N., AND PFEIFER, G. 2002. Pruning operators for answer set
programming systems. In Proceedings of the 9th International Workshop on Non-Monotonic
Reasoning (NMR’2002) . 200–209.
CHEN, W. AND WARREN, D. S. 1996. Computation of stable models and its integration with logical
query processing. IEEE Trans. Knowl. Data Eng. 8, 5, 742–757.
CHOLEWIŃSKI, P., MAREK, V. W., MIKITIUK, A., AND TRUSZCZYŃSKI, M. 1999. Computing with default
logic. Artific. Intell. 112, 2–3, 105–147.
CHOLEWIŃSKI, P., MAREK, V. W., AND TRUSZCZYŃSKI, M. 1996. Default reasoning system DeReS.
In Proceedings of the Fifth International Conference on Principles of Knowledge Representation
and Reasoning (KR ’96), Cambridge, MA. Morgan Kaufmann, San Francisco, CA, 518–528.
CLARK, K. 1978. Negation as failure. In Logic and Data Bases, H. Gallaire and J. Minker, Eds.
Plenum Press, New York, NY, 293–322.
DANTSIN, E., EITER, T., GOTTLOB, G., AND VORONKOV, A. 2001. Complexity and expressive power of
logic programming. ACM Comput. Surv. 33, 3, 374–425.
DELGRANDE, J., SCHAUB, T., AND TOMPITS, H. 2001. plp: A generic compiler for ordered logic
programs. In Proceedings of the 6th International Conference on Logic Programming and
Nonmonotonic Reasoning (LPNMR-01), T. Eiter, W. Faber, and M. Truszczyński, Eds. Lecture
Notes in Computer Science, vol. 2173, Springer, Berlin, Germany, 411–415.
DELL’ARMI, T., FABER, W., IELPA, G., LEONE, N., AND PFEIFER, G. 2003. Aggregate functions in
disjunctive logic programm: Semantics, complexity, and implementation in DLV. In Proceedings
of the 18th International Joint Conference on Artificial Intelligence (IJCAI 2003), Acapulco,
Mexico. Morgan Kaufmann, San Francisco, CA.
DIX, J. 1995. Semantics of logic programs: Their intuitions and formal properties. An overview.
In Logic, Action and Information. Proceedings of the Konstanz Colloquium in Logic and
Information (LogIn’92). Walter de Gruyter, Berlin, Germany, 241–329.
DIX, J. AND FURBACH, U. 1996. The DFG project DisLoP on disjunctive logic programming.
Computat. Logic 2, 2, 89–90.
DIX, J., GOTTLOB, G., AND MAREK, V. W. 1996. Reducing disjunctive to non-disjunctive semantics
by shift-operations. Fundamenta Informaticae 28, 87–100.
DIX, J., KUTER, U., AND NAU, D. 2002. Planning in answer set programming using ordered task
decomposition. Theo. Pract. Logic Programm. Revised paper submitted for publication.
EAST, D. AND TRUSZCZYŃSKI, M. 2000. dcs: An implementation of DATALOG with constraints.
In Proceedings of the 8th International Workshop on Non-Monotonic Reasoning (NMR’2000),
Breckenridge, Colorado, USA, C. Baral and M. Truszczyński, Eds.
PRZYMUSINSKI, T. 1990. Stationary semantics for disjunctive logic programs and deductive
databases. In Proceedings of the North American Conference on Logic Programming. 40–62.
PRZYMUSINSKI, T. 1995. Static semantics for normal and disjunctive logic programs. Ann. Math.
Artificial Intelligence 14, 323–357.
PRZYMUSINSKI, T. C. 1988. On the declarative semantics of deductive databases and logic pro-
grams. In Foundations of Deductive Databases and Logic Programming, J. Minker, Ed. Morgan
Kaufmann, San Francisco, CA, 193–216.
PRZYMUSINSKI, T. C. 1991. Stable semantics for disjunctive programs. New Generat. Comp. 9,
401–424.
RADZISZOWSKI, S. P. 1994. Small RAMSEY numbers. Electron. J. Combinatorics 1. Revision 9:
July 15, 2002.
RAO, P., SAGONAS, K. F., SWIFT, T., WARREN, D. S., AND FREIRE, J. 1997. XSB: A system for efficiently
computing well-founded semantics. In Proceedings of the 4th International Conference on Logic
Programming and Non-Monotonic Reasoning (LPNMR’97), J. Dix, U. Furbach, and A. Nerode,
Eds. Lecture Notes in Computer Science/Lecture Notes in Artificial Intelligence, vol. 1265.
Springer, Berlin, Germany, 2–17.
REITER, R. 1987. A theory of diagnosis from first principles. Artificial Intelligence 32, 57–95.
ROSS, K. 1990. The well-founded semantics for Disjunctive Logic Programs. In Deductive
and Object-Oriented Databases, W. Kim, J.-M. Nicolas, and S. Nishio, Eds. Elsevier Science,
Amsterdam, The Netherlands, 385–402.
SAKAMA, C. 1989. Possible model semantics for disjunctive databases. In Proceedings of the
First International Conference on Deductive and Object-Oriented Databases (DOOD-89).
North-Holland, Amsterdam, The Netherlands, 369–383.
SCHAUB, T. AND WANG, K. 2001. A comparative study of logic programs with preference. In
Proceedings of the 17th International Joint Conference on Artificial Intelligence (IJCAI 2001).
Morgan Kaufmann, San Francisco, CA, 597–602.
SEIPEL, D. AND THÖNE, H. 1994. DisLog—A system for reasoning in disjunctive deductive
databases. In Proceedings of the International Workshop on the Deductive Approach to Infor-
mation Systems and Databases (DAISD’94), A. Olivé, Ed. Universitat Politecnica de Catalunya
(UPC), Barcelona, Spain, 325–343.
SIMONS, P. 2000. Extending and implementing the stable model semantics. Ph.D. dissertation.
Helsinki University of Technology, Helsinki, Finland.
SIMONS, P., NIEMELÄ, I., AND SOININEN, T. 2002. Extending and implementing the stable model
semantics. Artificial Intelligence 138, 1–2, 181–234.
SYRJÄNEN, T. 2002. Lparse 1.0 user’s manual. Go online to <URL:http://www.tcs.hut.fi/
Software/smodels/lparse.ps.gz>.
VAN GELDER, A., ROSS, K., AND SCHLIPF, J. 1991. The well-founded semantics for general logic
programs. Assoc. Comput. Mach. 38, 3, 620–650.
WOLFINGER, B., ED. 1994. Workshop: Disjunctive Logic Programming and Disjunctive Databases
Proceedings, 13th IFIP World Computer Congress, Hamburg, Germany. German Society for
Computer Science (GI) Springer, Berlin, Germany.
ZHAO, Y. 2002. ASSAT homepage. Go online to http://assat.cs.ust.hk/.