From: FLAIRS-02 Proceedings. Copyright © 2002, AAAI (www.aaai.org). All rights reserved.
An On-Line Satisfiability Algorithm for Conjunctive Normal Form Expressions with Two Literals
John F. Kolen Institute of Human and Machine Cognition University of West Florida Pensacola, Florida 32501 [email protected]
Abstract so far. For instance, an on-line convex hull algorithm incre- mentally maintains the convex hull of a sequence of coplanar This paper describes two algorithms for determining points (Preparata 1979). the satisfiability of Boolean conjunctive normal form In this paper, I first describe an on-line algorithm for 2- expressions limited to two literals per clause (2-SAT) SAT. At each insertion of a clause, the algorithm condition- extending the classic effort of Aspvall, Plass, and Tar- jan. The first algorithm differs from the original in ally performs a depth first search of subset of the dual impli- that satisfiability is determined upon the presentation of cation graph and checks affected components for inclusion each clause rather than the entire clause set. This on- of literal pairs (x and x). A large performance savings is line algorithm experimentally exhibits average run-time made by not searching on pure variables, by making oppor- linear to the number of variables. This performance tunistic variable assignments, especially during depth first is achieved by performing a single depth first search search of the graph. These techniques are used to construct of one of the incoming literals. Additional search is an off-line algorithm, as well. The performance of the algo- avoided by excluding clauses containing pure variables rithms are demonstrated experimentally. or variables whose truth value has been explicitly pro- vided or can be inferred. An off-line algorithm is also described that incorporates these strategies. Preliminaries During the course of this paper, the following terms are used to describe satisfiability problems and their graph theoretic Introduction equivalents. Let X = x1, ..., xn be a set of Boolean vari- A conjunctive normal form Boolean expression (CNF) is a ables. A literal is either a variable or it’s negation, hence L = {x , ..., x }∪{x , ..., x } conjunction of disjunctive clauses. Determining the exis- 1 n 1 n is the set of literals. A c k tance of an assignment of truth values to the variables of clause, ,isamultiset representing the disjunction of L the CNF expression that makes it evaluate as true is the sat- members of .For this paper, we are only interested in the k =2 isfiability problem. When the clause size is greater than case where . This restriction implies that clauses will a, b ∈ L a ∨ a two, the problem is NP-Complete (Cook 1971). A linear exhibit one of three forms ( ): i) unit clauses , a ∨ a a ∨ b algorithm for 2-SAT was originally developed by Aspvall, ii) tautological clauses, , iii) and regular clauses, . C Lk Plass, and Tarjan (Aspvall, Plass, & Tarjan 1979) (APT al- A clause set is the multiset drawn from .Aninstance k F =(X, C) a gorithm). Consider a directed graph where the vertices are of a -SAT problem is .Aliteral, ,ispure, if C the set of literals from a 2-CNF formula. One could con- it’s negation does not appear in any clause in . struct a digraph on these vertices from the formula by in- The 2-SAT decision problem is intimately related to deci- terpreting each clause a ∨ b as a pair of directed edges sions problems on graphs (Aspvall, Plass, & Tarjan 1979). All graphs are assumed to be directed. Let G =(V,E) a → b and b → a on the graph. They proved that a designate a graph with V vertices and E edges. The graph formula is satisfiable if, and only if, no pair of literals, x dual, or implication graph, G,ofa2-SAT problem instance and x, appear in the same strongly connected component. (X, C) directly represents the implication relationship be- Since a linear time algorithm for determining the strongly tween literals of X induced by the disjunctive clauses of C. connected components of a digraph existed (Tarjan 1972; The vertices, V ,ofthe graph are the literals, L.Anedge Aho, Hopcroft, & Ullman 1974), the 2-SAT question could exists in the graph if and only if the implication relation- be answered in linear time as well. ship holds between the two vertices. Hence, E = {(a, b) | The APT algorithm requires the entire expression before (a ∨ b) ∈ C}. Note that both (a, b) ∈ E if and only if it can begin processing–an off-line algorithm. An on-line b, a ∈ E. Literal and vertex will be used interchangeably algorithm, on the other hand, is one receives a sequence of through out the paper. inputs and performs some computation on the sequence seen Avertex b is reachable from vertex a if there exists a set Copyright c 2002, American Association for Artificial Intelli- (xi,xi+1) ⊂ V of vertices such that a → x1, x1 → x2, gence (www.aaai.org). All rights reserved. ..., xi → b. Reachability of two vertices is represented as
FLAIRS 2002 187 proc 2-SAT APT(F ) G.Either P = P or there exist two components S1,S2 ∈ P Construct the dual graph G=(V,E) of F such that S1,S2 ∈ P but S1 ∪ S2 ⊆ S, and S ∈ P . foreach v ∈ E do if not(w.Mark) then SearchAPT(v); fi Theorem 3 Let a b and a b. There exists a path from return not(SearchFailed()) od. a to a through b (and b) with length | a b | + | a b |. proc SearchAPT(v) Theorem 4 S is a contradictory component if and only if Push(v); ∀b ∈ S, b ∈ S. v.Lowlink := v.Dfnum := count; count := count +1; v.Mark := true; Algorithms foreach w where (v, w) ∈ E do While the APT algorithm performs well–linear run time if not(w.Mark) with respect to the number of variables and edges–it requires then SearchAPT(w); the entire formula to begin it’s processing. There are situa- v.Lowlink := min(v.Lowlink, w.Lowlink) tions, however, that this may not be feasible or, at least, in- elsif w.Dfnum