Keywords

These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.

1 Introduction

Nowadays, Satisfiability Modulo Theories (SMT) solving is widely applied. Traditionally, SMT solvers are expected to return any model (satisfying assignment), given a satisfiable formula, but many applications require a model which optimizes some user-given function [12, 13, 23, 24, 32, 38]. The problem of finding the optimal model in SMT is called Optimization Modulo Theories (OMT) [35].

OMT was first addressed in [32], which presented a general OMT framework, in which the minimization/maximization cost function is restricted to Boolean variables. The restriction of the cost function to Boolean variables was lifted in [35]. In that work, a solution for optimization modulo linear arithmetic over the rationals was proposed, where the cost function can be an arbitrary arithmetic term. The two basic approaches to optimization, given a satisfiability solver, applied in [35], are binary and linear search, respectively, for the optimal assignment. In [35], both approaches are customized and tuned to arithmetic reasoning in the context of the DPLL(T) approach to SMT [18].

Bit-vector (BV) SMT theory [5] is a highly expressive theory, where the variables are fixed-size bit-vectors and the set of operators includes arithmetic, comparison, bit-wise, and bit-propagating (e.g., extraction, concatenation, shifts) operators. BV solvers are widely applied [15, 20, 25, 26, 34, 42]. Given a BV formula F, we define the problem of Optimization modulo Bit-Vectors (OBV) to be the problem of finding a satisfying assignment to F which maximizes some user-given target bit-vector term t in the formula, where the term is interpreted as an unsigned number. (Minimization can be modeled as maximization of the target’s negation.)

Our definition lets the cost function be as generic as possible (similarly to the approach of [35] to arithmetic optimization) as the target term can be an arbitrary function over the formula’s input variables. Let our maximization target be \(t=\left[ v_{n-1},v_{n-2},\ldots ,v_0\right] \), where \(v_i\)’s are bits and \(v_0\) is the Least Significant Bit (LSB). Note that our semantics induces a strict priority for satisfying the bits of t in the following sense. The solver will prefer satisfying bit i while leaving the lower bits \(i-1, \ldots , 0\) unsatisfied, to satisfying bits \(i-1, \ldots , 0\) while leaving bit i unsatisfied (since, e.g., the value \(\left[ 1000\right] =8\) is higher than the value \(\left[ 0111\right] =7\)).

Surprisingly, OBV research is scarce. We are not aware of any paper dedicated to OBV. The only existing solver supporting OBV is an extension to the Z3 SMT solver, called \(\nu Z\) [8, 9]. \(\nu Z\) solves OBV by applying the following reduction to weighted MAX-SAT, proposed in [7] (where, given a set of hard Boolean clauses and a set of soft weighted Boolean clauses, weighted MAX-SAT finds a satisfying assignment to the hard clauses maximizing the weight of the satisfied soft clauses). First, the input BV formula is translated to hard Boolean clauses. Second, for each \(i \in \left\{ 0, 1, \ldots , n\right\} \), a soft weighted unit clause \((v_i)\) of the weight \(2^i\) is added to the formula. The reduction guarantees that the solver will give a strictly higher priority to satisfying bit number i than to bits \(i-1, \ldots , 0\), thus ensuring that t’s value is maximized. Note that applying a similar reduction with equal weights given to the bits of t would result in maximizing the number of satisfied bits in t, rather than t’s value.

This paper proposes two new algorithms for OBV solving by leveraging binary and linear search to eager BV solving [17, 21]. Both algorithms are easy to implement. Both are incremental. Both take advantage of the SAT solver’s conflict analysis capabilities to prune the search space on-the-fly.

The application which triggered our OBV research emerged during the placement sub-stage of the physical design stage of the Computer-Aided Design (CAD) [39] flow at Intel. Assume that after a placement of standard cells has already been generated, a new set of design constraints of different priority, introduced late in the process, has to be taken into account by the placement flow. Re-running the placer from scratch with the new set of constraints would not satisfy backward compatibility, stability, and run-time requirements, hence a new post-processing fixer tool is required. The goal of the fixer is to fix as many as possible of the violations resulting from applying the additional design constraints, with preference being given to fixing high-priority violations. We will demonstrate that this problem can be reduced to optimization modulo either bit-vectors or linear integer arithmetic (LIA). Section 6 of this work shows that our algorithms have substantially better capacity on real-world and crafted placement fixer benchmarks than \(\nu Z\) in both LIA and BV mode and OptiMathSAT [36, 37] in LIA mode (the crafted benchmarks are publicly available at [29]).

In what follows, Sect. 2 contains preliminaries. Section 3 introduces our reduction of the placement fixer problem to optimization modulo BV and LIA. Sections 4 and 5 present our OBV algorithms. Section 6 presents the experimental results, and Sect. 7 concludes our work.

2 Preliminaries

We start off with some basic notions. A bit is a Boolean variable which can be interpreted as 0 or 1. A bit-vector of width n, \(v^{\left[ n\right] }=\left[ v_{n-1},v_{n-2},\ldots ,v_0\right] \), is a sequence of n bits, where bit \(v_0\) is the Least Significant Bit (LSB) and \(v_{n-1}\) is the Most Significant Bit (MSB). We consider Boolean variables and bit-vector variables of width 1 to be interchangeable. A constant is a bit-vector each one of whose bits is substituted by 0 or 1. A bit-vector operation receives one or more bit-vectors and returns a bit-vector. A Term DAG is a Directed Acyclic Graph (DAG), each of whose input nodes (that is, nodes with in-degree 0) comprises a bit-vector or a constant and each of whose internal nodes (that is, nodes with in-degree \({>}\,0\)) is an application of a bit-vector operation over previous nodes. A BV formula F is a term DAG, where some of its Boolean terms are asserted to 1 (that is, they must be assigned 1 in every assignment which satisfies F).

The only assumption this paper makes about the input BV formula is that it can be translated to Conjunctive Normal Form (CNF) in propositional logic (a CNF formula is a conjunction of clauses, where each clause is a disjunction of Boolean literals, and a Boolean literal is a Boolean variable or its negation). This assumption holds for the BV language as defined in the SMT-LIB standard [5]. See [19] for a further overview of BV syntax and semantics.

Let \(\mu \) be a full assignment to the variables of a BV formula F and v be a term in F. We denote by \(\mu (v)\) the value assigned to v in \(\mu \), interpreted as an unsigned number.

A BV formula F is satisfiable iff it has a model (where a model is a satisfying assignment). A model \(\mu \) to F is t -maximal iff \(\mu (t) \ge \nu (t)\) for every model \(\nu \) to F.

Given a BV formula F and a term t in F, where t is called the optimization target, let the problem of Bit-Vector Optimization (OBV) be the problem of finding a t-maximal model to F.

A SAT solver [6, 27, 40] receives a CNF formula F and returns a model, if one exists. In incremental SAT solving under assumptions [14, 30, 31], the user may invoke the SAT solver multiple times, each time with a different set of assumption literals and, possibly, additional clauses. The solver then checks the satisfiability of all the clauses provided so far, while enforcing the values of the current assumptions only. In the widely used Minisat’s approach [14] to incremental SAT solving under assumptions, the same SAT solver instance solves the entire sequence internally. The assumptions are modeled as first decision literals in the user-given order. Each assignment to an assumption is followed by Boolean Constraint Propagation (BCP). If the solver discovers that the negation of one of the assumptions is implied by other assumptions during BCP, it halts and returns that the problem is unsatisfiable. Whenever the solver unassigns one or more of the assumptions following a backtracking or a restart, it reassigns the unassigned assumptions in the user-given order (where each assignment is followed by BCP) before picking any other decisions.

An eager BV solver [11, 17] works by preprocessing the given BV formula [11, 17, 28], bit-blasting it to CNF and solving with SAT.

3 Modeling the Placement Fixer Problem

This section details the placement fixing problem, mentioned in Sect. 1, and shows how to reduce it to an optimization problem modulo either BV or LIA.

3.1 Problem Formulation

We start with the problem formulation. We will be using the example in Fig. 1 for illustration.

Initial Set Up. We are given a grid of size (XY) and a set of n non-overlapping (but possibly touching) rectangles \(r_1, \ldots , r_n\) placed on the grid. Each rectangle \(r_i\)’s initial placement is given as the coordinates of its bottom-left corner (\(x_i\),\(y_i\)), height \(h_i\) and width \(w_i\). The example in Fig. 1 has five rectangles.

A placement of rectangles in the grid might have violations between pairs of touching rectangles. A violation \(v(b,t,\delta )\) between the bottom rectangle \(r_b\) and the top rectangle \(r_t\), where \(1 \le b,t \le n\) and \(-w_b< \delta < w_t\), occurs when \(r_b\)’s top side touches \(r_t\)’s bottom side (that is, when \(y_b+h_b=y_t\)) and the relative horizontal position of the rectangles is \(\delta =x_b-x_t\). Each violation \(v(b,t,\delta )\) has a problem-induced unique priority \(p(b,t,\delta ) \in \mathbb {N}\). In other words, the problem causes all the violations to be ranked according to their priority.

In our example shown in Fig. 1, there exist three violations of priority: \(p(1,4,-2)\), p(4, 3, 2), and p(5, 2, 0).

Fixer Goal. Given the initial placement, the fixer may shift the rectangles horizontally or vertically (that is, move each rectangle horizontally or vertically), so as to reduce the number of violations according to their priority. Shifting the same rectangle both horizontally and vertically is allowed. The priority is strictly followed in the sense that fixing one violation of priority p should be preferred to fixing any number of violations of priorities lower than p. Note that shifting existing rectangles might create new violations.

The input problem induces additional constraints on the allowed shifts:

  1. 1.

    Shift constraints: some of the rectangles are non-shiftable (that is, they must not be shifted), while the greatest allowed horizontal and vertical shift for any shiftable rectangle is \(\alpha \) and \(\beta \), respectively.

  2. 2.

    Parity preservation: for each rectangle the y-coordinate at the new location must be even iff the original y-coordinate is even.

Consider our example in Fig. 1. Assume that all the rectangles are shiftable and that \(\alpha =2\) and \(\beta =2\). Violation 3 can be eliminated altogether by shifting \(r_5\) down to (6, 0) (shifting it down to (6, 1) is disallowed by parity preservation). The other two violations \(v_1\) and \(v_2\) can be resolved by shifting \(r_4\) to the right to (4, 3). Note that if \(r_4\) had been non-shiftable, violations \(v_1\) and \(v_2\) could have been resolved only at the expense of creating new violations, in which case the optimal solution to the problem would have depended on the actual priorities of the violations (unspecified in our example).

Fig. 1.
figure 1

Fixer placement problem modeling example.

3.2 Problem Encoding

The encoding is shown in Fig. 2. It can be applied to encode our problem into optimization modulo either BV or LIA.

First, the algorithm goes over all the shiftable rectangles. For each rectangle \(r_i\), it creates two new variables \(x'_i, y'_i\) to represent \(r_i\)’s location after the fix (the bit-width of the BV variables is chosen to accommodate the size of the grid). In addition, the algorithm ensures that the parity is preserved. For BV, the parity preservation constraint can be modeled by asserting \( y_i \& 1 == y'_i \& 1\) (where & stands for bit-wise AND). For LIA, it can be modeled in either one of the two following ways: (a) using an auxiliary variable t to assert that \(y_i - y'_i == 2t\), or (b) using LIA’s native mod operator to assert that \(y_i\) mod 2 == \(y'_j\) mod 2.

Second, the algorithm ensures that the rectangles will not overlap after the fix. This can easily be done for both BV and LIA by adding inequalities for each pair of rectangles over the new variables \(x'_i, y'_i,x'_j, y'_j\) to ensure there is no overlap.

Third, the algorithm creates the target term to be used for BV maximization (adjusting our construction to LIA reasoning is explained in the next paragraph). It starts by creating an empty bit-vector u. It then goes over all the potential violations in a loop, in order of priority, starting with the violation of the lowest priority. It formulates a condition c which holds iff the violation occurs after the fix. Then the negation of c is inserted into u as the MSB (using concatenation).

Our construction guarantees that the fixer accomplishes the task of generating a placement having as few violations as possible while strictly following the priority, iff u is given the maximal value. Hence, the solver is asked to maximize the value of u in the case where BV reasoning is applied. To achieve the same effect for LIA, the algorithm maximizes the bits of u lexicographically starting from the MSB and going towards the LSB (lexicographical maximization for LIA is available in both \(\nu Z\) and OptiMathSAT).

Fig. 2.
figure 2

Placement fixer: encoding

Note that one cannot use integer linear programming (ILP) to encode our problem efficiently, since our problem requires using disjunctive constraints to prevent overlaps between pairs of rectangles. Specifically, given any two rectangles \(r_1\) and \(r_2\), it is either that \(x'_1 > x'_2 + w_2\) or \(x'_2 > x'_1 + w_1\) (similar equations must be generated for y coordinates). One could, though, use Linear Disjunctive Programming (LDP) [2, 3] to encode our problem. We have left the non-trivial work of reducing our problem to LDP to the future.

4 Optimization with Weak Assumptions

Our first OBV algorithm is based on a modification to Minisat’s approach to SAT solving under assumptions, called SAT solver under weak assumptions. We call our algorithm OBV-WA (standing for Optimization modulo Bit-Vectors with Weak Assumptions). It can also be understood as a linear search for the t-maximal model starting with the highest possible value of t and going towards 0, where the algorithm stops at the first satisfying assignment. Section 6 will demonstrate that OBV-WA is substantially more efficient than the Naïve Linear Search (NLS) algorithm, depicted below (given a satisfiable formula F and the optimization target t):

figure a

4.1 OBV-WA Algorithm

Assume an eager BV solver is provided with a satisfiable BV formula F and an optimization target \(t^{\left[ n\right] }\) and is requested to find a t-maximal model to F (one can verify that F is satisfiable by invoking a BV solver before applying our algorithm). First, OBV-WA translates F to CNF (following an optional invocation of word-level preprocessing). Then it applies a SAT solver, where literals corresponding to the bits \(t_{n-1},t_{n-2},\ldots ,t_0\) are provided to the solver as weak assumptions which are processed as follows. The SAT solver assigns the weak assumptions as the first decision variables in the specified order (from the MSB \(t_{n-1}\) towards the LSB \(t_0\)), where BCP follows each assignment. If the solver discovers that the negation of one of the assumptions is implied by other assumptions during BCP, it continues to the next assumption (in contrast to returning that the problem is unsatisfiable, as in Minisat’s approach to SAT solving under assumptions).

This simple adjustment of Minisat’s algorithm guarantees that the solver returns a t-maximal model. Indeed, OBV-WA checks the satisfiability of F under every t value starting from \(t=2^n-1\) towards \(t=0\) in decreasing order. t is decreased by \(\delta >1\) only once the solver proves that there is no model in the range \(\left[ t, t-\delta +1\right] \). Indeed, the bit \(t_i\) is flipped by the solver to 0 only if there is no model to F with \(t_i=1\).

The algorithm in Algorithm 1 is an implementation of OBV-WA. It contains the following three functions:

  1. 1.

    Solve: the main function invoked by the user: given a BV formula F and an optimization target \(t^{\left[ n\right] }\), it returns a t-maximal model. The function initializes an index i, which points to the next unassigned assumption, with \(n-1\). It also initializes \({ dl\_wa}\) to 0, where \({ dl\_wa}\) is the highest decision level where a weak assumption is assigned as a decision literal. It then invokes a SAT solver with decision and backtrack strategies modified as specified below. The algorithm returns the model found by the SAT solver (we assume an implicit conversion from the Boolean model returned by the SAT solver to the corresponding BV model to the original formula).

  2. 2.

    OnDecision: invoked by the underlying SAT solver to get a decision literal when it has to take a decision. It receives the next decision level. OnDecision returns the next unassigned assumption, if any, and decreases the index i by 1. Assigned assumptions are skipped. If an unassigned assumption is found, the function stores the assumption’s index in a decision level indexed array \({ SavedI}\) and updates \({ dl\_wa}\). This is required for proper backtracking. If all the assumptions are assigned, a standard SAT decision heuristic is applied.

  3. 3.

    OnBacktrack: invoked by the SAT solver whenever it backtracks. It receives the decision level to backtrack to. If the decision level is higher than \({ dl\_wa}\), nothing is done. Otherwise, the function updates the assumption index i so as to point to the next unassigned assumption. It also updates \({ dl\_wa}\) accordingly.

Note that the decision level of an assigned weak assumption i might be different from \(n-i\), since any assumption could entail other assumptions at the same decision level. For this reason, the algorithm must maintain the mapping \({ SavedI}\) from the decision level \({ dl}\) of each assigned weak assumption to its index i.

An approach similar to SAT solving under unordered weak assumptions has recently been used in [10] to reduce the number of faults in model-based safety analysis. The contribution of our work is in reducing OBV to SAT solving under weak assumptions, where the assumptions must correspond to the target variable bits, ordered from the MSB towards the LSB.

4.2 Incrementality

OBV-WA is incremental in the same sense as Minisat’s algorithm: it can be invoked multiple times with different optimization targets, where the formula can be extended between the invocations. This type of incrementality is now supported in the new SMT-LIB format SMT-LIB 2.5 [4]. To support incremental push/pop, another type of incrementality inherited by SMT-LIB 2.5 from SMT-LIB 2.0, one can use selector literals as follows: following each push, add a fresh selector literal s to every clause in the bit-blasted formula and then add \(\lnot s\) as a (strong) assumption. To pop, add the unit clause \(\lnot s\). To use both strong and weak assumptions in one invocation, simply assign first the strong assumptions and then the weak ones.

figure b

5 Optimization with Inline Binary Search

In this section we present our second OBV algorithm, called OBV-BS (standing for Bit-Vector Optimization with Binary Search). We will see in Sect. 6 that OBV-BS’s is considerably more efficient than the Naïve Binary Search (NBS) algorithm performing a binary search for the maximal t value using the SMT solver as an oracle.

5.1 OBV-BS Algorithm

Like OBV-WA, this algorithm first translates the formula to CNF. It then applies a binary search-style algorithm implemented on top of an incremental SAT solver.

We need to extend our definitions for the subsequent discussion in the context of OBV solving given a formula F and the optimization target t. Let the value of an assignment \(\alpha \) to F be \(\alpha (t)\) (that is, the value assigned to the target t in \(\alpha \)).

For a partial assignment \(\alpha \), we define its value \(\alpha (t)\) to be equal to \(\alpha _0(t)\), where \(\alpha _0\) extends \(\alpha \) by assigning 0 to all the unassigned bits of t. Values of assignments induce an order between them. In particular, an assignment \(\alpha \) is higher, lower, or equal to \(\beta \), if \(\alpha (t) > \beta (t)\), \(\alpha (t) < \beta (t)\), or \(\alpha (t) = \beta (t)\), respectively. We sometimes interpret assignments to F as Boolean assignments, assigning values to the bits of BV variables individually. Alternatively, we sometimes interpret assignments to F as sets of Boolean literals, where each assigned bit b of a BV variable appears as either b or \(\lnot b\).

Consider Algorithm 2 implementing OBV-BS. The algorithm maintains the current model \(\mu \), initialized with an arbitrary model to F at line 3, and a partial assignment \(\alpha \), which is empty in the beginning. The main loop of the algorithm (starting at line 5) goes over all the bits of the optimization target t starting from the MSB \(t_{n-1}\) down to \(t_0\). Each iteration extends \(\alpha \) with either \(t_i\) or \(\lnot t_i\), where \(t_i\) is preferred over \(\lnot t_i\) iff there exists a model where \(t_i\) is assigned 1 while bits higher than i have already been assigned in previous iterations. In other words, \(t_i\) is preferred whenever there exists a model whose value is greater than or equal to \(\alpha (t) + 2^i\). Essentially, the algorithm implements a binary search over all the possible values of the optimization target t, where the search is automatically pruned based on the conclusions of the SAT solver’s conflict analysis.

The algorithm is incremental in the same sense as OBV-WA, that is, it fully supports Minisat-style incremental solving under assumptions, while push/pop can be supported through selector variables.

5.2 Correctness Proof

Three invariants, which hold throughout the algorithm at the beginning of the algorithm’s loop, are shown in Fig. 3. According to Inv. 1, \(\mu \) must be a model. According to Inv. 2 and 3, \(\alpha \) is always a subset of \(\mu \) and any t-maximal model, respectively (where the assignments are interpreted as sets of Boolean literals). Note that if the invariants hold, then at the end of the algorithm \(\mu \) is a t-maximal model, since: (a) by the end \(\alpha \) will have assigned values to every bit of t, (b) Inv. 2 ensures that \(\mu \) agrees with \(\alpha \) on all bits of t and (c) Inv. 3 guarantees that \(\alpha \) agrees on all bits of t with t-maximal models.

The invariants clearly hold just before the first loop iteration. Consider an arbitrary iteration of the loop. We assume that the invariants hold at its beginning.

First, the algorithm checks whether the current bit \(t_i\) is 1 in \(\mu \) (at line 6). If it is, \(\alpha \) is simply extended with \(t_i\) and the algorithm goes on to the next iteration. Let us verify that the invariants hold at the end of an iteration in this case. First, \(\mu \) is not changed, hence Inv. 1 still holds. Second, \(\alpha \) is extended with a \(\mu \) literal, thus Inv. 2 is preserved. Inv. 3 and 2 hold in the beginning of the iteration, hence any t-maximal model \(\nu \) agrees with \(\alpha \) and \(\mu \) on the values of the Boolean variables \(t_{n-1},\ldots ,t_{i+1}\). Any such \(\nu \) must also contain \(t_i\) positively, since otherwise \(\mu \)’s value would have been higher than that of \(\nu \). Thus, Inv. 3 is preserved.

Assume now that \(t_i=0\) in \(\mu \), that is \(\lnot t_i \in \mu \). In this case (the treatment of which starts at line 9), the algorithm checks whether there exists a model (different from \(\mu \)) that extends \(\alpha \) with \(t_i\). It does this by invoking a SAT solver and providing it \(\alpha \) and \(t_i\) as (strong) assumptions.

If the problem is satisfiable and a model \(\tau \) is found, we update \(\mu \) to \(\tau \) and continue to the next iteration of the loop. Let us verify the invariants at the end of the loop for this case. \(\mu \) is still a model after the update, so Inv. 1 holds. \(\alpha \) still agrees with \(\mu \) on all \(\alpha \) values, since the \(\alpha \) values have been provided to the SAT solver as assumptions, so the updated \(\mu \) must contain them. Thus, Inv. 2 is preserved. Inv. 3 still holds, since \(\alpha \) has not been changed.

In the only remaining case, if the SAT solver returns UNSAT, we extend \(\alpha \) with \(\lnot t_i\). Let us verify the invariants. Inv. 1 is preserved, since \(\mu \) is not changed. Inv. 2 is preserved, since \(\mu \) must contain \(\lnot t_i\) according to our algorithm’s flow (otherwise, the condition at line 6 would hold). Finally, any t-maximal model must still agree with \(\alpha \), preserving Inv. 3 for the following reasons. The only potential disagreement could be regarding the value of \(t_i\), since Inv. 3 holds at the beginning of the loop. But the outcome of our SAT query guarantees that there is no model containing \(\alpha \) and \(t_i\), hence any t-maximal model must contain \(\lnot t_i\).

Fig. 3.
figure 3

OBV-BS invariants

figure c

5.3 Performance Optimizations

We have implemented two important performance optimizations for Algorithm 2:

  1. 1.

    In non-incremental mode, one can add unit clauses instead of the assumptions at lines 7 and 13. This is expected to boost the performance, since it has been shown that using unit clauses instead of assumptions results in a substantial performance improvement in the context of incremental SAT solving under assumptions [28, 30].

  2. 2.

    Modern SAT solvers apply phase saving [16, 33, 41] as their polarity selection heuristic. In phase saving, once a variable is picked by the variable decision heuristic, the literal is chosen according to its latest value, where the values are normally initialized with 0. In our implementation of OBV-BS we initialize the phase saving values of all the bits of the optimization target t to 1 in each invocation, encouraging the solver to prefer a higher value for t’s bits by default. This optimization allows the algorithm to converge faster.

5.4 Comparing OBV-WA and OBV-BS

Let us compare OBV-WA and OBV-BS at a high-level. OBV-WA should work better when the t-optimal model’s value has many 1’s in it, since OBV-WA tries to assign 1’s to all the bits of t whenever possible. Otherwise, OBV-BS is expected to perform better. In addition, OBV-BS has the advantage that it always has an approximation of the maximal model that can be returned to the user if optimality can be traded for performance. OBV-WA does not have intermediate non-optimal solutions.

6 Experimental Results

We have implemented our algorithms OBV-WA and OBV-BS in Intel’s eager BV solver Hazel. This section studies the performance of OBV-WA and OBV-BS on industrial placement fixer benchmarks as well as publicly available placement fixer benchmarks crafted by us [29].

The crafted benchmarks consist of diversified instances of the generic problem of placing rectangles on a grid, described in Sect. 3. First, we created a number of families, where a family is defined per grid size \(g \times g\), where \(g \in \left\{ 10,25,50,75,100\right\} \). Each family consists of 40 benchmarks. Let the density of a benchmark \(d \in \left\{ 0.2, 0.5, 0.7, 0.9\right\} \) be the fraction of occupied grid cells. Each family has 10 benchmarks for each of the four possible density values. The size and coordinates of the rectangles for each benchmark are drawn randomly, where the size of rectangles’ sides is drawn from the set \(\left\{ 1, 2, \ldots , \left\lceil g/10 \right\rceil \right\} \). Second, we crafted another family of high-density instances, called HD (High-Density), for grid size \(50 \times 50\). Each benchmark in the HD family was created by placing rectangles on the grid until all the room was exhausted.

For the comparison we used two publicly available OMT solvers: \(\nu Z\) [8, 9] (version 4.3.3) in BV and LIA modes, and OptiMathSAT [36, 37] (version 1.3.5) in LIA mode. \(\nu Z\) and OptiMathSAT are extensions of the leading SMT solvers Z3 and MathSAT, respectively, for OMT. Note that \(\nu Z\) is the only available solver that supports OBV.

Recall from Sect. 3.2 that we presented two ways of encoding the parity preservation constraint \(y_i\) mod 2 == \(y'_j\) mod 2: (a) using an auxiliary variable t to assert that \(y_i - y'_i == 2t\), or (b) using LIA’s native mod operator. We experimented with \(\nu Z\) in LIA mode on benchmarks generated with both encodings. \(\nu Z\)-BV, \(\nu Z\)-LIA, and \(\nu Z\)-LIA-m below stand for, respectively, \(\nu Z\) in BV mode, \(\nu Z\) in LIA mode using auxiliary variables to encode parity constraints, and \(\nu Z\) in LIA mode using the LIA’s native mod operator to encode parity constraints. We used OptiMathSAT with only the auxiliary variable-based encoding, since OptiMathSAT does not support the mod operator.

We have also implemented the Naïve Linear Search (NLS) and Naïve Binary Search (NBS) algorithms (recall the beginning of Sects. 4 and 5, respectively) on top of Hazel.

We used machines with 32 GB of memory running Intel\(\circledR \) Xeon\(\circledR \) processors with 3 GHz CPU frequency. The time-out was set to 1800 s. Detailed experimental results are available in [29].

Consider Table 1. It presents the number of instances solved within the time-out per family, where a family is defined per grid size for all crafted instances, except for the HD family. In addition, we considered a family of 50 industrial instances. The family name is shown in column 1. Column 2 shows the average number of unsatisfied bits in the optimization target t (in the optimal solution), while column 3 provides the number of SAT calls within OBV-BS on average. The number of instances per family is shown in column 4. (Statistics are not available for the industrial instances because of IP considerations.) The subsequent columns present the number of instances solved for a particular solver.

Table 1. Comparing OBV algorithms
Fig. 4.
figure 4

Comparing OBV-WA to OBV-BS on \(100\times 100\) grids.

Fig. 5.
figure 5

Comparing OBV-WA to OBV-BS on industrial instances.

Consider the non-HD crafted instances and the industrial instances. Our algorithms clearly outperform the current state-of-the-art. Both OBV-WA and OBV-BS solve all the non-HD crafted instances and all the industrial instances. None of the other solvers can solve a single industrial instance. \(\nu Z\), in each one of the three modes, solves only a portion of the crafted \(50\times 50\) instances, and can solve none of the crafted \(100\times 100\) instances. OptiMathSAT is outperformed by the other solvers on the crafted instances. The naïve binary and linear search algorithms (NBS and NLS) are not competitive.

Figures 4 and 5 compare OBV-WA to OBV-BS head-to-head on \(100 \times 100\) grids and industrial instances, respectively. One can see that OBV-WA consistently outperforms OBV-BS on both the crafted and the industrial instances. In light of these results, OBV-WA is now applied for the placement fixing problem at Intel.

Strikingly, the apparent advantage of OBV-WA does not extend to the HD family. OBV-BS solves all the HD instances, while OBV-WA only solves a single HD instance (the other solvers solve none of the HD instances). This phenomenon is explained by the fact the number of unsatisfied bits in the maximal solution is significantly higher for the HD family. Our conclusion is that OBV-BS is more robust than OBV-WA, but in practice OBV-WA might still be preferred, if the instances are not too difficult.

7 Conclusion

This paper is the first full-blown work dedicated to the problem of Optimization modulo Bit-Vectors (OBV). We have presented two incremental OBV algorithms, which can easily be implemented in an eager Bit-Vector (BV) solver.

We have implemented our algorithms and studied their performance on real-world instances emerging in the industrial problem of fixing cell placement during the physical design stage of CAD process. The problem can be encoded as either optimization modulo BV or Linear Integer Arithmetic (LIA). We have also experimented with crafted, publicly-available instances that mimick the placement fixing problem.

Our algorithms have shown substantially better capacity than the state-of-the-art Optimization Modulo Theories (OMT) solvers \(\nu Z\) and OptiMathSAT, where OptiMathSAT has been applied in LIA mode and \(\nu Z\) in both BV and LIA modes.

As a future work we intend to study the integration of our algorithms with more recent approaches to incremental SAT solving under assumptions [31]. In addition, we are planning to apply our OBV algorithms to other problems.