Abstract
In this paper we describe several variations of the incremental MSU3 and MSU4 algorithms for the MaxSAT problem, and show that some of these improve performance. Among the variations considered are new cardinality constraint encodings which enable incrementally updating the constraint, and have smaller worst-case size than those encodings previously considered. The new cardinality encodings are based on the well-known sorting networks. The incremental approach is also extended, in a novel way, inspired by the idea behind resizing arrays. Best performance was achieved when the totalizer encoding was used in conjunction with sorting networks; unlike other implementations of such combinations in the literature we found that to get best performance, sorting networks should be used very sparingly. We submitted a solver using a version of the methods described in this paper to the 2017 MaxSAT evaluation where it placed fourth out of 8 solvers participating in the unweighted category.
Keywords
Introduction
MaxSAT solvers have an impressive list of applications ranging from software package upgrades (Argelich et al. [6]) to hardware design (Chen et al. [11]). MaxSAT is the problem of finding an assignment that maximizes the number of satisfied clauses of a boolean formula in Conjunctive Normal Form (CNF). There are several approaches to solving MaxSAT, for instance, the solver MaxSatz (Li et al. [19]) extends the inference rules of SAT to MaxSAT, and the solver MaxHS (Davies and Bacchus [13]) combines Mixed Integer Programming and SAT solving. In this paper we are primarily concerned with MaxSAT algorithms based on satisfiability testing (for an introduction to MaxSAT techniques see for instance Li and Manyà [18]).
MaxSAT algorithms based on satisfiability testing, such as MSU3 (Marques-Silva and Planes [21]) and MSU4 (Marques-Sila and Planes [20]), call a SAT solver, inspect the result to refine upper and lower bounds, and then repeat the call to the solver with a modified formula. The formula is modified by adding constraints that bound the number of unsatisfied clauses, all encoded as a CNF formula.
Several SAT solvers facilitate such a use, and are therefore called incremental. An incremental SAT solver allows certain modifications to the formula before it can be rechecked for satisfiability, reusing as much as possible of the runs with the previous formulas. There are several such solvers, and the SAT-Race 2015 competition featured an incremental SAT solver track where 5 solvers entered.
Martins et al. [23] showed that leveraging the incremental aspect of SAT solvers is crucial for the MSU3 algorithm. To do so they devised a way of reusing a cardinality encoding, called totalizer (Bailleux and Boufkhad [9]), between calls to the solver. In this paper we extend this work to the cardinality network encoding (Asín et al. [7]), the mixed encoding of Abío et al. [3], and to the MSU4 algorithm. Our experiments show that the simple combination of the mixed encoding and the incremental MSU4 algorithm gives a competitive MaxSAT solver. However, unlike in (Martins [22]) and (Abío et al. [3]), best performance is achieved when sorting networks are used sparingly in the mixed encoding. This might be due to the size of the cardinality constraint being less important when the latter is reused.
There are three main varieties of MaxSAT: unweighted, partial, and weighted. All varieties can be solved using satisfiability testing with cardinality constraints (see for instance Ansótegui et al. [5]). However, for simplicity, we only discuss the unweighted case. For our experiments we use benchmarks that are partial MaxSAT from the 2016 MaxSAT evaluation (2016 MaxSAT evaluation [1]), which includes a large collection of industrial partial MaxSAT benchmarks.
In Section 2 we introduce notation and review the incremental MSU3 algorithm and present a straight forward extension to the MSU4 algorithm for incremental SAT solvers. In Section 4 we review the method used by Martins et al. [23] of reusing the totalizer encoding between calls to the solver and extend it to cardinality networks and the mixed encoding. In Section 5 we present experimental results, and conclude in Section 6.
Preliminaries
A literal l is either a variable x or its negation
Unit propagation. Most modern SAT solvers make use of the unit propagation rule to decide satisfiability of a CNF formula. In this paper we will use unit propagation as a preprocessing step. The procedure is centered around unit clauses, clauses containing only one literal. A partial assignment ϕ to the variables in the formula F is built by applying the following steps (in any order) until a fixpoint is reached:
If F contains a clause c containing exactly one literal l and l is unassigned then the assignment is extended so that
If a clause contains a literal l with
If a clause contains a literal l with
Assume that the formula
Cardinality constraints. In addition to clauses, we will need to make use of cardinality constraints. Cardinality constraints extend the expressiveness of a clause slightly. A clause
For the most part, in this paper, we will need cardinality constraints that limit the number of true literals to at most k. For convenience, we denote such a cardinality contraint as
A SAT solver only handles CNF formulas so the cardinality constraint will have to be realised by a CNF formula. We will use the general term constraint to mean either a clause or a cardinality constraint.
Indicator variables. We will need to relax a constraint, and we do this with an indicator variable. Given a constraint ψ and a CNF formula
Incremental SAT solvers. We will exploit that many SAT solvers can function incrementally, that is, solve a similar formula reusing as much as possible of the run with the original formula. In addition to being incremental, we also require that the SAT solver provides an unsatisfiable core if the formula is unsatisfiable, that is, a (preferably small) subset of the clauses which is unsatisfiable.
We assume that an incremental SAT solver provides the following functionality:
The SAT solver maintains a CNF formula, and we may at any time add a clause c to it. Assume literal l to be assigned true, that is, when considering satisfiability, only assignments where If the literal l was assumed, remove the assumption. Check if the current formula is satisfiable with the current assumptions. Provide a core if the formula is found to be unsatisfiable.
Incremental algorithms for MaxSAT
In this section we will review the MSU3 algorithm of Marques-Silva and Planes [21], focusing on the improvement made by Martins et al. [23] in leveraging incremental SAT solvers. This is then extended in a straight forward manner to the MSU4 algorithm. The exact etymology of the MSU acronym is unclear, but Marques-Silva and Planes [21] suggests that it refers to the Fu and Malik [16] MaxSAT algorithm based on unsatisfiable subformulas.
Linear search algorithm
First we review a simple linear search algorithm that the MSU3 algorithm is based on. A lower bound on the number of unsatisfied clauses is kept. Each clause is given an indicator. By using a cardinality constraint the lower bound is refined by bounding the number of active indicator variables and repeatedly asking the solver to verify increasing lower bounds. In this way, the linear search algorithm incrementally relaxes the formula, initially requiring that all clauses are satisfied and increasing the bound by one for each step, until we reach an optimal solution.

Simple linear search algorithm
A major inefficiency in Algorithm 1 is the size of β in the cardinality constraint. To remedy this shortcoming the incremental MSU3 algorithm will initially assume all indicators to be false, we say that the indicators are inactive. The cardinality constraint only contains active indicators. When the formula is shown to be unsatisfiable, the unsatisfiable core is examined to find indicators that need to be activated. Any indicator of a clause from the input formula that occurs in a unsatisfiable core must be activated.
The algorithm works in two phases: first we seek only to make the formula satisfiable by removing assumptions, and keep track of a lower bound on the number of unsatisfied clauses. Each time the solver answers unsatisfiable, we increase the bound, and activate all indicators in the core. This leads to one (possibly suboptimal) solution.
In phase two, a cardinality constraint is assumed that requires the solution to be no worse than the current lower bound. Iteratively, the formula is checked for satisfiability, the lower bound is refined, and the cardinality constraint updated until the formula is satisfiable. We refer to (Marques-Silva and Planes [21]) for the proof of correctness of this algorithm.

MSU3 (Marques-Silva and Planes [21])
In Algorithm 2 the set α contains the original clauses with the added indicator variables. This set is used to check for indicators needing activation in the unsatisfiable core. Unlike in the linear algorithm, β is initially empty and indicators will enter β only once they are shown to be contained in a unsatisfiable core. If unlucky, β quickly contains all indicators in which case the MSU3 algorithm defaults to linear search.
The procedure requires the following property from the cardinality encoding: it should be possible to efficiently change the constraint from
The MSU4 (Marques-Sila and Planes [20]) algorithm is a slight variation on the MSU3 algorithm which has been shown to sometimes increase performance. The essential difference is that in Phase(2) the algorithm will attempt to iteratively lower an upper bound in addition to increasing a lower bound.
Phase(1) coincides exactly with the MSU3 algorithm, but in Phase(2) the cardinality encoding bounds the number of unsatisfied clauses to be at least as good as the current upper bound. If a satisfying assignment is found, it must satisfy more clauses and hence refine the upper bound. If no satisfying assignment can be found, the lower bound can be incremented and if no new inactive indicators are found in the core, the incumbent assignment is optimal. Proof of the correctness of this algorithm can be found in (Marques-Sila and Planes [20]).
Utilising an incremental SAT solver for the MSU4 algorithm is analogous to the MSU3 algorithm, see Algorithm 3.

MSU4 (Marques-Sila and Planes [20])
In this section we review two cardinality encodings: the totalizer encoding (Bailleux and Boufkhad [9]) and odd-even sorting networks (Batcher [10]). Recall that, as described in Section 3.2, an incremental encoding of a cardinality constraint
The totalizer cardinality encoding has
In this section we first introduce delayed variables, the method which we use to create our incremental encodings. Then the totalizer encoding, sorting networks encoding, and mixed encoding are introduced. Thereafter we explain how delayed variables are applied to achieve the aforementioned size bounds. Finally we discuss implementation details of delayed variables.
Delayed variables
To simplify the description of these incremental encodings we introduce delayed variables, denoted
Let us say we have the formula
Now x is undelayed so the SAT solver is notified of two new clauses:
In Example 1, after the variable x is undelayed the previous assignment can not be extended to satisfy the undelayed clauses. This shows that satisfying assignments can change after variables are undelayed. Indeed, undelaying can even lead to unsatisfiability.
To avoid changes to clauses already given to the SAT solver, one cannot delay a variable that has already been undelayed. Therefore variables can be introduced as being delayed, and then only undelayed once, and never redelayed. Since all clauses containing delayed variables are not given to the SAT solver yet, we are able to substitute literals in delayed clauses without having to change the formula. In Section 4.7 we show how delayed variables can be implemented efficiently for the purpose of this paper.
A sorting network applies a predetermined series of compare-and-swap operations to sort an input sequence. Several well-studied varieties exist: odd-even sorting networks (oe-sort) (Batcher [10]) are known to have optimal size for input with less than 9 elements, and have asymptotic size
Asín et al. [7] note that when sorting networks are used to encode cardinality constraints, one only needs the kth output of the sorting network and they devise a method of only providing the k lowest values of the output in sorted order using no more than
Codish and Zazon-Ivry [12] provide a method for achieving size
The merge-sort network
Both the totalizer and oe-sort are based on a merge-sort pattern. Unlike oe-sort, the totalizer encoding is not based on compare-and-swap operations, but implements merging in another way. The merge-sort pattern that the two encodings share is a function which we define in the following way:
(Sort).
The function sort takes a list of input variables and returns a pair of a list of output variables and a set of clauses S, such that S enforces that the outputs are the inputs in sorted order (1s before 0s).
The base case is:
As mentioned, we will use this pattern for both totalizer and oe-sort, the only difference will be how merge is defined. We should therefore take care to describe what we require from merge.
Let M be the network
Note that, with unidirectional merge the network does not sort in a strict sense. However, it is still a correct encoding of the cardinality constraint: all input 1’s are propagated.
As noted by Asín et al. [7], although bidirectional merge is useful for encoding cardinality constraints of the form
Note that we need no more than the
An encoding based on the merge-sort lends itself immediately to incrementality, new literals can be added to the list by merging, but we generalize by using delayed variables.
We can obtain k-simplification with delayed variables: we rely on the sort function delaying all input and output variables of merge operations with index larger than k which in turn will reduce the size of the merge operation. How much the size is reduced depends on the implementation of merge which we will discuss later.
Let us say we want to encode
To increase k to
However, the above setup ignores the fact that m might be much smaller than n so that we might have to apply a large number of merges, each time increasing the number of sorted variables by very little. This leads to not achieving the aforementioned size bounds on the totalizer and oe-sort encoding.
Our proposed remedy is to use an amortized update scheme. We instead update the encoding to
The variable
We now review the totalizer encoding (Bailleux and Boufkhad [9]), and the k-simplification of Koshimura et al. [17]. We describe an incremental version of this encoding based on delayed variables, which is equivalent to the incremental version described by Martins et al. [23]. We will describe the totalizer merge function, and rely on the sort function (Definition 1) to provide the remaining elements of the cardinality encoding.
(Totalizer merge function).
Since tot-merge creates
By delaying all input and output variables with index larger than k in each merge operation, sorting with tot-merge only produces
First we observe that each merge produces only
The size of M is
S produces
Although we achieve smaller encodings using this approach, under some conditions, tot-merge is not bidirectional when k-simplification is applied:
In
The only undelayed clauses containing
Note that this cannot be easily repaired as we require the clause
As apposed to tot-merge, oe-sort merging is done using compare-and-swap operations. A compare-and-swap operation
In order to use sorting networks to encode
The clauses (4)–(6) are what is required for unidirectional merge, but by adding all we get bidirectional merging.
We will now describe the odd-even merge network. We refer to Asín et al. [7] for correctness of the construction as it will be similar to the definition given there.
(Odd even merge network).
For sequences of length 1 the odd-even merge function is defined in the following way:
To simplify the following proofs, we will divide a oe-merge operation into recursion levels. We say that a “call” to oe-merge by sort has recursion depth 0, while any subsequent call has depth 1+r where r is the recursion depth of the merge “calling” it. A recursion level is the collection of merges with same depth stemming from the same merge operation. The output (input) variables of a level are the output (input) variables of all merge operations in that level.
Delaying auxiliary variables
The sort network will ensure that the appropriate outputs and inputs are delayed. However, unlike with totalizer, oe-merge will create auxiliary variables in the two recursive calls to oe-merge. To lower the number of undelayed clauses we have to delay auxiliary variables. This is done by propagating delayed variables through swaps using the following rules:
We will explain why these rules correctly delay unused clauses and variables. To do so we first need to formalize the well known fact that monochromatic variables, that is, variables that only occur negated or only unnegated in the formula, have little impact on the set of models.
Let p be a variable and
Rule (11) can be understood as follows. Let the swaps be unidirectionally encoded by (4)–(6). Delaying
We will have to take care with these rules when variables are undelayed. In essence when inputs or outputs to oe-merge are undelayed some auxiliary variables will need to be undelayed as a consequence. In Section 4.7 we will discuss how to efficiently implement delayed variables for sorting networks, but for now it is sufficient to say that any auxiliary variable a is delayed iff the above propagation rules, started with only delayed inputs and outputs results in a being delayed. This means that the rules will have to be reexamined whenever inputs or outputs are undelayed to find undelayed auxiliary variables.
Using the above rules, the number of undelayed output variables of each level is bounded by the number of undelayed inputs to that level.
The rules preserve that there are no more outputs than inputs in any given swap operation. A merge operation only produces swap operations in such a way that each variable occurs at most once as an input in a swap. Any variable also occurs only once as an output. Therefore a delayed output can be mapped 1-to-1 to a delayed input. □
The propagation rules (11) and (12) do not preserve bidirectionality, for rule (11) the only undelayed clause that remains is
However, this would mean that we could no longer update the constraint. We will show that by using the rules (15) and (16) the merge network simplifies to
Using the rules (
15
) and (
16
) reduces
At some point before the depth of recursion has reached
Using Lemma 3, at each level of recursion, there are at most
We can relate the above propagation rules to those commonly applied in SAT solving. Seeing a delayed clause as one that is set to false, which is admissible when encoding When delaying all input and output variables with index larger than k in an oe-merge network, after propagating delayed variables, only If only the first input variable in each list of a oe-merge is undelayed, then that merge only produces one swap with undelayed clauses, and that swap is generated in the base case of oe-merge. Only in the first The number of swaps with undelayed clauses is therefore at most By delaying all input and output variables with index larger than k in all merge operation, sorting with oe-merge produces In the sorting formula there are only
It is possible to combine the sorting network encoding with the totalizer encoding, as noted by Abío et al. [3]. The reason for doing so is that totalizer, in addition to creating fewer variables, also uses fewer clauses for short input sequences.
Surprisingly, it also provides us with a way of getting asymptotically smaller incremental networks. As noted in the proof of Lemma 4, after
As noted in Abío et al. [3], it might be beneficial to use tot-merge in order to optimize the ratio between the number of clauses and number of variables, and we have observed that totalizer might incur not just fewer variables but also fewer clauses for number of undelayed inputs up to 8.
In the following λ is a parameter controlling how to weigh the number of clauses versus the number variables when minimizing the formula. The
The idea is to minimize the ratio between the number of clauses and the number of variables, and so λ determines how heavily the number of variables should be weighed.
We prove this for
After at most
Abío et al. [3] note that

Number of 2016 MaxSAT competition industrial benchmarks solved over time.

Number of 2016 MaxSAT competition crafted benchmarks solved over time.
We will now describe an efficient implementation of delayed variables suitable for the totalizer, odd-even merge sort and the mixed encoding.
Keeping every delayed clause in memory is not ideal since there can be many delayed clauses, and many of them will never be used. Also, keeping track of the consequences of undelaying a variable is not simple. Instead, in our implementation, indicator variables are undelayed when found in a core and we store additional information in order to discover which variables must be undelayed as a consequence. We also store information for each such variable so that when they are discovered, the clauses that contains them are generated.
Recall that when encoding
By keeping track of the recursive calls to oe-merge and the out-index of each variable, we are able to find which variables to undelay and therefore efficiently generate undelayed clauses. Details of this rather involved procedure are beyond the scope of this paper.
Results
We chose to use the partial MaxSAT benchmarks from the 2016 MaxSAT competition (2016 MaxSAT evaluation [1]). Both industrial and crafted instances were considered. There are versions of the incremental MSU3 and MSU4 algorithms that work with not just the partial benchmarks but also the unweighted and weighted ones as well, see for instance Ansótegui et al. [5]. However, we restrict our experiments to the partial benchmarks as we are only interested in the cardinality encoding aspect of these algorithms.
Figures 1 and 2 show the amount of benchmarks solved using MSU3 and MSU4 in conjunction with the encodings odd-even sorting network, totalizer, mixed (labeled mixed-ratio in the plots), and mixed-limit. Additionally, we compare these results with the MaxSAT solver Open-WBO 1.3.0 (OWBO, Martins et al. [24]), which ranked second on the crafted partial benchmarks in the 2016 MaxSAT competition (2016 MaxSAT evaluation [1]). Open-WBO uses the incremental MSU3 algorithm with the totalizer encoding. Overall, our implementation of MSU3 with the totalizer encoding seems to have similar performance to their implementation, and outperforms Open-WBO on the industrial benchmarks. The incremental interface of the glucose-syrup (Audemard and Simon [8]) was used in the implementation of all experiments.
Choice of λ and threshold
As a preliminary experiment, we selected 30 of the benchmarks from the MaxSAT competition to experiment with varying threshold T in the mixed-limit encoding and λ in the mixed-ratio encoding. We chose to set T to a multiple τ of the number of input clauses. Results are shown in Fig. 3.
For τ, performance seems roughly the same for values larger than 2. When
We chose to use
Experiments with the 2016 MaxSAT partial benchmark set
Overall it seems that MSU3 works best for the crafted instances, while MSU4 is better for the industrial instances. For encodings, the benchmarks favor heavily the totalizer encoding. The mixed-limit approach solves two extra instances of the crafted benchmarks than the totalizer encoding, which is already quite good, and one extra for the industrial benchmarks. All benchmarks solved with the totalizer encoding are also solved using the mixed-limit encoding. This behavior seems to be caused by the mixed-limit encoding avoiding an explosion in the number of clauses on some benchmarks while using totalizer in most other cases.

Experiments with 30 selected benchmarks, varying λ and τ.
For both MSU3 and MSU4 using the odd-even sorting networks alone performed very poorly. Additionally, the mixed encoding performed better when odd-even merges are used very sparingly. This is contrary to findings of Martins [22]. In their experiments, the totalizer encoding performs less favorably than odd-even sorting networks. However, those experiments were done with a non-incremental setup. It therefore seems that the totalizer encoding gains an advantage when there is no need to regenerate the entire formula.
A version of the solver used for these experiments was submitted to the 2017 MaxSAT Evaluation (2017 MaxSAT evaluation [2]) where it placed 4th out of 8 solvers in the unweighted category. In addition to using the mixed-limit incremental encoding, it combined using both the MSU3 and MSU4 algorithms as the union of solved instances by these algorithms is larger than the intersection.
In this paper we investigated an incremental setup of the MSU3 and MSU4 algorithm together with several schemes for encoding the cardinality encoding. We found that a combination of the totalizer encoding and the sorting networks encoding can increase performance slightly if the totalizer encoding is favored heavily. Most notably, unlike in other works where both the totalizer encoding and the sorting networks encoding is used (Abío et al. [3], Martins [22]), sorting networks alone seem to have poorer performance than the totalizer encoding. This might hint at some unidentified advantage of the totalizer encoding which might be explored further.
