forked from rnakade/Reduced-Order-Binary-Decision-Diagrams
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbddObj.h
212 lines (148 loc) · 4.15 KB
/
bddObj.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#ifndef _BDDOBJ_
#define _BDDOBJ_
#include <stdio.h>
#include <cassert>
#include <vector>
#include <iostream>
using namespace std;
/************************************************************************
* DO NOT CHANGE THIS #ifdef; enables testing with CUDD
************************************************************************/
#ifdef USE_CUDD
// This is for those who wish to test their BDD package with CUDD
#include "cuddObj.hh"
typedef Cudd bddMgr;
#else
/* g_debug is used to toggle on and off any debug output you embed in your
* code. If it is nonzero, then output the debug information. Otherwise
* do not output anything.
*/
extern int g_debug;
/* g_verbose is used to toggle on and off any verbose output you embed in
* your code. This is not debug output, just more information than nothing.
*/
extern int g_verbose;
/* This is the default size of each bddMgr's unique and compute tables
* respectively.
*/
static const int BDDMGR_UNIQUE_SLOTS = 1000;
static const int BDDMGR_CACHE_SLOTS = 2000;
/************************************************************************
* CLASSES YOU NEED TO IMPLEMENT
***********************************************************************/
/* BDD
*
* Wrapper for pointers in to the bddMgr data structures. Each
* BDD needs a hook to know which bddMgr it belongs too.
*
* IMPORTANT: you do need to add checks for mismatched managers and
* empty BDDs that are uninitialized or have no manager from the
* default constructor. Correct behavior is to output a error message
* and exit.
*
* The destructor should _not_ delete memory managed by the bddMgr.
* It only frees memory related to the BDD wrapper around the
* accessors into the bddMgr's data structures.
*/
class bddMgr;
class BDD {
friend class bddMgr;
protected:
int v;
BDD * high;
BDD * low;
int id;
bddMgr* ptrMgr;
public:
BDD();
BDD(const BDD &from);
~BDD();
int
operator==(const BDD& other);
BDD&
operator=(const BDD& right);
BDD
operator~();
BDD
operator&(const BDD& other);
BDD
operator|(const BDD& other);
BDD
Restrict(BDD g);
BDD
Ite(const BDD& g, const BDD& h, unsigned int limit = 0) const;
int isOne(void) const;
int isZero(void) const;
int getVariable(void) const;
BDD& getHigh(void) const;
BDD& getLow(void) const;
int getTopVariable(const BDD& g, const BDD& h) const;
BDD basicCofactor(int v, const BDD& x, int pos) const;
};
/* bddMgr
*
* The bddMgr manages the unique and compute tables. It keeps track
* of all the bdd variables. BDDs are just wrappers to protect
* accessors into the bddMgr data structures (pointer, etc.).
*
*/
struct compute_table_entries{
BDD firstVar;
BDD SecondVar;
BDD ThirdVar;
BDD Answer;
};
class bddMgr {
friend class BDD;
protected:
int verbose;
int debug;
vector<BDD *> unique;
vector <compute_table_entries> compute_table;
public:
bddMgr(unsigned int numVars = 0,
unsigned int numSlots = BDDMGR_UNIQUE_SLOTS,
unsigned int cacheSize = BDDMGR_CACHE_SLOTS);
/* Makes a complete copy of a bddMgr. BDDs for x should not
* work in the copy (i.e., the copy has its own memory etc.)
*/
bddMgr(bddMgr& x);
~bddMgr();
void
makeVerbose() {verbose = 1;}
void
makeDebug() {debug = 1;};
/* This should use the copy constructor to make a complete
* independent memory copy of the bddMgr.
*/
bddMgr&
operator=(const bddMgr& right);
/* Creates a new variable in this manager. Variables begin at 0
* and increase monotonically by 1 with each call to bddVar.
*/
BDD
bddVar();
/* Returns the BDD for variable index. If the variable index does
* not exist, then it creates the variable and returns the BDD.
*
* If index < 0, then fail gracefully.
*/
BDD
bddVar(int index);
BDD
bddOne();
BDD
bddZero();
BDD
getOne();
BDD
getZero();
BDD& createbddOne();
BDD& createbddZero();
BDD createNode(int v, BDD& h, BDD& l);
};
/************************************************************************
* END OF CLASSES YOU NEED TO IMPLELMENT
***********************************************************************/
#endif
#endif