On Exploiting Structures for Constraint Solving
Sathiamoorthy Subbarayan Computational Logic and Algorithms Group IT University of Copenhagen
A dissertation submitted to the IT University of Copenhagen in partial fulfilment of the requirements for the degree of Doctor of Philosophy in Computer Science.
Copenhagen, January, 2008
ii
Abstract The constraint satisfaction problem (CSP) instances modeling problems occurring in practice often have structures which can be exploited to speed-up the constraint solving process. This thesis explores the exploitation of three such structures. The three structures explored in this thesis are: 1. Tree-like relationships: Several CSP instances have tree-like relationships between the variables in them. Such a relationship can be observed by using the tree-width parameter. Given a CSP instance with low tree-width, implying close to tree-like relationship, a treedecomposition of the instance could be used to speed-up the constraint solving process. 2. Compact BDD representation: For some finite-domain constraint problem instances, the solutions of each constraint in those instances might be represented by a compact Binary Decision Diagram (BDD). In which case, it is advantageous to represent the constraints using BDDs. This might lead to speeding-up the propagation and other reasoning steps in a constraint solver. 3. Abundance of infrequent variables: In some constraint problem instances, the modeling process might introduce a lot of variables to simplify the encoding of a problem instance. Such introduction of new variables might lead to abundance of variables occurring in only a few constraints. In such cases, the existential quantification of those infrequent variables in a preprocessing step might reduce the effort required to determine the satisfiability of the instance. This thesis explores toward exploiting these three ideas on several problem instances. Suggestions are made toward incorporation of these ideas and those suggestions are supported by empirical data. Since these kind of structures won’t be found in randomly generated CSP instances, the experiments in this thesis were done on instances either mostly from practice or on those close to those occurring in practice. For most of the experiments reported in this thesis, the source code or the executable code used, along with the input data are publicly available for further research. iii
iv
ABSTRACT Some highlights of the results in this thesis are: 1. Using the tree-decomposition of configuration problems lead to up to 96% reduction in space required for BDD-based interactive configuration, while still guaranteeing reasonable response time. 2. Exporting the idea of mixing tree-decomposition with BDDs to the knowledge compilation tasks lead to up to 1000 times lesser space usage than the earlier methods. 3. A new linear-time method for finding a minimal-reason for a variable implication by a BDD, while the earlier method in the worst case requires at least quadratic-time. 4. Existential quantification (by using variable elimination resolution) of infrequent variables in CNF SAT problem instances lead to a significant reduction in the time taken for solving several CNF SAT instances. Subsequently, an extension of this idea has been used in the winning SAT solvers of both the last two SAT solver competitions (during 2005 and 2007). 5. Finally, a new method for hypertree decomposition lead to significant improvement over the earlier methods for hypertree decomposition of CSPs.
Acknowledgments First, I thank my supervisor Henrik Reif Andersen for his support during the past four years. The discussions I had with him in the beginning were quite useful in shaping many of the results in this thesis. He also let me pursue my ideas independently, which at the end has given me a lot of self-confidence. Rune Jensen helped me a lot, both through the research discussions and through his publicly available CLab tool. The CLab tool was quite useful as a starting point to implement and test many of my ideas. I was fortunate enough to do a three month internship at Microsoft Research, Cambridge-UK during the year 2005. I thank the hosts Youssef Hamadi and Lucas Bordeaux, discussions with whom gave me a new dimension to my research skills. I would like to thank Dhiraj Pradhan with whom I worked in Bristol-UK before I moved to Copenhagen. His decades of experience benefitted me. Further I would like to thank current and former members of the CLA research group, in particular Tarik Hadzic, Andrzej Wasowski, Eric van der Meer, Peter Tiedemann, Esben Rune Hansen, K˚ are Jelling Kristoffersen, Jens Chr. Godskesen, Jianjun Chen, Milan Ruzic and Philip Bille. Conference travels, research discussions and general talks with them are memorable. I would also like to thank Sudhakar, Ashok, Vivek, Sanmohan, Srinivas, Aditya and Pradip for hanging out with me in and around Copenhagen. Above all I would like to thank my family, who missed me a lot during the past few years.
v
vi
ACKNOWLEDGMENTS
Contents Abstract
iii
Acknowledgments
v
1 Introduction Appendix: Other Related Contributions . . . . . . . . . . . .
1 6
2 The 2.1 2.2 2.3 2.4
Tree-of-BDDs for Compiling Configuration Problems Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . An Algorithm for Interactive Configuration . . . . . . . . . . Representing Solution Space using Binary Decision Diagrams The BDD Operations . . . . . . . . . . . . . . . . . . . . . . 2.5 The Tree-of-BDDs for Configuration . . . . . . . . . . . . . . Tree Decomposition for CSP Compilation . . . . . . . . . . . The Tree-of-BDDs . . . . . . . . . . . . . . . . . . . . . . . . Configuration Functions on Tree-of-BDDs . . . . . . . . . . . 2.6 Algorithms for Minimum Explanations . . . . . . . . . . . . . Minimum Explanations in the Monolithic-BDD Scheme . . . Minimum Explanations in the Tree-of-BDDs Scheme . . . . . 2.7 Efficient Full Interchangeability Detection for CSP Reformulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.8 Experimental Results . . . . . . . . . . . . . . . . . . . . . . . 2.9 Related work . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.10 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3 Knowledge Compilation Properties of Tree-of-BDDs 3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3.2 The Tree-of-BDDs . . . . . . . . . . . . . . . . . . . . Definitions . . . . . . . . . . . . . . . . . . . . . . . . . The compiler . . . . . . . . . . . . . . . . . . . . . . . 3.3 Queries: Algorithms and Complexity . . . . . . . . . . 3.4 Experiments . . . . . . . . . . . . . . . . . . . . . . . . 3.5 Related Work . . . . . . . . . . . . . . . . . . . . . . . vii
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
9 10 11 16 18 23 24 24 28 31 33 33 43 44 45 48 49 51 52 52 53 55 56 60 63
viii
CONTENTS 3.6
Conclusion and Future Work . . . . . . . . . . . . . . . . . .
4 Efficient Reasoning in BDDs for Nogoods 4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . 4.2 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . The Constraint Satisfaction Problem . . . . . . . . . . The Binary Decision Diagrams . . . . . . . . . . . . . Representing Constraints Using BDDs . . . . . . . . . The Nogoods . . . . . . . . . . . . . . . . . . . . . . . The Reasons for Variable Assignment . . . . . . . . . 4.3 The MINIMUM BDD-REASON is Intractable . . . . . . 4.4 A Linear-Time Algorithm for MINIMAL BDD-REASON 4.5 Related Work . . . . . . . . . . . . . . . . . . . . . . . 4.6 Experiments . . . . . . . . . . . . . . . . . . . . . . . . 4.7 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . 5 The 5.1 5.2 5.3 5.4
5.5
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
64 67 68 68 68 69 69 70 70 71 73 79 80 82
NiVER SAT Preprocessor 85 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 SAT Preprocessors . . . . . . . . . . . . . . . . . . . . . . . . 86 NiVER: Non-increasing VER . . . . . . . . . . . . . . . . . . 88 Experimental Results . . . . . . . . . . . . . . . . . . . . . . . 91 Effect of NiVER on SAT-solvers: BerkMin and Siege . . . . . 91 Effect of NiVER on Time and Memory Usage by Siege SAT Solver . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
6 Backtracking Procedures for Hypertree, HyperSpread and Connected Hypertree Decomposition of CSPs 103 6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 6.2 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 6.3 The Backtracking Procedure . . . . . . . . . . . . . . . . . . 106 6.4 Variants of Hypertree Decomposition . . . . . . . . . . . . . . 109 HyperSpread Decomposition . . . . . . . . . . . . . . . . . . . 109 Connected Hypertree Decomposition . . . . . . . . . . . . . . 112 6.5 Experiments . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 6.6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 A Other Related Contributions
125
Chapter 1
Introduction Constraint models of several real-world problems could be created such that computers could be used in solving those problems. A constraint problem typically consists of several parameters, with each parameter taking a value in some domain, and some constraints by which the parameters could take their values. Examples for constraint problems include: configuration of a product from a catalog of available parts, verification of a microprocessor implementation to check whether it confirms to its specification, and optimal packing of cargo containers in a ship. An example configuration problem is the task of assembling a computer. Given a list of available parts, along with preferences, the task is to find a combination of some of the available parts such that the resulting configuration is valid as per the specifications and also satisfies the preferences as much as possible. The next chapter further explores the configuration problems. In the case of verification problems, an example problem is the task of checking whether two Boolean circuits represent the same Boolean function. Since a circuit might have been designed first, and then automatic tools might have been used to modify the initial circuit for optimizing some criteria, any bug in the automatic tool might result in a bug in the automatically modified circuit. Since modifications introduced by the automated tools are just supposed to optimize the structure of the input circuit and not to modify the Boolean function represented by it, verification tools could be used to check whether the circuit resulting after processing by automated tools represent the same Boolean function as the original one. This problem of verifying the equivalence of two Boolean circuits could be modeled as a conjunctive normal form (CNF) formula, such that the unsatisfiability of the CNF formula implies the equivalence of the circuits. The variables in this example are all Boolean variables and the constraints are clauses (disjunction of literals) defined over those variables. In the case of the optimal packing problems, an example is the packing 1
2
CHAPTER 1. INTRODUCTION
of containers on a ship that iterates between several ports in a sequence. The packing of containers in such a ship should be such that the amount of time that a ship spends at a port is as small as possible. This requires the preference that all the containers to be unloaded at a port form a top layer of the ship when the ship arrives at the port. If the containers to be unloaded at a port does not occur in the top layers of the containers on the ship, then some containers have to be temporarily unloaded just to unload some other containers beneath them. The temporarily unloaded containers, whose destination port is further in the sequence of ports visited by the ship, needs to be placed back on the ship, resulting in more time being spent by the ship at the port, which directly results in additional cost. This preference along with several other preferences in placing containers on ships makes the problem quite complex and tedious for humans to solve satisfactorily. Further, some preferences could be considered as hard, which needs to be satisfied. Other preferences might be soft, and hence could be violated at some cost. Hence, modeling this problem such that computers can help in solving is preferred. The container packing problem in ships could be modeled as an integer linear problem, where the variables would imply the position of the containers on a ship and the linear inequality constraints in the model, defined over the integer and linear variables in the model, would ensure that the hard preferences are satisfied by a container allocation. The objective of the model, which is a function defined over the variables, will be such that finding a solution minimizing the objective will result in satisfying the soft preferences as much as possible. All the three examples require the creation of models representing some problem of importance in the real-world, such that computers could be used to solve those models. The satisfactory solutions to those models will improve the productivity. Hence, the interest in improving existing constraint solvers, which could increase the ability of computers to solve large models of the real-world problems, which in turn will lead to increased productivity. The objective of my PhD work is to improve the ability to solve constraint problem models. The focus is on exploiting the structures in models of finite-domain constraint problems in practice. Even though a constraint problem might be computationally hard, problem instances occurring in practice often have some kind of structures in them. Due to such structures, the instances in practice often are much easier to solve than the difficulty implied by worse case complexity analysis. For example, even though SAT problem is NP-complete, modern SAT solvers [63] are able to solve many real-world SAT instances having thousands of variables and clauses. Similarly, in [65] it has been shown that instances of the automatic test pattern generation (ATPG) problem occurring in practice often are easily solvable due to low cut-width structure, even
3 though ATPG is NP-complete. Hence, even though a constraint problem of importance in practice might be hard in theory, often collecting sample instances and identifying any structures that might occur in those instances might lead to a constraint solver that could be used to solve the problem with reasonable resources. This thesis explores the usage of three different structures on a some classes of constraint problems. The three structures are: low tree-width, compact BDD representation and abundance of infrequent variables. I have published five papers on this topic and they form the technical content of the thesis. Each one of the next five chapters correspond to a published paper. Since those chapters have been published independently, each one of them is self-contained and could be read separately. An overview of those five papers: 1. S. Subbarayan, ”Integrating CSP Decomposition Techniques and BDDs for Compiling Configuration Problems”,CP-AI-OR Conference, Prague, 2005, Springer LNCS 3524. pages 351-365. In this paper, a new propositional representation called Tree-of-BDDs (ToB) was presented, which is a combination of BDDs and tree decomposition [66, 24] techniques. The paper then presents methods for implementing a configurator based on ToBs, by extending the previous known algorithms for BDD-based configurator to work on ToB-based framework. Although, some of the queries of interest to configurators on ToBs are not polytime and at most exponential in the treewidth of the used decomposition, the presented empirical results show the viability of ToBs in comparison with BDDs. The experiments show that ToBs are often very small compared to matching BDDs that, even though configuration methods on ToBs may not be polytime, the ToB-based approach is useful. The paper also presents methods for generating minimum explanations in both BDD and ToB-based configurators. The minimumexplanation method presented for BDDs take time at most linear in the size of the BDD. I had fruitful discussions with Henrik Reif Andersen and Erik Roland van der Meer while working on this paper. Erik Roland van der Meer in his PhD thesis independently developed a dynamic version of ToBs for use in modular configuration systems. 2. S. Subbarayan, L. Bordeaux, Y. Hamadi, ”Knowledge Compilation
4
CHAPTER 1. INTRODUCTION Properties of Tree-of-BDDs ”, AAAI Conference, Vancouver, 2007, pages 502-507. This paper present the properties of Tree-of-BDDs (ToB) which makes it an interesting data-structure for knowledge compilation tools. The paper shows that for a given CNF, an equivalent ToB can be compiled in time at most exponential in the width of the used tree decomposition of the CNF. This shows the scalability of ToB based methods on low tree width instances. The paper then presents algorithms for seven interesting queries on ToBs: consistency, validity, clausal entailment, implicant check, equality, sentential entailment and model enumeration. All the presented methods are at most exponential in the treewidth. The experiments of the paper shows that ToBs are often very small in size when compared to previous methods. The experiments also show the viability of ToBs for knowledge compilation by showing that ToBs in reasonable time can answer non-trivial queries like clausal entailment for several realistic instances, for which previous popular methods fail. The source code of the Tree-of-BDDs software, which can compile both CNF instances and instances from constraint problems like configuration, power supply restoration, fault trees, etc., into Tree-ofBDDs, is available online. 3. S. Subbarayan, ”Efficient Reasoning for Nogoods in Constraint Solvers with BDDs”,PADL Symposium, San Francisco, January 2008, Springer LNCS 4902. pages 53-67. When the propagation of a set of variable assignments A on a constraint c implies a new variable assignment I, a reason R is a subset of A, R ⊆ A, such that the propagation of R on c is enough for implication of I. Such reasons of small size are of interest for the Nogood recording process in constraint solvers. This paper presents a new method for finding small-sized reasons for a variable implication by a BDD. The method, which finds a minimal sized reason, runs in time linear in the size of the BDD representing the corresponding constraint, while the previous method requires at least quadratic-time. The paper also shows that the task of finding a minimum sized reason is NP-complete by reduction from the hitting set problem. Empirical results are also presented, highlighting the scalability of the new method over the previous one.
5 4. S. Subbarayan, D. K. Pradhan, ”NiVER: Non-increasing Variable Elimination Resolution for Preprocessing SAT Instances”, SAT 2004 Conference, Vancouver, 2004, Revised Selected Papers, Springer LNCS 3542. pages 276-291. In this paper, a new preprocessor for CNF instances was presented. The Variable Elimination Resolution (VER) [22] was introduced as a method for determining satisfiability (SAT) of CNF instances in 1960. But for several decades this method was written off as not useful in solving practical sized CNF instances, and methods based on DPLL [21] procedure was used for SAT solving. We found out that a limited version of VER, which does not allow the CNF formula size to increase could lead to removal of up to 50% of the variables in many real-life instances. The paper describes the preprocessor based on this idea and presents an extensive set of supporting experiments. The main idea is quite simple, but the method is very useful. Several researchers in the SAT solving area have used the public release of the NiVER preprocessor tool and reported the results in their articles. Subsequent to the publication of this paper, an improved version of this work was presented in SAT-2005 conference called SatElite [26] preprocessor. The SatElite preprocessor mainly added clause subsumption detection to NiVER. In SAT solver competition of 2005, the SAT solver using SatElite preprocessor won the best SAT solver award. The Rsat [64] SAT solver, the winner of the 2007 SAT solver competition, also uses SatElite preprocessor.
5. S. Subbarayan, H. R. Andersen, ”Backtracking Procedures for Hypertree, HyperSpread and Connected Hypertree Decomposition of CSPs”, IJCAI Conference, Hyderabad, 2007. pages 180-185. This paper presents a new backtracking procedure for hypertree decomposition [38]. The procedure is then presented in a generic form. The variations in the generic form results in two variants of hypertree decomposition: hyperspread and connected hypertree. The hyperspread width is shown to be bounded by both hypertree width [38] and spread cut width [15], which gave a simple positive answer to a recently stated open problem [4] of finding a tractable decomposition technique better than hypertree decomposition. The empirical results of this paper shows the usefulness of the presented methods. The backtracking method presented for hypertree decomposition is an order of magnitude faster than the previous method.
6
CHAPTER 1. INTRODUCTION Further, the connected hypertree decomposition is shown to be a very practically effective variant of hypertree decomposition. The empirical results in the paper, apart from showing the usefulness of the presented ideas, also show that the empirical complexity of the queries corresponding to the decision version of the optimal hypertree decomposition problem peaks around the optimal width, and then tapers down steeply on the right side of the optimal width. This observation could be used in designing procedures for finding close to optimal tree-decompositions in general.
Appendix: Other Related Contributions The appendix of this thesis contains the following five articles, which are related to the thesis topic and could be read for further interest. 1. T. Hadzic, S. Subbarayan, R. M. Jensen, H. R. Andersen, J. Møller, H. Hulgaard, ”Fast Backtrack-Free Product Configuration using a Precompiled Solution Space Representation”, PETO conference, Copenhagen, 2004. pages 131-138. This paper presents the BDD-based configurator framework. The paper shows how the BDDs can be used to pre-compute and store the solutions of some configuration instances, and how the pre-computed structure could be used to quickly answer some configuration related queries.
2. S. Subbarayan, R.M. Jensen, T. Hadzic, H.R. Andersen, J. Møller, H. Hulgaard , ”Comparing two implementations of a Complete and Backtrack-free Interactive Configurator”, CP2004 CSPIA Workshop, Toronto, 2004. pages 97-111. This article presents an experimental comparison of a BDD-based symbolic configurator and a search-based (backtracking) configurator. Although, the implementation of the search-based configurator is probably not the best possible and hence the comparison might not be fair, the experiments show that the BDD-based configurator is very good on several realistic instances. Also, the ease with which the BDDbased tool can be used in comparison with the search-based procedure is highlighted by the effort required in using those two methods.
7 3. S. Subbarayan, H. R. Andersen, ”Linear Functions for Interactive Configuration Using Join Matching and CSP Tree Decomposition”, IJCAI-2005 Configuration Workshop, 2005, Edinburgh. This paper presents preliminary ideas on how the notion of Join Matching on a tree structured CSP instance can be used to implement several configuration related queries in linear time. 4. S. Subbarayan, H. R. Andersen, ”Integrating a Variable Ordering Heuristic with BDDs and CSP Decomposition Techniques for Interactive Configurators”, unpublished manuscript, 2005. This unpublished work presents a variable ordering heuristic for BDDs, called cluster shifting, which groups (clusters) together Boolean variables in a BDD. Each such cluster will encode a single non-Boolean variable of an input problem. The effectiveness of the heuristic was tested on some data. The experiments also show that the effect of variable order on the size of Tree-of-BDDs (ToB) is quite limited in comparison to the effect on BDDs. This shows the relative independence of ToBs to the used variable order. 5. S. Subbarayan, L. Bordeaux, Y. Hamadi, ”On hybrid SAT solving using tree decompositions and BDDs”, Technical Report MSR-TR-2006-28, Microsoft Research, Cambridge, 2006. This technical report presents a new hybrid SAT solver for solving CNF instances. The presented method is a combination of BDDs, treedecomposition and the state-of-the-art SAT solving techniques [63] like clause-learning, watched literals, etc.,. The hybrid method worked very well on a few instances.
8
CHAPTER 1. INTRODUCTION
Chapter 2
The Tree-of-BDDs for Compiling Configuration Problems In this chapter we present the tree-of-BDDs approach for configurators, a decomposition-based method extending the earlier single-BDD approach. We also present efficient techniques for generating minimum cost explanations in the BDD-based configuration schemes. Our algorithm for finding minimum cost explanations in the single-BDD approach just requires time linear in the size of the BDD, under a variable order assumption. Given a BDD representing the solutions of a CSP, a simple technique for detecting full interchangeable values is also presented. Experimental results show that the techniques presented here might often drastically reduce the time and space requirements for interactive configurators.
This chapter is a substantially enhanced version of the paper: S. Subbarayan, ”Integrating CSP Decomposition Techniques and BDDs for Compiling Configuration Problems”,CP-AI-OR Conference, Prague, 2005, Springer LNCS 3524. pages 351-365.
9
10
2.1
CHAPTER 2. TREE-OF-BDDS FOR CSP COMPILATION
Introduction
The complexity of made-to-order products keeps increasing. Examples of such products include personal computers, bikes, and power-backup systems. Such products will be represented in the form of a product model. A product model will list the number of parameters (variables) defining the product, their possible values and the rules by which those parameter values can be chosen. A product model implicitly represents all valid configurations of a product, and it can be viewed as a Constraint Satisfaction Problem (CSP), where the solutions to the CSP are equivalent to valid configurations of the corresponding product model. The increase in the complexity of madeto-order products rises the need for efficient decision support systems to configure a product based on the requirements posed by the customer. Such decision support systems are called configurators. A configurator reads a product model representing all valid configurations of a product, and guides an user in choosing one among the valid configurations as close as possible to his requirements. An interactive configurator takes a product model as input and interactively helps the user to choose his preferred values for the parameters in the product model, oneby-one. The interactive configurator might be required to be complete and backtrack-free. Complete means that all valid configurations need to be configurable using the configurator. Backtrack-Free means that the configurator should not allow the user to choose a value for a parameter in the product model which would eventually lead him to no valid configurations. To ensure backtrack-freeness, the interactive configurator needs to prune away values from the possible values of parameters in the product model as and when those values will not lead to any valid configuration. In addition, the interactive configurator needs to give responses in a short period of time. Examples for commercial interactive configurators include Configit Developer[16] and Array Configurator[7]. The Binary Decision Diagram (BDD) [12] based symbolic CSP compilation technique [42, 70] can be used to compile all solutions of a configuration problem into a single (monolithic) BDD. Once a BDD is obtained, the functions required for interactive configuration can be efficiently implemented. The problem with such an approach is that they do not exploit the fact that configuration problems are often specified in hierarchies. Due to this the BDD obtained after compilation could be unnecessarily large. Such hierarchies are often closer to trees in shape. Hence, the tree decomposition techniques for CSPs could be used to enhance the compilation schemes for configuration problems. In this chapter, we present the tree-of-BDDs approach: a combination of the BDD-based compilation technique and a CSP decomposition technique for compilation of all solutions. Precisely, the contributions of this chapter are:
2.2. BACKGROUND
11
1. A compilation scheme for configuration problems, using the hinge CSP decomposition technique [40] and BDDs. In the experiments the scheme results in upto 96% reduction in space. Response time for interactions also decrease. 2. Efficient minimum explanation algorithms for both the BDD-based compilation schemes. 3. Method to detect full interchangeable (FI) value sets in the two BDDbased compilation schemes. The FI value sets can be used for problem reformulations. 4. Efficient implementation and experimental evaluation of the above techniques. The source code used in the experiments has been placed in the public domain. The drastic reduction in space requirement is of great importance in online configuration applications, where one needs to send the configuration details through the internet, and also in embedded configuration, where one needs to embed the configuration details on a product itself, so that it could be reconfigured as and when required. Reduction in response times enable the tree-of-BDDs scheme to scale higher than the monolithic BDD scheme. In the Section 2.2, the basic definitions are given. In the Section 2.3, the interactive configuration algorithm is listed. Representing solution space using BDDs is discussed in the Section 2.4. The tree-of-BDDs compilation scheme, and the algorithms for explanations and detection of full interchangeable values are presented in the subsequent sections. Experimental results are presented in the Section 2.8. Discussion on related work, followed by some concluding remarks, finish this chapter.
2.2
Background
In this section we give the necessary background. Some of the definitions in this section are based on the definitions in [70, 6, 58]. Definition 1 Let X be a set of variables {x1 , x2 , . . . , xn } and D be the set {D1 , D2 , . . . , Dn }, where Di is the finite domain of values for the variable xi . Definition 2 A relation R over the variables in a set M , where M ⊆ X, is a set of allowed combinations of values for the variables in M . Let M = {xm1 , xm2 , . . . , xmk }, then R ⊆ (Dm1 × Dm2 × . . . Dmk ). The R restricts the ways in which the variables in M could be assigned values.
12
CHAPTER 2. TREE-OF-BDDS FOR CSP COMPILATION X = {x1 , x2 , x3 , x4 , x5 } D = {{0, 1, 2}, {0, 1}, {4, 5}, {0, 1, 3}, {0, 1, 2}} C = {((x1 , x2 ), {(0, 1), (2, 0)}), ({x2 , x3 }, {(0, 4), (1, 4)}), ({x3 , x4 , x5 }, {(4, 3, 0), (4, 0, 2), (5, 3, 2)}), ({x1 , x4 }, {(0, 0), (0, 1), (1, 1), (0, 3)})} Figure 2.1: An example constraint satisfaction problem.
Definition 3 A constraint satisfaction problem instance CSP is a triplet (X, D, C), where C = {c1 , c2 , . . . , cm } is a set of constraints. Each constraint, ci , is a pair (vars(ci ), Ri ), where vars(ci ) ⊆ X is the scope of the constraint and Ri is a relation over the variables in vars(ci ). Definition 4 An assignment is a pair (xi , a), where xi ∈ X and a ∈ Di . The assignment (xi , a) bounds the value of xi to a. A partial assignment, P A, is a set of assignments for all the variables in a X 0 , where X 0 ⊆ X. A partial assignment is complete when X 0 = X. The notation P A|xs , where xs is a set of variables, means the restriction of the elements in P A to the variables in xs. Similarly, R|xs , where R is a relation, means the restriction of the tuples in R to the variables in xs, i.e., the projection of R over the variables in xs. Definition 5 Let vars(P A) = {x | (x, a) ∈ P A}, the set of variables assigned values by a PA. Let val(P A) = {a | (x, a) ∈ P A}, the set of values assigned for vars(P A). A partial assignment P A satisfies a constraint ci , when val(P A|vars(P A)∩vars(ci ) ) ∈ Ri|vars(P A)∩vars(ci ) . Definition 6 A complete assignment CA is a solution S for the CSP when CA satisfies all the constraints in C. Example 1 Fig. 2.1 shows an example CSP. In this example, there are five variables {x1 , x2 , x3 , x4 , x5 } and four constraints. A sample solution for the example is {(x1 , 0), (x2 , 1), (x3 , 4), (x4 , 3), (x5 , 0)}. ♦ Given a CSP instance, the set of all complete assignments CAS ≡ D1 × D2 × . . . × Dn . The number of possible complete assignments is |CAS|. Let SOL denote the set of all solutions of the CSP. To simplify the presentation, we have assumed that the allowed combinations of a constraint is specified as an explicit relation, however in practice often the constraints are specified by symbolic expressions. Several real-world problems can be modeled as CSP instances, including: configuration, scheduling, rostering, and sequencing. Here, we focus on
2.2. BACKGROUND
13
configuration problems modeled as CSP instances and present techniques for efficient interactive configuration. Definition 7 A customizable product specification is given by the available options in the product and the rules confirming which the choices for those options can be selected. Given a customizable product specification, the configuration problem CP is defined as selecting a choice for each of the available options, such that all the rules are satisfied. In this work, we only consider the static configuration problem, in which the number of available options and the rules remain the same throughout the configuration process. In case of dynamic configuration problems [62], some of the choices for the available options might add new options and rules to the configuration problem. Methods for static configuration problems can often be extended to dynamic configuration problems [71]. Example 2 Consider an example, introduced in [71], for specifying a Tshirt by choosing the color (black, white, red, or blue), the size (small, medium, or large) and the print (”Men In Black” - MIB or ”Save The Whales” - STW). There are two rules that we have to observe: if we choose the MIB print then the color black has to be chosen as well, and if we choose the small size then the STW print (including a big picture of a whale) cannot be selected as the large whale does not fit on the small shirt. Fig. 2.2 shows a T-shirt configuration problem as a CSP instance. The configuration problem consists of variables X = {x1 , x2 , x3 } representing color, size and print. Variable domains are D1 = {black , white, red , blue}, D2 = {small , medium, large}, and D3 = {MIB , STW }. The two rules translate to C = {c1 , c2 }, where c1 ≡ (x3 = MIB ) ⇒ (x1 = black ) and c2 ≡ (x3 = STW ) ⇒ (x2 6= small ). There are |D1 ||D2 ||D3 | = 24 possible CAs. Eleven of these assignments are valid configurations and they form the corresponding SOL shown in Fig. 2.3. ♦ Example 3 Consider another example, for specifying a personal computer (PC) shown in the Figure 2.4. There are five options (variables) in the model: cabinet (x1 ), powersupply (x2 ), monitor (x3 ), motherboard (x4 ) and memory (x5 ). There are five constraints in this problem. As shown next in the Figure 2.5, there are nine possible configurations. ♦ Definition 8 A configurator is a tool which helps the user in selecting his preferred product, which needs to be valid according to a given product specification. An interactive configurator IC is a configurator which interacts with the user as and when a choice is made by the user. After each and every choice selection by the user the IC shows a list of unselected options and the valid choices for each of them.
14
CHAPTER 2. TREE-OF-BDDS FOR CSP COMPILATION
X = {x1 , x2 , x3 } D = {{black , white, red , blue}, {small , medium, large}, {MIB , STW }} C = {({x1 , x3 }, {(black , MIB ), (black , STW ), (white, STW ), (red , STW ), (blue, STW )}) ({x2 , x3 }, {(small , MIB ), (medium, MIB ), (medium, STW ), (large, MIB ), (large, STW )})}
Figure 2.2: A T-shirt configuration problem as a CSP instance. (black , small , MIB ) (black , medium, MIB ) (black , medium, STW ) (black , large, MIB )
(black , large, STW ) (white, medium, STW ) (white, large, STW ) (red , medium, STW )
(red , large, STW ) (blue, medium, STW ) (blue, large, STW )
Figure 2.3: The solution space SOL for the T-shirt example.
X = {x1 , x2 , x3 , x4 , x5 } D = {{C1 , C2 , C3 , C4 }, {110V , 220V }, {M1 , M2 , M3 }, {MB1 , MB2 , MB3 , MB4 , MB5 }, {DDR, SDRAM }} C = {({x1 , x2 }, {(C1 , 110V ), (C2 , 110V ), (C3 , 220V ), (C4 , 220V )}) ({x2 , x3 }, {(110V , M1 ), (220V , M2 ), (220V , M3 )}) ({x4 , x5 }, {(MB1 , DDR), (MB2 , SDRAM ), (MB3 , DDR), (MB4 , SDRAM ), (MB5 , SDRAM )}) ({x1 , x4 }, {(C1 , MB1 ), (C1 , MB2 ), (C2 , MB1 ), (C3 , MB3 ), (C3 , MB4 ), (C4 , MB5 )}) ({x1 , x3 }, {(C1 , M1 ), (C2 , M1 ), (C3 , M2 ), (C3 , M3 ), (C4 , M1 ), (C4 , M2 ), (C4 , M3 )})}
Figure 2.4: A PC configuration problem as a CSP instance. (C1 , 110V , M1 , MB1 , DDR) (C2 , 110V , M1 , MB1 , DDR) (C3 , 220V , M2 , MB4 , SDRAM ) (C3 , 220V , M3 , MB4 , SDRAM ) (C4 , 220V , M3 , MB5 , SDRAM )
(C1 , 110V , M1 , MB2 , SDRAM ) (C3 , 220V , M2 , MB3 , DDR) (C3 , 220V , M3 , MB3 , DDR) (C4 , 220V , M2 , MB5 , SDRAM )
Figure 2.5: The solution space SOL for the PC example.
2.2. BACKGROUND
15
The IC only shows the list of valid choices to the user. This prevents the user from selecting a choice which, along with any previous choices made by the user, will result in no valid product according to the specification. We mention such choices as invalid choices. The configurator, hence, automatically hides the invalid choices from the user. When the current PA is extended by the user, some of the choices might be implied for consistency. Such choices are automatically selected by the configurator and they are called implied choices. A configuration problem instance can be modeled as a CSP instance, in which each available option will be represented by a variable and the choices available for each option will form the domain of the corresponding variable. Each rule in the product specification can be represented by a corresponding constraint in the CSP instance. The CAS and SOL of the CSP instance will denote the all possible-configurations and all possible-valid-configurations of the corresponding configuration problem. Hereafter, the terms CSP, CAS, and SOL may be used directly in place of the corresponding configuration terms. Let us assume that the SOL of a CSP can be obtained. Given SOL, the three functionalities required for interactive configuration are: 1. Display 2. Propagate 3. Explain Definition 9 The Display(CSP, SOL0 ) is the function, which for an input CSP whose solution space is SOL and an input SOL’, SOL’ ⊆ SOL, lists X, the options in the CSP and Di0 , the available valid choices, for each option xi ∈ X, where Di0 = {a | (xi , a) ∈ S, S ∈ SOL0 }. The Di0 is the valid domain for the variable xi as per SOL0 . The display function is required to list the available choices to the user of a configurator. Definition 10 The Propagate(CSP, SOL0 , (xi , a)), where a ∈ {a0 | (xi , a0 ) ∈ S, S ∈ SOL0 } , restricts SOL’ to {S | (xi , a) ∈ S, S ∈ SOL0 }. That is Propagate(CSP, SOL0 , (xi , a)) ≡ SOL0 := {S | (xi , a) ∈ S, S ∈ SOL0 }. Hence the Propagate(CSP, SOL0 , (xi , a)) removes each solution S 0 with (xi , a) ∈ / S 0 from the input SOL0 . By the requirements of an IC, the propagation function is necessary. Every time the user selects a choice (xi , a) displayed as available by the configurator, the choice (xi , a) will be added to the current partial assignment P A and the Propagate function will restrict the solution space further by the choice (xi , a) to maintain consistency.
16
CHAPTER 2. TREE-OF-BDDS FOR CSP COMPILATION
The Propagate function could also be written as restricting SOL0 to SOL0 |(xi ,a) . Sometimes the restriction might involve a set of assignments, which is equivalent to making each assignment in the set one by one. An explanation facility is required when the user wants to know why a choice has become invalid. Let PA be the current partial assignment that has been made by the user. Let SOL0 = SOL|P A . Let the propagation of P A results in a ∈ / Di0 , where Di0 = {a0 | (xi , a0 ) ∈ S, S ∈ SOL0 }. This implies (xi , a) is an invalid choice as per P A. Hence, the Display(CSP, SOL0 ) will not list (xi , a) as an available choice for selection. Definition 11 The Explain(CSP, SOL0 , P A, (xi , a)) is the function for generating an explanation E, a set of one or more selections made by the user, E ⊆ P A, which invalidates (xi , a). That is propagation of P A\E does not invalidate (xi , a), while propagation of P A invalidates (xi , a). The E is called an explanation for (xi , a) as per P A. By the definition of explanation, Display(CSP , SOL|P A\E ) will list (xi , a) as a choice for the unselected option xi . Each selection, (xi , ai ), made by the user could be attached a nonnegative value as its priority, P (xi , ai ), and the explain function can be required to find a minimum cost explanation. P Definition 12 The cost of an explanation is Cost(E) = (xi ,ai )∈E P (xi , ai ). An explanation E is minimum, if there does not exists an explanation E’ for (xi , a), such that Cost(E’) 1) // number of solutions more than one? 4: Display(CSP , SOL0 ) // display the valid choices to the user 5: (xi , a) :=’User input choice’ 6: if (a ∈ Di0 ) // where Di0 = {a0 | (xi , a0 ) ∈ S, S ∈ SOL0 } 7: P A := P A ∪ {(xi , a)} 8: SOL0 := Propagate(CSP , SOL0 , (xi , a)) 9: else // a ∈ / Di0 , i.e, an invalid choice for xi 10: E := Explain(CSP , SOL0 , P A, (xi , a)) 11: if ’User prefers (xi , a)’ 12: P A := (P A\E) ∪ {(xi , a)} 13: SOL0 := SOL|P A 14: return P A
Figure 2.6: An Interactive Configurator Algorithm.
At the line-2, the partial assignment is initialized to empty set. Also, SOL0 a copy of the CSP solution space SOL is initialized. An invariant maintained during the configuration process is: ”SOL0 = SOL|P A ”. That is, SOL0 represents the solutions in SOL restricted by the current partial assignment P A. When the P A is such that the corresponding SOL0 has only one solution, i.e., |SOL0 | = 1, then the procedure returns the P A, which implies the preferred configuration of the user. The while-loop at the line-3 iterates until the size of the |SOL0 | = 1. During each iteration of the while-loop, the user either selects a choice (xi , a) displayed to him and extends the P A with the choice, or the user requests an explanation E for an invalid choice a ∈ / Di0 . When an explanation E is presented to the user, if the user prefers to select the invalid choice (xi , a) at the line-11, then the assignments in E are removed from the P A at the line-12 along with the inclusion of (xi , a). Then, the SOL0 is appropriately updated at the line-13. Finally, if the while-loop condition fails implying that the P A implies a single configuration, then the P A is returned by the configurator at the line-14.
18
2.4
CHAPTER 2. TREE-OF-BDDS FOR CSP COMPILATION
Representing Solution Space using Binary Decision Diagrams
In this section, we will describe reduced ordered Binary Decision Diagrams (BDD) and show how a BDD can be used to represent a solution space. A BDD [12] is a rooted directed acyclic graph with two terminal nodes marked 1 and 0, respectively. The Figure 2.7 shows an example BDD. All the non-terminal nodes, including the root, will be associated with a Boolean variable. Each non-terminal node will have two outgoing edges: low (or dashed) and high (or solid). All the non-terminal nodes, in any path, will be ordered based on a linear variable order. A BDD is reduced such that no two nodes in the BDD have the same low and high successors, and no node has the same low and high successors. The variable ordering and the reductions make BDDs canonical for a Boolean function. The BDDs can be used to represent Boolean functions. Given any Boolean function, the corresponding BDD can be obtained by standard composition functions on BDDs representing atomic elements of the Boolean function. Given an assignment to the Boolean variables in the function, there exists a unique path from the root node to one of the terminal nodes, defined by recursively following the high edge, when the associated variable is assigned true, and the low edge, when the associated variable is assigned false. If the path leads to the 1-terminal node, then the assignment is a solution, otherwise not. Given a BDD, any path from the root to the 1terminal node represents one or more solutions. Any variable whose node is not present in such a path is a don’t care variable in the solution. A BDD will be represented by its root node. The size of a BDD is measured by the number of non-terminal nodes. Let n1 and n2 be two nodes in a BDD. Then, the term solid (n1 ) evaluates to n2 iff (n1 , n2 ) is a solid edge in the BDD. Similarly, dashed (n1 ) evaluates to n2 iff (n1 , n2 ) is a dashed edge. Let the Boolean variable associated with a BDD node n be denoted by var(n). The Boolean variable assignment corresponding to an edge (n1 , n2 ) is (var(n1 ), a), where a = true iff n2 = solid(n1 ). That is, if the edge (n1 , n2 ) is solid, then the corresponding assignment is (var(n1 ), true), otherwise the corresponding assignment of the edge is (var(n1 ), false). Consider a path p =< n1 , n2 , . . . , nl > in a BDD with nl = 1, from a node n1 to the 1-terminal. The assignment Ap corresponding to the path p is Ap = {(var(ni ), a) | 1 ≤ i ≤ (l − 1), (ni+1 = solid(ni )) ⇔ (a = true)}. The Ap is the set of the variable assignments corresponding to each edge in the path. The path p is a solution path if n1 = b and nl = 1, i.,e, starts from the root node and ends at the 1-terminal node. Each solution path in a BDD represents one or more solutions of the Boolean function represented by the
2.4. REPRESENTING SOLUTION SPACE USING BDDS
19
BDD. A solution S is represented by a path q if q is a solution path and its corresponding assignment Aq is a subset of S, i.e., Aq ⊆ S. Due to the reduced property of BDDs, few variables (don’t cares) might not appear in a solution path q, therefore Aq might be a subset of more than one solution. In which case, Aq ends up representing all of those solutions. A BDD b represents a Boolean function f iff for any solution S to f , there exists a solution path p in b, such that Ap ⊆ S. We may denote the Boolean function represented by a BDD b by b itself. If S is a solution of f , we may specify S ∈ f . The set of solutions Sp corresponding to a solution path p is Sp = {S | Ap ⊆ S, S ∈ b}. For an assignment of a value a to a Boolean variable yi , (yi , a), we denote (yi , a) ∈ p to specify that there exists a S ∈ Sp such that (yi , a) ∈ S. Similarly, for an assignment A to some of the Boolean variables, we denote A ∈ p if there exists a S ∈ Sp such that A ⊆ S. Note, (yi , a) ∈ p mentions that either there occurs an edge (ni , ni+1 ) in p whose corresponding assignment is (yi , a), or there is no node ni in the path p such that var(ni ) = yi . We denote (yi , a) ∈ / p, if (yi , a) ∈ p is false. Although the size of a BDD representing a function in the worst case can be exponential in the number of variables in the function, reduction property makes the BDDs typically small for many practical functions. Due to this BDDs have been successfully used for representing solutions sets in several research areas, including: hardware verification [13, 75], constraint satisfaction [10, 57], planning [51], and configuration [42, 70]. The size of the BDDs are very sensitive to the used variable order. Finding the best variable order is itself a difficult problem. A good rule of thumb is to pick a variable order in which highly related variables are close in the order. Further details on BDDs can be obtained from [12, 61, 73]. When the solution space of a non-Boolean function needs to be represented by a BDD, each non-Boolean variable xi with finite domain Di will be represented by li Boolean variables, where li = dlg |Di |e. Each value of xi will be represented by an unique combination of Boolean values for the corresponding Boolean variables. A BDD corresponding to any symbolic rule (function) can be obtained by the composition function on BDDs representing the atomic elements of the rule. In case of a CSP, the conjunction of the rules (constraints) represent the solution space, and hence the conjunction function when applied to the BDDs obtained for all the rules in the CSP will give a single/monolithic BDD, which will represent the solution space of the CSP. As li Boolean variables could represent 2li values, in cases where |Di | < 2li , additional simple rules need to be added to maintain domain integrity. Let bvars(xj ) denote the set of Boolean variables used to encode the finite domain variable xj . Given a set of finite domain variables K, let bvars(K) = S bvars(k). That is, bvars(K) is the union of the Boolean variables k∈K representing the finite domain variables in K. For a Boolean variable yi ,
20
CHAPTER 2. TREE-OF-BDDS FOR CSP COMPILATION
if yi ∈ bvars(xj ), let ovar(yi ) denote xj the corresponding original finite domain variable. Let for a given CSP instance (X, D, C), Y be the set of Boolean variables used to represent the finite domain variables in X. That is, Y = S x∈X bvars(x). Hereafter, the terms like solution or partial assignment might be used to denote either those over the original CSP variables in X or those over the encoding Boolean variables in Y , which will be clear from the context. For example, for a solution path p in a BDD representing (X, D, C), the corresponding variable assignment Ap might denote the assignment of values to some of the variables in Y as we have defined or depending upon the context might denote the matching assignment for some of the finite domain variables in X. The following example shows how the solution space for the T-shirt example can be represented by using a BDD. Example 4 The BDD representing the solution space of the T-shirt example is shown in Fig. 2.7. In the figure, the non-terminal nodes corresponding to a Boolean variable yj are just labeled with j. In the T-shirt example there are three variables: x1 (color) , x2 (size) and x3 (print), whose domain sizes are four, three and two, respectively. As explained, each variable is represented by a set of Boolean variables. For the three variables, the Boolean variables encoding them are: bvars(x1 ) = {y0 , y1 }, bvars(x2 ) = {y2 , y3 } and bvars(x3 ) = {y4 }. The Figure 2.8 shows the mapping between the values of the finite-domain variables and the values for the encoding Boolean variables. For example, the variable x2 which corresponds to the size of the T-shirt is represented by the Boolean variables {y2 , y3 }. The three values small, medium, and large for the variable x2 are represented by the value combinations (false,false), (false,true) and (true,false), respectively, for the Boolean variables y2 and y3 . In the BDD, any path from the root node to the terminal node 1, corresponds to one or more valid configurations. For example, consider the solution path p =< b, n1 , n2 , n3 , 1 >, from the root node b to the 1-terminal node, such that the assignment corresponding to the path Ap = {(y0 , f alse), (y1 , f alse), (y2 , f alse), (y3 , f alse), (y4 , f alse)}. There is only one solution in the solutions corresponding to the path, Sp = {(black , small , MIB )}. Consider another solution path q =< b, n01 , n02 , 1 >, with the assignment Aq = {(y0 , f alse), (y1 , f alse), (y2 , true), (y3 , f alse)}. There are two corresponding solutions, Sq = {(black , large, MIB ), (black , large, STW )}. In the path q, the variable y4 is a don’t care variable and hence can take both true and false values, which leads to two valid configurations. ♦ Example 5 The Figure 2.9 shows a BDD representing the solution space of the PC example (introduced earlier in the Figure 2.4). The Figure 2.10 shows the mapping between the values of the finite-domain variables and the values for the encoding Boolean variables. ♦
2.4. REPRESENTING SOLUTION SPACE USING BDDS
21
0
1
2
2
3
3
4
3
3
1
4
0
Figure 2.7: A BDD representing the solution space of the T-shirt example. The non-terminal nodes corresponding to a Boolean variable yj are just labeled with j. x1 (color) black white red blue
y0 false false true true
y1 false true false true
x2 (size) small medium large
y2
y3
false false true
false true false
x3 (print) MIB STW
y4 false true
Figure 2.8: The Boolean encoding of the variables in the Shirt example.
22
CHAPTER 2. TREE-OF-BDDS FOR CSP COMPILATION 0
2
1
1
2
2
3
4
2
3
3
4
4
5
3
4
5
4
4
5
6
6
5
6
7
6
7
7
8
0
8
1
Figure 2.9: A BDD representing the solution space of the PC example. x1 (cabinet) C1 C2 C3 C4
y0 false false true true
y1 false true false true
x4 (motherboard) MB1 MB2 MB3 MB4 MB5
x2 (power) 110V 220V
y2 false true
y5
y6
y7
false false false false true
false false true true false
false true false true false
x3 (monitor) M1 M2 M3
x5 (ramtype) DDR SDRAM
y3
y4
false false true
false true false
y8 false true
Figure 2.10: The Boolean encoding of the variables in the PC example.
2.4. REPRESENTING SOLUTION SPACE USING BDDS
23
The BDD Operations Let b be a BDD. Let vars(b) denote the set of variables occurring in b. The following standard BDD operations could be used to implement a BDDbased configurator. 1. Restrict(b, (yi , a)): Given a BDD b and an assignment (yi , a) where yi is a Boolean variable and a is a Boolean value, the restrict operation will return a BDD b0 , which will represent a function obtained by substituting each occurrence of yi in b by a. The complexity of restrict is linear in the size of the given BDD. In our case, when we restrict a BDD by a non-Boolean variable assignment (x, a0 ), the necessary effect will be achieved by a sequence of corresponding restrict operations on the Boolean variables that encode the non-Boolean variable x. 2. Exist(b, yi ): The exist function will existentially quantify the Boolean variable yi from the BDD b. The output of Exist(b, yi ) is a BDD b0 such that b0 = Restrict(b, (yi , true)) ∨ Restrict(b, (yi , false)). As the restrict operation is linear and the OR-operation(∨) is quadratic, the complexity of exist is quadratic. Usually existential quantification of a variable will result in a smaller BDD. When a non-Boolean variable or a set of non-Boolean variables is given as second argument, all the corresponding Boolean variables will be existentially quantified out. 3. Conjoin(b1 , b2 ): The conjoin operation will give the result of ANDoperation between the two BDDs b1 and b2 . This also has quadratic complexity. 4. Proj(b1 , b2 ): The Proj(b1 , b2 ) operation projects the solution space of the BDD b2 over the solution space of the BDD b1 . This results in making the solution space of b1 consistent with that of b2 , meaning for any solution of b1 , there exists a solution of b2 , such that, the two solutions have the same values for their common variables vars(b1 ) ∩ vars(b2 ). Hence, Proj(b1 , b2 ) ≡ (b1 := Exist(Conjoin(b1 , b2 ), vars(b2 )\vars(b1 ))). The complexity of this projection operation depends upon the number of variables existentially quantified. 5. (b1 =b2 ): Due to the canonicity property of BDDs, equality testing of the functions represented by any two BDDs b1 and b2 could be done in constant time. Given a BDD representing the solution space of a configuration problem, using the above BDD-operations, the three functions required for interactive configuration – Display, Propagate, and Explain – can be implemented. The Display function can be implemented by an algorithm that traverses the paths from the root node to the 1-terminal node. Such an algorithm with
24
CHAPTER 2. TREE-OF-BDDS FOR CSP COMPILATION
polynomial complexity is explained in [49, 41]. The Propagate function can be implemented by a sequence of calls to the restrict function. In the Section 2.6, an algorithm for Explain function to generate minimum cost explanations is presented.
2.5
The Tree-of-BDDs for Configuration
Tree Decomposition for CSP Compilation Tree decomposition techniques [66, 25, 40, 38] for CSPs can be used to obtain a compilation scheme with lesser storage requirement than the compilation schemes without decompositions. The following definitions mostly based on [24] will be useful in discussing tree decomposition of CSPs. Definition 13 The dual-constraint graph (N ,E) of a CSP instance (X,D,C) will contain a node for each constraint in C and an edge between two nodes if their corresponding constraints share at least one variable in their scopes. Each edge will be labeled by the variables that are shared by the scope of the corresponding constraints. By definition, each node in N is associated with a constraint c ∈ C. Let the node in N associated with the constraint c be denoted nc . Also, there will be an edge (nci , ncj ) in E if vars(ci ) ∩ vars(cj ) 6= ∅, and the label of the edge (nci , ncj ) will be vars(ci ) ∩ vars(cj ). To simplify the presentation, we assume that the dual-constraint graph of a CSP we consider is connected. In case the dual-constraint graph of a CSP is not connected, then each connected component is an independent subproblem and could be dealt with separately. Lets consider the shirt example. Let the two constraints in the shirt example be C = {c1 , c2 }, with vars(c1 ) = {x1 , x3 } and vars(c2 ) = {x2 , x3 }. The Figure 2.11 shows the dual-constraint graph of the shirt example. There are two nodes in the graph, one for each constraint. The edge between the nodes is labeled with the corresponding constraints’ common variable x3 . Lets consider our PC example. Let the five constraints in the PC example be C = {c1 , c2 , c3 , c4 , c5 }, with vars(c1 ) = {x1 , x2 }, vars(c2 ) = {x2 , x3 }, vars(c3 ) = {x4 , x5 }, vars(c4 ) = {x1 , x4 } and vars(c5 ) = {x1 , x3 }. The Figure 2.12 shows the dual-constraint graph of the PC example. There are five nodes in the graph, one for each constraint. There is an edge between two nodes, if their corresponding constraints have a common variable. The edge between the nodes is labeled with the corresponding constraints’ common variables.
2.5. THE TREE-OF-BDDS FOR CONFIGURATION
c1 {x3 } c2
Figure 2.11: The dual-constraint graph for the shirt example.
c3
c1 {x2 } {x1 }
{x1 } c2 {x3 }
{x4 }
c4 {x1 }
c5
Figure 2.12: The dual-constraint graph for the PC example.
25
26
CHAPTER 2. TREE-OF-BDDS FOR CSP COMPILATION
c3
c1 {x2 }
{x1 } c2 {x3 }
{x4 }
c4 {x1 }
c5
Figure 2.13: A join graph for the PC example. Definition 14 A subset of the edges, (E 0 ⊆ E), in a dual-constraint graph (N ,E) satisfies the connectedness condition, if for any variable x shared by any two constraints, there exists a path between the corresponding nodes in the dual-constraint graph, using only the edges in E 0 with x in their labels. Definition 15 A join graph (V ,E 00 ) of a dual-constraint graph (N ,E) is such that E 00 ⊆ E and E 00 satisfies the connectedness property. If the join graph does not have any cycles, then it is called a join-tree. Let consider the dual-constraint graph of the shirt example in the Figure 2.11. The graph is already a tree, hence the graph is also a join-tree. Let consider the dual-constraint graph of the PC example in the Figure 2.12. A join-graph of the PC example is presented in the Figure 2.13. The PC example does not have a join-tree. Several tree decomposition techniques [25, 40, 38] have been proposed to convert a CSP instance (X,D,C) into an another one (X,D,C 0 ), such that: (X,D,C) and (X,D,C 0 ) have equivalent solutions, and (X,D,C 0 ) has a join-tree. A CSP with a join-tree is called acyclic CSP. Acyclic CSPs can be efficiently solved. A dual-constraint graph has a join-tree only if its maximum spanning tree, when the edges are weighted by the number of shared variables, is a join-tree [24]. So, the acyclicity of a CSP can be determined by just checking whether the corresponding maximum spanning tree is a join-tree.
2.5. THE TREE-OF-BDDS FOR CONFIGURATION
27
X = {x1 , x2 , x3 , x4 , x5 } D = {{C1 , C2 , C3 , C4 }, {110V , 220V }, {M1 , M2 , M3 }, {MB1 , MB2 , MB3 , MB4 , MB5 }, {DDR, SDRAM }} C 0 = {({x1 , x2 , x3 }, {(C1 , 110V , M1 ), (C2 , 110V , M1 ), (C3 , 220V , M2 ), (C3 , 220V , M3 ), (C4 , 220V , M2 ), (C4 , 220V , M3 )}) ({x4 , x5 }, {(MB1 , DDR), (MB2 , SDRAM ), (MB3 , DDR), (MB4 , SDRAM ), (MB5 , SDRAM )}) ({x1 , x4 }, {(C1 , MB1 ), (C1 , MB2 ), (C2 , MB1 ), (C3 , MB3 ), (C3 , MB4 ), (C4 , MB5 )})
Figure 2.14: An acyclic CSP instance (X, D, C 0 ) representing the PC configuration problem .
c01
c02 {x1 }
{x4 } c03
Figure 2.15: The dual-constraint graph for acyclic CSP instance (X, D, C 0 ) representing the PC example. The graph is also a join-tree. Lets consider the shirt example. The dual-constraint graph of the shirt example is also a join-tree. Since, there exists a join-tree, the shirt example is an acyclic CSP instance. Lets consider CSP (X, D, C) representing the PC example presented in the Figure 2.4. Since, the PC example does not have a join-tree, the instance (X, D, C) is not acyclic CSP instance. We present a new CSP instance (X, D, C 0 ) in the Figure 2.14, such that (X, D, C 0 ) and (X, D, C) have equivalent solutions. Let the three constraints in the new instance (X, D, C 0 ) be C 0 = {c01 , c02 , c03 }, with vars(c01 ) = {x1 , x2 , x3 }, vars(c02 ) = {x4 , x5 } and vars(c03 ) = {x1 , x4 }. The Figure 2.15 presents the dual-constraint graph for the (X, D, C 0 ) instance. The graph is also a join-tree, hence the instance (X, D, C 0 ) is acyclic. Definition 16 A constraint of a CSP is minimal when all the solutions of the constraint can be extended to a solution for the CSP. Definition 17 A pair of constraints ci and cj are consistent if any partial assignment satisfying ci can be extended to satisfy cj as well and vice versa.
28
CHAPTER 2. TREE-OF-BDDS FOR CSP COMPILATION
An acyclic CSP is join-tree consistent if any pair of constraints adjacent in a join-tree are consistent. If the pair of constraints ci and cj are consistent, then any assignment to vars(ci ) (resp. vars(cj )) satisfying ci (resp. cj ) can be extended to an assignment for vars(ci ) ∪ vars(cj ) satisfying both ci and cj . A given pair of constraints ci and cj can be made consistent by removing every tuple t from any of their relations Ri or Rj , if the tuple t’s corresponding assignment cannot be extended to a solution for both the constraints ci and cj . Given an acyclic CSP with its join-tree (N, E), the CSP can be made join-tree consistent, if for any edge (nci , ncj ) ∈ E, the constraints ci and cj are made consistent. By exploiting properties of acyclic CSPs, enforcing join-tree consistency could be done efficiently [24]. The nice property of an acyclic CSP is that, enforcing join-tree consistency makes all the constraints minimal. Minimality of constraints is enough to obtain the efficient functions required for interactive configuration. If each constraint is minimal, a valid choice for a variable in a constraint will also be a valid choice for all the variables in the CSP, and the display function could use this to efficiently display valid choices. Given an assignment, the propagate function just needs to reduce all the constraints in which the variable is present, and propagate the effect to other constraints by enforcing join-tree consistency. Hence, if we have the join-tree of a CSP, we don’t have to compile the solutions of the CSP into a single data-structure like a BDD. We can achieve the main configuration functionalities by just manipulating the solutions local to each pair of constraints adjacent in the join-tree, without building a single/monolithic BDD.
The Tree-of-BDDs Since the product configuration specifications have a hierarchical description, often with tree-like relationships, the tree decomposition methods might be able to convert an input instance (X,D,C) to an acyclic (X,D,C 0 ), such that (X,D,C 0 ) is of reasonable size, while still guaranteeing tractability. Lets assume that the input CSP instance (X, D, C) is acyclic. If the input CSP instance is not acyclic we can obtain an equivalent acyclic one by using the tree decomposition techniques. Definition 18 The tree-of-BDDs of an acyclic CSP (X, D, C) is a triple (N, A, B), where (N, A) is a join tree of (X, D, C) and B is a mapping such that for each nc ∈ N : B(nc ) is a BDD representing the solutions of the constraint c ∈ C. A solution to a tree-of-BDDs (N, A, B) is required to be a solution of B(n), for each n ∈ N . Note, since tree-of-BDDs just represents each constraint in the acyclic CSP instance (X, D, C) by using a BDD, we don’t lose
2.5. THE TREE-OF-BDDS FOR CONFIGURATION 0
29
2
1
3
4
1
0
B(nc1 )
3
4
0
1
B(nc2 )
Figure 2.16: The B(nc1 ) and B(nc2 ) BDDs of the Tree-of-BDDs (N, A, B) representing the T-shirt example.
(or add) any solutions. Since a BDD could be exponentially smaller than an explicit representation of a constraint using relations, a tree-of-BDDs could be exponentially smaller than its equivalent explicit acyclic CSP representation. Instead of compiling the conjunction of all the constraints in a CSP into a single/monolithic BDD, the tree decomposition based compilation scheme just requires a BDD for each constraint in the corresponding acyclic instance. Since the sum of sizes of the BDDs in a tree-of-BDDs is potentially smaller than the size of the corresponding monolithic BDD, decomposition schemes might lead to significant space savings in CSP compilations. Lets consider the shirt example’s CSP instance (X, D, C) introduced in the Figure 2.2. The instance (X, D, C) is acyclic with two constraints c1 and c2 . Let the tree-of-BDDs (N, A, B) represent the solutions of the shirt example. The Figure 2.11 shows the dual-constraint graph of the instance which is also its join-tree (N, A). The Figure 2.16 presents the two BDDs B(nc1 ) and B(nc2 ) of (N, A, B). The number of non-terminal nodes in the BDD representing the shirt example in the Figure 2.7 is 10, while the total number of non-terminal nodes in the two BDDs of the tree-of-BDDs is just 7. Lets consider the PC example’s acyclic CSP (X, D, C 0 ) introduced in the Figure 2.14. The (X, D, C 0 ) has three constraints c01 , c02 and c03 . Let the tree-of-BDDs (N, A, B) represent the solutions of the PC example. The Figure 2.15 shows the dual-constraint graph of the acyclic PC instance which is also its join-tree (N, A). The Figure 2.17 presents the three BDDs B(nc01 ), B(nc02 ) and B(nc03 ) of (N, A, B). The number of non-terminal nodes in the BDD representing the PC example in the Figure 2.9 is 30, while the total number of non-terminal nodes in the three BDDs of the tree-of-BDDs is
30
CHAPTER 2. TREE-OF-BDDS FOR CSP COMPILATION
0
5
2
2
3
6
3
7
4
7
4
0
8
1
0
B(nc01 )
8
1
B(nc02 )
0
1
5
1
5
6
5
7
5
6
0
6
1
B(nc03 )
Figure 2.17: The B(nc01 ), B(nc02 ) and B(nc03 ) BDDs of the Tree-of-BDDs (N, A, B) representing the PC example.
2.5. THE TREE-OF-BDDS FOR CONFIGURATION
31
just 24.
Configuration Functions on Tree-of-BDDs Let the solution space SOL of the input CSP (X, D, C) is represented by the tree-of-BDDs (N, A, B). We use the notation (N, A, B 0 ) to denote the representation of SOL0 by using the tree-of-BDDs structure, where SOL0 ⊆ SOL. In the InteractiveConfigurator algorithm presented in the Figure 2.6, we can substitute every occurrence of SOL (SOL0 ) with (N, A, B) ((N, A, B 0 )) to obtain a new algorithm using the tree-of-BDDs to store solution spaces. We now present the algorithms for Display, Propagate and Explain functions in the version of InteractiveConfigurator using the tree-of-BDDs. We first extend the notion of join-tree consistency to tree-of-BDDs. We then present a method for enforcing join-tree consistency in a tree-of-BDDs. Subsequently, methods for the display and propagate functions on tree-ofBDDs are presented. The next section presents a method for the explain function. Definition 19 A tree-of-BDDs is join-tree consistent if the set of solutions represented by each BDD in the tree-of-BDDs is minimal. For each node nc ∈ N , B(nc ) represents the solutions of the constraint c ∈ C. Hence, by the above definition, the tree-of-BDDs is minimal if the equivalent CSP (X, D, C) is minimal. Let BFOrder for the join tree (N, A) be the order in which the nodes in N are visited by a breadth-first traversal of the join tree (N, A), starting at an arbitrary node r ∈ N as the root node. Let BFOrder(i) denote the ith node in the order. Let for a non-root node n ∈ N , parent(n) denote the unique neighbor of n which occurs before n in the BFOrder. Let children(n) denote the neighbors of n which occur after n in the BFOrder. MakeJoinConsistent ((N ,A,B 0 )) 1 : for i := |N | to 2 // except the root tree-node r 2: n := BFOrder(i) 3: p := parent(n) 4: Proj(B 0 (p), B 0 (n)) 5 : for i := 1 to |N | 6: n := BFOrder(i) 7: H := children(n) 8: ∀h ∈ H. Proj(B 0 (h), B 0 (n)) Figure 2.18: The MakeJoinConsistent procedure to enforce minimality of each BDD in a tree-of-BDDs (N ,A,B 0 ).
32
CHAPTER 2. TREE-OF-BDDS FOR CSP COMPILATION
The Figure 2.18 presents the MakeJoinConsistent procedure. The procedure takes a tree-of-BDDs (N, A, B 0 ) as input and makes it join-tree consistent. The procedure has two phases. In the first phase between the lines 1-4, the procedure makes the solutions of the BDD of each node consistent with it parent node. In the second phase between the lines 5-8, the procedure makes the solutions of the BDD of each node consistent with its children, resulting in enforcing join-tree consistency. The correctness of the procedure follows from the established properties of CSP tree decomposition [24]. Propagate ((X, D, C), (N, A, B 0 ), (xi ,a) ) 1 : ∀c ∈ C such that xi ∈ vars(c) 2: B 0 (nc ) := Restrict(B 0 (nc ), (xi , a)) 3 : MakeJoinConsistent((N, A, B 0 )) Figure 2.19: The Propagate procedure for assignment propagation in the tree-of-BDDs scheme. The Figure 2.19 presents the procedure for implementing the Propagate functionality in the tree-of-BDDs scheme. Lets recall that, the Propagate functionality takes a solution space along with a variable assignment (xi , a) as input and restricts the solution space to the solutions with the assignment (xi , a). In our case, the solution space is represented by a tree-of-BDDs (N, A, B 0 ). The presented Propagate procedure achieves the functionality by restricting the solutions of constraints with the variable xi by the assignment (xi , a) and then propagating the effect to the rest of the constraints by a call to the MakeJoinConsistent procedure. Display ((X, D, C), (N, A, B 0 )) 1 : D0 := ∅ 2 : ∀c ∈ C 3: D0 := D0 ∪ (Display((X, D, C), B 0 (nc ))|vars(c) ) 4 : Print D0 Figure 2.20: The Display for printing valid choices in the tree-of-BDDs scheme. The Figure 2.20 presents the procedure for the Display functionality in the tree-of-BDDs scheme. Recall that the task of the Display procedure is to take a solution space as input and present the domain of the variables D0 occurring in the solutions of the input solution space. The D0 is such that the assignment of any variable with a value from its domain in D0 will lead to at least one valid solution in the current solution space. In our case, the solution space is represented by a tree-of-BDDs. The presented procedure in Figure 2.20 uses the Display((X, D, C), b) function, where b is a BDD.
2.6. ALGORITHMS FOR MINIMUM EXPLANATIONS
33
The Display((X, D, C), b) function is an implementation of the Display functionality in the previous single BDD scheme, which returns the valid domain w.r.t. a BDD b. A polynomial time procedure for Display((X, D, C), b) has been presented in [50, 41], where the procedure was called valid-domain function. Since for a constraint c, vars(c) may not contain all the variables in X, the Display((X, D, C), B 0 (nc )) will return the current valid domains for the variables in vars(c) as implied by B 0 (nc ), and the initial domains for the other variables in X\vars(c). Hence, we restrict the output of Display(B 0 (nc )) to the vars(c) at the line-3 of the procedure. Note, for two constraints ci and cj , if a variable v occurs in both vars(ci ) and vars(cj ), then due to the properties of tree decomposition, the domains for the variable v returned by the two calls Display((X, D, C), B 0 (nci )) and Display((X, D, C), B 0 (ncj )) will be the same. The union of the domains returned by each call to Display((X, D, C), B 0 (nc )) restricted to vars(c) at the line-3, results in the valid domain of interest D0 , which is printed to the user at the line-4. Since, the Display((X, D, C), (N, A, B 0 )) makes at most |N | calls to Display((X, D, C), B 0 (nc )), it runs in polytime.
2.6
Algorithms for Minimum Explanations
Efficient explanations have been an interesting topic of research in both AI and CP fields [52, 53, 32, 6]. In this section we present two algorithms for generating explanations for BDD-based interactive configurators. The first algorithm is for the monolithic-BDD based scheme and the second one for the tree-of-BDDs scheme. Both the algorithms generate minimum explanations with respect to a linear cost function.
Minimum Explanations in the Monolithic-BDD Scheme As we have explained earlier, the Explain functionality takes a variable assignment (xi , a) as an input, where (xi , a) is an invalid choice as per the current partial assignment P A. The task of the Explain function is to specify an explanation E, a subset of the partial assignment, E ⊆ P A, such that retracting the assignments in E will make the choice (xi , a) available again for selection. Throughout this subsection, we assume (xi , a) is the invalid choice for which we seek an explanation. We specify xj for j 6= i to denote another variable in X. Our algorithm for the Explain functionality assumes that for any variable x ∈ X, the encoding Boolean variables in bvars(x) occur consecutively in the BDD variable order. This assumption is necessary to follow our method for explanations.
34
CHAPTER 2. TREE-OF-BDDS FOR CSP COMPILATION
Since (xi , a) is an invalid choice under current P A, there does not exist a solution S ∈ b, such that P A ⊆ S and (xi , a) ∈ S. Assuming that (xi , a) is not an invalid choice in the beginning when P A was empty, there should exist a solution S 0 ∈ b, such that (xi , a) ∈ S 0 . Also, there should exist a solution path p in the BDD b, such that S 0 ∈ Sp , where, as we have defined earlier, Sp is the set of solutions represented by the path. Considering Ap the assignment corresponding to the path, we can define E = {(xj , aj ) | xj ∈ vars(Ap ) ∧ xj ∈ vars(P A) ∧ (xj , aj ) ∈ / Ap ∧ (xj , aj ) ∈ P A}. For each assignment (xj , aj ) in P A, if (xj , aj ) conflicts the possible choices for xj allowed by Ap , then (xj , aj ) belongs to the set E. Since (P A\E) will not contain any assignment that conflicts with Ap , removing the assignments in E from the partial assignment P A, will lead to (xi , a) choice being available to the user again for selection. Hence, the E so obtained would be an explanation for (xi , a) under P A. We say the E so obtained as the explanation corresponding to the solution path p. We can extend our definition for cost of an explanation to the cost of a path p, such that if E is an explanation corresponding to the path p, then Cost(p) = Cost(E). Now, the problem of finding a minimum cost explanation for (xi , a) can be reduced to the problem of finding a solution path p such that (xi , a) ∈ p and the Cost(p) is minimum. We modify the popular single source shortest path algorithm for directed acyclic graphs (DAG) to find a minimum cost solution path in the BDD, and then extract the explanation corresponding to the path. We assume that the reader is familiar with the shortest path algorithm [17]. Briefly, the algorithm first obtains a topological sort of the nodes in the input DAG with edge weights (costs). Then, in the sorted order, each node n is processed (relaxed) one by one. When a node n is selected for processing, the shortest path from the source (root node) to n would already have been found. During the processing of the node n, for each outgoing edge of n, like (n, n0 ), it will be checked whether reaching n0 through n is shorter (cheaper) than any existing path to n0 . If it is shorter to reach n0 through n, then the node n will be added as the predecessor (parent) node of n0 in the shortest path to n0 . During the course of the algorithm, if n is the predecessor of n0 , then the extension of the shortest path of n with (n, n0 ) is a shortest known way to reach n0 , not necessary the shortest. At the end of the algorithm, if n is the predecessor of n0 , then the extension of the shortest path of n with (n, n0 ) is a shortest path to reach n0 . When all the nodes are processed, the algorithm would have found a shortest path from the source node to every other node. The adopted version of the shortest path algorithm runs on the underlying DAG of the BDD representation, with appropriately defined edge weights (costs). To use the shortest path algorithm for DAGs, we first need to define how the cost of any path (of any length) originating at the source
2.6. ALGORITHMS FOR MINIMUM EXPLANATIONS
35
(the root node) is calculated. Let yz ∈ bvars(xj ). We denote (yz , az ) ∈ (xj , aj ) if the Boolean assignment (yz , az ) is implied by the assignment (xj , aj ). Otherwise, we denote (yz , az ) ∈ / (xj , aj ). An edge (n1 , n2 ) violates an assignment (xj , aj ) if var(n1 ) ∈ bvars(xj ) and the assignment corresponding to the edge (var(n1 ), a) ∈ / (xj , aj ). If the edge (n1 , n2 ) violates the assignment (xj , aj ), then in any solution path p, if the edge (n1 , n2 ) occurs in p, then for any solution S ∈ Sp , (xj , aj ) ∈ / S. When an edge (n1 , n2 ) violates an assignment (xj , aj ) ∈ P A, we may also say that the edge violates xj . We define a cost associated with each edge in any path from the root as follows: 1. First we handle the case of the edges associated with the variable xi . Since we are only interested in solution paths with (xi , a), we can ignore any path p with (xi , a) ∈ / p. If (xi , a) ∈ / p then there should be an edge (n1 , n2 ) in p such that var(n1 ) ∈ bvars(xi ) and the Boolean assignment (var(n1 ), a0 ) corresponding to (n1 , n2 ) does not occur in (xi , a), i.e., (var(n1 ), a0 ) ∈ / (xi , a). That is, the edge (n1 , n2 ) violates (xi , a). For all such edges (n1 , n2 ) with var(n1 ) ∈ bvars(xi ) and (var(n1 ), a0 ) ∈ / (xi , a), the Cost((n1 , n2 )) = ∞. For all other edges (n1 , n2 ) with var(n1 ) ∈ bvars(xi ) and (var(n1 ), a0 ) ∈ (xi , a), Cost((n1 , n2 )) = 0. 2. Now, we handle the case of the edges associated with the variables in (X\(vars(P A) ∪ {xi })), the variables not assigned a value in PA and also not xi . For any edge (n1 , n2 ) such that the corresponding original variable xj = ovar(var(n1 )), xj 6= xi and xj ∈ / vars(P A), Cost(n1 , n2 ) = 0. This is because there is no impact on the cost of an explanation by any variable not in the PA. 3. Now, we handle the case of the edges associated with a variable in vars(P A). For any edge (n1 , n2 ) such that xj = ovar(var(n1 )) and (xj , aj ) ∈ P A, the Cost(n1 , n2 ) is dynamically assigned a value from {0, P (xj , aj )} based on the solution path under consideration. Let (var(n1 ), a1 ) be the assignment corresponding to (n1 , n2 ). There are two subcases: Case 1: (var(n1 ), a1 ) ∈ P A. In this case, the edge (n1 , n2 ) does not violate P A and hence Cost(n1 , n2 ) = 0. Case 2: (var(n1 ), a1 ) ∈ / P A. In this case, the edge (n1 , n2 ) violates the P A. Now, the cost of the edge (n1 , n2 ) depends upon whether the edge is the first violating edge of (xj , aj ) in a specific path. If in an arbitrary path p starting from the root node, there occurs an edge (n01 , n02 ) before the occurrence of the (n1 , n2 ), such that xj = ovar(var(n01 )) and the edge’s corresponding assignment (var(n01 ), a0 ) ∈ /
36
CHAPTER 2. TREE-OF-BDDS FOR CSP COMPILATION P A, then Cost(n1 , n2 ) = 0. Otherwise, i.e., if there is no such (n01 , n02 ) before (n1 , n2 ) then the Cost(n1 , n2 ) = P (xj , aj ). Hence, in a path p, if for any (xj , aj ) ∈ P A there exists one or more edges in p each violating (xj , aj ), we include the cost P (xj , aj ) just for the first one of those edges, the rest of those edges have zero cost. This is to ensure that, when more than one edge in a path violate the same assignment (xj , aj ) ∈ P A, we don’t count the cost more than once.
Given a path starting at the root and ending at any node, the summation of the cost associated with the edges in the path will be the Cost of the path. While adopting the shortest path algorithm for our purpose on the DAG of a BDD, there are two major problems: 1. A variable x ∈ X could be encoded by more than one Boolean variable in the BDD. Hence, as discussed in the last case of the cost definition for edges, in a solution path p, more than one edge corresponding to x may violate the P A. In which case, we have to adopt the shortest path algorithm to handle properly, by incurring cost for just the first violation of x in p. 2. Consider the two solution paths in the BDD p1 =< b, nt1 , nt2 , . . . , ntα , nu1 , nu2 , . . . , nuβ , 1 > and p2 =< b, nv1 , nv2 , . . . , nvγ , nu1 , nu2 , . . . , nuβ , 1 >, where b is the root node representing the BDD. Let {var(ntα ), var(nu1 ), var(nu2 ), var(nvγ )} ⊆ bvars(xj ). Let (xj , aj ) ∈ P A. Let in both the paths there is no violation of (xj , aj ) from the root node b up to ntα and nvγ , respectively. Let the edge (ntα , nu1 ) violates the assignment (xj , aj ) and the edge (nvγ , nu1 ) does not violate (xj , aj ). Lets consider two subpaths: p01 =< b, nt1 , nt2 , . . . , ntα > and p02 =< b, nv1 , nv2 , . . . , nvγ >. Let the cumulative cost for violations of P A in the subpaths p01 and p02 be J and K, respectively. Let J < K and J + P (xj , aj ) > K. Now, at the node nu1 there are at least two incoming paths. One through ntα and the other through nuγ , which are extensions of the subpaths p01 and p02 , respectively. Let the algorithm has to decide on the shortest (least cost) way to reach nu1 , which could be either through ntα or through nvγ or through some other nodes in the BDD. Without loss of generality (wlog), we can assume that extending p02 with (nvγ , nu1 ) is one among the shortest ways to reach nu1 without violating (xj , aj ). Also, wlog, we can assume that extending p01 with (ntα , nu1 ) is one among the shortest ways to reach nu1 with a violation of (xj , aj ). The decision whether reaching nu1 through ntα will result in shorter final solution path than through nvγ cannot be made at the node nu1 . To be more precise, lets consider two paths, p001 =< b, nt1 , nt2 , . . . , ntα , nu1 > and
2.6. ALGORITHMS FOR MINIMUM EXPLANATIONS
37
p002 =< b, nv1 , nv2 , . . . , nvγ , nu1 >. Then, Cost(p001 ) = J + P (xj , aj ) and Cost(p002 ) = K. As K < J +P (xj , aj ), it might seem to be shorter to use p002 than p001 , but, the cost P (xj , aj ) has never been incurred in p002 and hence, the future extension of p002 might incur cost of P (xj , aj ). But, any extension of p001 won’t incur P (xj , aj ) as p001 has already incurred P (xj , aj ) due to the edge (ntα , nu1 ). Let the paths p000 1 =< b, nt1 , nt2 , . . . , ntα , nu1 , nu2 > and 000 p2 =< b, nv1 , nv2 , . . . , nvγ , nu1 , nu2 >. Let the edge (nu1 , nu2 ) violates 000 (xj , aj ). Then, the Cost(p000 1 ) = J + P (xj , aj ) and Cost(p2 ) = K + P (xj , aj ). Now, it is shorter to reach nu2 through an extension of p001 than an extension of p002 , although Cost(p002 ) < Cost(p001 ). Hence, the decision whether to choose one among p01 and p02 cannot be made at the node nu1 and needs to be deferred until there is no node associated with the variables in bvars(xj ), further down the paths. We now define two types of paths, which we use to solve the above specified problems. During the execution of our algorithm, two paths are associated with each node n: 1. the path pvn called the violated path, such that: pvn starts from the root and ends at n, and pvn violates the corresponding original finitedomain variable ovar(var(n)) before reaching n. If any candidate path for pvn exists, our algorithm during its execution will find the shortest among those candidate paths. 2. the path pcn called the clear path, such that: pcn starts from the root and ends at n, and pcn does not violate ovar(var(n)) before reaching n. If any candidate path for pcn exists, our algorithm during its execution will find the shortest among those candidate paths. Note, the clear path pcn is guaranteed to have no violation of ovar(var(n)), but may have violated another variable x ∈ X that occurs before ovar(var(n)) in the variable order. Due to our assumption that, initially when the partial assignment was empty the choice (xi , a) was valid, for any node n there will exists at least one among pcn and pvn . Also, due to the same assumption, a clear-path of the 1-terminal pc1−terminal will exists at the end of our algorithm. At the end, the explanation corresponding to the path pc1−terminal is a minimum cost explanation. We solve the specified two problems by: 1. During the execution of the traditional single-source shortest path algorithm, only one path will be maintained to each node. But, we maintain two paths to each node n, pvn with a violation and pcn without violation of ovar(var(n)). We can infer that the path pvn has
38
CHAPTER 2. TREE-OF-BDDS FOR CSP COMPILATION already incurred a cost for violation and pcn has not incurred any cost for violation. Hence, the first problem does not arise when we maintain both pvn and pcn . 2. We solve the second problem too by using pvn and pcn . There are two subcases: Case-1: During the processing of a node n, for an outgoing edge (n, n0 ) if ovar(var(n)) 6= ovar(var(n0 )), then it implies that there is no descendant d of node n reachable through (n, n0 ), such that ovar(var(n)) = ovar(var(d)). This is due to our assumption that for any x ∈ X, the Boolean variables in bvars(x) occur consecutively in the variable order. If there is no such descendant of n reachable through (n, n0 ), we can pick the shorter one among pcn and pvn , ignoring the other, when attempting to reach n0 through n. Case-2: In case ovar(var(n)) = ovar(var(n0 )), then there is at least a descendant d of n reachable through (n, n0 ) such that ovar(var(n)) = ovar(var(d)), for example d = n0 . Hence, the algorithm cannot ignore either one of pvn and pcn . Depending upon the cost for the edge (n, n0 ) and whether the edge (n, n0 ) violated ovar(var(n)), our algorithm will attempt to extend both pvn and pcn with (n, n0 ) and consider the resulting two paths as candidate paths for pvn0 and pcn0 . Note, if the edge (n, n0 ) violates ovar(var(n)), then the extension of the clear path pcn with (n, n0 ) could only be a candidate for the violated path pvn0 and not a candidate for the clear path pcn0 .
The presentation of our procedure for finding the minimum explanation requires the following six attributes for each node n: 1. vCostn : An integer value to denote the cost of the path pvn , i.e., vCostn = Cost(pvn ). Initially, the value for this attribute will be ∞, specifying that either there is no such path or no candidate path for pvn has been observed by the algorithm yet. 2. vParentn : The parent (predecessor) node of n in the path pvn . 3. vParentTypen : To simplify notation, let m = vParentn , the parent of n in its violated path. This variable vParentTypen takes a value from the set {vi, cl}. The value of vParentTypen is vi if the path pvn is an extension of the path pvm . That is if the violated path pvm of the parent node m is extended with the edge (m, n) to reach the node n as a violated path to n. The value of vParentTypen is cl if the path pvn is an extension of the path pcm . That is if the clear path pcm to the node m is extended with the edge (m, n) to reach the node n as a violated path to n. Note, if the clear path of the node m is extended to a violated path of n then the edge (m, n) violates the variable ovar(var(n)) and also ovar(var(n)) = ovar(var(m)).
2.6. ALGORITHMS FOR MINIMUM EXPLANATIONS
39
Explain ((X, D, C), b, PA, (xi ,a)) 1 : Q := TopologicalSort(b) //Terminal nodes are excluded 2 : Initialize(b) 3 : while (Q.NotEmpty()) 4: n := Q.PopFront() 5: Relax(n) 6 : E := ExtractExplanation (b) 7 : return E Figure 2.21: The Explain algorithm for the monolithic-BDD scheme. Initialize (b) 1 : For each node n in the BDD b including the terminal nodes: 2: cCostn := ∞ 3: vCostn := ∞ 4 : cParentb := NULL 5 : cCostb := 0 Figure 2.22: The Initialize procedure. 4. cCostn : An integer value to denote the cost of the path pcn , i.e., cCostn = Cost(pcn ). Initially, the value for this attribute will be ∞, specifying that either there is no such path or no candidate path for pcn has been observed by the algorithm yet. 5. cParentn : The parent (predecessor) node of n in the path pcn . 6. cParentTypen : To simplify notation, let m = cParentn , the parent of n in its clear path. This variable cParentTypen takes a value from the set {vi, cl}. The value of cParentTypen is vi if the path pcn is an extension of the path pvm . That is if the violated path pvm of the parent node m is extended with the edge (m, n) to reach the node n as a clear path to n. Note, if the violated path of the node m is extended to a clear path of n then ovar(var(n)) 6= ovar(var(m)). The value of cParentTypen is cl if the path pcn is an extension of the path pcm . That is if the clear path pcm to the node m is extended with the edge (m, n) to reach the node n as a clear path to n. The Figure 2.21 shows the Explain procedure. The procedure first obtains a topological sort of the internal nodes in the input BDD and stores the nodes in the sorted order in a queue Q. Then, the procedure calls the Initialize procedure. The Initialize procedure shown in the Figure 2.22 initializes the cost values at each node to ∞ and then sets the values for the root node b appropriately. At the line-3 of the Explain, the while loop iterates over
40
CHAPTER 2. TREE-OF-BDDS FOR CSP COMPILATION
each internal node in the sorted order and calls the Relax procedure. The calls to the Relax procedure appropriately sets the attributes of the nodes such that at the end of the while-loop, the shortest solution path pc1−terminal and the corresponding explanation can be extracted. At the line-6, the Explain procedure calls the ExtractExplanation procedure which retraces the shortest solution path from the 1-terminal to the root-node, keeping track of the violated edges in the path, and returns the explanation corresponding to the violated edges. The Figure 2.23 presents the Relax procedure. The precondition for invoking this procedure for a node n is that: both the shortest pcn and the shortest pvn , if any of them exist, has been found. Both the paths can be retraced by using the cParentn , vParentn , cParentTypen and vParentTypen values. At the line-1, the Relax procedure does some initialization steps. Between the lines 2-5, the procedure checks if the variable xj is assigned a value in P A. If the variable xj is assigned a value aj , then based on the value for var(n) implied by (xj , aj ), either the solid or the dashed edge violates (xj , aj ). The variables dashedCost (resp. solidCost) is set to P (xj , aj ) if the dashed (resp. solid ) edge violates (xj , aj ). The variables dashedCost and solidCost are subsequently used to denote the cost for the corresponding edges. At the line-6, the procedure initializes ns (resp. nd ) to the solid-edge (resp. dashed-edge) child of n. At the line-7 of the procedure, two variables cC and vC are initialized. The cC is initialized to the cost for reaching the node ns by following the path pcn and then the edge (n, ns ). Similarly, the variable vC is initialized to the cost for reaching the node ns through the path pvn and then the edge (n, ns ). Note, at the line-7, we ignore the cost for the solid edge while initializing the vC value, as the path pvn , if the path exists, has already incurred the cost P (xj , aj ). Hence the cost for the solid edge, if any, need not be added to the vC value. At the line-8, the procedure checks whether the finite-domain variable of node ns is the same as that of n. If so, at the line 9, the procedure checks whether reaching ns by following pcn and then the edge (n, ns ) is shorter than any existing clear path pcns to ns . If it is shorter to reach ns through pcn and (n, ns ), at the line-10, the procedure updates the attributes of ns appropriately. Similarly, the lines 11-12 check whether reaching ns through the path pvn is shorter, and if so updates the attributes of ns appropriately. Note, since between the lines 9-12, the condition (ovar(var(ns )) 6= xj ) holds, extensions of the paths pcn and pvn to reach ns could only be the candidates for pcns and not for pvns . The lines 14-21 of the procedure handle the case where both the variables ovar(var(n)) and xj are the same, and in which case both the paths pcn and pvn might have to be extended to ns . Between the lines 14-15, we extend the path pvn with (n, ns ) if that is shorter than the existing violated path pvns
2.6. ALGORITHMS FOR MINIMUM EXPLANATIONS
41
Relax (n) 1 : solidCost := 0; dashedCost := 0; xj := ovar(var(n)) 2 : if xj ∈ vars(P A) 3: There exists aj such that (xj , aj ) ∈ P A 4: if ((var(n), true) ∈ P A) dashedCost := P (xj , aj ) 5: else solidCost := P (xj , aj ) 6 : ns := solid(n); nd := dashed(n) 7 : cC := cCostn + solidCost; vC := vCostn 8 : if (ovar(var(ns )) 6= xj ) 9: if (cCostns > cC) 10: cCostns := cC; cParentns := n; cParentTypens := cl 11: if (cCostns > vC) 12: cCostns := vC; cParentns := n; cParentTypens := vi 13: else//(ovar(var(ns )) = xj ) 14: if (vCostns > vC) 15: vCostns := vC; vParentns := n; vParentTypens := vi 16: if ((var(n), true) ∈ / P A) //the edge violates PA 17: if (vCostns > cC) 18: vCostns := cC; vParentns := n; vParentTypens := cl 19: else //the edge does not violate PA 20: if (cCostns > cC) 21: cCostns := cC; cParentns := n; cParentTypens := cl 22: cC := cCostn + dashedCost 23: if (ovar(var(nd )) 6= xj ) 24: if (cCostnd > cC) 25: cCostnd := cC; cParentnd := n; cParentTypend := cl 26: if (cCostnd > vC) 27: cCostnd := vC; cParentnd := n; cParentTypend := vi 28: else//(ovar(var(nd )) = xj ) 29: if (vCostnd > vC) 30: vCostnd := vC; vParentnd := n; vParentTypend := vi 31: if ((var(n), false) ∈ / P A) //the edge violates PA 32: if (vCostnd > cC) 33: vCostnd := cC; vParentnd := n; vParentTypend := cl 34: else //the edge does not violate PA 35: if (cCostnd > cC) 36: cCostnd := cC; cParentnd := n; cParentTypend := cl Figure 2.23: The Relax procedure used by the Explain algorithm. to ns . Note, we set vParentTypens to vi to denote that we are extending the path pvn , at the line-15. Between the lines 16-21, we handle the case of extending the path pcn
42
CHAPTER 2. TREE-OF-BDDS FOR CSP COMPILATION ExtractExplanation (b) 1 : n := 1-terminal; E := ∅; parentType := cl 2 : while (n 6= b) 3: if (parentType = cl) m := cParentn 4: else m := vParentn 5: xj := ovar(var(m)) 6: if ( (n = solid(m) ∧ ((var(m), false) ∈ P A)) ∨(n = dashed(m) ∧ ((var(m), true) ∈ P A)) ) 7: There exists aj such that (xj , aj ) ∈ P A 8: E := E ∪ {(xj , aj )} 9: if (parentType = cl) parentType := cParentTypen 10: else parentType := vParentTypen 11: n := m 12: return E Figure 2.24: The ExtractExplanation procedure.
with (n, ns ). If the edge (n, ns ) violated P A, the lines 17-18 are executed, where pcn is extended to reach ns if its shorter. The path pcn extended with (n, ns ) violates P A, at the lines 17-18. Hence, at the line-18, we store the resulting path, if shorter than any existing pvns , as the new violated path pvns to the node ns . Between the lines 20-21, the case where the edge does not violate P A, we extend the clear path pcn as the new clear shortest path to ns , if the new one is shorter than the existing one. Between the lines 7-21, the procedure handled the case of the solid-edge child node ns . Similarly, between the lines 22-36, the case of the dashed-edge child node nd is handled. The Figure 2.24 presents the ExtractExplanation procedure. This procedure retraces the shortest solution path pc1−terminal of the BDD obtained after processing of all the non-terminal nodes by the Explain procedure. While retracing the path pc1−terminal , the procedure observes the violating edges in the path and extracts the corresponding explanation. At the line-1 of the procedure, the variable n is initialized to the 1terminal. The procedure retraces the shortest solution path in the reverse direction, starting from the 1-terminal up to the root-node b. The variable E, which will store the explanation at the end, is initialized to empty set. The variable parentType which takes values from {cl, vi} is initialized to cl. The variable parentType is used to keep track of the cParentType and vParentType values of the nodes visited while retracing the shortest solution path. The while-loop at the line-2, loops over all the nodes in the shortest path up to the node b. In each loop, the current node n and its parent (predecessor) node m in the shortest path, as implied by the parentType value are first obtained. Then, the condition of the if -statement at the line-
2.6. ALGORITHMS FOR MINIMUM EXPLANATIONS
43
6 tests whether the edge (m, n) violates the assignment P A. If the edge (m, n) violates P A, then the corresponding assignment (xj , aj ) is added to the explanation E at the line-8. Between the lines 9-11, the values of parentType and n are appropriately set for the next iteration. The time complexity of the Explain ((X, D, C), b, P A, (xi , a)) is dominated by the calls to the Relax procedure. Each call to Relax takes constant time. The number of calls to Relax is bounded by the number of nodes in the BDD. The Explain procedure requires just a constant (six) number of attributes attached to each node. Hence, the complexity of the Explain ((X, D, C), b, P A, (xi , a)) is linear in the number of nodes in the input BDD b.
Minimum Explanations in the Tree-of-BDDs Scheme We now present a procedure for finding a minimum explanation in the treeof-BDDs scheme. Our approach is to first project the solution space SOL, of an acyclic CSP instance (X, D, C), represented by a tree-of-BDDs (N, A, B) over the variables of interest to explanation generation. Note, the cost function for explanations depend only on the variable xi and the variables in vars(P A). Hence, we can project the solutions over vars(P A) ∪ {xi }, and then search for an explanation in the projection. Let for a tree-node nc ∈ N , vars(nc ) denote vars(c), the variables in the corresponding constraint c ∈ C. The Figure 2.25 presents a procedure for projecting the solution space of a tree-of-BDDs (N, A, B) over the variables in K. The procedure obtains a conjunction of all the BDDs in the input tree-of-BDDs, with appropriate existential quantification of unnecessary variables, such that the final BDD obtained represents the required projection of the input solution space. The conjunction steps are guided by the BFOrder (breadth-first traversal order) of the tree-nodes in the tree-of-BDDs. Each conjunction operation is between a BDD of a node n and the BDD of its parent node p in the BFOrder. In between the conjunction operations, a variable x is existentially quantified if x ∈ / (vars(P A)∪{xi }) and the variable does not occur in any tree-node before the current tree-node in the used BFOrder. The Figure 2.26 presents the Explain procedure for the tree-of-BDDs scheme. The procedure first projects the solution space of the input (N, A, B) over vars(P A) ∪ {xi } at the line-1 and stores the resulting projection in the BDD b. Now, as we have a single BDD representing the solutions of the projection, we can use the Explain procedure for the monolithic-BDD scheme for finding a minimum explanation. At the line-2, we make a call to the Explain((X, D, C), b, P A, (xi , a)), which outputs a minimum explanation. The complexity of the Explain((X, D, C), (N, A, B), P A, (xi , a)) procedure is at most exponential in the size of vars(P A) ∪ {xi }.
44
CHAPTER 2. TREE-OF-BDDS FOR CSP COMPILATION Project ((N ,A,B), K) 1 : for i := |N | to 2 // except the root tree-node r 2 : n := BFOrder(i); p := parent(n) 3 : γ := bvars(X)\(bvars(vars(p)) ∪ bvars(K)) 4 : B(p) := B(p) ∧ Exist(B(n), γ) 5 : return Exist(B(r), (bvars(vars(r))\bvars(K)))
Figure 2.25: The projection of the solutions of a tree-of-BDDs (N ,A,B) representing an acyclic CSP (X, D, C) on a subset of variables K ⊆ X. Explain ((X, D, C),(N, A, B), PA, (xi ,a)) 1 : b := Project((N, A, B), vars(PA) ∪ {xi }) 2 : E := Explain ((X, D, C), b, PA, (xi , a)) 3 : return E Figure 2.26: The Explain algorithm for the tree-of-BDDs scheme.
2.7
Efficient Full Interchangeability Detection for CSP Reformulation
In this section, we present methods to detect full interchangeable (FI) values of a CSP in both the monolithic-BDD and the tree-of-BDDs scheme. Definition 20 [31] A value a’ for a variable xi is fully interchangeable (FI) with a value a” if and only if every solution in which xi =a’ remains a solution when a” is substituted for a’ and vice-versa. Let SOL denote the solution space represented in any form. We specify a simple method using existential quantifications which can identify interchangeable values. Theorem 1 A value a’ for a variable xi is fully interchangeable with a value a” if and only if Exist(SOL|(xi ,a0 ) ,xi )=Exist(SOL|(xi ,a00 ) ,xi ). Hence, given a variable xi with domain {a1 , . . . , an }, testing the equality of the BDDs corresponding to Exist(SOL|(xi ,ak ) ,xi ), for every k, can be used to find interchangeable value sets of the variable xi . After that, the corresponding CSP could be reformulated by choosing a representative value for each interchangeable value set. The advantage of such reformulations is that with the reduction in the domain size of a variable, the problem gets simpler. Due to simplification, reformulations might lead to space reduction when storing solutions. Also, reformulations could be made transparent to the user by appropriately changing the Display function. This method could be extended to the tree-of-BDDs scheme as follows.
2.8. EXPERIMENTAL RESULTS
45
Definition 21 [31] A value a’ for a variable xi is neighborhood interchangeable (NI) with a value a” if and only if for every constraint on xi , the values compatible with xi =a’ are exactly those compatible with xi =a”. By the definitions of FI and NI, NI⇒FI, while FI;NI. Theorem 2 When all the constraints in a CSP are minimal, FI⇔NI The proof of the above theorem is simple as any solution of a minimal constraint can be extended to a solution for the entire CSP. Now, in case of the tree-of-BDDs scheme, the MakeJoinConsistent procedure makes its constraints minimal. For a given variable xi , the NI value sets can be detected by applying the same method, specified for finding FI value sets in the monolithic-BDD scheme, on all the tree-nodes in which xi is present. By the above theorem, the obtained NI value sets are equivalent to the FI value sets.
2.8
Experimental Results
We use the hinge tree decomposition algorithm introduced in [40] for decomposing the CSPs representing the configuration problems. The hinge decomposition method runs in polynomial time. The hinge decomposition method takes a CSP instance (X, D, C) as input and returns an acyclic CSP (X, D, C 0 ) as output, such that (X, D, C) and (X, D, C 0 ) have equivalent solutions. The hinge decomposition method is such that, for each c0 ∈ C 0 , one of the following two conditions hold: (i) there exists a c ∈ C such that c0 = c, or (ii) there exists a T ⊆ C such that c0 = (∧c∈T c). That is, for each constraint c0 in the instance (X, D, C 0 ) either c0 also occurs in (X, D, C) or c0 is a conjunction of a subset T of constraints in (X, D, C). For such a subset T , explicitly representing (∧c∈T c) using a relation might need a lot of space compared to symbolically representing (∧c∈T c) using a BDD. Hence, while building (X, D, C 0 ) instance by using the hinge decomposition method, we don’t build (X, D, C 0 ) using explicit relation representation. Instead, each constraint c0 ∈ C 0 will be represented by a BDD. Once we have such a representation of (X, D, C 0 ), we then obtain a join-tree (N, A) and subsequently, the equivalent tree-of-BDDs (N, A, B). The experiments are done by implementing the techniques presented so far, on top of CLab [50], an open source interactive configurator based on the monolithic-BDD scheme. The CLab does not have an explanation facility, and the minimum cost explanation algorithm was implemented in it. The tree-of-BDDs scheme was implemented as a tool called iCoDE (interactive Configurator with Decompositions and Explanations). The iCoDE source code, which includes CLab with explanations, is available at [48]. A
46
CHAPTER 2. TREE-OF-BDDS FOR CSP COMPILATION
Pentium Xeon machine with 4GB RAM and 1MB L2 Cache is used in the experiments. The default variable ordering, the order in which variables appear in the input file, is used. The four configuration instances used in the experiments are: PC, Renault [6], psr-1-32-1 and psr-1-32-2. All the four instances are publicly available on the web [5]. The PC instance is a personal computer configuration problem. The Renault instance is a car configuration problem, and it was the only instance used in the experiments of [6]. The Renault instance is quite large, the input file size is around 23 Megabytes, and it has totally around 200,000 tuples in 113 constraints of it. The other two instances are power supply restoration problems modeled as configuration problems. The characteristics of the benchmarks, like P the number of variables and constraints, are listed in Table 2.1. The |Di | refers to the sum of the domain size of the variables in the instance. The arity of a constraint c is the size of its scope, i.e.,P|vars(c)|. The ”Max a” refers to maximum arity of the constraints. The ai refers to the sum of the constraint arities. The |SOL| refers to the number of solutions in the instance. The compilation details are listed in Table 2.2. The CLab and iCoDE refer to the monolithic-BDD and the tree-of-BDDs scheme, respectively. The column ”Hinge(sec)” refers to the time taken by the Hinge CSP Decomposition algorithm. The following columns list the time taken for compilation in both the schemes. In the largest instance, Renault, iCoDE takes only around 50% of the time taken by CLab. The compilation timings include the time taken for finding FI values. Reformulating the instances, by removing FI values, resulted in decreasing the space requirement by around 10% in the instances. In case of iCoDE, the instance will be reformulated by exploiting the fully interchangeable values. The BDD-nodes for CLab, refers to the number of nodes in the monolithic-BDD obtained after compilation. In case of iCoDE, BDD-nodes refers to the total number of nodes in the tree-of-BDDs. As in any standard BDD package, there is a chance for two BDDs in the hinge tree to share some BDD-nodes, and such shared nodes will be counted only once. The Hinge decomposition(iCoDE) for Renault instance results in 96% decrease in the number of BDD-nodes required. The Peak BDD-nodes refers to the number of nodes used by CLab (iCoDE), to finish the compilation process. Even if the final BDD is small, the intermediate BDDs required during the compilation process may be very large, and hence the interest in Peak BDD-nodes. For the Renault instance, iCoDE uses only 80,000 BDD-nodes to finish the compilation process, which is 97% less than that used by CLab. The response and explanation times of both the schemes are compared in Table 2.3. The values listed are obtained from 10,000 random interactions. Each response is the sum of the time taken for a call to the Propagate function and a subsequent call to the Display function. During the random interactions, the time taken for calls to Explain function was also measured.
PC Renault psr-1-32-1 psr-1-32-2
Benchmark
PC Renault psr-1-32-1 psr-1-32-2
Benchmark
Table 2.2: Compilation Details Compile (sec) BDD-nodes CLab iCoDE CLab iCoDE 0.11 0.19 16494 4458 119 77 455796 17602 0.46 4 56923 8917 2 9 246775 22101
|SOL| 1.19x106 2.84x1012 1.72x1011 1.76x1013
WET (sec) CLab iCoDE 0.010 0.030 0.440 0.921 0.067 2.155 0.329 10.78
Peak BDD-nodes CLab iCoDE 0.08M 0.04M 2.5M 0.08M 0.6M 0.6M 1.2M 1.2M
ai 107 588 913 913
P
Table 2.3: Response and explanation time comparison ART(sec) WRT(sec) AET (sec) CLab iCoDE CLab iCoDE CLab iCoDE 0.004 0.0001 0.050 0.006 0.004 0.010 0.070 0.0003 0.452 0.020 0.160 0.088 0.016 0.0010 0.057 0.038 0.031 1.208 0.037 0.0002 0.618 0.107 0.122 5.38
16 73 114 114
|C 0 |
Table 2.1: P Configuration Benchmarks |Di | Constraints Max a Variables 45 383 36 16 99 402 113 10 110 258 222 9 110 296 222 9
Hinge (sec) 0.04 0.25 2 2
Benchmark PC Renault psr-1-32-1 psr-1-32-2
2.8. EXPERIMENTAL RESULTS 47
48
CHAPTER 2. TREE-OF-BDDS FOR CSP COMPILATION
The ART and WRT refers to the average and worst response time, respectively. The AET and WET refers to the average and worst time taken for minimum explanations, respectively. In case of Renault instance, iCoDE results in 200X speedup for ART and 20X speedup for WRT. In explanation results for Renault instance, even though the Explain function for tree-ofBDDs is not linear like the Explain for monolithic-BDD, in average case the Explain function for tree-of-BDDs takes lesser time to generate an explanation. This is due to 96% decrease in the BDD-nodes value. The WET by iCoDE is around twice the time taken by CLab. This should be due to the higher time complexity of the Explain function for tree-of-BDDs, which is in the worst case exponential in the number of variables in the corresponding partial assignment P A. The explanation function in CLab is also a contribution of this work. The results for the last two instances show almost the same phenomenon as that for the Renault instance.
2.9
Related work
Only a very few published CSP compilation techniques use tree decomposition techniques. We are not aware of any work detecting full interchangeable values for problem reformulation. In [74] a compilation scheme was presented, but it did not use tree decomposition techniques to guarantee a polynomial response time. Also, it only exploited the neighborhood interchangeability. In [6], an automaton based compilation scheme without decomposition was presented. It is similar to the monolithic-BDD scheme. In [58], a CSP compilation technique combining tree clustering [25] and cartesian product representation (CPR) was presented. That work did not have minimum explanations and full interchangeability detection. In [28], Tree-Driven Automata, a CSP compilation technique combining automata and tree decomposition was presented. It did not focus on the functionalities, like explanations, required for interactive configuration. Also, it did not have any experimental results. Our algorithm for explanations in the monolithic-BDD scheme was inspired by an algorithm discussed in [10]. However, the problem in [10] was made easier by adding an additional Boolean variable for each dynamic constraint added to a BDD. The additional variables will be used as switches to turn on or off the corresponding dynamic constraints. The additional variables will significantly increase the size of the BDD. In our case, the dynamic constraints posted for propagation are unary (a variable assignment), and we assume that the Boolean variables corresponding to a original finite domain variable are placed consequently in the variable order.
2.10. CONCLUSION
2.10
49
Conclusion
A decomposition scheme, tree-of-BDDs, for compiling models for interactive configurators was presented. The decomposition scheme results in a drastic reduction in space required for storing the compiled solutions. A linear algorithm for minimum explanations in the monolithic-BDD scheme was given. Using abstractions, the explanation algorithm was extended to work in the tree-of-BDDs scheme. Procedures for exploiting full interchangeable values was given. All the techniques presented here were experimentally evaluated as useful. Altogether, we believe that this work improves the state-of-the-art in configurators and CSP compilation techniques. Future work include: experiments on BDD variable orderings, hybrid representations instead of just BDDs, using multi-valued decision diagrams instead of BDDs [54], efficient quantification scheduling for explanations in the tree-of-BDDs scheme, and comparing other tree decomposition techniques with hinge decomposition technique.
50
CHAPTER 2. TREE-OF-BDDS FOR CSP COMPILATION
Chapter 3
Knowledge Compilation Properties of Tree-of-BDDs We present a CNF to Tree-of-BDDs (ToB) compiler with complexity at most exponential in the tree width. We then present algorithms for interesting queries on ToB. Although some of the presented query algorithms are in the worst case exponential in the tree width, our experiments show that ToB can answer non-trivial queries like clausal entailment in reasonable time for several realistic instances. While our ToB-tool compiles all the used 91 instances, d-DNNF compilation failed for 12 or 8 of them based on the decomposition heuristic used. Also, on the succeeded instances, a d-DNNF is up to 1000 times larger than the matching ToB. The ToB compilations are often an order of magnitude faster than the d-DNNF compilation. This makes ToB a quite interesting knowledge compilation form.
This contents of this chapter has been published as the paper: S. Subbarayan, L. Bordeaux, Y. Hamadi, ”Knowledge Compilation Properties of Tree-of-BDDs ”, AAAI Conference, Vancouver, 2007, pages 502-507.
51
52
3.1
CHAPTER 3. TREE-OF-BDDS FOR COMPILING KNOWLEDGE
Introduction
The characteristics of a real-world system modeled in propositional theory could be used for reasoning the behavior of the system. Knowledge compilation focuses on methods for improving such reasoning. A recent focus has been to compile the theory representing a system into a form such that arbitrary number of interesting queries on the system behavior can be quickly answered. The forms which have been studied for compilation include OBDDs [12], DNNF [19] and d-DNNF [20]. Applications of knowledge compilation include configuration, model-based diagnosis and Bayesian inference. The Tree-of-BDDs (ToB) [69] is a recently introduced form in the context of configuration systems. We present the properties of ToB, which makes it a quite interesting form. Specifically, we show that a system modeled in a CNF can be compiled into a canonical ToB with compilation complexity exponential in a tree decomposition width of the CNF. Hence, bounded treewidth CNF instances can be compiled into ToBs using linear time and space. We then present algorithms for several interesting queries on ToBs. Although some of the presented query algorithms are not polytime, our experiments show the viability of ToBs for knowledge compilation. Our experiments on 91 realistic instances show that ToB compilations often use an order of magnitude lesser time and space than d-DNNF. In fact, while all the 91 instances are compiled into ToBs within 926 seconds, several d-DNNF compilations fail with 3600 seconds time allowed for each instance. A d-DNNF successfully compiled is up to 1000 times larger than the matching ToB. Also, we observe that non-trivial queries like clausal entailment can be answered by ToBs in reasonable time even for several instances whose d-DNNF compilation fails. The next section defines the ToB and presents a CNF to ToB compiler. The following section presents the algorithms for queries on ToB. Subsequently, the empirical results are presented followed by some concluding remarks.
3.2
The Tree-of-BDDs
We consider that the model to be compiled is given as a CNF. But the presented techniques can be easily extended for more general representations. Let the pair (V ,C) denote a CNF, where V is a set of variables and C a set of clauses over V . Let the set of variables occurring in a clause c be denoted by vars(c). The terms like OBDD (DNNF) may refer to a specific OBDD (DNNF), or the function represented by an OBDD (a DNNF), or the set of all possible OBDDs (DNNFs), which will be clear from the context.
3.2. THE TREE-OF-BDDS
53
Definitions An ordered binary decision diagram (OBDD) [12] is a rooted directed acyclic graph with two terminal nodes, marked true (1) and false (0). Each internal node will have two outgoing edges, one solid and another dashed. Each internal node will be associated a variable, such that in any path from the root to a terminal node the variables associated with the nodes in the path occur at most once and occur in a linear order. We only consider a special reduced version of OBDDs in which a node n1 with both of its outgoing edges reaching the same node n2 will be removed, and all the incoming edges of n1 will be made to directly reach n2 . Also, isomorphic nodes, i.e., nodes {n1 , . . . ni }, associated with a same variable, whose solid and dashed edges reach the same nodes ns and nd respectively, will be merged into a single node n, with all the incoming edges of {n1 , . . . ni } now reaching n. Given an OBDD b defined over propositional variables P , and an assignment A to P , the corresponding path in b is the unique path from the root node of b to a terminal node, such that the path contains the solid outgoing edge of a node iff the variable corresponding to the node takes true value in A. A function f is represented by an OBDD iff the path corresponding to any solution (i.e., a satisfying assignment) of f reaches the true terminal. The size of an OBDD b, denoted |b|, is measured in terms of the number of internal nodes or edges. The operations on OBDDs we use are conjunction (∧), disjunction (∨), restriction (|) and existential quantification of a set of variables S (∃S). The time and space complexity of ∧ and ∨ operations between two OBDDs b1 and b2 is O(|b1 ||b2 |). The |-operation takes linear time. The time and space complexity of ∃-operation of a variable is O(|b|2 ). Given an OBDD b representing a function over variables V , the projection of b over a set of variables S is obtained by ∃(V \S).b. Given a CNF and a variable order, the OBDD of the CNF could be compiled by ∧-operations over trivial OBDDs representing the clauses. A tree decomposition [66, 24] of a CNF (V ,C) is a tree (N ,A), such that N is the set of nodes and A the set of edges. Each node n ∈ N will be associated with vars(n) ⊆ V . For any n ∈ N , let clauses(n) = {c | c ∈ C ∧ vars(c) ⊆ vars(n)}. Additionally, (N ,A) has to satisfy two conditions: (1) for each clause c ∈ C, ∃n ∈ N. c ∈ clauses(n) and (2) for each v ∈ V , the set of nodes {n | n ∈ N ∧ v ∈ vars(n)} form a connected subtree in (N ,A). By the first condition, for every clause c ∈ C, at least one (need not be unique) node n ∈ N is such that: vars(c) ⊆ vars(n). The second condition specifies that all the nodes that share a variable form a connected subtree. The width (w) of (N ,A) is maxn∈N {|vars(n)| − 1}. A Tree-of-BDDs (ToB) [69] of a given CNF (V ,C) is a triple (N ,A,B), where (N ,A) is a decomposition of (V ,C), and B is a mapping such that ∀n ∈ N , the B(n) is an OBDD representing the projection of the CNF on
54
CHAPTER 3. TREE-OF-BDDS FOR COMPILING KNOWLEDGE
vars(n). That is if the OBDD b represents the CNF, then ∀n ∈ N. B(n) = ∃(V \vars(n)).b. Note, all the B(n) OBDDs use a common variable order. Also, by the properties of tree decomposition, conjunction of the OBDDs of each node will be equivalent to the CNF, i.e., (b = ∧n∈N B(n)). The size of a ToB (N ,A,B) is Σn∈N |B(n)|. Similar to OBDDs each ToB also represents a function. A ToB represents a function f iff for any assignment A satisfying f , for each n ∈ N , the path in B(n) corresponding to A reaches the true terminal.
a b
b
a
c
c
b
d
e d
b 0
e
(b)
d
0
1 0
1
(c)
1
(a) OR
AND
OR
AND
¬a
AND
b
AND
¬d
a
¬b
¬c
¬e
(d) Figure 3.1: (a) An OBDD, (b) B(0), (c) B(1) and (d) A d-DNNF.
3.2. THE TREE-OF-BDDS
55
An example Lets consider an example CNF (V ,C) with V = {a, b, c, d, e} and C = {(¬a∨ ¬e), (a ∨ b), (b ∨ ¬c), (c ∨ ¬d), (¬b ∨ ¬d)}. The matching OBDD using the order a < b < c < d < e is in Figure 3.1a. A matching ToB is (N ,A,B) with N = {0, 1}, A = {(0, 1)}, vars(0) = {a, b, e} and vars(1) = {b, c, d}. The Figures 3.1b and 3.1c show the B(0) and B(1) OBDDs. The size of the OBDD is 14 edges, while the size of the ToB is 12 edges. We state the following theorem. The theorem follows immediately from the canonicity (uniqueness) of an OBDD for a function up to the used variable order. Theorem 3 Given a CNF (V ,C), a tree decomposition of the CNF (N ,A), a linear order < of V , the corresponding ToB (N ,A,B) using < is canonical. CNF2ToB ( (V ,C), (N ,A) ) 1 : ∀n ∈ N. B(n) := ∧c∈clauses(n) cl2bdd(c) 2 : Propagate ((N ,A,B)) 3 : return (N ,A,B) Propagate ((N ,A,B)) 1 : for i := |N | to 2 // except the root node r 2 : n := BFOrder(i); p := parent(n) 3 : B(p) := B(p) ∧ ∃(V \vars(p)).B(n) 4 : for i := 1 to |N | 5 : n := BFOrder(i); H := children(n) 6 : ∀h ∈ H. B(h) := B(h) ∧ ∃(V \vars(h)).B(n) Figure 3.2: The CNF to ToB compiler.
The compiler Let BFOrder for a decomposition (N ,A) be an order the nodes in N are visited by a breadth-first traversal of (N ,A) starting at an arbitrary node r as root. Let BFOrder (i) denote the ith element in the BFOrder. Then, for any non-root node n ∈ N , let parent(n) denote the unique neighbor of n which occurs before n in the BFOrder and let children(n) denote the neighbors of n which occur after n in the BFOrder. Let cl2bdd (c) be a function that takes a clause c as input and returns the equivalent OBDD. The pseudo-code of the function CNF2ToB which takes a CNF (V ,C) and a tree decomposition (N ,A) as input, and returns a ToB (N ,A,B) is shown in Figure 3.2. There are two phases in the function. In the first phase, for each node n in the tree the clauses(n) are compiled into
56
CHAPTER 3. TREE-OF-BDDS FOR COMPILING KNOWLEDGE
equivalent OBDDs and conjoined to form an initial B(n). In the next phase, the Propagate function is called which results in a ToB (N ,A,B). In the lines 1-3 of the Propagate function, in the reverse BFOrder, each node projects its solution space on its parent node. In the lines 4-6, in the BFOrder, each node projects its solution space over its children, which results in a ToB. The correctness of the pseudo-code CNF2ToB follows from the fact that the code is just a CNF adaptation of a similar compiler in [69], which in turn is a compressed way of handling the well-known tree-clustering [24] process. The following theorem shows that the complexity of CNF2ToB is exponential in the width of the input tree decomposition and hence linear for bounded treewidth CNFs. Theorem 4 The complexity of CNF2ToB is O(|V |w2 22w ). Proof 1 The main cost of the CNF2ToB procedure is due to projection and conjunction operations on B(n) OBDDs. Since each vars(n) has at most w + 1 variables, the matching B(n) never has more than 2w+1 paths (solutions) from root to true terminal node. Since each path in a B(n) can have at most w + 1 nodes, the number of nodes in a B(n) is at most (w + 1)2w+1 at any moment. Also, in a good tree decomposition |N | ≤ |V | . Hence by using the complexity of the OBDD operations used, the complexity of CNF2ToB is O(|V |w2 22w ). ¤
3.3
Queries: Algorithms and Complexity
In this section, following [20], we define the NNF form, and present its subsets. We then present algorithms for interesting queries on ToBs. A negation normal form (NNF) is a rooted directed acyclic graph with leaf nodes associated with either true, false or a literal, and non-leaf nodes will be either an ∧ (AND) node or an ∨ (OR) node. A NNF represents the function obtained by recursively defining the functionality of OR and AND nodes to be ∨- and ∧- operations respectively, over the functions of the child nodes. The size of a NNF is the number of edges. A NNF may be an OBDD, a DNNF or a d-DNNF based on whether it satisfies some of the four properties: decomposable (D), deterministic (d), decision, and ordering (1s%: % of 10000 queries requiring more than one second to respond.
3.5. RELATED WORK
63
instances is 926 seconds, the 90 ToBs other than that of C210FW are compiled in just 263 seconds. The Table 3.3 also lists the mean and maximum response time for 10000 random CE and IM queries for each instance. Each random CE (IM) query will use a random clause (term) with at most |V |/10 consistent literals. The table shows that on the average ToB takes at most one second even for the listed hard instances for d-DNNF. In case of C210FW, ToB takes 10 seconds to respond in the worst case, but the size of ToB is around 20 times smaller than the d-DNNF-mg that we definitely get a trade-off, even if d-DNNF gives shorter response time. In Figure 3.4, we plot the compilation time taken by ToB versus dDNNF. In Figure 3.5, we have a similar plot comparing size. The figures show that the ToB compilations often require relatively very small time and space. 10000
1000
d-DNNF (seconds)
100
10
1
0.1
0.01 d-DNNF (hg) d-DNNF (mf) x=y 0.001 0.001
0.01
0.1
1 ToB (seconds)
10
100
1000
Figure 3.4: Compilation time: ToB vs. d-DNNF.
3.5
Related Work
Although BDD-trees [60] and ToB have a similar name, they are quite different. The BDD-trees representation uses a binary tree decomposition, while the decomposition used by ToB need not be a binary tree decomposition.
64
CHAPTER 3. TREE-OF-BDDS FOR COMPILING KNOWLEDGE 1e+009
1e+008
d-DNNF (edges)
1e+007
1e+006
100000
10000
1000 d-DNNF (hg) d-DNNF (mf) x=y 100 100
1000
10000
100000
1e+006
1e+007
ToB (edges)
Figure 3.5: Representation size: ToB vs. d-DNNF.
Each node in a ToB maps to precisely one OBDD, while each node in a BDD-trees will have a two-dimensional matrix of OBDDs. If the left and right child functions of a node in a BDD-trees has m and n equivalence classes of solutions respectively, then the matrix of the node will be of size m*n. Each entry in the matrix will be an OBDD. Hence, BDD-trees are quite complex compared to ToB. Each node in an AND/OR BDD [59] represents a Boolean function of the form: ((α1 ∧ α2 ∧ . . . ∧ αn1 ) ∧ x ∨ (β1 ∧ β2 ∧ . . . ∧ βn2 ) ∧ ¬x), where αi s and βi s are functions represented by the children of the node and x is the decision variable of the node. Hence, AND/OR BDDs define a subset of dDNNFs and satisfy the decomposable property. The AND/OR MDDs [59] are multi-valued versions of AND/OR BDDs. Both the tree-driven automata [28] and the Ordered DDGs [27] are decomposable, and hence different from ToBs.
3.6
Conclusion and Future Work
We have presented a CNF to ToB compiler with compilation complexity exponential in the width of a tree decomposition of the CNF. Hence, the compilation takes linear time and space for bounded width CNFs. We have
3.6. CONCLUSION AND FUTURE WORK
65
also presented algorithms for several interesting queries on ToBs. We have presented experiments on several instances, which show that ToB compilation is usually fast and results in smaller representations than d-DNNF compilation. In some instances d-DNNF compilation fails, while ToB compilation succeeds all the used instances. Even in the instances for which d-DNNF compilation succeeds, a resulting d-DNNF is up to 1000 times larger than the matching ToB. Our experiments show that ToBs are able to answer non-trivial queries like clausal entailment in reasonable time even for several realistic instances whose d-DNNF compilation fails. This makes ToB a quite interesting form for knowledge compilation. Avenues for future work include studying the succinctness of ToBs, and the transformations supported by ToBs. For example, the negation transformation of a ToB is trivial, by just switching the two terminal nodes, while it is not known to be polytime for d-DNNFs. Also, the ToB could be adapted for exploiting multi-core CPUs. For instance, if there are four cores in a CPU, then the child subtrees of the root node can be partitioned into four groups and the processing in each group can be allocated to a core.
66
CHAPTER 3. TREE-OF-BDDS FOR COMPILING KNOWLEDGE
Chapter 4
Efficient Reasoning in BDDs for Nogoods When BDDs are used for propagation in a constraint solver with nogood recording, it is necessary to find a small subset of a given set of variable assignments that is enough for a BDD to imply a new variable assignment. We show that the task of finding such a minimum subset is NP-complete by reduction from the hitting set problem. We present a new algorithm for finding such a minimal subset, which runs in time linear in the size of the BDD representation. In our experiments, the new method is up to ten times faster than the previous method, thereby reducing the solution time by even more than 80%. Due to linear time complexity the new method is able to scale well.
This contents of this chapter has been published as the paper: S. Subbarayan, ”Efficient Reasoning for Nogoods in Constraint Solvers with BDDs”,PADL Symposium, San Francisco, January 2008, Springer LNCS 4902. pages 53-67.
67
68
4.1
CHAPTER 4. REASONING IN BDDS FOR NOGOODS
Introduction
Many useful functions have compact Binary decision diagram (BDD) [12] representations. Hence, the BDDs has attracted attention as a constraint representation [10, 42, 71, 70, 57, 44, 14]. The BDDs have been used in many applications, including: verification, configuration and fault-tree analysis. The nogood recording [23, 68] is a technique in constraint solvers to find a subset of the variable assignments made upto a dead-end in a search tree, such that the found subset could independently lead to dead-ends. By recording such subsets called nogoods and by preventing similar assignment patterns, the search effort can be drastically reduced. For a given set of variable assignments X, if the propagation of X in a constraint c implies a variable assignment (v := a), denoted X∧c ⇒ (v := a), then a reason R is a subset of X, such that R ∧ c ⇒ (v := a). Finding small reasons is essential for nogood recording. The nogood recording plays a major part in the successful SAT solvers. The adoption of the nogood recording in general constraint solvers requires efficient methods for finding small reasons in every important constraint representation, including BDDs. This chapter focuses on finding small reasons in BDDs. We show that the task of finding a minimum-sized reason in BDDs is NP-complete by reduction from the hitting set problem. We also present a new algorithm for finding minimal-sized reasons, which runs in time linear in the size of the BDD representation. We then empirically demonstrate the usefulness of the new algorithm over a previous method. In our experiments, the new method scales better, and is upto 10 times faster than the previous one.
4.2
Definitions
The Constraint Satisfaction Problem A constraint satisfaction problem (CSP) instance is a triple (V, D, C), where V is a set of variables, D is a set of finite domains, one domain di ∈ D for each variable vi ∈ V , and C is a set of constraints. Each constraint ci ∈ C is a pair of the form (si , ri ), where si ⊆ V and ri is a relation over the variables in si . An assignment X is a set like {vx1 := ax1 , vx2 := ax2 , . . . , vx|X| := ax|X| }. The variable assignment (vxi := axi ) fixes the value of vxi to axi , where axi ∈ dxi . An assignment X is full if |X| = |V |, partial otherwise. A solution to a CSP is a full assignment S, such that for any constraint (si , ri ) ∈ C, the assignment S restricted to si belongs to the relation ri , i.e., S|si ∈ ri . For a given assignment X, a constraint ci implies a variable assignment (v := a), denoted X ∧ ci ⇒ (v := a), if every tuple in the relation ri containing X|si also contains (v := a).
4.2. DEFINITIONS
69
The Binary Decision Diagrams A reduced ordered binary decision diagram (BDD) [12] is a directed acyclic graph with two terminal nodes, one marked with 1 (true) and the other with 0 (false). The Figure 4.2 (a) and Figure 4.3 (a) show two example BDDs. Each non-terminal node n is associated with a Boolean variable var (n). Each node n has two outgoing edges, one dashed and another solid. The occurrence of variables in any path has to obey a linear order. Also, isomorphic subgraphs will be merged together, and a node n with both its outgoing edges reaching the same node nc will be removed with all the incoming edges of n made to reach nc directly. A BDD will be represented by its root node. The size of a BDD b, |b|, is the number of non-terminal nodes. For a given BDD, the term solid (n1 ) evaluates to n2 iff (n1 , n2 ) is a solid edge in the BDD. Similarly, dashed (n1 ) evaluates to n2 iff (n1 , n2 ) is a dashed edge. The variable assignment corresponding to an edge (n1 , n2 ) is (var(n1 ) := a), where a = true iff n2 = solid(n1 ). Consider a path p =< n1 , n2 , . . . , nl > in a BDD with nl = 1, from a node n1 to the 1-terminal. The assignment Xp corresponding to the path p is Xp = {(var(ni ) := a) | 1 ≤ i ≤ (l −1), (ni+1 = solid(ni )) ⇔ (a = true)}. The Xp is the set of the variable assignments corresponding to each edge in the path. The path p is a solution path if n1 = b and nl = 1, i.,e, starts from the root node. A BDD b represents a Boolean function f iff for any solution S to f , there exists a solution path p in b, such that Xp ⊆ S. We may denote the function represented by a BDD b by b itself. If S is a solution of f , we may specify S ∈ f . The set of solutions Sp corresponding to a solution path p is Sp = {S | Xp ⊆ S, S ∈ b}. We denote (v := a) ∈ p to specify that there exists a S ∈ Sp such that (v := a) ∈ S. Similarly, we denote X ∈ p if there exists a S ∈ Sp such that X ⊆ S. Note, (v := a) ∈ p mentions that either there occurs an edge (ni , ni+1 ) in p whose corresponding assignment is (v := a), or there is no node ni in the path p such that var(ni ) = v. Although a BDD representing a Boolean function could be exponential in the number of variables in the function, for several practically useful functions the equivalent BDDs are of small size. Hence, the BDDs have found widespread usage in several applications.
Representing Constraints Using BDDs To simplify the presentation, we assume that all the variables in a given CSP have Boolean domain. Given a general CSP, we can encode it using Boolean variables. For example, using the log-encoding method, a non-Boolean variable v ∈ V with domain d can be substituted by dlog |d|e Boolean variables, matching each value in d to a unique assignment of the introduced dlog |d|e Boolean variables. Each constraint ci ∈ C is hence a Boolean function defined over si , with
70
CHAPTER 4. REASONING IN BDDS FOR NOGOODS
the function mapping an assignment for si to true iff the assignment belongs to ri . For X = {vx1 := ax1 , vx2 := ax2 , . . . , vx|X| := ax|X| }, the Boolean function obtained by the conjunction of the variable assignments in X is also V denoted by X, i.e., X = 1≤i≤|X| (vxi = axi ), which will be clear from the context. Given a CSP with several constraints, some of the constraints’ function might be represented by compact BDDs. The BDDs of some of the constraints might result in obtaining helpful inferences to speed-up the constraint solver. Hence, the BDDs has attracted attention as a constraint representation [10, 42, 71, 70, 57, 44, 14].
The Nogoods A nogood [23, 68] of a CSP is a partial assignment N , such that for any solution S of the CSP, N * S. Hence, a nogood N cannot be part of any solution to the CSP. In a typical constraint solver, an initial empty assignment X = {} will be extended by both the branching decisions and the variable assignments implied by the decisions, and the partial assignment X will be reduced by the backtracking steps. The extensions and reductions will go on until either X becomes a solution or all possible assignments are exhausted. A backtracking step occurs when the assignment X cannot be extended to a solution. The nogood recording, if implemented in a constraint solver, will be invoked just before each backtracking step. The nogood recording involves finding and storing a subset N of the partial assignment X, such that N is a nogood. Such nogoods can be used to prevent some bad branching choices in the future and hence speed-up the solution process. This paper focuses on a building block of nogood recording and can be understood independently. We refer the interested reader to [23, 68, 55, 76, 44] for details on the whole nogood recording process.
The Reasons for Variable Assignment A building block of nogood recording is to find a small subset R of an assignment X that is a reason for the implication of a variable. If X ∧ c ⇒ (v := a), then the reason R is a subset of X, R ⊆ X, such that R ∧ c ⇒ (v := a). Heuristically, smaller sized reasons are preferred, since that would lead to smaller nogoods resulting in better pruning. We show that when a BDD represents a constraint, the task of finding a minimum sized reason is NP-complete. We also show that a minimal sized reason can be found in time linear in the size of the BDD. Given a BDD b, an assignment X and (v := a) such that X ∧ b ⇒ (v := a), let Rall = { R | R ⊆ X, R ∧ b ⇒ (v := a)}. The set Rall contains all the
4.3. THE MINIMUM BDD-REASON IS INTRACTABLE
71
reasons. Now, we formally define the problems for finding minimum and minimal reasons in BDDs. We specify the decision version for the minimum problem. MINIMUM BDD-REASON : Input: A BDD b, an assignment X, and (v := a), such that X ∧b ⇒ (v := a) and a positive integer K. Output: Yes, if there is a R, such that R ∈ Rall , and |R| ≤ K. No, otherwise. MINIMAL BDD-REASON : Input: A BDD b, an assignment X, and (v := a), such that X ∧b ⇒ (v := a). Output: R, such that R ∈ Rall , and ∀R0 ∈ Rall . if R0 ⊆ R then R = R0 .
4.3
The MINIMUM BDD-REASON is Intractable
We prove that MINIMUM BDD-REASON is NP-complete by using reduction from the HITTING SET problem. HITTING SET [33]: Input: A collection Q of subsets of a finite set P , and a positive integer K ≤ |P |. Output: Yes, if there is a set P 0 with |P 0 | ≤ K such that P 0 contains at least one element from each subset in Q. No, otherwise. Lemma 8 A relation r with q tuples, defined over k Boolean variables, can be represented by a BDD of size at most qk nodes. Proof 5 If the BDD b represents the relation r, then there will be exactly q solutions in b, one for each tuple in r. Since representing each solution by b requires at most k nodes, there will be at most qk non-terminal nodes in b. ¤ Lemma 9 Given a BDD m of a function over the variables in {b1 , b2 , . . . , bk }, using the order b1 < b2 < . . . < bk , if m ⇒ (bk := false) then the size of the BDD m0 representing m ∨ (bk = true) is |m|. Proof 6 Since the variable bk is at the end of the variable order, given m we can obtain m0 by just the following two steps. 1. Add a new node n0 with var(n0 ) = bk . The dashed edge of n0 will reach the 0-terminal and the solid edge will reach the 1-terminal. The n0 represents the function (bk = true). Now, for each dashed (resp. solid) edge of the form (n, 0) for any node n, where n 6= n0 , replace the dashed (resp. solid) edge (n, 0) with a new dashed (resp. solid) edge (n, n0 ). 2. There will be only one n00 such that var(n00 ) = bk and n00 6= n0 , representing the function (bk = false), otherwise m ⇒ (bk := false) is not
72
CHAPTER 4. REASONING IN BDDS FOR NOGOODS possible. Remove n00 and make the incoming edges of n00 to reach the 1-terminal.
Exactly one node n0 is added and one node n00 is removed. Hence, |m0 | = |m|. ¤ Theorem 10 The MINIMUM BDD-REASON is NP-complete. Proof 7 The problem is in NP, as we can quickly check the correctness of any R. Now, we reduce the HITTING SET problem into MINIMUM BDDREASON. Let the set P = {p1 , p2 , . . . , p|P | }, Q = {q1 , q2 , . . . , q|Q| } with qi ⊆ P and an integer K define an instance of the HITTING SET problem. Let r be a relation defined over the |P | + 1 Boolean variables in the set {b1 , b2 , . . . , b|P |+1 }. The Figure 4.1 shows the structure of the relation r. There will be |Q| rows in r. The row i of r will correspond to the qi ∈ Q. Let the Boolean term aij be false iff pj ∈ qi . The row i of the relation r will contain the tuple (ai1 , ai2 , . . . , ai|P | , false). Let the BDD br represents the function of r, using the order b1 < b2 < . . . < b|P |+1 . Let the BDD b0 represents the function (b|P |+1 = true). The b0 is trivial with just one non-terminal node. Let the BDD b represents br ∨ b0 , i.e., b = br ∨ b0 . Let X = {b1 := true, b2 := true, . . . , b|P | := true}. By the definition of r, in each solution S of br the b|P |+1 takes false value. Also, if S is a solution of b0 , then b|P |+1 takes true value in S. Due to the different values for b|P |+1 , the solutions of br and b0 are disjoint. So for any S ∈ b, either S ∈ br or S ∈ b0 , but not both. For any qi ∈ Q, |qi | ≥ 1, therefore, for each row i of r there exists a pj ∈ qi such that aij = false. So, for any S ∈ b, S ∈ br implies that there exists an i, 1 ≤ i ≤ |P |, such that aij = false, and hence bi takes false value in S. As, for 1 ≤ i ≤ |P |, bi takes true in X, X ∧ br is false. So, X ∧ b = X ∧ b0 and since b0 = (b|P |+1 = true), X ∧ b ⇒ (b|P |+1 := true). So, the assignment X, the BDD b, the variable assignment (b|P |+1 := true) and the integer K define an instance of the MINIMUM BDD-REASON problem. So given a HITTING SET instance (P, Q, K), we can obtain a corresponding instance of MINIMUM BDD-REASON defined by (X, b, (b|P |+1 := true), K). We now have to show that given (P, Q, K), we can obtain (X, b, (b|P |+1 := true), K) in polytime and also that the output to (X, b, (b|P |+1 := true), K) is Yes iff the output for (P, Q, K) is Yes. To show that we can obtain (X, b, (b|P |+1 := true), K) in polytime, we just have to show that we can obtain b in polytime. By Lemma 8, |br | is bounded by |Q|(|P | + 1). Also, by Lemma 9, |b| which is equivalent to br ∨ (b|P |+1 = true) is at most |br |. Hence, we can obtain (X, b, (b|P |+1 := true), K) in polytime.
4.4. A LINEAR-TIME ALGORITHM FOR MINIMAL BDD-REASON b1 a11 a21 . . . a|Q|1
b2 a12 a22 . . . a|Q|2
. . . . . . .
. . . . . . .
. . . . . . .
b|P | a1|P | a2|P | . . . a|Q||P |
73
b|P |+1 false false . . . false
Figure 4.1: The relation r.
Now, we just have to show that the instance (P, Q, K) has the Yes output iff the instance (X, b, (b|P |+1 := true), K) has the Yes output. (⇒): Let P 0 = {pt1 , pt2 , . . . , pt|P 0 | }, where 1 ≤ ti ≤ |P |, be an answer for the Yes output of (P, Q, K). Then consider R to be {bt1 := true, bt2 := true, . . . , bt|P 0 | := true}. We show that R ∧ b ⇒ (b|P |+1 := true), which proves the (⇒) case. Since P 0 is a Yes answer, by definition, for each row i of r, there will be a j, such that pj ∈ P 0 and (aij = false). So for each row i, there will be a j, such that (aij = false) and bj takes true value in R. Hence, the solution S ∈ br corresponding to any row i cannot be a solution of R ∧ br . So, R ∧ br = false, which implies R ∧ b = R ∧ (br ∨ b0 ) = ((R ∧ br ) ∨ (R ∧ b0 )) = ((false) ∨ (R ∧ b0 )) = R ∧ b0 . Since, (R ∧ b0 ) ⇒ (b|P |+1 := true), R ∧ b ⇒ (b|P |+1 := true). Hence the (⇒) case. (⇐): Let R = {br1 := true, br2 := true, . . . , br|R| := true} be a solution for the Yes answer of (X, b, (b|P |+1 := true), K). Let P 0 = {pr1 , pr2 , . . . , pr|R| }. We have to show that P 0 has at least one element pj ∈ qi for each qi ∈ Q. Since R ∧b ⇒ (b|P |+1 := true), b0 ⇒ (b|P |+1 := true) and br ⇒ (b|P |+1 := false), R ∧ br = false. So, there is no solution S such that S ∈ (R ∧ br ). For each row i of the relation r there exists a j such that (aij = false) and (bj := true) ∈ R. Otherwise, i.e., if there does not exist such a j for a row i then, the solution S corresponding to the row i belongs to (R ∧ br ), which is a contradiction to R ∧ br = false. So, for each row i, there exists a j such that (aij = false) and (bj := true) ∈ R, hence, pj ∈ qi and pj ∈ P 0 , which proves the (⇐) case. ¤
4.4
A Linear-Time Algorithm for MINIMAL BDDREASON
A dashed edge (n1 , n2 ) in a BDD b is a conflicting edge with respect to an assignment X if (var(n1 ) := true) ∈ X. Similarly, a solid edge (n1 , n2 ) in b is a conflicting edge with respect to X if (var(n1 ) := false) ∈ X.
74
CHAPTER 4. REASONING IN BDDS FOR NOGOODS
Suppose X ∧ b ⇒ (v := a), then the removal of all the conflicting edges w.r.t X in b will result in removing each solution path p with (v := ¬a) ∈ p. Otherwise, there will be a p such that X ∈ p and (v := ¬a) ∈ p, which is a contradiction to X ∧ b ⇒ (v := a). Example 1 Consider the BDD b in the Figure 4.2 (a) and the assignment X = {v := true, x := true, z := false}, then X ∧ b ⇒ (y := true). Hence, the removal of the conflicting edges, as shown in the Figure 4.2 (b), removes every solution path p with (y := false) ∈ p. Example 2 Consider the BDD b in the Figure 4.3 (a) and the assignment X = {v := false, w := true, y := false}, then X ∧ b ⇒ (x := false). Hence, the removal of the conflicting edges, as shown in the Figure 4.3 (b), removes every solution path p with (x := true) ∈ p. v
v w
w x
w
x
x
x
y
y
y
w y
x
z
1
v
0
x
x
x
y
w
y
y
y
x
z
1
(a)
w x
x
y
0
x
y
y
y
z
1
0
(b)
(c)
Figure 4.2: Example 1, X ∧ b ⇒ (y := true). (a) The BDD b, (b) The BDD b without the conflicting edges w.r.t X, (c) The BDD b without the frontier edges. v
v
w
x
w
x
w
y
y
0
v
1
(a)
x
x
w
x
w
y
y
0
v
1
(b)
x
x
w
x
w
y
y
0
1
(c)
x
x
x
w
y
y
0
x
1
(d)
Figure 4.3: Example 2, X ∧ b ⇒ (x := false). (a) The BDD b, (b) The BDD b without the conflicting edges w.r.t X, (c) The BDD b without the frontier edges, (d) The BDD b without the conflicting edges w.r.t R = {(v := false), (w := true)}. Suppose X ∧ b ⇒ (v := a), a conflicting edge (n1 , n2 ) is a frontier edge if there exists a solution path p using (n1 , n2 ), such that (v := ¬a) ∈ p, and the subpath of p from n2 to the 1-terminal does not use any conflicting edge.
4.4. A LINEAR-TIME ALGORITHM FOR MINIMAL BDD-REASON
75
In any solution path p with (v := ¬a) ∈ p, the frontier edge is the conflicting edge nearest to the 1-terminal. Hence, removal of all the frontier edges will result in removing every solution path with (v := ¬a). Otherwise, there will exist a solution path p without using any frontier edge, such that (v := ¬a) ∈ p, which is a contradiction to X ∧ b ⇒ (v := a). The Figure 4.2 (c) and Figure 4.3 (c) show the BDDs of the two examples without just the frontier edges. In both the cases, the removal of the frontier edges removes every solution path p with the corresponding variable assignment. The idea of our minimal reason algorithm is to first find the frontier edges. Then, to find a subset of the frontier edges such that the inclusion of the variable assignments conflicting the subset in R will ensure that R ∧ b ⇒ (v := a) and R is minimal. In the Example 1, as in the Figure 4.2 (c), all the frontier edges conflict with just (x := true). Hence, the set R = {(x := true)} is such that R ∧ b ⇒ (y := true). In the Example 2, as in the Figure 4.3 (c), each assignment in X has a frontier edge. There is only one solution path with a frontier edge of (y := false). Also, in that path there is a conflicting edge of (w := true). Hence, the inclusion of (w := true) in R will make the frontier edge of (y := false) redundant. So, if (w := true) ∈ R then (y := false) need not belong to R. This results in a minimal reason R = {(v =: false), (w := true)}. The Figure 4.3 (d) shows the BDD b for the Example 2 after removal of the conflicting edges w.r.t. R = {(v := false), (w := true)}. It can be observed that all the solution paths with (x := true) are removed in the figure. Also, the set R is minimal, since for any R0 ( R, there exists a solution path p in the BDD b, with both R0 ∈ p and (x := true) ∈ p. The idea of our algorithm is hence to find the frontier edges first. Then to look at the frontier edges, in the order of their variables, and decide on the inclusion of a matching variable assignment in R if it is necessary to remove a solution path. The Figure 4.4 presents the MinimalReason procedure. The MinimalReason uses the FindFrontier procedure in Figure 4.5 to mark the nodes with an outgoing frontier edge. The assumptions made in presenting the procedures are: 1. The BDD b represents a function defined over the k Boolean variables in the set {b1 , b2 , . . . , bk }, using the variable order b1 < b2 < . . . < bk . We assume X ∧ b ⇒ (v := a) where v = bi for an i, 1 ≤ i ≤ k. 2. The visited, reach1, and frontier are three Boolean arrays, indexed by the nodes in the BDD b. The entries in the three arrays are initially false. 3. The reachedSet is an array of sets indexed by the variables in the BDD. The entries in the reachedSet array are initially empty sets.
76
CHAPTER 4. REASONING IN BDDS FOR NOGOODS 4. The set VX denotes the variables in X, i.e., VX := {bi | (bi := a0 ) ∈ X}.
The procedure FindFrontier visits all the nodes in the BDD b in a depth first manner and if an edge (n1 , n2 ) is a frontier edge, then sets the entry frontier[n1 ] to true. The procedure uses the visited array to make sure it visits a node only once. At the end of the procedure, the entry reach1[n] is true iff there exists a path from n to the 1-terminal without using a conflicting edge or an edge corresponding to (v := a). The lines 1-2 of the MinimalReason procedure appropriately initializes the reach1 and visited entries for the two terminal nodes and makes a call to FindFrontier. The lines 1-3 of the FindFrontier procedure ensure that a node is visited only once and the child nodes are processed first. In the case (var(n) = v) at line-4, based on the value of ’a’ the procedure appropriately sets reach1[n], ignoring the edge corresponding to (v := a). Since we are just interested in removing solution paths with (v := ¬a), we can ignore the edge corresponding to (v := a). In the case (var(n) ∈ / VX ) at line-9, the procedure sets the reach1[n] to true if any of the child nodes of n has true entry in reach1. The lines 12-13 correspond to the case where var(n) ∈ VX , in which an outgoing edge of the node n could be a frontier edge. Based on the value var(n) takes in X and the reach1 entries of the child nodes, the procedure decides whether frontier[n] is true or not. Note, the value frontier[n] becomes true if an outgoing edge of the node n is a frontier edge. At the end of the first recursive call made to FindFrontier at the line-2 of MinimalReason, all the nodes with an outgoing frontier edge are identified by the entries in the frontier array. At the line-3 of the MinimalReason procedure, the set reachedSet[var(b)] is assigned a set with just the root node. At the end of MinimalReason, if a node n belongs to the set reachedSet[var(n)], then it means the node n could be reached from the root node b without using any conflicting edge w.r.t R, where R is the output minimal reason. At the line-3 of the procedure, the set R is initialized to be empty and T is initialized to a set with both the terminal nodes. At the line-4, the procedure starts to loop over each variable in the BDD, in the variable order. During each loop, if any node n belongs to the reachedSet[var(n)] with (frontier[n] = true), then the procedure adds the assignment of var(n) in X to R and ignores the child node of n which can be reached by the frontier edge of n by not adding it to the reachedSet. In the case there was no frontier node in reachedSet[bi ], then the lines 18-20 adds both the child nodes of each n ∈ reachedSet[bi ] to the reachedSet if they are not terminal nodes. At the line-21, the procedure returns the obtained minimal reason R, such that R ∧ b ⇒ (v := a). Lemma 11 If (nf , nf +1 ) is a frontier edge, then the FindFrontier results in f rontier[nf ] = true. Proof 8 Let a solution path p for which (nf , nf +1 ) is a frontier edge be
4.4. A LINEAR-TIME ALGORITHM FOR MINIMAL BDD-REASON
77
MinimalReason (X, b, (v := a)) 1 : reach1[0] := false ; reach1[1] := true ; visited[0] := true ; visited[1] := true 2 : FindFrontier(b) 3 : reachedSet[var(b)] := {b} ; R = { } ; T := {0, 1} // T - terminal nodes 4 : for i := 1 to k // i.e., for each variable bi 5: foundFrontier := false 6: for each n ∈ reachedSet[bi ] 7: if (frontier[n]) foundFrontier := true 8: if (foundFrontier) 9: if ((bi := true) ∈ X) 10: R.Add((bi := true)) 11: for each n ∈ reachedSet[bi ] 12: if (solid(n) ∈ / T ) reachedSet[var(solid(n))].Add(solid(n)) 13: else // i.e., ((bi := false) ∈ X) 14: R.Add((bi := false)) 15: for each n ∈ reachedSet[bi ] 16: if (dashed(n) ∈ / T ) reachedSet[var(dashed(n))].Add(dashed(n)) 17: else // i.e., (foundFrontier = false) 18: for each n ∈ reachedSet[bi ] 19: if (solid(n) ∈ / T ) reachedSet[var(solid(n))].Add(solid(n)) 20: if (dashed(n) ∈ / T ) reachedSet[var(dashed(n))].Add(dashed(n)) 21: return R Figure 4.4: The MinimalReason Procedure. FindFrontier (n) 1 : visited[n] := true 2 : if (¬visited[solid(n)]) FindFrontier(solid(n)) 3 : if (¬visited[dashed(n)]) FindFrontier(dashed(n)) 4 : if (var(n) = v) 5: if (a) 6: if (reach1[dashed(n)]) reach1[n] := true 7: else // i.e., (a = false) 8: if (reach1[solid(n)]) reach1[n] := true 9 : else if (var(n) ∈ / VX ) 10: if (reach1[dashed(n)] ∨ reach1[solid(n)]) reach1[n] := true 11: else // i.e., var(n) ∈ VX 12: if((var(n) := true) ∈ X) 13: if (reach1[dashed(n)]) frontier[n] := true 14: if (reach1[solid(n)]) reach1[n] := true 15: else 16: if (reach1[solid(n)]) frontier[n] := true 17: if (reach1[dashed(n)]) reach1[n] := true Figure 4.5: The FindFrontier Procedure.
78
CHAPTER 4. REASONING IN BDDS FOR NOGOODS
p =< n1 , n2 , . . . , nf , nf +1 , . . . , nl >, where n1 = b and nl = 1. We know (v := ¬a) ∈ p. It can be observed that the FindFrontier procedure ensures that, for f < j ≤ l, reach1[nj ] = true. Since nl = 1, this trivially holds for nl , as initialized at the line-1 of the MinimalReason procedure. For f < j < l, the edge (nj , nj+1 ) is not a conflicting edge by frontier edge definition, also (nj , nj+1 ) does not correspond to the assignment (v := a) as (v := ¬a) ∈ p. Hence, for f < j < l, the FindFrontier procedure ensures that reach1[nj+1 ] ⇒ reach1[nj ]. Therefore, for f < j ≤ l, reach1[nj ] = true, which implies reach1[nf +1 ] = true. Since reach1[nf +1 ] = true during the call FindFrontier(nf ), the lines 12-17 of the procedure will ensure that frontier[nf ] = true. ¤ Theorem 12 If MinimalReason (X, b, (v := a)) returns R then R ∧ b ⇒ (v := a). Proof 9 We show that in any solution path p in the BDD b with (v := ¬a) ∈ p, there exists a conflicting edge w.r.t. R. Hence, for any solution S ∈ b, if (v := ¬a) ∈ S, then S ∈ / (R ∧ b), which proves the theorem. The proof is by contradiction. Suppose there exists a solution path p in the BDD b with (v := ¬a) ∈ p. Let p =< n1 , n2 , . . . , nf , nf +1 , . . . , nl >, where n1 = b, nl = 1 and (nf , nf +1 ) is the frontier edge. Lets assume the path does not use any conflicting edge w.r.t R. Then, we show that nf ∈ reachedSet[var(nf )] and hence the assignment of var(nf ) in X, which conflicts (nf , nf +1 ), belongs to R, which is a contradiction. Since by assumption the path p does not contain any conflicting edge w.r.t R, for any edge (ni , ni+1 ) in p, if the assignment corresponding to the edge is (var(ni ) := a0 ), then (var(ni ) := ¬a0 ) ∈ / R. Then for 1 ≤ i ≤ f , ni ∈ reachedSet[var(ni )]. This holds trivially for i = 1 as initialized at the line-3. For 1 ≤ i < f , since by assumption the edge (ni , ni + 1) is not a conflicting edge w.r.t R, the procedure would have added ni+1 to reachedSet[var(ni+1 )], irrespective of the value of the foundFrontier flag during the loop at the line-4 for var(ni ). Hence, nf ∈ reachedSet[var(nf )]. During the loop corresponding to var(nf ), at the line-4 of the MinimalReason procedure, since nf ∈ reachedSet[var(nf )] and by Lemma 11, frontier[nf ] = true, the foundFrontier flag will be true. Hence, the assignment to var(nf ) in X will be in R, with (nf , nf +1 ) being a conflicting edge w.r.t. R, which is a contradiction. ¤ Theorem 13 If MinimalReason (X, b, (v := a)) returns R then R is a minimal reason. Proof 10 Let (v 0 := a0 ) ∈ R. The MinimalReason includes (v 0 := a0 ) in R only if there exists a node n with frontier[n] = true, var(n) = v 0 and
4.5. RELATED WORK
79
n ∈ reachedSet[v 0 ]. Hence, by the frontier edge definition, an edge of the form (n, n0 ) is the only conflicting edge w.r.t R in a solution path p with (v := ¬a) ∈ p. Hence, the removal of (v 0 := a0 ) from R would imply R ∧ b ⇒ (v := a) is not true. Therefore, R is minimal. ¤ Theorem 14 The MinimalReason procedure takes time at most linear in |b|. Proof 11 The total amount of space used by all the used data-structures is at most linear in b. We can ignore the number of variables k when compared with |b|, as |b| could be exponential in k. After excluding time taken by the descendant calls, each call to the FindFrontier procedure takes constant time. Hence, the call FindFrontier(b) in total takes time at most linear in |b|. The running time of MinimalReason procedure, excluding the call to FindFrontier, is dominated by the loop at line-4. The loop iterates k times. Since a node n in the BDD b is added to reachedSet[var(n)] at most once during all the k iterations, the total time required for all the k loops is linear in b. Hence, the MinimalReason procedure takes time at most linear in |b| to find a minimal reason. ¤
4.5
Related Work
A method for finding minimal reasons in BDDs was presented in [44], which we call as the PADL06 method. The authors did not specify the worst case running time of the PADL06 method. But, the PADL06 method uses existential quantification operations on BDDs and hence quite costly when compared to our new linear-time method. If the BDD b is defined over the variables in Vb , the PADL06 method existentially quantifies the variables in (Vb \VX ) from the BDD b for finding a minimal reason. Note, the time and space complexity of each existential quantification operation in the worst case could even be quadratic [12] in |b|. Precisely, some of the advantages of our new method over the PADL06 [44] method are: 1. Worst case linear running time. 2. No costly BDD operations like existential quantifications. 3. No creation of new BDD nodes, the BDDs remain static during our solution process. Our new minimal reason method just uses the underlying directed acyclic graph of the BDDs, and hence does not require a full BDD package, while the PADL06 method requires a full BDD package.
80
CHAPTER 4. REASONING IN BDDS FOR NOGOODS
In [18], the authors did not give details of their method for generating minimal reasons in BDDs, even the complexity of their method was not mentioned.
4.6
Experiments
We have implemented our new minimal reason algorithm as part of a constraint solver with nogood learning. Our solver uses the BuDDy1 BDD package. Our solver just uses the lexicographic variable order. Given a CSP instance in the CLab [50] input format, we use the CLab tool to compile BDDs, one BDD for each constraint in the CSP. This will convert the input CSP instance into a list of Boolean variables and a set of BDDs defined over those variables. Our tool takes the set of BDDs as input and uses our constraint solver to find a solution. Our tool is designed after the BDD-based hybrid SAT solver in [18], which requires a method for MINIMAL BDD-REASON . We use the 34 CSPs modelling power supply restoration problem in our experiments. The instances are available online2 , in the CLab format. All the instances are satisfiable. We have also implemented the PADL06 [44] method in our tool for comparison. To study the scalability of the PADL06 method and our new method, for each input CSP, we create three types of instances in BDD format with increasing BDD sizes. The first type called Group-1 instance, as mentioned above, is obtained by building one BDD for each constraint in the CSP. The second type called Group-5 instance is obtained by first partitioning the constraints into d|C|/5e disjoint groups of constraints in the CSP. Each group will have at most five consecutive constraints, in lexicographic order. Then one BDD will be built to represent the conjunction of the constraints in each group. The third type called Group-10 instance is created similar to Group-5, but by using groups of size ten. Since the size of a BDD representing conjunction of five constraints will be usually larger than the sum of the sizes of five BDDs representing each one of the five constraints, the sizes of the BDDs in a Group-5 instance will usually be larger than those in the matching Group-1 instance. Hence, by using Group-1, Group-5 and Group-10 instances of an input CSP, we can study the scalability of the new method and the PADL06 method over increasing BDD sizes. All our experiments are done in a Cygwin environment with Intel Centrino 1.6 GHz processor and 1 GB RAM. The conversion of the 34 CSPs into Group-k types, for k ∈ {1, 5, 10}, resulted in 102 instances in BDD representation. To compare our new method 1 2
http://buddy.sourceforge.net/ http://www.itu.dk/research/cla/externals/clib
and-break-complex complex-P1 complex.10 complex.11 complex.12 complex
Name
|V | 414 299 414 414 414 414
|V 998 731 998 998 998 998
0|
|C| 852 592 849 849 849 849
Group-1 Max Total 755 38808 755 24055 631 33923 608 32937 724 37902 755 38804
BDD Size Group-5 Max Total 3540 110340 13523 77414 4271 89448 4371 89168 5443 108263 5823 112873 Group-10 Max Total 62735 459564 139048 356546 38901 262059 40235 276547 55494 349829 60903 381951
Group-1 PADL06 NEW ST, MRT ST, MRT 3.20, 1.03 2.94, 0.00 1.24, 0.76 1.14, 0.03 5.04, 1.48 4.44, 0.01 5.81, 1.54 5.14, 0.01 2.65, 1.21 2.14, 0.04 3.19, 1.08 2.94, 0.01
Group-5 PADL06 NEW ST, MRT ST, MRT 13.12, 7.49 7.40, 1.21 3.88, 2.27 2.98, 0.16 9.19, 5.27 5.55, 0.90 6.47, 3.86 3.95, 0.60 3.15, 2.43 2.07, 0.27 19.91, 9.94 12.29, 1.88
Group-10 PADL06 NEW ST, MRT ST, MRT 50.54, 41.02 14.62, 4.40 37.13, 21.52 18.17, 2.32 58.01, 45.10 15.96, 4.89 17.26, 12.81 6.73, 1.31 22.40, 18.10 6.96, 1.75 227.75, 189.04 41.77, 15.20
Table 4.2: Solution Time (ST) and Minimal Reason Time (MRT).
Name and-break-complex complex-P1 complex.10 complex.11 complex.12 complex
Instance
Table 4.1: Instance Characteristics. |V |: the number of variables in the input CSP. |V 0 |: the number of Boolean variables required to encode the original variables. |C|: the number of constraints. Max: the size of the largest BDD in the corresponding Group-k instance. Total: the sum of the sizes of all the BDDs in the corresponding Group-k instance.
4.6. EXPERIMENTS 81
82
CHAPTER 4. REASONING IN BDDS FOR NOGOODS
with the PADL06 method, we used our solver to find a solution for each one of the 104 instances, first using our new method and then using the PADL06 method. We repeated each experiment thrice and obtained the average values. For each instance, we noted the total time taken to find a solution, and the total time taken for the calls made to the corresponding minimal reason method. We used the gprof tool to measure the time taken by the minimal reason procedure calls. Since we do not have space to list the details for all the 34 instances, we picked five relatively large instances and present their characteristics in Table 4.1. The Table 4.2 presents the time taken for finding a solution and the total time taken for finding minimal reasons in both the type of experiments on the five instances. The Figure 4.6 and Figure 4.7 plots the solution time and minimal reason time for the both the minimal reason methods, for all the instances. The tables and figures show that the new method is at least as fast as the PADL06 method in all the used instances. The new method is even 10 times faster than the PADL06 method. Also, the new method scales better than the PADL06 method as the run-time difference between the new method and the PADL06 method widens from a Group-1 instance to the matching Group-10 instance. In the case of the complex Group-10 instance, the PADL06 method dominates the solution time taking 83% of the solution time, while the usage of the new method reduces the solution time to less than a fifth.
4.7
Conclusion
We have shown that the problem of finding a minimum reason for an implication by a BDD is NP-complete. We have also presented a linear-time algorithm for finding minimal reasons, which can be used to improve the nogood reasoning process in hybrid constraint solvers using BDDs. Our experiments shows that the new method for finding minimal reasons is better than the previous method for several instances and also scales well due to linear time complexity.
4.7. CONCLUSION
83
1000
100
PADL06
10
1
0.1 Group-1 Group-5 Group-10 x 0.01 0.01
0.1
1 NEW
10
100
Figure 4.6: Solution Time. 1000
100
PADL06
10
1
0.1
0.01 Group-1 Group-5 Group-10 x 0.001 0.001
0.01
0.1
1 NEW
Figure 4.7: Minimal Reason Time.
10
100
84
CHAPTER 4. REASONING IN BDDS FOR NOGOODS
Chapter 5
The NiVER SAT Preprocessor The original algorithm for the SAT problem, Variable Elimination Resolution (VER/DP) has exponential space complexity. To tackle that, the backtracking-based DPLL procedure [21] is used in SAT solvers. We present a combination of two techniques: we use NiVER, a special case of VER, to eliminate some variables in a preprocessing step, and then solve the simplified problem using a DPLL SAT solver. NiVER is a strictly formula size not increasing resolution based preprocessor. In the experiments, NiVER resulted in up to 74% decrease in N (Number of variables), 58% decrease in K (Number of clauses) and 46% decrease in L (Literal count). In many reallife instances, we observed that most of the resolvents for several variables are tautologies. Such variables are removed by NiVER. Hence, despite its simplicity, NiVER does result in easier instances. In case NiVER removable variables are not present, due to very low overhead, the cost of NiVER is insignificant. Empirical results using the state-of-the-art SAT solvers show the usefulness of NiVER. Some instances cannot be solved without NiVER preprocessing. NiVER consistently performs well and hence, can be incorporated into all general purpose SAT solvers.
This contents of this chapter has been published as the paper: S. Subbarayan, D. K. Pradhan, ”NiVER: Non-increasing Variable Elimination Resolution for Preprocessing SAT Instances”, SAT 2004 Conference, Vancouver, 2004, Revised Selected Papers, Springer LNCS 3542. pages 276291. 85
86
5.1
CHAPTER 5. THE NIVER SAT PREPROCESSOR
Introduction
The Variable Elimination Resolution (VER) [22] has serious problems due to exponential space complexity. So, modern SAT solvers are based on DPLL [21]. Preprocessors (simplifiers) can be used to simplify SAT instances. The simplified formula can then be solved by using a SAT Solver. Preprocessing is worthwhile only if the overall time taken for simplification as well as for solving the simplified formula is less than the time required to solve the original formula. This chapter introduces NiVER (Non-increasing VER), a new preprocessor based on VER. NiVER is a limited version of VER, which resolves away a variable only if there will be no resulting increase in space. For several instances, NiVER results in reducing the overall runtime. In many cases, NiVER takes less than one second CPU time. Because, NiVER consistently performs well, like clause learning and decision heuristics, NiVER can also be integrated into the DPLL framework for general purpose SAT solvers. The important contribution of this chapter is the observation that most of the real-life SAT instances have several NiVER removable variables, which can be resolved away without increase in space. The structure of the reallife instances are such that for several variables, most of the resolvents are tautologies. Hence, there will be no increase in space due to VER on them. Empirical results show that NiVER not only decreases the time taken to solve an instance, but also decreases the amount of memory needed to solve it. Some of the instances cannot be solved without NiVER preprocessing, because of more memory requirement. Importantly, empirical results also show that the benefit of NiVER preprocessing increases with the increase in the size of the problem. As the size of the problem instances increases, it is useful to have a NiVER preprocessor in general SAT solvers. Another advantage is its simplicity: NiVER can be implemented with the conventional data structures used for clause representation in modern SAT solvers. In fact, in our implementation we have used the data structures from the zChaff SAT solver [63]. Hence, there will not be a significant overhead in implementation of NiVER with SAT solvers. The next section presents a brief overview of previous SAT preprocessing techniques. Section 3 presents the NiVER preprocessor and gives some examples. Empirical results are presented in section 4. We conclude in section 5.
5.2
SAT Preprocessors
Simplifiers are used to change the formula into a simpler one, which is easier to solve. Pure literal elimination and unit propagation are the two best known simplification methods used in most of the DPLL based SAT
5.2. SAT PREPROCESSORS
87
solvers. Although several preprocessors have been published [8],[11], the current state-of-the-art SAT solvers [63],[36], just use these two simplifications. The 2-simplify preprocessor by Brafman [11], applies unit clause resolution, equivalent variable substitution, and a limited form of hyper-resolution. It also generates new implications using binary clause resolution. The recent preprocessor, HyPre [8] applies all the rules in 2-simplify and also does hyper-binary resolution. For some problems HyPre preprocessor itself solves the problem. But for other instances, it takes a lot of time to preprocess, while the original problem is easily solvable by SAT solvers. VER has already been used as a simplifier, but to a lesser extent. In [29], variables with two occurences are resolved away. For a class of random benchmarks, [29] has empirically shown that the procedure, in average case, results in polynomial time solutions. In 2clsVER [34], VER was used. They resolved away a variable rather than splitting on it, if the VER results in less than a 200 increase in L (Number of literals). It was done inside a DPLL method, not as a preprocessor. But that method was not successful when compared to the state-of-the-art DPLL algorithms. A variant of the NiVER method, which does not allow an increase in K, was used in [45] to obtain the current best worst-case upper bounds. The method in [45] was used not just as a preprocessor, but, at each node of a DPLL search. However, no implementation was found. Algorithm 1 NiVER CNF Preprocessor 1: NiVER(F ) 2: repeat 3: entry = F ALSE 4: for all V ∈ Var(F ) do 5: PC = {C | C ∈ F , lV ∈ C } 6: NC = {C | C ∈ F , lV ∈ C } 7: R={} 8: for all P ∈ PC do 9: for all N ∈ NC do 10: R = R ∪ Resolve(P ,N ) 11: end for 12: end for 13: Old Num Lits = Number of Literals in (PC ∪NC ) 14: New Num Lits = Number of Literals in R 15: if (Old Num Lits ≥ New Num Lits) then 16: F =F -(PC ∪NC ), F =F +R, entry = T RU E 17: end if 18: end for 19: until ¬entry 20: return F
88
5.3
CHAPTER 5. THE NIVER SAT PREPROCESSOR
NiVER: Non-increasing VER
Like other simplifiers, NiVER takes a CNF as input and outputs another CNF, with a lesser or equal number of variables. The VER, the original algorithm for SAT solving, has exponential space complexity, while that of DPLL is linear. Both have exponential time complexity. In NiVER, as we do not allow space increasing resolutions, we have linear space complexity. The strategy we use is to simplify the SAT instance as much as possible using NiVER, a linear-space version of VER. Then, the resulting problem is solved using a DPLL-based SAT solver. NiVER does not consider the number of occurrences of variables in the formula. In some instances, NiVER removes variables having more than 25 occurrences. For each variable, NiVER checks whether it can be removed by VER, without increasing L (Literal count). If so, it eliminates the variable by VER. The NiVER procedure is shown in Algorithm 1. When VER removes a variable, all resolvents of the variable have to be added. We discard trivial resolvents (tautologies). The rest of the resolvents are added to the formula. Then, all the clauses containing the variable are deleted from the formula. In many real-life instances (Figure 5.1 and Figure 5.2) we observed that for many variables, most of the resolvents are tautologies. So, there will be no increase in space when those variables are resolved away. Apart from checking for tautologies, NiVER does not do any complex steps like subsumption checking. No other simplification is done. The variables are checked in the sequence of their numbering in the original formula. There is not much difference due to different variable orders. Some variable removals may cause other variables to become removable. The NiVER iterates until no more variable can be removed. In the present implementation, NiVER does not even check whether any unit clause is present. Rarely, when a variable is removed, we observed an increase in K (Number of clauses), although, NiVER does not allow L to increase. Unlike HyPre or 2-simplify, NiVER does not do unit propagation, neither explicitly nor implicitly. The Figure 5.1 shows an example of variable elimination by NiVER, when applied to the barrel8 instance from Bounded Model Checking [9]. In this example, variable 24 has 10 resolvents. Among them, eight are tautologies, which can be discarded. Only the two remaining non-trivial resolvents are added. The seven old clauses containing a literal of variable 24 are deleted. The variable elimination decreases N (number of variables) by one, K (number of clauses) by 12, and L (literal count) by five. The Figure 5.2 shows another example of variable elimination by NiVER, when applied to the 6pipe instance from a microprocessor verification benchmark suite[72]. In this example, variable 44 has nine resolvents. Among them, five are tautologies, which can be discarded. Only the four remaining non-trivial resolvents are added. The six old clauses containing a literal of
5.3. NIVER: NON-INCREASING VER Clauses with literal l24 (l23 +l24 ) (l22 +l24 ) (l24 +l31 ) (l2 + l15 + l24 ) (l2 + l15 + l24 ) Old Num Lits = 22
89 Clauses with literal l24 (l22 +l23 +l24 +l2 +l15 ) (l22 + l23 + l24 + l2 + l15 )
Number of Clauses deleted = 7
Added Resolvents (l31 + l22 + l23 + l2 + l15 ) (l31 + l22 + l23 + l2 + l15 ) Eight other resolvents are tautologies New Num Lits = 10
Number of Clauses added = 2
Figure 5.1: NiVER Example 1: Elimination of Variable numbered 24 of barrel8 instance from Bounded Model Checking
variable 44 are deleted. The variable elimination decreases N by one, K by two, and L by two. Clauses with literal l44 (l44 + l6315 + l15605 ) (l44 + l6192 + l6315 ) (l44 + l3951 + l11794 ) Old Num Lits = 18 Added Resolvents (l6315 + l15605 + l3951 + l11794 ) (l6192 + l6315 + l3951 + l11794 ) (l3951 + l11794 + l6315 + l15605 ) (l3951 + l11794 + l6192 + l6315 ) New Num Lits = 16
Clauses with literal l44 (l44 + l6315 + l15605 ) (l44 + l6192 + l6315 ) (l44 + l3951 + l11794 ) Number of Clauses deleted = 6 Discarded Resolvents(Tautologies) (l6315 + l15605 + l6315 + l15605 ) (l6315 + l15605 + l6192 + l6315 ) (l6192 + l6315 + l6315 + l15605 ) (l6192 + l6315 + l6192 + l6315 ) (l3951 +l11794 +l3951 +l11794 ) Number of Clauses added = 4
Figure 5.2: NiVER Example 2: Elimination of Variable numbered 44 of 6pipe instance from Microprocessor Verification The Table 5.1 shows the effect of NiVER on a few instances from [46]. For the fifo8 400 instance, NiVER resulted in a 74% decrease in N , a 58% decrease in K and a 46% decrease in L. The benefit of these reductions is shown in the results section. In many of the real-life instances, NiVER decreases N , K and L. This might be a reason for the usefulness of NiVER on those instances. The NiVER preserves the satisfiability of the original problem. If the
CHAPTER 5. THE NIVER SAT PREPROCESSOR 90
Table 5.1: The effect of NiVER preprocessing. N-org, N-pre: N (Number of variables) in original and simplified formulas. %N↓ : The percentage of variables removed by NiVER. Corresponding information about clauses are listed in consecutive columns. %K↓ : The percentage decrease in K due to NiVER. %L↓ : The percentage decrease in L (Number of Literals) due to NiVER. The last column reports the CPU time taken by NiVER preprocessor in seconds. Some good entries are in bold. A machine with AthlonXP1900+ processor and 1GB memory was used in the experiments. Benchmark N-org N-pre %N↓ K-org K-pre %K↓ L-org L-pre %L↓ Time 6pipe 15800 15067 5 394739 393239 0.4 1157225 1154868 0.2 0.5 f2clk 40 27568 10408 62 80439 44302 45 234655 157761 32.8 1.3 ip50 66131 34393 48 214786 148477 31 512828 398319 22.3 5.2 fifo8 400 259762 68790 74 707913 300842 58 1601865 858776 46.4 14.3 comb2 31933 20238 37 112462 89100 21 274030 230537 15.9 1 cache 10 227210 129786 43 879754 605614 31 2191576 1679937 23.3 20.1 longmult15 7807 3629 54 24351 16057 34 58557 45899 21.6 0.2 barrel9 8903 4124 54 36606 20973 43 102370 66244 35.2 0.4 ibm-rule20 k45 90542 46231 49 373125 281252 25 939748 832479 11.4 4.5 ibm-rule03 k80 88641 55997 37 375087 307728 18 971866 887363 8.7 3.6 w08 14 120367 69151 43 425316 323935 24 1038230 859105 17.3 5.45 abp1-1-k31 14809 8183 45 48483 34118 30 123522 97635 21.0 0.44 guidance-1-k56 98746 45111 54 307346 193087 37 757661 553250 27.0 2.74
5.4. EXPERIMENTAL RESULTS
91
simplified problem is unsatisfiable, then the original is also unsatisfiable. If the simplified problem is satisfiable, the assignment for the variables in the simplified formula is a subset of at least one of the satisfying assignments of the original problem. For variables removed by NiVER, the satisfying assignment can be obtained by a well-known polynomial procedure, in which the way NiVER proceeds is simply reversed. The variables are added back in the reverse order in which they were eliminated. While adding each variable, assignment is made to that variable such that the formula is satisfied. For example, let F be the original formula. Let Cx refer to a set of clauses containing literals of variable x. Let Cxr represent the set of clauses obtained by resolving clauses in Cx on variable x. Let NiVER first eliminates variable a from F , by removing Ca from F and adding Car to F , resulting in the new formula Fa . Then let NiVER eliminates variable b by deleting Cb from Fa and adding Cbr to Fa , resulting in Fab . Similarly, eliminating c results in Fabc . Now NiVER terminates and let a SAT solver finds a satisfying assignment, Aabc , for Fabc . Aabc will contain satisfying values for all variables in Fabc . Now, add variables in the reverse order they were deleted. First, add Cc to Fabc , resulting in Fab . Assign to c either the value one (true) or the value zero (false), such that Fab is satisfied. At least one among those assignments will satisfy Fab . Similarly, add Cb and find a value for b and then for a. During preprocessing, just the set of clauses, Ca , Cb and Cc , should be stored, so that a satisfying assignment can be obtained if the DPLL SAT solver finds a satisfying assignment for the simplified theory.
5.4
Experimental Results
This section contains two subsections. The subsection 5.4 presents the effect of the NiVER Preprocessor on two state-of-the-art SAT solvers: Berkmin and Siege. As the two SAT solvers have different decision strategies, the effect of NiVER on them can be studied. The other subsection presents the effect of NiVER on time and memory requirement for solving large instances from four families. The time listed for NiVER preprocessing in the tables are just the time taken for preprocessing the instance. At present, as NiVER is a separate tool, and, if the instance is very large, it might take few additional seconds to read the file and write back into the disk. But, as the data structures used in NiVER implementation are those used in modern SAT solvers to represent clauses, the time taken for reading and writing back can be avoided when integrated with the SAT solver.
Effect of NiVER on SAT-solvers: BerkMin and Siege The SAT benchmarks used in this subsection are from [46], [1] and [3]. The benchmarks used in [8] are mostly used. The NiVER software is available at [2]. Experiments were done with, Berkmin [36], a complete deterministic
92
CHAPTER 5. THE NIVER SAT PREPROCESSOR
Table 5.2: Results with Berkmin (Ber) SAT solver. CPU Time (seconds) for four types of experiments, along with class type (Cls) for each benchmark. An underlined entry in the second column indicates that NiVER+Berkmin results in better runtime than just using the solver. SpdUp column lists the speedup due to NiVER+Berkmin over Berkmin. A machine with AthlonXP1900+ processor and 1GB memory was used in the experiments. BenchMark 6pipe 6pipe 6 ooo 7pipe 9vliw bp mc comb2 comb3 fifo8 300 fifo8 400 ip38 ip50 barrel9 barrel8 ibm-rule20 k30 ibm-rule20 k35 ibm-rule20 k45 ibm-rule03 k70 ibm-rule03 k75 ibm-rule03 k80 abp1-1-k31 abp4-1-k31 avg-checker-5-34 guidance-1-k56 w08 14 ooo.tag14.ucl cache.inv14.ucl cache 05 cache 10 f2clk 30 f2clk 40 longmult15 longmult12 cnt10
Berkmin 210 276 729 90 305 817 16822 42345 256 341 106 368 475 1064 5806 21470 30674 31206 1546 1640 1361 90755 3657 18 36 3430 22504 100 2014 183 283 4170
Berkmin with NiVER NiVER +HyPre HyPre 222 392 395 253 738 771 734 1165 1295 100 1010 1031 240 271 302 407 337 368 13706 244 440 1290 667 760 99 52 105 313 87 224 39 34 114 34 10 38 554 116 305 1527 310 478 8423 757 1611 9438 399 637 29986 898 936 58893 1833 1343 3282 1066 766 949 1056 610 1099 595 919 17736 14970 22210 4379 1381 1931 8 399 1703 7 396 2502 1390 2845 3529 55290 12449 15212 61 29 53 1848 1506 737 160 128 54 233 180 39 2799 193 134
Cls
(UN)SAT
I I I I II II II II II II II II II II II II II II IV IV II III III III III III III IV IV IV IV IV
UNSAT UNSAT UNSAT UNSAT UNSAT UNSAT UNSAT UNSAT UNSAT UNSAT UNSAT UNSAT UNSAT UNSAT SAT SAT SAT SAT UNSAT UNSAT UNSAT UNSAT SAT UNSAT UNSAT SAT SAT UNSAT UNSAT UNSAT UNSAT SAT
SpdUp 0.95 1.09 0.99 0.90 1.27 2 1.23 32.82 2.59 1.09 2.71 10.82 0.86 0.70 0.69 2.28 1.02 0.53 0.47 1.72 1.24 5.17 0.84 2.25 5.14 2.47 0.41 1.64 1.09 1.14 1.21 1.49
5.4. EXPERIMENTAL RESULTS
93
Table 5.3: Results with Siege (Sie) SAT solver. A machine with AthlonXP1900+ processor and 1GB memory was used in the experiments. BenchMark 6 pipe 6pipe 6 ooo 7pipe 9vliw bp mc comb2 comb3 fifo8 300 fifo8 400 ip38 ip50 barrel9 barrel8 ibm-rule20 k30 ibm-rule20 k35 ibm-rule20 k45 ibm-rule03 k70 ibm-rule03 k75 ibm-rule03 k80 abp1-1-k31 abp4-1-k31 avg-checker-5-34 guidance-1-k56 w08 14 ooo.tag14.ucl cache.inv14.ucl cache 05 cache 10 f2clk 30 f2clk 40 longmult15 longmult12 cnt10
Siege 79 187 185 52 407 550 519 882 146 405 59 173 216 294 1537 369 757 946 559 455 619 9972 1251 15 39 238 1373 70 891 325 471 236
NiVER 70 156 177 46 266 419 310 657 117 258 12 25 131 352 1422 360 492 781 471 489 621 8678 901 6 13 124 669 48 988 198 256 139
Siege with NiVER +HyPre 360 743 1095 975 257 396 229 404 85 131 16 6 112 267 1308 223 502 653 281 303 548 6887 1365 396 396 2805 10130 53 802 169 292 193
HyPre 361 800 1183 1014 287 366 281 920 115 234 54 16 315 482 827 516 533 883 429 346 690 20478 1931 1703 2503 3540 13053 41 519 54 72 134
Cls
(UN)SAT
I I I I II II II II II II II II II II II II II II II II II II III III III III III IV IV IV IV IV
UNSAT UNSAT UNSAT UNSAT UNSAT UNSAT UNSAT UNSAT UNSAT UNSAT UNSAT UNSAT UNSAT UNSAT SAT SAT SAT SAT UNSAT UNSAT UNSAT UNSAT SAT UNSAT UNSAT SAT SAT UNSAT UNSAT UNSAT UNSAT SAT
SpdUp 1.13 1.20 1.05 1.14 1.53 1.31 1.68 1.34 1.25 1.57 4.92 6.92 1.65 0.84 1.08 1.03 1.54 1.21 1.19 0.93 1 1.15 1.39 2.5 3 1.92 2.05 1.46 0.90 1.64 1.84 1.70
SAT solver and Siege(v 4) [67] , a complete randomized SAT Solver. The two SAT solvers have different decision strategies and hence the effect of NiVER on them can be studied. In Table 5.2 runtimes in CPU seconds for experiments using Berkmin are shown. In Table 5.3 corresponding runtimes using Siege are tabulated. All experiments using Siege were done with 100 as the random seed parameter. For every benchmark, four types of experiments were done with each solver. The first type is just using the solvers to solve the instance. The second one is using the NiVER preprocessor and solving the simplified theory by the SAT solvers. The third type of experiments involves two preprocessors. First the benchmark is simplified by NiVER and then by HyPre. The output of HyPre is then solved using the SAT solvers. A fourth type of experiment uses just HyPre simplifier and the SAT-solvers. When preprocessor(s) are used, the reported runtimes are the overall time taken to find satisfiability.
94
CHAPTER 5. THE NIVER SAT PREPROCESSOR
Based on the experimental results in these two tables of this subsection, we classify the SAT instances into four classes. Class-I: Instances for which preprocessing results in no significant improvement. Class-II: Instances for which NiVER+HyPre preprocessing results in best runtimes. Class-III: Instances for which NiVER preprocessing results in best runtimes. Class-IV: Instances for which HyPre preprocessing results in best runtimes. The sixth column in the tables lists the class to which each problem belongs. When using SAT solvers to solve problems from a particular domain, samples from the domain can be used to classify them into one of the four classes. After classification, the corresponding type of framework can be used to get better run times. In case of Class-I problems, NiVER results are almost same as the pure SAT solver results. But HyPre takes a lot of time for preprocessing some of the Class-I problems like pipe instances. There are several Class-I problems not listed in tables here, for which neither NiVER nor HyPre results in any simplification, and hence no significant overhead. In case of Class-II problems, NiVER removes many variables and results in a simplified theory FN . HyPre further simplifies FN and results in FN +H which is easier for SAT solvers. When HyPre is alone used for Class-II problems, they simplify well, but the simplification process takes more time than for simplifying corresponding FN . NiVER removes many variables and results in FN . But the cost of reducing the same variables by comparatively complex procedures in HyPre is very high. Hence, for Class-II, with few exceptions, HyPre+Solver column values are more than the values in NiVER+HyPre+Solver column. For Class-III problems, HyPre takes a lot of time to preprocess instances, which increases the total time taken to solve by many magnitudes than the normal solving time. In case of cache.inv14.ucl [3], NiVER+Siege takes 13 seconds to solve, while HyPre+Siege takes 2503 seconds. The performance of HyPre is similar to that on other benchmarks generated by an infinite state systems verification tool [3]. Those benchmarks are trivial for DPLL SAT Solvers. The Class-IV problems are very special cases in which HyPre outperform others. When NiVER is applied to these problems, it destroys the structure of binary clauses in the formula. HyPre which relies on hyper binary resolution does not perform well on the formula simplified by NiVER. In case of longmult15 and cnt10, the HyPre preprocessor itself solves the problem. When just the first two types of experiments are considered, NiVER performs better in almost all of the instances.
Effect of NiVER on Time and Memory Usage by Siege SAT Solver In this subsection the effect of the NiVER preprocessor on four families of large SAT instances are presented. As the results in the previous subsection show, Siege SAT solver is better than Berkmin. As we are primarily inter-
5.4. EXPERIMENTAL RESULTS
95
ested in studying the effect of NiVER on memory and time requirements of SAT solvers, all the results in this section are done using the Siege SAT solver, alone. Again, the random seed parameter for the Siege SAT solver was fixed at 100. Table 5.4: Results for x-x-barrel family. Experiments were done on an Intel Xeon 2.8 GHz machine with 2 GB of memory. SF : Segmentation fault by HyPre preprocessor. Benchmark
N
%N↓
8-8-barrel 9-9-barrel 10-10-barrel 11-11-barrel 12-12-barrel 13-13-barrel 14-14-barrel
5106 8903 11982 15699 20114 25287 31278
56 53 54 54 55 55 55
NiVER Time (sec) 0.2 0.4 1 1 2 3 5
Siege 86 29 45 77 580 429 1307
Time (sec) NiVER HyPre +Siege +Siege 14 9 7 25 10 65 12 SF 73 SF 42 SF 96 SF
Memory (MB) NiVER HyPre Siege +Siege +Siege 59 26 13 20 8 41 31 12 63 52 14 SF 147 50 SF 120 34 SF 208 70 SF
1400 Siege NIVER+Siege HyPre+Siege
Time (sec)
1200 1000 800 600 400 200 0
8
9
10
11
12
13
14
x-x-barrel Instance
Figure 5.3: Time comparison for the x-x-barrel family 250 Siege NiVER+Siege HyPre+Siege
Memory (MB)
200
150
100
50
0 8
9
10
11
12
13
14
x-x-barrel Instance
Figure 5.4: Memory usage comparison for the x-x-barrel family
96
CHAPTER 5. THE NIVER SAT PREPROCESSOR
In the tables in this subsection: NiVER Time (sec) refers to the CPUtime in seconds taken by NiVER to preprocess the benchmark. Time (sec)Siege refers to the CPU-time in seconds taken by Siege to solve the original benchmark. Time (sec)-NiVER+Siege refers to the sum of the time taken for NiVER preprocessing and the time taken for solving the NiVERpreprocessed instance by Siege. Time (sec)-HyPre+Siege refers to the sum of the time taken for HyPre preprocessing and the time taken for solving the HyPre-preprocessed instance by Siege. The other three columns list the amount of memory, in MegaBytes (MB), used by Siege SAT solver to solve the original and the corresponding preprocessed instances. MA-S means memory-abort by Siege SAT solver. MA-H means memory-abort by HyPre preprocessor. SF mentions segmentation fault by HyPre preprocessor. The x-x-barrel family of instances are generated using the tools, BM C and genbarrel, available at [9]. The BM C tool, bounded model checker, takes as input: a model and a parameter, k, the bound for which the model should be verified. It then creates a SAT formula, whose unsatisfiability implies the verification of a property for the specified bound. The genbarrel tool takes an integer parameter and generates a model of the corresponding size. The x-x-barrel instances are generated using the command: genbarrel x | bmc -dimacs -k x > x-x-barrel.cnf The results for the x-x-barrel family are listed in Table 5.4. Three types of experiments are done. One just using the plain Siege SAT solver. Second one using the NiVER preprocessor. Third one using the HyPre preprocessor. The corresponding time and memory usage are listed. The Figure 5.3 shows the graph obtained when the time usage for x-x-barrel instances are plotted. The Figure 5.4 shows the graph obtained when the memory usage for x-x-barrel instances are plotted. The HyPre preprocessor was not able to handle instances larger than the 10-10-barrel, and aborted with a segmentation fault error message. Although the Siege SAT solver was able to solve all the original x-x-barrel instances, it used more time and space, than those for the corresponding NiVER simplified instances. As the Figure 5.3 shows, with the increase in the size of the instance, the benefit of NiVER preprocessing increases. For example, the speed-up due to NiVER in case of 8-8-barrel instance is 6.1 (Table5.3), while it is 13.6 in case of 14-14barrel instance. Similar trend is also observed in the graph (Figure 5.4) for memory usage comparison. More than half of the variables in x-x-barrel instances are resolved away by NiVER preprocessor. In several other bounded model checking SAT instances, we observed similar amount of decrease in the number of variables due to NiVER preprocessing. For example, the longmult15 instance and w08 14 instance in Table 5.1 are both generated for bounded model checking. In both cases, approximately half of the variables are removed by NiVER. In all the x-x-barrel instances, the time taken for NiVER preprocessing is very small, and insignificant, when compared with
5.4. EXPERIMENTAL RESULTS
97
the original solution time. Table 5.5: Results for the xpipe k family. Experiments were done on an Intel Xeon 2.8 GHz machine with 2 GB of memory. MA-S : Memory Abort by Siege SAT solver. MA-H : Memory Abort by HyPre preprocessor. Benchmark 7pipe k 8pipe k 9pipe k 10pipe k 11pipe k 12pipe k 13pipe k 14pipe k
N
%N↓
23909 35065 49112 67300 89315 115915 147626 184980
4 5 3 5 5 5 5 5
NiVER Time (sec) 1 1 1 2 2 3 4 5
Siege 64 144 109 565 1183 3325 5276 MA-S
Time (sec) NiVER +Siege 69 127 106 544 915 2170 3639 8559
HyPre +Siege 361 947 4709 5695 MA-H MA-H MA-H MA-H
Siege 93 152 121 308 443 670 842 MA-S
Memory (MB) NiVER HyPre +Siege +Siege 94 61 115 87 123 121 212 196 296 MA-H 418 MA-H 579 MA-H 730 MA-H
14000
Time (sec)
12000
Siege NiVER+Siege HyPre+Siege
10000 8000 6000 4000 2000 0 8
9
10
11
12
13
14
15
xpipe_k Instance
Figure 5.5: Time comparison for the xpipe k family 2500 Siege NiVER+Siege HyPre+Siege
Memory (MB)
2000 1500 1000 500 0 8
9
10
11
12
13
14
15
xpipe_k Instance
Figure 5.6: Memory usage comparison for the xpipe k family
The other three families of large SAT instances: xpipe k, xpipe q0 k, and, xpipe xooo q0 T0, are all obtained from the Microprocessor Verification
98
CHAPTER 5. THE NIVER SAT PREPROCESSOR
benchmark suite at [72]. The results obtained from experiments on xpipe k, xpipe q0 k, and, xpipe xooo q0 T0 families are listed in Tables 5.5, 5.6, and 5.7, respectively. Figures for corresponding time and memory comparison follow them. In the case of the xpipe k family, without using the NiVER preprocessor, all the instances cannot be solved. Memory values listed in the tables just show the amount of memory used by the Siege SAT solver. Even when preprocessors are used, the memory values listed are just those used by Siege for solving the corresponding preprocessed instance. The amount of memory used by preprocessors is not listed. The aborts (MA-H ) in the HyPre column of Table 5.5 are due to HyPre. In a machine with 2GB of memory, the HyPre preprocessor was not able to handle instances larger than 10pipe k. Even for the instances smaller than 10pipe k, HyPre took a lot of time. In case of 9pipe k, HyPre took 47 times the time taken by Siege. Siege SAT solver was not able to handle the 14pipe k instance. It aborted due to insufficient memory. But after NiVER preprocessing the 14pipe k instance was solved by Siege using the same machine. While solving NiVER preprocessed instance, Siege consumed only one third (730MB) of the available 2GB. As the results in Table 5.5 and the corresponding time comparison graph (Figure 5.5) shows, the speed-up due to NiVER keeps increasing with the increase in size of the instance. It is also interesting to note that in case of 14pipe k instance, only 5% of the variables are removed by NiVER. But still it resulted in solving the instance by using just 730MB of memory. As shown in Figure 5.6, the memory usage ratio, between the original instance and the corresponding NiVER preprocessed instance, also increases with the increase in the instance size. Table 5.6: Results for the xpipe q0 k family. Experiments were done on an Intel Xeon 2.8 GHz machine with 2 GB of memory. MA-H : Memory Abort by HyPre preprocessor. Benchmark 8pipe q0 k 9pipe q0 k 10pipe q0 k 11pipe q0 k 12pipe q0 k 13pipe q0 k 14pipe q0 k 15pipe q0 k
N 39434 55996 77639 104244 136800 176066 222845 277976
%N↓ 27 28 29 31 32 33 34 35
NiVER Time (sec) 1 2 2 3 4 5 7 10
Siege 90 71 295 520 1060 1656 2797 5653
Time (sec) NiVER +Siege 68 61 280 478 873 1472 3751 4165
HyPre +Siege 304 1337 1116 1913 3368 5747 MA-H MA-H
Siege 81 77 170 233 351 481 616 826
Memory (MB) NiVER HyPre +Siege +Siege 62 56 66 76 120 117 164 154 227 225 295 315 412 MA-H 494 MA-H
In the case of the xpipe q0 k family, again HyPre was not able to handle all the instances. As in the other cases, the benefit of NiVER preprocessing increases with the increase in the size of the instances. This is shown by the graphs in Figures 5.7 and 5.8. For the 15pipe q0 k instance, NiVER resulted in decreasing the memory usage by 40%. Even in time usage, there
5.4. EXPERIMENTAL RESULTS
99
7000 Siege NiVER+Siege HyPre+Siege
Time (sec)
6000 5000 4000 3000 2000 1000 0 8
9
10
11
12
13
14
15
xpipe_q0_k
Figure 5.7: Time comparison for the xpipe q0 kfamily 2500
Memory (MB)
2000
Siege NiVER+Siege HyPre+Siege
1500 1000 500 0 8
9
10
11
12
13
14
15
xpipe_q0_k Instance
Figure 5.8: Memory usage comparison for the xpipe q0 k family
is a significant improvement. In the case of the xpipe x ooo q0 T0 family (Table 5.7), both NiVER and HyPre preprocessors give similar improvement over the original instance. But still the advantages of NiVER over HyPre are its simplicity, and usefulness in a wide range of real-life instances. Table 5.7: Results for the xpipe x ooo q0 T 0 family. Experiments were done on an Intel Xeon 2.8 GHz machine with 2 GB of memory. In this table an entry x in the Benchmark column refers to an xpipe x ooo q0 T 0 instance. Benchmark 7 8 9 10 11 12
N 27846 41491 59024 81932 110150 144721
%N↓ 24 25 25 27 28 29
NiVER Time (sec) 1 1 1 2 2 3
Siege 97 252 415 2123 9917 56748
Time (sec) NiVER HyPre +Siege +Siege 87 229 226 605 359 1524 2391 3190 8007 8313 30392 27071
Siege 60 100 135 215 317 448
Memory (MB) NiVER HyPre +Siege +Siege 60 45 85 77 119 113 172 171 240 234 330 342
100
CHAPTER 5. THE NIVER SAT PREPROCESSOR 60000 Siege NiVER+Siege HyPre+Siege
Time (sec)
50000 40000 30000 20000 10000 0
7
8
9
10
11
12
xpipe_x_ooo_q0_T0 Instance
Memory (MB)
Figure 5.9: Time comparison for the xpipe x ooo q0 T 0 family 500 450 400 350 300 250 200 150 100 50 0
Siege NiVER+Siege HyPre+Siege
7
8
9
10
11
12
xpipe_x_ooo_q0_T0 Instance
Figure 5.10: Memory usage comparison for the xpipe x ooo q0 T 0 family
5.5
Conclusion
We have shown that a special case of VER, NiVER, is an efficient simplifier. Although several simplifiers have been proposed, the state-of-the-art SAT-solvers do not use simplification steps other than unit propogation and pure literal elimination. We believe that efficient simplifiers will improve SAT-solvers. NiVER does the VER space efficiently by not allowing space increasing resolutions. Otherwise, the advantage of VER would be annulled by the associated space explosion. Empirical results have shown that NiVER results in improvement in most of the cases. NiVER+Berkmin outperforms Berkmin in 22 out of 32 cases (Table 5.2) and yields up to 33x speedup. In the other cases, mostly the difference is negligible. NiVER+Siege outperforms Siege in 29 out of 32 cases (Table 5.3) and gives up to 7x speedup. In the three other cases, the difference is negligible. Although, NiVER results in easier problems when some variables are removed by it, the poor performance of SAT solvers on few NiVER simplified instances is due to
5.5. CONCLUSION
101
the decision heuristics. Experiments on four families of large SAT instances show that, the usefulness of NiVER increases with the increase in size of the problem size. NiVER also decreases the memory usage by SAT solvers. Due to that, more instances can be solved with the same machine configuration. The NiVER simplifier performs well, as most of the best runtimes in the experiments are obtained using it. Due to its usefulness and simplicity, like decision heuristics and clause learning, NiVER can also be incorporated into all general purpose DPLL SAT solvers.
102
CHAPTER 5. THE NIVER SAT PREPROCESSOR
Chapter 6
Backtracking Procedures for Hypertree, HyperSpread and Connected Hypertree Decomposition of CSPs Hypertree decomposition has been shown to be the most general CSP decomposition method. However, so far the exact methods are not able to find optimal hypertree decompositions of realistic instances. We present a backtracking procedure which, along with isomorphic component detection, results in optimal hypertree decompositions. We also make the procedure generic; variations of which results in two new tractable decompositions: hyperspread and connected hypertree. We show that the hyperspread width is bounded by both the hypertree width and the spread cut width, which solves a recently stated open problem. In our experiments on several realistic instances, our methods find many optimal decompositions, while the previous methods can find at most one.
This contents of this chapter has been published as the paper: S. Subbarayan, H. R. Andersen, ”Backtracking Procedures for Hypertree, HyperSpread and Connected Hypertree Decomposition of CSPs”, IJCAI Conference, Hyderabad, 2007. pages 180-185.
103
104 CHAPTER 6. HYPERTREE, HYPERSPREAD & CONNECTED ...
6.1
Introduction
A CSP decomposition method DM is tractable if, for a fixed k, determining whether the DM-width of a CSP instance is at most k takes polynomial time and all the CSP instances having DM-width at most k can be solved in polynomial time. A method DM1 is more general than another method DM2 if all the CSP instance classes having bounded DM2 -width also have bounded DM1 -width but not vice-versa. Likewise, DM1 is better than DM2 if the DM1 -width of any instance is at most its DM2 -width, and for an instance its DM1 -width is smaller than its DM2 -width. Among several tractable decomposition methods [30, 24, 40, 38], the hypertree decomposition has been shown to be the most general [38]. But no exact procedure for hypertree decomposition has been able to handle instances of realistic sizes. This is mainly due to huge preprocessing in the existing exact methods [37, 43]. We first present a backtracking procedure for hypertree decomposition. We identify isomorphic components of a hypergraph, and use it to speed-up the procedure. We generalize the procedure, the variations of which results in two new tractable decomposition methods: HyperSpread and Connected Hypertree. Finding a tractable decomposition better than hypertree decomposition has been recently stated as an open problem [4]. We show that hyperspread width is bounded by both hypertree width and spread cut width, which gives a simple positive answer to the open problem. In the experiments on several instances our hypertree and connected hypertree decomposition methods result in finding optimal decompositions of many instances, while the previous methods can find optimal decompositions of at most one instance. In our experiments with a given time limit, for all the instances we are able to obtain a connected hypertree decomposition of width at least as small as the obtained hypertree decomposition. We finally state as an open problem whether the connected hypertree width of an instance equals the hypertree width. The next section lists necessary definitions. The Section 6.3 presents the backtracking procedure and defines isomorphic components. The generic procedure and its variants are presented in the Section 6.4. The Section 6.5 presents the experimental results. The Section 6.6 concludes the chapter.
6.2
Definitions
A constraint satisfaction problem instance (CSP) is a triple (V ,D,C), where V is a set of variables, D is a set of domains and C is a set of constraints. A variable vi ∈ V can take values in the finite domain di ∈ D. A constraint ci ∈ C is a pair (si ,ri ), where si ⊆ V is the scope of the constraint and ri is a relation over si . The ri restricts the allowed combination of values the variables in si can be assigned. A solution to a CSP is an assignment of
6.2. DEFINITIONS
105
values to all the variables in the CSP, such that the assignment restricted to a scope si belongs to the relation ri . A CSP is satisfiable if there is a solution for the CSP. A constraint hypergraph of a CSP (V ,D,C) is a hypergraph H = (V ,E), where the set of nodes in the hypergraph V is the same as the set of variables in the CSP. For each (si ,ri ) ∈ C, there will be an edge (also called a hyperedge) ei ∈ E, such that ei = si , i.e., E = {si | (si , ri ) ∈ C}. Hereafter, just the term hypergraph refers to a constraint hypergraph. For a set S of edges K ⊆ E, let the term vars(K) = e∈K e, i.e., the union of variables occurring in the edges K. For a set of variables L ⊆ V , let the term edgeVars(L) = vars({e | e ∈ E, e ∩ L 6= ∅}), i.e., all the variables occurring in a set of edges, where each edge in the set contains at least one variable in L. A tree decomposition [66, 24] of a hypergraph (V ,E) is a pair TD = (T ,γ), where T = (N ,A) is a tree and γ is a mapping which for each node n ∈ N associates γ(n) ⊆ V . Additionally, a tree decomposition has to satisfy two properties: (1) ∀e ∈ E. ∃n ∈ N. e ⊆ γ(n), and (2) ∀v ∈ V , the nodes {n | n ∈ N, v ∈ γ(n)} induces a connected subtree in T . A hypertree [38] of a hypergraph (V ,E) is a triple (T ,χ,λ), where T = (N ,A) is a rooted tree. The χ and λ are mappings that associate for each node n ∈ NS , χ(n) ⊆ V and λ(n) ⊆ E. If T 0 = (N 0 , A0 ) is a subtree of T , then χ(T 0 ) = n∈N 0 χ(n). Let the term Tn denote the subtree rooted at the node n ∈ N . Let the term nodes(T ) = N . The width of the hypertree (T ,χ,λ) is max {|λ(n)| | n ∈ nodes(T )}. A hypertree decomposition [38] of a hypergraph H is a hypertree HD = (T, χ, λ), which has to satisfy the three properties: (1) (T ,χ) is a tree decomposition of H, (2) ∀n ∈ nodes(T ), χ(n) ⊆ vars(λ(n)), and (3) ∀n ∈ nodes(T ), χ(Tn ) ∩ vars(λ(n)) ⊆ χ(n). The hypertree width of H, denoted htw (H), is the minimum width of all possible hypertree decompositions of H. To simplify the presentation, we assume that H is connected. Given a set of variables P ⊆ V , and two variables m, n ∈ V , the variables m and n are [P]-adjacent if ∃e ∈ E. m, n ∈ (e\P ). A set of variables Q ⊆ V is [P]connected, if for any two variables m, n ∈ Q, there is a sequence of variables m = l1 , l2 , . . . , lr−1 , lr = n, such that, for each i ∈ [1, r − 1], li and li+1 are [P ]-adjacent. A set of variables Q ⊆ V is a [P]-component (or [P]-comp in short), if it is a maximal [P ]-connected subset of V . Let [P]-components (or [P]-comps in short) denote the set containing every [P]-component. Given an integer k and α ⊆ E, α is a k-edge, if |α| ≤ k. Let the set k-edges = {α | α ⊆ E, |α| ≤ k}, i.e, the set containing every k-edge. Given a k-edge α, an α-comp is a [vars(α)]-comp. The size of α-comps, which contains every α-comp, is at most |E|, as for every α-comp edgeVars(αcomp) will uniquely contain at least one edge e ∈ E. Given a set of variables Q ⊆ V , the sub-hypergraph induced by Q is the hypergraph (V 0 ,E 0 ), where V 0 = Q and E 0 = {e ∩ Q | e ∈ E}. Let a pair of the form (α,α-comp), where
106 CHAPTER 6. HYPERTREE, HYPERSPREAD & CONNECTED ... α is a k-edge, be called a k-edge-component.
6.3
The Backtracking Procedure
Our procedure is shown in Figure 6.1. The main procedure IsDecomposable takes the pair ((V ,E), k) as input. The output is a hypertree decomposition if htw ((V ,E)) ≤ k, otherwise the message ’Not-k-decomposable’. Given a k-edge-component (α,α-comp), we say the pair (α,α-comp) is k-decomposable iff the sub-hypergraph induced by the nodes in edgeVars(αcomp) has a hypertree decomposition HD’ of width at most k, such that, if the root node of HD’ is r, then edgeVars(α-comp) \ α-comp ⊆ χ(r). Essentially, the notion k-decomposable tells us whether the sub-hypergraph can be decomposed into a HD’ of width at most k, such that HD’ can be used as a block in building a decomposition for the whole hypergraph. Hence, the pair (∅,V ) is k-decomposable iff the htw ((V ,E)) ≤ k. We say that the (α,α-comp) is k-decomposable by using the k-edge β if there exists a HD’ with λ(r) = β. The procedure AddGood is used to add a tuple (α,α-comp,β,cCs) to the set goods, if the pair (α,α-comp) is k-decomposable by using the k-edge β. The set cCs in the tuple, denotes the elements of β-comps contained in α-comp. Similarly, the procedure AddNoGood is used to add a pair (α,αcomp) to the set noGoods, if the pair (α,α-comp) is not k-decomposable. The procedure IsGood (α,α-comp) returns true iff a tuple of the form (α,αcomp,β,cCs) exists in the set goods. Similarly, the procedure IsNoGood (α,αcomp) returns true iff the pair (α,α-comp) exists in the set noGoods. The procedure Decompose takes a (α,α-comp) pair as input and returns true iff (α,α-comp) is k-decomposable. The line(1) of the procedure finds cv, the set of variables through which the α-comp is connected to the rest of the variables in the hypergraph. The loop that begins at line(2) iterates for every k-edge β, such that (vars(β) ∩ α-comp 6= ∅) and (cv ⊆ vars(β)). That is the β should be such that vars(β) contains at least one variable in α-comp, and cv is contained in vars(β). The set cCs in line(3) is the set of elements of β-comps, which are contained in α-comp and hence necessary for consideration by the Decompose procedure. The internal loop starting at line(5) of Decompose checks whether a (β,cC) pair is k-decomposable. The variable success will be true at the line(10) iff, for each cC ∈ cCs, the pair (β,cC) is k-decomposable. A call to Decompose(β,cC) at line(8) is made iff both the calls to IsNoGood (β,cC) and IsGood (β,cC) return false. This makes sure that for any (β,β-comp) pair, the call Decompose(β,β-comp) is made at most once. At line(10), if the variable success is set to true, then the tuple (α,α-comp,β,cCs) is added to the set goods and the procedure returns true. Otherwise, the loop at line(2) continues with an another k-edge choice for β. If all choices for β at line(2)
6.3. THE BACKTRACKING PROCEDURE
107
Set goods = ∅; Set noGoods = ∅; Hypertree HD = (T ,λ,χ) Decompose (α,α-comp) 1: cv = vars(α) ∩ edgeVars(α-comp) 2: ∀β ∈ k-edges. (vars(β) ∩ α-comp 6= ∅). (cv ⊆ vars(β)) 3: cCs = {cC | cC ∈ β-comps, cC ⊆ α-comp } 4: success = true 5: ∀ cC ∈ cCs 6: if (IsNoGood (β,cC)) then success = false 7: else if (IsGood (β,cC)) then continue 8: else if (Decompose(β,cC)) then continue 9: else success = false 10: if (success) then AddGood (α,α-comp,β,cCs); return true 11: AddNoGood (α,α-comp); return false IsDecomposable ((V ,E),k) 1: if (Decompose(∅,V )) then 2: Add root node r to T ; Find (∅,V ,β,cCs) ∈ goods 3: λ(r) = β; χ(r) = vars(β) 4: ∀ cC ∈ cCs 5: BuildHypertree (β,cC,r) 6: return HD 7: else return ’Not-k-Decomposable’ IsGood (t1 ,t2 ) 1: ∀ (tw ,tx ,ty ,tz ) ∈ goods 2: if (t1 ,t2 ) = (tw ,tx ) then return true 3: return false IsNoGood (t1 ,t2 ) 1: ∀ (tx ,ty ) ∈ noGoods 2: if (t1 ,t2 ) = (tx ,ty ) then return true 3: return false AddGood (t1 ,t2 ,t3 ,t4 ) 1: goods = goods ∪ {(t1 , t2 , t3 , t4 )} AddNoGood (t1 ,t2 ) 1: noGoods = noGoods ∪ {(t1 , t2 )} BuildHypertree (α,α-comp,s) 1: Find (α,α-comp,β,cCs) ∈ goods 2: Add a node t to T as a child node of s 3: λ(t) = β; χ(t) = (vars(β) ∩ edgeVars(α-comp)) 4: ∀ cC ∈ cCs 5: BuildHypertree (β,cC,t) Figure 6.1: The pseudo code of the backtracking procedure for hypertree decomposition.
108 CHAPTER 6. HYPERTREE, HYPERSPREAD & CONNECTED ... is exhausted without any success, then the procedure adds the (α,α-comp) pair to the set noGoods at line(11) and then returns false. In case the call Decompose(∅,V ) at line(1) of the procedure IsDecomposable returns true, then a hypertree decomposition (HD) is built and returned. Otherwise, a message ’Not-k-decomposable’, meaning the hypertree width of (V ,E) is larger than k, is returned. At line(2) of the procedure a root node r is created and a tuple of the form (∅,V ,β,cCs) is obtained from the set goods. The third entry β in the tuple corresponds to the k-edge used during the first call of the recursive Decompose procedure. Hence, λ(r) is set to β. By the definition of hypertree decomposition, for a root node r, χ(r) = vars(λ(r)). Hence, the χ(r) is set to vars(β). In the lines(4-5), for each cC ∈ cCs, a child node of r is created by the call BuildHypertree (β,cC,r). The procedure BuildHypertree in fact recursively calls itself and extracts, from the set goods, the subtree rooted at a child vertex of r. At line(6), the procedure returns a hypertree decomposition. Theorem 15 The IsDecomposable(H,k) returns a hypertree decomposition iff htw(H) ≤ k. The proof of the above theorem follows from the fact that, our procedure is essentially a backtracking version of the opt-k-decomp [37] procedure for hypertree decomposition. The opt-k-decomp procedure suffers from a huge pre-processing cost. For a given k, the opt-k-decomp implicitly finds all possible decompositions of width at most k and extracts the optimal one. But our backtracking procedure stops as soon as it discovers a decomposition of width at most k. Hence, our procedure will be able to stop quickly when there are several decompositions of width at most k. Theorem 16 The time complexity of IsDecomposable(H,k) is O(|E|3k+3 ). Proof 12 The time complexity is dominated by Decompose. During a call to Decompose, the loop over choices for β iterates at most O(|E|k ). The |cCs| is at most |E|. Since each k-edge results in at most |E| k-edgecomponents, the total number of k-edge-components is O(|E|k+1 ). The cost of each call to IsNoGood/IsGood will take O(|E|k+1 ) time, as the size of goods/noGoods can be at most the number of k-edge-components. We can ignore the cost for calls to AddGood/AddNoGood as their contribution to the complexity is dominated. Hence, the cost for each call to Decompose is O(|E|2k+2 ). There can be at most O(|E|k+1 ) calls to Decompose, at most once for each k-edge-component. Hence, the time complexity of the procedure IsDecomposable is O(|E|3k+3 ). ¤ Given two k-edge-components (α,comp) and (α0 ,comp’), they are isomorphic if comp = comp’.
6.4. VARIANTS OF HYPERTREE DECOMPOSITION
109
Theorem 17 Given two isomorphic pairs (α,comp) and (α0 ,comp’), (α,comp) is k-decomposable iff (α0 ,comp’) is k-decomposable. Proof 13 By definition comp = comp’. Hence, the only difference between the calls Decompose(α,comp) and Decompose(α0 ,comp’) are the first parameters: α and α0 . In Decompose the distinction between α and α0 is of importance only at line(2), where the set cv is calculated. We now show that cv is independent of α. Since (α,comp) is a k-edge-component, by definition, ∀e ∈ E. e ⊆ edgeVars(comp) ⇒ (e\comp) ⊆ vars(α). Also, comp ∩ vars(α) = ∅. This implies that, during the call Decompose(α,comp), the set cv = edgeVars(comp)\(comp). Therefore, the set cv remains the same during both the calls Decompose(α,comp) and Decompose(α0 ,comp’). Hence, the proof. ¤ For each set of isomorphic components we need to make at most one call to Decompose. Hence, by using isomorphism the number of calls to Decompose may reduce significantly.
6.4
Variants of Hypertree Decomposition
The Figure 6.2 presents the pseudo code for a generic decomposition procedure IsDecomposableGe, based on the hypertree framework. There are two changes in the generic procedure from the earlier procedure in Figure 6.1. First change is that, the generic version is able to detect isomorphism, so that a call to Decompose is made at most once for a set of isomorphic components. The second change is in line(2) of the procedure Decompose, where the code β ∈ k-edges in the old procedure has been replaced with (β, Qβ ) ∈ Ω in the generic version. Each element in the set Ω is a pair of the form (β, Qβ ), where β ∈ k-edges and Qβ ⊆ vars(β). In all the places where vars(β) was used in the old procedure, Qβ is used in the generic procedure. The set Ω defines, for each β ∈ k-edges, the allowed subsets of vars(β) which can be used for decomposition. Essentially, by allowing subsets of vars(β) to be considered for obtaining a decomposition we obtain a generic procedure. Note, the procedures IsGood, AddGood, IsNoGood, and AddNoGood are not listed in Figure 6.2 as the old versions of them can be naturally modified to work in the generic framework. Let the set ΩHTD = {(α, vars(α)) | α ∈ kedges }. We have the following theorem. Theorem 18 When Ω = ΩHTD , IsDecomposableGe(H,k) returns a hypertree decomposition iff htw(H) ≤ k.
HyperSpread Decomposition An unbroken guarded block (ug-block) [15] is a pair (α,Qα ), where α ⊆ E and Qα ⊆ vars(α), satisfying two conditions: (1) ∀e1 , e2 ∈ α. e1 ∩ e2 ⊆ Qα , and
110 CHAPTER 6. HYPERTREE, HYPERSPREAD & CONNECTED ...
Set goods = ∅; Set noGoods = ∅; Hypertree D = (T ,λ,χ) Decompose (comp) 1: cv = edgeVars(comp) \ comp 2: ∀(β, Qβ ) ∈ Ω. (Qβ ∩ comp 6= ∅). (cv ⊆ Qβ ) 3: cCs = {cC | cC ∈ [Qβ ]-comps, cC ⊆ comp } 4: success = true 5: ∀ cC ∈ cCs 6: if (IsNoGood (cC)) then success = false 7: else if (IsGood (cC)) then continue 8: else if (Decompose(cC)) then continue 9: else success = false 10: if (success) then AddGood (comp,β,Qβ ,cCs); return true 11: AddNoGood (comp); return false IsDecomposableGe ((V ,E),k) 1: if (Decompose(V )) then 2: Add root node r to T ; Find (V ,β,Qβ ,cCs) ∈ goods 3: λ(r) = β; χ(r) = Qβ 4: ∀ cC ∈ cCs 5: BuildHypertree (cC,r) 6: return D 7: else return ’Not-k-Decomposable’ BuildHypertree (comp,s) 1: Find (comp,β,Qβ ,cCs) ∈ goods 2: Add a node t to T as a child node of s 3: λ(t) = β; χ(t) = (Qβ ∩ edgeVars(comp)) 4: ∀ cC ∈ cCs 5: BuildHypertree (cC,t) Figure 6.2: The pseudo code of the generic procedure for decomposition in hypertree framework.
6.4. VARIANTS OF HYPERTREE DECOMPOSITION
111
(2) each [Qα ]-comp has non-empty intersection with at most one [vars(α)]comp. The size of an ug-block (α,Qα ) is |α|. For some α ⊆ E and v ∈ V , let the label, Lα (v) = {cC | cC ∈ [α]-comps, v ∈ edgeVars(cC)}. An ug-block (α,Qα ) is canonical if ∀e ∈ α. ∀v1 , v2 ∈ e\Qα . Lα (v1 ) = Lα (v2 ). Let ΩHSD be the set of all the at most k sized canonical ug-blocks of (V ,E). Note, by the definition of canonical ug-blocks, ΩHTD ⊆ ΩHSD . Given k and a canonical ug-block (α,Qα ) with |α| ≤ k, let a triple of the form (α,Qα ,[Qα ]-comp) be called a k-spreadcomponent. It has been shown in [15] that, there exists at most (|E| + 1)k+2 k-spread-components. The notion of isomorphism can be naturally extended to k-spread-components. Given two k-spread-components (α,Qα ,comp) and (α0 ,Qα0 ,comp’), they are isomorphic when comp = comp’. A spread cut [15] of a hypergraph H is a hypertree SC = (T ,λ,χ), satisfying the two conditions: (1) (T ,χ) is a tree decomposition of H, and (2) ∀n ∈ nodes(T ), (λ(n),χ(n)) is a canonical ug-block. The spread cut width of H, denoted scw (H), is the minimum width of all possible spread cuts of H. A hyperspread decomposition of a hypergraph H is a hypertree HSD = (T, λ, χ), satisfying the two conditions: (1) (T ,χ) is a tree decomposition of H, and (2) ∀n ∈ nodes(T ). ∃(α, Qα ) ∈ ΩHSD . λ(n) = α. χ(n) = Qα ∩χ(Tn ). The hyperspread width of H, denoted hsw (H), is the minimum width of all possible hyperspread decompositions of H. Due to a variant of IsDecomposableGe, we have: Theorem 19 When Ω = ΩHSD , IsDecomposableGe(H,k) returns a hyperspread decomposition iff hsw(H) ≤ k. By arguments similar to those of Theorem 16, we have: Theorem 20 When Ω = ΩHSD , the procedure IsDecomposableGe(H,k) has time complexity O((|E| + 1)3k+7 ). Given a hyperspread decomposition of a CSP, the CSP can be solved by the same algorithm for CSP solving using hypertree decompositions [38]. Also, for a fixed k, determining whether hsw of CSP is ≤ k takes polynomial time. Hence, the hyperspread decomposition is tractable. We now state that the hyperspread width is bounded by both hypertree width and the spread cut width. Theorem 21 hsw(H) ≤ htw(H) and hsw(H) ≤ scw(H) Proof 14 The last two conditions in the definition of hypertree decomposition implies that: ∀n ∈ nodes(T ). ∃(α, Qα ) ∈ ΩHTD . λ(n) = α. χ(n) = Qα ∩χ(Tn ). Since for any k, ΩHTD ⊆ ΩHSD , each hypertree decomposition is also a hyperspread decomposition. Hence, hsw(H) ≤ htw(H). The second condition in the definition of spread cut implies that: ∀n ∈ nodes(T ). ∃(α, Qα ) ∈ ΩHSD . λ(n) = α. χ(n) = Qα . Therefore, each spread cut is also a hyperspread decomposition. Hence, hsw(H) ≤ scw(H). ¤
112 CHAPTER 6. HYPERTREE, HYPERSPREAD & CONNECTED ... Recently in [4], the existence of a tractable decomposition better than hypertree decomposition was stated as an open problem. In [15], a family of hypergraphs Hn , for n = 1, 2, . . ., was presented for which the hypertree width of Hn is at least 3n, while the spread cut width is at most 2n. Note, it is not known whether for any H, scw(H) ≤ htw(H). Since for any H, hsw(H) ≤ htw(H) and hsw(Hn ) ≤ scw(Hn ) < htw(Hn ), hyperspread decomposition gives a simple positive answer to the open problem.
Connected Hypertree Decomposition A connected hypertree decomposition is a hypertree decomposition CHTD = (T, λ, χ), satisfying two additional conditions: (1) for the root node r of T , |λ(r)| = 1, and (2) if c ∈ nodes(T ) is a non-root node and the parent node of c is p, then ∀e ∈ λ(c). ∃v ∈ χ(c) ∩ χ(p). v ∈ e. The second condition states that for any non-root node c with parent node p, each edge e in λ(c) should have at least one variable that is common to both χ(c) and χ(p). The two conditions in the definition results in a significant reduction of the branching choices in the procedure Decompose. We show empirical results in the next section to support such reduction. Let the connected hypertree width of a hypergraph H, denoted chtw (H), be the minimum width of the all possible connected hypertree decompositions of H. By definitions, htw(H) ≤ chtw(H). It is an open problem whether chtw(H) = htw(H). Let ΩCHTD (cv) = {(α, vars(α)) | α ∈ k-edges, (cv = ∅) ⇒ (|α| = 1), (cv 6= ∅) ⇒ (∀e ∈ α. ∃v ∈ cv. v ∈ e)}, where cv ⊆ V corresponds to the connection variables in the procedure Decompose. As an another variant of the generic decomposition procedure, we state the following theorem. Theorem 22 When Ω = ΩCHTD (cv), a connected hypertree decomposition is returned by IsDecomposableGe(H, k) iff chtw(H) ≤ k. Unlike the previous two variants of the generic decomposition procedure, when Ω = ΩCHTD (cv), the set Ω is newly defined during each call to Decompose based on the connection variables cv. Since connected hypertree decompositions are subsets of hypertree decompositions, connected hypertree decomposition is tractable.
6.5
Experiments
We have implemented the presented backtracking procedures for both hypertree decomposition and connected hypertree decomposition. We have not implemented the hyperspread decomposition procedure. All of our experiments are done on an Intel Xeon 3.2Ghz machine, running Linux and
Arity µ, Max 3.15, 8 2.89, 3 2.90, 3 3.61, 6 3.55, 6 3.46, 17 4, 7 3.56, 7 3.55, 7 3.19, 10 3.16, 8 4.91, 10
CHTD Time,Width 64, 4* 1800, 64 1800, 208 1800, 6 660, 6* 1800, 10 4, 5* 0.33, 4* 196, 7* 5, 3* 22, 4* 0.31, 2* 8
CHTD-NoIso Time, Width 503, 4* 1800, 64 1800, 208 1800, 6 1800, 6 1800, 10 21, 5* 0.7, 4* 1800, 7 11, 3* 159, 4* 0.38, 2* 6
Exact Methods BE+CHTD HTD Time, Width Time, Width 64, 4* 1800, 4 1800, 17 1800, 82 1800, 64 1800, 456 1800, 6 1800, 6 660, 6* 1800, 6 1800, 9 1800, 13 4, 5* 1139, 5* 0.35, 4* 59, 4* 196, 7* 1800, 7 5, 3* 50, 3* 22, 4* 308, 4* 0.4, 2* 0.19, 2* 8 5 HTD-NoIso Time, Width 1800, 4 1800, 82 1800, 456 1800, 6 1800, 6 1800, 13 1800, 5 312, 4* 1800, 8 172, 3* 1800, 4 0.25, 2* 3
Heuristic BE µT, µW, MinW 0.12, 4, 4 1, 18.4, 17 66, 67.4, 64 0.14, 8, 8 0.17, 7, 7 4, 9.4, 9 0.14, 6, 6 0.12, 6, 6 0.15, 9, 9 0.35, 4, 4 0.08, 5, 5 0.28, 2.6, 2 n/a
Table 6.1: Experimental results. The mean (µ) and the maximum arity of the instances are also listed.
Instance Size Name |V |, |E| 1-32.1.cp 110, 222 FISCHER1-1-fair.smt 308, 284 FISCHER1-6-fair.smt 1523, 1419 baobab1.dag 145, 84 baobab3.dag 187, 107 complex.cp 414, 849 das9201.dag 204, 82 isp9601.dag 247, 104 isp9603.dag 186, 95 large-partial.cp 184, 371 large2.cp 77, 130 renault.cp 99, 113 # optimal
6.5. EXPERIMENTS 113
114 CHAPTER 6. HYPERTREE, HYPERSPREAD & CONNECTED ... with 4GB RAM. We use 12 instances in our experiments. They are constraint hypergraphs from different sources: five from configuration problems (*.cp), five from fault trees (*.dag), and two from SMT instances (*.smt). Our tools and instances are available online1 . The source code of our tools are also available online as part of the TreeD 2 tree decomposition code. In our implementation, for a given Ω and H = (V, E), we find an optimal decomposition by a sequence of queries to the procedure IsDecomposableGe(H,k). The parameter k will take values in the sequence k1 , k2 , . . . , kl−1 , kl . In the sequence, k1 = |E|. If the query IsDecomposableGe(H,ki ) returns a decomposition of width k 0 , then ki+1 = k 0 − 1. If the query IsDecomposableGe(H,ki ) returns the message ’Not-k-Decomposable’, then l = i. The optimal width will be kl + 1. We found that the l is often very small due to jumps the sequence could make. The results of our experiments are listed in Table 6.1. All the experiments in the table are done with a time limit of 1800 CPU seconds. The legend ’CHTD’ (’HTD’) refers to the experiments with Ω = ΩCHTD (Ω = ΩHTD ). The legend ’CHTD-NoIso’ (’HTD-NoIso’) refers the ’CHTD’ (’HTD’) procedure without detection of isomorphic components. For each method, we list the best width obtained. In the cases we are able to prove optimality, the entries in the width columns will be of the form k∗. We also tested the heuristic ’BE’ in the HTDECOMP 3 tool. The BE uses tree decomposition heuristics and set covering heuristics to obtain a heuristic Generalized Hypertree Decomposition (GHTD) [39]. In case of a GHTD, the third condition in the definition of hypertree decomposition may be violated. Since BE is randomized, we ran experiments using BE five times, and list in the table the mean time (µT), the mean width (µW) and the best width (MinW). We also did experiments on a hybrid BE+CHTD, in which five runs of BE will be used to first obtain five GHTDs. If the best width of the GHTDs so obtained is kbe , then the CHTD procedure will be invoked with k1 = kbe . Note, the best width decomposition found by the hybrid BE+CHTD may be a GHTD, whose width can be smaller than htw. Although, the HTDECOMP tool has heuristic choices other than BE, we choose BE since we think it is the best choice. The BE+CHTD combination can be naturally extended with any initialization heuristic. The last row, #optimal of the table lists the number of proven optimal width decompositions obtained by each method. Note, to prove optimality, the query corresponding to kl needs to return ’Not-k-decomposable’ within the time limit. All the exact methods listed in the table are our contributions. The experiments using the implementations4 of the previous exact methods opt1
http://www.itu.dk/people/sathi/connected-hypertree/ http://www.itu.dk/people/sathi/treed/ 3 http://www.dbai.tuwien.ac.at/proj/hypertree/downloads.html 4 http://www.dsl.uow.edu.au/˜harvey/research hypertrees.shtml 2
6.5. EXPERIMENTS
115
1000 1-32.1 baobab3 das9201 isp9601 isp9603 large-partial large2 renault
CPU Seconds (logscale)
100
10
1
0.1
0.01
0.001 0
2
4
6 Width
8
10
12
Figure 6.3: Width vs. CPU-time (y axis in logscale). The empirical complexity peaks at k ∗ −1. k-decomp, and an improvement over opt-k-decomp, red-k-decomp [43], either exceeded time limit or aborted in all cases except renault.cp, in which red-kdecomp took 1257 seconds to find an optimal decomposition. In fact, both the experiments using the opt-k-decomp and red-k-decomp tools consisted of only one query to the tool. For an instance H, if the ’CHTD’ finds a decomposition of width k 0 in 1800 seconds, then the opt-k-decomp and redk-decomp are just asked to find a decomposition of width k 0 . Hence, the experiments are done in a favorable setting to the previous methods. From the table, we can observe that the CHTD procedure gives more optimal decompositions than others. In none of the instances the HTD could find a better decomposition than that of CHTD. In three instances the BE finds GHTDs of width smaller than those by the exact methods. For use in practice the hybrid BE+CHTD seems the best choice, as it results in best decomposition in all the cases. In Figure 6.3, we plot the time taken for the queries IsDecomposableGe(H,k) with Ω = ΩCHTD , k ∈ {1, 2, . . . , 11, 12} and H being one among the eight instances for which CHTD succeeds in obtaining optimal decompositions within 1800 seconds. We can observe that, for each instance H, the cost of queries until k ∗ −1, where k∗ is chtw (H), increases exponentially. The cost suddenly decreases at k∗ and continues to decrease exponentially.
116 CHAPTER 6. HYPERTREE, HYPERSPREAD & CONNECTED ...
10000 CHTD CHTD-NoIso HTD HTD-NoIso
1000
CPU Seconds (logscale)
100
10
1
0.1
0.01
0.001 0
2
4
6 Width
8
10
12
Figure 6.4: The effect of detecting isomorphism and CHTD vs. HTD in isp9603 instance (time limit 10000 seconds).
6.6. CONCLUSION
117
In Figure 6.4, we plot the results of queries on the four different exact procedures for the instance isp9603, with time limit 10000 seconds. The plot shows a huge benefit of identifying isomorphism. The plot also shows an exponential difference between the runtime of CHTD and HTD which is due to the branching restrictions in CHTD. The HTD and HTD-NoIso timed out for some queries.
6.6
Conclusion
We have presented a backtracking procedure for hypertree decomposition and defined isomorphism to speed-up the procedure. We generalized the procedure, the variants of which results in two new tractable decompositions: hyperspread and connected hypertree. We have shown that hyperspread width is bounded by both hypertree width and spread cut width, which solves a recently stated open problem. The experiments using our methods are able to find optimal decompositions of several instances. Avenues for future work include: implementation of hyperspread decomposition, determining chtw = htw?, identifying other tractable variants, and comparison with exact methods for tree decomposition like [35].
118 CHAPTER 6. HYPERTREE, HYPERSPREAD & CONNECTED ...
Bibliography [1] IBM formal verification benchmarks. http://www.haifa.il.ibm.com/ projects/verification/RB Homepage/bmcbenchmarks.html. [2] Niver sat preprocessor. http://www.itu.dk/people/sathi/niver.html. [3] Uclid. http://www-2.cs.cmu.edu/˜uclid/ . [4] Open Problems List - MathsCSP Workshop (version 0.3), Oxford. 2006. [5] http://www.itu.dk/research/cla/ externals/clib/. 2006. [6] J. Amilhastre, H. Fargier, and P. Marquis. Consistency restoration and explanations in dynamic CSPs-application to configuration. AIJ, 1-2:199–234, 2002. [7] Array-Technology. http://www.array.dk/, 2005. [8] F. Bachhus and J. Winter. Effective preprocessing with hyperresolution and equality reduction. In SAT, pages 341–355, 2003. [9] A. Biere. Bmc. http://www-2.cs.cmu.edu/˜modelcheck/bmc.html. [10] F. Bouquet and P. J´egou. Using OBDDs to handle dynamic constraints. Information Processing Letters, 62(3):111–120, 1997. [11] R. I. Brafman. A simplifier for propositional formulas with many binary clauses. In IJCAI, pages 515–522, 2001. [12] R. E. Bryant. Graph-based algorithms for boolean function manipulation. Transactions on Computers, 8:677–691, 1986. [13] J. R. Burch, E. M. Clarke, and K. McMillan. Symbolic model checking: 1020 states and beyond. In LICS, pages 428–439, 1990. [14] K. C. K. Cheng and R. H. C. Yap. Maintaining generalized arc consistency on ad-hoc n-ary Boolean constraints. In ECAI, pages 78–82, 2006. 119
120
BIBLIOGRAPHY
[15] D. Cohen, P. Jeavons, and M. Gyssens. A unified theory of structural tractability for constraint satisfaction and spread cut decomposition. In IJCAI, pages 72–77, 2005. [16] Configit-Software. http://www.configit-software.com, 2005. [17] T. H. Cormen, C. E. Leiserson, R. L. Rivest, and C. Stein. Introduction to Algorithms (Second Edition). MIT Press/McGraw-Hill, 2001. [18] R. F. Damiano and J. H. Kukula. Checking satisfiability of a conjunction of BDDs. In DAC, pages 818–823, 2003. [19] A. Darwiche. Decomposable negation normal form. Journal of ACM, 48(4):608–647, 2001. [20] A. Darwiche and P. Marquis. A knowledge compilation map. JAIR, 17:229–264, 2002. [21] M. Davis, G. Logemann, and D. Loveland. A machine program for theorem proving. Communications of the ACM, 5(7):394–397, 1962. [22] M. Davis and H. Putnam. A computing procedure for quantification theory. Journal of the ACM, 7(3):201–215, 1960. [23] R. Dechter. Enhancement schemes for constraint processing: Backjumping, learning and cutset decomposition. Artificial Intelligence, 41(3):273–312, 1990. [24] R. Dechter. Constraint Processing. Morgan Kaufmann, 2003. [25] R. Dechter and J. Pearl. Tree-clustering schemes for constraintprocessing. AIJ, 38(3):353–366, 1989. [26] N. Een and A. Biere. Effective preprocessing in SAT through variable and clause elimination. In SAT, pages 61–75, 2005. [27] H. Fargier and P. Marquis. On the use of partially ordered decision graphs in knowledge compilation and quantified boolean formulae. In AAAI, pages 35–40, 2006. [28] H. Fargier and M.-C. Vilarem. Compiling CSPs into tree-driven automata for interactive solving. Constraints, 9(4):263–287, 2004. [29] F. Franco. Elimination of infrequent variables improves average case performance of satisfiability algorithms. SIAM Journal of Computing, 20:1119–1127, 1991. [30] E. C. Freuder. A sufficient condition for backtrack-bounded search. Journal of ACM, 32(4):755–761, 1985.
BIBLIOGRAPHY
121
[31] E. C. Freuder. Eliminating interchangeable values in constraint satisfaction problems. In AAAI, pages 227–233, 1991. [32] E. C. Freuder, C. Likitvivatanavong, M. Moretti, F. Rossi, and R. J. Wallace. Explanations and optimization in preference-based configurators. pages 58–71. LNCS 2627, Recent Advances in Constraints, Springer, 2002. [33] M. R. Garey and D. S. Johnson. Computers and Intractability-A Guide to the Theory of NP-Completeness. W H Freeman and Co, 1979. [34] A. V. Gelder. Combining preorder and postorder resolution in a satisfiability solver. In Electronic Notes of SAT, 2001. [35] V. Gogate and R. Dechter. A complete anytime algorithm for treewidth. In UAI, pages 201–208, 2004. [36] E. Goldberg and Y. Novikov. Berkmin: a fast and robust sat-solver. In DATE, pages 142–149, 2002. [37] G. Gottlob, N. Leone, and F. Scarcello. On tractable queries and constraints. In DEXA, pages 1–15, 1999. [38] G. Gottlob, N. Leone, and F. Scarcello. A comparison of structural CSP decomposition methods. AIJ, 124(2):243–282, 2000. [39] G. Gottlob, N. Leone, and F. Scarcello. Robbers, marshals, and guards: game theoretic and logical characterizations of hypertree width. Journal of computer and system sciences, 66(4):775–808, 2003. [40] M. Gyssens, P. G. Jeavons, and D. A. Cohen. Decomposing constraint satisfaction problems using database techniques. AIJ, 66(1):57–89, 1994. [41] T. Hadzic, R. Jensen, and H. R. Andersen. Notes on calculating valid domains. http://www.itu.dk/ tarik/cvd/cvd.pdf, 2006. [42] T. Hadzic, S. Subbarayan, R. M. Jensen, H. R. Andersen, J. Møller, and H. Hulgaard. Fast backtrack-free product configuration using a precompiled solution space representation. In PETO, pages 131–138, 2004. [43] P. Harvey and A. Ghose. Reducing redundancy in the hypertree decomposition scheme. In ICTAI, pages 474–481, 2003. [44] P. Hawkins and P. J. Stuckey. A hybrid BDD and SAT finite domain constraint solver. In PADL, pages 103–117, 2006.
122
BIBLIOGRAPHY
[45] E. D. Hirsch. New worst-case upper bounds for sat. Automated Reasoning, 24:297–420, 2000. [46] H. Hoos and T. Stutzle. Satlib: An online resource for research on sat. In SAT, pages 283–292, 2000. www.satlib.org. [47] J. Huang and A. Darwiche. DPLL with a trace: From SAT to knowledge compilation. In IJCAI, pages 156–162, 2005. [48] iCoDE. www.itu.dk/people/sathi/icode/, 2004. [49] R. M. Jensen. Clab 1.0 user manual. port, IT University of Copenhagen, 2004. http://www.itu.dk/people/rmj/clab/.
Technical reITU-TR-2004-46
[50] R. M. Jensen. CLab: A C++ library for fast backtrackfree interactive product configuration. In CP, page 816, 2004. http://www.itu.dk/people/rmj/clab/. [51] R. M. Jensen, R. E. Bryant, and M. M. Veloso. SetA*: An efficient BDD-based heuristic search algorithm. In Proceedings of 18th National Conference on Artificial Intelligence (AAAI’02), pages 668–673, 2002. [52] U. Junker. Quickxplain: Conflict detection for arbitrary constraint propagation algorithms. In IJCAI Workshop on Modelling and Solving with constraints, 2001. [53] N. Jussien. e-constraints: explanation-based constraint programming. In CP01 Workshop on User-Interaction in Constraint Satisfaction, 2001. [54] T. Kam, T. Villa, R. K. Brayton, and A. L. Sangiovanni-Vincentelli. Multi-valued decision diagrams: Theory and applications. MultipleValued Logic: An International Journal, 4(1-2):9–62, 1998. [55] G. Katsirelos and F. Bacchus. Unrestricted nogood recording in CSP search. In CP, pages 873–877, 2003. [56] U. Kjærulff. Triangulation of Graphs: Algorithms Giving Small Total State Space. Technical report, University of Aalborg, 1990. [57] V. Lagoon and P. Stuckey. Set domain propagation using ROBDDs. In CP, pages 347–361, 2004. [58] J. N. Madsen. Methods for interactive constraint satisfaction. Master’s thesis, Department of Computer Science, University of Copenhagen, 2003.
BIBLIOGRAPHY
123
[59] R. Mateescu and R. Dechter. Compiling constraint networks into AND/OR multi-valued decision diagrams (AOMDDs). In CP, pages 329–343, 2006. [60] K. McMillan. Hierarchical representations of discrete functions, with application to model checking. In CAV, pages 41–54, 1994. [61] C. Meinel and T. Theobald. Algorithms and Data Structures in VLSI Design. Springer, 1998. [62] S. Mittal and B. Falkenhainer. Dynamic constraint satisfaction problems. In AAAI, pages 25–32, 1989. [63] M. W. Moskewicz, C. F. Madigan, Y. Zhao, L. Zhang, and S. Malik. Chaff: Engineering an efficient SAT solver. In DAC, pages 530–535, 2001. [64] K. Pipatsrisawat and A. Darwiche. Rsat 2.0: Sat solver description. Technical report D153. Automated Reasoning Group, Computer Science Department, University of California, Los Angeles, 2007. [65] M. Prasad, P. Chong, and K. Keutzer. Why is ATPG easy? In DAC, pages 22–28, 1999. [66] N. Robertson and P. Seymour. Graph minors. II: Algorithmic aspects of tree-width. Journal of algorithms, 7(3):309–322, 1986. [67] L. Ryan. Siege sat solver. http://www.cs.sfu.ca/˜loryan/personal/. [68] T. Schiex and G. Verfaillie. Nogood recording for static and dynamic constraint satisfaction problems. International Journal of Artificial Intelligence Tools, 3(2):187–207, 1994. [69] S. Subbarayan. Integrating CSP decomposition techniques and BDDs for compiling configuration problems. In CP-AI-OR, pages 351–365, 2005. [70] S. Subbarayan, R. M. Jensen, T. Hadzic, H. R. Andersen, H. Hulgaard, and J. Møller. Comparing two implementations of a complete and backtrack-free interactive configurator. In CP 2004 CSPIA Workshop, pages 97–111, 2004. [71] E. R. van der Meer and H. R. Andersen. BDD-based recursive and conditional modular interactive product configuration. In CP 2004 CSPIA Workshop, pages 112–126, 2004. [72] M. N. Velev. Microprocessor benchmarks. http://www.ece.cmu.edu/ ˜mvelev/sat benchmarks.html.
124
BIBLIOGRAPHY
[73] I. Wegener. Branching Programs and Binary Decision Diagrams. Society for Industrial and Applied Mathematics (SIAM), 2000. [74] R. Weigel and B. Faltings. Compiling constraint satisfaction problems. AIJ, 115(2):257–287, 1999. [75] B. Yang, R. E. Bryant, D. R. O’Hallaron, A. Biere, O. Coudert, G. Janssen, R. K. Ranjan, and F. Somenzi. A performance study of BDD-based model checking. In Formal Methods in Computer-Aided Design FMCAD’98, pages 255–289, 1998. [76] L. Zhang, C. F. Madigan, M. W. Moskewicz, and S. Malik. Efficient conflict driven learning in boolean satisfiability solver. In ICCAD, pages 279–285, 2001.
Appendix A
Other Related Contributions Other articles written during the past few years, which are related to this thesis, and would be of interest for further reading, are placed here.
125
FAST BACKTRACK-FREE PRODUCT CONFIGURATION USING A PRECOMPILED SOLUTION SPACE REPRESENTATION Tarik Hadzic, Sathiamoorthy Subbarayan, Rune M. Jensen, Henrik R. Andersen, Jesper Møller*, and Henrik Hulgaard* Department of Innovation IT University of Copenhagen Glentevej 67 2400 Copenhagen NV Denmark +45 3816 8888 Email: {tarik, sathi, rmj, hra}@itu.dk
Configit Software A/S* Vermundsgade 38 B DK-2100 Copenhagen Ø Denmark +45 7022 6700 Email: {jm, henrik}@configit-software.com
In this paper we describe a two-phase approach to interactive product configuration. In the first phase, a compressed symbolic representation of the set of valid configurations (the solution space) is compiled offline. In the second phase, this representation is embedded in an online configurator and utilized for fast, complete, and backtrack-free interactive product configuration. The main advantage of our approach compared to online search-based approaches is that we avoid searching for valid solutions in each iteration of the interactive configuration process. The computationally hard part of the problem is fully solved in the offline phase given that the produced symbolic representation is small. The employed symbolic representation is Binary Decision Diagrams (BDDs). More than a decade of research in formal verification has shown that BDDs often compactly encode formal models of systems encountered in practice. To our experience this is also the case for product models. Often the compiled BDD is small enough to be embedded directly in hardware. Our research has led to the establishment of a spin-off company called Configit Software A/S. Configit has developed software for writing product models in a strongly typed language and has patented a particularly efficient symbolic representation called Virtual Tables. Significance: Several companies have benefited from the tools developed by Configit Software. The application areas are diverse and include ordinary product configuration as well as sales support and user interfaces for hardware components. Keywords: Interactive Product Configuration, Configuration Space Models, Binary Decision Diagrams. (Received
; Accepted
)
1. INTRODUCTION The focus in manufacturing industry has shifted from mass production to mass customization. Companies continually have to offer more product variants with greater flexibility. At the same time, the rapid development of information technology has significantly increased the complexity of each individual product. These changes have led to a situation where the industry is losing track of the functionality of their products. It has become common practice to ship mobile phones and software that is close to impossible to setup correctly even for expert customers. Efficient tools are needed to handle the increasing complexity of products. Product configurators are one such class of tools. Given a set of rules defining the set of valid configurations (the solution space) of the product, the configurators guide sales people and users to find a valid and desirable configuration of the product. Most configurators are based on searching online in the solution space [8, 9, 14]. This may work well for many products, but it is impossible to guarantee that the search time is polynomially bounded with the size of the product model, since finding just a single valid configuration is NP-complete. This means that search-based configurators sometimes may have undesirable long response times. Moreover, the performance of these tools often depends on how the rules are written, and it can be very difficult to write rules that work well in practice. In this paper we describe an alternative approach to product configuration based on a precompiled representation of the solution space. The approach has two phases. The first phase is offline and consists of compiling the product rules into a Binary Decision Diagram (BDD) [2] representing the solution space. BDDs are a canonical representation of Boolean functions. During the last 15 years, they have been applied successfully in formal verification and other areas of computer science to represent formal models of very large systems [3]. Our experience is that BDDs also compactly encode the solution space of industrial products. Since the compiled BDD is canonical, it only depends on what Boolean function the
product rules represent and not on how the rules are written. This gives the rule writer freedom to choose a format of the rules that naturally represents the behavior of the product. In the second phase, the compiled BDD is used online in an interactive configurator. In each iteration of the interactive configuration process, specialized BDD algorithms compute the set of possible ways the current partial configuration can be extended to a valid product. The interactive configuration process is complete and backtrack-free. The user can choose freely between any valid configuration and is prevented from reaching dead-ends of impossible configurations. More importantly, the worst-case response time only grows polynomially with the size of the BDD. Thus, the computationally hard part of the configuration problem is fully solved in the offline phase given that the compiled BDD is small. Surprisingly this is often the case even for complex products with long compilation times. Our research has led to the establishment of a spin-off company called Configit Software A/S. Configit has improved the BDD-based technique and patented a particularly efficient symbolic representation called Virtual Tables (VTs). A VT is an XML file that in addition to the symbolic representation holds the definition of the information it stores. VTs can be embedded in a wide variety of products ranging from web-configurators to electronic products. The remainder of the paper is organized as follows. In Section 2, we formally define product configuration and describe the interactive configuration process. In Section 3, we show how to encode a solution space symbolically as a Boolean function and illustrate how this can be done with BDDs. In Section 4, we briefly introduce Configit’s approach and special features. Section 5 presents experimental work. Related work is discussed in Section 6. Finally in Section 7, we conclude and consider directions for future work.
2. INTERACTIVE PRODUCT CONFIGURATION We can think of product configuration as a process of specifying a product defined by a set of attributes, where attribute values can be combined only in predefined ways. Our formal definition captures this as a mathematical object with three elements: variables, domains for the variables defining the combinatorial space of possible assignments and formulae defining which combinations are valid assignments. Each variable represents a product attribute, variable domain refers to the options available for its attribute and formulae specify the rules that the product must satisfy. Definition 1. A configuration problem C is a triple ( X , D, F ) , where X is a set of variables x1 , x 2 , , x n , D is a Cartesian product of their finite domains D1 × D2 × × D n and F = { f1 , f 2 ,, f m } is a set of propositional formulas over atomic propositions xi = v , where v ∈ Di , specifying conditions that the variable assignments have to satisfy. Each formula f i is a propositional expression ϕ inductively defined by
ϕ ≡ xi = v | ϕ ∧ψ | ϕ ∨ψ | ¬ϕ , where v ∈ Di . We will use the abbreviation ϕ ψ ≡ ¬ϕ ∨ ψ for logical implication. For a configuration problem C, we define the solution space S(C) as the set of all valid configurations, i.e. the set of all assignments to the variables X that satisfy the rules F . Many interesting questions about configuration problems are hard to answer. Just determining whether the solution space is empty is NP-complete, since we can reduce the Boolean satisfiability problem to it in polynomial time [10]. As an example consider specifying a T-shirt by choosing the color (black, white, red or blue), the size (small, medium or large) and the print (“Men In Black” - MIB or “Save The Whales” – STW). There are two rules that we have to observe: if we choose the MIB print then the color black has to be chosen as well, and if we choose the small size then the STW print (including a big picture of a whale) cannot be selected as the large whale does not fit on the small shirt. The configuration problem ( X , D, F ) of the T-shirt example consists of variables X = {x1 , x 2 , x 3 } representing color, size and print. Variable domains are D1 = {black, white, red , blue} , D2 = {small, medium, large} and D3 = {MIB , STW } . The two rules translate to F = { f1 , f 2 } where f1 is (x 3 = MIB ) (x 1 = black ) and f 2 is (x 3 = STW ) (x 2 ≠ small ) . There are D1 D2 D3 = 24 possible assignments. Eleven of these assignments are valid configurations and they form the solution space shown in Figure 1. (black, small, MIB) (black, medium, MIB) (black, medium, STW) (black, large, MIB)
(black, large, STW) (white, medium, STW) (white, large, STW) (red, medium, STW)
(red, large, STW) (blue, medium, STW) (blue, large, STW)
Figure 1. Solution space for the T-shirt example. When we talk about interactive configuration, we are referring to the process of a user interactively tailoring a product to his specific needs by using supporting software called a configurator. Every time the user assigns a value to a variable, the configurator restricts the solution space by removing all assignments that violate this new condition, reducing the available
user choices to only those values that appear in at least one configuration in the restricted solution space. The user keeps selecting variable values until only one configuration is left. The algorithm in Figure 2 illustrates this interactive process. INTERACTIVE-CONFIGURATION(C) 1 Sol ← S (C ) 2 while Sol > 1 3 4
do choose ( x i = v ) ∈ VALID-ASS(Sol) Sol ← Sol Dx =v i
Figure 2. Interactive configuration procedure. The VALID-ASS(Sol) procedure in line 3 extracts the set of valid assignments (choices) from the solution space Sol. We restrict the solution space in line 4 by intersection with Dx =v = D1 × Di −1 × {v} × Di +1 × Dn , which effectively enforces that only those tuples with value v for xi remain in the solution space. This behavior of the configurator enforces a very important property of interactive configuration called completeness of inference. The user cannot pick a value that is not a part of a valid solution, and furthermore, a user is able to pick all values that are part of at least one valid solution. These two properties are often not satisfied in existing configurators, either exposing the user to backtracking or making some valid choices unavailable. In the T-shirt example, the assignment x 2 = small will, by the second rule, imply x3 ≠ STW and since there is only one possibility left for variable x3 , it follows that x3 = MIB . The first rule then implies x1 = black . Unexpectedly, we have completely specified a T-shirt by just one assignment. Actually, the configurator just deletes all configurations that do not satisfy x 2 = small and discovers that a solution space is reduced to just one tuple: (black, small, MIB) . From the user’s point of view, the configurator responds to the assignment by calculating valid choices for undecided variables. It is important that the response time is very short, offering the user truly interactive experience. The demand for short response-time and completeness of inference is difficult to satisfy due to the hardness of the configuration problem. i
3. TWO PHASE APPROACH Since checking whether the solution space is empty is NP-complete, it is unlikely that we can construct a configurator that takes a configuration problem C and guarantees a response time that is polynomially bounded with respect to the size of C. Our approach is offline to compile the solution space of a configuration problem to a representation that supports fast interaction algorithms. The idea is to remove the hard part of the problem in the offline phase. This will happen if the compiled representation is small. We cannot always avoid exponentially large representations. However, for most realworld problem instances, we get small representations and therefore fast interaction algorithms. Furthermore, after the compilation is finished, we know the size of the solution space representation. Therefore we are able to precisely predict the running time of the interaction algorithms.
3.1 Symbolic Solution Space Representation Our configuration problem C can be efficiently encoded using Boolean variables and Boolean functions. We assume that domains Di contain successive integers starting from 0. For example, we encode D2 = {small, medium, large} as D2 = {0,1,2} . Let li = ªlg | Di |º denote the number of bits required to encode a value in domain Di . Every value v ∈ Di can & be represented in a binary format and therefore seen as a vector of Boolean values v = (v li −1 , , v1 , v 0 ) ∈ B li . Analogously, & every variable xi can be encoded by a vector of Boolean &variables b = (bli −1 , , b1 , b0 ) . Now, the formula xi = v can be & represented as a Boolean function given by the expression b = v i.e. bli −1 = vli −1 ∧ ∧ b1 = v1 ∧ b0 = v 0 . In the T-shirt example, D2 = {small, medium, large} and l2 = ªlg 3º = 2 , so we can encode small ∈ D2 as 00 (b1 = 0, b0 = 0) , medium as 01 (b1 = 0, b0 = 1) and large as 10 (b1 = 1, b0 = 0) . This translation to a Boolean domain is not surjective, i.e. not every combination of assignments to Boolean variables bli −1 ,, b1 , b0 yields a valid value v ∈ Di . For example, the combination 11 does not encode a valid value in D2 . Therefore we introduce a Boolean constraint (a so called domain constraint) that forbids these unwanted combinations FD = ∧ ni=1 (∨ v∈D xi = v) . Furthermore, we define a translation function τ that maps a propositional expression ϕ to the Boolean function it represents i
n
τ (ϕ ) : ∏ B l → B . i
The translation is defined inductively as follows
i =1
& & IJ x =v ≡ b =v i i IJ (ϕ ∧ ȥ ) ≡ IJ (ϕ ) ∧ IJ (ȥ )
(
)
(
)
IJ (ϕ ∨ ȥ ) ≡ IJ (ϕ ) ∨ IJ (ȥ ) IJ (¬ϕ )
≡ ¬IJ (ϕ ).
Finally, we are able to express a Boolean function representation S ′(C ) of the solution space S(C) S ′(C ) ≡ ∧ mi=1τ ( f i ) ∧ τ (FD ) .
The interactive process of product configuration can be represented using the already described procedure (Figure 2), but now using the Boolean representation of the solution space. The resulting algorithm is shown in Figure 3. INTERACTIVE-CONFIGURATION(C) 1 Sol ← S ′(C ) 2 while Sol > 1 do choose ( x i = v ) ∈ VALID-ASS(Sol) Sol ← Sol ∧ τ ( x i = v )
3 4
Figure 3. Boolean version of interactive configuration.
3.2 Binary Decision Diagrams A reduced ordered Binary Decision Diagram (BDD) is a rooted directed acyclic graph representing a Boolean function on a set of linearly ordered Boolean variables. It has one or two terminal nodes labeled 1 or 0 and a set of variable nodes. Each variable node is associated with a Boolean variable and has two outgoing edges low and high. Given an assignment of the variables, the value of the Boolean function is determined by a path starting at the root node and recursively following the high edge, if the associated variable is true, and the low edge, if the associated variable is false. The function value is true, if the label of the reached terminal node is 1; otherwise it is false. The graph is ordered such that all paths respect the ordering of the variables. A BDD representing the function f (x1 , x 2 ) = x1 ∨ ¬x1 ∧ ¬x 2 is shown Figure 4a. A BDD is reduced such that no two distinct nodes u and v are associated with the same variable and low and high successors (Figure 4b), and no variable node u has identical low and high successors (Figure 4c).
xx11 x2
1
u
v
u
xx1
xx1
xx1
0 (a)
(b)
(c)
Figure 4. (a) A BDD representing the function f (x1 , x 2 ) = x1 ∨ ¬x1 ∧ ¬x 2 . High and low edges are drawn with solid and dashed lines, respectively. (b) Nodes associated with the same variable with equal low and high successors will be converted to a single node. (c) Nodes causing redundant tests on a variable are eliminated. Due to these reductions, the number of nodes in a BDD for many functions encountered in practice is often much smaller than the number of truth assignments of the function. Another advantage is that the reductions make BDDs canonical [2]. Large space savings can be obtained by representing a collection of BDDs in a single multi-rooted graph where the subgraphs of the BDDs are shared. Due to the canonicity, two BDDs are identical if and only if they have the same root. Consequently, when using this representation, equivalence checking between two BDDs can be done in constant time. In
addition, BDDs are easy to manipulate. Any Boolean operation on two BDDs can be carried out in time proportional to the product of their size. The size of a BDD can depend critically on the variable ordering. To find an optimal ordering is a co-NP-complete problem in itself [2], but a good heuristic for choosing an ordering is to locate dependent variables close to each other in the ordering. For a comprehensive introduction to BDDs and branching programs in general, we refer the reader to Bryant’s original paper [2] and the books [13, 18].
3.3 BDD-Based Interactive Configuration ~ In the offline phase of BDD-based interactive configuration, we compile a BDD S (C ) of the Boolean function ~ representation S ′(C ) of the solution space. The variable ordering of S (C ) is identical to the ordering of the Boolean ~ variables of S ′(C ) . S (C ) can be compiled using a BDD version τ~ of the function τ , where each Boolean operation is translated to its corresponding BDD operation τ~ ( xi = v ) ≡ BDD of τ ( xi = v ) τ~ (ϕ ∧ ψ ) ≡ Op ∧ (τ~ (ϕ ), τ~ (ψ )) τ~ (ϕ ∨ ψ ) ≡ Op ∨ (τ~ (ϕ ), τ~ (ψ )) ≡ Op (τ~ (ϕ )). τ~ (¬ϕ ) ¬
In the base case, τ~( xi = v ) denotes a BDD of the Boolean function τ (x i = v ) as defined in Section 3.1. For each of the inductive cases, we first compile a BDD for each sub-expression and then perform the BDD operation corresponding to the Boolean operation on the sub-expressions. We have ~ S (C ) ≡ Op ∧ (τ~ (FD ),τ~ ( f 1 ), ,τ~ ( f m )) . ~ Due to the polynomial complexity of BDD-operations, the complexity of computing S (C ) may be exponential in the size of C. A version of the INTERACTIVE-CONFIGURATION procedure shown in Figure 3, where the Boolean functions are represented by BDDs, is used in the online phase. Each Boolean operation of this procedure is translated to its corresponding BDD operation. The response time of the procedure is determined by the complexity of performing a single iteration of the procedure. All sub-operations can be done in time linear in the size of Sol except VALID-ASS in Line 3. This procedure can be realized by a specialized BDD operation with worst-case complexity § O¨ ¨ ©
n
¦V i =1
i
· Di ¸ , ¸ ¹
where Vi denotes the nodes in Sol associated with BDD variables encoding the domain of variable x i . As usual, Di denotes the domain of x i . For each value of each variable the procedure tracks whether the value is encoded by Sol. Due to the ordering of the BDD variables, for each variable x i , this tracking can be constrained to the nodes Vi . 4. CONFIGIT SOFTWARE Configit Product Modeller (Configit-PM) is a software product for interactive configuration developed and distributed by Configit software [4]. Configit-PM requires product models to be specified in its own strongly typed language. The language is simple but expressive enough to handle the product models occurring in real-life modeling applications. Configit-PM also has a compiler which first checks for the semantic correctness of the product model. If the semantics is valid then it creates a virtual table (VT) that contains all valid solutions of the product model. VTs are stored in XML format. Details about the variables in the product model including their domain sizes are stored in a header part of the VT file. The header is followed by a BDD derived data structure that represents the valid solutions of the product model. All the information necessary to configure a product is embedded in a single VT file. Using Configit-PM, a preferred interface can be created to interact with the VT file for configuring a product. The Configit-PM also has a built-in simulator, PM-Viewer, which can be used to interact and configure products. PM-Viewer can be used to select a value for each variable in the product model. It also has an undo facility to go back and forth between selections. Implications of the user selections will be shown as forced selections. The user need not have to select values for all the variables. After selecting a value for zero or more variables, the user can request the PM-Viewer to complete the rest of the options automatically. The PM-Viewer can also give explanations for all the forced selections. When the user wishes to select an invalidated value of a variable, the PM-Viewer will show a list of previous choices to be undone to resolve the conflict.
5. EXPERIMENTAL WORK In this section we present experiments we have carried out using Configit-PM. The results are listed in Table 1. First column lists a benchmark name. Four benchmarks were used in the experiments. Three successive columns list the time taken for generating the corresponding VT, the size of the VT, and, the number of valid configurations (#Solutions), respectively. Last column shows the average response time over 1000 random requests on the generated VT. Each request corresponds to an iteration of the INTERACTIVE-CONFIGURATION procedure. The Renault benchmark represents a car configuration problem used in [1]. The PSR benchmark represents a power supply restoration (PSR) problem. Information about the PSR problem is available in [16]. PC is a benchmark distributed by Configit [4] along with Configit-PM. It represents a personal computer configuration problem. Parity represents a parity learning problem as a configuration instance. Information about this problem is available in [7]. The results show that even though a problem may take long time to compile in the offline phase, it may result in a small VT that gives very short response times in the online phase. This is in particular true for the Renault benchmark. Also notice that VTs due to the symbolic encoding may represent large solution spaces very compactly. Benchmark Renault PSR PC Parity
Time (sec) 460.00 0.38 0.89 30.00
Virtual Table Size (KB) #Solutions 1292 2.8x1012 37 24 1219
Average Response Time (sec) 0.127
9
0.001
6
0.075
6
0.096
7.7x10
1.1x10
198x10
Table 1. Experimental results on four benchmark problems.
6. RELATED WORK Related work can broadly be classified into search-methods based on Constraint Satisfaction Problems (CSPs) [9] and Boolean satisfiability formulations [14], and, compilation methods using data structures like acyclic constraint networks [5, 6] and Automata [1]. In this section we give an overview of some of them. In [8], the authors propose a preprocessing method to convert a CSP into another one, having Backtrack-Free problem Representation (BFR). The BFR can then be used for interactive configuration. Unlike conventional preprocessing methods which add additional constraints and hence increase the size of the problem representation, their method does not add any additional constraints. Instead, they restrict the domain of variables, such that a BFR is obtained. The main drawback of this approach is that the BFR does not contain all valid solutions. They give a guarantee that their preprocessor will give an error message if all solutions are removed by it. Although the authors claim that deletion of some valid solutions by their preprocessing step is acceptable in many cases, hiding even a single valid solution from the user is questionable. Although their representation is backtrack-free like our BDD-based method, some solutions are lost and hence their method is not preferable in real-life product configuration systems. In [9], the authors use consistency methods to obtain explanations and implications for a configurator based on a CSP representation. They use the N-Queens problem to demonstrate their method. It is like other CSP-based search methods, which solve an intractable problem every time the user makes a request. In [18], the authors presented Minimal Synthesis Trees (MSTs), a data structure to compactly represent the set of all solutions in a CSP. It takes advantage of combining the consistency techniques with a decomposition and interchangeability idea. Unlike our approach, which generates worst case exponential-size BDDs, the MST is a polynomial-size structure. Operations on the MSTs, however, are of exponential time complexity while they are of polynomial complexity in our approach. In [14], the authors present an approach to the configuration problem based on a Boolean Satisfiability (SAT) solver. They have developed a non-interactive configuration system (BIS) based on a new SAT solver designed by them. The BIS system was developed for a commercial car manufacturer. Although their technique can be extended to an interactive configuration method, it will not move the intractability of the configuration process into an offline activity. The problem with search-based methods is that the intractability of the configuration problem is solved every time the user gives a request to the configurator. In case of compilation techniques, the advantage is that the compilation process may be intractable but once the valid solutions are compiled into an efficient data structure, the interaction process is efficient.
Acyclic constraint networks and the Tree clustering algorithm [5, 6] represent a CSP solution space in a more compact way, organizing it as a tree of solved sub-problems. The generated structure offers polynomial time guarantees for extracting a solution in the size of the generated structure. The size of the sub-problems, however, cannot be controlled for all instances and might lead to an exponential blow-up. The complexity of the original problem is dominated by the complexity of the sub-problems, which are exponential in both space and time. Nevertheless, this is one of the first compilation approaches used to solve CSP problems. There are efforts to cope with this exponential blow-up by additional compression using Cartesian product representation [12]. In [1], the authors present a method which compiles all valid solutions of a configuration problem into an automaton. After compiling the solutions into an automaton, functions required for interactive configuration, like implications, explanations, and valid-domain-calculations can be done efficiently. They also present a theoretical view of all the complexity issues involved in their approach. They show that all the tasks involved in an interactive configuration process are intractable in the worst case. They claim that intractability can be circumvented by compiling configuration problems into an automaton. That is, moving the intractable part of the problem into an offline compilation process. Technically this work is the closest one to our approach. They use automaton to represent valid configurations, where we use BDDs. The two approaches to two-phase interactive configuration may perform equally well. However, a major advantage of using BDDs is that this data structure has been studied intensely in formal verification for representing formal models of large systems [3, 19]. In particular, the variable ordering problem is well studied [13]. Furthermore a range of powerful software packages have been developed for manipulating BDDs [11, 15]. To our knowledge, the automata approach has not reached this level of maturity.
7. CONCLUSION In this paper we have demonstrated how to solve the computationally hard interactive configuration problem by dividing it into two phases. First, in an offline phase, we compile the solution space of the problem to a Boolean domain using BDDs as underlying data structure. Second, if the resulting BDD is small enough, we achieve fast algorithms for interactive configuration in an online phase while providing user-friendly requirements such as completeness of inference. The experimental results indicate that BDDs representing the solution space of real-world configuration problems are often small and enable very short response times in the online interactive configuration phase. Future work includes combining our approach with the state-of-the-art search-based techniques for solving the configuration problem. We also plan to generate more experimental results using benchmarks from different application domains.
REFERENCES 1.
J. Amilhastre, H. Fargier, P.Marquis: Consistency restoration and explanations in dynamic CSPs—application to configuration. Artificial Intelligence, 135(1-2), 199-234, 2002
2.
R. Bryant: Graph-Based Algorithms for Boolean Function Manipulation. IEEE Transactions on Computers. Vol. C35, No. 8, 677-691, 1986.
3.
J. R. Burch, E. M. Clarke, K. McMillan: Symbolic model checking: 1020 states and beyond. In Proceedings of the 5th Annual IEEE Symposium on Logic in Computer Science, pages 428–439, 1990.
4.
Configit website : www.configit-software.com
5.
R. Dechter, J. Pearl: Network-based heuristics for constraint-satisfaction problems. Artificial Intelligence. Vol. 34 No. 1, 1-38, 1987
6.
R. Dechter, J. Pearl: Tree-Clustering Schemes for Constraint-Processing. Artificial Intelligence. Vol. 38(3), 353-366, 1989
7.
ftp://dimacs.rutgers.edu/pub/challenge/satisfiability/contributed/crawford/README
8.
E.C.Freuder, T.Carchrae, J.C.Beck: Satisfaction Guaranteed in Workshop on Configuration, Eighteenth International Joint Conference on Artificial Intelligence, 2003
9.
E. C. Freuder, C. Likitvivatanavong, R. J. Wallace: Explanation and Implication for Configuration Problems in IJCAI2001 Workshop on Configuration, Seattle, WA, August 2001, 2001
10. M.R. Garey, D.S. Johnson: Computers and Intractability-A Guide to the Theory of NP-Completeness, W H Freeman & Co, 1979 11. J. Lind-Nielsen: BuDDy - A Binary Decision Diagram Package. Technical Report IT-TR: 1999-028, Institute of Information Technology, Technical University of Denmark, 1999. http://cs.it.dtu.dk/buddy. 12. J. N. Madsen: Methods for Interactive Constraint Satisfaction. M.Sc. Thesis, Department of Computer Science, University of Copenhagen. 2003. http://www.diku.dk/forskning/performance-engineering/jeppe/ 13. C. Meinel, T. Theobald: Algorithms and Data Structures in VLSI Design. Springer, 1998 14. C. Sinz, A. Kaiser, W. Küchlin: Formal methods for the validation of automotive product configuration data. Artificial Intelligence for Engineering Design, Analysis and Manufacturing, 17(1):75-97, January 2003. Special issue on configuration. 15. F. Somenzi: CUDD: Colorado university decision diagram package. ftp://vlsi.colorado.edu/pub/, 1996. 16. S. Thiebaux, M. O. Cordie: Supply restoration in power distribution systems a benchmark for planning under uncertainty. In Pre-Proceedings of the 6th European Conference on Planning (ECP-01), 85-96, 2001 17. I.Wegener: Branching Programs and Binary Decision Diagrams. Society for Industrial and Applied Mathematics (SIAM), 2000 18. R. Weigel, B. Faltings: Compiling constraint satisfaction problems. Artificial Intelligence 115(2): 257-287 (1999) 19. B. Yang, et.al,:A Performance Study of BDD-Based Model Checking. Proceedings of the Second International Conference on Formal Methods in Computer-Aided Design, 255 - 289, 1998
Comparing Two Implementations of a Complete and Backtrack-Free Interactive Configurator Sathiamoorthy Subbarayan1 , Rune M. Jensen1 , Tarik Hadzic1 , Henrik R. Andersen1 , Henrik Hulgaard2 , and Jesper Møller2 1
Department of Innovation, IT University of Copenhagen, Rued Langgaards Vej 7, DK-2300 Copenhagen S, Denmark {sathi,rmj,tarik,hra}@itu.dk 2 Configit Software A/S, Vermundsgade 38 B, DK-2100 Copenhagen Ø, Denmark {jm,henrik}@configit-software.com
Abstract. A product configurator should be complete and backtrack free in the sense that the user can choose freely between any valid configuration and will be prevented from making choices that no valid configuration satisfies. In this paper, we experimentally evaluate a symbolic and search-based implementation of an interactive product configuration algorithm with these properties. Our results show that the symbolic approach often has several orders of magnitude faster response time than the search-based approach due to the precompilation of a symbolic representation of the solution space. Moreover, the difference between the average and worst response time for the symbolic approach is typically within a factor of two, whereas it for the search-based approach may be more than two orders of magnitude.
1
Introduction
Product configuration involves two major tasks: to define a modeling language that makes it easy to specify and maintain a formal product model and to develop a decision support tool that efficiently guides users to desirable product configurations [1]. In this paper we focus on the latter task and investigate a complete and backtrack-free approach to Interactive Product Configuration (IPC). The input to our IPC algorithm is a product model that consists of a set of product variables with finite domains and a set of product rules. A valid product configuration is an assignment to each variable that satisfies the product rules. The IPC algorithm initially has an empty set of user selected assignments. In each iteration of the algorithm, invalid values in the domain of the variables are pruned away such that each value in the domain of a variable is part of at least one valid configuration satisfying the existing set of assignments. The user then selects his preferred value for any free variable. The algorithm terminates when each variable in the product model is assigned a value. The IPC algorithm is complete in the sense that the user can choose freely between any valid configuration. It is also backtrack-free since the user is prevented from
choosing a variable assignment for which no valid configuration exists. Hence the algorithm never forces the user to go back to a previous configuration state to explore alternative choices. In this paper we experimentally evaluate a symbolic and search-based implementation of the IPC algorithm. The symbolic implementation is using a two-phase approach [2]. In the first phase, the product rules are compiled into a reduced ordered Binary Decision Diagram (BDD) [3] representing the set of valid configurations (the solution space). In the second phase, a fast specialized BDD operation is used to prune the variable domains. The worst-case response time only grows polynomially with the size of the BDD. Thus, the computationally hard part of the configuration problem is fully solved in the offline phase given that the compiled BDD is small. The search-based implementation prunes variable domains by iterating over each possible assignment and searching for a valid configuration satisfying it. This approach can be improved by memorizing all assignments for which no solution exist across iterations and, within each iteration, adding all assignments in a found solution (not just the one being verified). The symbolic approach has been implemented using Configit Developer 3.2 [4] that employs a BDD-derived symbolic representation called Virtual Tables (VTs). The search-based approach has been implemented using ILOG Solver 5.3 [5]. We have developed a publicly available benchmark suite called CLib [6] for the experiments that consists of 14 configuration problems. Our results show that the symbolic approach often has several orders of magnitude faster response time than the search based approach. In addition, the difference between average and worst response time is often within a factor of two for the symbolic approach, but some times more than two orders of magnitude for the search-based approach. Moreover, our results indicate that the configuration space of industrial configuration problems often have small symbolic representations. This result is somewhat surprising since BDDs blow up for many combinatorial problems investigated in AI (e.g., the n-queens problem and other permutation problems). It may be the frequent hierarchical structure of real-world configuration problems that make them particularly well-suited for BDDs. The remainder of the paper is organized as follows. In Sect. 2, we define product configuration and describe the IPC algorithm. The symbolic and searchbased implementation of the IPC algorithm are described in Sect. 3 and Sect. 4, respectively. We focus on describing the symbolic implementation since we assume that the search-based implementation is straight forward for most readers. Section 5 presents experimental work. Finally, we describe related work in Sect. 6 and draw conclusions in Sect. 7.
2
Interactive Product Configuration
We can think of product configuration as a process of specifying a product defined by a set of attributes, where attribute values can be combined only in predefined ways. Our formal definition captures this as a mathematical object
with three elements: variables, domains for the variables defining the combinatorial space of possible assignments and formulas defining which combinations are valid assignments. Each variable represents a product attribute. The variable domain refers to the options available for its attribute and formulas specify the rules that the product must satisfy. Definition 1. A configuration problem C is a triple (X, D, F ), where X is a set of variables x1 , x2 , · · · , xn , D is the Cartesian product of their finite domains D1 × D2 × · · · × Dn , and F = {f1 , f2 , · · · , fm } is a set of propositional formulas over atomic propositions xi = v, where v ∈ Di , specifying conditions that the variable assignments must satisfy. Each formula fi is a propositional expression inductively defined by φ ≡ xi = v | φ ∧ ψ | φ ∨ ψ | ¬φ,
(1)
where v ∈ Di . We use the abbreviation φ ⇒ ψ ≡ ¬φ ∨ ψ for logical implication. For a configuration problem C, we define the solution space S(C) as the set of all valid configurations, i.e. the set of all assignments to the variables X that satisfy the rules F . Many interesting questions about configuration problems are hard to answer. Just determining whether the solution space is empty is NP-complete, since the Boolean satisfiability problem can be reduced to it in polynomial time. Example 1. Consider specifying a T-shirt by choosing the color (black, white, red, or blue), the size (small, medium, or large) and the print (”Men In Black” - MIB or ”Save The Whales” - STW). There are two rules that we have to observe: if we choose the MIB print then the color black has to be chosen as well, and if we choose the small size then the STW print (including a big picture of a whale) cannot be selected as the large whale does not fit on the small shirt. The configuration problem (X, D, F ) of the T-shirt example consists of variables X = {x1 , x2 , x3 } representing color, size and print. Variable domains are D1 = {black , white, red , blue}, D2 = {small , medium, large}, and D3 = {MIB , STW }. The two rules translate to F = {f1 , f2 }, where f1 = (x3 = MIB ) ⇒ (x1 = black ) and f2 = (x3 = STW ) ⇒ (x2 = small ). There are |D1 ||D2 ||D3 | = 24 possible assignments. Eleven of these assignments are valid configurations and they form the solution space shown in Fig. 1. ♦
(black , small , MIB ) (black , medium, MIB ) (black , medium, STW ) (black , large, MIB )
(black , large, STW ) (white, medium, STW ) (white, large, STW ) (red , medium, STW )
(red , large, STW ) (blue, medium, STW ) (blue, large, STW )
Fig. 1. Solution space for the T-shirt example
By interactive product configuration we refer to the process of a user interactively tailoring a product to his specific needs by using supporting software
called a configurator. Every time the user assigns a value to a variable, the configurator restricts the possible solutions to configurations consistent with this new condition. The user keeps selecting variable values until only one configuration is left. The IPC algorithm in Fig. 2 illustrates this interactive process. In line 1, the configurator takes a given configuration problem C and compiles IPC(C) 1 R ← Compile(C) 2 while |R| > 1 3 do choose (xi = v) ∈ Valid-Assignments(R) 4 R ← R|xi =v Fig. 2. The IPC Algorithm
it into an internal representation R. The procedure Valid-Assignments(R) in line 3 extracts the set of valid assignments (choices) from the internal representation. In line 4, the internal representation is restricted to configurations satisfying the new condition. This behavior of the configurator enforces a very important property of interactive configuration called completeness of inference. The user cannot pick a value that is not a part of a valid solution, and furthermore, a user is able to pick all values that are part of at least one valid solution. These two properties are often not satisfied in existing configurators, either exposing the user to backtracking or making some valid choices unavailable. The symbolic and search-based implementation of the IPC algorithm differ in their internal representation and implementation of the valid assignment and restrict operations. Example 2. For the T-shirt problem, the assignment x2 = small will, by the second rule, imply x3 = STW and since there is only one possibility left for variable x3 , it follows that x3 = MIB . The first rule then implies x1 = black . Unexpectedly, we have completely specified a T-shirt by just one assignment. ♦ From the user’s point of view, the configurator responds to the assignment by calculating valid choices for undecided variables. It is important that the response time is very short, offering the user a truly interactive experience. The demand for short response-time and completeness of inference is difficult to satisfy due to the hardness of the configuration problem.
3
Symbolic Implementation of the IPC Algorithm
Since checking whether the solution space is empty is NP-complete, it is unlikely that we can construct a configurator that takes a configuration problem and guarantees a response time that is polynomially bounded with respect to its size. The symbolic approach is offline to compile the configuration problem to
a representation of the solution space that supports fast interaction algorithms. The idea is to remove the hard part of the problem in the offline phase. This will happen if the compiled representation is small. We cannot, however, in general avoid exponentially large representations. 3.1
Symbolic Solution Space Representation
A configuration problem can be efficiently encoded using Boolean variables and Boolean functions. We assume that domains Di contain successive integers starting from 0. For example we encode D2 = {small , medium, large} as D2 = {0, 1, 2}. Let li = lg |Di | denote the number of bits required to encode a value in domain Di . Every value v ∈ Di can be represented in binary as a vector of Boolean values v = (vli −1 , · · · , v1 , v0 ) ∈ Bli . Analogously, every variable xi can be encoded by a vector of Boolean variables b = (bli −1 , · · · , b1 , b0 ). Now, the formula xi = v can be represented as a Boolean function given by the expression bli −1 = vli −1 ∧ · · · ∧ b1 = v1 ∧ b0 = v0 (written b = v). For the T-shirt example we have, D2 = {small , medium, large} and l2 = lg 3 = 2, so we can encode small ∈ D2 as 00 (b1 = 0, b0 = 0)) , medium as 01 and large as 10. The translation to a Boolean domain is not surjective. There may exist assignments to the Boolean variables yielding invalid values. For example, the combination 11 does not encode a valid value in D2 . Therefore weintroduce a domain n constraint that forbids these unwanted combinations FD = i=1 ( v∈Di xi = v). Furthermore, we define a translation function τ that maps a propositional expression φ to the Boolean function it represents τ (φ) :
n
Bli → B.
(2)
i=1
The translation is defined inductively as follows τ (xi = v) ≡ (bi = v) τ (φ ∧ ψ) ≡ τ (φ) ∧ τ (ψ) τ (φ ∨ ψ) ≡ τ (φ) ∨ τ (ψ) τ (¬φ) ≡ ¬τ (φ).
(3) (4) (5) (6)
Finally we can express a Boolean function representation S (C) of the solution space S(C). m τ (fj ). (7) S (C) ≡ τ (FD ) ∧ j=1
The resulting symbolic implementation of the IPC algorithm is shown in Fig. 3. In this implementation, the internal representation is a Boolean encoding Sol of the solution space. In order to restrict the solution space in line 4, it is conjoined with the Boolean encoding of the assignment chosen by the user.
Symbolic-IPC(C) 1 Sol ← S (C) 2 while |Sol | > 1 3 do choose (xi = v) ∈ Valid-Assignments(Sol ) 4 Sol ← Sol ∧ τ (xi = v) Fig. 3. Symbolic implementation of the IPC algorithm
3.2
Binary Decision Diagrams
A reduced ordered Binary Decision Diagram (BDD) is a rooted directed acyclic graph representing a Boolean function on a set of linearly ordered Boolean variables. It has one or two terminal nodes labeled 1 or 0 and a set of variable nodes. Each variable node is associated with a Boolean variable and has two outgoing edges low and high. Given an assignment of the variables, the value of the Boolean function is determined by a path starting at the root node and recursively following the high edge, if the associated variable is true, and the low edge, if the associated variable is false. The function value is true, if the label of the reached terminal node is 1; otherwise it is false. The graph is ordered such that all paths respect the ordering of the variables. A BDD is reduced such that no pair of distinct nodes u and v are associated with the same variable and low and high successors (Fig. 4a), and no variable node u has identical low and high successors (Fig. 4b). Due to these reductions,
u
v
u
x
x
x
(a)
(b)
Fig. 4. (a) nodes associated to the same variable with equal low and high successors will be converted to a single node. (b) nodes causing redundant tests on a variable are eliminated. High and low edges are drawn with solid and dashed lines, respectively
the number of nodes in a BDD for many functions encountered in practice is often much smaller than the number of truth assignments of the function. Another advantage is that the reductions make BDDs canonical [3]. Large space savings can be obtained by representing a collection of BDDs in a single multi-rooted
graph where the sub-graphs of the BDDs are shared. Due to the canonicity, two BDDs are identical if and only if they have the same root. Consequently, when using this representation, equivalence checking between two BDDs can be done in constant time. In addition, BDDs are easy to manipulate. Any Boolean operation on two BDDs can be carried out in time proportional to the product of their size. The size of a BDD can depend critically on the variable ordering. To find an optimal ordering is a co-NP-complete problem in itself [3], but a good heuristic for choosing an ordering is to locate dependent variables close to each other in the ordering. For a comprehensive introduction to BDDs and branching programs in general, we refer the reader to Bryant’s original paper [3] and the books [7, 8]. 3.3
BDD-Based Implementation of the IPC Algorithm
In the offline phase of BDD-based interactive configuration, we compile a BDD ˜ S(C) of the Boolean function S (C) of the solution space. The variable ordering ˜ of Boolean variables of S(C) is identical to the ordering of the Boolean variables ˜ of S (C). S(C) can be compiled using a BDD version τ˜ of the function τ , where each Boolean operation is translated to its corresponding BDD operation τ˜(xi = v) ≡ BDD of τ (xi = v) τ˜(φ ∧ ψ) ≡ Op∧ (˜ τ (φ), τ˜(ψ)) τ˜(φ ∨ ψ) ≡ Op∨ (˜ τ (φ), τ˜(ψ)) τ˜(¬φ) ≡ Op¬ (˜ τ (φ)).
(8) (9) (10) (11)
In the base case (8), τ˜(xi = v) denotes a BDD of the Boolean function τ (xi = v) as defined in Sec. 3.1. For each of the inductive cases, we first compile a BDD for each sub-expression and then perform the BDD operation corresponding to the Boolean operation on the sub-expressions. We have ˜ S(C) ≡ Op∧ (˜ τ (FD ), τ˜(f1 ), · · · , τ˜(fm )).
(12)
Due to the polynomial complexity of BDD operations, the complexity of com˜ puting S(C) may be exponential in the size of C. Example 3. The BDD representing the solution space of the T-shirt example introduced in Sect. 2 is shown in Fig. 5. In the T-shirt example there are three variables: x1 , x2 and x3 , whose domain sizes are four, three and two, respectively. As explained in Sect. 3.1, each variable is represented by a vector of Boolean variables. In the figure the Boolean vector for the variable xi with domain Di is (xili −1 , · · · , x1i , x0i ), where li = lg |Di |. For example, in the figure, variable x2 which corresponds to the size of the T-shirt is represented by the Boolean vector (x12 , x02 ). In the BDD any path from the root node to the terminal node 1, corresponds to one or more valid configurations. For example, the path from the root node to the terminal node 1, with all the variables taking low values represents the valid configuration (black , small , MIB ). Another path with x11 , x01 ,
and x12 taking low values, and x02 taking high value represents two valid configurations: (black , medium, MIB ) and (black , medium, STW ), namely. In this path the variable x03 is a don’t care variable and hence can take both low and high value, which leads to two valid configurations. Any path from the root node to the terminal node 0 corresponds to invalid configurations. ♦
x11 x01 x12 x02
x12 x02
x02
x02 x03
x03
1
0
Fig. 5. BDD of the solution space of the T-shirt example. Variable xji denotes bit bj of the Boolean encoding of product variable xi .
For a BDD version of the Symbolic-IPC algorithm, each Boolean operation is translated to its corresponding BDD operation. The response time is determined by the complexity of performing a single iteration of the procedure. All sub-operations can be done in time linear in the size of Sol except ValidAssignments in Line 3. This procedure can be realized by a specialized BDD operation with worst-case complexity n |Vi ||Di |), O(
(13)
i=1
where Vi denotes the nodes in Sol associated with BDD variables encoding the domain of variable xi . As usual, Di denotes the domain of xi . For each value of each variable, the procedure tracks whether the value is encoded by Sol. Due to the ordering of the BDD variables, for each variable xi , this tracking can be constrained to the nodes Vi .
4
Search-based Implementation of the IPC Algorithm
Search-based approaches like SAT techniques or CSP techniques can also be used to implement the IPC algorithm. In such cases the first step of the algorithm is to compile the configuration problem into an internal representation used by the applied search technique. The internal representation implicitly represents the set of valid configurations. The iterative step of the IPC algorithm is repeated until all the variables in the product model are assigned a value. For search-based techniques, the procedure for calculating Valid-Assignments is theoretically intractable. Every time an assignment is made, propagation is applied to prune the invalid values in the domain of all unselected variables. This can be done by checking whether each value in the domain of all the variables has at least one valid configuration satisfying the existing set of variable assignments. In the m worst case, the search-based configurator has to find 1 − m + i=1 di solutions for each iteration, where m is the number of unassigned variables during the iteration, and di is the domain size of the unassigned variable i during the iteration. Improved average complexity of Valid-Assignments can be obtained by memorizing invalid variable values. Since the solution space keeps decreasing, an invalid value will remain invalid in later iterations. In addition, within each iteration, whenever the search-based IPC finds a solution, it can mark all the assignments in the solution as valid. This can remove redundant search for solutions.
5
Experimental Evaluation
We use Configit Developer 3.2 [4] for the symbolic implementation of the IPC algorithm. Configit Developer has a compiler which first checks for the semantic correctness of the product model. If the semantics is valid, it creates a Virtual Table (VT) that symbolically represents all valid solutions of the product model. For the search-based implementation of the IPC algorithm we use ILOG Solver 5.3 [5]. ILOG Solver is a commercial constraint programming based C++ library for solving constraint satisfaction/optimization problems. In a comparative study, it has been shown to outperform a range of other CSP solvers [9]. The source code of our benchmarks for ILOG Solver has been constructed to the best of our knowledge. But we are not experts on the ILOG Solver technology and there may exist more efficient implementations. ILOG Configurator [5] is another product from the same company which uses ILOG Solver for configuration problems. ILOG Configurator, however, only does set bound propagation. This means that it may be possible for a user to choose assignments for which no valid configuration exists if the ILOG Configurator is used for interactive configuration. For each configuration benchmark used in the experiments, 1000 random requests are generated using Configit Developer. There are several cycles of requests. Each cycle contains a sequence of requests in increasing order. Each request consists of a set of assignments to some of the variables in the product
model. Each cycle of requests simulates an interactive configuration process of a product. All the experiments were carried out on a Pentium-III 1 GHz machine with 2GB of memory, running Linux. The benchmarks used in the experiments are available in the CLib benchmark suite [6] in the Configit input language and the ILOG Solver source language. The results are shown in Table 1. The first column in the table lists the name of the benchmark. The second column lists the amount of CPU time in seconds used by Configit Developer for generating the corresponding VT file. The third column lists the size of the generated VT file in Kilo Bytes (KB). As for BDDs (see Sect. 3), the variable ordering plays a crucial role in the size of the VT files generated. Unless specified, the default variable order was used in the experiments. The fourth column lists the number of solutions (#Sol) in the generated VT file. After generating a VT, the number of solutions represented by it can easily be counted. This is equivalent to the total number of valid configurations for the instance. In the subsequent four columns, the CPU time for Average response (Avg. RT) and Worst response (Wst. RT) are listed in seconds for both Configit Developer and ILOG Solver. The response times listed for Configit Developer include the time taken for the requests generation and writing the requests into a file. The corresponding times listed for ILOG Solver only include the time taken for reading the requests information from the file. Requests are generated as specified above. Table 1. Experimental Results Virtual Table Benchmark
Avg. RT (sec) Wst. RT (sec)
Time(sec) Size(KB) #Sol Configit ILOG Configit Renault 460.00 1292 2.8x1012 0.1273 489.29* 0.240 Bike 0.45 22 1.3x108 0.0005 1.855 0.010 PC 0.89 24 1.1x106 0.0007 1.302 0.010 PSR 0.38 37 7.7x109 0.0014 2.398 0.010 Parity32 13 30.00 1219 2.0x108 0.0960 0.061 0.416 Big-PC 14.82 76 6.2x1019 0.0012 0.010 v1 5.67† 253 8.2x10123 0.1620 0.320 w1 56.52† 1347 1.0x1089 0.0680 0.160 ESVS 0.25 6.7 3.5x109 0.0004 0.059 0.010 FS 0.25 5.8 2.4x107 0.0003 0.036 0.010 FX 0.22 5.3 1.2x106 0.0003 0.029 0.010 Machine 0.14 6.7 4.7x108 0.0004 0.009 0.010 C169 FV 2.30 (144) 287 3.2x1015 0.0134 0.195 0.010 C211 FS 6.93 (957) 370 1.4x1067 0.0219 0.314 0.020 C250 FW 3.22 (111) 308 1.2x1037 0.0148 0.203 0.010 C638 FVK 16.53 (1980) 534 8.8x10123 0.0385 0.608 0.050 *For finding one solution only (i.e., not complete). † The variable order file has been provided by Configit Software.
ILOG 489.29* 882.68 2.12 486.12 0.24
0.14 0.21 0.10 0.03 28.77 67.09 38.98 72.62
The Renault car configuration benchmark is described in [10]. Configit Developer takes 460 seconds to generate the VT file containing 2.8x1012 solutions for the Renault instance. But ILOG Solver takes 489 seconds just to solve the problem represented as a CSP instance. The average response time obtained for Renault by Configit Developer is 0.1273 second. Corresponding worst response time is 0.240 second. The Bike and PC instances are configuration examples provided along with Configit Developer. They represent a bike and a personal computer configuration problem. The size of the PC and Bike instances in the Configit language is around 500 and 700 lines of code, respectively. In both cases, the average response time for Configit Developer is only a fraction of a millisecond. This is possible as the sizes of the corresponding VT files are very small. The corresponding worst response time for those two instances are 10 milliseconds only. But the average and worst response times for ILOG Solver are comparatively very high. The worst response time for ILOG Solver in case of Bike is 882.68 seconds, which is more than 400 times the corresponding average response time. In case of the PC example, there is not a large difference between the average and the worst response time of ILOG Solver. But still the values are high when compared to the corresponding values for Configit Developer. The PSR benchmark represents a power supply restoration problem modelled as a configuration instance. Further details about this problem is available in [11]. The performance of ILOG Solver and Configit Developer on the PSR instance is similar to those obtained for the Bike instance, with a large worst case response time by ILOG Solver. Parity32 13 represents a parity learning problem as a configuration instance. Information about this problem is available in [12]. In case of the Parity32 13 problem, ILOG Solver has better performance compared to Configit Developer. The difference is not large though. It is interesting that the VT files for Bike, PC, and PSR are compiled faster than the corresponding average response times given by ILOG Solver. Big-PC represents the configuration problem of a personal computer with several additional features than those of the previous PC instance. The v1 and w1 instances represent real configuration problems of some of the customers of Configit Software. They are anonymized by renaming.3 For these two instances, the corresponding variable order file was also provided by Configit Software. These instances have very large product models. For example, the Big-PC has 2500 lines of code in the Configit language. The w1 instance has more than 66,000 lines of code. It is very hard and error prone to convert them manually to ILOG Solver code. Hence for those instances Table 1 only has results obtained for Configit Developer. Even though these instances represent very large product models, Configit Developer has fast average and worst response times. The ESVS, FS, FX, and Machine instances are from [13]. The first three instances represent screw compressor configuration problems. The last one represents parts of a real-world 4-wheeled vehicle configuration problem, anonymized by renaming. These four instances are easy compared to the previous 8 instances. 3
Due to legal issues, v1 and w1 are not available in CLib.
This is reflected by their VT file sizes. The VT files for these instances are generated in a fraction of a second. In case of the FS instance, the VT file generation time is almost equal to the corresponding worst response time by ILOG Solver. The last four instances are automotive product configuration problems from [14]. The original instances are in DIMACS CNF format. Good variable orders for these instances are obtained with the BuDDy BDD package [15] using the sift dynamic variable ordering heuristic. Configit Developer uses these variable orders for efficient VT file generation. The time taken by BuDDy to find a good variable order is listed in brackets in the second column of the table. For some large CNF files in [14], we did not do experiments as it took a lot of time to find good variable orders. For those instances, the average response time and the worst response time given by ILOG Solver are very large.
6
Related Work
Compilation techniques have also been studied for search techniques. In [16], the authors presented Minimal Synthesis Trees (MSTs), a data structure to compactly represent the set of all solutions in a CSP. It takes advantage of combining the consistency techniques with a decomposition and interchangeability idea. The MST is a polynomial-size structure. Operations on the MSTs, however, are of exponential time complexity. This may lead to long response times for an interactive configurator based on MSTs. Acyclic constraint networks and the tree clustering algorithm [17, 18] represent a CSP solution space in a more compact way, organizing it as a tree of solved sub-problems. For extracting a solution, the generated structure offers polynomial time guarantees in the size of the structure. The size of the subproblems, however, cannot be controlled for all instances and might lead to an exponential blow-up. The complexity of the original problem is dominated by the complexity of the sub-problems, which are exponential in both space and time. Nevertheless, this is one of the first compilation approaches used to solve CSP problems. There are efforts to cope with this exponential blow-up by additional compression using Cartesian product representation [19]. We are only aware of one other symbolic precompilation technique. In [10], the authors present a method which compiles all valid solutions of a configuration problem into an automaton. After compiling the solutions into an automaton, functions required for interactive configuration, like implications, explanations, and valid-domain-calculations can be done efficiently. They also present a theoretical view of all the complexity issues involved in their approach. They show that all the tasks involved in an interactive configuration process are intractable in the worst case. The BDD and automata approach to two-phase interactive configuration may perform equally well. A major advantage of using BDDs, however, is that this data structure has been studied intensely in formal verification for representing formal models of large systems [20, 21]. In particular, the variable ordering problem is well studied [7]. Furthermore a range of powerful
software packages have been developed for manipulating BDDs [15, 22]. To our knowledge, automata compilation has not reached this level of maturity. Previous work comparing symbolic and search-based approaches is very limited. Comparative studies of the SAT search engine zChaff [23] and BDD compilation show that neither approach has generally better performance than the other [24]. Similarly, a comparison of the Davis-Putnam procedure and BDDs shows complementary strengths of the two approaches rather than one dominating the other [25]. For interactive configuration, though, an important advantage of the BDD approach is that it is possible to compile the solution space prior to user interaction whereas search must be interleaved with user requests.
7
Conclusion
In this paper we have compared a symbolic and search-based implementation of a complete and backtrack-free interactive product configuration algorithm. Our experimental results show that the symbolic approach often has several orders of magnitude faster response time than the search based approach due to the precompilation of the solution space into a symbolic representation. In addition, the difference between average and worst response time is often much smaller for the symbolic approach than for the search-based approach. Our results indicate that BDD-derived representations often are small for real-world configuration instances. We believe that this may be due to the modular structure of configuration problems with a frequent hierarchical tree-like decomposition of dependencies that BDDs are particularly well-suited for. We are currently working on an open source C++ Library for BDD-based interactive configuration for research and education purposes (CLab, [26]) and a comprehensive benchmark suite of industrial configuration problems (CLib, [6]). Future work includes developing specialized BDD operations to support both the compilation phase and interactive phase of product configuration. Acknowledgments We would like to thank ILOG for their elaborate answers to our user questions for ILOG Solver 5.3. We also thank Erik R. van der Meer for providing the T-shirt example.
References 1. Sabin, D., Weigel, R.: Product configuration frameworks - a survey. Intelligent Systems, IEEE 13 (1998) 42–49 2. Hadzic, T., Subbarayan, S., Jensen, R.M., Andersen, H.R., Møller, J., Hulgaard, H.: Fast backtrack-free product configuration using a precompiled solution space representation. In: Proceedings of the International Conference on Economic, Technical and Organizational aspects of Product Configuration Systems, DTU-tryk (2004) 131–138
3. Bryant, R.E.: Graph-based algorithms for boolean function manipulation. IEEE Transactions on Computers 8 (1986) 677–691 4. Configit Software A/S. http://www.configit-software.com (online) 5. ILOG. http://www.ilog.com (online) 6. CLib: Configuration benchmarks library. http://www.itu.dk/doi/VeCoS/clib/ (online) 7. Meinel, C., Theobald, T.: Algorithms and Data Structures in VLSI Design. Springer (1998) 8. Wegener, I.: Branching Programs and Binary Decision Diagrams. Society for Industrial and Applied Mathematics (SIAM) (2000) 9. Fern´ andez, A.J., Hill, P.M.: A comparative study of eight constraint programming languages over the boolean and finite domains. Constraints 5 (2000) 275–301 10. Amilhastre, J., Fargier, H., Marquis, P.: Consistency restoration and explanations in dynamic CSPs-application to configuration. Artificial Intelligence 1-2 (2002) 199–234 ftp://fpt.irit.fr/pub/IRIT/RPDMP/Configuration/. 11. Thi´ebaux, S., Cordier, M.O.: Supply restoration in power distribution systems – a benchmark for planning under uncertainty. In: Pre-Proceedings of the 6th European Conference on Planning (ECP-01). (2001) 85–96 12. Parity-Function. ftp://dimacs.rutgers.edu/pub/challenge/satisfiability/ contributed/crawford/README (online) 13. Tiihonen, J., Soininen, T., Niemel¨ a, I., Sulonen, R.: Empirical testing of a weight constraint rule based configurator. In: ECAI 2002 Configuration Workshop. (2002) 17–22 http://www.soberit.hut.fi/pdmg/Empirical/index.html. 14. Sinz, C., Kaiser, A., Kchlin, W.: Formal methods for the validation of automotive product configuration data. Artificial Intelligence for Engineering Design, Analysis and Manufacturing 17 (2003) 75–97 Special issue on configuration http://www-sr.informatik.uni-tuebingen.de/~sinz/DC/. 15. Lind-Nielsen, J.: BuDDy - A Binary Decision Diagram Package. http://sourceforge.net/projects/buddy (online) 16. Weigel, R., Faltings, B.: Compiling constraint satisfaction problems. Artificial Intelligence 115 (1999) 257–287 17. Dechter, R., Pearl, J.: Network-based heuristics for constraint-satisfaction problems. Artificial Intelligence 34 (1987) 1–38 18. Dechter, R., Pearl, J.: Tree-clustering schemes for constraint-processing. Artificial Intelligence 38 (1989) 353–366 19. Madsen, J.N.: Methods for interactive constraint satisfaction. Master’s thesis, Department of Computer Science, University of Copenhagen (2003) 20. Burch, J.R., Clarke, E.M., McMillan, K.: Symbolic model checking: 1020 states and beyond. In: Proceedings of the 5th Annual IEEE Symposium on Logic in Computer Science. (1990) 428–439 21. Yang, B., Bryant, R.E., O’Hallaron, D.R., Biere, A., Coudert, O., Janssen, G., Ranjan, R.K., Somenzi, F.: A performance study of BDD-based model checking. In: Formal Methods in Computer-Aided Design FMCAD’98. (1998) 255–289 22. Somenzi, F.: CUDD: Colorado university decision diagram package. ftp://vlsi .colorado.edu/pub/ (1996) 23. Moskewicz, M.W., Madigan, C.F., Zhao, Y., Zhang, L., Malik, S.: Chaff: Engineering an efficient SAT solver. In: Proceedings of the 38th Design Automation Conference (DAC’01). (2001) 24. Pan, G.and Vardi, M.Y.: Search vs. symbolic techniques in satisfiability solving. In: Proceedings of the Seventh International Conference on Theory and Applications of Satisfiability Testing (SAT 2004). (2004)
25. Uribe, T.E., Stickel, M.E.: Ordered binary decision diagrams and the DavisPutnam procedure. In Jouannaud, J.P., ed.: Proceedings of the 1st International Conference on Constraints in Computational Logics. Volume 845 of Lecture Notes in Computer Science., Springer (1994) 26. Jensen, R.M.: CLab: A C++ library for fast backtrack-free interactive product configuration. http://www.itu.dk/people/rmj/clab/ (online)
Linear Functions for Interactive Configuration Using Join Matching and CSP Tree Decomposition Sathiamoorthy Subbarayan, Henrik Reif Andersen Department of Innovation, IT University of Copenhagen Denmark
Abstract Quick responses are required for interactive configuration. For this an ideal interactive configurator needs to provide the functionalities required for interactive configuration with at most linear time complexity. In this paper, we present such a data structure called Join Matched CSP (JMCSP). When a JMCSP is used to represent a configuration problem, the functionalities required for interactive configuration can be obtained with linear time complexity. Unlike the tree-of-BDDs [Subbarayan, 2005], the JMCSPs while taking advantage of treedecomposition also provide linear configuration functions. Although obtaining a JMCSP is exponential in the tree-width of the input configuration problem, due to tree-like hierarchical nature of configuration problems, this is typically feasible. We present the JMCSP compilation process along with the linear interactive configuration functions on it. The linear functionalities provided by the JMCSPs include computation of all minimum explanations.
1 Introduction The complexity of made-to-order products keeps increasing. Examples of such products include personal computers, bikes, and power-backup systems. Such products will be represented in the form of a product model. A product model will list the parameters (variables) defining the product, their possible values and the rules by which those parameter values can be chosen. A product model implicitly represents all valid configurations of a product, and it can be viewed as a Constraint Satisfaction Problem (CSP), where the solutions to the CSP are equivalent to valid configurations of the corresponding product model. The increase in the complexity of made-to-order products rises the need for efficient decision support systems to configure a product based on the requirements posed by the customer. Such decision support systems are called configurators. Configurators read a product model which represents all valid configurations of the product and guides the user in choosing one among the valid configurations as close as possible to his requirements. An interactive configurator takes
a product model as input and interactively helps the user to choose his preferred values for the parameters in the product model, one-by-one. The interactive configurator needs to be complete and backtrack-free. Complete means that all valid configurations need to be configurable using the configurator. Backtrackfree means that the configurator should not allow the user to choose a value for a parameter in the product model which would eventually lead him to no valid configurations. To ensure backtrack-freeness, the interactive configurator needs to prune away values from the possible values of parameters in the product model as and when those values will not lead to any valid configuration. In addition, the interactive configurator needs to give responses in a short period of time. Examples for commercial interactive configurators include Configit Developer [Configit-Software, 2005] and Array Configurator [Array-Technology, 2005]. The Binary Decision Diagram (BDD) [Bryant, 1986] based symbolic CSP compilation technique [Hadzic et al., 2004; Subbarayan et al., 2004] can be used to compile all solutions of a configuration problem into a single (monolithic) BDD. Once a BDD is obtained, the functions required for interactive configuration can be efficiently implemented. The problem with such approaches is that they do not exploit the fact that configuration problems are specified in hierarchies. Due to this the BDD obtained after compilation could be unnecessarily large. Such hierarchies are closer to trees in shape. The tree-of-BDDs approach: a combination of the BDD-based compilation technique and a CSP decomposition technique for efficient compilation of all solutions was presented in [Subbarayan, 2005]. The tree-of-BDDs scheme exploited the tree-like nature of configuration problems. The advantage of monolithic-BDD is that it can provide linear functions for interactive configuration. The advantage of treeof-BDDs is that they need very small space to store, when compared with that of the monolithic-BDD. But, at the cost of having costly functions for interactive configuration. The results in [Subbarayan, 2005] have shown that, for functionalities like minimum explanation generation, the tree-of-BDDs can take significantly long time to respond. Hence, we would like to have a compilation scheme that takes advantage of the tree-decomposition techniques and at the same time provide linear interactive configuration functions. Towards this we introduce the notion of Join Matching in
tree-structured CSP instances. Given a configuration problem, we can use tree-decomposition techniques to obtain an equivalent tree-structured CSP. Then, we can easily obtain a join tree for the tree-structured CSP. By performing Join Matching on the join tree, we obtain a data structure called Join Matched CSP (JMCSP). The size of JMCSP is exponential in the tree-width of the input configuration problem. As the configuration problems typically have very low treewidth, this should be practically feasible. We also present the linear functions required for interactive configuration using JMCSPs. This is a first step towards join matching in other configuration-problem compilation schemes, using the compression data structures like BDDs, DNNF [Darwiche, 2001], automata [Amilhastre et al., 2002; Fargier and Vilarem, 2004], and cartesian product representation [Madsen, 2003]. That might lead to linear functions for interactive configuration with additional reduction in space than just using JMCSPs. The other potential applications of join matching include: the general constraint propagation techniques, modelbased diagnosis, and database systems. In Section 2, the basic definitions are given. In Section 3 the CSP tree-decomposition techniques are discussed. The Section 4 describes the join matching process for compiling JMCSPs. The following section presents the interactive configurator algorithm. The Section 6 describes the linear functions for interactive configuration using the JMCSPs. Discussion on future work and related work, followed by concluding remarks, finish this paper.
2 Background In this section we give the necessary background. Let X be a set of variables {x1 , x2 , . . . , xn } and D be the set {D1 , D2 , . . . , Dn }, where Di is the domain of values for variable xi . Definition A relation R over the variables in M , M ⊆ X, is a set of allowed combinations of values (tuples) for the variables in M . Let M = {xm1 , xm2 , . . . , xmk }, then R ⊆ (Dm1 × Dm2 × . . . Dmk ). R restricts the ways in which the variables in M could be assigned values. Definition A constraint satisfaction problem instance CSP is a triplet (X, D, C), where C = {c1 , c2 , . . . , cm } is a set of constraints. Each constraint, ci , is a pair (Si , Ri ), where Si ⊆ X is the scope of the constraint and Ri is a relation over the variables in Si . We assume that the variables whenever grouped in a set are ordered in a fixed sequence. The same ordering is assumed on any set of the values of variables and the pairs with variables in them. Definition An assignment for a variable xi is a pair (xi , v), where xi ∈ X and v ∈ Di . The assignment (xi , v) binds the value of xi to v. A partial assignment PA is a set of assignments for all the variables in Y , where Y ⊆ X. A partial assignment is complete when Y = X. The notation PA|xs , where xs is a set of variables, means the restriction of the elements in PA to the variables in xs.
Similarly, R|xs , where R is a relation, means the restriction of the tuples in R to the variables in xs. Definition Let the set of variables assigned values by a PA be var(PA)={xi |∃xi .(xi , v)∈PA}. Let the tuple of values assigned by a PA be val(PA)=(vl1 , . . . , vlj ) when var(PA)={xl1 , . . . , xlj } and (xln , vln )∈PA. A partial assignment PA satisfies a constraint ci , when val(PA|var(PA)∩Si ) ∈ Ri|var(P A)∩Si . Definition A complete assignment CA is a solution S for the CSP when CA satisfies all the constraints in C. Given a CSP instance, the set of all complete assignments is CAS ≡ D1 × D2 × . . . × Dn . Let SOL denote the set of all solutions of the CSP. Then, SOL⊆CAS. A configurator is a tool which helps the user in selecting his preferred product, which needs to be valid according to a given product specification. An interactive configurator is a configurator which interacts with the user as and when a choice is made by the user. After each and every choice selection by the user the interactive configurator shows a list of unselected options and the valid choices for each of them. The interactive configurator only shows the list of valid choices to the user. This prevents the user from selecting a choice, which along with the previous choices made by the user, if any, will result in no valid product according to the specification. The configurator, hence, automatically hides the invalid choices from the user. The invalid choices will still be visible to the user, but with a tag that they are inconsistent with the current partial assignment. When the current partial assignment is extended by the user, some of the choices might be implied for consistency. Such choices are automatically selected by the configurator and they are called implied choices. A configuration problem can be modelled as a CSP instance, in which each available option will be represented by a variable and the choices available for each option will form the domain of the corresponding variable. Each rule in the product specification can be represented by a corresponding constraint in the CSP instance. The CAS and SOL of the CSP instance will denote the all possible-configurations and all possible-valid-configurations of the corresponding configuration problem. Hereafter, the terms CSP, CAS, and SOL may be used directly in place of the corresponding configuration terms. Let us assume that the SOL of a configuration problem can be obtained. Given SOL, the three functionalities required for interactive configuration are: Display, Propagate, and Explain. Definition Display is the function, which given a CSP, a subset of its solutions space SOL’ ⊆ SOL, lists X, the options in CSP and CDi , the available valid choices, for each option xi ∈ X, where CDi = {v|(xi , v) ∈ S, S ∈ SOL’}. CDi is the current valid domain for the variable xi . The display function is required to list the available choices to the user. Definition Propagate is the function, which given a CSP, a subset of its solutions space SOL’ ⊆ SOL, and (xi , v), where v ∈ CDi , restricts SOL’ to {S|(xi , v) ∈ S, S ∈ SOL’}.
By the definition of interactive configurator, the propagation function is necessary. Propagate could also be written as restricting SOL’ to SOL’|(xi ,v) . Sometimes the restriction might involve a set of assignments, which is equivalent to making each assignment in the set one by one. Definition A choice (xi , vi ) is an implied choice, when (xi , vi )∈PA / and (SOL|PA )|xi ={vi } . A choice (xi , vi ) is an invalid choice, when {vi }∈(SOL / |PA )|xi . Let (xi , vi ) be an implied or invalid choice. Then Explain(xi , vi ) is the process of generating, E, a set of one or more selections made by the user, which implies or invalidates (xi , vi ). The E is called as an explanation for (xi , vi ). An explanation facility is required when the user wants to know why a choice is implied or invalid. Let PA be the current partial assignment that has been made by the user. By the definition of explanation, Display(CSP, SOL|PA\E ) will list vi as a choice for the unselected option xi . Each selection, (xi , v), made by the user could be attached a non-negative value as its priority, P (xi , v), and the explain function can be required to find a minimum explanation. Definition The cost of an explanation is Cost(E) = P (xi ,v)∈E P (xi , v). An explanation E is minimum, if there does not exists an explanation E’ for (xi , vi ), such that Cost(E’) 1 4 Display(CP, SOL’) 5 (xi ,v) := ’User input choice’ 6 if (xi ,v)∈ CDi 7 SOL’:=Propagate(CP,SOL’,(xi ,v)) 8 PA:=PA∪{(xi ,v)} 9 else 10 E:=Explain(CP, SOL’, (xi ,v)) 11 if ’User prefers (xi ,v)’ 12 PA:=(PA\ E)∪{(xi ,v)} 13 SOL’:=SOL|P A 14 return PA
Figure 3: An Interactive Configurator Using JMCSPs.
6
Configuration Functions on JMCSPs
6.1 The Propagate Function
Definition A topological ordering of nodes (constraints) in a JMCSP, is an ordering such that, if c1 and c2 are two nodes in the JMCSP, then c1 precedes c2 in the ordering, if c2 can be reached from c1 . A topological ordering can be obtained in linear time during the JMCSP creation process. Definition The valuation is a function which given a PA and a corresponding JMCSP, maps a tuple in the JMCSP to a positive integer value or ∞. The valuation function is defined as follows: 1. Each element in the tuple corresponding to an unassigned variable will contribute nothing to the valuation. 2. Each element in the tuple that violates an assignment in PA will contribute the value given by the cost-function, for that assignment. 3. The cost for violation of (xi ,vi ) is ∞. 4. If the tuple contains a pointers to a CJB of an incoming directed edge, then the min cost field in the CJB will contribute towards the valuation. After a valuation of a tuple is obtained, it is compared with the min cost value in the corresponding CJBs of its outgoing edges, if any. If the existing min cost is larger than the valuation of the tuple then, the min cost field is assigned the valuation of the tuple and the corresponding min ptr is updated to point to the tuple. When the tuples of the constraint (node) without any outgoing edge are valuated, a tuple with minimum valuation in the constraint will be obtained. Recall that there can be only one such node. Given these steps, a minimum explanation can be obtained as follows:
Given a JMCSP and an assignment (x,v), we just have to restrict (mark appropriately) the tuples of one among the constraints having the variable x and propagate the changes to the adjacent constraints in the join tree. Using the CJBS lists, we can obtain the list of non-compliant tuples in the adjacent constraints and mark them as removed. During the process, if all the tuples corresponding to any CJB are removed, then the corresponding CJB is marked as removed and the effect is propagated. The Propagate function should not consider the direction of the edges in the join tree. Due to the properties of acyclic CSPs, such a propagation is enough to maintain minimality after unary assignments. The time complexity of Propagate is linear in the size of the JMCSP.
Note that all minimum explanations can be obtained by remembering all the min cost valuated tuples in each node. Even with that facility, the Explain function will just have a linear time complexity.
6.2
7
The Display Function
Given a JMCSP, with tuples in it marked as removed or not, the Display function just has to access all the tuples once and obtain the allowed values for the unassigned variables. This function also has a linear time complexity.
6.3 The Explain Function Given a JMCSP, a partial assignment PA, a cost-function for each assignment in PA, and an assignment (xi ,vi ) for which explanation is required, all minimum explanations can be obtained as follows.
1. Assign ∞ to all min cost fields in the JMCSP. 2. Following the topological ordering, select constraints and obtain valuation for their tuples. 3. All the min ptr pointed tuples and the cheapest tuple in the last node now gives a minimum explanation. The assignments in PA that are violated by those tuples is the minimum explanation.
Future Work
The tree-of-BDDs [Subbarayan, 2005] scheme has two types of space reduction. Potentially exponential space reduction due to tree-decomposition and another potential exponential space reduction due to BDD-based representation of each constraint. The JMCSPs just takes advantage of treedecomposition and provides linear functions. The next step will be to adapt the join matching process for tree-of-BDDs. This seems plausible although not the generation of all minimum explanations. But, generation of one minimum explanation seems easy. Further research is required in this direction.
The join matching process has potential applications in general constraint propagation, model-based diagnosis, and database systems. The join matching might reduce the complexity of some of the functions in these applications.
8 Related Work In [Fattah and Dechter, 1995; Stumptner and Wotawa, 2001], the authors have presented techniques for generating minimal diagnosis in model-based diagnosis systems. The problem of minimal diagnosis is very similar to our problem of generating minimum explanations. But they use sorting operations on constraints in the diagnosis process, and this increases the complexity of the operations by a logarithmic factor. Such a logarithmic factor might influence a lot, since the constraints in the real-world instances could have several thousand tuples in a single constraint, even before decomposition. After tree decomposition the number of tuples in the constraints of the resulting acyclic CSP is normally more than the number of tuples in the constraints before decomposition. Hence, it will take a significant amount of time to sort those constraints while generating explanations. For example, the Renault car configuration instance used in [Amilhastre et al., 2002] has around 40,000 tuples in a constraint, even before decomposition. Also, in their complexity analysis a linear factor is suppressed and hence their minimal diagnosis algorithms will demand more time. The JMCSPs, whose data structures remains relatively static during the explanation generation process, can hence be used in generating minimal diagnosis without any complex steps like sorting used in [Fattah and Dechter, 1995; Stumptner and Wotawa, 2001]. In [Madsen, 2003], the author uses some preprocessing techniques along with tree-decomposition and cartesian product representation for interactive configuration. The author was able to provide linear propagation functions but not explanations.
9
Conclusion
The JMCSPs, a data structure with linear configuration functions was presented. Experiments on real-life instances need to be done to empirically test the usefulness of JMCSPs. The join matching technique in JMCSPs can be combined with the compression capability of BDDs or automata [Amilhastre et al., 2002] such that we get an additional decrease in space, while having linear configuration functions.
Acknowledgements Special thanks to Tarik Hadzic for his comments on a previous version of this paper. Erik van der Meer has independently developed a dynamic version of Tree-of-BDDs in his PhD thesis and discussions with him were helpful.
References [Amilhastre et al., 2002] J. Amilhastre, H. Fargier, and P. Marquis. Consistency restoration and explanations in dynamic CSPs-application to configuration. Artificial Intelligence, 1-2:199–234, 2002.
[Array-Technology, 2005] Array-Technology. http://www.array.dk/, 2005. [Bodlaender, 2005] Hans L. Bodlaender. Discovering treewidth. In Proceedings of SOFSEM, pages 1–16, 2005. Springer LNCS. [Bryant, 1986] R. E. Bryant. Graph-based algorithms for boolean function manipulation. IEEE Transactions on Computers, 8:677–691, 1986. [Configit-Software, 2005] Configit-Software. http://www.configit-software.com, 2005. [Darwiche, 2001] Adnan Darwiche. Decomposable negation normal form. Journal of the ACM, 48(4):608–647, 2001. [Dechter and Pearl, 1989] R. Dechter and J. Pearl. Treeclustering schemes for constraint-processing. Artificial Intelligence, 38(3):353–366, 1989. [Dechter, 2003] Rina Dechter. Constraint Processing. Morgan Kaufmann, 2003. [Fargier and Vilarem, 2004] H. Fargier and M-C. Vilarem. Compiling CSPs into tree-driven automata for interactive solving. Constraints, 9(4):263–287, 2004. [Fattah and Dechter, 1995] Yousri El Fattah and Rina Dechter. Diagnosing tree-decomposable circuits. In Proceedings of IJCAI, pages 1742–1749, 1995. [Goodman and Shmueli, 1982] Nathan Goodman and Oded Shmueli. The tree property is fundamental for query processing. In Proceedings of PODS, pages 40–48, 1982. [Gottlob et al., 2000] Georg Gottlob, Nicola Leone, and Francesco Scarcello. A comparison of structural CSP decomposition methods. Artificial. Intelligence, 124(2):243– 282, 2000. [Gyssens et al., 1994] Marc Gyssens, Peter G. Jeavons, and David A. Cohen. Decomposing constraint satisfaction problems using database techniques. Artificial Intelligence, 66(1):57–89, 1994. [Hadzic et al., 2004] T. Hadzic, S. Subbarayan, R. M. Jensen, H. R. Andersen, J. Møller, and H. Hulgaard. Fast backtrack-free product configuration using a precompiled solution space representation. In Proceedings of PETO conference, pages 131–138, 2004. [Madsen, 2003] J. N. Madsen. Methods for interactive constraint satisfaction. Master’s thesis, Department of Computer Science, University of Copenhagen, 2003. [Stumptner and Wotawa, 2001] Markus Stumptner and Franz Wotawa. Diagnosing tree-structured systems. Artificial Intelligence, 127(1):1–29, 2001. [Subbarayan et al., 2004] S. Subbarayan, R. M. Jensen, T. Hadzic, H. R. Andersen, H. Hulgaard, and J. Møller. Comparing two implementations of a complete and backtrack-free interactive configurator. In CP’04 CSPIA Workshop, pages 97–111, 2004. [Subbarayan, 2005] Sathiamoorthy Subbarayan. Integrating CSP decomposition techniques and BDDs for compiling configuration problems. In Proceedings of the CP-AI-OR. Springer LNCS, 2005.
Integrating a Variable Ordering Heuristic with BDDs and CSP Decomposition Techniques for Interactive Configurators Sathiamoorthy Subbarayan
Henrik Reif Andersen
Department of Innovation, IT University of Copenhagen, Denmark sathi,
[email protected]
Abstract The Binary Decision Diagram (BDD) based compilation schemes are quite suitable for representing configuration knowledge bases. It is well-known that the size of BDDs are very sensitive to the variable order. In this paper, we study the variable ordering problem of BDDs when they represent a configuration knowledge. Such a study is crucial to better understand the BDD-based compilation schemes. We introduce a small variant of a classical variable ordering heuristic, that proves empirically useful. It is surprising since such a heuristic is known to fail when BDDs are used in formalverification. We show that a compilation scheme using CSP tree-decomposition is less dependent on the variable order. We also show that, for a good variable order the benefit of tree-decomposition, which reduces space, can drastically diminish.
Introduction The complexity of made-to-order products keeps increasing. Examples of such products include personal computers, cars, and power-backup systems. Such products will be represented in the form of a product model. A product model will list the number of parameters (variables) defining the product, their possible values (domains) and the rules (constraints) by which those parameter values can be chosen. A product model implicitly represents all valid configurations of a product, and it can be viewed as a Constraint Satisfaction Problem (CSP), where the solutions to the CSP are equivalent to valid configurations. The parameters, values and rules of a configuration problem, correspond to the variables, domains and constraints in a CSP. The increase in the complexity of made-to-order products rises the need for efficient decision support systems to configure a product based on the requirements posed by a customer. Such systems, called configurators, read a product model as input and guide the user in choosing one among the valid configurations as close as possible to his requirements. An interactive configurator interactively helps the user to choose his preferred values for the parameters in the product model, one-by-one. The interactive configurator needs to be complete and backtrack-free. Complete means that all valid configurations need to be configurable using
the configurator. Backtrack-free means that the configurator should not allow the user to choose a value for a parameter in the product model which would eventually lead him to no valid configurations. To ensure backtrack-freeness, the interactive configurator needs to prune away values from the possible values of parameters in the product model as and when those values will not lead to any valid configuration. In addition, the interactive configurator needs to give responses in a short period of time. The Binary Decision Diagram (BDD) (Bryant 1986) based symbolic CSP compilation technique (Hadzic et al. 2004) can be used to compile all solutions of a configuration problem into a single (monolithic) BDD. Once a BDD is obtained, the functions required for interactive configuration can be efficiently implemented. The tree-of-BDDs approach (Subbarayan 2005), a combination of the BDDbased compilation technique and a CSP tree-decomposition technique, exploited the fact that configuration problems are specified in tree-like hierarchies. Experiments in (Subbarayan 2005) showed that decomposition techniques can drastically reduce the space required to represent configuration knowledges. It is well-known that the size of BDDs are very sensitive to the ordering of the variables. The variable ordering problem (Meinel & Theobald 1998) of BDDs is well-studied in the area of formal verification. But, the ordering problem while representing a configuration problem has not been not studied. So far the default variable order, the order in which variables are declared in the input is typically being used. A study on the variable ordering problem is crucial to better understand the compilation schemes. The usage of tree decomposition techniques, which were not used in formal verification, increases the need for a detailed study. The contributions of this paper are: 1. Cluster Sifting, a small variant of sifting (Rudell 1993), a classical variable ordering heuristic. In the experiments, cluster sifting resulted in up to 97% decrease in the size of a monolithic-BDD. The classical sifting heuristic did not help. This is surprising since cluster sifting uses cluster ordering. When BDDs are used in formal-verification cluster ordering is considered bad and interleaved ordering is preferred (Kam et al. 1998). 2. The observation that the size of a tree-of-BDDs is less
dependent on the variable ordering when compared with that of a monolithic-BDD. 3. Experimental results on several real-life instances, which show that efficient variable ordering can drastically reduce the size of a monolithic-BDD, while it can decrease the size of a tree-of-BDDs only by a small factor. In one instance, the usage of cluster sifting even results in a monolithic-BDD with size smaller than the size of the corresponding tree-of-BDDs (see Table 2). This gives an interesting trade-off between the two schemes. The drastic reduction in space requirement is of great importance in online configuration applications, where one needs to send the configuration details through the internet, and also in embedded configuration, where one needs to embed the configuration details on a product itself, so that it could be reconfigured as and when required. The rest of the paper is organized as follows. The two BDD-based compilation schemes are explained in the next section. Subsequently the variable ordering problem is discussed and the cluster sifting heuristic is presented. Experimental results, followed by some suggestions for future work and concluding remarks, finish this paper.
C1
C3
C4
C2
b
C5
CSP C6
C7
C1
BDD
C3
b1
C2 C3
CSP’
C6
C4
b2 C5
b3 C7
C6
Tree-of-BDDs
Figure 2: The two BDD-based compilation schemes.
BDD-based Interactive Configurators Due to space limitation we just explain how a BDD or a treeof-BDDs can represent a configuration problem. The methods required for providing interactive configuration using these data structures are explained in (Hadzic et al. 2004; Subbarayan 2005).
a b c d
c d
d
d e
e 1
0
Figure 1: A Binary Decision Diagram. A BDD (Bryant 1986) is a rooted directed acyclic graph with two terminal nodes marked 1 and 0, respectively. All the non-terminal nodes are associated with a Boolean variable. Each non-terminal node has two outgoing edges: low (dashed) and high (solid). The nodes in a BDD are ordered based on a linear variable order. BDDs can be used to represent Boolean functions. A BDD for a given function can be obtained by standard composition functions on BDDs representing atomic elements of the function. Given an assignment to the variables in the function, there exists a unique path from the root
node to one of the terminal nodes, defined by recursively following the high edge, when the associated variable is assigned true, and the low edge, when the associated variable is assigned false. If the path leads to the 1-terminal, then the assignment is a solution, otherwise not. Although the size of a BDD can be exponential in the worst case, the BDDs are small for many practical functions. Due to this BDDs have been successfully used in several research areas, including: verification, CSP, and planning. The size of the BDDs are very sensitive to the used variable ordering. When solution space of a non-Boolean function needs to be represented by a BDD, each variable xi with domain Di will be represented by li Boolean variables, where li = dlg |Di |e. Each value of xi will be represented by an unique combination of Boolean values for the corresponding Boolean variables. A BDD corresponding to any constraint can be obtained by the composition function on BDDs representing the atomic elements of the constraint. In case of CSPs, the conjunction of the constraints represents the solution space (SOL), and hence the conjunction function when applied to the BDDs obtained for all the constraints in a CSP will give a monolithic-BDD, representing the SOL. As li Boolean variables could represent 2li values, in cases where |Di | < 2li , additional rules need to be added to maintain domain integrity. In the monolithic-BDD based interactive configurator scheme (Hadzic et al. 2004), a monolithic-BDD will be compiled to represent the configuration knowledge. The tree-of-BDDs scheme (Subbarayan 2005), an improvement to this method, is based on the observation that configuration problems have tree-like hierarchies. Both the schemes are shown in Figure 2. In the figure, a CSP is represented by its constraint graph. The constraint graph of a CSP contains a node for each of its constraints and edges between
two nodes if the corresponding constraints share at least one variable. A CSP without cycles in it’s constraint graph can be efficiently solved (Dechter 2003). The tree-of-BDDs scheme (Subbarayan 2005) uses treedecomposition techniques to decompose a configuration problem (see Figure 2). The output of decomposition is CSP’, in which a cluster of constraints in the original CSP form a constraint. Due to the properties of tree-structured CSP instances (Dechter 2003), BDDs obtained for each constraint in CSP’ need not have to be conjoined into a monolithic-BDD. The tree-of-BDDs structure is enough to provide interactive configuration functionalities (Subbarayan 2005). The sum of the sizes of the BDDs in a tree-of-BDDs is potentially smaller than the corresponding monolithic-BDD. The experiments in (Subbarayan 2005) showed a drastic decrease in space requirements due to decomposition.
Cluster Sifting for BDD Variable Order Variable ordering of BDDs are usually optimized using heuristics as finding the best variable order is a coNP-Complete problem. Static variable ordering heuristics (Meinel & Theobald 1998) try to find a good variable order based on the topological relations in a given input instance, for which a BDD is going to be constructed. Dynamic variable reordering heuristics try to minimize a BDD, during or after the BDD construction. Mostly they are hill climbing procedures which will try to reorder a given variable order such that the BDD size decreases. The sifting heuristic (Rudell 1993) is one of the best dynamic reordering heuristics. Given a BDD and its variable order, the sifting heuristic will select a variable and move it to a position in the current variable order, where the size of the given BDD is minimum. Other than the selected variable, the variable positions will not change. Similarly, the heuristic will try to move all the variables one-by-one, to their best possible position. We initially implemented sifting heuristic, but it did not help in any of the configuration instances we tested. Then we implemented a small variant of sifting, which we call Cluster Sifting. In cluster sifting, all the Boolean variables representing a CSP variable will be clustered together (cluster ordering), and the cluster sifting will move the clusters in the ordering, instead of the individual Boolean variables. In case of interleaved ordering, when Boolean variables encode a non-Boolean variable, the Boolean variables corresponding to the least significant values of the non-Boolean variables will be kept together in the variable order. Similarly, the Boolean variables corresponding to other significant positions will be grouped together in the order. The interleaved ordering works well in case of arithmetic constraints like a+b=c. If the three variables {a,b,c} are each encoded by k Boolean variables, then all the Boolean variables of {a,b,c}, corresponding to each one among the k significant positions will be grouped together. Cluster ordering performed well in the configuration instances we tested. This is surprising as it is unconventional. As in (Kam et al. 1998), when using BDDs for formal verification it is conventional to consider cluster ordering as bad,
and interleaved ordering is preferred. In case of configuration problems, most of the constraints are non-arithmetic constraints. This might be a reason for better performance of cluster ordering in configuration problems. C LUSTER S IFT() vo:=GetVariableOrder() for i:=1 to n for j:=1 to n if vo[j] = i min pos:=j; old pos:=j min size:=SizeOf(SOL); break for j:=old pos to n − 1 vo[j]:=vo[j + 1]; vo[j + 1]:=i SetVariableOrder(vo); size:=SizeOf(SOL) if size < min size min pos:=j + 1; min size:=size for j:=n to old pos + 1 vo[j]:=vo[j − 1] vo[old pos]:=i for j:=old pos to 2 vo[j]:=vo[j − 1]; vo[j − 1]:=i SetVariableOrder(vo); size:=SizeOf(SOL) if size < min size min pos:=j − 1; min size:=size for j:=1 to min pos − 1 vo[j]:=vo[j + 1]; vo[j + 1]:=i SetVariableOrder(vo)
Figure 3: The Cluster Sifting Heuristic. We assume that given a BDD and a new variable order, the BDD-package will be able to give a new BDD with the given variable order. Most of the BDD-packages have such a facility. The algorithm for cluster sifting is shown in Figure 3. In the algorithm, vo is an array of CSP variables. The position of each CSP variable in the array reflects their ordering in the BDD. The number of variables is represented by n. The function GetVariableOrder() will return vo. The function SizeOf(b) will return the number of nodes in the BDD b. In case b is a tree-of-BDDs, it will return the sum of the sizes of BDDs in b. The SetVariableOrder() function will take a vo as input and change the variable order of the monolithicBDD (tree-of-BDDs) representing the solution space to vo. SOL is the BDD (tree-of-BDDs) representing the solution space. The outermost loop in the algorithm is to move (sift) all the n CSP variables to their best possible position. There are five inner loops. The first one locates the current position of a variable i in the order. The second one moves i to the last position in the order, while remembering the cheapest visited position. The next two loops are to move i to the first place in the order. The last loop moves i to the best found position. Finally, the variable i is set to that position. After a call to the cluster sift method, if the size of SOL has decreased more than 1% of the initial size, the cluster sift method is invoked again. This is repeated until there is no decrease or less than 1% decrease in the size.
The Block Sifting heuristic in (Meinel & Slobodov´a 1997) is quite similar to cluster sifting. However, block sifting is quite complex as it looks for blocks of functionally dependent Boolean variables. In case of cluster sifting, we do not look for any functional dependency between Boolean variables. We just group all the Boolean variables corresponding to a single CSP variable as a cluster.
Less Dependency of Tree-of-BDDs From the structure of the tree-of-BDDs we can observe that the tree-of-BDDs are less dependent on the variable order than the monolithic-BDDs. This is illustrated in Figure 4. Suppose, we have a CSP with variables {a, b, c, d, e, f, g} and the initial variable order is (a, b, c, d, e, f, g). Let treedecomposition results in three BDDs in the corresponding tree-of-BDDs, with the variables appearing in the nodes as shown. Let the variable order be changed, by moving variable g to the front, to (g, a, b, c, d, e, f ). This affects the size of only one BDD in the tree-of-BDDs, as g occurs only in it. In this sense the variable order change only results in a local change in the size of the tree-of-BDDs. But, in case of the corresponding monolithic-BDD, as all the variables appear in a single BDD the change is global.
Monolithic-BDD b
b
(a,b,c,d,e,f,g) (g,a,b,c,d,e,f)
b1
b1
(a,b,c) (a,b,c) b3
(e,f,g)
b2
b2
(a,c,d,e)
Tree-of-BDDs
b3
(a,c,d,e)
(g,e,f)
Figure 4: Effect of variable order. Also, due to the tree-decomposition properties, the three variables {e, f, g} appearing in BDD b3 are highly related in the CSP. It is a general rule of thumb to keep related variables close in the order, to reduce the size of BDDs. Although the variable g is moved away from e and f in the global variable order, in the partial order corresponding to BDD b3 they still remain close and the change in the size of b3 will be small, when compared to that of the monolithic-BDD. This implies that, when the monolithicBDD size could increase (decrease) a lot with a change in the variable order, the corresponding increase or decrease in the size of the tree-of-BDDs will be relatively small. This shows the less dependency of tree-of-BDDs on the variable order. Hence, for a poor variable order the tree-of-BDDs will be a lot smaller than the corresponding monolithic-BDD, while
for a good variable order the difference should diminish. We observe this empirically in the next section.
Experimental Results Experiments are done by implementing the Cluster Sifting heuristic, on top of CLab (Jensen 2004) and iCoDE (iCoDE 2004). CLab is an interactive configurator based on the monolithic-BDD scheme and the tree-of-BDDs scheme is available in iCoDE. In the experiments, first a monolithicBDD (tree-of-BDDs) will be obtained using the initial variable order (IVO) and then cluster sifting will be done. IVO is the order in which variables are declared in the input. A Pentium Xeon 3.2 GHz machine with 4GB RAM and 1MB L2 Cache is used in the experiments. Five configuration instances are used in the experiments: PC, Bike, Renault, psr-1-32-1 and psr-1-32-2. PC, Bike and Renault refer to computer, bike and car configuration problems, respectively (CLib 2004). Renault was the only instance used in the experiments of (Amilhastre, Fargier, & Marquis 2002) and it is quite large, the input file size is around 23 Megabytes, and it has around 200,000 tuples in 113 constraints. The other two instances are power supply restoration problems modelled as configuration instances (Sonne & Jensen 2005). The characteristics of the benchmarks are P listed in Table 1. The column |Di | refers to the sum of the domain sizes of the variables in the instance. Arity of a constraint is the size of its scope. The column MaxP |a| refers to maximum arity of the constraints. The column |ai | refers to the sum of the constraint arities. The column |SOL| refers to the number of solutions. The effect of the cluster sifting is shown in Table 2. In the table, Compile refers to the compilation time. The column #nodes refers to the number of nodes in the BDD for initial variable order (IVO). The column ClusterSift refers to the time taken by the cluster sifting heuristic. The column #nodes’ refers to the number of nodes after cluster sifting. The size of a tree-of-BDDs is the sum of the sizes of the BDDs in each node of the tree. The column #nodes” refers to the number of nodes in the monolithic-BDD after using the variable order obtained by cluster sifting on the corresponding tree-of-BDDs. The values in the table clearly shows that, for IVO, the size of tree-of-BDDs are significantly smaller when compared to the corresponding sizes of the monolithic-BDDs. But after cluster sifting, the difference between them decreases. In case of the PC instance, after cluster sifting, the size of the tree-of-BDDs is even larger than the size of the monolithic-BDD. In case of the Renault instance, the cluster sifting decreases the size of the monolithic-BDD by 97%. Although the time taken for cluster sifting is quite large, this is acceptable as a configuration problem instance will not change quite often. The compilation needs to be done only when the instance changes. Several interactions can be handled using the same monolithic-BDD (tree-of-BDDs). Even when it changes, the changes will be incremental and the basic structure of the instance will not change, and hence the good variable order will typically remain as a good one. Response timings for simulation of 10000 random interactions in both the compilation schemes, using IVO and
Benchmark PC Bike Renault psr-1-32-1 psr-1-32-2
#Variables 45 34 99 110 110
Table P 1: Benchmark Properties. |Di | #Constraints Max |a| 383 36 16 210 76 6 402 113 10 258 222 9 296 222 9
P
|ai | 107 141 588 913 913
|SOL| 1.19x106 8.07x108 2.84x1012 1.72x1011 1.76x1013
Table 2: Effect of Cluster Sifting in both the BDD-based schemes. Time values are in CPU seconds. Benchmark Monolithic-BDD Tree-of-BDDs Compile #nodes ClusterSift #nodes’ #nodes” Compile #nodes ClusterSift PC 0.11 16494 1635 1312 1568 0.19 4458 2740 Bike 0.1 10986 523 1966 10455 0.2 3391 267 Renault 119 455796 95160 13248 32792 77 17602 22092 psr-1-32-1 0.46 56923 15801 15894 16752 4 8917 18247 psr-1-32-2 2 246775 34287 46512 46645 9 22101 34445
#nodes’ 1477 1494 6802 3918 7711
Table 3: Response timings for 10000 random interactions. Time values are in CPU milli-seconds. Benchmark Monolithic-BDD Tree-of-BDDs ART ART’ WRT WRT’ ART ART’ WRT WRT’ PC 16 14 40 20 8 8 10 10 Bike 14 13 20 10 7 7 10 10 Renault 119 16 530 30 9 8 30 20 psr-1-32-1 17 16 60 30 11 8 40 20 psr-1-32-2 38 20 620 70 17 9 110 30
500000 450000 400000
Monolithic-BDD
Tree-of-BDDs
350000
#nodes
cluster sifting is shown in Table 3. ART refers to the average response time. WRT: worst response time. ART’ and WRT’ refer to the corresponding values obtained using cluster sifting. The results show that after cluster sifting the difference between the timings for both the compilation schemes decreases. Figure 5 shows the convergence of cluster sifting heuristic in both the schemes. For the monolithic case, the cluster sifting heuristic converges quite quickly in the beginning, and then slowly until it reaches the stop criterion. For the tree-of-BDDs case, when compared with the difference in the monolithic case, there is not much difference between the initial size and the final size. To find out the dependency of the two compilation schemes on the variable order, 1000 random variable orders are generated for each instance. Experiments on both the schemes are done, using each one of them as initial variable order for the corresponding instance. Results are reported in Table 4. The results for the last two instances are not reported as all of the variable orders resulted in huge memory requirement and had to be aborted. The table clearly shows that, the tree-of-BDDs method is less dependent on the variable order. It varies a little with different variable orderings, while the monolithic-method varies a lot. Especially in case of the Renault instance, the monolithic-method has to abort in 540 cases, while the sizes of the corresponding tree-ofBDDs varied a little. The statistics for Renault was obtained from the results of the successful 460 experiments. As mentioned before, the classical sifting heuristic did not help in any of the configuration instances. We used
300000 250000 200000 150000 100000 50000 0
Time
Figure 5: Convergence on Renault.
Configit-Developer (Configit Software 2005) tool to generate two heuristic variable orders for the Renault instance. The heuristics are MST (Minimum spanning tree) and DFS (Depth first search). Both the heuristics use the structure of the input configuration instance and give a variable order. As shown in Table 5 both the MST and DFS did not result in a variable order as good as cluster sifting.
Table 4: Statistics on experiments with 1000 random variable orders. Statistic on #nodes Average Max Std.Dev #Aborts
PC Monolithic Tree 598337 29080 4517525 71996 618876 12906 0 0
Bike Monolithic 87484 525532 79448 0
Tree 10705 27517 4125 0
Future Work It can observed from Figure 4 that in the case of tree-ofBDDs, cluster sifting only has to consider local variable order. In the example shown in the figure, it does not matter whether variable g is moved to the front or between a and b. In both the cases the local variable order for each node in the tree-of-BDDs remain the same. This observation can be used to improve the cluster sifting heuristic for the tree-ofBDDs. Experiments on domain reduction methods for cluster sifting. For a given configuration instance, some of the values in the domain of some of its variables can be deleted, such that the monolithic-BDD size becomes small. This might reduce the time taken for cluster sifting. The cluster sifting can then be used to obtain a good variable order, which is most likely good for the original instance without domain reduction. This intuition is based on the observation that deleting some of the values still preserve the overall structure of the configuration instance. Cluster sifting works on built BDDs. Instead of this the heuristic could be incorporated into the BDD building process itself. This is how most of the BDD-packages implement variable ordering heuristics.
Conclusion Cluster sifting, a variable ordering heuristic, was introduced and its effect on two BDD-based compilation schemes were studied. It was shown that the tree-of-BDDs are less dependent on the variable order than the corresponding monolithic-BDDs. The advantage of monolithic-BDDs is that the entire configuration knowledge is represented by a single BDD. Hence, some advanced features like minimum explanations (Subbarayan 2005) can be efficiently implemented in monolithic-BDDs. The disadvantage of them is their huge dependency on the used variable order. Similarly the advantage of tree-of-BDDs is their less dependency on the variable order, while at the overhead of having the knowledge spread across several nodes in a tree-of-BDDs. The cluster sifting heuristic gives a good tradeoff between them. Given enough time, the cluster sifting could be used to obtain a good variable order and hence a small monolithic-BDD. Otherwise, the tree-of-BDDs can be built to provide basic interactive configuration facilities. In the cases where the initial variable order is so bad that a monolithic-BDD cannot be built, the tree-of-BDDs could be used to obtain a good variable order. As shown in the
Renault Monolithic Tree 951968 23669 2857552 38344 381705 4801 540 0
Table 5: Heuristics on Renault. Heuristic #nodes ClusterSift 13248 MST 707463 DFS 407382
column #nodes” of Table 2, it will be a good variable order for the corresponding monolithic-BDD as well.
References Amilhastre, J.; Fargier, H.; and Marquis, P. 2002. Consistency restoration and explanations in dynamic CSPsapplication to configuration. Artificial Intelligence 12:199–234. Bryant, R. E. 1986. Graph-based algorithms for boolean function manipulation. IEEE Transactions on Computers 8:677–691. CLib. 2004. www.itu.dk/doi/VeCoS/clib/. Configit Software. 2005. configit-software.com. Dechter, R. 2003. Constraint Processing. Morgan Kaufmann. Hadzic, T.; Subbarayan, S.; Jensen, R. M.; Andersen, H. R.; Møller, J.; and Hulgaard, H. 2004. Fast backtrackfree product configuration using a precompiled solution space representation. In International Conference on Economic, Technical and Organizational aspects of Product Configuration Systems, 131–138. iCoDE. 2004. www.itu.dk/people/sathi/icode/. Jensen, R. M. 2004. CLab: A C++ library for fast backtrack-free interactive product configuration. In Proceedings of CP-2004, 816. http://www.itu.dk/people/rmj/clab/. Kam, T.; Villa, T.; Brayton, R. K.; and SangiovanniVincentelli, A. L. 1998. Multi-valued decision diagrams: Theory and applications. Multiple-Valued Logic: An International Journal 4(1-2):9–62. Meinel, C., and Slobodov´a, A. 1997. Speeding up variable reordering of OBDDs. In Proceedings of ICCD, 338–343. Meinel, C., and Theobald, T. 1998. Algorithms and Data Structures in VLSI Design. Springer. Rudell, R. 1993. Dynamic variable ordering for ordered binary decision diagrams. In Proceedings of the International Conference on Computer-Aided Design, 139–144. Sonne, L. E., and Jensen, R. L. 2005. Power Supply Restoration. Master’s thesis, IT University of Copenhagen. Subbarayan, S. 2005. Integrating CSP decomposition techniques and BDDs for compiling configuration problems. Technical report, IT University of Copenhagen. www.itu.dk/people/sathi/icode.pdf.
On Hybrid SAT Solving Using Tree Decompositions and BDDs Sathiamoorthy Subbarayan Lucas Bordeaux Youssef Hamadi March 2006 Technical Report MSR-TR-2006-28
The goal of this paper is to study the benefits of hybridizing the CNF SAT Solvers with BDDs. Towards this we define a metric for the level of hybridization based on a tree decomposition of an input CNF. We also present a new linear time algorithm on BDDs, which is useful for efficient conflict analysis in any BDD-based hybrid SAT solver. Experiments on an implementation of our hybrid solver shows when to use such a hybridization.
Microsoft Research Microsoft Corporation One Microsoft Way Redmond, WA 98052 http://www.research.microsoft.com
1
Introduction
Our work is motivated by the fact that BDDs [1] and resolution-based CNF solvers are different reasoning methods [2]. Some constraints are easy for BDD representations while they are hard for CNF solvers and vice versa. The complexity of solving a SAT instance can be expressed as exponential in the tree width [3] of the instance. Hence, when the tree width of a SAT instance is quite low, we can use this fact to guide a SAT solver. In this paper, we present a hybrid SAT solver combining BDDs and CNF reasoning methods with tree decomposition techniques. Although attempts have been made in the past to combine some of the these techniques [4, 5], we are not aware of any previous work mixing all the three techniques. Our work takes care of the problems in the previous approaches, such as ad hoc methods to build BDDs [4], suffering from high cost for obtaining tree decompositions [5]. The goal of this paper is to study the benefits of our hybridization. We first create a tree decomposition of an input CNF instance of n variables. Then, based on a parameter h ∈ [0,..,2n ], we make a heuristic cut in the tree decomposition. The cut will be such that for each subtree below the cut the clauses K covered by the subtree can be represented by a BDD of size at most h*nLits, where nLits is the number of literal occurrences in the clauses K. For each subtree below the cut its BDD will be created and the corresponding clauses in the input CNF will be replaced by the BDD. This results in a hybrid representation. We then have a hybrid SAT solver of the form used in [4], which has to do propagation and conflict analysis in this hybrid representation to determine satisfiability. The contributions of this paper include a new linear-time algorithm for finding minimal necessary assignments for implications by BDDs, which will be used by the hybrid conflict learning process. At h=0 (h=2n ) the hybrid solver will be a pure CNF (BDD) solver. The intermediate values of h result in a really hybrid solver. An implementation of the above mentioned method is used in an experimental study of the tradeoffs between BDD and CNF representations. In some instances, we observe very low tree width which should naturally help in hybrid SAT solving. The rest of the paper is organized as follows. The necessary background on tree-decomposition methods and BDDs are given in Section 2. The process of creating the hybrid representation, the hybrid SAT solver and the new BDD algorithm useful for conflict analysis are presented in Section 3. The subsequent section presents the experimental results, which is followed by related work and some concluding remarks.
1
2
Background
2.1
Tree Decomposition
Let (V ,C) be a CNF SAT problem, where V is the set of propositional variables and C is the set of clauses in the CNF. Let the notation vars(c) denote the set of variables occurring in the literals of a clause c ∈ C. Then, the tree decomposition [3] of the SAT problem is a tree T =(N ,E), where N is the set of nodes in the tree and E is the set of edges in the tree. Each node n ∈ N will be associated to a set vars(n), where vars(n) ⊆ V . A node n is said to contain the variables vars(n). Additionally, a tree decomposition has to satisfy the following two conditions: 1. for any clause c ∈ C, there exists a node n ∈ N such that vars(c) ⊆ vars(n). i.e., each clause needs to be covered by at least one node in the tree. 2. for any variable v ∈ V , the nodes in N containing the variable v form a connected subtree in the tree T . The size of a node in the tree decomposition is the number of variables in it. The tree width of a tree decomposition ω’ is the size of the largest sized node of the tree decomposition minus one. The tree width of a SAT instance ω is then the smallest number among the tree widths of all possible tree decompositions of the instance. It is well known that finding the tree width of a SAT instance is NPhard [3]. Hence, heuristics are employed to approximate the tree decomposition. Given a tree decomposition of a SAT problem, the SAT instance can be solved by a dynamic programming method [6] with complexity exponential in the tree width of the given tree decomposition. This is the fact we can exploit to improve the current SAT solvers. Since finding the best tree decomposition is NP-hard, we can use one among the several available heuristics to obtain a good tree decomposition and build a SAT solver to use the decomposition. For a set of problem instances of same tree width and increasing instance sizes, the performance of the tree width based SAT solvers depend only upon the ability of the heuristic to find good decompositions. Exploiting tree width could be useful in cases like bounded model checking [7], where with the increase in the size of the bound, the tree width of the corresponding instances should not differ a lot, as a similar circuit structure is repeated for each increase in bound. 2.1.1
The min-degree heuristic
We use minimum-degree (min-degree) [8] heuristic for obtaining tree decompositions. The min-degree heuristic uses a graph in which all the variables will have a node. There will be an edge between two nodes if the corresponding two variables occur together in an input CNF clause. Given such a graph, the following steps will be repeated until all nodes are eliminated from the graph: 1. select a node n with minimum degree.
2
2. form a clique between the node n and all of its neighbors, by adding an edge between two neighbors of n, if required. 3. remove (eliminate) the node n and all the edges connected to it from the graph. A tree decomposition can be obtained when all the nodes are being eliminated by the above method. Each clique formed during the elimination process will have a corresponding node in the tree decomposition. A tree node will contain all the variables in its corresponding clique. The edges between the nodes in the tree decomposition are obtained as follows. In the step-3 of the above elimination process, when the node n with k neighbors is removed, the k neighbors will still form a clique of size k in the remaining graph. All such k-cliques can be marked and each one of them can be associated with the tree node formed during the immediate previous step. When a new clique is formed in step-2, if it contains any marked k-clique, then the tree node corresponding to the new clique will have an edge with each one of the tree nodes associated with the contained marked cliques. Note that, in a tree decomposition, when the variables contained in a tree node n1 form a subset of the variables contained in its adjacent node n2 , then the node n1 can be removed after adding an edge between n2 and each one of the neighbors of n1 . Using the largest sized node in a tree decomposition obtained by min-degree as the root node, we can arrange the nodes in the tree and mark the leaf nodes accordingly. During a traversal along any path from a leaf node to the root node, the structure of the min-degree heuristic decompositions are such that the number of variables contained in a node in the path will keep increasing. Due to elimination of the minimum degree nodes, the size of the cliques created during the elimination process tend to increase with each node elimination. The leaf nodes would have been created earlier in the elimination process and the root node at the end.
2.2
Binary Decision Diagrams
A binary decision diagram (BDD) [1] is a rooted directed acyclic graph with two terminal nodes marked with 0 and 1. The non-terminal nodes are associated with a propositional variable and each one of them will have two outgoing edges, one solid and one dashed. The solid (dashed) edges are used when the corresponding variables take true (false) value. Figure 1 shows a sample BDD. The solid (dashed) edge is also mentioned as high (low) edge. Given a BDD representing a propositional function, each path from the root node to the 1-terminal node represents one or more solutions to the function. A non-occurrence of a variable’s node in such a path would mean that the variable is a don’t care variable and hence it can take both true and false values. Similarly, paths from the root to the 0-terminal node represent the non-solutions of the function. We are only interested in a special type of BDD called reduced ordered binary decision diagram(ROBDD), in which the nodes in the BDD 3
aB a
bB b
bB b
c
c
d
d
c
d
cFB
cFB
cFB
dB
d
dB
d
d
e
e
1 1
cFB
c
0
0
Figure 1: A Binary Decision Diagram
Figure 2: An example for the Minimal Reason-Vars algorithm
obey a selected variable order in all paths in the BDD, and isomorphic nodes are merged and represented by a single node. Hereafter, we simply mention ROBDD as BDD. The size of a BDD b, denoted by |b|, is the number of nodes in the BDD. Given two BDDs, b1 and b2 , representing two Boolean functions, the time and space complexity of the conjoin (disjoin) operation between them is O(|b1 |*|b2 |) [9]. The time and space complexity of existential quantification of a variable from a BDD of size |b| is O(|b|*|b|) [9]. Given a CNF clause, its equivalent BDD can be obtained by disjoin operations between the BDDs representing the literals in the clause. Let the assignment of a propositional value val to a propositional variable var be denoted by the pair (var,val ). A path from a BDD node to one of the terminal nodes is said to contain an assignment pair (var,val ), if the path contains an edge corresponding to the assignment pair or there is no var node in the path. A path is said to violate an assignment pair (var,val ) if the path does not contain (var,val ). The nice property of BDDs is their ability to succinctly represent several practical propositional functions, due to which they have been widely used in the verification area. Hence, we use BDDs to represent the partial solution spaces of tree nodes in our decomposition based SAT solver. The size of the BDD representing a function can vary exponentially based on the variable order used [9]. Since, a typical SAT instance will have a lot of variables, in our work, we do not spend time on finding good variable order. We just use the order in which the variables are numbered in a DIMACS-format CNF instance.
4
3
The Hybrid SAT Solver
3.1
The Hybrid Representation
Given a tree decomposition of a SAT problem, the satisfiability of the problem can be determined as follows: 1. For each leaf node in the tree, create a BDD of the node by conjoining the BDDs representing the clauses covered by the leaf node. 2. A tree node is qualified for this step if the BDDs for each one of its child nodes have been created. If there is any qualifying node n, create a BDD by conjoining all the BDDs of the child nodes of n along with the BDDs representing each one of the clauses covered by n. Then, existentially quantify out any variable v from the so obtained BDD, if the variable v only occurs in the subtree rooted at n. The resulting BDD is associated with n. 3. Repeat the previous step if there is any qualifying tree node for the step. At the end of the above procedure, if the BDD for the root node represents false then the input problem is unsatisfiable, otherwise satisfiable.
Figure 3: The Tree Decomposition to the Hybrid Representation conversion Although the BDDs can succinctly represent the solution spaces of small SAT problems, for large problems the above procedure will typically fail due to large memory requirements to store BDDs. Hence, we modify the above procedure such that BDDs of restricted size only are created. Towards this we parameterize the BDD creation process by h, where h is an integer in the range [0,..,2n ], n is the number of variables in the input SAT problem. For a given h, the BDD for a tree node is created only if the size of the BDD is at most h*nLits, where nLits is the number of literals in the clauses covered by the subtree rooted at the tree node. Whenever a BDD is created in step-1 or step-2 of the above procedure, the size restriction is checked. If it is not violated, then the BDD will be accepted and the clauses covered by the tree node will be removed from the CNF. Otherwise, the BDD will be discarded and the corresponding node will be marked as unqualified for step-2. After such parametrization, the above procedure results in a hybrid representation of the SAT problem using some BDDs and some CNF clauses. Note 5
that when we accept a BDD created for a tree node, then the BDDs for all of its child nodes can be discarded. Due to the properties of tree decomposition, this is enough to determine satisfiability. When a satisfying solution is required in case of a satisfiable input, we cannot discard the BDDs of the child nodes. In this work we just focus on determining satisfiability, since extending our work to find a satisfying solution is trivial. When h=0, only BDDs of size zero will be accepted, i.e. either true or false. This would be equivalent to a pure CNF representation. When h=2n , BDDs of all sizes will be accepted, hence, given enough time and memory, the BDD of the root node will be created. This is equivalent to a pure BDD SAT solver with interleaved conjoins and quantifications. The intermediate values of h would result in a real hybrid representation. The choice for h makes a cut in the tree decomposition as shown in the Figure 3. A triangle in the figure represents a BDD that replaces a subtree below the cut. All the clauses covered by each subtree below the cut will be replaced by a BDD in the hybrid representation.
3.2
The Solver
To build a zChaff [10] style SAT solver to work on this hybrid representation we need to port the techniques like watching-based lazy propagation [11], conflictdirected backtracking [12] and conflict clause learning [12, 10] from the pure CNF representation to the hybrid representation. We use the VSIDS [11] heuristic for making branching decisions in the hybrid SAT solver. The two-literal watching based lazy propagation [12] is used in the CNF part. The propagation in a BDD is done by a very naive procedure which traverses the nodes in the BDD. During the traversal the procedure visits only those nodes that can be reached by the assignments that have been made and marks the possible assignments for any unassigned variable in the tree node corresponding to the BDD. In case an unassigned variable has only one of its possible Boolean choices marked during the process, it results in an implication by the BDD. In case both the choices of an unassigned variable are unmarked during the process then it results in a conflict. The complexity of this trivial function is linear in the number of nodes in the BDD. When conflicts occur in the search process, we use the 1-UIP [10] type conflict clause learning. Since the 1-UIP conflict learning procedure results in an asserting clause [12, 10], the SAT solver backtracks to the asserting decision level after learning a conflict clause. In the 1-UIP learning scheme, when a variable implication at the latest decision level is involved in a conflict, all the assignments prior to the implication which are enough to make the implication need to be found. We call the set of variables in the assignments which are enough for an implication reason-vars set for the implication. Finding reason-vars is trivial for an implication by a CNF clause, as all the variables in the clause, except the implied one, are reason-vars for the implication.
6
In case of an implication made by a BDD, this process is non-trivial. All the variables in the BDD that were assigned a value before the implication would themselves constitute a reason-vars set. But such a set of reason-vars is not useful as only a small subset among them might still be a reason-vars set and using a smaller sized reason-vars set would result in smaller conflict learnt clauses and hence better propagation. Hence, we would like to have a reason-vars set whose size is minimum.
3.3
A Linear Time Algorithm for Minimal Reason-Vars
We are not aware of any BDD algorithm that can find a minimum or even minimal reason-vars set in linear-time. We give an algorithm to this problem, that can obtain a minimal reason-vars set. The complexity of the algorithm is linear in the number of nodes in the BDD. Given a set of assignments A={(vara1 ,vala1 ),..,(varak ,valak )}, a BDD b and an implication (vari ,vali ), where the assignments A result in the BDD to imply (vari ,vali ). Our goal is to find a minimal subset of variables in A, whose assignments are enough for the BDD to imply (vari ,vali ). Let the m variables contained in the tree node corresponding to the BDD b be {varc1 ,..,varcm }. Let the variable order used in the BDD be varcl < varcl+1 . In a BDD each path from the root node to the 1-terminal represents one or more solutions. That the pair (vari ,vali ) was implied by the BDD b means that there is no path in the BDD that contains (vari ,¬vali ), such that the path does not violate any of the assignments of A. Given any path from the root node of BDD to the 1-terminal that contains (vari ,¬vali ), there will be at least one edge in the path that violates an assignment in A. Among them we can pick the edge that is nearest to the 1-terminal and label it as a frontier edge. If a node has one of its outgoing edges labeled as a frontier edge, then the node could be labeled as a frontier node. Considering all the paths in the BDD which contain (vari ,¬vali ), we can label all the frontier nodes in the BDD. This can be done in linear time, as a BDD is a rooted directed acyclic graph. Given a node n from the BDD, the propositional term frontier(n) evaluates to true if and only if n is labeled as a frontier node. In our algorithm for finding minimal reason-vars, we will mark some nodes with the blue color. The term blue(n) evaluates to true if and only if the node is marked with blue color. Let var(n) denote the variable associated with the BDD node n. The pseudo code of our algorithm for finding minimal reason-vars is shown in Algorithm 1. Additional low-level details of the algorithm and arguments on the correctness and complexity of the algorithm are in the appendix of this paper. An example for the minimal reason-vars algorithm is shown in Figure 2. In the example, the set of variables in the tree node of the BDD is {a,b,c,d,e}. The BDD in the example is the same as the one in Figure 1, but with frontier labelings and blue marks. An entry ”F” (”B”) in a node of the BDD refers to a frontier label (blue mark). In the example, the set A={(a,1),(c,1),(e,0)} and 7
Algorithm 1 An algorithm to find Minimal Reason-Vars 1: REASONVARS(A, b, (vari ,vali )) 2: Label all frontier nodes 3: Mark the root node as blue 4: for j = 1 to m do 5: BMN:={n|∃n ∈ b.blue(n)∧(var(n)=varcj )} 6: if @n∈BMN.frontier(n) then 7: for all n ∈ BMN do 8: if i = cj then 9: Mark the ¬vali child node of n with blue 10: else 11: Mark both the child nodes of n with blue 12: end if 13: end for 14: else 15: for all n ∈ BMN do 16: Mark the valj child node of n with blue 17: end for 18: end if 19: end for 20: M:={var(n)|∃n ∈ b.blue(n)∧frontier(n)} 21: return M (vari ,vali )=(d,1 ). The set M returned by the algorithm is {c}. At the end of the reason-vars algorithm, a node in the BDD will be marked with blue, if the node can be reached from the root node without using an edge that violates an assignment of the variables in M and also without using a (vari ,vali ) edge. Note that, during a run of the reason-vars algorithm, a frontier node n will not be marked blue, if there is an edge (varx ,valx ) in all the paths between n and the root node, such that ∃k ∈ b.blue(k)∧frontier(k)∧(var(k)=varx ) and (varx ,¬valx )∈ A.
4
Experiments
A prototype of the hybrid SAT solver was implemented in C++. The BDD part of the solver was implemented using the BuDDy [13] package. Experiments were done on six sets of benchmark instances. The barrel [14], longmult [14], cnt [15] and w08 [15] instances are bounded model checking instances, while the x1 [15] instances are xor-chain verification instances and the pipe k [16] instances are microprocessor verification instances. All the longmult, barrel, x1 and pipe k instances are unsatisfiable instances, while all the cnt instances are satisfiable. In case of the w08 instances, the w08 10 instance is unsatisfiable, while the rest are satisfiable. The experiments were performed on an Intel Xeon 3.2GHz dual processor
8
machine, running linux and with 4GB RAM. For each experiment at most 3600 seconds was given for solving an instance. A ”TO” entry in the table mentions a timeout. The benchmark statistics are shown in Table 1. In the table, the first column lists the instance name. The following three columns list the number of variables (#vars), clauses (#cls) and literals (#lits) in the corresponding instance. The next two columns list the number of decisions (#des) and time taken (in CPU seconds) by the Minisat Solver (version 1.14) [17, 18] to solve the instances. The next two columns list the time taken for obtaining a tree decomposition using the min-degree heuristic and the width (ω’) of the decomposition. The last column list the percentage of (ω’/#vars). From the table, we can infer that in many cases the cost of finding the tree decompositions is quite affordable. In some of the cases the tree decompositions have very small tree-width, especially in case of the cnt instances. The rate at which ω’ increases within each family of instances is quite small when compared with the rate of #vars increase. In some of the families, with the increase in the instance size, there is a considerable decrease in the (ω’/#vars) value. This is especially the case in the bounded model checking instances. The implementation of our hybrid solver is mainly intended for studying the benefits due to different levels of hybridization. Since our implementation is not optimized for speed, it cannot be compared with well-optimized SAT solvers like Minisat. Also, our implementation does not have some of the techniques like clause deletion [11], clause minimization [19] and random restarts [11]. We did the experiments on our six set of instances with six different values for h (the hybridization parameter): {0,1,2,4,8,2n}. The results of the experiments are listed in the Table 2. All the CPU time listings in the table include the time taken for obtaining a min-degree decomposition for the corresponding instances. When h=0, the hybrid solver behaves as a pure CNF solver, as BDDs of size zero are alone allowed. At level h=2n , since the hybrid representation creation process alone will determine satisfiability, there is no requirement for the #des column. The ”MO” (memory out) entries in this column mean aborts of the corresponding experiments due to the memory limitations. Except the case of cnt and x1 instances, the h=2n experiments have to be aborted. Since BDDs can provide higher level of consistency than the pure CNF representations, we would expect fewer decisions when we allow larger BDDs. But as we can infer from the tables, in most of the cases, with the increase in the level of hybridization there is no effect on the number of decisions. The exceptions are cnt and x1 instances. Hence, even if we can find a better way of doing unit propagation in BDDs, it might not be useful, due to almost no reduction in the number of decisions required in the hybrid solver. In case of the cnt instances, the reason for the success of h=2n level should be mainly due to the very low tree width. For example, the cnt10 instance has 20470 variables, but its tree width is just 38 and such a tree decomposition can be obtained in just 3 seconds using min-degree. Interestingly, the rate at which the tree width of the cnt instances increase is very small when compared with the corresponding increase in the number of variables. For example cnt10 has 9
Instance
Original
Minisat
MinDeg
#vars
#cls
#lits
#des
Time
Time
ω’
(ω’/#vars)%
barrel5
1407
5383
14814
25464
1
0.78
171
12.15
barrel6
2306
8931
24664
98669
4
3.41
289
12.53
barrel7
3523
13765
38112
214373
22
7.24
407
11.55
barrel8
5106
20083
55716
164743
78
21.96
585
11.46
barrel9
8903
36606
102370
3671194
164
72.42
874
9.82
longmult7
3319
10335
24957
15656
3
0.65
86
2.59
longmult8
3810
11877
28667
55962
17
0.71
102
2.68
longmult9
4321
13479
32517
93112
37
0.84
99
2.29
longmult10
4852
15141
36507
123972
55
0.93
104
2.14
longmult11
5403
16863
40637
144381
71
1.06
115
2.13
longmult12
5974
18645
44907
150683
79
1.30
107
1.79
longmult13
6565
20487
49317
161321
84
1.54
120
1.83
longmult14
7176
22389
53867
128639
82
1.55
120
1.67
longmult15
7807
24351
58557
95544
50
1.82
126
1.61
cnt05
316
1002
2738
673
0.01
0.02
14
4.43
cnt06
762
2469
6753
452
0.04
0.04
21
2.76
cnt07
1786
5856
16016
20840
0.3
0.10
23
1.29
cnt08
4089
13531
36991
79958
2
0.33
24
0.59
cnt09
9207
30678
83822
363761
24
1.14
32
0.35
cnt10
20470
68561
187229
1620603
228
3.31
38
0.19
x1 16
46
122
364
6068
0.3
0.00
10
21.74
xl 24
70
186
556
174806
1
0.00
17
24.29
xl 32
94
250
748
557869
3.3
0.01
22
23.40
xl 36
106
282
844
1934814
13
0.01
25
23.58
xl 40
118
314
940
11777704
106
0.00
25
21.19
xl 44
130
346
1036
67154414
719
0.01
28
21.54
xl 48
142
378
1132
12738588
112
0.00
26
18.31
xl 56
166
442
1324
TO
0.01
38
22.89
xl 64
190
506
1516
TO
0.02
34
17.89
xl 72
214
570
1708
TO
0.01
42
19.63
xl 80
238
634
1900
TO
0.01
47
19.75
x1 96
286
762
2284
TO
0.01
65
22.73
xl 128
382
1018
3052
TO
0.03
66
17.28
2pipe k
860
6693
18633
6566
0.1
2
114
13.26
3pipe k
2391
27405
78127
66110
3
30
273
11.42
4pipe k
5095
79489
229675
1363155
1160
208
483
9.48
5pipe k
9330
189109
551125
TO
1070
950
10.18
6pipe k
15346
408792
1199026
350
TO
1383
9.01
7pipe k
23909
751116
2211464
TO
TO
1939
8.11
w08 10
71615
248504
604106
34694
18
177
1731
2.42
w08 14
120367
425316
1038230
245482
398
482
2476
2.06
w08 15
132555
469519
1146761
304040
569
535
2153
1.62
4858021
Table 1: Benchmark statistics
10
Instance
h=0 #des
h=1 Time
#des
h=2 Time
#des
h=4
Time
h=2n
h=8
#des
Time
#des
Time
Time
barrel5
10181
2
6248
4
5971
5
5759
216
6493
32
MO
barrel6
29120
13
22241
18
26566
28
24018
258
25563
285
MO
barrel7
75471
84
54947
87
43701
45
46940
316
72380
609
MO
barrel8
86185
172
74935
115
66350
102
74517
961
107803
1701
MO
barrel9
345055
493
231851
530
426801
1186
478656
1718
longmult7
23153
14
15456
27
14289
44
15688
870
17520
longmult8
52817
59
42156
95
35198
124
40944
234
longmult9
84480
137
66481
181
74399
339
73674
461
longmult10
113642
201
91055
282
118978
560
123713
longmult11
127923
224
112036
422
127331
728
longmult12
121660
197
159430
702
129012
longmult13
114271
176
150467
706
longmult14
145838
308
132870
longmult15
117011
162
cnt05
627
cnt06 cnt07
TO
MO
197
MO
35307
511
MO
81309
1195
MO
787
113580
1369
MO
133042
1026
136856
2060
MO
785
131310
1193
132840
1625
MO
182749
1248
133606
1277
126893
1993
MO
636
153947
1239
142029
1602
131025
2632
MO
113217
519
113872
719
113408
1144
95167
1663
MO
0.2
5
0.2
0
0.2
0
0.16
0
0.19
0.2
3218
0.3
1465
0.4
0
0.3
0
0.22
0
0.22
0.3
18055
0.8
11837
3
3224
2
68
0.39
0
0.36
0.5
cnt08
90636
11
44991
17
35507
22
7333
630
0
0.69
1
cnt09
354998
96
246166
184
143212
150
137478
269
113592
300
3
cnt10
1590226
2085
1076313
1859
726391
1410
634009
2291
TO
12
x1 16
1422
0.2
0
0.5
0
0.5
0
0.5
0
0.5
0.5
xl 24
29074
2
0
0.5
0
0.5
0
0.5
0
0.5
0.5
xl 32
471350
796
0
0.5
0
0.5
0
0.5
0
0.5
0.5
xl 36
TO
0
0.5
0
0.5
0
0.5
0
0.5
0.5
xl 40
TO
0
0.5
0
0.5
0
0.5
0
0.5
0.5
xl 44
TO
0
0.5
0
0.5
0
0.5
0
0.5
0.5
xl 48
TO
0
0.5
0
0.5
0
0.5
0
0.5
0.5
xl 56
TO
0
0.5
0
0.5
0
0.5
0
0.5
0.5
xl 64
TO
0
0.5
0
0.5
0
0.5
0
0.5
0.5
xl 72
TO
0
0.5
0
0.5
0
0.5
0
0.5
0.5
xl 80
TO
0
0.5
0
0.5
0
0.5
0
0.5
0.5
x1 96
TO
0
0.5
0
0.5
0
0.5
0
0.5
0.5
xl 128
TO
0
0.5
0
0.5
0
0.5
0
0.5
0.5
1
6856
4
7329
9
8203
18
7240
15
MO
173175
1063
109413
2pipe k
12788
3pipe k
148601
38
85927
153
55548
193
1238
MO
4pipe k
788461
667
678733
2787
438606
3560
TO
TO
MO
5pipe k
1856324
2943
TO
TO
TO
TO
MO
6pipe k
TO
TO
TO
TO
TO
MO
7pipe k
TO
TO
TO
TO
TO
MO
625
MO
w08 10
34536
58
24570
187
w08 14
300409
1148
203378
2456
w08 15
294824
817
181341
1683
17925
262
106069
1860
17116
394 TO
TO
MO
92761
2537
TO
MO
TO
Table 2: Experiments with different values of h
11
15528
more than double the number of variables in cnt09, but the tree width of cnt10 is just 20% more than the tree width of cnt09. In case of the x1 instances, which are known to be very hard for DPLL solvers, pure CNF is not able to scale as high as the BDD hybrids. By observing the (ω’/#vars) column, the tree width for these instances does not seem to be very low. Hence, the BDD representation should have been the main reason for the scalability of the hybrid solver in the x1 instances.
5
Related Work
In [4], the authors converted each one of the clauses in an input CNF SAT problem into a BDD. Then a heuristic was used to conjoin the obtained BDDs. During the conjoining process, a variable will be existentially quantified out if it occurs in only one BDD. The conjoining process was restricted such that BDDs of size at most 100 nodes were only created. Then a hybrid SAT solver was implemented to decide satisfiability, in which the conflict learnt clauses will be in CNF form. In [4], we can observe that the restriction of creating BDDs of size at most 100 is ad hoc. We have defined an improved measure h*nLits, which is willing to create a BDD of size larger than 100 if the BDD replaces enough literals. This is more reasonable than a constant size limit. Also, most of the interesting instances used in the experiments of [4] are nonpublicly available industrial instances. This makes it hard to infer conclusions from their experiments. All the instances we use and the descriptions of their origin are publicly available. Unlike [4], we use a tree decomposition to guide the BDDs creation process. This results in conversion of some parts of an input CNF into BDDs, while the rest remains in CNF form. In [5], the authors used tree decomposition techniques to guide a CNF SAT solver, such that conflict learning creates clauses of size bounded by the width of a tree decomposition. The authors of [5] evaluated two heuristics to obtain tree decompositions: MINCE [20] and min-degree. Upon a preliminary evaluation the authors found out that the tree width of the tree decomposition by MINCE is generally smaller than that by the min-degree heuristic. Although the authors had also observed that min-degree heuristic is very fast than the MINCE, they dumped min-degree in favor of MINCE, mentioning the importance of smaller tree width. But the problem with MINCE, as observed in [5], is that the cost of obtaining MINCE tree decompositions of a SAT instance very often exceeds the actual cost of solving the instance using the state-of-the-art SAT solving techniques. Hence, we use min-degree heuristic in our work. Although min-degree might give poorer decompositions compared to the MINCE heuristic, when compared to the number of variables in an instance, the width of a decomposition obtained by min-degree is still very small (see Table 1). In [4], the authors did not give the details of their method for generating minimal reason-vars set, and the complexity of their method was also not mentioned. Recently in [21], the authors have given a method for finding minimal reason-vars set, but the complexity of their method is quite high, as their
12
method uses several existential quantification operations. Also, their method creates new BDD nodes, which should preferably be avoided. In our case, we use existential quantifications and new BDD node creations only while creating the hybrid representation. After that, during hybrid SAT solving, the BDDs remain static.
6
Conclusion
We have presented an evaluation of a hybrid SAT solver. From the experiments on the different levels of hybridization, we can fairly conclude that there are two cases where the hybridization certainly helps: the first case when the instances have very low tree width; the second case when the properties of instances make them hard for DPLL and easy for BDD based solvers. In all other cases, even allowing very small BDDs does not help. This is mainly due to the high cost of unit propagation in BDDs and no significant reduction in the number of required decisions. Therefore, even if one can find a better way of doing unit propagation in BDDs, as it will not reduce the decisions required, it might not improve the overall efficiency. A nice future work topic is to study the effect of our hybrid solver using tree decompositions and BDDs on finding all solutions. Indeed, by storing the BDDs created for each node in the tree decompositions, we can have an implicit representation of all solutions. In ideal cases like the satisfiable cnt instances, we are able to build the BDDs up to the root node. Overall, we hope that our investigations would have clarified the relative interest of CNF and BDD representations.
References [1] Bryant, R.E.: Graph-based algorithms for boolean function manipulation. IEEE Transactions on Computers 8 (1986) 677–691 [2] Groote, J.F., Zantema, H.: Resolution and binary decision diagrams cannot simulate each other polynomially. Discrete Applied Mathematics 130 (2003) 157–171 [3] Bodlaender, H.L.: Discovering treewidth. In: Proceedings of SOFSEM. (2005) 1–16 [4] Damiano, R.F., Kukula, J.H.: Checking satisfiability of a conjunction of BDDs. In: Proceedings of DAC. (2003) 818–823 [5] Bjesse, P., Kukula, J., Damiano, R., Stanion, T., Zhu, Y.: Guiding SAT diagnosis with tree decompositions. In: Proceedings of Theory and Applications of Satisfiability Testing: 6th International Conference, SAT 2003, Selected Revised Papers, Springer LNCS (2004) 315–329
13
[6] Dechter, R.: Constraint Processing. Morgan Kaufmann (2003) [7] Biere, A., Cimatti, A., Clarke, E.M., Zhu, Y.: Symbolic model checking without BDDs. In: Proceedings of TACAS. (1999) 193–207 [8] Heggernes, P., Eisenstat, S., Kumfert, G., Pothen, A.: The computational complexity of the minimum degree algorithm. In: Proceedings of NIK 2001 - 14th Norwegian Computer Science Conference. (2001) 98 – 109 [9] Bryant, R.E.: Symbolic boolean manipulation with ordered binary decision diagrams. ACM Computing Surveys 24 (1992) 293–318 [10] Zhang, L., Madigan, C.F., Moskewicz, M.W., Malik, S.: Efficient conflict driven learning in boolean satisfiability solver. In: Proceedings of ICCAD. (2001) 279–285 [11] Moskewicz, M.W., Madigan, C.F., Zhao, Y., Zhang, L., Malik, S.: Chaff: Engineering an efficient SAT solver. In: Proceedings of the 38th Design Automation Conference (DAC’01). (2001) [12] Silva, J.P.M., Sakallah, K.A.: GRASP: A search algorithm for propositional satisfiability. IEEE Transactions on Computers 48 (1999) 506–521 [13] Lind-Nielsen, J.: BuDDy - A Binary Decision Diagram Package. http://sourceforge.net/projects/buddy (online) [14] CMU-BMC instances. http://www.cs.cmu.edu/~modelcheck/bmc.html (online) [15] SAT 2002 competition instances. http://www.satlib.org (online) [16] Microprocessor Benchmarks. www.ece.cmu.edu/~mvelev/sat_benchmarks.html (online) [17] Een, N., Sorensson, N.: An extensible SAT-solver. In: Proceedings of SAT. (2003) 502–518 [18] Minisat SAT Solver. http://www.cs.chalmers.se/Cs/Research/FormalMethods/ MiniSat/Main.html (online) [19] Een, N., Sorensson, N.: Minisat a SAT solver with conflict-clause minimization. In: Posters of SAT. (2005) [20] Aloul, F., Markov, I., Sakallah, K.A.: MINCE: A static global variableordering heuristic for sat search and bdd manipulation. Journal of Universal Computer Science 10 (2004) 1562–1596 [21] Hawkins, P., Stuckey, P.J.: A hybrid BDD and SAT finite domain constraint solver. In: Proceedings of PADL. (2006) 103–117 APPENDIX 14
A
The Linear Time Algorithm for Minimal ReasonVars
Given a set of assignments A={(vara1 ,vala1 ),..,(varak ,valak )}, a BDD and an implication (vari ,vali ), where the assignments A results in the BDD to imply (vari ,vali ). Our goal is to find a minimal subset of variables in A, whose assignments are enough for the BDD to imply (vari ,vali ). In a BDD each path from the root node to the 1-terminal represents one or more solutions. The pair (vari ,vali ) was implied by the BDD means that there is no path in the BDD that contains (vari ,¬vali ), such that the path does not violate any of the assignments of A. Given any path from the root node of BDD to the 1-terminal that contains (vari ,¬vali ), there will be at least one edge in the path, that violates an assignment in A. Among them we can pick the edge that is nearest to the 1-terminal and label it as a frontier edge. If a node has one of its outgoing edges labeled as a frontier edge, then the node could be labeled as a frontier node. Considering all the paths in the BDD which contain (vari ,¬vali ), we can label all the frontier nodes in the BDD. This can be done in linear time, as a BDD is a rooted directed acyclic graph. Now mark the root node of the BDD. Then, in the sequence of the variable order used in the BDD, look at the marked nodes of each variable v in the BDD. If v=vari , then mark the child nodes of the marked nodes of v, which can only be reached using the ¬vali edge. This is because, when we find the minimal reason-vars set we can ignore the solutions paths not containing (vari ,¬vali ). If the variable v is not vari , and none of the marked nodes of v is a frontier node, then mark both the child nodes of each one of the marked nodes of v. If any of the marked nodes of the variable v is a frontier node, then for each node n of those marked nodes, mark the child node of n, which can only be reached using the outgoing edge of n that contains the assignment for v. Note that the 1-terminal cannot be marked, as we ignore all the solution paths not containing (vari ,¬vali ), and in the rest of the paths there will be at least one marked frontier node. Now, let M be the set of variables, such that for each v ∈ M, there is at least one node of v in the BDD, which is a marked frontier node. The set M is a minimal reason-vars set. The following low-level descriptions can be used in checking the correctness and the linear-time complexity of the whole algorithm. The algorithm we call GetReasonVars is shown in Figure 4. In the figure (vari ,vali ) is denoted by (impliedVar,impliedValue). The GetReasonVars procedure requires five variables to be associated with each node in a BDD. The five variables are: highcolor, lowcolor, color, colorMarked and isFrontier. The first three variables can be assigned a value from the set {GREEN,RED,BLUE}, while the last two variables are Boolean variables. Apart from these variables, each node will also have a variable varId denoting the variable of the node. The notation ”b.highNode” refers to the BDD node at the end of the high edge of the BDD node b. The procedure takes three arguments. The first one ”tn” denotes the tree
15
GetReasonVars(TreeNode tn, BddNode b, int[] isRequired) 1 MarkReasonColor(b) 2 b.color=BLUE 3 forall varId contained in tn /* loop in the BDD variable order */ 4 blueMarkedNodes=GetBlueMarkedNodes(varId,b) 5 forall node in blueMarkedNodes 6 if(node.isFrontier) 7 isRequired[varId]=TRUE 8 if(isRequired[varId]==FALSE) 9 forall node in blueMarkedNodes 10 if(varId!=impliedVar || impliedValue!=TRUE) 11 node.highNode.color=BLUE 12 if(varId!=impliedVar || impliedValue!=FALSE) 13 node.lowNode.color=BLUE 14 else 15 forall node in blueMarkedNodes 16 if(value[varId]==TRUE) 17 node.highNode.color=BLUE 18 else 19 node.lowNode.color=BLUE Figure 4: The GetReasonVars algorithm. node whose BDD made the implication. The second one ”b” denotes the root node of the BDD. The last one ”isRequired ” is an array of Boolean values indexed by variables. Before calling the procedure, the isFrontier and colorMarked variables in all the nodes of the BDD needs to be initialized to FALSE. All the entries in the isRequired array needs to be FALSE as well. When the procedure returns, the variables contained in the tree node ”tn”, whose isRequired value is set to TRUE will be a minimal reason-vars set. The procedure calls another procedure called MarkReasonColor shown in Figure 5. The MarkReasonColor algorithm is a recursive procedure which takes a BDD Node ”b” as input. When the procedure returns, the ”b.color” will be set to GREEN if there is a path from b to the 1-terminal not containing (vari ,vali ), and the path does not violate any of the assignments in A. The MarkReasonColor procedure assigns TRUE value to the isFrontier variable of a node, only if there exists a path from the node to the 1-terminal node by violating the assignment of the varId of the node, without violating any other assignment in A and the path does not contain (vari ,vali ). We label a node whose isFrontier is set to TRUE as a frontier node. When the call made to the MarkReasonColor from the GetReasonVars procedure returns, the color of the root node of the BDD will have been set a RED value, otherwise there would not have been an implication of (vari ,vali ). At the line 2 of the GetReasonVars procedure, the color of the root node
16
of the input BDD is set to BLUE. At the end of the procedure, the BLUE marked nodes are those that can be reached from the root node without using any frontier edge. The line 3 starts a loop on the list of variables contained in the tree node ”tn”, where the variables in the list are ordered based on the variable ordering used in the BDD. The procedure GetBlueMarkedNode(varId,b) would return a list of all the varId variable nodes in ”b”, which are marked with BLUE color. Note that, in a loop for a variable varId, isRequired[varId] is set to TRUE, only if there exists at least one frontier node of varId, which node can be reached by a path from the root node of the input BDD, with the path not containing an another frontier node with its isRequired value set to FALSE. When the GetReasonVars procedure returns, all the variable contained in the ”tn” tree node, whose isRequired value is set to TRUE will form a minimal reason-vars set. MarkReasonColor(BddNode b) 1 if(b==1-terminal) b.color=GREEN; b.colorMarked=TRUE; return 2 if(b==0-terminal) b.color=RED; b.colorMarked=TRUE; return 3 if(b.highNode.colorMarked==FALSE) MarkReasonColor(b.highNode) 4 if(b.lowNode.colorMarked==FALSE) MarkReasonColor(b.lowNode) 5 b.highColor=b.highNode.color; b.lowColor=b.lowNode.color 6 if(b.varId==impliedVar) 7 if(impliedValue==TRUE) 8 b.highColor=RED 9 else 10 b.lowColor=RED 11 else 12 if(value[b.varId]==FALSE) 13 if(b.highColor==GREEN) 14 b.highColor=RED; b.isFrontier=TRUE 15 else if(value[b.varId]==TRUE) 16 if(b.lowColor==GREEN) 17 b.lowColor=RED; b.isFrontier=TRUE 18 if(b.highColor==GREEN || b.lowColor==GREEN) 19 b.color=GREEN 20 else 21 b.color=RED 22 b.colorMarked=TRUE; return Figure 5: The MarkReasonColor algorithm.
A.0.1
The correctness of GetReasonVars
The correctness of GetReasonVars procedure can be observed from the facts: 1. any of the paths from the root node of the BDD to the 1-terminal, that 17
contains the assignment (vari ,¬vali ) violate at least one among the assignments of the variables in the reason-vars set obtained by using GetReasonVars procedure. This shows that the reason-vars set is enough for the implication. 2. removing any variable from the obtained reason-vars set will result in a path from a BLUE marked frontier node to the 1-terminal node without violating the assignment to the other variables in the reason-vars set. Since, this implies that the assignment pair (vari ,vali ) is not an implication, the reason-vars set obtained by GetReasonVars is minimal. A.0.2
The complexity of GetReasonVars
The initialization of isRequired to FALSE values needs to be done only once, when the hybrid SAT solver is started. After each call to GetReasonVars, only the isRequired entries of the variables in the corresponding tree node needs to be reset to FALSE. The initialization of isFrontier and colorMarked values of the BDD nodes could be done in a traversal of the BDD nodes in linear-time. The total number of calls to MarkReasonVars is linear as the function is invoked at most once for a node. An implementation of the GetBlueMarkedNodes will also need only linear time; we can maintain a list of BLUE marked nodes for each varId, a node is entered into the list at most once and the list of BLUE marked nodes for a variable is read at most once. Since, each line inside the loop at line 3 of GetReasonVars is used at most once for each node in the BDD, the complexity of the GetReasonVars procedure is linear in the number of nodes in the BDD.
18