IT University of Copenhagen
Lecture 7: BDD Construction and Manipulation1. BDD construction2. Boolean operations on BDDs3. BDD-Based configuration
IT University of Copenhagen
Today’s ProgramToday’s ProgramToday’s ProgramToday’s Program
• [12:00-13:15] – Unique table– Build(t)– Apply(op,u1,u2)– BDD-Based configuration (SJHAHM04)
• [13:20-14:00] Henrik Hulgaard, Configit A/S – A configuration technology company
2011 Rune Møller Jensen 2
IT University of Copenhagen
BDD ConstructionBDD ConstructionBDD ConstructionBDD Construction
32011 Rune Møller Jensen
IT University of Copenhagen
Last week:
1.Make a Decision Tree of formula
2.Keep reducing it until no further reductions are possible
This week:• Reduce the decision tree to a BDD while building
it
BDD constructionBDD constructionBDD constructionBDD construction
42011 Rune Møller Jensen
IT University of Copenhagen
• Represent BDD by a table of unique nodes (UT) • Build BDDs recursively,
i.e. to add a new node u:1. Compute high(u) and low(u) and store them in UT
2. Maintain BDD reductions when adding u to UT:
a) Only extend UT with u if high(u) low(u) (non-redundancy test)
b) Only extend UT with u if u UT (uniqueness)
Reduce decision tree to BDD during constructionReduce decision tree to BDD during constructionReduce decision tree to BDD during constructionReduce decision tree to BDD during construction
52011 Rune Møller Jensen
IT University of Copenhagen
Unique Table RepresentationUnique Table RepresentationUnique Table RepresentationUnique Table RepresentationNode Attributes
Represent Unique Table by two tables T and HT : u (i,l,h) H: (i,l,h) u
62011 Rune Møller Jensen
H is the inverse of T:T(u) = (i,l,h) H(i,l,h) = u
u unique node identifier {0,1,2,3,…} i = var(u) variable index {1,2,…,n,n+1}l = low(u) node identifier of lowh = high(u) node identifier of high
u
low(u) high(u)
var(u)
IT University of Copenhagen
Primitive Operations on T and HPrimitive Operations on T and HPrimitive Operations on T and HPrimitive Operations on T and H
72011 Rune Møller Jensen
IT University of Copenhagen
Unique Table Interface: MakeNode (MK)Unique Table Interface: MakeNode (MK)Unique Table Interface: MakeNode (MK)Unique Table Interface: MakeNode (MK)
82011 Rune Møller Jensen
IT University of Copenhagen
Idea: Construct the BDD recursively using theShannon Expansion t = x t[1/x], t[0/x]
• Terminal casesBuild(0) = 0Build(1) = 1
• Recursive case
Build(t(xi,xi+1,…,xn)) = Mk( )
BuildBuildBuildBuild
92011 Rune Møller Jensen
Build(t(0,xi+1,…,xn)) Build(t(1,xi+1,…,xn))
xi
IT University of Copenhagen
BDD ManipulationBDD ManipulationBDD ManipulationBDD Manipulation
112011 Rune Møller Jensen
IT University of Copenhagen
Multi-Rooted BDDMulti-Rooted BDDMulti-Rooted BDDMulti-Rooted BDD
2011 Rune Møller Jensen 12
5 6x1
x2
x3 2
3 4
1 0
Unique Table contains many BDDs
x1 x3 x1 x2
x2
IT University of Copenhagen
ApplyApplyApplyApply
• Apply(op,u1,u2): computes the BDD of u1 op u2
where op : any of the 16 Boolean operatorsu1, u2: root nodes of BDDs
• Relies on the Shannon expansion properties:
(x t1,t0) op (x t’1,t’0) x (t1 op t’1),(t0 op t’0)
(x t1,t0) op t x (t1 op t),(t0 op t)132011 Rune Møller Jensen
IT University of Copenhagen
• Terminal case: u {0,1} u’ {0,1}
App(u u’) = u u’
• Recursive case: u = xv u1, u0 u’ = xw u’1, u’0 App(u u’) = Mk(xv, App(u0 u’0), App(u1 u’1) ) if v = w
Mk(xv, App(u0 u’), App(u1 u’) ) if v < w
Mk(xw, App(u u’0), App(u u’1) ) if w < v
Apply with Apply with opop = = Apply with Apply with opop = =
142011 Rune Møller Jensen
IT University of Copenhagen
Construct BDDs from expression treeConstruct BDDs from expression treeConstruct BDDs from expression treeConstruct BDDs from expression tree
162011 Rune Møller Jensen
x1 x2 x3
u5 u4
u2 u3
x1 x2 x3
u2 u3u4
u5
u6
IT University of Copenhagen
Properties of ApplyProperties of ApplyProperties of ApplyProperties of Apply• Improvements?
– Early termination. E.g., no reason to keep recursing if the left side in a conjunction is 0
• Complexity : O(|u1||u2|) , due to dynamic programming
• So a BDD of any formula can be computed in poly time?
172011 Rune Møller Jensen
IT University of Copenhagen
BDDsBDDsBDDsBDDs • Compact • Equality check easy • Easy to evaluate the truth-value of an assignment • Boolean operations efficient • SAT check efficient • Tautology check efficient • Easy to implement
182011 Rune Møller Jensen
IT University of Copenhagen
BDD-Based ConfigurationBDD-Based ConfigurationBDD-Based ConfigurationBDD-Based Configuration
192011 Rune Møller Jensen
IT University of Copenhagen
A configuration problem C is a triple (Y,D,F)– Y is a set of variables y1, y2, … ,yn
– D is the Cartesian product of their finite domainsD = D1 D2 … Dn
– F = {f1,f2,…,fm} is a set of propositional formulas over atomic propositions yi = v, where v Di, specifying the conditions that the variable assignments must satisfy. Each formula is inductively defined by
f yi = v | f g | f g | f
Configuration ProblemsConfiguration ProblemsConfiguration ProblemsConfiguration Problems
202011 Rune Møller Jensen
IT University of Copenhagen
• y1 {black, white, red, blue} : Color y2 {small, medium, large} : Sizey3 {“Men in black” - MIB, “Save the whales” -STW} : Print
• f1 (y3 = MIB) (y1 = black)f2 (y3 = STW) (y2 small)
• y1 y2 y3black small MIBwhite medium STWred largeblue
T-Shirt ExampleT-Shirt Example11T-Shirt ExampleT-Shirt Example11
212011 Rune Møller Jensen 1: Due to Erik van der Meer, now at Microsoft
IT University of Copenhagen
• y1 {black, white, red, blue} : Color y2 {small, medium, large} : Sizey3 {“Men in black” - MIB, “Save the whales” -STW} : Print
• f1 (y3 = MIB) (y1 = black)f2 (y3 = STW) (y2 small)
• y1 y2 y3black small MIBwhite medium STWred largeblue
T-Shirt ExampleT-Shirt Example11T-Shirt ExampleT-Shirt Example11
222011 Rune Møller Jensen 1: Due to Erik van der Meer, now at Microsoft
IT University of Copenhagen
• y1 {black, white, red, blue} : Color y2 {small, medium, large} : Sizey3 {“Men in black” - MIB, “Save the whales” -STW} : Print
• f1 (y3 = MIB) (y1 = black)f2 (y3 = STW) (y2 small)
• y1 y2 y3black small MIBwhite medium STWred largeblue
T-Shirt ExampleT-Shirt Example11T-Shirt ExampleT-Shirt Example11
232011 Rune Møller Jensen 1: Due to Erik van der Meer, now at Microsoft
IT University of Copenhagen
• y1 {black, white, red, blue} : Color y2 {small, medium, large} : Sizey3 {“Men in black” - MIB, “Save the whales” -STW} : Print
• f1 (y3 = MIB) (y1 = black)f2 (y3 = STW) (y2 small)
• y1 y2 y3black small MIBwhite medium STWred largeblue
T-Shirt ExampleT-Shirt Example11T-Shirt ExampleT-Shirt Example11
242011 Rune Møller Jensen 1: Due to Erik van der Meer, now at Microsoft
IT University of Copenhagen
• y1 {black, white, red, blue} : Color y2 {small, medium, large} : Sizey3 {“Men in black” - MIB, “Save the whales” -STW} : Print
• f1 (y3 = MIB) (y1 = black)f2 (y3 = STW) (y2 small)
• y1 y2 y3black small MIBwhite medium STWred largeblue
T-Shirt ExampleT-Shirt Example11T-Shirt ExampleT-Shirt Example11
252011 Rune Møller Jensen 1: Due to Erik van der Meer, now at Microsoft
IT University of Copenhagen
IPC(C)
1.R COMPILE(C)
2. while |R| > 1 do
3. choose (yi = v) VALIDASSIGNMENTS(R)
4. R R (yi = v)
Interactive Product ConfiguratorInteractive Product ConfiguratorInteractive Product ConfiguratorInteractive Product Configurator
262011 Rune Møller Jensen
IT University of Copenhagen
Idea
1.Use a BDD to represent R
2.Use a polynomial-time BDD algorithm to compute VALIDASSIGNMENTS(R)
BDD-based configurationBDD-based configurationBDD-based configurationBDD-based configuration
272011 Rune Møller Jensen
IT University of Copenhagen
1. Define domains in binary 00 : black, 01 : white, 10 : red, 11 : blue 00 : small, 01 : medium, 10 : large 0 : MIB, 1 : STW
2. Build a BDD of the rules
Represent Represent RR by a BDD by a BDDRepresent Represent RR by a BDD by a BDD
28
01
11 , xx
02
12 , xx03x
IT University of Copenhagen
• Trace paths for each variable layer in the BDD
Compute VALIDASSIGNMENTS(Compute VALIDASSIGNMENTS(RR))Compute VALIDASSIGNMENTS(Compute VALIDASSIGNMENTS(RR))
29