Professional Documents
Culture Documents
The 2-MAXSAT Problem Can Be Solved in Polynomial Time: Yangjun Chen
The 2-MAXSAT Problem Can Be Solved in Polynomial Time: Yangjun Chen
The 2-MAXSAT Problem Can Be Solved in Polynomial Time: Yangjun Chen
Polynomial Time
Yangjun Chen*
Abstract—By the MAXSAT problem, we are given a set V of terms of [7], any algorithm based on branch-and-bound runs
m variables and a collection C of n clauses over V . We will in O*(cm ) time with c ≥ 2.
seek a truth assignment to maximize the number of satisfied
arXiv:2304.12517v16 [cs.CC] 15 Aug 2023
B. Basic algorithm
v5 c5 v5 c5
To find a truth assignment to maximize the number of
satisfied Dj′ s in D, we will first construct a trie-like structure
v6 c6 v6 c6 G over D, and then search G bottom-up to find answers.
Let P1 *, P2 *, ..., Pn * be all the p*-graphs constructed for
all Dj ’s in D, respectively. Let pj and Sj * (j = 1, ..., n) be
v7 $ v7 $ (b) the main path of Pj * and the transitive closure over its spans,
(a)
respectively. We will construct G in two steps. In the first step,
we will establish a trie [13], denoted as T = trie(R) over R
F IG . 1: A p-path and a p∗-path.
= {p1 , ..., pn } as follows.
If |R| = 0, trie(R) is, of course, empty. For |R| = 1, trie(R)
is a single node. If |R| > 1, R is split into m (possibly empty)
‘*’s, just like <v1 , v1 , v2 > and <v1 , v2 , v3 >, which corre-
subsets R1 , R2 , . . . , Rm so that each Ri (i = 1, . . . , m)
spond to two consecutive ‘*’s: (c2 , *) and (c3 , *). Therefore,
contains all those sequences with the same first variable name.
the overlapped spans exhibit some kind of transitivity. That
The tries: trie(R1 ), trie(R2 ), . . . , trie(Rm ) are constructed
is, if s1 and s2 are two overlapped spans, the s1 ∪ s2 must
in the same way except that at the kth step, the splitting of sets
be a new, but bigger span. Applying this operation to all
is based on the kth variable name (along the global ordering
the spans over a p-path, we will get a ’transitive closure’
of variables). They are then connected from their respective
of overlapped spans. Based on this observation, we give the
roots to a single node to create trie(R).
following definition.
In Fig. 2, we show the trie constructed for the variable
Definition 2. (p*-graph) Let P be a p-graph. Let p be its main
sequences shown in the third column of Table I. In such a
path and S be the set of all spans over p. Denote by S* the
trie, special attention should be paid to all the leaf nodes
‘transitive closure’ of S. Then, the p*-graph with respect to
each labeled with $, representing a conjunction (or a subset of
P is the union of p and S*, denoted as P * = p ∪ S*.
conjunctions, which can be satisfied under the truth assignment
In Fig. 1(b), we show the p*-graph with respect to the p-
represented by the corresponding main path.)
graph shown in Fig. 1(a). Concerning p*-graphs, we have the
The advantage of tries is to cluster common parts of variable
following lemma.
sequences together to avoid possible repeated checking. (Then,
Lemma 1. Let P * be a p*-graph for a conjunction Di this is the main reason why we sort variable sequences
(represented as a variable sequence) in D. Then, each path according to their appearance frequencies.) Especially, this
from # to $ in P * represents a truth assignment, under which idea can also be applied to the variable subsequences (as will
be seen in Section IV-B), over which some dynamical tries that the span belongs to 3 conjunctions: D1 , D5 , and D6 . But
can be recursively constructed, leading to a polynomial time no numbers are associated with any tree edges.
algorithm for solving the problem. In addition, each p*-graph itself is considered to be a simple
Each edge in the trie is referred to as a tree edge. In addition, trie-like graph.
the variable c associated with a node v is referred to as the From Fig. 3, we can see that although the number of truth
label of v, denoted as l(v) = c. Also, we will associate each assignments for D is exponential, they can be represented by a
node v in the trie T a pair of numbers (pre, post) to speed graph with polynomial numbers of nodes and edges. In fact, in
up recognizing ancestor/descendant relationships of nodes in a single p*-graph, the number of edges is bounded by O(n2 ).
T , where pre is the order number of v when searching T in Thus, a trie-like graph over m p*-graphs has at most O(n2 m)
preorder and post is the order number of v when searching T edges.
in postorder.
v0
#
v0 (1, 18)
# v1 6 6
1,5,6
1 c2 4
v1
c2 (2, 17)
1,3 v2 v14
6 4
3
v2 c3 c1
v14
4
c3 (3, 12) c1 (15, 16) v3 6 4 v15
v11 6
2
3,5 c1 c4 6 c4 4
v3 v15 5 6
v11
c1 (4, 8) c4 (12, 11) c4 (16, 15) v4 v8 2
v12 v16 4 4
4
5 c5 2
5 c4 c5 c6
v8 v12 v16 2 4
v4 v5 6 6
(5, 4) c5 (9, 7) (13, 10) v13 4 v17
c4 c5 c6 (17, 14) 1,5 5 v9
c5 c6 $ $
1
v13 v17 2
v5 v9
2
D6 D4
(6, 3) c5 c6 (10, 6) $ (14, 9) (18, 13) 1,3
$ v6 v10
c6 $
D6 D4
(7, 2) v6 v10 D2
c6 $ (11, 5) v7
$
D2 D1 D3 D5
(8, 1) v7
$
D1 D3 D5 F IG . 3: A trie-like graph G.
F IG . 2: A trie and tree encoding. In a next step, to find the answer, we will search G bottom-
up level by level. First of all, for each leaf node, we will
These two numbers can be used to characterize the ancestor- figure out all its parents. Then, all such parent nodes will be
descendant relationships in T as follows. categorized into different groups such that the nodes in the
same group will have the same label (variable name), which
- Let v and v ′ be two nodes in T . Then, v ′ is a descendant enables us to recognizes all those conjunctions which can
of v iff pre(v ′ ) > pre(v) and post(v ′ ) < post(v). be satisfied by a same assignment efficiently. All the groups
For the proof of this property of any tree, see Exercise 2.3.2- containing only a single node will not be further explored.
20 in [12]. (That is, if a group contains only one node v, the parent of
For instance, by checking the label associated with v2 v will not be checked.) Next, all the nodes with more than
against the label for v9 in Fig. 2, we see that v2 is an ancestor one node will be explored. We repeat this process until we
of v9 in terms of this property. We note that v2 ’s label is (3, reach a level at which each group contains only one node. In
12) and v9 ’s label is (10, 6), and we have 3 < 10 and 12 > this way, we will find a set of subgraphs, each rooted at a
6. We also see that since the pairs associated with v14 and v6 certain node v, in which the nodes at the same level must be
do not satisfy the property, v14 must not be an ancestor of v6 labeled with the same variable name. Then, the path in the
and vice versa. trie from the root to v and any path from v to a leaf node
In the second step, we will add all Si * (i = 1, ..., n) to in the subgraph correspond to an assignment satisfying all the
the trie T to construct a trie-like graph G, as illustrated in conjunctions labeling a leaf node in it.
Fig. 3. This trie-like graph is constructed for all the variable See Fig. 4 for illustration.
sequences given in Table I, in which each span is associated In Fig. 4, we show part of the bottom-up process of
with a set of numbers used to indicate what variable sequences searching the trie-like graph G shown in Fig. 3.
the span belongs to. For example, the span <v0 , v1 , v2 > (in • step 1: The leaf nodes of G are v7 , v10 , v13 , v17 (see level
Fig. 3) is associated with three numbers: 1, 5, 6, indicating 1), representing the 6 variable sequences in D shown in
v1 v0
level5: c2 #
1 4 5
1,3
v4 v3 v2 v3 v14 v2 v1 v1 v0
level4: c4 c1 c3 c1 c1 c3 c2 c2 #
g121
5 2 3,5
1,3 1 4
v5 v8 v15 v4 v3 v14 v2 v1 v0 v3 v1
c5 c5 c4 c4 c1 c1 c3 c2 # c1 c2
level3: g12 g13
g11 5 5 4 4
2 4 2
1,5
6 4
D1 D3 D5 D2 D6 D4
v0 a v4 a g1 v0 a v4
Proposition 2. Let D be a formula in DNF. Let G be
a trie-like graph created for D. Then, the result produced
(a) (b)
by SEARCH(G) must be a truth assignment satisfying a
maximum subset of conjunctions in D. v3 d
1 4 5
1,3
v4 v3 v2 v3 v14 v2 v1 v1 v0
l4 c4 c1 c3 c1 c1 c3 c2 c2 #
g121
5 2
v5 v8
c5 c5
l 3 g11
upBound upBound.
• Merge the repeated nodes of Case 1 to a single one at
the corresponding layer in G′ .
See the following example for illustration.
Example 1. When checking the repeated node v3 in the
bottom-up search process, we will calculate all the reachable
subsets through spans with respect to v3 as described above:
RSv2 [c5 ], RSv2 [c6 ], RSv3 [c5 ], and RSv3 [c6 ]. In terms of these
F IG . 8: Illustration for upBounds. reachable subsets through spans, we will get the corresponding
upBound {v5 , v8 }. Node v4 (above the upBound) will not be
involved by the recursive execution of the algorithm.
node of Case 1). Then, we will construct a trie-like graph Concretely, when we make a recursive call of the algorithm,
over two subgraphs, rooted at v5 and v8 , respectively. Then, applied to two subgraphs: G1 - rooted at v5 , and G2 - rooted
we make a recursive call of the algorithm over such a at v8 (see Fig. 9(a)), we will first constrcut a trie-like graph as
newly constructed trie-like subgraph to recognize some more shown in Fig. 9(b). Here, we notice that the subset associated
subsets of conjunctions which can be satisfied by a same with its unique leaf node is {D2 , D5 }, instead of {D1 , D2 ,
truth assignment. Here, however, v4 is not included since the D3 , D5 }. It is because the number associated with span v2 − →
5
truth assignment with v4 being set to true satisfies only the v5 is 5 while the number associated with span v2 −
2
→ v8 is 2.
conjunctions associated with leaf node v10 . This has already
By searching the trie-like graph shown in Fig. 9(b), we
been determined when the initial trie is built up. In fact, the
will find the truth assignment satisfying {D2 , D5 }. This truth
purpose of upper boundaries is to take away the nodes like v4
assignment is represented by a path consisting three parts: the
from the subsequent computation. 5
tree path from root to v2 , the span v2 − → v5 , the subpath v5
Specifically, the following operations will be carried out
to v7 . So the truth assignment is {c1 = 0, c2 = 1, c3 = 1, c4
when encounteing a repeated node v of Case 1. = 0, c5 = 1, c6 = 1}.
• Calculate all RSs with respect v. We remember that when generating the trie T over the main
• Calculate the upBound in terms of RSs. paths of the p*-graphs over the variable sequences shown
• Make a recursive call of the algorithm over all the p*- in Table I, we have already found a subset of conjunctions
subgraphs each starting from a node on the corresponding {D1 , D3 , D5 }, which can be satisfied by a truth assignment
v2 v2 handled according to the three cases described in the previous
1 c3 G2 c3
5 2 2,5
subsection (see lines 5 - 8). Especially, in Case 1, we will
first create the corresponding upBound L with respect to v,
v5 c5 v8 c5 c5
and then generate a trie-like graph D′ over all those trie-like
1,3 1,2,3
subgraphs each rooted at a node on L. Next, v will be added
v6 c6 v9 c6 2 c6
to D′ as its root. Finally, a recursive call to the algorithm on
D′ will be invoked.
v7 $ v10 $ $
In Case 2, all the repeated nodes will be simply merged
together while in Case 3 the repeated nodes will be handled
D1 D3 D5 D2 D2 D5
according to both Case 1 and Case 2.
(a) (b)
Besides, D′ = {v} ∪ D′ in line 6 is a simplified represen-
tation of an operation, by which we add not only node v, but
F IG . 9: Illustration for recursive call of the algorithm.
also the corresponding edges to D′ .
The sample trace given in the following example helps for
represented by the corresponding main path. This is larger than illustration.
{D2 , D5 }. Therefore, {D2 , D5 } should not be kept around
and this part of computation is futile. However, this kind of Example 2. When applying SEARCH( ) to the p*-graphs
useless work can be avoided by performing a pre-checking: shown in Fig. 3, we will encounter three repeated nodes of
if the number of p*-subgraphs, over which the recursive call Case 1: v3 , v2 , and v1 .
of the algorithm will be invoked, is smaller than the size of • Checking v3 . As shown in Example 1, by this checking,
the partial answer already obtained, the recursive call of the we will find a subset of two conjunctions {D2 , D5 }
algorithm should not be conducted. satisfied by a truth assignment {c1 = 0, c2 = 1, c3 = 1,
In terms of the above discussion, we change SEARCH( ) to c4 = 0, c5 = 1, c6 = 1}. However, when creating T at the
a recursive algorithm shown below. very beginning, a subset of conjunctions {D1 , D2 , D5 }
has already been found (see node v7 in Fig. 2), which
Algorithm 3: SEARCH(G) can be satisfied by a same truth assignment: c1 = 1, c2
Input : a trie-like subgraphs G. = 1, c3 = 1, c4 = 1, c5 = 1, c6 = 1. (See the path from
Output: a largest subset of conjunctions satisfying a the root to v7 in Fig. 2.) Since {D1 , D2 , D5 } is larger
certain truth assignment. than than {D2 , D5 }, the result obtained by this checking
1 assume that the height of G is m; should not be kept around.
2 let L1 = {all the leaf nodes of G}; • Checking v2 . When we encounter this repeated node of
3 for i = 1 to m - 1 do Case 1 during the generation of G′ , we will find two
4 generate Li+1 from Li ; (*each node in Li+1 is a subgraphs in G[v2 ], respectively rooted at v3 and v11 , as
parent of some nodes in Li *) shown in Fig. 10.
5 for each repeated node v in Li+1 do
6 Case 1: calculate RSs with respect to v and the v2
c3
corresponding upBound; let D be the set of
all the subgraphs each rooted at a node on upBound v3 v11
c1 c4
upBound; generate a trie-like subgraph D′
over D; D′ = {v} ∪ D′ ; call SEARCH(D′ ); v4 v8
2
v12
6
Merge all the appearances of v to a single c4 c5 c5
one; v5
1,5
v9 2 v13
7 Case 2: merge all the multiple appearances of c5 c6 $
1
v to a single node; D6
1,3 v6 v10
8 Case 3: distinguish between the nodes of Case c6 $
1 and the nodes of Case 2; and handle them
D2
differently; v7
$
9 denote by G′ the generated layered graph; D1 D3 D5
10 return f indSubset(G′);
F IG . 10: Two subgraphs in G[v2 ] and a upBound.
The improved algorithm (Algorithm 3) works in a quite
different way from Algorithm 1. Concretely, G′ will be created With respect to v2 , we will first calculate all the relevant
level by level (see line 4), and for each created level all reachable subsets through spans for all the nodes on the
the multiple appearances of nodes v will be recognized and tree path from root to v2 in G. Altogether we can figure
out five reachable subsets through spans shown below. a repeated nodes of Case 1: node v5−12 . Then, we will make
Among them, associated with v1 (on the tree path from a recursive call of the algorithm, generating an upBound {v7 ,
root to v2 in Fig. 3), we have v13 }. Accordingly, we will find a single path as shown in
Fig. 11(b), by which we can figure out another largest subset
- RSv1 [c4 ] = {v4 , v11 }, of conjunctions {D3 , D6 }, which can be satisfied by a certain
truth assignment. We notice that the subset associated with
due to the following two spans (see Fig. 3): this path is {D3 , D6 }, instead of {D3 , D5 , D6 }. It is because
the span from v5−12 to v7 (in Fig. 11(a)) is labeled with 3 and
3 6
→ v4 , v1 −
- {v1 − → v11 }. D5 should be removed.
v4-11
Associated with v2 (the repeated node itself) have we level4: c4
the following four reachable subsets through spans:
v4-11
v4-11 v5-12 v4-11 v8
- RSv2 [c4 ] = {v4 , v11 }, level3: c4 c5 c4 c4 c5
D3 D5 D6 D2
3,5 6
- {v2 −−→ v4 , v2 −→ v11 },
5 2 6 F IG . 12: A naive bottom-up search of G.
- {v2 → v5 , v2 −
− → v8 , v2 −→ v12 },
5 2
- {v2 → v6 , v2 −
− → v9 },
2 6 When we encounter the second repeated node v2 , we will
- {v2 → v10 , v2 −
− → v13 }. create a set of RS’s shown below:
- RSv1 = ∅, (Note that any RS with |RS| < 2 will not be
In terms of these reachable subsets through spans, we can
considered.)
establish the corresponding upper boundary {v4 , v8 , v11 } 5
- RSv2 [c5 ] = {v5−12 , v8 }, (due to the span v2 −→ v5−12
(which is illustrated as a thick line in Fig. 10). Then, we
and the tree edge v2 → v8 .)
can determine over what subgraphs a trie-like graph will 5
be established, on which the algorithm will be recursively - RSv2 [c6 ] = {v6 , v9 }, (due to the spans v2 −
→ v6 and v2
2
executed. −
→ v9 .)
In Fig. 11(a), we show the trie-like graph built over the In terms of these RSs, we construct the corresponding
three p*-subgraphs (starting respectively from v4 , v8 , v11 on upBound {v5−12 , v8 }, and create a trie-like graph as shown in
the upBound shown in Fig. 10), in which v4−11 stands for the Fig. 13(a). The only branching node in this graph is v5−12−8 .
merging of v4 and v11 , and v5−12 for the merging of v5 and Checking this node, we will finally get a single path as shown
v12 . Especially, v2 is involved as a braching node, working in Fig. 13(b), indicating a new subset of conjunctions which
as a bridge between the newly contructed trie-like graph and can be satisfied by a certain truth assignment.
the rest part of G. (See operation D′ = {v} ∪ D′ in line 6 of
v2
Alrorithm 3.) c3
v2 2,5
c3
v5-12-8 v5-12-8
5 c5
3,5 5 2 c5
v4-11 v8
c4 -
c5
v5-12
v9 2 v6-9 v6-9
5 c5 c6
6 v5-12 c6 2,3 $ c6
v6 v13 2
c5
D2
c6 3 $ v10 $
v7-13
v7-10 v7-10
D6 D2 $
v7 $ $
$
D3 D6 (a) (b)
D2 D5 D2 D5
D3 D5
(a) (b)
F IG . 13: Illustration for the recursive execution of the algo-
F IG . 11: A trie-like graph and a path. rithm.
By a recursive call of SEARCH( ), we will create its layed In the whole working process, a simple but very powerful
graph as shown in Fig. 12. At level 2 in Fig. 12, we can see heuristics can be used to improve efficiency. Let α be the
size of the largest subset of conjunctions found up to now, each branching node a recursive call of the algorithm will
which can be satisfied by a certain truth assignment. Then, any be performed:
recursive call of the algorithm over a smaller than α subset of
p*-subgraphs will be surpressed.
O(1), if l ≤ a constant,
After v2 is removed from the corresponding levels in G′ , Γ (l) =
the next repeated node v1 of Case 1 will be checked in a way P⌈logd l⌉
di Γ ( dli ) + O(l2 m), otherwise.
i=1
similar to v3 and v2 . (4)
Concerning the correctness of Algorithm 3, we have the Here, in the above recursive equation, O(l2 m) is the cost for
following proposition. generating all the reachable subsets of a node through spans
Proposition 3. Let G be a trie-like graph established over a and upper boundries, together with the cost for generating all
logic formula in DNF. Applying Algorithm 3 to G, we will get the trie-like subgraphs for each recursive call of the algorithm.
a maximum subset of conjunctions satisfying a certain truth We notice that the size of all the RSs together is bounded by
assignment. the number of spans in G, which cannot ne larger than O(lm).
From (4), we can get the following inequality:
Proof. To prove the proposition, we first show that any subset
of conjunctions found by the algorithm must be satisfied by a l
Γ (l) ≤ d · logd l · Γ ( ) + O(l2 m). (5)
same truth assignment. This can be observed by the definition d
of RSs and the corresponding upBounds. Solving this inequality, we will get
Then, we need to show that any subset of conjunctions,
which can be satisfied by a certain truth assignment, can be Γ (l) ≤ d · logd l · Γ ( dl ) + O(l2 m)
found by the algorithm. For this purpose, consider a subset of
conjunctions D′ which can be satisfied by a truth assignment ≤ d2 (logd l)( logd dl )Γ ( dl2 ) + (logd l) l2 m + l2 m
represented by a path
v1 → v2 ... vi−1 → vi → vj ... → vm , ≤ ... ...
in which vi → vj corresponds to a span. According to the l
≤ d⌈logd ⌉ (logd l) (logd ( dl )) ... ( logd l
l )
definition of RSs, the algorithm will find this path. This d⌈logd ⌉
analysis can be extended to general cases that a path contains
one or more spans. + l2 m((logd l)(logd ( dl )) ... (logd l
l ) + ... + logd l + 1)
d⌈logd ⌉
R EFERENCES
[1] J. Argelich, et. al., MinSAT versus MaxSAT for Optimization Problems,
International Conference on Principles and Practice of Constraint Pro-
gramming, 2013, pp. 133-142.
[2] S. A. Cook, The complexity of theorem-proving procedures, in: Proc.
of the 3rd Annual ACM Symposium on the Theory of Computing, 1971,
pp. 151-158.
[3] Y. Djenouri, Z. Habbas, D. Djenouri, Data Mining-Based Decomposition
for Solving the MAXSAT Problem: Toward a New Approach, IEEE
Intelligent Systems, Vol. No. 4, 2017, pp. 48-58.
[4] C. Dumitrescu, An algorithm for MAX2SAT, International Journal of
Scientific and Research Publications, Volume 6, Issue 12, December 2016.
[5] Y. Even, A. Itai, and A. Shamir, On the complexity of timetable and
multicommodity flow problems„ SIAM J. Comput., 5 (1976), pp. 691-
703.
This figure "fig1.png" is available in "png" format from:
http://arxiv.org/ps/2304.12517v16