CBMC
bdd_cudd.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Binary Decision Diagrams
4 
5 Author: Romain Brenguier, romain.brenguier@diffblue.com
6 
7 \*******************************************************************/
8 
14 
15 #ifndef CPROVER_SOLVERS_BDD_BDD_CUDD_H
16 #define CPROVER_SOLVERS_BDD_BDD_CUDD_H
17 
18 #include <cplusplus/cuddObj.hh>
19 
20 #include <util/narrow.h>
21 
22 class bdd_managert;
23 class bddt;
24 class bdd_nodet;
25 
27 class bdd_nodet
28 {
29 public:
30  bool is_constant() const
31  {
32  return Cudd_IsConstant(node) != 0;
33  }
34 
35  bool is_complement() const
36  {
37  return Cudd_IsComplement(node) != 0;
38  }
39 
41  using indext = unsigned int;
42 
44  indext index() const
45  {
46  return Cudd_NodeReadIndex(node);
47  }
48 
50  {
51  return bdd_nodet(Cudd_T(node));
52  }
53 
55  {
56  return bdd_nodet(Cudd_E(node));
57  }
58 
60  using idt = DdNode *;
61 
63  idt id() const
64  {
65  return node;
66  }
67 
68 private:
69  DdNode *node;
70  explicit bdd_nodet(DdNode *node) : node(node)
71  {
72  }
73  friend class bdd_managert;
74 };
75 
77 class bddt
78 {
79 public:
80  bool equals(const bddt &other) const
81  {
82  return bdd == other.bdd;
83  }
84 
85  bool is_true() const
86  {
87  return bdd.IsOne();
88  }
89 
90  bool is_false() const
91  {
92  return bdd.IsZero();
93  }
94 
95  bddt bdd_not() const
96  {
97  return bddt(!bdd);
98  }
99 
100  bddt bdd_or(const bddt &other) const
101  {
102  return bddt(bdd.Or(other.bdd));
103  }
104 
105  bddt bdd_and(const bddt &other) const
106  {
107  return bddt(bdd.And(other.bdd));
108  }
109 
110  bddt bdd_xor(const bddt &other) const
111  {
112  return bddt(bdd.Xor(other.bdd));
113  }
114 
115  static bddt bdd_ite(const bddt &i, const bddt &t, const bddt &e)
116  {
117  return bddt(i.bdd.Ite(t.bdd, e.bdd));
118  }
119 
120  bddt constrain(const bddt &other)
121  {
122  return bddt(bdd.Constrain(other.bdd));
123  }
124 
125  bddt &operator=(const bddt &other) = default;
126 
127 private:
128  BDD bdd;
129  friend class bdd_managert;
130  explicit bddt(BDD bdd) : bdd(std::move(bdd))
131  {
132  }
133 };
134 
137 {
138 public:
140  {
141  }
142 
143  bdd_managert(const bdd_managert &) = delete;
144 
146  {
147  return bddt(cudd.bddOne());
148  }
149 
151  {
152  return bddt(cudd.bddZero());
153  }
154 
156  {
157  return bddt(cudd.bddVar(narrow_cast<int>(index)));
158  }
159 
160  bdd_nodet bdd_node(const bddt &bdd) const
161  {
162  return bdd_nodet(bdd.bdd.getNode());
163  }
164 
165 private:
166  Cudd cudd;
167 };
168 
169 #endif // CPROVER_SOLVERS_BDD_BDD_H
Manager for BDD creation.
Definition: bdd_cudd.h:137
bddt bdd_false()
Definition: bdd_cudd.h:150
bddt bdd_true()
Definition: bdd_cudd.h:145
bdd_nodet bdd_node(const bddt &bdd) const
Definition: bdd_cudd.h:160
bdd_managert(const bdd_managert &)=delete
bddt bdd_variable(bdd_nodet::indext index)
Definition: bdd_cudd.h:155
Low level access to the structure of the BDD, read-only.
Definition: bdd_cudd.h:28
indext index() const
Label on the node, corresponds to the index of a Boolean variable.
Definition: bdd_cudd.h:44
unsigned int indext
Type of indexes of Boolean variables.
Definition: bdd_cudd.h:41
DdNode * idt
Return type for id()
Definition: bdd_cudd.h:60
bool is_complement() const
Definition: bdd_cudd.h:35
idt id() const
Unique identifier of the node.
Definition: bdd_cudd.h:63
bdd_nodet(DdNode *node)
Definition: bdd_cudd.h:70
bool is_constant() const
Definition: bdd_cudd.h:30
bdd_nodet then_branch() const
Definition: bdd_cudd.h:49
DdNode * node
Definition: bdd_cudd.h:69
bdd_nodet else_branch() const
Definition: bdd_cudd.h:54
Logical operations on BDDs.
Definition: bdd_cudd.h:78
bool equals(const bddt &other) const
Definition: bdd_cudd.h:80
bddt bdd_xor(const bddt &other) const
Definition: bdd_cudd.h:110
bddt constrain(const bddt &other)
Definition: bdd_cudd.h:120
static bddt bdd_ite(const bddt &i, const bddt &t, const bddt &e)
Definition: bdd_cudd.h:115
bddt bdd_or(const bddt &other) const
Definition: bdd_cudd.h:100
bddt bdd_not() const
Definition: bdd_cudd.h:95
bool is_true() const
Definition: bdd_cudd.h:85
bddt bdd_and(const bddt &other) const
Definition: bdd_cudd.h:105
bool is_false() const
Definition: bdd_cudd.h:90
bddt(BDD bdd)
Definition: bdd_cudd.h:130
bddt & operator=(const bddt &other)=default
BDD bdd
Definition: bdd_cudd.h:128