-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrepycudd.h
258 lines (229 loc) · 5.36 KB
/
repycudd.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#ifndef PYCUDD_H
#define PYCUDD_H
#include "util.h"
#include "cudd.h"
#include "cuddInt.h"
#include "dddmp.h"
#ifdef SWIG
%feature("autodoc","1");
#endif
// Exception class
class RangeError {};
class DdArray;
class IntArray {
int sz;
public:
int* vec;
IntArray(int size);
~IntArray();
void AssignVect( int *str, int size);
void AssignComplVect( int *str, int size, int univ);
int **ArrayAddress() { return &vec; }
#ifdef SWIG
%exception {
try {
$function
}
catch (RangeError x) {
PyErr_SetString(PyExc_IndexError,"index out-of-bounds");
return NULL;
}
}
#endif
int __getitem__(int j) {
if (j<sz && j>=0) return vec[j];
throw RangeError();
};
void __setitem__(int j, int val) {
if (j<sz && j>=0) vec[j]=val;
else throw RangeError();
};
int __len__() { return sz; }
void Assign( int *list, int k) {
if (k > sz) throw RangeError();
for (int i=0; i < k; i++) vec[i] = list[i];
}
void Swap( int i, int j) {
if (i<sz && i>=0 && j<sz && j>=0) {
int tmp = vec[i];
vec[i] = vec[j];
vec[j] = tmp;
}
else throw RangeError();
}
#ifdef SWIG
%exception;
#endif
};
class StringArray {
int sz;
public:
char** vec;
StringArray(int size);
~StringArray();
char ***ArrayAddress() { return &vec; }
#ifdef SWIG
%exception {
try {
$function
}
catch (RangeError x) {
PyErr_SetString(PyExc_IndexError,"index out-of-bounds");
return NULL;
}
}
#endif
char * __getitem__(int j) {
if (j<sz && j>=0) return vec[j];
throw RangeError();
};
void __setitem__(int j, char *val) {
if (j<sz && j>=0) vec[j]=val;
else throw RangeError();
};
int __len__() { return sz; }
void Assign( char **list, int k) {
if (k > sz) throw RangeError();
for (int i=0; i < k; i++) vec[i] = list[i];
}
void Swap( int i, int j) {
if (i<sz && i>=0 && j<sz && j>=0) {
char *tmp = vec[i];
vec[i] = vec[j];
vec[j] = tmp;
}
else throw RangeError();
}
#ifdef SWIG
%exception;
#endif
};
class DoubleArray {
int sz;
public:
double* vec;
DoubleArray(int size);
~DoubleArray();
#ifdef SWIG
%exception {
try {
$function
}
catch (RangeError x) {
PyErr_SetString(PyExc_IndexError,"index out-of-bounds");
return NULL;
}
}
#endif
double __getitem__(int j) {
if (j<sz && j>=0) return vec[j];
throw RangeError();
};
void __setitem__(int j, double val) {
if (j<sz && j>=0) vec[j]=val;
else throw RangeError();
};
void Assign( double *list, int k) {
if (k > sz) throw RangeError();
for (int i=0; i < k; i++) vec[i] = list[i];
}
void Swap( int i, int j) {
if (i<sz && i>=0 && j<sz && j>=0) {
double tmp = vec[i];
vec[i] = vec[j];
vec[j] = tmp;
}
else throw RangeError();
}
#ifdef SWIG
%exception;
#endif
};
class DdArray {
#ifdef SWIG
%pythoncode %{
__doc__ = "This class provides an array of DdNodes. This is an addition to the CUDD package. Create a DdArray by calling the constructor with the length of the array. In terms of Python array-like behaviour, you can index it, assign individual elements and take its length. Typically, these arrays are populated via the Push method. Refer pycudd.h and pycudd.cpp for function details.<br>"
%}
#endif
int i;
public:
int sz;
DdNode** vec;
DdManager* mgr;
DdArray(DdManager* ddman, int size);
~DdArray();
#ifdef SWIG
%exception {
try {
$function
}
catch (RangeError x) {
PyErr_SetString(PyExc_IndexError,"index out-of-bounds");
return NULL;
}
}
#endif
DdNode* __getitem__(int j) {
DdNode* result = NULL;
if (j<sz && j>=0) {
result = vec[j];
Cudd_Ref(result);
}
else throw RangeError();
return result;
};
void __setitem__(int j, DdNode* val) {
if (j<sz && j>=0) {
if (vec[j]!=NULL) Cudd_RecursiveDeref(mgr,vec[j]);
vec[j]=val;
Cudd_Ref(vec[j]);
}
else throw RangeError();
};
int __len__() { return sz; }
void Swap( int i, int j) {
if (i<sz && i>=0 && j<sz && j>=0) {
DdNode *tmp = vec[i];
vec[i] = vec[j];
vec[j] = tmp;
}
else throw RangeError();
}
#ifdef SWIG
%exception;
#endif
DdNode* Pop();
DdNode* And();
DdNode* Or();
DdNode* AtLeastN(int n);
DdNode* ExactlyN(int n);
DdNode* UpToN(int n);
DdNode* Constraint(int low, int high);
DdNode* Compose(DdNode* term);
void Assign( DdNode** list, int k) {
if (k > sz) throw RangeError();
for (int i=0; i < k; i++) { vec[i] = list[i]; }
}
void Push(DdNode* val);
void SwapNodes( int i, int j);
void Fill(int offset, int mod);
void FillWithIntArray( IntArray *t);
void OrderVector(int left, int right);
void SupportVector(DdNode* term);
int SetVarMap(DdArray* other);
DdNode* VectorSupport();
int VectorSupportIndex(int **dum_sup);
DdNode* PickOneMinterm( DdNode* term );
DdNode* HoldTR( DdArray* other );
int Find( DdNode* term);
int Save( char* filename );
int SaveText( char* filename );
int Load( char* filename );
int LoadText( char* filename );
int ArrayLoad( int rootmatchmode, StringArray *rootmatchnames, int varmatchmode,
StringArray *varmatchnames, IntArray *varmatchauxids, IntArray *varcomposeids,
int mode, char *filename, FILE *fp=NULL);
int ArrayStore( char *ddname, StringArray *rootnames, StringArray *varnames, IntArray *auxids,
int mode, int varinfo, char *filename, FILE *fp=NULL);
};
#endif // PYCUDD_H